Added "proto" to listener_find_byipaddr
authorAlan T. DeKok <aland@freeradius.org>
Tue, 3 May 2011 15:39:11 +0000 (17:39 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Tue, 3 May 2011 15:39:11 +0000 (17:39 +0200)
This allows the control socket interface to show stats for
both UDP and TCP sockets

src/include/radiusd.h
src/main/command.c
src/main/listen.c
src/main/stats.c

index 6191bdc..737e2a9 100644 (file)
@@ -686,7 +686,8 @@ RADCLIENT *client_listener_find(rad_listen_t *listener,
 RADCLIENT_LIST *listener_find_client_list(const fr_ipaddr_t *ipaddr,
                                          int port);
 #endif
-rad_listen_t *listener_find_byipaddr(const fr_ipaddr_t *ipaddr, int port);
+rad_listen_t *listener_find_byipaddr(const fr_ipaddr_t *ipaddr, int port,
+                                    int proto);
 
 /* event.c */
 int radius_event_init(CONF_SECTION *cs, int spawn_flag);
index 3b41815..dac6d10 100644 (file)
@@ -1104,7 +1104,7 @@ static rad_listen_t *get_socket(rad_listen_t *listener, int argc,
 #endif
        }
 
-       sock = listener_find_byipaddr(&ipaddr, port);
+       sock = listener_find_byipaddr(&ipaddr, port, proto);
        if (!sock) {
                cprintf(listener, "ERROR: No such listen section\n");
                return NULL;
index de6f207..af7e2a4 100644 (file)
@@ -2905,34 +2905,35 @@ RADCLIENT_LIST *listener_find_client_list(const fr_ipaddr_t *ipaddr,
 }
 #endif
 
-rad_listen_t *listener_find_byipaddr(const fr_ipaddr_t *ipaddr, int port)
+rad_listen_t *listener_find_byipaddr(const fr_ipaddr_t *ipaddr, int port, int proto)
 {
        rad_listen_t *this;
 
        for (this = mainconfig.listen; this != NULL; this = this->next) {
                listen_socket_t *sock;
 
-               /*
-                *      FIXME: For TCP, ignore the *secondary*
-                *      listeners associated with the main socket.
-                */
-               if ((this->type != RAD_LISTEN_AUTH)
-#ifdef WITH_ACCOUNTING
-                   && (this->type != RAD_LISTEN_ACCT)
-#endif
-                   ) continue;
-               
                sock = this->data;
 
-               if ((sock->my_port == port) &&
-                   (fr_ipaddr_cmp(ipaddr, &sock->my_ipaddr) == 0)) {
-                       return this;
-               }
+               if (sock->my_port != port) continue;
+               if (sock->proto != proto) continue;
+               if (fr_ipaddr_cmp(ipaddr, &sock->my_ipaddr) != 0) continue;
 
-               if ((sock->my_port == port) &&
-                   fr_inaddr_any(&sock->my_ipaddr)) {
-                       return this;
-               }
+               return this;
+       }
+
+       /*
+        *      Failed to find a specific one.  Find INADDR_ANY
+        */
+       for (this = mainconfig.listen; this != NULL; this = this->next) {
+               listen_socket_t *sock;
+
+               sock = this->data;
+
+               if (sock->my_port != port) continue;
+               if (sock->proto != proto) continue;
+               if (!fr_ipaddr_any(&sock->my_ipaddr)) continue;
+
+               return this;
        }
 
        return NULL;
index ba00dd9..a94c90e 100644 (file)
@@ -601,7 +601,8 @@ void request_stats_reply(REQUEST *request)
                ipaddr.af = AF_INET;
                ipaddr.ipaddr.ip4addr.s_addr = server_ip->vp_ipaddr;
                this = listener_find_byipaddr(&ipaddr,
-                                             server_port->vp_integer);
+                                             server_port->vp_integer,
+                                             IPPROTO_UDP);
                
                /*
                 *      Not found: don't do anything