r5411: make network interface selection a bit saner
authorAndrew Tridgell <tridge@samba.org>
Wed, 16 Feb 2005 01:48:11 +0000 (01:48 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:10:43 +0000 (13:10 -0500)
- if we have no configured network interfaces, then don't start nbtd (when I add dynamic
  interface loading this will change to a delay until a network interface comes up)

- choose the best interface by netmask for torture tests that need a
  specific IP (such as the WINS test). Added iface_best_ip() for that.

- if specific interfaces are chosen in smb.conf, then keep that ordering, and
  default to the first one listed
(This used to be commit 4d08c114079ef6d1d10a96195046fe43631aefa2)

source4/lib/netif/interface.c
source4/nbt_server/nbt_server.c
source4/smbd/process_single.c
source4/smbd/service_task.c
source4/torture/nbt/register.c
source4/torture/nbt/wins.c
source4/torture/nbt/winsbench.c

index 2d90df43cf00bb973e78d299a68df0b6fd660ada..78f4456cd83bbaeac315867ce3fe98e2b02acc69 100644 (file)
@@ -94,7 +94,7 @@ static void add_interface(struct in_addr ip, struct in_addr nmask)
        iface->nmask = tov4(nmask);
        iface->bcast.addr = MKBCADDR(iface->ip.addr, iface->nmask.addr);
 
-       DLIST_ADD(local_interfaces, iface);
+       DLIST_ADD_END(local_interfaces, iface, struct interface *);
 
        DEBUG(2,("added interface ip=%s ",sys_inet_ntoa(iface->ip)));
        DEBUG(2,("bcast=%s ",sys_inet_ntoa(iface->bcast)));
@@ -339,3 +339,18 @@ const char *iface_n_netmask(int n)
        return NULL;
 }
 
+/*
+  return the local IP address that best matches a destination IP, or
+  our first interface if none match
+*/
+const char *iface_best_ip(const char *dest)
+{
+       struct interface *iface;
+       struct in_addr ip;
+       ip.s_addr = interpret_addr(dest);
+       iface = iface_find(ip, True);
+       if (iface) {
+               return sys_inet_ntoa(iface->ip);
+       }
+       return iface_n_ip(0);
+}
index d939482d2f5cadc37a6eebcb136faade24785448..2c7615216076d55f4b71e2f6e3ae1b791052fb46 100644 (file)
@@ -34,6 +34,11 @@ static void nbtd_task_init(struct task_server *task)
        struct nbtd_server *nbtsrv;
        NTSTATUS status;
 
+       if (iface_count() == 0) {
+               task_terminate(task, "nbtd: no network interfaces configured");
+               return;
+       }
+
        nbtsrv = talloc(task, struct nbtd_server);
        if (nbtsrv == NULL) {
                task_terminate(task, "nbtd: out of memory");
index 0a1e2a61031387ae133ee6e56ea225d6fe5e79fc..8d26481a951c827fc494bdb9ea917f5a1deb112f 100644 (file)
@@ -74,6 +74,7 @@ static void single_new_task(struct event_context *ev,
 /* called when a task goes down */
 static void single_terminate(struct event_context *ev, const char *reason) 
 {
+       DEBUG(2,("single_terminate: reason[%s]\n",reason));
 }
 
 static const struct model_ops single_ops = {
index 8f2255cf3ee38c3c8d7c82892aa6b6766dbd223a..68aba690197e3a8e6c581e7ef1c8a9714e433dbb 100644 (file)
@@ -32,6 +32,7 @@ void task_terminate(struct task_server *task, const char *reason)
 {
        struct event_context *event_ctx = task->event_ctx;
        const struct model_ops *model_ops = task->model_ops;
+       DEBUG(0,("task_terminate: [%s]\n", reason));
        talloc_free(task);
        model_ops->terminate(event_ctx, reason);
 }
index 40b8a587fec3f6e20d389c970b42e3282771cee0..e9b98663a59155386de81a1cd9e17bda4cdd1cc7 100644 (file)
@@ -49,7 +49,7 @@ static BOOL nbt_register_own(TALLOC_CTX *mem_ctx, struct nbt_name *name,
        NTSTATUS status;
        struct nbt_name_socket *nbtsock = nbt_name_socket_init(mem_ctx, NULL);
        BOOL ret = True;
-       const char *myaddress = iface_n_ip(0);
+       const char *myaddress = iface_best_ip(address);
 
        socket_listen(nbtsock->sock, myaddress, 0, 0, 0);
 
@@ -114,7 +114,7 @@ static BOOL nbt_refresh_own(TALLOC_CTX *mem_ctx, struct nbt_name *name,
        NTSTATUS status;
        struct nbt_name_socket *nbtsock = nbt_name_socket_init(mem_ctx, NULL);
        BOOL ret = True;
-       const char *myaddress = iface_n_ip(0);
+       const char *myaddress = iface_best_ip(address);
 
        socket_listen(nbtsock->sock, myaddress, 0, 0, 0);
 
index 3f8b361a932686ba9e95480b6a772011a65d9a93..f92a23f7324abab9be421ed27b0bf21e49b0b2bd 100644 (file)
@@ -60,7 +60,7 @@ static BOOL nbt_test_wins_name(TALLOC_CTX *mem_ctx, const char *address,
        NTSTATUS status;
        struct nbt_name_socket *nbtsock = nbt_name_socket_init(mem_ctx, NULL);
        BOOL ret = True;
-       const char *myaddress = talloc_strdup(mem_ctx, iface_n_ip(0));
+       const char *myaddress = talloc_strdup(mem_ctx, iface_best_ip(address));
 
        /* we do the listen here to ensure the WINS server receives the packets from
           the right IP */
index f6a6283dd245cc89bdc2b350b6f906d0518d0770..54f730ce84ad21673f61a430ac068a02d306d67a 100644 (file)
@@ -231,7 +231,7 @@ static BOOL bench_wins(TALLOC_CTX *mem_ctx, struct nbt_name *name, const char *a
        state->num_names = torture_entries;
        state->registered = talloc_zero_array(state, BOOL, state->num_names);
        state->wins_server = address;
-       state->my_ip = talloc_strdup(mem_ctx, iface_n_ip(0));
+       state->my_ip = talloc_strdup(mem_ctx, iface_best_ip(address));
        state->ttl = timelimit;
 
        socket_listen(nbtsock->sock, state->my_ip, 0, 0, 0);