Allow building WITHOUT_STATS
[freeradius.git] / src / main / client.c
index 38ddc1d..35045df 100644 (file)
@@ -233,15 +233,34 @@ static int client_sane(RADCLIENT *client)
                               sizeof(client->ipaddr.ipaddr.ip6addr));
 
                } else if (client->prefix < 128) {
-                       int i;
                        uint32_t mask, *addr;
 
                        addr = (uint32_t *) &client->ipaddr.ipaddr.ip6addr;
 
-                       for (i = client->prefix; i < 128; i += 32) {
-                               mask = ~0;
-                               mask <<= ((128 - i) & 0x1f);
-                               addr[i / 32] &= mask;
+                       if ((client->prefix & 0x1f) == 0) {
+                               mask = 0;
+                       } else {
+                               mask = ~ ((uint32_t) 0);
+                               mask <<= (32 - (client->prefix & 0x1f));
+                               mask = htonl(mask);
+                       }
+
+                       switch (client->prefix >> 5) {
+                       case 0:
+                               addr[0] &= mask;
+                               mask = 0;
+                               /* FALL-THROUGH */
+                       case 1:
+                               addr[1] &= mask;
+                               mask = 0;
+                               /* FALL-THROUGH */
+                       case 2:
+                               addr[2] &= mask;
+                               mask = 0;
+                               /* FALL-THROUGH */
+                       case 3:
+                               addr[3] &= mask;
+                         break;
                        }
                }
                break;
@@ -376,11 +395,7 @@ int client_add(RADCLIENT_LIST *clients, RADCLIENT *client)
                 *      If there IS an enclosing network,
                 *      inherit the lifetime from it.
                 */
-               network = client_find(clients, &client->ipaddr
-#ifdef WITH_TCP
-                                     , client->proto
-#endif
-                       );
+               network = client_find(clients, &client->ipaddr, client->proto);
                if (network) {
                        client->lifetime = network->lifetime;
                }
@@ -403,13 +418,19 @@ int client_add(RADCLIENT_LIST *clients, RADCLIENT *client)
 #ifdef WITH_DYNAMIC_CLIENTS
 void client_delete(RADCLIENT_LIST *clients, RADCLIENT *client)
 {
-       if (!clients || !client) return;
+       if (!client) return;
+
+       if (!clients) clients = root_clients;
+
+       if (!client->dynamic) return;
 
        rad_assert((client->prefix >= 0) && (client->prefix <= 128));
 
        client->dynamic = 2;    /* signal to client_free */
 
+#ifdef WITH_STATS
        rbtree_deletebydata(tree_num, client);
+#endif
        rbtree_deletebydata(clients->trees[client->prefix], client);
 }
 #endif
@@ -448,11 +469,7 @@ RADCLIENT *client_findbynumber(const RADCLIENT_LIST *clients,
  *     Find a client in the RADCLIENTS list.
  */
 RADCLIENT *client_find(const RADCLIENT_LIST *clients,
-                      const fr_ipaddr_t *ipaddr
-#ifdef WITH_TCP
-                      , int proto
-#endif
-       )
+                      const fr_ipaddr_t *ipaddr, int proto)
 {
        int i, max_prefix;
        RADCLIENT myclient;
@@ -479,9 +496,7 @@ RADCLIENT *client_find(const RADCLIENT_LIST *clients,
 
                myclient.prefix = i;
                myclient.ipaddr = *ipaddr;
-#ifdef WITH_TCP
                myclient.proto = proto;
-#endif
                client_sane(&myclient); /* clean up the ipaddress */
 
                if (!clients->trees[i]) continue;
@@ -548,6 +563,8 @@ static const CONF_PARSER client_config[] = {
          offsetof(RADCLIENT, client_server), 0, NULL },
        { "lifetime",  PW_TYPE_INTEGER,
          offsetof(RADCLIENT, lifetime), 0, NULL },
+       { "rate_limit",  PW_TYPE_BOOLEAN,
+         offsetof(RADCLIENT, rate_limit), 0, NULL },
 #endif
 
 #ifdef WITH_COA
@@ -694,8 +711,8 @@ static RADCLIENT *client_parse(CONF_SECTION *cs, int in_server)
                 */
                if (!c->shortname) c->shortname = strdup(name2);
 
-#ifdef WITH_TCP
                c->proto = IPPROTO_UDP;
+#ifdef WITH_TCP
                if (hs_proto) {
                        if (strcmp(hs_proto, "udp") == 0) {
                                free(hs_proto);
@@ -1056,7 +1073,7 @@ RADCLIENT *client_create(RADCLIENT_LIST *clients, REQUEST *request)
                        return NULL;
                }
 
-               vp = pairfind(request->config_items, da->attr);
+               vp = pairfind(request->config_items, da->attr, da->vendor);
                if (!vp) {
                        /*
                         *      Not required.  Skip it.