The branch main has been updated by glebius:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=d052fcbd86680c60bfddb2f74d7bc05f43c57a8f

commit d052fcbd86680c60bfddb2f74d7bc05f43c57a8f
Author:     Gleb Smirnoff <gleb...@freebsd.org>
AuthorDate: 2024-12-19 20:11:51 +0000
Commit:     Gleb Smirnoff <gleb...@freebsd.org>
CommitDate: 2024-12-19 20:11:51 +0000

    rpc: svc_tli_create() is always called with NULL socket
    
    Axe dead code that allows to provide a created socket.
---
 sys/rpc/svc.h         |  5 ++-
 sys/rpc/svc_generic.c | 88 +++++++++++++++++++--------------------------------
 2 files changed, 35 insertions(+), 58 deletions(-)

diff --git a/sys/rpc/svc.h b/sys/rpc/svc.h
index cfeb2a92c54e..43a388984c00 100644
--- a/sys/rpc/svc.h
+++ b/sys/rpc/svc.h
@@ -804,10 +804,9 @@ extern void *clnt_bck_create(struct socket *, const 
rpcprog_t, const rpcvers_t);
 /*
  * Generic TLI create routine
  */
-extern SVCXPRT *svc_tli_create(SVCPOOL *, struct socket *,
-    const struct netconfig *, const struct t_bind *, const size_t, const 
size_t);
+extern SVCXPRT *svc_tli_create(SVCPOOL *, const struct netconfig *,
+    const struct t_bind *, const size_t, const size_t);
 /*
- *      struct socket * so;             -- connection end point
  *      const struct netconfig *nconf;  -- netconfig structure for network
  *      const struct t_bind *bindaddr;  -- local bind address
  *      const size_t sendsz;             -- max sendsize
diff --git a/sys/rpc/svc_generic.c b/sys/rpc/svc_generic.c
index b2626d66490d..6fb43dc5c940 100644
--- a/sys/rpc/svc_generic.c
+++ b/sys/rpc/svc_generic.c
@@ -164,10 +164,10 @@ svc_tp_create(
                bind.addr = *taddr;
                free(taddr, M_RPC);
                bind.qlen = -1;
-               xprt = svc_tli_create(pool, NULL, nconf, &bind, 0, 0);
+               xprt = svc_tli_create(pool, nconf, &bind, 0, 0);
                free(bind.addr.buf, M_RPC);
        } else {
-               xprt = svc_tli_create(pool, NULL, nconf, NULL, 0, 0);
+               xprt = svc_tli_create(pool, nconf, NULL, 0, 0);
        }
        if (xprt == NULL) {
                return (NULL);
@@ -199,70 +199,52 @@ svc_tp_create(
 SVCXPRT *
 svc_tli_create(
        SVCPOOL *pool,
-       struct socket *so,              /* Connection end point */
        const struct netconfig *nconf,  /* Netconfig struct for nettoken */
        const struct t_bind *bindaddr,  /* Local bind address */
        size_t sendsz,                  /* Max sendsize */
        size_t recvsz)                  /* Max recvsize */
 {
+       struct socket *so;
        SVCXPRT *xprt = NULL;           /* service handle */
-       bool_t madeso = FALSE;          /* whether so opened here  */
        struct __rpc_sockinfo si;
        struct sockaddr_storage ss;
 
+       if (nconf == NULL) {
+               printf("svc_tli_create: invalid netconfig\n");
+               return (NULL);
+       }
+       so = __rpc_nconf2socket(nconf);
        if (!so) {
-               if (nconf == NULL) {
-                       printf("svc_tli_create: invalid netconfig\n");
-                       return (NULL);
-               }
-               so = __rpc_nconf2socket(nconf);
-               if (!so) {
-                       printf(
-                           "svc_tli_create: could not open connection for 
%s\n",
-                                       nconf->nc_netid);
-                       return (NULL);
-               }
-               __rpc_nconf2sockinfo(nconf, &si);
-               madeso = TRUE;
-       } else {
-               /*
-                * It is an open socket. Get the transport info.
-                */
-               if (!__rpc_socket2sockinfo(so, &si)) {
-                       printf(
-               "svc_tli_create: could not get transport information\n");
-                       return (NULL);
-               }
+               printf(
+                   "svc_tli_create: could not open connection for %s\n",
+                               nconf->nc_netid);
+               return (NULL);
        }
+       __rpc_nconf2sockinfo(nconf, &si);
 
-       /*
-        * If the socket is unbound, try to bind it.
-        */
-       if (madeso || !__rpc_sockisbound(so)) {
-               if (bindaddr == NULL) {
-                       if (bindresvport(so, NULL)) {
-                               memset(&ss, 0, sizeof ss);
-                               ss.ss_family = si.si_af;
-                               ss.ss_len = si.si_alen;
-                               if (sobind(so, (struct sockaddr *)&ss,
-                                       curthread)) {
-                                       printf(
-                       "svc_tli_create: could not bind to anonymous port\n");
-                                       goto freedata;
-                               }
-                       }
-                       solisten(so, -1, curthread);
-               } else {
-                       if (bindresvport(so,
-                               (struct sockaddr *)bindaddr->addr.buf)) {
+       if (bindaddr == NULL) {
+               if (bindresvport(so, NULL)) {
+                       memset(&ss, 0, sizeof ss);
+                       ss.ss_family = si.si_af;
+                       ss.ss_len = si.si_alen;
+                       if (sobind(so, (struct sockaddr *)&ss,
+                               curthread)) {
                                printf(
-               "svc_tli_create: could not bind to requested address\n");
+               "svc_tli_create: could not bind to anonymous port\n");
                                goto freedata;
                        }
-                       solisten(so, (int)bindaddr->qlen, curthread);
                }
-                       
+               solisten(so, -1, curthread);
+       } else {
+               if (bindresvport(so,
+                       (struct sockaddr *)bindaddr->addr.buf)) {
+                       printf(
+       "svc_tli_create: could not bind to requested address\n");
+                       goto freedata;
+               }
+               solisten(so, (int)bindaddr->qlen, curthread);
        }
+
        /*
         * call transport specific function.
         */
@@ -310,12 +292,8 @@ svc_tli_create(
        return (xprt);
 
 freedata:
-       if (madeso)
-               (void)soclose(so);
-       if (xprt) {
-               if (!madeso) /* so that svc_destroy doesnt close fd */
-                       xprt->xp_socket = NULL;
+       (void)soclose(so);
+       if (xprt)
                xprt_unregister(xprt);
-       }
        return (NULL);
 }

Reply via email to