FreeBSD Compatability

Please port pihole to FreeBsd so it will work with iocage. Thank you.

I really love the tool and think it would make itself great in a FreeBSD Jail or a similiar surrounding.

I'd love to run pihole on my pfSense appliance...

Running it on my pfSense boks would be nice

1 Like

FreeNAS jail support would be awesome. What are the alternatives?

1 Like

Please port pihole to FreeBsd so it will work with iocage. Thank you.

Just waiting for someone from the FreeBSD community to start working on porting.

Is there a list of work items what needs to be done? How can people help?

None of the developers use FreeBSD so you'll need to start trying to install and see what is broken.

I was working through this a bit over the weekend. It is too frustrating to try to use the installer script, so I installed it on a Pi then copied the install over to a freenas jail and was working through it.
I have all the FreeBSD packages installed and get a rudimentary UI. The base packages are pretty simple: lighttpd plus a bunch of lighttpd packages, the sqlite3 and php stuff and a few others which are available on both systems, just packaged differently.
I was starting to go through the Pi-Hole scripts that run the system and ran into a few issues that I think are also resolvable: mktemp in freebsd does not support -suffix, this can be worked around and it is used pretty heavily in /opt/pihole scripts. I personally think this particular issue can be 'fixed' so that the script works on both systems seamlessly. There is another script that tries to run a function that is not present in BSD shell and there is a common workaround as well. I am pretty sure these can all be pretty easily overcome. It appears that most of it is scripts which, I believe, can be adapted to work on freebsd, even if the install script would have to be way different than a Debian install.
The big issue is the FTL package. I tried to build it and fail miserably:
https://github.com/pi-hole/FTL.git
Unless there is someone here that can spend some time on that and get it to compile I think a FreeBSD Pi-Hole is lost...

What kind of errors or failures were you getting?

First, I have to edit the build.sh file as FreeBSD doesn't understand 'nproc'

 # Build the sources
 #cmake --build . -- -j $(nproc)
 cmake --build . -- -j 2

Then I try to build it and get this:

/FTL$ bash ./build.sh
-- The C compiler identification is Clang 10.0.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kgrider/FTL/cmake
Scanning dependencies of target database
[  1%] Building C object src/database/CMakeFiles/database.dir/common.c.o
cc: error: -Wl,-z,relro,-z,now: 'linker' input unused [-Werror,-Wunused-command-line-argument]
cc: error: -Wl,-z,defs: 'linker' input unused [-Werror,-Wunused-command-line-argument]
cc: error: -Wl,-z,now: 'linker' input unused [-Werror,-Wunused-command-line-argument]
cc: error: -Wl,-z,relro: 'linker' input unused [-Werror,-Wunused-command-line-argument]
--- src/database/CMakeFiles/database.dir/common.c.o ---
*** [src/database/CMakeFiles/database.dir/common.c.o] Error code 1

make[2]: stopped in /usr/home/kgrider/FTL/cmake
1 error

make[2]: stopped in /usr/home/kgrider/FTL/cmake
--- src/database/CMakeFiles/database.dir/all ---
*** [src/database/CMakeFiles/database.dir/all] Error code 2

make[1]: stopped in /usr/home/kgrider/FTL/cmake
Scanning dependencies of target sqlite3
A failure has been detected in another branch of the parallel make

make[2]: stopped in /usr/home/kgrider/FTL/cmake
--- src/database/CMakeFiles/sqlite3.dir/all ---
*** [src/database/CMakeFiles/sqlite3.dir/all] Error code 2

make[1]: stopped in /usr/home/kgrider/FTL/cmake
2 errors

make[1]: stopped in /usr/home/kgrider/FTL/cmake
*** [all] Error code 2

make: stopped in /usr/home/kgrider/FTL/cmake
1 error

make: stopped in /usr/home/kgrider/FTL/cmake

I'm not a dev, but ran across this github commit that seems to resolve a similar issue:

Okay, that might be from:

And compiling a static binary.

And, how do we overcome this? For FreeBSD, I can deal with shared libraries. Is there is a way to do it the same way on FreeBSD, please guide us...

I have pthreadpool, libpthread-stubs, nettle, gmp, gmp-ecm and gmp-api installed.

Might actually be the opposite, need to make a static binary. If you set static=true then make should do the rest for you. This cmake is a new build process for us so there may be some things left to fix in the process.

@DL6ER When you get some free time, I know you're swamped right now.

There is no issues with pthread here as cmake found a way to make Threads, it just needed to look for a way. I guess this should work.

Looking at

I don't see any issues with lpthread in here.

Rather, your cc complains that it does not understand the linking options. This is expected as:

whereas Pi-hole's FTL (and the embedded dnsmasq) have been designed for gcc for compilation. Even when we might be able to change the linker flags to get desired behavior with the (entirely different!) clang compiler, it may still stumble over GNU C extensions we're using in the code.

It's difficult to say. For starters, I'd suggest removing -Werror from this line in src/CMakeLists.txt:

and trying again. Keep us updated with the warnings which are produced. Maybe the build succeeds (optimal outcome), maybe not (expected outcome).

The issue you referenced shows that clang is not expecting linker flags when not linking, gcc doesn't complain about this. We can change this, we'll just have to find out how to do it :wink:

I came across this last night and got a start on porting. There is still much to be done from the looks of things, but here is the progress I've made so far: GitHub - freqlabs/FTL at freebsd-wip

So reading a bit through the comments, I checked on a few things.

  1. gcc is available for FreeBSD (I installed it)
  2. I figured out how to force cmake to use it. It gets a slight bit farther.
  3. I removed -Werror from src/CMakeLists.txt

I am guessing trying to build it with gcc will be more useful than with clang? This is with the pi-hole archive, not the WIP version from freqlabs

My edits to the build.sh script:

# Configure build
mkdir -p cmake
cd cmake
#cmake ..
cmake -DCMAKE_C_COMPILER=/usr/local/bin/gcc ..

# Build the sources
#cmake --build . -- -j $(nproc)
cmake --build . -- -j 2

Now it gets here:
I do not know what sys/prctl.h does, is it in kernel headers?

~/FTL$ bash ./build.sh
-- The C compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/local/bin/gcc
-- Check for working C compiler: /usr/local/bin/gcc - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kgrider/FTL/cmake
Scanning dependencies of target database
[  1%] Building C object src/database/CMakeFiles/database.dir/common.c.o
In file included from /home/kgrider/FTL/src/database/common.c:11:
/home/kgrider/FTL/src/FTL.h:35:10: fatal error: sys/prctl.h: No such file or directory
   35 | #include <sys/prctl.h>
      |          ^~~~~~~~~~~~~
compilation terminated.
--- src/database/CMakeFiles/database.dir/common.c.o ---
*** [src/database/CMakeFiles/database.dir/common.c.o] Error code 1

make[2]: stopped in /usr/home/kgrider/FTL/cmake
1 error

make[2]: stopped in /usr/home/kgrider/FTL/cmake
--- src/database/CMakeFiles/database.dir/all ---
*** [src/database/CMakeFiles/database.dir/all] Error code 2

make[1]: stopped in /usr/home/kgrider/FTL/cmake
Scanning dependencies of target sqlite3
A failure has been detected in another branch of the parallel make

make[2]: stopped in /usr/home/kgrider/FTL/cmake
--- src/database/CMakeFiles/sqlite3.dir/all ---
*** [src/database/CMakeFiles/sqlite3.dir/all] Error code 2

make[1]: stopped in /usr/home/kgrider/FTL/cmake
2 errors

make[1]: stopped in /usr/home/kgrider/FTL/cmake
*** [all] Error code 2

make: stopped in /usr/home/kgrider/FTL/cmake
1 error

make: stopped in /usr/home/kgrider/FTL/cmake

So I found this:
https://www.netroby.com/view/3595

The headers I got were:
ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/11.3-RELEASE/src.txz

I installed the headers and looked for sys/prctl.h and found nothing like that. I expected it here:
/usr/src/sys/amd64/amd64. I have no idea if this is right or not.

There is a ton of Linux-specific stuff (such as prctl) in the code. Those parts will need to be properly abstracted and reimplemented.