]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
start of add / delete / lookup API for reverse coa listeners
authorAlan T. DeKok <aland@freeradius.org>
Thu, 1 Apr 2021 14:43:48 +0000 (10:43 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 22 Jul 2021 13:55:20 +0000 (09:55 -0400)
src/include/radiusd.h
src/main/listen.c
src/main/process.c
src/main/tls_listen.c

index c3714fa5e31078af73cb88bb9df657f89ebaa9c0..1dbe8a5450cc8ab85dcb5a92556017003ce16ce2 100644 (file)
@@ -610,6 +610,9 @@ int proxy_tls_send(rad_listen_t *listener, REQUEST *request);
 #ifdef WITH_COA_TUNNEL
 int proxy_tls_send_reply(rad_listen_t *listener, REQUEST *request);
 int dual_tls_send_coa_request(rad_listen_t *listener, REQUEST *request);
+void listen_coa_add(rad_listen_t *listener, char const *key);
+void listen_coa_delete(rad_listen_t *listener);
+rad_listen_t *listen_coa_find(REQUEST *request, char const *key);
 #endif
 #endif
 
index 614c8a9b5edb7950df7f657b0baa29c61a02d3cb..cbe45c67fe969811ff443ed3fa1a19650df1f248 100644 (file)
@@ -785,8 +785,6 @@ static int dual_tcp_accept(rad_listen_t *listener)
                this->proxy_encode = master_listen[RAD_LISTEN_PROXY].encode;
                this->proxy_decode = master_listen[RAD_LISTEN_PROXY].decode;
 
-//             listener_store_byaddr(this, &sock->other_ipaddr);
-
                /*
                 *      Automatically create a home server for this
                 *      client.  There MAY be one already one for that
@@ -3685,3 +3683,52 @@ rad_listen_t *listener_find_byipaddr(fr_ipaddr_t const *ipaddr, uint16_t port, i
 
        return NULL;
 }
+
+#ifdef WITH_COA_TUNNEL
+/*
+ *     Adds a listener to the hash of listeners, based on key.
+ */
+void listen_coa_add(rad_listen_t *this, char const *key)
+{
+       rad_assert(this->send_coa);
+       rad_assert(this->parent);
+
+       /*
+        *      We can use "this" as a context, because it's created
+        *      in the NULL context, so it's thread-safe.
+        */
+       this->key = talloc_strdup(this, key);
+
+       /*
+        *      Do more things here.
+        */
+}
+
+/*
+ *     Delete a listener from the hash of listeners.
+ *
+ *     Note that all requests using this MUST be removed from the
+ *     listener, and MUST NOT point to the listener any more.
+ */
+void listen_coa_delete(rad_listen_t *this)
+{
+       rad_assert(this->send_coa);
+       rad_assert(this->parent);
+
+
+       /*
+        *      Do more things here.
+        */
+}
+
+/*
+ *     Find an active listener by key.
+ */
+rad_listen_t *listen_coa_find(UNUSED REQUEST *request, UNUSED char const *key)
+{
+       /*
+        *      Do more things here.
+        */
+       return NULL;
+}
+#endif
index c0ac7a8eb8b7da608080b2fcff565bf33fd35e3d..c528e585619a27e9b070c1784d0113c1ba7e44ef 100644 (file)
@@ -2330,8 +2330,8 @@ static int insert_into_proxy_hash(REQUEST *request)
 
                RDEBUG3("proxy: Trying to allocate ID (%d/2)", tries);
                success = fr_packet_list_id_alloc(proxy_list,
-                                               request->home_server->proto,
-                                               &request->proxy, &proxy_listener);
+                                                 request->home_server->proto,
+                                                 &request->proxy, &proxy_listener);
                if (success) break;
 
                if (tries > 0) continue; /* try opening new socket only once */
@@ -5256,11 +5256,11 @@ static void event_new_fd(rad_listen_t *this)
                         */
                        if (this->send_coa && this->parent) {
                                PTHREAD_MUTEX_LOCK(&proxy_mutex);
-                               if(!fr_packet_list_socket_add(proxy_list, this->fd,
-                                                             sock->proto,
-                                                             &sock->other_ipaddr, sock->other_port,
-                                                             this)) {
-                                       ERROR("Failed adding proxy socket");
+                               if (!fr_packet_list_socket_add(proxy_list, this->fd,
+                                                              sock->proto,
+                                                              &sock->other_ipaddr, sock->other_port,
+                                                              this)) {
+                                       ERROR("Failed adding coa proxy socket");
                                        fr_exit_now(1);
                                }
                                PTHREAD_MUTEX_UNLOCK(&proxy_mutex);
@@ -5430,7 +5430,11 @@ static void event_new_fd(rad_listen_t *this)
                 *      to stop using it.  And then remove it from the
                 *      list of outgoing sockets.
                 */
-               if (this->type == RAD_LISTEN_PROXY) {
+               if ((this->type == RAD_LISTEN_PROXY)
+#ifdef WITH_COA_TUNNEL
+                   || (this->send_coa && this->parent)
+#endif
+                       ) {
                        home_server_t *home;
 
                        home = sock->home;
@@ -5459,6 +5463,18 @@ static void event_new_fd(rad_listen_t *this)
                         *      EOL all requests using this socket.
                         */
                        rbtree_walk(pl, RBTREE_DELETE_ORDER, eol_listener, this);
+
+#ifdef WITH_COA_TUNNEL
+                       /*
+                        *      Delete the listener from the set of
+                        *      listeners by key.  This is done early,
+                        *      so that it won't be used while the
+                        *      cleanup timers are being run.
+                        */
+                       if (this->key) {
+                               listen_coa_delete(this);
+                       }
+#endif
                }
 
                /*
index 05e05f87fba7cb796973fa58a44a49a29eea44c9..e6d491bde35aadfa51cc4aa9b73fe708dc9740a9 100644 (file)
@@ -588,7 +588,7 @@ int dual_tls_send(rad_listen_t *listener, REQUEST *request)
                vp = fr_pair_find_by_num(request->config, PW_TCP_SESSION_KEY, 0, TAG_ANY);
                if (vp) {
                        RDEBUG("Adding send CoA listener with key %s", vp->vp_strvalue);
-//                     listener_store_bykey(request->listener, vp->vp_strvalue);
+                       listen_coa_add(request->listener, vp->vp_strvalue);
                }
        }
 #endif