]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:smbd: let smbd_open_socket_for_ip() return the number of successful binds
authorStefan Metzmacher <metze@samba.org>
Thu, 3 Apr 2025 12:47:13 +0000 (14:47 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 18 Apr 2025 10:17:29 +0000 (10:17 +0000)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
source3/smbd/server.c

index 17862eb82a0629d094319df4b97a612f229bb321..eb70742a9c087e30fff9b76a41d34c03d3884543 100644 (file)
@@ -1549,16 +1549,16 @@ static NTSTATUS smbd_claim_version(struct messaging_context *msg,
  Open socket communication on given ip address
 ****************************************************************************/
 
-static bool smbd_open_socket_for_ip(struct smbd_parent_context *parent,
-                                   struct tevent_context *ev_ctx,
-                                   struct messaging_context *msg_ctx,
-                                   const char *smb_ports,
-                                   const struct sockaddr_storage *ifss)
+static size_t smbd_open_socket_for_ip(struct smbd_parent_context *parent,
+                                     struct tevent_context *ev_ctx,
+                                     struct messaging_context *msg_ctx,
+                                     const char *smb_ports,
+                                     const struct sockaddr_storage *ifss)
 {
        int j;
        const char **ports;
        TALLOC_CTX *ctx;
-       bool status = true;
+       size_t num_ok = 0;
 
        ports = lp_smb_ports();
        ctx = talloc_stackframe();
@@ -1577,14 +1577,14 @@ static bool smbd_open_socket_for_ip(struct smbd_parent_context *parent,
                                          ev_ctx,
                                          ifss,
                                          port)) {
-                       status = false;
-                       goto out_free;
+                       continue;
                }
+
+               num_ok += 1;
        }
 
-out_free:
        TALLOC_FREE(ctx);
-       return status;
+       return num_ok;
 }
 
 struct smbd_addrchanged_state {
@@ -1721,6 +1721,7 @@ static void smbd_addr_changed(struct tevent_req *req)
 
        if (type == ADDRCHANGE_ADD) {
                char addrstr[INET6_ADDRSTRLEN];
+               size_t num_ok;
 
                print_sockaddr(addrstr, sizeof(addrstr), &addr.u.ss);
 
@@ -1728,11 +1729,12 @@ static void smbd_addr_changed(struct tevent_req *req)
                           "on if_index %u\n",
                           addrstr, if_index);
 
-               if (!smbd_open_socket_for_ip(state->parent,
-                                            state->ev,
-                                            state->msg_ctx,
-                                            state->ports,
-                                            &addr.u.ss)) {
+               num_ok = smbd_open_socket_for_ip(state->parent,
+                                                state->ev,
+                                                state->msg_ctx,
+                                                state->ports,
+                                                &addr.u.ss);
+               if (num_ok == 0) {
                        DBG_NOTICE("smbd: Unable to open socket on %s\n",
                                   addrstr);
                }