From: Alan T. DeKok Date: Thu, 1 Apr 2021 14:43:48 +0000 (-0400) Subject: start of add / delete / lookup API for reverse coa listeners X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36f4f35072a5631503744ffc306e0161d8f67748;p=thirdparty%2Ffreeradius-server.git start of add / delete / lookup API for reverse coa listeners --- diff --git a/src/include/radiusd.h b/src/include/radiusd.h index b737b420b3..b1e3947efd 100644 --- a/src/include/radiusd.h +++ b/src/include/radiusd.h @@ -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 diff --git a/src/main/listen.c b/src/main/listen.c index 8c5293b527..13fca9a093 100644 --- a/src/main/listen.c +++ b/src/main/listen.c @@ -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 diff --git a/src/main/process.c b/src/main/process.c index ae3da725a9..f4d0c99e0a 100644 --- a/src/main/process.c +++ b/src/main/process.c @@ -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 } /* diff --git a/src/main/tls_listen.c b/src/main/tls_listen.c index c5f78ee03d..7bc848116c 100644 --- a/src/main/tls_listen.c +++ b/src/main/tls_listen.c @@ -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