LaKabane / libtuntap

The portable Tun/Tap devices configuration utility
193 stars 63 forks source link

Add support for musl-libc runtime library #6

Closed Polpetta closed 6 years ago

Polpetta commented 6 years ago

Hello, we were trying to compile our application inside an Alpine Linux Docker container and we noticed include errors since Alpine doesn't use GLIBC, but it uses Musl-libc:

bash-4.4# make
Scanning dependencies of target tuntap
[  7%] Building C object CMakeFiles/tuntap.dir/tuntap.c.o
[ 14%] Building C object CMakeFiles/tuntap.dir/tuntap_log.c.o
[ 21%] Building C object CMakeFiles/tuntap.dir/tuntap-unix.c.o
[ 28%] Building C object CMakeFiles/tuntap.dir/tuntap-unix-linux.c.o
In file included from /libtuntap/tuntap-unix-linux.c:25:0:
/usr/include/netinet/if_ether.h:104:8: error: redefinition of 'struct ethhdr'
 struct ethhdr {
        ^~~~~~
In file included from /usr/include/linux/if_tun.h:20:0,
                 from /libtuntap/tuntap-unix-linux.c:24:
/usr/include/linux/if_ether.h:140:8: note: originally defined here
 struct ethhdr {
        ^~~~~~
make[2]: *** [CMakeFiles/tuntap.dir/build.make:102: CMakeFiles/tuntap.dir/tuntap-unix-linux.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:68: CMakeFiles/tuntap.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

The reason of the error is explained here: https://wiki.musl-libc.org/faq.html#Q:-Why-am-I-getting- I've fixed them adding a stripped down version of if_tun.h to the project. I've taken the solution from here: https://github.com/stsp/dosemu2/issues/530

This solution works on Alpine Linux and on systems using gnu libc with this version:

[dpolonio@davmark ~]$ /usr/lib/libc.so.6 
GNU C Library (GNU libc) stable release version 2.28.
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 8.2.0.
libc ABIs: UNIQUE IFUNC ABSOLUTE
For bug reporting instructions, please see:
<https://bugs.archlinux.org/>.

Hope it helps! Cheers

tleguern commented 6 years ago

If we go down this road we need a way to keep this file in sync and test the compilation with musl-libc, which I don't use. Have you considered using sabotage-linux's headers instead ?

Polpetta commented 6 years ago

I've checked out sabotage-Linux's headers. The problem is that our software is going to run in Docker containers inside a Kubernetes environment, so changing kernel headers would be very difficult for us.

Anyway, if you need a continuous integration environment system where you can check for each commit compilation and regression tests I could set up one with Docker and Travis-ci.

tleguern commented 6 years ago

About your offer for a continuous integration system: thanks although I am not sure Docker and Travis-ci are the right tools as we need to check more than OS X and Linux. Correct me if I am wrong but I don't think it is possible to check build on NetBSD or OpenBSD this way.

chipot commented 6 years ago

I could reproduce the bug in debian.

I found that including linux/if_tun.h after netinet/if_ether.h fixes the compilation issue.

I've added a new PR #7. Can you check if it fixes the build in your environment ?

Polpetta commented 6 years ago

Since #7 has been merged, I'm gonna close this!

tleguern commented 6 years ago

Thanks :)