X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Flisten.c;h=e82d5850fe07121ce557ec420255e7825b9b7460;hb=e9831edfd3d9f38e6996d6e0e655feb0e1547be8;hp=67eed257860c571666d174bc778f7f100e64e150;hpb=7480c9f55c5cc4655c22dbf00c4bcd837cd4e12d;p=freeradius.git diff --git a/src/main/listen.c b/src/main/listen.c index 67eed25..e82d585 100644 --- a/src/main/listen.c +++ b/src/main/listen.c @@ -2441,6 +2441,26 @@ static rad_listen_t *listen_parse(CONF_SECTION *cs, const char *server) return this; } +static int is_loopback(const fr_ipaddr_t *ipaddr) +{ + /* + * We shouldn't proxy on loopback. + */ + if ((ipaddr->af == AF_INET) && + (ipaddr->ipaddr.ip4addr.s_addr == htonl(INADDR_LOOPBACK))) { + return 1; + } + +#ifdef HAVE_STRUCT_SOCKADDR_IN6 + if ((ipaddr->af == AF_INET6) && + (IN6_IS_ADDR_LINKLOCAL(&ipaddr->ipaddr.ip6addr))) { + return 1; + } +#endif + + return 0; +} + /* * Generate a list of listeners. Takes an input list of * listeners, too, so we don't close sockets with waiting packets. @@ -2667,6 +2687,15 @@ int listen_init(CONF_SECTION *config, rad_listen_t **head) add_sockets: /* + * No sockets to receive packets, this is an error. + * proxying is pointless. + */ + if (!*head) { + radlog(L_ERR, "The server is not configured to listen on any ports. Cannot start."); + return -1; + } + + /* * Print out which sockets we're listening on, and * add them to the event list. */ @@ -2706,6 +2735,9 @@ add_sockets: for (this = *head; this != NULL; this = this->next) { if (this->type == RAD_LISTEN_AUTH) { sock = this->data; + + if (is_loopback(&sock->my_ipaddr)) continue; + if (home.src_ipaddr.af == AF_UNSPEC) { home.src_ipaddr = sock->my_ipaddr; } @@ -2715,6 +2747,9 @@ add_sockets: #ifdef WITH_ACCT if (this->type == RAD_LISTEN_ACCT) { sock = this->data; + + if (is_loopback(&sock->my_ipaddr)) continue; + if (home.src_ipaddr.af == AF_UNSPEC) { home.src_ipaddr = sock->my_ipaddr; } @@ -2842,18 +2877,9 @@ rad_listen_t *listener_find_byipaddr(const fr_ipaddr_t *ipaddr, int port) } if ((sock->my_port == port) && - ((sock->my_ipaddr.af == AF_INET) && - (sock->my_ipaddr.ipaddr.ip4addr.s_addr == INADDR_ANY))) { + fr_inaddr_any(&sock->my_ipaddr)) { return this; } - -#ifdef HAVE_STRUCT_SOCKADDR_IN6 - if ((sock->my_port == port) && - (sock->my_ipaddr.af == AF_INET6) && - (IN6_IS_ADDR_UNSPECIFIED(&sock->my_ipaddr.ipaddr.ip6addr))) { - return this; - } -#endif } return NULL;