Bug 259374

Summary: Linux(4) getifaddrs() results in Address family not supported by protocol getifaddrs() (EAFNOSUPPORT)
Product: Base System Reporter: Didier Garcin <didu31>
Component: kernAssignee: Alexander V. Chernikov <melifaro>
Status: Closed FIXED    
Severity: Affects Many People CC: dchagin, emaste, trasz
Priority: --- Keywords: needs-qa
Version: 13.0-RELEASEFlags: koobs: maintainer-feedback? (trasz)
koobs: maintainer-feedback? (dchagin)
koobs: mfc-stable13?
koobs: mfc-stable12?
koobs: mfc-stable11-
Hardware: amd64   
OS: Any   

Description Didier Garcin 2021-10-23 10:27:05 UTC
Hi,

interface with gnu/linux getifaddrs() is no perfect.
This concerns at least interface with debian wheezy, buster and bulleyes kernels.

freebsd-13% ifconfig
bge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=c019b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,TSO4,VLAN_HWTSO,LINKSTATE>
        ether 84:2b:2b:ae:6a:85
        inet 192.168.0.45 netmask 0xffffff00 broadcast 192.168.0.255
        media: Ethernet autoselect (100baseTX <full-duplex>)
        status: active
        nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
        options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
        inet 127.0.0.1 netmask 0xff000000
        groups: lo
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>

And consider this snippet, if.c:

#include <errno.h>
#include <stdio.h>
#include <ifaddrs.h>

int main(int argc, char** argv)
{
  struct ifaddrs *addrs, *ent;

  if (getifaddrs(&addrs))
  {
      printf("errno = %d\n", errno);
      perror("getifaddrs()");
      return 1;
  }

  int count = 0;

  /* Count the number of interfaces */
  for (ent = addrs; ent; ent = ent->ifa_next) 
  {
    count++;
  }
freeifaddrs(addrs);
}

freebsd-13% cc if.c -o if
freebsd-13% ./if
"bge0" af_family = 18            (= AF_LINK  /* Link layer interface */)
"bge0" af_family = 2             (= AF_INET)
"lo0" af_family = 18
"lo0" af_family = 2

freebsd-13% sudo chroot compat/debian /bin/bash
debian% cc if.c -o if
debian% ./if
errno = 97                      (EAFNOSUPPORT)
getifaddrs(): Address family not supported by protocol


Could it be a compatibility bug with AF_LINK ?
Comment 1 Didier Garcin 2021-10-23 10:35:43 UTC
#include <errno.h>
#include <stdio.h>
#include <ifaddrs.h>
#include <sys/socket.h>

int main(int argc, char** argv)
{
  struct ifaddrs *addrs, *ent;

  if (getifaddrs(&addrs))
    printf("errno = %d\n", errno);

  int count = 0;

  /* Count the number of interfaces */
  for (ent = addrs; ent; ent = ent->ifa_next) 
  {
    count++;
    /* ERRATUM */
    printf("\"%s\" af_family = %d\n", ent->ifa_name, ent->ifa_addr->sa_family);
  }
freeifaddrs(addrs);
}
Comment 2 Ed Maste freebsd_committer freebsd_triage 2021-10-25 18:54:22 UTC
(In reply to Didier Garcin from comment #1)

Can you capture and attach ktrace/strace from running the sample under the Linuxulator? Also, what happens if you run your sample on real Linux?
Comment 3 Didier Garcin 2021-10-26 20:53:29 UTC
(In reply to Ed Maste from comment #2)

I'm sorry, strace is suspended automatically without producing any log :

debian$ strace  ./if


^C
debian$
debian$ strace ./if &
[1] 25885
didier@teahupoo:~/labo$ 
debian$ ps 
  PID TTY          TIME CMD
26803 pts/1    00:00:00 ps
26436 pts/1    00:00:00 strace
25885 pts/1    00:00:00 strace
70426 pts/1    00:00:00 bash
debian$

On host :

freebsd-13% sudo ps -a                    
  PID TT  STAT    TIME COMMAND
.
.
.
25885  1  I    0:00,00 strace ./if
26436  1  TX   0:00,00 strace ./if
69793  1  I    0:00,01 sudo chroot debian /bin/bash
.
.
.
Comment 4 Dmitry Chagin freebsd_committer freebsd_triage 2021-10-26 22:38:37 UTC
AFAIRemember, from some time glibc use NETLINK for getifaddrs, it in my queue, but for first in my POV we need modify domain code to allow detaching of protocol family. I think it’s possible for now after epoch
Comment 5 Didier Garcin 2021-10-27 14:15:12 UTC
(In reply to Dmitry Chagin from comment #4)

Very good news !!
Comment 6 Dmitry Chagin freebsd_committer freebsd_triage 2022-09-08 09:15:39 UTC
over to netlink author
Comment 7 Dmitry Chagin freebsd_committer freebsd_triage 2023-01-29 18:45:22 UTC
merged into the stable/13, thanks too melifaro@