Skip to content

Commit

Permalink
libc: use musl implementation of getifaddrs and if_nameindex
Browse files Browse the repository at this point in the history
This patch replaces our home grown (possibly old musl version based)
implementation of getifaddrs() and if_nameindex() with the
implemantation of those provided by modern version musl 1.1.24 that
uses netlink interface. The advantage is that it will also support
IPV6 once we merge the ipv6 branch.

Please note that we are applying simple header trick with __netlink.h
to counter a bug in musl netlink.c. In essence the __netlink_enumerate()
in musl netlink.c calls recv() with MSG_DONTWAIT flag may (and it does
sometimes on OSv) yield EAGAIN or EWOULDBLOCK errors and there is no
error handling logic of those. Instead of adding the error handling we
change recv call to use 0 flags by re-defining MSG_DONTWAIT as 0 to
enforce blocking call which is for example what Golang runtime does
to implement similar functionality. Eventually we should try to upstream
a patch to musl.

Signed-off-by: Waldemar Kozaczuk <[email protected]>
  • Loading branch information
wkozaczuk committed Jun 13, 2022
1 parent 5adf186 commit e6ab059
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 312 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1503,10 +1503,12 @@ musl += network/getservbyname_r.o
musl += network/getservbyname.o
musl += network/getservbyport_r.o
musl += network/getservbyport.o
libc += network/getifaddrs.o
libc += network/if_nameindex.o
musl += network/getifaddrs.o
musl += network/if_nameindex.o
musl += network/if_freenameindex.o
musl += network/res_init.o
musl += network/netlink.o
$(out)/musl/src/network/netlink.o: CFLAGS += --include libc/syscall_to_function.h --include libc/network/__netlink.h

musl += prng/rand.o
musl += prng/rand_r.o
Expand Down
4 changes: 4 additions & 0 deletions libc/network/__netlink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include <sys/socket.h>
#undef MSG_DONTWAIT
//Let us disable the non-blocking call to recv() netlink.c by re-defining MSG_DONTWAIT as 0
#define MSG_DONTWAIT 0
252 changes: 0 additions & 252 deletions libc/network/getifaddrs.c

This file was deleted.

58 changes: 0 additions & 58 deletions libc/network/if_nameindex.c

This file was deleted.

0 comments on commit e6ab059

Please sign in to comment.