From 207227068c1ce313c73cfa6c54acde93dcfe1aa5 Mon Sep 17 00:00:00 2001 From: aland Date: Tue, 10 Apr 2007 13:11:01 +0000 Subject: [PATCH] Moved SNMP socket handling to listen.c, in preparation for priority queues of sockets. i.e. we may decide to completely ignore SNMP requests if there is a pending queue of authentication requests. --- src/include/radiusd.h | 1 + src/main/listen.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++----- src/main/radiusd.c | 45 +++----------------------------- 3 files changed, 70 insertions(+), 48 deletions(-) diff --git a/src/include/radiusd.h b/src/include/radiusd.h index d8386ca..55be2ef 100644 --- a/src/include/radiusd.h +++ b/src/include/radiusd.h @@ -154,6 +154,7 @@ typedef enum RAD_LISTEN_TYPE { RAD_LISTEN_ACCT, RAD_LISTEN_PROXY, RAD_LISTEN_DETAIL, + RAD_LISTEN_SNMP, RAD_LISTEN_MAX } RAD_LISTEN_TYPE; diff --git a/src/main/listen.c b/src/main/listen.c index dd845a4..2102a48 100644 --- a/src/main/listen.c +++ b/src/main/listen.c @@ -547,7 +547,7 @@ static int proxy_socket_recv(rad_listen_t *listener, } -static int client_socket_encode(rad_listen_t *listener, REQUEST *request) +static int client_socket_encode(UNUSED rad_listen_t *listener, REQUEST *request) { if (!request->reply->code) return 0; @@ -558,7 +558,7 @@ static int client_socket_encode(rad_listen_t *listener, REQUEST *request) } -static int client_socket_decode(rad_listen_t *listener, REQUEST *request) +static int client_socket_decode(UNUSED rad_listen_t *listener, REQUEST *request) { if (rad_verify(request->packet, NULL, request->secret) < 0) { return -1; @@ -567,7 +567,7 @@ static int client_socket_decode(rad_listen_t *listener, REQUEST *request) return rad_decode(request->packet, NULL, request->secret); } -static int proxy_socket_encode(rad_listen_t *listener, REQUEST *request) +static int proxy_socket_encode(UNUSED rad_listen_t *listener, REQUEST *request) { rad_encode(request->proxy, NULL, request->home_server->secret); rad_sign(request->proxy, NULL, request->home_server->secret); @@ -576,7 +576,7 @@ static int proxy_socket_encode(rad_listen_t *listener, REQUEST *request) } -static int proxy_socket_decode(rad_listen_t *listener, REQUEST *request) +static int proxy_socket_decode(UNUSED rad_listen_t *listener, REQUEST *request) { if (rad_verify(request->proxy_reply, request->proxy, request->home_server->secret) < 0) { @@ -1106,7 +1106,7 @@ static int detail_print(rad_listen_t *this, char *buffer, size_t bufsize) ((listen_detail_t *)(this->data))->detail); } -static int detail_encode(rad_listen_t *this, REQUEST *request) +static int detail_encode(UNUSED rad_listen_t *this, UNUSED REQUEST *request) { /* * We never encode responses "sent to" the detail file. @@ -1114,7 +1114,7 @@ static int detail_encode(rad_listen_t *this, REQUEST *request) return 0; } -static int detail_decode(rad_listen_t *this, REQUEST *request) +static int detail_decode(UNUSED rad_listen_t *this, UNUSED REQUEST *request) { /* * We never decode responses read from the detail file. @@ -1172,6 +1172,44 @@ static int detail_parse(const char *filename, int lineno, return 0; } + +#ifdef WITH_SNMP +static int radius_snmp_recv(rad_listen_t *listener, + UNUSED RAD_REQUEST_FUNP *pfun, + UNUSED REQUEST **prequest) +{ + if (!mainconfig.do_snmp) return 0; + + if ((rad_snmp.smux_fd >= 0) && + (rad_snmp.smux_event == SMUX_READ)) { + smux_read(); + } + + /* + * If we've got to re-connect, then do so now, + * before calling select again. + */ + if (rad_snmp.smux_event == SMUX_CONNECT) { + smux_connect(); + } + + /* + * Reset this every time, as the smux connect may have + * opened a new socket. + */ + listener->fd = rad_snmp.smux_fd; + + return 0; +} + + +static int radius_snmp_print(rad_listen_t *this, char *buffer, size_t bufsize) +{ + return snprintf(buffer, bufsize, "SMUX with OID .1.3.6.1.4.1.3317.1.3.1"); +} + +#endif + static const rad_listen_master_t master_listen[RAD_LISTEN_MAX] = { { NULL, NULL, NULL, NULL, NULL, NULL, NULL}, /* RAD_LISTEN_NONE */ @@ -1193,7 +1231,9 @@ static const rad_listen_master_t master_listen[RAD_LISTEN_MAX] = { /* detail */ { detail_parse, detail_free, detail_recv, detail_send, - detail_print, detail_encode, detail_decode } + detail_print, detail_encode, detail_decode }, + + { NULL, NULL, NULL, NULL, NULL, NULL, NULL}, /* RAD_LISTEN_SNMP */ }; @@ -1685,6 +1725,24 @@ int listen_init(const char *filename, rad_listen_t **head) } } +#ifdef WITH_SNMP + if (mainconfig.do_snmp) { + radius_snmp_init(); + + this = rad_malloc(sizeof(*this)); + memset(this, 0, sizeof(*this)); + + this->type = RAD_LISTEN_SNMP; + this->fd = rad_snmp.smux_fd; + + this->recv = radius_snmp_recv; + this->print = radius_snmp_print; + + *last = this; + last = &(this->next); + } +#endif + /* * Sanity check the configuration. */ diff --git a/src/main/radiusd.c b/src/main/radiusd.c index 4683a95..f1a3a04 100644 --- a/src/main/radiusd.c +++ b/src/main/radiusd.c @@ -312,10 +312,6 @@ int main(int argc, char *argv[]) #endif } -#ifdef WITH_SNMP - if (mainconfig.do_snmp) radius_snmp_init(); -#endif - /* * Ensure that we're using the CORRECT pid after forking, * NOT the one we started with. @@ -409,6 +405,10 @@ int main(int argc, char *argv[]) DEBUG("Listening on detail file %s", buffer); break; + case RAD_LISTEN_SNMP: + DEBUG("Listening on SNMP %s", buffer); + break; + default: break; } @@ -561,14 +561,6 @@ int main(int argc, char *argv[]) if (listener->fd > max_fd) max_fd = listener->fd; } -#ifdef WITH_SNMP - if (mainconfig.do_snmp && - (rad_snmp.smux_fd >= 0)) { - FD_SET(rad_snmp.smux_fd, &readfds); - if (rad_snmp.smux_fd > max_fd) max_fd = rad_snmp.smux_fd; - } -#endif - if (!ptv) { DEBUG2("Nothing to do. Sleeping until we see a request."); } else if (tv.tv_sec) { @@ -653,8 +645,6 @@ int main(int argc, char *argv[]) continue; } - // EVENT FIX FIXME! Nuke this! - /* * Drop the request into the thread pool, * and let the thread pool take care of @@ -665,33 +655,6 @@ int main(int argc, char *argv[]) } } /* loop over listening sockets*/ -#ifdef WITH_SNMP - if (mainconfig.do_snmp) { - /* - * After handling all authentication/accounting - * requests, THEN process any pending SMUX/SNMP - * queries. - * - * Note that the handling is done in the main server, - * which probably isn't a Good Thing. It really - * should be wrapped, and handled in a thread pool. - */ - if ((rad_snmp.smux_fd >= 0) && - FD_ISSET(rad_snmp.smux_fd, &readfds) && - (rad_snmp.smux_event == SMUX_READ)) { - smux_read(); - } - - /* - * If we've got to re-connect, then do so now, - * before calling select again. - */ - if (rad_snmp.smux_event == SMUX_CONNECT) { - smux_connect(); - } - } -#endif - ptv = &tv; radius_event_process(&ptv); -- 2.1.4