From 5a8b6ac4c0ea88bdab12349830985560c69cbf8c Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 2 May 2011 12:09:19 +1000 Subject: s4-lib merge get_interfaces() from Samba3 to Samba4 --- source4/lib/socket/interface.c | 244 ++++++++++++++++++++++++++++------------- 1 file changed, 165 insertions(+), 79 deletions(-) (limited to 'source4/lib/socket/interface.c') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index c4411b623c..abeca8ba1e 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -25,11 +25,14 @@ #include "../lib/util/util_net.h" #include "../lib/util/dlinklist.h" -/** used for network interfaces */ +/* used for network interfaces */ struct interface { struct interface *next, *prev; - struct in_addr ip; - struct in_addr nmask; + char *name; + int flags; + struct sockaddr_storage ip; + struct sockaddr_storage netmask; + struct sockaddr_storage bcast; const char *ip_s; const char *bcast_s; const char *nmask_s; @@ -46,30 +49,45 @@ struct interface { Try and find an interface that matches an ip. If we cannot, return NULL **************************************************************************/ static struct interface *iface_find(struct interface *interfaces, - struct in_addr ip, bool CheckMask) + const struct sockaddr *ip, + bool check_mask) { struct interface *i; - if (is_zero_ip_v4(ip)) return interfaces; - for (i=interfaces;i;i=i->next) - if (CheckMask) { - if (same_net_v4(i->ip,ip,i->nmask)) return i; - } else if (i->ip.s_addr == ip.s_addr) return i; + if (is_address_any(ip)) { + return interfaces; + } + + for (i=interfaces;i;i=i->next) { + if (check_mask) { + if (same_net(ip, (struct sockaddr *)&i->ip, (struct sockaddr *)&i->netmask)) { + return i; + } + } else if (sockaddr_equal((struct sockaddr *)&i->ip, ip)) { + return i; + } + } return NULL; } - /**************************************************************************** add an interface to the linked list of interfaces ****************************************************************************/ -static void add_interface(TALLOC_CTX *mem_ctx, struct in_addr ip, struct in_addr nmask, struct interface **interfaces) +static void add_interface(TALLOC_CTX *mem_ctx, const struct iface_struct *ifs, struct interface **interfaces) { + char addr[INET6_ADDRSTRLEN]; struct interface *iface; - struct in_addr bcast; - if (iface_find(*interfaces, ip, false)) { - DEBUG(3,("not adding duplicate interface %s\n",inet_ntoa(ip))); + if (iface_find(*interfaces, (const struct sockaddr *)&ifs->ip, false)) { + DEBUG(3,("add_interface: not adding duplicate interface %s\n", + print_sockaddr(addr, sizeof(addr), &ifs->ip) )); + return; + } + + if (!(ifs->flags & (IFF_BROADCAST|IFF_LOOPBACK))) { + DEBUG(3,("not adding non-broadcast interface %s\n", + ifs->name )); return; } @@ -79,26 +97,36 @@ static void add_interface(TALLOC_CTX *mem_ctx, struct in_addr ip, struct in_addr ZERO_STRUCTPN(iface); - iface->ip = ip; - iface->nmask = nmask; - bcast.s_addr = MKBCADDR(iface->ip.s_addr, iface->nmask.s_addr); + iface->name = talloc_strdup(iface, ifs->name); + if (!iface->name) { + SAFE_FREE(iface); + return; + } + iface->flags = ifs->flags; + iface->ip = ifs->ip; + iface->netmask = ifs->netmask; + iface->bcast = ifs->bcast; /* keep string versions too, to avoid people tripping over the implied static in inet_ntoa() */ - iface->ip_s = talloc_strdup(iface, inet_ntoa(iface->ip)); - iface->nmask_s = talloc_strdup(iface, inet_ntoa(iface->nmask)); - - if (nmask.s_addr != ~0) { - iface->bcast_s = talloc_strdup(iface, inet_ntoa(bcast)); - } - - DLIST_ADD_END(*interfaces, iface, struct interface *); - - DEBUG(3,("added interface ip=%s nmask=%s\n", iface->ip_s, iface->nmask_s)); + print_sockaddr(addr, sizeof(addr), &iface->ip); + DEBUG(2,("added interface %s ip=%s ", + iface->name, addr)); + iface->ip_s = talloc_strdup(iface, addr); + + print_sockaddr(addr, sizeof(addr), + &iface->bcast); + DEBUG(2,("bcast=%s ", addr)); + iface->bcast_s = talloc_strdup(iface, addr); + + print_sockaddr(addr, sizeof(addr), + &iface->netmask); + DEBUG(2,("netmask=%s\n", addr)); + iface->nmask_s = talloc_strdup(iface, addr); + + DLIST_ADD(*interfaces, iface); } - - /** interpret a single element from a interfaces= config line @@ -116,77 +144,134 @@ static void interpret_interface(TALLOC_CTX *mem_ctx, int total_probed, struct interface **local_interfaces) { - struct in_addr ip, nmask; + struct sockaddr_storage ss; + struct sockaddr_storage ss_mask; + struct sockaddr_storage ss_net; + struct sockaddr_storage ss_bcast; + struct iface_struct ifs; char *p; - char *address; - int i, added=0; + int i; + bool added=false; + bool goodaddr = false; - ip.s_addr = 0; - nmask.s_addr = 0; - /* first check if it is an interface name */ for (i=0;i 2) { - nmask.s_addr = interpret_addr2(p).s_addr; + goodaddr = interpret_string_addr(&ss_mask, p, 0); + if (!goodaddr) { + DEBUG(2,("interpret_interface: " + "can't determine netmask from %s\n", + p)); + return; + } } else { - nmask.s_addr = htonl(((ALLONES >> atoi(p)) ^ ALLONES)); + char *endp = NULL; + unsigned long val = strtoul(p, &endp, 0); + if (p == endp || (endp && *endp != '\0')) { + DEBUG(2,("interpret_interface: " + "can't determine netmask value from %s\n", + p)); + return; + } + if (!make_netmask(&ss_mask, &ss, val)) { + DEBUG(2,("interpret_interface: " + "can't apply netmask value %lu from %s\n", + val, + p)); + return; + } } - /* maybe the first component was a broadcast address */ - if (ip.s_addr == MKBCADDR(ip.s_addr, nmask.s_addr) || - ip.s_addr == MKNETADDR(ip.s_addr, nmask.s_addr)) { + make_bcast(&ss_bcast, &ss, &ss_mask); + make_net(&ss_net, &ss, &ss_mask); + + /* Maybe the first component was a broadcast address. */ + if (sockaddr_equal((struct sockaddr *)&ss_bcast, (struct sockaddr *)&ss) || + sockaddr_equal((struct sockaddr *)&ss_net, (struct sockaddr *)&ss)) { for (i=0;iip_s; } @@ -315,10 +399,12 @@ const char *iface_best_ip(struct interface *ifaces, const char *dest) */ bool iface_is_local(struct interface *ifaces, const char *dest) { - struct in_addr ip; + struct sockaddr_storage ss; - ip.s_addr = interpret_addr(dest); - if (iface_find(ifaces, ip, true)) { + if (!interpret_string_addr(&ss, dest, AI_NUMERICHOST)) { + return false; + } + if (iface_find(ifaces, (const struct sockaddr *)&ss, true)) { return true; } return false; -- cgit From 879498b3622102630a5ade8d7d5421720f6fd7c6 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 3 May 2011 19:41:41 +1000 Subject: s4-lib/socket Samba4 is not IPv6 compatible Don't add IPv6 interfaces until we actually support them. I'll soon have IPv6 service at home, and then I'll make it my buisness to sort this out once and for all. Andrew Bartlett --- source4/lib/socket/interface.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source4/lib/socket/interface.c') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index abeca8ba1e..69b7ec1d49 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -91,6 +91,11 @@ static void add_interface(TALLOC_CTX *mem_ctx, const struct iface_struct *ifs, s return; } + if (ifs->ip.ss_family != AF_INET) { + DEBUG(5, ("not adding IPv6 interface %s\n", ifs->name)); + return; + } + iface = talloc(*interfaces == NULL ? mem_ctx : *interfaces, struct interface); if (iface == NULL) return; -- cgit From 22cb631b4fd0647b70fbaaafaffda8712a84a999 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 2 May 2011 15:57:19 +1000 Subject: s4-interfaces Rename interfaces code so not to conflict with source3/ The iface_count, iface_n_bcast, and load_interfaces functions conflicted with functions of the same name in source3, so the source4 functions were renamed. Hopefully we can actually wrap one around the other in future. Andrew Bartlett --- source4/lib/socket/interface.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'source4/lib/socket/interface.c') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 69b7ec1d49..4eb4f3a517 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -48,9 +48,9 @@ struct interface { /**************************************************************************** Try and find an interface that matches an ip. If we cannot, return NULL **************************************************************************/ -static struct interface *iface_find(struct interface *interfaces, - const struct sockaddr *ip, - bool check_mask) +static struct interface *iface_list_find(struct interface *interfaces, + const struct sockaddr *ip, + bool check_mask) { struct interface *i; @@ -79,7 +79,7 @@ static void add_interface(TALLOC_CTX *mem_ctx, const struct iface_struct *ifs, s char addr[INET6_ADDRSTRLEN]; struct interface *iface; - if (iface_find(*interfaces, (const struct sockaddr *)&ifs->ip, false)) { + if (iface_list_find(*interfaces, (const struct sockaddr *)&ifs->ip, false)) { DEBUG(3,("add_interface: not adding duplicate interface %s\n", print_sockaddr(addr, sizeof(addr), &ifs->ip) )); return; @@ -283,7 +283,7 @@ static void interpret_interface(TALLOC_CTX *mem_ctx, /** load the list of network interfaces **/ -void load_interfaces(TALLOC_CTX *mem_ctx, const char **interfaces, struct interface **local_interfaces) +void load_interface_list(TALLOC_CTX *mem_ctx, const char **interfaces, struct interface **local_interfaces) { const char **ptr = interfaces; int i; @@ -322,7 +322,7 @@ void load_interfaces(TALLOC_CTX *mem_ctx, const char **interfaces, struct interf /** how many interfaces do we have **/ -int iface_count(struct interface *ifaces) +int iface_list_count(struct interface *ifaces) { int ret = 0; struct interface *i; @@ -335,7 +335,7 @@ int iface_count(struct interface *ifaces) /** return IP of the Nth interface **/ -const char *iface_n_ip(struct interface *ifaces, int n) +const char *iface_list_n_ip(struct interface *ifaces, int n) { struct interface *i; @@ -351,7 +351,7 @@ const char *iface_n_ip(struct interface *ifaces, int n) /** return bcast of the Nth interface **/ -const char *iface_n_bcast(struct interface *ifaces, int n) +const char *iface_list_n_bcast(struct interface *ifaces, int n) { struct interface *i; @@ -367,7 +367,7 @@ const char *iface_n_bcast(struct interface *ifaces, int n) /** return netmask of the Nth interface **/ -const char *iface_n_netmask(struct interface *ifaces, int n) +const char *iface_list_n_netmask(struct interface *ifaces, int n) { struct interface *i; @@ -384,32 +384,32 @@ const char *iface_n_netmask(struct interface *ifaces, int n) return the local IP address that best matches a destination IP, or our first interface if none match */ -const char *iface_best_ip(struct interface *ifaces, const char *dest) +const char *iface_list_best_ip(struct interface *ifaces, const char *dest) { struct interface *iface; struct sockaddr_storage ss; if (!interpret_string_addr(&ss, dest, AI_NUMERICHOST)) { - return iface_n_ip(ifaces, 0); + return iface_list_n_ip(ifaces, 0); } - iface = iface_find(ifaces, (const struct sockaddr *)&ss, true); + iface = iface_list_find(ifaces, (const struct sockaddr *)&ss, true); if (iface) { return iface->ip_s; } - return iface_n_ip(ifaces, 0); + return iface_list_n_ip(ifaces, 0); } /** return true if an IP is one one of our local networks */ -bool iface_is_local(struct interface *ifaces, const char *dest) +bool iface_list_is_local(struct interface *ifaces, const char *dest) { struct sockaddr_storage ss; if (!interpret_string_addr(&ss, dest, AI_NUMERICHOST)) { return false; } - if (iface_find(ifaces, (const struct sockaddr *)&ss, true)) { + if (iface_list_find(ifaces, (const struct sockaddr *)&ss, true)) { return true; } return false; @@ -418,7 +418,7 @@ bool iface_is_local(struct interface *ifaces, const char *dest) /** return true if a IP matches a IP/netmask pair */ -bool iface_same_net(const char *ip1, const char *ip2, const char *netmask) +bool iface_list_same_net(const char *ip1, const char *ip2, const char *netmask) { return same_net_v4(interpret_addr2(ip1), interpret_addr2(ip2), -- cgit From c596d85afd41c2512ef77a10a9d6b40f4836c386 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 8 May 2011 12:55:41 +0200 Subject: s4-interfaces: keep interfaces in the order they were declared the spoolss notify test depends on the interfaces order Pair-Programmed-With: Andrew Bartlett Autobuild-User: Andrew Tridgell Autobuild-Date: Sun May 8 13:57:58 CEST 2011 on sn-devel-104 --- source4/lib/socket/interface.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source4/lib/socket/interface.c') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 4eb4f3a517..b762f5573a 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -129,7 +129,11 @@ static void add_interface(TALLOC_CTX *mem_ctx, const struct iface_struct *ifs, s DEBUG(2,("netmask=%s\n", addr)); iface->nmask_s = talloc_strdup(iface, addr); - DLIST_ADD(*interfaces, iface); + /* + this needs to be a ADD_END, as some tests (such as the + spoolss notify test) depend on the interfaces ordering + */ + DLIST_ADD_END(*interfaces, iface, NULL); } /** -- cgit From 2fc11518b7573bce3cdf2f2acf7dec024f22e9c6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 May 2011 12:23:35 +0200 Subject: s4-ipv6: added iface_list_wildcard() this returns a list of wildcard address to listen on, when we don't have 'bind interfaces only' set. It is a list, not a single address, we need to listen separately for the IPv6 "::" address from the IPv4 0.0.0.0 address. This also takes account of the loadparm "socket address" option --- source4/lib/socket/interface.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'source4/lib/socket/interface.c') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index b762f5573a..83d8e4c129 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -21,6 +21,7 @@ #include "includes.h" #include "system/network.h" +#include "param/param.h" #include "lib/socket/netif.h" #include "../lib/util/util_net.h" #include "../lib/util/dlinklist.h" @@ -428,3 +429,30 @@ bool iface_list_same_net(const char *ip1, const char *ip2, const char *netmask) interpret_addr2(ip2), interpret_addr2(netmask)); } + +/** + return the list of wildcard interfaces + this will include the IPv4 0.0.0.0, and may include IPv6 :: + it is overridden by the 'socket address' option in smb.conf +*/ +const char **iface_list_wildcard(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx) +{ + const char **ret; + const char *socket_address; + + /* the user may have configured a specific address */ + socket_address = lpcfg_socket_address(lp_ctx); + if (strcmp(socket_address, "") != 0) { + ret = (const char **)str_list_make(mem_ctx, socket_address, NULL); + return ret; + } + + ret = (const char **)str_list_make(mem_ctx, "0.0.0.0", NULL); + if (ret == NULL) return NULL; + +#ifdef HAVE_IPV6 + return str_list_add(ret, "::"); +#endif + + return ret; +} -- cgit From 62af4a3798995b0368625c0322bc9d5373bb0348 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 May 2011 12:26:18 +0200 Subject: s4-ipv6: allow IPv6 addresses in our interfaces list --- source4/lib/socket/interface.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'source4/lib/socket/interface.c') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 83d8e4c129..9ae658da3e 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -92,11 +92,6 @@ static void add_interface(TALLOC_CTX *mem_ctx, const struct iface_struct *ifs, s return; } - if (ifs->ip.ss_family != AF_INET) { - DEBUG(5, ("not adding IPv6 interface %s\n", ifs->name)); - return; - } - iface = talloc(*interfaces == NULL ? mem_ctx : *interfaces, struct interface); if (iface == NULL) return; -- cgit From a527b96c968037db2d699493a9017709d053f95a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 May 2011 12:27:01 +0200 Subject: s4-ipv6: fixed a warning --- source4/lib/socket/interface.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/lib/socket/interface.c') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 9ae658da3e..0de44c1517 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -302,7 +302,7 @@ void load_interface_list(TALLOC_CTX *mem_ctx, const char **interfaces, struct in DEBUG(0,("ERROR: Could not determine network interfaces, you must use a interfaces config line\n")); } for (i=0;i Date: Thu, 12 May 2011 12:27:37 +0200 Subject: s4-ipv6: added ipv4 functions to interface code this adds iface_list_first_v4() and iface_list_n_is_v4(). The NBT server will use these to allow it to listen only for IPv4 addresses. --- source4/lib/socket/interface.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'source4/lib/socket/interface.c') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 0de44c1517..3737f57f9b 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -348,6 +348,38 @@ const char *iface_list_n_ip(struct interface *ifaces, int n) return NULL; } + +/** + return the first IPv4 interface address we have registered + **/ +const char *iface_list_first_v4(struct interface *ifaces) +{ + struct interface *i; + + for (i=ifaces; i; i=i->next) { + if (i->ip.ss_family == AF_INET) { + return i->ip_s; + } + } + return NULL; +} + +/** + check if an interface is IPv4 + **/ +bool iface_list_n_is_v4(struct interface *ifaces, int n) +{ + struct interface *i; + + for (i=ifaces;i && n;i=i->next) + n--; + + if (i) { + return i->ip.ss_family == AF_INET; + } + return false; +} + /** return bcast of the Nth interface **/ -- cgit From 44d47e85157209f5aec1a6e0cd507c1084716816 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 2 Jun 2011 15:39:54 +1000 Subject: s4-ipv6: allow ipv6 to be enabled/disabled in smb.conf this adds the parametric option ipv6:enable=true/false It defaults to false for now, until the remaining issues with testing of ipv6 are resolved --- source4/lib/socket/interface.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) (limited to 'source4/lib/socket/interface.c') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 3737f57f9b..00550a9ed4 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -75,7 +75,8 @@ static struct interface *iface_list_find(struct interface *interfaces, /**************************************************************************** add an interface to the linked list of interfaces ****************************************************************************/ -static void add_interface(TALLOC_CTX *mem_ctx, const struct iface_struct *ifs, struct interface **interfaces) +static void add_interface(TALLOC_CTX *mem_ctx, const struct iface_struct *ifs, struct interface **interfaces, + bool enable_ipv6) { char addr[INET6_ADDRSTRLEN]; struct interface *iface; @@ -92,6 +93,10 @@ static void add_interface(TALLOC_CTX *mem_ctx, const struct iface_struct *ifs, s return; } + if (!enable_ipv6 && ifs->ip.ss_family != AF_INET) { + return; + } + iface = talloc(*interfaces == NULL ? mem_ctx : *interfaces, struct interface); if (iface == NULL) return; @@ -147,7 +152,8 @@ static void interpret_interface(TALLOC_CTX *mem_ctx, const char *token, struct iface_struct *probed_ifaces, int total_probed, - struct interface **local_interfaces) + struct interface **local_interfaces, + bool enable_ipv6) { struct sockaddr_storage ss; struct sockaddr_storage ss_mask; @@ -163,7 +169,7 @@ static void interpret_interface(TALLOC_CTX *mem_ctx, for (i=0;i Date: Sat, 4 Jun 2011 07:59:54 +1000 Subject: s4-ipv6: enable IPv6 by default it now passes all tests --- source4/lib/socket/interface.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/lib/socket/interface.c') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 00550a9ed4..96cee2fbe6 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -295,7 +295,7 @@ void load_interface_list(TALLOC_CTX *mem_ctx, struct loadparm_context *lp_ctx, s int i; struct iface_struct *ifaces; int total_probed; - bool enable_ipv6 = lpcfg_parm_bool(lp_ctx, NULL, "ipv6", "enable", false); + bool enable_ipv6 = lpcfg_parm_bool(lp_ctx, NULL, "ipv6", "enable", true); *local_interfaces = NULL; @@ -485,7 +485,7 @@ const char **iface_list_wildcard(TALLOC_CTX *mem_ctx, struct loadparm_context *l if (ret == NULL) return NULL; #ifdef HAVE_IPV6 - if (lpcfg_parm_bool(lp_ctx, NULL, "ipv6", "enable", false)) { + if (lpcfg_parm_bool(lp_ctx, NULL, "ipv6", "enable", true)) { return str_list_add(ret, "::"); } #endif -- cgit From 6a6d4d8884788c1e860bda886d168301623e1ea3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 6 Jun 2011 15:18:12 +1000 Subject: s4-ipv6: fix iface_list_best_ip() for IPv6 return an interface with the same address family as the target --- source4/lib/socket/interface.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'source4/lib/socket/interface.c') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 96cee2fbe6..1bf1e4f62b 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -371,6 +371,23 @@ const char *iface_list_first_v4(struct interface *ifaces) return NULL; } +/** + return the first IPv6 interface address we have registered + **/ +static const char *iface_list_first_v6(struct interface *ifaces) +{ + struct interface *i; + +#ifdef HAVE_IPV6 + for (i=ifaces; i; i=i->next) { + if (i->ip.ss_family == AF_INET6) { + return i->ip_s; + } + } +#endif + return NULL; +} + /** check if an interface is IPv4 **/ @@ -435,7 +452,12 @@ const char *iface_list_best_ip(struct interface *ifaces, const char *dest) if (iface) { return iface->ip_s; } - return iface_list_n_ip(ifaces, 0); +#ifdef HAVE_IPV6 + if (ss.ss_family == AF_INET6) { + return iface_list_first_v6(ifaces); + } +#endif + return iface_list_first_v4(ifaces); } /** -- cgit From 3ccb72d7496aadbdf35b0aee3b2384466d9dd3b8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 7 Jun 2011 12:55:09 +1000 Subject: s4-ipv6: fixed iface_list_same_net() for IPv6 --- source4/lib/socket/interface.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'source4/lib/socket/interface.c') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 1bf1e4f62b..9cb8f5e611 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -481,9 +481,21 @@ bool iface_list_is_local(struct interface *ifaces, const char *dest) */ bool iface_list_same_net(const char *ip1, const char *ip2, const char *netmask) { - return same_net_v4(interpret_addr2(ip1), - interpret_addr2(ip2), - interpret_addr2(netmask)); + struct sockaddr_storage ip1_ss, ip2_ss, nm_ss; + + if (!interpret_string_addr(&ip1_ss, ip1, AI_NUMERICHOST)) { + return false; + } + if (!interpret_string_addr(&ip2_ss, ip2, AI_NUMERICHOST)) { + return false; + } + if (!interpret_string_addr(&nm_ss, netmask, AI_NUMERICHOST)) { + return false; + } + + return same_net((struct sockaddr *)&ip1_ss, + (struct sockaddr *)&ip2_ss, + (struct sockaddr *)&nm_ss); } /** -- cgit From 79ef434b900288f23f352dcce083c37308baef2d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 8 Jun 2011 10:41:38 +1000 Subject: s4-interface: raise the debug level for interface discovery --- source4/lib/socket/interface.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/lib/socket/interface.c') diff --git a/source4/lib/socket/interface.c b/source4/lib/socket/interface.c index 9cb8f5e611..d5b610fea7 100644 --- a/source4/lib/socket/interface.c +++ b/source4/lib/socket/interface.c @@ -116,18 +116,18 @@ static void add_interface(TALLOC_CTX *mem_ctx, const struct iface_struct *ifs, s /* keep string versions too, to avoid people tripping over the implied static in inet_ntoa() */ print_sockaddr(addr, sizeof(addr), &iface->ip); - DEBUG(2,("added interface %s ip=%s ", + DEBUG(4,("added interface %s ip=%s ", iface->name, addr)); iface->ip_s = talloc_strdup(iface, addr); print_sockaddr(addr, sizeof(addr), &iface->bcast); - DEBUG(2,("bcast=%s ", addr)); + DEBUG(4,("bcast=%s ", addr)); iface->bcast_s = talloc_strdup(iface, addr); print_sockaddr(addr, sizeof(addr), &iface->netmask); - DEBUG(2,("netmask=%s\n", addr)); + DEBUG(4,("netmask=%s\n", addr)); iface->nmask_s = talloc_strdup(iface, addr); /* -- cgit