2 * listen.c Handle socket stuff
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 * Copyright 2005,2006 The FreeRADIUS server project
21 * Copyright 2005 Alan DeKok <aland@ox.org>
24 #include <freeradius-devel/ident.h>
27 #include <freeradius-devel/radiusd.h>
28 #include <freeradius-devel/modules.h>
29 #include <freeradius-devel/rad_assert.h>
30 #include <freeradius-devel/vqp.h>
31 #include <freeradius-devel/dhcp.h>
33 #include <freeradius-devel/vmps.h>
34 #include <freeradius-devel/detail.h>
37 #include <freeradius-devel/udpfromto.h>
40 #ifdef HAVE_SYS_RESOURCE_H
41 #include <sys/resource.h>
54 * We'll use this below.
56 typedef int (*rad_listen_parse_t)(CONF_SECTION *, rad_listen_t *);
57 typedef void (*rad_listen_free_t)(rad_listen_t *);
59 typedef struct rad_listen_master_t {
60 rad_listen_parse_t parse;
61 rad_listen_free_t free;
62 rad_listen_recv_t recv;
63 rad_listen_send_t send;
64 rad_listen_print_t print;
65 rad_listen_encode_t encode;
66 rad_listen_decode_t decode;
67 } rad_listen_master_t;
69 typedef struct listen_socket_t {
75 #ifdef SO_BINDTODEVICE
76 const char *interface;
78 RADCLIENT_LIST *clients;
81 static rad_listen_t *listen_alloc(RAD_LISTEN_TYPE type);
84 * Find a per-socket client.
86 RADCLIENT *client_listener_find(const rad_listen_t *listener,
87 const fr_ipaddr_t *ipaddr, int src_port)
89 #ifdef WITH_DYNAMIC_CLIENTS
96 RADCLIENT_LIST *clients;
98 rad_assert(listener != NULL);
99 rad_assert(ipaddr != NULL);
101 clients = ((listen_socket_t *)listener->data)->clients;
104 * This HAS to have been initialized previously.
106 rad_assert(clients != NULL);
108 client = client_find(clients, ipaddr);
110 static time_t last_printed = 0;
111 char name[256], buffer[128];
113 #ifdef WITH_DYNAMIC_CLIENTS
114 unknown: /* used only for dynamic clients */
118 * DoS attack quenching, but only in debug mode.
119 * If they're running in debug mode, show them
122 if (debug_flag == 0) {
124 if (last_printed == now) return NULL;
129 listener->print(listener, name, sizeof(name));
131 radlog(L_ERR, "Ignoring request to %s from unknown client %s port %d",
132 name, inet_ntop(ipaddr->af, &ipaddr->ipaddr,
133 buffer, sizeof(buffer)),
138 #ifndef WITH_DYNAMIC_CLIENTS
139 return client; /* return the found client. */
143 * No server defined, and it's not dynamic. Return it.
145 if (!client->client_server && !client->dynamic) return client;
150 * It's a dynamically generated client, check it.
152 if (client->dynamic && (src_port != 0)) {
154 * Lives forever. Return it.
156 if (client->lifetime == 0) return client;
159 * Rate-limit the deletion of known clients.
160 * This makes them last a little longer, but
161 * prevents the server from melting down if (say)
162 * 10k clients all expire at once.
164 if (now == client->last_new_client) return client;
167 * It's not dead yet. Return it.
169 if ((client->created + client->lifetime) > now) return client;
172 * This really puts them onto a queue for later
175 client_delete(clients, client);
178 * Go find the enclosing network again.
180 client = client_find(clients, ipaddr);
185 if (!client) goto unknown;
186 if (!client->client_server) goto unknown;
189 * At this point, 'client' is the enclosing
190 * network that configures where dynamic clients
193 rad_assert(client->dynamic == 0);
196 * The IP is unknown, so we've found an enclosing
197 * network. Enable DoS protection. We only
198 * allow one new client per second. Known
199 * clients aren't subject to this restriction.
201 if (now == client->last_new_client) goto unknown;
204 client->last_new_client = now;
206 request = request_alloc();
207 if (!request) goto unknown;
209 request->listener = listener;
210 request->client = client;
211 request->packet = rad_recv(listener->fd, 0x02); /* MSG_PEEK */
212 if (!request->packet) { /* badly formed, etc */
213 request_free(&request);
216 request->reply = rad_alloc_reply(request->packet);
217 if (!request->reply) {
218 request_free(&request);
221 request->packet->timestamp = request->timestamp;
223 request->priority = listener->type;
224 request->server = client->client_server;
225 request->root = &mainconfig;
228 * Run a fake request through the given virtual server.
229 * Look for FreeRADIUS-Client-IP-Address
230 * FreeRADIUS-Client-Secret
233 * and create the RADCLIENT structure from that.
235 DEBUG("server %s {", request->server);
237 rcode = module_authorize(0, request);
239 DEBUG("} # server %s", request->server);
241 if (rcode != RLM_MODULE_OK) {
242 request_free(&request);
247 * If the client was updated by rlm_dynamic_clients,
248 * don't create the client from attribute-value pairs.
250 if (request->client == client) {
251 created = client_create(clients, request);
253 created = request->client;
256 * This frees the client if it isn't valid.
258 if (!client_validate(clients, client, created)) goto unknown;
260 request_free(&request);
262 if (!created) goto unknown;
268 static int listen_bind(rad_listen_t *this);
272 * Process and reply to a server-status request.
273 * Like rad_authenticate and rad_accounting this should
274 * live in it's own file but it's so small we don't bother.
276 static int rad_status_server(REQUEST *request)
278 int rcode = RLM_MODULE_OK;
281 switch (request->listener->type) {
283 case RAD_LISTEN_NONE:
285 case RAD_LISTEN_AUTH:
286 dval = dict_valbyname(PW_AUTZ_TYPE, "Status-Server");
288 rcode = module_authorize(dval->value, request);
290 rcode = RLM_MODULE_OK;
295 case RLM_MODULE_UPDATED:
296 request->reply->code = PW_AUTHENTICATION_ACK;
299 case RLM_MODULE_FAIL:
300 case RLM_MODULE_HANDLED:
301 request->reply->code = 0; /* don't reply */
305 case RLM_MODULE_REJECT:
306 request->reply->code = PW_AUTHENTICATION_REJECT;
311 #ifdef WITH_ACCOUNTING
312 case RAD_LISTEN_ACCT:
313 dval = dict_valbyname(PW_ACCT_TYPE, "Status-Server");
315 rcode = module_accounting(dval->value, request);
317 rcode = RLM_MODULE_OK;
322 case RLM_MODULE_UPDATED:
323 request->reply->code = PW_ACCOUNTING_RESPONSE;
327 request->reply->code = 0; /* don't reply */
335 * This is a vendor extension. Suggested by Glen
336 * Zorn in IETF 72, and rejected by the rest of
337 * the WG. We like it, so it goes in here.
340 dval = dict_valbyname(PW_RECV_COA_TYPE, "Status-Server");
342 rcode = module_recv_coa(dval->value, request);
344 rcode = RLM_MODULE_OK;
349 case RLM_MODULE_UPDATED:
350 request->reply->code = PW_COA_ACK;
354 request->reply->code = 0; /* don't reply */
366 * Full statistics are available only on a statistics
369 if (request->listener->type == RAD_LISTEN_NONE) {
370 request_stats_reply(request);
378 static int socket_print(rad_listen_t *this, char *buffer, size_t bufsize)
381 listen_socket_t *sock = this->data;
384 switch (this->type) {
386 case RAD_LISTEN_NONE: /* what a hack... */
391 case RAD_LISTEN_AUTH:
392 name = "authentication";
395 #ifdef WITH_ACCOUNTING
396 case RAD_LISTEN_ACCT:
402 case RAD_LISTEN_PROXY:
414 case RAD_LISTEN_DHCP:
430 #define FORWARD len = strlen(buffer); if (len >= (bufsize + 1)) return 0;buffer += len;bufsize -= len
431 #define ADDSTRING(_x) strlcpy(buffer, _x, bufsize);FORWARD
435 #ifdef SO_BINDTODEVICE
436 if (sock->interface) {
437 ADDSTRING(" interface ");
438 ADDSTRING(sock->interface);
442 ADDSTRING(" address ");
444 if ((sock->ipaddr.af == AF_INET) &&
445 (sock->ipaddr.ipaddr.ip4addr.s_addr == htonl(INADDR_ANY))) {
446 strlcpy(buffer, "*", bufsize);
448 ip_ntoh(&sock->ipaddr, buffer, bufsize);
453 snprintf(buffer, bufsize, "%d", sock->port);
457 ADDSTRING(" as server ");
458 ADDSTRING(this->server);
469 * Parse an authentication or accounting socket.
471 static int common_socket_parse(CONF_SECTION *cs, rad_listen_t *this)
476 listen_socket_t *sock = this->data;
477 char *section_name = NULL;
478 CONF_SECTION *client_cs, *parentcs;
483 ipaddr.ipaddr.ip4addr.s_addr = htonl(INADDR_NONE);
484 rcode = cf_item_parse(cs, "ipaddr", PW_TYPE_IPADDR,
485 &ipaddr.ipaddr.ip4addr, NULL);
486 if (rcode < 0) return -1;
488 if (rcode == 0) { /* successfully parsed IPv4 */
491 } else { /* maybe IPv6? */
492 rcode = cf_item_parse(cs, "ipv6addr", PW_TYPE_IPV6ADDR,
493 &ipaddr.ipaddr.ip6addr, NULL);
494 if (rcode < 0) return -1;
497 cf_log_err(cf_sectiontoitem(cs),
498 "No address specified in listen section");
501 ipaddr.af = AF_INET6;
504 rcode = cf_item_parse(cs, "port", PW_TYPE_INTEGER,
506 if (rcode < 0) return -1;
508 if ((listen_port < 0) || (listen_port > 65535)) {
509 cf_log_err(cf_sectiontoitem(cs),
510 "Invalid value for \"port\"");
514 sock->ipaddr = ipaddr;
515 sock->port = listen_port;
518 * If we can bind to interfaces, do so,
521 if (cf_pair_find(cs, "interface")) {
522 #ifndef SO_BINDTODEVICE
523 cf_log_err(cf_sectiontoitem(cs),
524 "System does not support binding to interfaces. Delete this line from the configuration file.");
528 CONF_PAIR *cp = cf_pair_find(cs, "interface");
530 rad_assert(cp != NULL);
531 value = cf_pair_value(cp);
533 cf_log_err(cf_sectiontoitem(cs),
534 "No interface name given");
537 sock->interface = value;
542 * And bind it to the port.
544 if (listen_bind(this) < 0) {
546 cf_log_err(cf_sectiontoitem(cs),
547 "Error binding to port for %s port %d",
548 ip_ntoh(&sock->ipaddr, buffer, sizeof(buffer)),
555 * Proxy sockets don't have clients.
557 if (this->type == RAD_LISTEN_PROXY) return 0;
561 * The more specific configurations are preferred to more
565 parentcs = cf_top_section(cs);
566 rcode = cf_item_parse(cs, "clients", PW_TYPE_STRING_PTR,
567 §ion_name, NULL);
568 if (rcode < 0) return -1; /* bad string */
571 * Explicit list given: use it.
573 client_cs = cf_section_sub_find_name2(parentcs,
577 client_cs = cf_section_find(section_name);
580 cf_log_err(cf_sectiontoitem(cs),
581 "Failed to find clients %s {...}",
587 } /* else there was no "clients = " entry. */
590 CONF_SECTION *server_cs;
592 server_cs = cf_section_sub_find_name2(parentcs,
596 * Found a "server foo" section. If there are clients
600 (cf_section_sub_find(server_cs, "client") != NULL)) {
601 client_cs = server_cs;
606 * Still nothing. Look for global clients.
608 if (!client_cs) client_cs = parentcs;
610 sock->clients = clients_parse_section(client_cs);
611 if (!sock->clients) {
612 cf_log_err(cf_sectiontoitem(cs),
613 "Failed to load clients for this listen section");
621 * Send an authentication response packet
623 static int auth_socket_send(rad_listen_t *listener, REQUEST *request)
625 rad_assert(request->listener == listener);
626 rad_assert(listener->send == auth_socket_send);
628 return rad_send(request->reply, request->packet,
629 request->client->secret);
633 #ifdef WITH_ACCOUNTING
635 * Send an accounting response packet (or not)
637 static int acct_socket_send(rad_listen_t *listener, REQUEST *request)
639 rad_assert(request->listener == listener);
640 rad_assert(listener->send == acct_socket_send);
643 * Accounting reject's are silently dropped.
645 * We do it here to avoid polluting the rest of the
646 * code with this knowledge
648 if (request->reply->code == 0) return 0;
650 return rad_send(request->reply, request->packet,
651 request->client->secret);
657 * Send a packet to a home server.
659 * FIXME: have different code for proxy auth & acct!
661 static int proxy_socket_send(rad_listen_t *listener, REQUEST *request)
663 listen_socket_t *sock = listener->data;
665 rad_assert(request->proxy_listener == listener);
666 rad_assert(listener->send == proxy_socket_send);
668 request->proxy->src_ipaddr = sock->ipaddr;
669 request->proxy->src_port = sock->port;
671 return rad_send(request->proxy, request->packet,
672 request->home_server->secret);
678 * Check if an incoming request is "ok"
680 * It takes packets, not requests. It sees if the packet looks
681 * OK. If so, it does a number of sanity checks on it.
683 static int stats_socket_recv(rad_listen_t *listener,
684 RAD_REQUEST_FUNP *pfun, REQUEST **prequest)
688 RADIUS_PACKET *packet;
690 fr_ipaddr_t src_ipaddr;
692 rcode = rad_recv_header(listener->fd, &src_ipaddr, &src_port, &code);
693 if (rcode < 0) return 0;
695 RAD_STATS_TYPE_INC(listener, total_requests);
697 if (rcode < 20) { /* AUTH_HDR_LEN */
698 RAD_STATS_TYPE_INC(listener, total_malformed_requests);
702 if ((client = client_listener_find(listener,
703 &src_ipaddr, src_port)) == NULL) {
704 rad_recv_discard(listener->fd);
705 RAD_STATS_TYPE_INC(listener, total_invalid_requests);
710 * We only understand Status-Server on this socket.
712 if (code != PW_STATUS_SERVER) {
713 DEBUG("Ignoring packet code %d sent to Status-Server port",
715 rad_recv_discard(listener->fd);
716 RAD_STATS_TYPE_INC(listener, total_unknown_types);
717 RAD_STATS_CLIENT_INC(listener, client, total_unknown_types);
722 * Now that we've sanity checked everything, receive the
725 packet = rad_recv(listener->fd, 1); /* require message authenticator */
727 RAD_STATS_TYPE_INC(listener, total_malformed_requests);
728 DEBUG("%s", fr_strerror());
732 if (!received_request(listener, packet, prequest, client)) {
733 RAD_STATS_TYPE_INC(listener, total_packets_dropped);
734 RAD_STATS_CLIENT_INC(listener, client, total_packets_dropped);
739 *pfun = rad_status_server;
746 * Check if an incoming request is "ok"
748 * It takes packets, not requests. It sees if the packet looks
749 * OK. If so, it does a number of sanity checks on it.
751 static int auth_socket_recv(rad_listen_t *listener,
752 RAD_REQUEST_FUNP *pfun, REQUEST **prequest)
756 RADIUS_PACKET *packet;
757 RAD_REQUEST_FUNP fun = NULL;
759 fr_ipaddr_t src_ipaddr;
761 rcode = rad_recv_header(listener->fd, &src_ipaddr, &src_port, &code);
762 if (rcode < 0) return 0;
764 RAD_STATS_TYPE_INC(listener, total_requests);
766 if (rcode < 20) { /* AUTH_HDR_LEN */
767 RAD_STATS_TYPE_INC(listener, total_malformed_requests);
771 if ((client = client_listener_find(listener,
772 &src_ipaddr, src_port)) == NULL) {
773 rad_recv_discard(listener->fd);
774 RAD_STATS_TYPE_INC(listener, total_invalid_requests);
779 * Some sanity checks, based on the packet code.
782 case PW_AUTHENTICATION_REQUEST:
783 RAD_STATS_CLIENT_INC(listener, client, total_requests);
784 fun = rad_authenticate;
787 case PW_STATUS_SERVER:
788 if (!mainconfig.status_server) {
789 rad_recv_discard(listener->fd);
790 RAD_STATS_TYPE_INC(listener, total_packets_dropped);
791 RAD_STATS_CLIENT_INC(listener, client, total_packets_dropped);
792 DEBUG("WARNING: Ignoring Status-Server request due to security configuration");
795 fun = rad_status_server;
799 rad_recv_discard(listener->fd);
800 RAD_STATS_INC(radius_auth_stats.total_unknown_types);
801 RAD_STATS_CLIENT_INC(listener, client, total_unknown_types);
803 DEBUG("Invalid packet code %d sent to authentication port from client %s port %d : IGNORED",
804 code, client->shortname, src_port);
807 } /* switch over packet types */
810 * Now that we've sanity checked everything, receive the
813 packet = rad_recv(listener->fd, client->message_authenticator);
815 RAD_STATS_TYPE_INC(listener, total_malformed_requests);
816 DEBUG("%s", fr_strerror());
820 if (!received_request(listener, packet, prequest, client)) {
821 RAD_STATS_TYPE_INC(listener, total_packets_dropped);
822 RAD_STATS_CLIENT_INC(listener, client, total_packets_dropped);
832 #ifdef WITH_ACCOUNTING
834 * Receive packets from an accounting socket
836 static int acct_socket_recv(rad_listen_t *listener,
837 RAD_REQUEST_FUNP *pfun, REQUEST **prequest)
841 RADIUS_PACKET *packet;
842 RAD_REQUEST_FUNP fun = NULL;
844 fr_ipaddr_t src_ipaddr;
846 rcode = rad_recv_header(listener->fd, &src_ipaddr, &src_port, &code);
847 if (rcode < 0) return 0;
849 RAD_STATS_TYPE_INC(listener, total_requests);
851 if (rcode < 20) { /* AUTH_HDR_LEN */
852 RAD_STATS_TYPE_INC(listener, total_malformed_requests);
856 if ((client = client_listener_find(listener,
857 &src_ipaddr, src_port)) == NULL) {
858 rad_recv_discard(listener->fd);
859 RAD_STATS_TYPE_INC(listener, total_invalid_requests);
864 * Some sanity checks, based on the packet code.
867 case PW_ACCOUNTING_REQUEST:
868 RAD_STATS_CLIENT_INC(listener, client, total_requests);
869 fun = rad_accounting;
872 case PW_STATUS_SERVER:
873 if (!mainconfig.status_server) {
874 rad_recv_discard(listener->fd);
875 RAD_STATS_TYPE_INC(listener, total_packets_dropped);
876 RAD_STATS_CLIENT_INC(listener, client, total_unknown_types);
878 DEBUG("WARNING: Ignoring Status-Server request due to security configuration");
881 fun = rad_status_server;
885 rad_recv_discard(listener->fd);
886 RAD_STATS_TYPE_INC(listener, total_unknown_types);
887 RAD_STATS_CLIENT_INC(listener, client, total_unknown_types);
889 DEBUG("Invalid packet code %d sent to a accounting port from client %s port %d : IGNORED",
890 code, client->shortname, src_port);
892 } /* switch over packet types */
895 * Now that we've sanity checked everything, receive the
898 packet = rad_recv(listener->fd, 0);
900 RAD_STATS_TYPE_INC(listener, total_malformed_requests);
901 radlog(L_ERR, "%s", fr_strerror());
906 * There can be no duplicate accounting packets.
908 if (!received_request(listener, packet, prequest, client)) {
909 RAD_STATS_TYPE_INC(listener, total_packets_dropped);
910 RAD_STATS_CLIENT_INC(listener, client, total_packets_dropped);
923 * For now, all CoA requests are *only* originated, and not
924 * proxied. So all of the necessary work is done in the
925 * post-proxy section, which is automatically handled by event.c.
926 * As a result, we don't have to do anything here.
928 static int rad_coa_reply(REQUEST *request)
933 * Inform the user about RFC requirements.
935 s1 = pairfind(request->proxy->vps, PW_STATE);
937 s2 = pairfind(request->proxy_reply->vps, PW_STATE);
940 DEBUG("WARNING: Client was sent State in CoA, and did not respond with State.");
942 } else if ((s1->length != s2->length) ||
943 (memcmp(s1->vp_octets, s2->vp_octets,
945 DEBUG("WARNING: Client was sent State in CoA, and did not respond with the same State.");
949 return RLM_MODULE_OK;
953 * Receive a CoA packet.
955 static int rad_coa_recv(REQUEST *request)
957 int rcode = RLM_MODULE_OK;
962 * Get the correct response
964 switch (request->packet->code) {
970 case PW_DISCONNECT_REQUEST:
971 ack = PW_DISCONNECT_ACK;
972 nak = PW_DISCONNECT_NAK;
975 default: /* shouldn't happen */
976 return RLM_MODULE_FAIL;
980 #define WAS_PROXIED (request->proxy)
982 #define WAS_PROXIED (0)
987 * RFC 5176 Section 3.3. If we have a CoA-Request
988 * with Service-Type = Authorize-Only, it MUST
989 * have a State attribute in it.
991 vp = pairfind(request->packet->vps, PW_SERVICE_TYPE);
992 if (request->packet->code == PW_COA_REQUEST) {
993 if (vp && (vp->vp_integer == 17)) {
994 vp = pairfind(request->packet->vps, PW_STATE);
995 if (!vp || (vp->length == 0)) {
996 RDEBUG("ERROR: CoA-Request with Service-Type = Authorize-Only MUST contain a State attribute");
997 request->reply->code = PW_COA_NAK;
998 return RLM_MODULE_FAIL;
1003 * RFC 5176, Section 3.2.
1005 RDEBUG("ERROR: Disconnect-Request MUST NOT contain a Service-Type attribute");
1006 request->reply->code = PW_DISCONNECT_NAK;
1007 return RLM_MODULE_FAIL;
1010 rcode = module_recv_coa(0, request);
1012 case RLM_MODULE_FAIL:
1013 case RLM_MODULE_INVALID:
1014 case RLM_MODULE_REJECT:
1015 case RLM_MODULE_USERLOCK:
1017 request->reply->code = nak;
1020 case RLM_MODULE_HANDLED:
1023 case RLM_MODULE_NOOP:
1024 case RLM_MODULE_NOTFOUND:
1026 case RLM_MODULE_UPDATED:
1027 request->reply->code = ack;
1032 * Start the reply code with the proxy reply
1035 request->reply->code = request->proxy_reply->code;
1039 * Copy State from the request to the reply.
1040 * See RFC 5176 Section 3.3.
1042 vp = paircopy2(request->packet->vps, PW_STATE);
1043 if (vp) pairadd(&request->reply->vps, vp);
1046 * We may want to over-ride the reply.
1048 rcode = module_send_coa(0, request);
1051 * We need to send CoA-NAK back if Service-Type
1052 * is Authorize-Only. Rely on the user's policy
1053 * to do that. We're not a real NAS, so this
1054 * restriction doesn't (ahem) apply to us.
1056 case RLM_MODULE_FAIL:
1057 case RLM_MODULE_INVALID:
1058 case RLM_MODULE_REJECT:
1059 case RLM_MODULE_USERLOCK:
1062 * Over-ride an ACK with a NAK
1064 request->reply->code = nak;
1067 case RLM_MODULE_HANDLED:
1070 case RLM_MODULE_NOOP:
1071 case RLM_MODULE_NOTFOUND:
1073 case RLM_MODULE_UPDATED:
1075 * Do NOT over-ride a previously set value.
1076 * Otherwise an "ok" here will re-write a
1079 if (request->reply->code == 0) {
1080 request->reply->code = ack;
1086 return RLM_MODULE_OK;
1091 * Check if an incoming request is "ok"
1093 * It takes packets, not requests. It sees if the packet looks
1094 * OK. If so, it does a number of sanity checks on it.
1096 static int coa_socket_recv(rad_listen_t *listener,
1097 RAD_REQUEST_FUNP *pfun, REQUEST **prequest)
1101 RADIUS_PACKET *packet;
1102 RAD_REQUEST_FUNP fun = NULL;
1105 fr_ipaddr_t src_ipaddr;
1107 rcode = rad_recv_header(listener->fd, &src_ipaddr, &src_port, &code);
1108 if (rcode < 0) return 0;
1110 RAD_STATS_TYPE_INC(listener, total_requests);
1112 if (rcode < 20) { /* AUTH_HDR_LEN */
1113 RAD_STATS_TYPE_INC(listener, total_malformed_requests);
1117 if ((client = client_listener_find(listener,
1118 &src_ipaddr, src_port)) == NULL) {
1119 rad_recv_discard(listener->fd);
1120 RAD_STATS_TYPE_INC(listener, total_invalid_requests);
1122 if (debug_flag > 0) {
1125 listener->print(listener, name, sizeof(name));
1128 * This is debugging rather than logging, so that
1129 * DoS attacks don't affect us.
1131 DEBUG("Ignoring request to %s from unknown client %s port %d",
1133 inet_ntop(src_ipaddr.af, &src_ipaddr.ipaddr,
1134 buffer, sizeof(buffer)), src_port);
1141 * Some sanity checks, based on the packet code.
1144 case PW_COA_REQUEST:
1145 case PW_DISCONNECT_REQUEST:
1150 rad_recv_discard(listener->fd);
1151 DEBUG("Invalid packet code %d sent to coa port from client %s port %d : IGNORED",
1152 code, client->shortname, src_port);
1155 } /* switch over packet types */
1158 * Now that we've sanity checked everything, receive the
1161 packet = rad_recv(listener->fd, client->message_authenticator);
1163 RAD_STATS_TYPE_INC(listener, total_malformed_requests);
1164 DEBUG("%s", fr_strerror());
1168 if (!received_request(listener, packet, prequest, client)) {
1180 * Recieve packets from a proxy socket.
1182 static int proxy_socket_recv(rad_listen_t *listener,
1183 RAD_REQUEST_FUNP *pfun, REQUEST **prequest)
1186 RADIUS_PACKET *packet;
1187 RAD_REQUEST_FUNP fun = NULL;
1190 packet = rad_recv(listener->fd, 0);
1192 radlog(L_ERR, "%s", fr_strerror());
1197 * FIXME: Client MIB updates?
1199 switch(packet->code) {
1200 case PW_AUTHENTICATION_ACK:
1201 case PW_ACCESS_CHALLENGE:
1202 case PW_AUTHENTICATION_REJECT:
1203 fun = rad_authenticate;
1206 #ifdef WITH_ACCOUNTING
1207 case PW_ACCOUNTING_RESPONSE:
1208 fun = rad_accounting;
1213 case PW_DISCONNECT_ACK:
1214 case PW_DISCONNECT_NAK:
1217 fun = rad_coa_reply;
1223 * FIXME: Update MIB for packet types?
1225 radlog(L_ERR, "Invalid packet code %d sent to a proxy port "
1226 "from home server %s port %d - ID %d : IGNORED",
1228 ip_ntoh(&packet->src_ipaddr, buffer, sizeof(buffer)),
1229 packet->src_port, packet->id);
1234 request = received_proxy_response(packet);
1242 * Distinguish proxied CoA requests from ones we
1245 if ((fun == rad_coa_reply) &&
1246 (request->packet->code == request->proxy->code)) {
1251 rad_assert(fun != NULL);
1253 *prequest = request;
1260 static int client_socket_encode(UNUSED rad_listen_t *listener, REQUEST *request)
1262 if (!request->reply->code) return 0;
1264 rad_encode(request->reply, request->packet,
1265 request->client->secret);
1266 rad_sign(request->reply, request->packet,
1267 request->client->secret);
1273 static int client_socket_decode(UNUSED rad_listen_t *listener, REQUEST *request)
1275 if (rad_verify(request->packet, NULL,
1276 request->client->secret) < 0) {
1280 return rad_decode(request->packet, NULL,
1281 request->client->secret);
1285 static int proxy_socket_encode(UNUSED rad_listen_t *listener, REQUEST *request)
1287 rad_encode(request->proxy, NULL, request->home_server->secret);
1288 rad_sign(request->proxy, NULL, request->home_server->secret);
1294 static int proxy_socket_decode(UNUSED rad_listen_t *listener, REQUEST *request)
1297 * rad_verify is run in event.c, received_proxy_response()
1300 return rad_decode(request->proxy_reply, request->proxy,
1301 request->home_server->secret);
1307 #include "command.c"
1309 static const rad_listen_master_t master_listen[RAD_LISTEN_MAX] = {
1311 { common_socket_parse, NULL,
1312 stats_socket_recv, auth_socket_send,
1313 socket_print, client_socket_encode, client_socket_decode },
1316 * This always gets defined.
1318 { NULL, NULL, NULL, NULL, NULL, NULL, NULL}, /* RAD_LISTEN_NONE */
1323 { common_socket_parse, NULL,
1324 proxy_socket_recv, proxy_socket_send,
1325 socket_print, proxy_socket_encode, proxy_socket_decode },
1328 /* authentication */
1329 { common_socket_parse, NULL,
1330 auth_socket_recv, auth_socket_send,
1331 socket_print, client_socket_encode, client_socket_decode },
1333 #ifdef WITH_ACCOUNTING
1335 { common_socket_parse, NULL,
1336 acct_socket_recv, acct_socket_send,
1337 socket_print, client_socket_encode, client_socket_decode},
1342 { detail_parse, detail_free,
1343 detail_recv, detail_send,
1344 detail_print, detail_encode, detail_decode },
1348 /* vlan query protocol */
1349 { common_socket_parse, NULL,
1350 vqp_socket_recv, vqp_socket_send,
1351 socket_print, vqp_socket_encode, vqp_socket_decode },
1355 /* dhcp query protocol */
1356 { dhcp_socket_parse, NULL,
1357 dhcp_socket_recv, dhcp_socket_send,
1358 socket_print, dhcp_socket_encode, dhcp_socket_decode },
1361 #ifdef WITH_COMMAND_SOCKET
1362 /* TCP command socket */
1363 { command_socket_parse, NULL,
1364 command_domain_accept, command_domain_send,
1365 command_socket_print, command_socket_encode, command_socket_decode },
1369 /* Change of Authorization */
1370 { common_socket_parse, NULL,
1371 coa_socket_recv, auth_socket_send, /* CoA packets are same as auth */
1372 socket_print, client_socket_encode, client_socket_decode },
1380 * Binds a listener to a socket.
1382 static int listen_bind(rad_listen_t *this)
1385 struct sockaddr_storage salocal;
1387 listen_socket_t *sock = this->data;
1390 * If the port is zero, then it means the appropriate
1391 * thing from /etc/services.
1393 if (sock->port == 0) {
1394 struct servent *svp;
1396 switch (this->type) {
1397 case RAD_LISTEN_AUTH:
1398 svp = getservbyname ("radius", "udp");
1400 sock->port = ntohs(svp->s_port);
1402 sock->port = PW_AUTH_UDP_PORT;
1406 #ifdef WITH_ACCOUNTING
1407 case RAD_LISTEN_ACCT:
1408 svp = getservbyname ("radacct", "udp");
1410 sock->port = ntohs(svp->s_port);
1412 sock->port = PW_ACCT_UDP_PORT;
1418 case RAD_LISTEN_PROXY:
1424 case RAD_LISTEN_VQP:
1430 case RAD_LISTEN_COA:
1431 sock->port = PW_COA_UDP_PORT;
1436 radlog(L_ERR, "ERROR: Non-fatal internal sanity check failed in bind.");
1442 * Copy fr_socket() here, as we may need to bind to a device.
1444 this->fd = socket(sock->ipaddr.af, SOCK_DGRAM, 0);
1446 radlog(L_ERR, "Failed opening socket: %s", strerror(errno));
1450 #ifdef SO_BINDTODEVICE
1452 * Bind to a device BEFORE touching IP addresses.
1454 if (sock->interface) {
1456 strcpy(ifreq.ifr_name, sock->interface);
1459 rcode = setsockopt(this->fd, SOL_SOCKET, SO_BINDTODEVICE,
1460 (char *)&ifreq, sizeof(ifreq));
1464 radlog(L_ERR, "Failed binding to interface %s: %s",
1465 sock->interface, strerror(errno));
1467 } /* else it worked. */
1471 #ifdef WITH_UDPFROMTO
1473 * Initialize udpfromto for all sockets.
1475 if (udpfromto_init(this->fd) != 0) {
1482 * Set up sockaddr stuff.
1484 if (!fr_ipaddr2sockaddr(&sock->ipaddr, sock->port, &salocal, &salen)) {
1489 #ifdef HAVE_STRUCT_SOCKADDR_IN6
1490 if (sock->ipaddr.af == AF_INET6) {
1492 * Listening on '::' does NOT get you IPv4 to
1493 * IPv6 mapping. You've got to listen on an IPv4
1494 * address, too. This makes the rest of the server
1495 * design a little simpler.
1499 if (IN6_IS_ADDR_UNSPECIFIED(&sock->ipaddr.ipaddr.ip6addr)) {
1502 setsockopt(this->fd, IPPROTO_IPV6, IPV6_V6ONLY,
1503 (char *)&on, sizeof(on));
1505 #endif /* IPV6_V6ONLY */
1507 #endif /* HAVE_STRUCT_SOCKADDR_IN6 */
1510 if (sock->ipaddr.af == AF_INET) {
1513 #if defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DONT)
1515 * Disable PMTU discovery. On Linux, this
1516 * also makes sure that the "don't fragment"
1519 flag = IP_PMTUDISC_DONT;
1520 setsockopt(this->fd, IPPROTO_IP, IP_MTU_DISCOVER,
1521 &flag, sizeof(flag));
1524 #if defined(IP_DONTFRAG)
1526 * Ensure that the "don't fragment" flag is zero.
1529 setsockopt(this->fd, IPPROTO_IP, IP_DONTFRAG,
1530 &flag, sizeof(flag));
1535 * May be binding to priviledged ports.
1538 rcode = bind(this->fd, (struct sockaddr *) &salocal, salen);
1544 this->print(this, buffer, sizeof(buffer));
1545 radlog(L_ERR, "Failed binding to %s: %s\n",
1546 buffer, strerror(errno));
1551 * FreeBSD jail issues. We bind to 0.0.0.0, but the
1552 * kernel instead binds us to a 1.2.3.4. If this
1553 * happens, notice, and remember our real IP.
1556 struct sockaddr_storage src;
1557 socklen_t sizeof_src = sizeof(src);
1559 memset(&src, 0, sizeof_src);
1560 if (getsockname(this->fd, (struct sockaddr *) &src,
1562 radlog(L_ERR, "Failed getting socket name: %s",
1567 if (!fr_sockaddr2ipaddr(&src, sizeof_src,
1568 &sock->ipaddr, &sock->port)) {
1569 radlog(L_ERR, "Socket has unsupported address family");
1578 if ((flags = fcntl(this->fd, F_GETFL, NULL)) < 0) {
1579 radlog(L_ERR, "Failure getting socket flags: %s)\n",
1584 flags |= O_NONBLOCK;
1585 if( fcntl(this->fd, F_SETFL, flags) < 0) {
1586 radlog(L_ERR, "Failure setting socket flags: %s)\n",
1598 * Allocate & initialize a new listener.
1600 static rad_listen_t *listen_alloc(RAD_LISTEN_TYPE type)
1604 this = rad_malloc(sizeof(*this));
1605 memset(this, 0, sizeof(*this));
1608 this->recv = master_listen[this->type].recv;
1609 this->send = master_listen[this->type].send;
1610 this->print = master_listen[this->type].print;
1611 this->encode = master_listen[this->type].encode;
1612 this->decode = master_listen[this->type].decode;
1616 case RAD_LISTEN_NONE:
1618 case RAD_LISTEN_AUTH:
1619 #ifdef WITH_ACCOUNTING
1620 case RAD_LISTEN_ACCT:
1623 case RAD_LISTEN_PROXY:
1626 case RAD_LISTEN_VQP:
1629 case RAD_LISTEN_COA:
1631 this->data = rad_malloc(sizeof(listen_socket_t));
1632 memset(this->data, 0, sizeof(listen_socket_t));
1636 case RAD_LISTEN_DHCP:
1637 this->data = rad_malloc(sizeof(dhcp_socket_t));
1638 memset(this->data, 0, sizeof(dhcp_socket_t));
1643 case RAD_LISTEN_DETAIL:
1648 #ifdef WITH_COMMAND_SOCKET
1649 case RAD_LISTEN_COMMAND:
1650 this->data = rad_malloc(sizeof(fr_command_socket_t));
1651 memset(this->data, 0, sizeof(fr_command_socket_t));
1656 rad_assert("Unsupported option!" == NULL);
1666 * Externally visible function for creating a new proxy LISTENER.
1668 * Not thread-safe, but all calls to it are protected by the
1669 * proxy mutex in event.c
1671 rad_listen_t *proxy_new_listener(fr_ipaddr_t *ipaddr, int exists)
1673 rad_listen_t *this, *tmp, **last;
1674 listen_socket_t *sock, *old;
1677 * Find an existing proxy socket to copy.
1680 last = &mainconfig.listen;
1681 for (tmp = mainconfig.listen; tmp != NULL; tmp = tmp->next) {
1683 * Not proxy, ignore it.
1685 if (tmp->type != RAD_LISTEN_PROXY) continue;
1690 * If we were asked to copy a specific one, do
1691 * so. If we're just finding one that already
1692 * exists, return a pointer to it. Otherwise,
1693 * create ANOTHER one with the same IP address.
1695 if ((ipaddr->af != AF_UNSPEC) &&
1696 (fr_ipaddr_cmp(&sock->ipaddr, ipaddr) != 0)) {
1697 if (exists) return tmp;
1701 if (!old) old = sock;
1703 last = &(tmp->next);
1708 * The socket MUST already exist if we're binding
1709 * to an address while proxying.
1711 * If we're initializing the server, it's OK for the
1712 * socket to NOT exist.
1714 if (!exists) return NULL;
1716 this = listen_alloc(RAD_LISTEN_PROXY);
1719 sock->ipaddr = *ipaddr;
1722 this = listen_alloc(RAD_LISTEN_PROXY);
1725 sock->ipaddr = old->ipaddr;
1730 if (listen_bind(this) >= 0) {
1732 * Add the new listener to the list of
1744 static const FR_NAME_NUMBER listen_compare[] = {
1746 { "status", RAD_LISTEN_NONE },
1748 { "auth", RAD_LISTEN_AUTH },
1749 #ifdef WITH_ACCOUNTING
1750 { "acct", RAD_LISTEN_ACCT },
1753 { "detail", RAD_LISTEN_DETAIL },
1756 { "proxy", RAD_LISTEN_PROXY },
1759 { "vmps", RAD_LISTEN_VQP },
1762 { "dhcp", RAD_LISTEN_DHCP },
1764 #ifdef WITH_COMMAND_SOCKET
1765 { "control", RAD_LISTEN_COMMAND },
1768 { "coa", RAD_LISTEN_COA },
1774 static rad_listen_t *listen_parse(CONF_SECTION *cs, const char *server)
1782 cf_log_info(cs, "listen {");
1784 rcode = cf_item_parse(cs, "type", PW_TYPE_STRING_PTR,
1786 if (rcode < 0) return NULL;
1789 cf_log_err(cf_sectiontoitem(cs),
1790 "No type specified in listen section");
1794 type = fr_str2int(listen_compare, listen_type, -1);
1796 cf_log_err(cf_sectiontoitem(cs),
1797 "Invalid type \"%s\" in listen section.",
1805 * Allow listen sections in the default config to
1806 * refer to a server.
1809 rcode = cf_item_parse(cs, "virtual_server", PW_TYPE_STRING_PTR,
1811 if (rcode == 1) { /* compatiblity with 2.0-pre */
1812 rcode = cf_item_parse(cs, "server", PW_TYPE_STRING_PTR,
1815 if (rcode < 0) return NULL;
1819 * Set up cross-type data.
1821 this = listen_alloc(type);
1822 this->server = server;
1826 * Call per-type parser.
1828 if (master_listen[type].parse(cs, this) < 0) {
1833 cf_log_info(cs, "}");
1839 * Generate a list of listeners. Takes an input list of
1840 * listeners, too, so we don't close sockets with waiting packets.
1842 int listen_init(CONF_SECTION *config, rad_listen_t **head)
1844 int override = FALSE;
1846 CONF_SECTION *cs = NULL;
1847 rad_listen_t **last;
1849 fr_ipaddr_t server_ipaddr;
1852 int defined_proxy = 0;
1856 * We shouldn't be called with a pre-existing list.
1858 rad_assert(head && (*head == NULL));
1861 server_ipaddr.af = AF_UNSPEC;
1864 * If the port is specified on the command-line,
1865 * it over-rides the configuration file.
1867 * FIXME: If argv[0] == "vmpsd", then don't listen on auth/acct!
1869 if (mainconfig.port >= 0) auth_port = mainconfig.port;
1872 * If the IP address was configured on the command-line,
1873 * use that as the "bind_address"
1875 if (mainconfig.myip.af != AF_UNSPEC) {
1876 memcpy(&server_ipaddr, &mainconfig.myip,
1877 sizeof(server_ipaddr));
1883 * Else look for bind_address and/or listen sections.
1885 server_ipaddr.ipaddr.ip4addr.s_addr = htonl(INADDR_NONE);
1886 rcode = cf_item_parse(config, "bind_address",
1888 &server_ipaddr.ipaddr.ip4addr, NULL);
1889 if (rcode < 0) return -1; /* error parsing it */
1891 if (rcode == 0) { /* successfully parsed IPv4 */
1892 listen_socket_t *sock;
1893 server_ipaddr.af = AF_INET;
1895 radlog(L_INFO, "WARNING: The directive 'bind_address' is deprecated, and will be removed in future versions of FreeRADIUS. Please edit the configuration files to use the directive 'listen'.");
1899 if (strcmp(progname, "vmpsd") == 0) {
1900 this = listen_alloc(RAD_LISTEN_VQP);
1901 if (!auth_port) auth_port = 1589;
1904 this = listen_alloc(RAD_LISTEN_AUTH);
1908 sock->ipaddr = server_ipaddr;
1909 sock->port = auth_port;
1911 sock->clients = clients_parse_section(config);
1912 if (!sock->clients) {
1913 cf_log_err(cf_sectiontoitem(config),
1914 "Failed to find any clients for this listen section");
1919 if (listen_bind(this) < 0) {
1921 radlog(L_ERR, "There appears to be another RADIUS server running on the authentication port %d", sock->port);
1925 auth_port = sock->port; /* may have been updated in listen_bind */
1927 cs = cf_section_sub_find_name2(config, "server",
1929 if (cs) this->server = mainconfig.name;
1933 last = &(this->next);
1939 if (strcmp(progname, "vmpsd") == 0) goto do_proxy;
1942 #ifdef WITH_ACCOUNTING
1944 * Open Accounting Socket.
1946 * If we haven't already gotten acct_port from
1947 * /etc/services, then make it auth_port + 1.
1949 this = listen_alloc(RAD_LISTEN_ACCT);
1953 * Create the accounting socket.
1955 * The accounting port is always the
1956 * authentication port + 1
1958 sock->ipaddr = server_ipaddr;
1959 sock->port = auth_port + 1;
1961 sock->clients = clients_parse_section(config);
1962 if (!sock->clients) {
1963 cf_log_err(cf_sectiontoitem(config),
1964 "Failed to find any clients for this listen section");
1968 if (listen_bind(this) < 0) {
1971 radlog(L_ERR, "There appears to be another RADIUS server running on the accounting port %d", sock->port);
1976 cs = cf_section_sub_find_name2(config, "server",
1978 if (cs) this->server = mainconfig.name;
1982 last = &(this->next);
1984 } else if (mainconfig.port > 0) { /* no bind address, but a port */
1985 radlog(L_ERR, "The command-line says \"-p %d\", but there is no associated IP address to use",
1991 * They specified an IP on the command-line, ignore
1992 * all listen sections except the one in '-n'.
1994 if (mainconfig.myip.af != AF_UNSPEC) {
1995 CONF_SECTION *subcs;
1996 const char *name2 = cf_section_name2(cs);
1998 cs = cf_section_sub_find_name2(config, "server",
2000 if (!cs) goto do_proxy;
2003 * Should really abstract this code...
2005 for (subcs = cf_subsection_find_next(cs, NULL, "listen");
2007 subcs = cf_subsection_find_next(cs, subcs, "listen")) {
2008 this = listen_parse(subcs, name2);
2015 if (this->type == RAD_LISTEN_PROXY) defined_proxy = 1;
2019 last = &(this->next);
2020 } /* loop over "listen" directives in server <foo> */
2026 * Walk through the "listen" sections, if they exist.
2028 for (cs = cf_subsection_find_next(config, NULL, "listen");
2030 cs = cf_subsection_find_next(config, cs, "listen")) {
2031 this = listen_parse(cs, NULL);
2038 if (this->type == RAD_LISTEN_PROXY) defined_proxy = 1;
2042 last = &(this->next);
2046 * Check virtual servers for "listen" sections, too.
2048 * FIXME: Move to virtual server init?
2050 for (cs = cf_subsection_find_next(config, NULL, "server");
2052 cs = cf_subsection_find_next(config, cs, "server")) {
2053 CONF_SECTION *subcs;
2054 const char *name2 = cf_section_name2(cs);
2056 for (subcs = cf_subsection_find_next(cs, NULL, "listen");
2058 subcs = cf_subsection_find_next(cs, subcs, "listen")) {
2059 this = listen_parse(subcs, name2);
2066 if (this->type == RAD_LISTEN_PROXY) {
2067 radlog(L_ERR, "Error: listen type \"proxy\" Cannot appear in a virtual server section");
2074 last = &(this->next);
2075 } /* loop over "listen" directives in virtual servers */
2076 } /* loop over virtual servers */
2079 * If we're proxying requests, open the proxy FD.
2080 * Otherwise, don't do anything.
2084 if (mainconfig.proxy_requests == TRUE) {
2086 listen_socket_t *sock = NULL;
2089 * No sockets to receive packets, therefore
2090 * proxying is pointless.
2092 if (!*head) return -1;
2094 if (defined_proxy) goto check_home_servers;
2097 * Find the first authentication port,
2100 for (this = *head; this != NULL; this = this->next) {
2101 if (this->type == RAD_LISTEN_AUTH) {
2103 if (server_ipaddr.af == AF_UNSPEC) {
2104 server_ipaddr = sock->ipaddr;
2106 port = sock->port + 2; /* skip acct port */
2110 if (this->type == RAD_LISTEN_VQP) {
2112 if (server_ipaddr.af == AF_UNSPEC) {
2113 server_ipaddr = sock->ipaddr;
2115 port = sock->port + 1;
2121 if (port < 0) port = 1024 + (fr_rand() & 0x1ff);
2124 * Address is still unspecified, use IPv4.
2126 if (server_ipaddr.af == AF_UNSPEC) {
2127 server_ipaddr.af = AF_INET;
2128 server_ipaddr.ipaddr.ip4addr.s_addr = htonl(INADDR_ANY);
2131 this = listen_alloc(RAD_LISTEN_PROXY);
2135 * Create the first proxy socket.
2137 sock->ipaddr = server_ipaddr;
2140 * Try to find a proxy port (value doesn't matter)
2142 for (sock->port = port;
2145 if (listen_bind(this) == 0) {
2147 last = &(this->next); /* just in case */
2152 if (sock->port >= 64000) {
2155 radlog(L_ERR, "Failed to open socket for proxying");
2160 * Create *additional* proxy listeners, based
2161 * on their src_ipaddr.
2164 if (home_server_create_listeners(*head) != 0) return -1;
2172 * Free a linked list of listeners;
2174 void listen_free(rad_listen_t **head)
2178 if (!head || !*head) return;
2182 rad_listen_t *next = this->next;
2185 * Other code may have eaten the FD.
2187 if (this->fd >= 0) close(this->fd);
2189 if (master_listen[this->type].free) {
2190 master_listen[this->type].free(this);
2202 RADCLIENT_LIST *listener_find_client_list(const fr_ipaddr_t *ipaddr,
2207 for (this = mainconfig.listen; this != NULL; this = this->next) {
2208 listen_socket_t *sock;
2210 if ((this->type != RAD_LISTEN_AUTH) &&
2211 (this->type != RAD_LISTEN_ACCT)) continue;
2215 if ((sock->port == port) &&
2216 (fr_ipaddr_cmp(ipaddr, &sock->ipaddr) == 0)) {
2217 return sock->clients;
2225 rad_listen_t *listener_find_byipaddr(const fr_ipaddr_t *ipaddr, int port)
2229 for (this = mainconfig.listen; this != NULL; this = this->next) {
2230 listen_socket_t *sock;
2233 * FIXME: For TCP, ignore the *secondary*
2234 * listeners associated with the main socket.
2236 if ((this->type != RAD_LISTEN_AUTH) &&
2237 (this->type != RAD_LISTEN_ACCT)) continue;
2241 if ((sock->port == port) &&
2242 (fr_ipaddr_cmp(ipaddr, &sock->ipaddr) == 0)) {
2246 if ((sock->port == port) &&
2247 ((sock->ipaddr.af == AF_INET) &&
2248 (sock->ipaddr.ipaddr.ip4addr.s_addr == INADDR_ANY))) {
2252 #ifdef HAVE_STRUCT_SOCKADDR_IN6
2253 if ((sock->port == port) &&
2254 (sock->ipaddr.af == AF_INET6) &&
2255 (IN6_IS_ADDR_UNSPECIFIED(&sock->ipaddr.ipaddr.ip6addr))) {