Bug 6970 - getifaddrs() issues on AIX
getifaddrs() issues on AIX
Status: NEW
Product: Samba 3.4
Classification: Unclassified
Component: Client Tools
unspecified
PPC AIX
: P3 normal
: ---
Assigned To: Stefan Metzmacher
Samba QA Contact
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2009-12-05 13:04 UTC by Miguel Sanders (mail account dead)
Modified: 2013-07-23 14:34 UTC (History)
7 users (show)

See Also:
fumiyas: review+


Attachments
Patch for bug 6970 (3.85 KB, patch)
2009-12-05 13:04 UTC, Miguel Sanders (mail account dead)
no flags Details
Patch for bug 6970 (II) (3.61 KB, patch)
2009-12-06 14:17 UTC, Miguel Sanders (mail account dead)
no flags Details
Patch for master and v3-6-test (4.07 KB, patch)
2012-12-18 15:25 UTC, SATOH Fumiyasu
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Miguel Sanders (mail account dead) 2009-12-05 13:04:18 UTC
Hi Samba team

I would like to report that the "interfaces / bind interfaces only" features of Samba do not function on AIX.
There are two problematic situations:
(1) Assume interfaces en1 and en2 have an IP address whereas en0 does not.
(Simplified) netstat output on AIX would show something like:
# netstat -in
Name  Mtu   Network     Address           
en1   9000  link#2      22.f1.30.0.10.6        
en1   9000  10.226.32   10.226.32.222          
en2   1500  link#3      22.f1.30.0.10.8        
en2   1500  10.226.33   10.226.33.222          
en0*  65390 link#4      22.f1.30.0.10.4        
lo0   16896 link#1                             
lo0   16896 127         127.0.0.1              
lo0   16896 ::1                                

If there is no interfaces entry in smb.conf (f.e. interfaces = en1 or interfaces = en2), smbd will simply not start.
The problem lies in the rep_getifaddrs function in lib/replace/getifaddrs.c
AIX, unlike Linux, also returns info on the layer 2 HW address of the adapter in the ifconf struct (as can be observed from the output above).
As a result, one should only call the SIOCGIFADDR ioctl if the sin_family is AF_INET. 

(2) Assume interface en2 has IP aliases.
(Simplified) netstat output on AIX would show something like:
# netstat -in
Name  Mtu   Network     Address           
en2   1500  link#3      22.f1.30.0.10.8        
en2   1500  10.226.33   10.226.33.222          
en2   1500  139.53.231  139.53.231.201         
en2   1500  139.53.231  139.53.231.107         
lo0   16896 link#1                             
lo0   16896 127         127.0.0.1              
lo0   16896 ::1                                

The IP aliases cannot be used in the interfaces entry in smb.conf.
The problem also lies in the rep_getifaddrs function in lib/replace/getifaddrs.c
AIX, unlike Linux, does not create a new interface for each IP alias.
As a result, the SIOCGIFADDR ioctl does not return any IP aliases of the network interface, only the base IP address.

The attached patch fixes both problems and was tested successfully on AIX 5.3 / 6.1
Comment 1 Miguel Sanders (mail account dead) 2009-12-05 13:04:59 UTC
Created attachment 5057 [details]
Patch for bug 6970
Comment 2 Stefan Metzmacher 2009-12-06 04:51:41 UTC
I think that patch is wrong,
on linux getifaddrs gives more than just AF_INET interfaces.

configure gives this:

checking for iface getifaddrs... lo         AF=17 
eth0       AF=17 
wmaster0   AF=17 
wlan0      AF=17 
tun48      <no address>
tun76      <no address>
tun24      <no address>
vmnet9     AF=17 
lo         IP=127.0.0.1 NETMASK=255.0.0.0
wlan0      IP=172.30.12.19 NETMASK=255.255.255.0
tun48      IP=172.30.48.9 NETMASK=255.255.255.255
tun76      IP=172.30.76.9 NETMASK=255.255.255.255
tun24      IP=192.168.24.16 NETMASK=255.255.255.255
tun24      IP=192.168.71.113 NETMASK=255.255.255.255
vmnet9     IP=172.31.9.1 NETMASK=255.255.255.0
lo         IP=::1 NETMASK=ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
wlan0      IP=fe80::221:6aff:fe70:1a7e NETMASK=ffff:ffff:ffff:ffff::
yes

what does it give on you system?

I assume this problem could also happen on non aix system
and we need to fix this at a higher level.

metze
Comment 3 Miguel Sanders (mail account dead) 2009-12-06 05:04:55 UTC
My comments on the Linux environment might be wrong, since I only have a limited Linux config at home. (I'm an AIX guy, not a Linux guy)
Nevertheless, the code for AIX was wrong and the supplied patch fixes those problems. The patch is certainly not wrong.

Since there is a separate function rep_getifaddrs especially for AIX (#ifdef HAVE_IFACE_AIX), I don't see why you cannot apply this patch.
Comment 4 Miguel Sanders (mail account dead) 2009-12-06 05:39:02 UTC
Metze

I forgot the answer to your questions.
The configure test shows the following:

checking for iface getifaddrs... no
checking for iface AIX... en1        IP=10.226.32.222
en1        IP=10.226.32.222
en2        IP=10.226.33.222
en2        IP=10.226.33.222
en2        IP=10.226.33.222
en2        IP=10.226.33.222
en2        IP=10.226.33.222
en2        IP=10.226.33.222
en2        IP=10.226.33.222
lo0        IP=127.0.0.1
lo0        IP=127.0.0.1
lo0        IP=127.0.0.1
yes

As you can see, IP aliases are not shows.
The output is exactly what I expected since the lib/replace/test/getifaddrs.c code relies on the actual code in lib/replace/getifaddrs.c.
Moreover, if I don't detach en0 (see example above) before running configure, HAVE_IFACE_AIX will not even be set since the actual code freaks out (running SIOCGIFADDR ioctl on sin_family = AF_LINK is not allowed).

After applying the patch, the configure test shows
checking for iface AIX... en1        IP=10.226.32.222
en2        IP=10.226.33.222
en2        IP=139.53.231.201
en2        IP=139.53.231.107
en2        IP=139.53.231.106
en2        IP=139.53.231.105
en2        IP=139.53.231.103
lo0        IP=127.0.0.1
yes

Which is much better

Cheers!  
Comment 5 Stefan Metzmacher 2009-12-06 06:02:17 UTC
Thanks!

However I see two problems

-	ifc.ifc_len = sizeof(buff);
-	ifc.ifc_buf = buff;
+	if (ioctl(fd, SIOCGSIZIFCONF, &size) != 0) {
+		return -1;
+	}
+
+	ifc.ifc_len = size;
+	ifc.ifc_buf = (struct ifreq *)buff;

we have to make sure size <= sizeof(buff)

And we should not remove ipv6 addresses.
http://ipv6int.net/systems/index.html says AIX 6.1 has support
for ipv6.

I'm also wondering why configure doesn't output any NETMASK= strings...

Comment 6 Miguel Sanders (mail account dead) 2009-12-06 06:55:30 UTC
Hi Metze

Yes, you're totally right about those two remarks.
In my test code, I made a dynamic memory allocation of size "size".
But since I don't know how the Samba project handles malloc calls (either direct or via wrappers), I left that out. (Some projects have their own wrappers around malloc and so on).

You're also right about IPV6.
I'll have a look at that.
Comment 7 Miguel Sanders (mail account dead) 2009-12-06 07:11:27 UTC
I'll have a look at this tonight, OK?

Cheers!
Comment 8 Miguel Sanders (mail account dead) 2009-12-06 14:17:35 UTC
Created attachment 5060 [details]
Patch for bug 6970 (II)
Comment 9 Miguel Sanders (mail account dead) 2009-12-06 14:18:52 UTC
Hi Metze

Following your remarks, I made some modifications to the patch.
I also tested it with IPV6 addresses.

Could you have a look?

Cheers!

Miguel
Comment 10 Miguel Sanders (mail account dead) 2009-12-06 14:25:36 UTC
Metze

The reason why there is no NETMASK output in configure appears to be caused by the implementation of the SIOCGIFNETMASK ioctl.
Apparently, this ioctl does not set sin_family!
I will contact some L3 people I know and ask them if this is by design or a bug.
If it's by design, I will open an additional bug in order to rectify lib/replace/test/getifaddrs.c . 

Do you agree on this?
Comment 11 Miguel Sanders (mail account dead) 2009-12-11 03:44:35 UTC
Hi Metze

I received feedback from my L3 contact and apparently the SIOCGIFNETMASK ioctl does not set sin_family. This is by design.
Have you had a chance to look at the patch for getifaddrs() ?

Cheers

Miguel
Comment 12 Miguel Sanders (mail account dead) 2009-12-23 12:53:13 UTC
Hi

Has anyone already reviewed the updated patch?
I really would like to get this in the next release...

Thanks for your help!
Comment 13 SATOH Fumiyasu 2012-09-20 12:13:23 UTC
I'm facing the same problem on AIX 6.1 WPAR (workload partition).

The nmbd on AIX WPAR found network interfaces that are configured
for global AIX (outer AIX WPAR), then tried and failed to open it.

Network interfaces on global AIX:

  # netstat -in@
  WPAR       Name  Mtu   Network     Address            Ipkts Ierrs    Opkts Oerrs  Coll
  Global     en0   1500  link#2      X.X.X.X.X.X      38260829     0 21399190     0     0
  Global     en0   1500  10          10.0.0.32        38260829     0 21399190     0     0
  build-aix6 en0   1500  10          10.0.0.92        23323258     0 20962573     0     0
  Global     lo0   16896 link#1                         512311     0   512310     0     0
  Global     lo0   16896 127         127.0.0.1          512311     0   512310     0     0
  Global     lo0   16896 ::1%1                          512311     0   512310     0     0

The IP address 10.0.0.32 is for global AIX (Global).
The IP address 10.0.0.92 is for AIX WPAR (build-aix6).

Network interfaces on AIX WPAR (buidl-aix6):

  # netstat -in@
  netstat: illegal option -- @
  usage: netstat [-Aaon] [-f address_family]
                [-inrsu] [-f address_family] [-p proto]
                [-n] [-I interface] [interval]
  # netstat -in
  Name  Mtu   Network     Address           Ipkts Ierrs    Opkts Oerrs  Coll
  en0   1500  link#2      X.X.X.X.X.X      23323239     0 20962559     0     0
  en0   1500  10          10.0.0.92        23323239     0 20962559     0     0
  lo0   16896 link#1                         412501     0   293745     0     0
  lo0   16896 127         127.0.0.1          412501     0   293745     0     0
  lo0   16896 ::1%1                          412501     0   293745     0     0

log.nmbd by nmbd on AIX WPAR (buidl-aix6):

  [2012/09/20 20:44:02,  0] nmbd/nmbd.c:857(main)
    nmbd version 3.5.13-40.1.aix6 started.
    Copyright Andrew Tridgell and the Samba Team 1992-2010
  [2012/09/20 20:44:02.565112,  0] lib/util_sock.c:881(open_socket_in)
    bind failed on port 137 socket_addr = 10.0.0.32.
    Error = Can't assign requested address
  [2012/09/20 20:44:02.565672,  0] nmbd/nmbd_subnetdb.c:112(make_subnet)
    nmbd_subnetdb:make_subnet()
      Failed to open nmb socket on interface 10.0.0.32 for port 137.  Error was Can't assign requested address

I've tried the Miguel Sanders's patch and confirmed this bug was gone.
Comment 14 SATOH Fumiyasu 2012-09-20 12:26:34 UTC
(In reply to comment #13)
> I've tried the Miguel Sanders's patch and confirmed this bug was gone.

I've confirmed with Samba 3.5.13 + Miguel Sanders's patch +
Rolf Anders' patch at:

  http://lists.samba.org/archive/samba-technical/2011-August/078954.html

Without Rolf Anders' patch, I met the following log:

  [2012/09/20 21:17:28,  0] nmbd/nmbd.c:857(main)
    nmbd version 3.5.13-40.1.aix6 started.
    Copyright Andrew Tridgell and the Samba Team 1992-2010
  [2012/09/20 21:17:28.458766,  0] lib/interface.c:519(load_interfaces)
    ERROR: Could not determine network interfaces, you must use a interfaces config line

See also Bug 8984 - AIX 6.1 nmbd Failed to open nmb bcast socket on interface.
Comment 15 SATOH Fumiyasu 2012-09-20 15:33:32 UTC
The smbd without patches found wrong IP address 10.0.0.32
(this is for global AIX) and does not find IPv6 address ::1.

  # /path/to/smbd-without-patches -DFS -d3
  ...
  added interface en0 ip=10.0.0.32 bcast=10.0.255.255 netmask=
  added interface lo0 ip=127.0.0.1 bcast=127.255.255.255 netmask=
  add_interface: not adding duplicate interface 127.0.0.1
  loaded services
  Becoming a daemon.

The smbd with patches found correct IP address 10.0.0.92
(this is for AIX WPAR) and IPv6 address ::1.

  # /path/to/smbd-with-patches -DFS -d3
  ...
  added interface lo0 ip=::1 bcast=ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff netmask=
  added interface en0 ip=10.0.0.92 bcast=10.0.255.255 netmask=
  added interface lo0 ip=127.0.0.1 bcast=127.255.255.255 netmask=
  loaded services
  Becoming a daemon.

I don't know why "netmask=" is null string in both cases...
Comment 16 SATOH Fumiyasu 2012-09-21 03:24:42 UTC
Another getifaddrs() implementation for AIX 5.3 (and later?) found at:

  getifaddrs for AIX
  http://lists.samba.org/archive/samba-technical/2009-February/063079.html
Comment 17 SATOH Fumiyasu 2012-12-18 15:25:26 UTC
Created attachment 8357 [details]
Patch for master and v3-6-test

I've created a patch by git format-patch.