2 * client.c Read clients into memory.
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 2000,2006 The FreeRADIUS server project
21 * Copyright 2000 Miquel van Smoorenburg <miquels@cistron.nl>
22 * Copyright 2000 Alan DeKok <aland@ox.org>
25 #include <freeradius-devel/ident.h>
28 #include <freeradius-devel/radiusd.h>
29 #include <freeradius-devel/rad_assert.h>
36 #ifdef WITH_DYNAMIC_CLIENTS
42 struct radclient_list {
44 * FIXME: One set of trees for IPv4, and another for IPv6?
46 rbtree_t *trees[129]; /* for 0..128, inclusive. */
52 static rbtree_t *tree_num = NULL; /* client numbers 0..N */
53 static int tree_num_max = 0;
55 static RADCLIENT_LIST *root_clients = NULL;
57 #ifdef WITH_DYNAMIC_CLIENTS
58 static fr_fifo_t *deleted_clients = NULL;
62 * Callback for freeing a client.
64 void client_free(RADCLIENT *client)
66 #ifdef WITH_DYNAMIC_CLIENTS
67 if (client->dynamic == 2) {
70 if (!deleted_clients) {
71 deleted_clients = fr_fifo_create(1024,
72 (void *) client_free);
73 if (!deleted_clients) return; /* MEMLEAK */
77 * Mark it as in the fifo, and remember when we
81 client->created = now = time(NULL); /* re-set it */
82 fr_fifo_push(deleted_clients, client);
85 * Peek at the head of the fifo. If it might
86 * still be in use, return. Otherwise, pop it
87 * from the queue and delete it.
89 client = fr_fifo_peek(deleted_clients);
90 if ((client->created + 120) >= now) return;
92 client = fr_fifo_pop(deleted_clients);
93 rad_assert(client != NULL);
97 free(client->longname);
99 free(client->shortname);
100 free(client->nastype);
102 free(client->password);
103 free(client->server);
107 #ifdef WITH_ACCOUNTING
112 #ifdef WITH_DYNAMIC_CLIENTS
113 free(client->client_server);
120 * Callback for comparing two clients.
122 static int client_ipaddr_cmp(const void *one, const void *two)
124 const RADCLIENT *a = one;
125 const RADCLIENT *b = two;
128 return fr_ipaddr_cmp(&a->ipaddr, &b->ipaddr);
132 rcode = fr_ipaddr_cmp(&a->ipaddr, &b->ipaddr);
133 if (rcode != 0) return rcode;
138 if ((a->proto == IPPROTO_IP) ||
139 (b->proto == IPPROTO_IP)) return 0;
141 return (a->proto - b->proto);
146 static int client_num_cmp(const void *one, const void *two)
148 const RADCLIENT *a = one;
149 const RADCLIENT *b = two;
151 return (a->number - b->number);
156 * Free a RADCLIENT list.
158 void clients_free(RADCLIENT_LIST *clients)
162 if (!clients) return;
164 for (i = 0; i <= 128; i++) {
165 if (clients->trees[i]) rbtree_free(clients->trees[i]);
166 clients->trees[i] = NULL;
169 if (clients == root_clients) {
171 if (tree_num) rbtree_free(tree_num);
178 #ifdef WITH_DYNAMIC_CLIENTS
180 * FIXME: No fr_fifo_delete()
188 * Return a new, initialized, set of clients.
190 RADCLIENT_LIST *clients_init(void)
192 RADCLIENT_LIST *clients = calloc(1, sizeof(RADCLIENT_LIST));
194 if (!clients) return NULL;
196 clients->min_prefix = 128;
203 * Sanity check a client.
205 static int client_sane(RADCLIENT *client)
207 switch (client->ipaddr.af) {
209 if (client->prefix > 32) {
214 * Zero out the subnet bits.
216 if (client->prefix == 0) {
217 memset(&client->ipaddr.ipaddr.ip4addr, 0,
218 sizeof(client->ipaddr.ipaddr.ip4addr));
220 } else if (client->prefix < 32) {
223 mask <<= (32 - client->prefix);
224 client->ipaddr.ipaddr.ip4addr.s_addr &= htonl(mask);
229 if (client->prefix > 128) return 0;
231 if (client->prefix == 0) {
232 memset(&client->ipaddr.ipaddr.ip6addr, 0,
233 sizeof(client->ipaddr.ipaddr.ip6addr));
235 } else if (client->prefix < 128) {
236 uint32_t mask, *addr;
238 addr = (uint32_t *) &client->ipaddr.ipaddr.ip6addr;
240 if ((client->prefix & 0x1f) == 0) {
243 mask = ~ ((uint32_t) 0);
244 mask <<= (32 - (client->prefix & 0x1f));
248 switch (client->prefix >> 5) {
277 * Add a client to the tree.
279 int client_add(RADCLIENT_LIST *clients, RADCLIENT *client)
288 * If "clients" is NULL, it means add to the global list.
292 * Initialize it, if not done already.
295 root_clients = clients_init();
296 if (!root_clients) return 0;
298 clients = root_clients;
301 if ((client->prefix < 0) || (client->prefix > 128)) {
305 if (!client_sane(client)) return 0;
308 * Create a tree for it.
310 if (!clients->trees[client->prefix]) {
311 clients->trees[client->prefix] = rbtree_create(client_ipaddr_cmp,
312 (void *) client_free, 0);
313 if (!clients->trees[client->prefix]) {
318 #define namecmp(a) ((!old->a && !client->a) || (old->a && client->a && (strcmp(old->a, client->a) == 0)))
321 * Cannot insert the same client twice.
323 old = rbtree_finddata(clients->trees[client->prefix], client);
326 * If it's a complete duplicate, then free the new
327 * one, and return "OK".
329 if ((fr_ipaddr_cmp(&old->ipaddr, &client->ipaddr) == 0) &&
330 (old->prefix == client->prefix) &&
331 namecmp(longname) && namecmp(secret) &&
332 namecmp(shortname) && namecmp(nastype) &&
333 namecmp(login) && namecmp(password) && namecmp(server) &&
334 #ifdef WITH_DYNAMIC_CLIENTS
335 (old->lifetime == client->lifetime) &&
336 namecmp(client_server) &&
340 (old->coa_server == client->coa_server) &&
341 (old->coa_pool == client->coa_pool) &&
343 (old->message_authenticator == client->message_authenticator)) {
344 DEBUG("WARNING: Ignoring duplicate client %s", client->longname);
349 radlog(L_ERR, "Failed to add duplicate client %s",
356 * Other error adding client: likely is fatal.
358 if (!rbtree_insert(clients->trees[client->prefix], client)) {
364 tree_num = rbtree_create(client_num_cmp, NULL, 0);
369 * Catch clients added by rlm_sql.
372 client->auth = rad_malloc(sizeof(*client->auth));
373 memset(client->auth, 0, sizeof(*client->auth));
376 #ifdef WITH_ACCOUNTING
378 client->acct = rad_malloc(sizeof(*client->acct));
379 memset(client->acct, 0, sizeof(*client->acct));
383 #ifdef WITH_DYNAMIC_CLIENTS
385 * More catching of clients added by rlm_sql.
387 * The sql modules sets the dynamic flag BEFORE calling
388 * us. The client_create() function sets it AFTER
391 if (client->dynamic && (client->lifetime == 0)) {
395 * If there IS an enclosing network,
396 * inherit the lifetime from it.
398 network = client_find(clients, &client->ipaddr, client->proto);
400 client->lifetime = network->lifetime;
405 client->number = tree_num_max;
407 if (tree_num) rbtree_insert(tree_num, client);
410 if (client->prefix < clients->min_prefix) {
411 clients->min_prefix = client->prefix;
418 #ifdef WITH_DYNAMIC_CLIENTS
419 void client_delete(RADCLIENT_LIST *clients, RADCLIENT *client)
423 if (!clients) clients = root_clients;
425 if (!client->dynamic) return;
427 rad_assert((client->prefix >= 0) && (client->prefix <= 128));
429 client->dynamic = 2; /* signal to client_free */
432 rbtree_deletebydata(tree_num, client);
434 rbtree_deletebydata(clients->trees[client->prefix], client);
440 * Find a client in the RADCLIENTS list by number.
441 * This is a support function for the statistics code.
443 RADCLIENT *client_findbynumber(const RADCLIENT_LIST *clients,
447 if (!clients) clients = root_clients;
449 if (!clients) return NULL;
451 if (number >= tree_num_max) return NULL;
456 myclient.number = number;
458 return rbtree_finddata(tree_num, &myclient);
461 clients = clients; /* -Wunused */
462 number = number; /* -Wunused */
469 * Find a client in the RADCLIENTS list.
471 RADCLIENT *client_find(const RADCLIENT_LIST *clients,
472 const fr_ipaddr_t *ipaddr, int proto)
477 if (!clients) clients = root_clients;
479 if (!clients || !ipaddr) return NULL;
481 switch (ipaddr->af) {
494 for (i = max_prefix; i >= clients->min_prefix; i--) {
498 myclient.ipaddr = *ipaddr;
499 myclient.proto = proto;
500 client_sane(&myclient); /* clean up the ipaddress */
502 if (!clients->trees[i]) continue;
504 data = rbtree_finddata(clients->trees[i], &myclient);
515 * Old wrapper for client_find
517 RADCLIENT *client_find_old(const fr_ipaddr_t *ipaddr)
519 return client_find(root_clients, ipaddr, IPPROTO_UDP);
522 static struct in_addr cl_ip4addr;
523 static struct in6_addr cl_ip6addr;
525 static char *hs_proto = NULL;
528 static const CONF_PARSER client_config[] = {
529 { "ipaddr", PW_TYPE_IPADDR,
530 0, &cl_ip4addr, NULL },
531 { "ipv6addr", PW_TYPE_IPV6ADDR,
532 0, &cl_ip6addr, NULL },
533 { "netmask", PW_TYPE_INTEGER,
534 offsetof(RADCLIENT, prefix), 0, NULL },
536 { "require_message_authenticator", PW_TYPE_BOOLEAN,
537 offsetof(RADCLIENT, message_authenticator), 0, "no" },
539 { "secret", PW_TYPE_STRING_PTR,
540 offsetof(RADCLIENT, secret), 0, NULL },
541 { "shortname", PW_TYPE_STRING_PTR,
542 offsetof(RADCLIENT, shortname), 0, NULL },
543 { "nastype", PW_TYPE_STRING_PTR,
544 offsetof(RADCLIENT, nastype), 0, NULL },
545 { "login", PW_TYPE_STRING_PTR,
546 offsetof(RADCLIENT, login), 0, NULL },
547 { "password", PW_TYPE_STRING_PTR,
548 offsetof(RADCLIENT, password), 0, NULL },
549 { "virtual_server", PW_TYPE_STRING_PTR,
550 offsetof(RADCLIENT, server), 0, NULL },
551 { "server", PW_TYPE_STRING_PTR, /* compatability with 2.0-pre */
552 offsetof(RADCLIENT, server), 0, NULL },
555 { "proto", PW_TYPE_STRING_PTR,
556 0, &hs_proto, NULL },
557 { "max_connections", PW_TYPE_INTEGER,
558 offsetof(RADCLIENT, max_connections), 0, "16" },
561 #ifdef WITH_DYNAMIC_CLIENTS
562 { "dynamic_clients", PW_TYPE_STRING_PTR,
563 offsetof(RADCLIENT, client_server), 0, NULL },
564 { "lifetime", PW_TYPE_INTEGER,
565 offsetof(RADCLIENT, lifetime), 0, NULL },
566 { "rate_limit", PW_TYPE_BOOLEAN,
567 offsetof(RADCLIENT, rate_limit), 0, NULL },
571 { "coa_server", PW_TYPE_STRING_PTR,
572 offsetof(RADCLIENT, coa_name), 0, NULL },
575 { NULL, -1, 0, NULL, NULL }
579 static RADCLIENT *client_parse(CONF_SECTION *cs, int in_server)
584 name2 = cf_section_name2(cs);
586 cf_log_err(cf_sectiontoitem(cs),
587 "Missing client name");
592 * The size is fine.. Let's create the buffer
594 c = rad_malloc(sizeof(*c));
595 memset(c, 0, sizeof(*c));
599 c->auth = rad_malloc(sizeof(*c->auth));
600 memset(c->auth, 0, sizeof(*c->auth));
602 #ifdef WITH_ACCOUNTING
603 c->acct = rad_malloc(sizeof(*c->acct));
604 memset(c->acct, 0, sizeof(*c->acct));
608 memset(&cl_ip4addr, 0, sizeof(cl_ip4addr));
609 memset(&cl_ip6addr, 0, sizeof(cl_ip6addr));
612 if (cf_section_parse(cs, c, client_config) < 0) {
613 cf_log_err(cf_sectiontoitem(cs),
614 "Error parsing client section.");
626 * Global clients can set servers to use,
627 * per-server clients cannot.
629 if (in_server && c->server) {
630 cf_log_err(cf_sectiontoitem(cs),
631 "Clients inside of an server section cannot point to a server.");
636 * No "ipaddr" or "ipv6addr", use old-style
637 * "client <ipaddr> {" syntax.
639 if (!cf_pair_find(cs, "ipaddr") &&
640 !cf_pair_find(cs, "ipv6addr")) {
643 prefix_ptr = strchr(name2, '/');
649 c->prefix = atoi(prefix_ptr + 1);
650 if ((c->prefix < 0) || (c->prefix > 128)) {
651 cf_log_err(cf_sectiontoitem(cs),
652 "Invalid Prefix value '%s' for IP.",
656 /* Replace '/' with '\0' */
661 * Always get the numeric representation of IP
663 if (ip_hton(name2, AF_UNSPEC, &c->ipaddr) < 0) {
664 cf_log_err(cf_sectiontoitem(cs),
665 "Failed to look up hostname %s: %s",
666 name2, fr_strerror());
670 if (prefix_ptr) *prefix_ptr = '/';
671 c->longname = strdup(name2);
673 if (!c->shortname) c->shortname = strdup(c->longname);
679 * Figure out which one to use.
681 if (cf_pair_find(cs, "ipaddr")) {
682 c->ipaddr.af = AF_INET;
683 c->ipaddr.ipaddr.ip4addr = cl_ip4addr;
685 if ((c->prefix < -1) || (c->prefix > 32)) {
686 cf_log_err(cf_sectiontoitem(cs),
687 "Netmask must be between 0 and 32");
691 } else if (cf_pair_find(cs, "ipv6addr")) {
692 c->ipaddr.af = AF_INET6;
693 c->ipaddr.ipaddr.ip6addr = cl_ip6addr;
695 if ((c->prefix < -1) || (c->prefix > 128)) {
696 cf_log_err(cf_sectiontoitem(cs),
697 "Netmask must be between 0 and 128");
701 cf_log_err(cf_sectiontoitem(cs),
702 "No IP address defined for the client");
706 ip_ntoh(&c->ipaddr, buffer, sizeof(buffer));
707 c->longname = strdup(buffer);
710 * Set the short name to the name2
712 if (!c->shortname) c->shortname = strdup(name2);
714 c->proto = IPPROTO_UDP;
717 if (strcmp(hs_proto, "udp") == 0) {
721 } else if (strcmp(hs_proto, "tcp") == 0) {
724 c->proto = IPPROTO_TCP;
726 } else if (strcmp(hs_proto, "*") == 0) {
729 c->proto = IPPROTO_IP; /* fake for dual */
732 cf_log_err(cf_sectiontoitem(cs),
733 "Unknown proto \"%s\".", hs_proto);
740 if (c->prefix < 0) switch (c->ipaddr.af) {
751 #ifdef WITH_DYNAMIC_CLIENTS
752 if (c->client_server) {
754 c->secret = strdup("testing123");
756 if (((c->ipaddr.af == AF_INET) &&
757 (c->prefix == 32)) ||
758 ((c->ipaddr.af == AF_INET6) &&
759 (c->prefix == 128))) {
760 cf_log_err(cf_sectiontoitem(cs),
761 "Dynamic clients MUST be a network, not a single IP address.");
769 if (!c->secret || !*c->secret) {
771 const char *value = NULL;
772 CONF_PAIR *cp = cf_pair_find(cs, "dhcp");
774 if (cp) value = cf_pair_value(cp);
777 * Secrets aren't needed for DHCP.
779 if (value && (strcmp(value, "yes") == 0)) return c;
782 cf_log_err(cf_sectiontoitem(cs),
783 "secret must be at least 1 character long");
789 * Point the client to the home server pool, OR to the
790 * home server. This gets around the problem of figuring
791 * out which port to use.
794 c->coa_pool = home_pool_byname(c->coa_name, HOME_TYPE_COA);
796 c->coa_server = home_server_byname(c->coa_name,
799 if (!c->coa_pool && !c->coa_server) {
800 cf_log_err(cf_sectiontoitem(cs), "No such home_server or home_server_pool \"%s\"", c->coa_name);
811 * Create the linked list of clients from the new configuration
812 * type. This way we don't have to change too much in the other
815 RADCLIENT_LIST *clients_parse_section(CONF_SECTION *section)
817 int global = FALSE, in_server = FALSE;
820 RADCLIENT_LIST *clients;
823 * Be forgiving. If there's already a clients, return
824 * it. Otherwise create a new one.
826 clients = cf_data_find(section, "clients");
827 if (clients) return clients;
829 clients = clients_init();
830 if (!clients) return NULL;
832 if (cf_top_section(section) == section) global = TRUE;
834 if (strcmp("server", cf_section_name1(section)) == 0) in_server = TRUE;
837 * Associate the clients structure with the section, where
838 * it will be freed once the section is freed.
840 if (cf_data_add(section, "clients", clients, (void *) clients_free) < 0) {
841 cf_log_err(cf_sectiontoitem(section),
842 "Failed to associate clients with section %s",
843 cf_section_name1(section));
844 clients_free(clients);
848 for (cs = cf_subsection_find_next(section, NULL, "client");
850 cs = cf_subsection_find_next(section, cs, "client")) {
851 c = client_parse(cs, in_server);
857 * FIXME: Add the client as data via cf_data_add,
858 * for migration issues.
861 #ifdef WITH_DYNAMIC_CLIENTS
863 if (c->client_server) {
868 struct stat stat_buf;
872 * Find the directory where individual
873 * client definitions are stored.
875 cp = cf_pair_find(cs, "directory");
876 if (!cp) goto add_client;
878 value = cf_pair_value(cp);
880 cf_log_err(cf_sectiontoitem(cs),
881 "The \"directory\" entry must not be empty");
886 DEBUG("including dynamic clients in %s", value);
888 dir = opendir(value);
890 cf_log_err(cf_sectiontoitem(cs), "Error reading directory %s: %s", value, strerror(errno));
896 * Read the directory, ignoring "." files.
898 while ((dp = readdir(dir)) != NULL) {
902 if (dp->d_name[0] == '.') continue;
905 * Check for valid characters
907 for (p = dp->d_name; *p != '\0'; p++) {
908 if (isalpha((int)*p) ||
911 (*p == '.')) continue;
914 if (*p != '\0') continue;
916 snprintf(buf2, sizeof(buf2), "%s/%s",
919 if ((stat(buf2, &stat_buf) != 0) ||
920 S_ISDIR(stat_buf.st_mode)) continue;
922 dc = client_read(buf2, in_server, TRUE);
924 cf_log_err(cf_sectiontoitem(cs),
925 "Failed reading client file \"%s\"", buf2);
931 * Validate, and add to the list.
933 if (!client_validate(clients, c, dc)) {
938 } /* loop over the directory */
940 #endif /* HAVE_DIRENT_H */
941 #endif /* WITH_DYNAMIC_CLIENTS */
944 if (!client_add(clients, c)) {
945 cf_log_err(cf_sectiontoitem(cs),
946 "Failed to add client %s",
947 cf_section_name2(cs));
955 * Replace the global list of clients with the new one.
956 * The old one is still referenced from the original
957 * configuration, and will be freed when that is freed.
960 root_clients = clients;
966 #ifdef WITH_DYNAMIC_CLIENTS
968 * We overload this structure a lot.
970 static const CONF_PARSER dynamic_config[] = {
971 { "FreeRADIUS-Client-IP-Address", PW_TYPE_IPADDR,
972 offsetof(RADCLIENT, ipaddr), 0, NULL },
973 { "FreeRADIUS-Client-IPv6-Address", PW_TYPE_IPV6ADDR,
974 offsetof(RADCLIENT, ipaddr), 0, NULL },
976 { "FreeRADIUS-Client-Require-MA", PW_TYPE_BOOLEAN,
977 offsetof(RADCLIENT, message_authenticator), NULL, NULL },
979 { "FreeRADIUS-Client-Secret", PW_TYPE_STRING_PTR,
980 offsetof(RADCLIENT, secret), 0, "" },
981 { "FreeRADIUS-Client-Shortname", PW_TYPE_STRING_PTR,
982 offsetof(RADCLIENT, shortname), 0, "" },
983 { "FreeRADIUS-Client-NAS-Type", PW_TYPE_STRING_PTR,
984 offsetof(RADCLIENT, nastype), 0, NULL },
985 { "FreeRADIUS-Client-Virtual-Server", PW_TYPE_STRING_PTR,
986 offsetof(RADCLIENT, server), 0, NULL },
988 { NULL, -1, 0, NULL, NULL }
992 int client_validate(RADCLIENT_LIST *clients, RADCLIENT *master, RADCLIENT *c)
997 * No virtual server defined. Inherit the parent's
1000 if (master->server && !c->server) {
1001 c->server = strdup(master->server);
1005 * If the client network isn't global (not tied to a
1006 * virtual server), then ensure that this clients server
1007 * is the same as the enclosing networks virtual server.
1009 if (master->server &&
1010 (strcmp(master->server, c->server) != 0)) {
1011 DEBUG("- Cannot add client %s: Virtual server %s is not the same as the virtual server for the network.",
1013 buffer, sizeof(buffer)),
1019 if (!client_add(clients, c)) {
1020 DEBUG("- Cannot add client %s: Internal error",
1022 buffer, sizeof(buffer)));
1028 * Initialize the remaining fields.
1031 c->lifetime = master->lifetime;
1032 c->created = time(NULL);
1033 c->longname = strdup(c->shortname);
1035 DEBUG("- Added client %s with shared secret %s",
1036 ip_ntoh(&c->ipaddr, buffer, sizeof(buffer)),
1047 RADCLIENT *client_create(RADCLIENT_LIST *clients, REQUEST *request)
1054 if (!clients || !request) return NULL;
1056 c = rad_malloc(sizeof(*c));
1057 memset(c, 0, sizeof(*c));
1058 c->cs = request->client->cs;
1059 c->ipaddr.af = AF_UNSPEC;
1061 for (i = 0; dynamic_config[i].name != NULL; i++) {
1065 da = dict_attrbyname(dynamic_config[i].name);
1067 DEBUG("- Cannot add client %s: attribute \"%s\"is not in the dictionary",
1068 ip_ntoh(&request->packet->src_ipaddr,
1069 buffer, sizeof(buffer)),
1070 dynamic_config[i].name);
1076 vp = pairfind(request->config_items, da->attr, da->vendor);
1079 * Not required. Skip it.
1081 if (!dynamic_config[i].dflt) continue;
1083 DEBUG("- Cannot add client %s: Required attribute \"%s\" is missing.",
1084 ip_ntoh(&request->packet->src_ipaddr,
1085 buffer, sizeof(buffer)),
1086 dynamic_config[i].name);
1090 switch (dynamic_config[i].type) {
1091 case PW_TYPE_IPADDR:
1092 c->ipaddr.af = AF_INET;
1093 c->ipaddr.ipaddr.ip4addr.s_addr = vp->vp_ipaddr;
1097 case PW_TYPE_IPV6ADDR:
1098 c->ipaddr.af = AF_INET6;
1099 c->ipaddr.ipaddr.ip6addr = vp->vp_ipv6addr;
1103 case PW_TYPE_STRING_PTR:
1104 p = (char **) ((char *) c + dynamic_config[i].offset);
1106 *p = strdup(vp->vp_strvalue);
1109 case PW_TYPE_BOOLEAN:
1110 pi = (int *) ((char *) c + dynamic_config[i].offset);
1111 *pi = vp->vp_integer;
1119 if (c->ipaddr.af == AF_UNSPEC) {
1120 DEBUG("- Cannot add client %s: No IP address was specified.",
1121 ip_ntoh(&request->packet->src_ipaddr,
1122 buffer, sizeof(buffer)));
1127 if (fr_ipaddr_cmp(&request->packet->src_ipaddr, &c->ipaddr) != 0) {
1130 DEBUG("- Cannot add client %s: IP address %s do not match",
1131 ip_ntoh(&request->packet->src_ipaddr,
1132 buffer, sizeof(buffer)),
1134 buf2, sizeof(buf2)));
1138 if (!client_validate(clients, request->client, c)) {
1146 * Read a client definition from the given filename.
1148 RADCLIENT *client_read(const char *filename, int in_server, int flag)
1155 if (!filename) return NULL;
1157 cs = cf_file_read(filename);
1158 if (!cs) return NULL;
1160 c = client_parse(cf_section_sub_find(cs, "client"), in_server);
1162 p = strrchr(filename, FR_DIR_SEP);
1169 if (!flag) return c;
1172 * Additional validations
1174 ip_ntoh(&c->ipaddr, buffer, sizeof(buffer));
1175 if (strcmp(p, buffer) != 0) {
1176 DEBUG("Invalid client definition in %s: IP address %s does not match name %s", filename, buffer, p);