]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Don't throw away discovered IPv4 scope_id
authorNick Porter <nick@portercomputing.co.uk>
Tue, 19 Aug 2025 16:37:12 +0000 (17:37 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Tue, 19 Aug 2025 17:14:50 +0000 (18:14 +0100)
src/lib/util/socket.c

index ae50ec832df6a520c29a56d8b2eb61fdd7fb0325..d250cee3e704ba564949a89ee428782ba607a91e 100644 (file)
@@ -231,6 +231,9 @@ int fr_socket_bind(int sockfd, char const *ifname, fr_ipaddr_t *src_ipaddr, uint
        fr_ipaddr_t                     my_ipaddr;
        struct sockaddr_storage         salocal;
        socklen_t                       salen;
+#ifdef HAVE_NET_IF_H
+       unsigned int scope_id = 0;
+#endif
 
        /*
         *      Clear the thread local error stack as we may
@@ -265,8 +268,6 @@ int fr_socket_bind(int sockfd, char const *ifname, fr_ipaddr_t *src_ipaddr, uint
         */
        if (ifname) {
 #ifdef HAVE_NET_IF_H
-               unsigned int scope_id;
-
                scope_id = if_nametoindex(ifname);
                if (!scope_id) {
                        fr_strerror_printf_push("Failed finding interface %s: %s", ifname, fr_syserror(errno));
@@ -452,6 +453,13 @@ int fr_socket_bind(int sockfd, char const *ifname, fr_ipaddr_t *src_ipaddr, uint
        }
 
        if (fr_ipaddr_from_sockaddr(&my_ipaddr, &my_port, &salocal, salen) < 0) return -1;
+
+#ifdef HAVE_NET_IF_H
+       /*
+        * fr_ipaddr_from_sockaddr clears scope_id for IPv4
+        */
+       if (ifname && scope_id && (my_ipaddr.af == AF_INET)) my_ipaddr.scope_id = scope_id;
+#endif
        *src_port = my_port;
        *src_ipaddr = my_ipaddr;