Bug 7140 - IPv4/IPv6 problems, bind/connect problems
Summary: IPv4/IPv6 problems, bind/connect problems
Status: RESOLVED FIXED
Alias: None
Product: Samba 3.5
Classification: Unclassified
Component: Winbind (show other bugs)
Version: 3.5.0rc2
Hardware: x86 Solaris
: P3 normal
Target Milestone: ---
Assignee: Karolin Seeger
QA Contact: Samba QA Contact
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-16 10:03 UTC by Ralf Schwiete
Modified: 2010-02-18 05:58 UTC (History)
3 users (show)

See Also:


Attachments
Patches which may fix the issues (3.49 KB, text/x-patch)
2010-02-16 10:06 UTC, Ralf Schwiete
no flags Details
Patches for v3-5 (10.18 KB, patch)
2010-02-17 08:15 UTC, Stefan Metzmacher
kai: review+
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ralf Schwiete 2010-02-16 10:03:40 UTC
Hello,
after building Samba 3.5.0rc2 on Solaris 10 x86 with Sun Studio Compiler I got the following error:

net ads testjoin
[2010/02/12 19:18:21.589785,  0] utils/net_ads.c:285()
  ads_connect: No logon servers
Join to domain is not valid: No logon servers
[2010/02/12 19:18:21.590027,  2] utils/net.c:909()
  return code = -1

truss shows the following output:
(...)
28019:  write(2, "     a d s _ t r y _ c o".., 85)      = 85
28019:  so_socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP, "", SOV_DEFAULT) = 7
28019:  fcntl(7, F_GETFL)                               = 2
                FWRITE
28019:  fcntl(7, F_SETFL, FWRITE|FNONBLOCK)             = 0
28019:  fcntl(7, F_GETFD, 0x00000000)                   = 0
28019:  fcntl(7, F_SETFD, 0x00000001)                   = 0
28019:  connect(7, 0x08957368, 256, SOV_DEFAULT)        Err#124 EAFNOSUPPORT
28019:          AF_INET  name = 183.201.245.15  port = 389
28019:  close(7)                                        = 0
28019:  getuid()                                        = 0 [0]
(...)

The Problem is, that the system opens an IPv6-Socket (which is wrong address family in this case) and then wants to connect on it with IPv4.

After doing some research I found out that the problem is in "libcli/cldap/cldap.c". There is a test if an local-address is given:
(...)
if (!local_addr) {
                ret = tsocket_address_inet_from_strings(c, "ip",
                                                        NULL, 0,
                                                        &any);
(...)

tsock_address_inet_from_strings gives us an tsocket_address-struct with an IPv6 Address.
(...)
        if (strcasecmp(fam, "ip") == 0) {
                hints.ai_family = AF_UNSPEC;
                if (!addr) {
#ifdef HAVE_IPV6
                        addr = "::";
#else
                        addr = "0.0.0.0";
#endif
                }
        } else if (strcasecmp(fam, "ipv4") == 0) {
(...)

after setting 
  socket_address_inet_from_strings(c, "ip",
to
  socket_address_inet_from_strings(c, "ipv4",
(just to check if I'am on the right path) I got an "EINVAL" error from bind and connect in function tdgram_bsd_dgram_socket. The call to bind is:
ret = bind(fd, &lbsda->u.sa, sa_socklen);
sa_socklen is defined as 
  sa_socklen = sizeof(lbsda->u.ss);
shouldn't that better
  sa_socklen = sizeof(lbsda->u.sa); ?
The call to connect is also called with sa_socketlen which also fails.

To fix the IPv4 vs. IPv6 Problem I wrote a little function wich gives me u.sa.addr_family so I can decide if I want an IPv4 Address or not. I also wrote a patch to solve the sa_socklen-Problem. I hope both helps to fix the problem.

Cheers,
Ralf
Comment 1 Ralf Schwiete 2010-02-16 10:06:10 UTC
Created attachment 5355 [details]
Patches which may fix the issues

There are 5 Patches in the Patchfile
Comment 2 Stefan Metzmacher 2010-02-16 14:28:40 UTC
I think this patch is the wrong way to fix this problem, I'll
try to create a more generic fix for this tomorrow.
Comment 3 Stefan Metzmacher 2010-02-17 08:15:35 UTC
Created attachment 5366 [details]
Patches for v3-5

Can you test this patches please?
Comment 4 Ralf Schwiete 2010-02-17 09:47:57 UTC
I've tested the patch and it works.
Thankyou!
Comment 5 Stefan Metzmacher 2010-02-17 13:58:04 UTC
Kai: please assign to Karolin once you've tested this patches.

Karolin: please pick this patches before the patch from
https://bugzilla.samba.org/show_bug.cgi?id=7115
Comment 6 Kai Blin 2010-02-17 15:41:59 UTC
Comment on attachment 5366 [details]
Patches for v3-5

This works fine on my IPv6-only win2k8-r2 domain.
Comment 7 Kai Blin 2010-02-18 04:49:20 UTC
Karolin, please pick.
Comment 8 Karolin Seeger 2010-02-18 05:58:13 UTC
Pushed to v3-5-test.
Closing out bug report.

Thanks!