r13505: allow servers to bind to non-broadcast interfaces. Servers now
authorAndrew Tridgell <tridge@samba.org>
Wed, 15 Feb 2006 04:18:11 +0000 (04:18 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:51:56 +0000 (13:51 -0500)
specifically ask for iface_n_bcast() and have to check if it returns
NULL, in which case it is a non-broadcast interface

source/lib/netif/interface.c
source/libcli/resolve/bcast.c
source/nbt_server/interfaces.c
source/utils/nmblookup.c

index 2a0e3642fee40ce0c790affdc65105dfbf64b352..222e63b92e8e2743757dd722cd0108abecfd2e6d 100644 (file)
@@ -29,7 +29,6 @@
 struct interface {
        struct interface *next, *prev;
        struct ipv4_addr ip;
-       struct ipv4_addr bcast;
        struct ipv4_addr nmask;
        const char *ip_s;
        const char *bcast_s;
@@ -75,16 +74,12 @@ add an interface to the linked list of interfaces
 static void add_interface(struct in_addr ip, struct in_addr nmask)
 {
        struct interface *iface;
+       struct ipv4_addr bcast;
        if (iface_find(ip, False)) {
                DEBUG(3,("not adding duplicate interface %s\n",inet_ntoa(ip)));
                return;
        }
 
-       if (nmask.s_addr == ~0) {
-               DEBUG(3,("not adding non-broadcast interface %s\n",inet_ntoa(ip)));
-               return;
-       }
-
        iface = talloc(local_interfaces, struct interface);
        if (!iface) return;
        
@@ -92,18 +87,20 @@ static void add_interface(struct in_addr ip, struct in_addr nmask)
 
        iface->ip = tov4(ip);
        iface->nmask = tov4(nmask);
-       iface->bcast.addr = MKBCADDR(iface->ip.addr, iface->nmask.addr);
+       bcast.addr = MKBCADDR(iface->ip.addr, iface->nmask.addr);
 
        /* keep string versions too, to avoid people tripping over the implied
           static in sys_inet_ntoa() */
        iface->ip_s = talloc_strdup(iface, sys_inet_ntoa(iface->ip));
-       iface->bcast_s = talloc_strdup(iface, sys_inet_ntoa(iface->bcast));
        iface->nmask_s = talloc_strdup(iface, sys_inet_ntoa(iface->nmask));
+       
+       if (nmask.s_addr != ~0) {
+               iface->bcast_s = talloc_strdup(iface, sys_inet_ntoa(bcast));
+       }
 
        DLIST_ADD_END(local_interfaces, iface, struct interface *);
 
-       DEBUG(2,("added interface ip=%s bcast=%s nmask=%s\n", 
-                iface->ip_s, iface->bcast_s, iface->nmask_s));
+       DEBUG(2,("added interface ip=%s nmask=%s\n", iface->ip_s, iface->nmask_s));
 }
 
 
@@ -149,8 +146,7 @@ static void interpret_interface(const char *token,
                }
                ip.s_addr = interpret_addr2(token).addr;
                for (i=0;i<total_probed;i++) {
-                       if (ip.s_addr == probed_ifaces[i].ip.s_addr &&
-                           probed_ifaces[i].netmask.s_addr != ~0) {
+                       if (ip.s_addr == probed_ifaces[i].ip.s_addr) {
                                add_interface(probed_ifaces[i].ip,
                                              probed_ifaces[i].netmask);
                                return;
@@ -209,15 +205,14 @@ static void load_interfaces(void)
        /* probe the kernel for interfaces */
        total_probed = get_interfaces(ifaces, MAX_INTERFACES);
 
-       /* if we don't have a interfaces line then use all broadcast capable 
-          interfaces except loopback */
+       /* if we don't have a interfaces line then use all interfaces
+          except loopback */
        if (!ptr || !*ptr || !**ptr) {
                if (total_probed <= 0) {
                        DEBUG(0,("ERROR: Could not determine network interfaces, you must use a interfaces config line\n"));
                }
                for (i=0;i<total_probed;i++) {
-                       if (ifaces[i].netmask.s_addr != ~0 &&
-                           ifaces[i].ip.s_addr != loopback_ip.addr) {
+                       if (ifaces[i].ip.s_addr != loopback_ip.addr) {
                                add_interface(ifaces[i].ip, 
                                              ifaces[i].netmask);
                        }
index c95fe945b1f6493b726cbabcbaf6ca471fcd050b..f8ea6b2b3b63ed966a66d11203a7ec7563911d47 100644 (file)
@@ -31,19 +31,22 @@ struct composite_context *resolve_name_bcast_send(struct nbt_name *name,
        int num_interfaces = iface_count();
        const char **address_list;
        struct composite_context *c;
-       int i;
+       int i, count=0;
 
        address_list = talloc_array(NULL, const char *, num_interfaces+1);
        if (address_list == NULL) return NULL;
 
        for (i=0;i<num_interfaces;i++) {
-               address_list[i] = talloc_strdup(address_list, iface_n_bcast(i));
-               if (address_list[i] == NULL) {
+               const char *bcast = iface_n_bcast(i);
+               if (bcast == NULL) continue;
+               address_list[count] = talloc_strdup(address_list, bcast);
+               if (address_list[count] == NULL) {
                        talloc_free(address_list);
                        return NULL;
                }
+               count++;
        }
-       address_list[i] = NULL;
+       address_list[count] = NULL;
 
        c = resolve_name_nbtlist_send(name, event_ctx, address_list, True, False);
        talloc_free(address_list);
index 9fdad96b55709890003d13850fdb386b771a99ba..36a65b18593acd6f82c56f08b7160ee1ebcfa768 100644 (file)
@@ -245,9 +245,15 @@ NTSTATUS nbtd_startup_interfaces(struct nbtd_server *nbtsrv)
        }
 
        for (i=0; i<num_interfaces; i++) {
-               const char *address = talloc_strdup(tmp_ctx, iface_n_ip(i));
-               const char *bcast   = talloc_strdup(tmp_ctx, iface_n_bcast(i));
-               const char *netmask = talloc_strdup(tmp_ctx, iface_n_netmask(i));
+               const char *bcast = iface_n_bcast(i);
+               const char *address, *netmask;
+
+               /* we can't assume every interface is broadcast capable */
+               if (bcast == NULL) continue;
+
+               address = talloc_strdup(tmp_ctx, iface_n_ip(i));
+               bcast   = talloc_strdup(tmp_ctx, bcast);
+               netmask = talloc_strdup(tmp_ctx, iface_n_netmask(i));
 
                status = nbtd_add_socket(nbtsrv, address, address, bcast, netmask);
                NT_STATUS_NOT_OK_RETURN(status);
index 2b1ca8d2ad1015fb252ce2b1c6f14f2d9931ec22..f7ec40d1371cdd5083226d92fb03164109ad90bf 100644 (file)
@@ -236,6 +236,7 @@ static BOOL process_one(const char *name)
                int i, num_interfaces = iface_count();
                for (i=0;i<num_interfaces;i++) {
                        const char *bcast = iface_n_bcast(i);
+                       if (bcast == NULL) continue;
                        status = do_node_query(nbtsock, bcast, node_name, node_type, True);
                        if (NT_STATUS_IS_OK(status)) break;
                }