]> 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>
Fri, 2 Apr 2021 19:14:00 +0000 (15:14 -0400)
src/include/radiusd.h
src/main/listen.c
src/main/process.c
src/main/tls_listen.c

index b737b420b372b98dceb3907b209c6ef6dcab264f..b1e3947efd3e59a385286de791e7d53f59acf2ee 100644 (file)
@@ -608,6 +608,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 8c5293b527eff54382b5731bd81f50ce2a5db9d2..13fca9a093add47640f896e84cbbfa5bc1c39cd7 100644 (file)
@@ -748,8 +748,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
@@ -3648,3 +3646,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 ae3da725a94240c39d2c1135fe5300dde7f7d825..f4d0c99e0a9b63ff3c275e81f7fa6b9eab2ec967 100644 (file)
@@ -2325,8 +2325,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 */
@@ -5241,11 +5241,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);
@@ -5415,7 +5415,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;
@@ -5444,6 +5448,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 c5f78ee03dacc7b53b11deeaece2ae6a2be20360..7bc848116c2612ae2f54cf83a08d5a44587f56ef 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