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;
127 return fr_ipaddr_cmp(&a->ipaddr, &b->ipaddr);
131 static int client_num_cmp(const void *one, const void *two)
133 const RADCLIENT *a = one;
134 const RADCLIENT *b = two;
136 return (a->number - b->number);
141 * Free a RADCLIENT list.
143 void clients_free(RADCLIENT_LIST *clients)
147 if (!clients) return;
149 for (i = 0; i <= 128; i++) {
150 if (clients->trees[i]) rbtree_free(clients->trees[i]);
151 clients->trees[i] = NULL;
154 if (clients == root_clients) {
156 if (tree_num) rbtree_free(tree_num);
163 #ifdef WITH_DYNAMIC_CLIENTS
165 * FIXME: No fr_fifo_delete()
173 * Return a new, initialized, set of clients.
175 RADCLIENT_LIST *clients_init(void)
177 RADCLIENT_LIST *clients = calloc(1, sizeof(RADCLIENT_LIST));
179 if (!clients) return NULL;
181 clients->min_prefix = 128;
188 * Sanity check a client.
190 static int client_sane(RADCLIENT *client)
192 switch (client->ipaddr.af) {
194 if (client->prefix > 32) {
199 * Zero out the subnet bits.
201 if (client->prefix == 0) {
202 memset(&client->ipaddr.ipaddr.ip4addr, 0,
203 sizeof(client->ipaddr.ipaddr.ip4addr));
205 } else if (client->prefix < 32) {
208 mask <<= (32 - client->prefix);
209 client->ipaddr.ipaddr.ip4addr.s_addr &= htonl(mask);
214 if (client->prefix > 128) return 0;
216 if (client->prefix == 0) {
217 memset(&client->ipaddr.ipaddr.ip6addr, 0,
218 sizeof(client->ipaddr.ipaddr.ip6addr));
220 } else if (client->prefix < 128) {
221 uint32_t mask, *addr;
223 addr = (uint32_t *) &client->ipaddr.ipaddr.ip6addr;
225 if ((client->prefix & 0x1f) == 0) {
228 mask = ~ ((uint32_t) 0);
229 mask <<= (32 - (client->prefix & 0x1f));
233 switch (client->prefix >> 5) {
262 * Add a client to the tree.
264 int client_add(RADCLIENT_LIST *clients, RADCLIENT *client)
273 * If "clients" is NULL, it means add to the global list.
277 * Initialize it, if not done already.
280 root_clients = clients_init();
281 if (!root_clients) return 0;
283 clients = root_clients;
286 if ((client->prefix < 0) || (client->prefix > 128)) {
290 if (!client_sane(client)) return 0;
293 * Create a tree for it.
295 if (!clients->trees[client->prefix]) {
296 clients->trees[client->prefix] = rbtree_create(client_ipaddr_cmp,
297 (void *) client_free, 0);
298 if (!clients->trees[client->prefix]) {
303 #define namecmp(a) ((!old->a && !client->a) || (old->a && client->a && (strcmp(old->a, client->a) == 0)))
306 * Cannot insert the same client twice.
308 old = rbtree_finddata(clients->trees[client->prefix], client);
311 * If it's a complete duplicate, then free the new
312 * one, and return "OK".
314 if ((fr_ipaddr_cmp(&old->ipaddr, &client->ipaddr) == 0) &&
315 (old->prefix == client->prefix) &&
316 namecmp(longname) && namecmp(secret) &&
317 namecmp(shortname) && namecmp(nastype) &&
318 namecmp(login) && namecmp(password) && namecmp(server) &&
319 #ifdef WITH_DYNAMIC_CLIENTS
320 (old->lifetime == client->lifetime) &&
321 namecmp(client_server) &&
325 (old->coa_server == client->coa_server) &&
326 (old->coa_pool == client->coa_pool) &&
328 (old->message_authenticator == client->message_authenticator)) {
329 DEBUG("WARNING: Ignoring duplicate client %s", client->longname);
334 radlog(L_ERR, "Failed to add duplicate client %s",
341 * Other error adding client: likely is fatal.
343 if (!rbtree_insert(clients->trees[client->prefix], client)) {
349 tree_num = rbtree_create(client_num_cmp, NULL, 0);
354 * Catch clients added by rlm_sql.
357 client->auth = rad_malloc(sizeof(*client->auth));
358 memset(client->auth, 0, sizeof(*client->auth));
361 #ifdef WITH_ACCOUNTING
363 client->acct = rad_malloc(sizeof(*client->acct));
364 memset(client->acct, 0, sizeof(*client->acct));
368 #ifdef WITH_DYNAMIC_CLIENTS
370 * More catching of clients added by rlm_sql.
372 * The sql modules sets the dynamic flag BEFORE calling
373 * us. The client_create() function sets it AFTER
376 if (client->dynamic && (client->lifetime == 0)) {
380 * If there IS an enclosing network,
381 * inherit the lifetime from it.
383 network = client_find(clients, &client->ipaddr);
385 client->lifetime = network->lifetime;
390 client->number = tree_num_max;
392 if (tree_num) rbtree_insert(tree_num, client);
395 if (client->prefix < clients->min_prefix) {
396 clients->min_prefix = client->prefix;
403 #ifdef WITH_DYNAMIC_CLIENTS
404 void client_delete(RADCLIENT_LIST *clients, RADCLIENT *client)
408 if (!clients) clients = root_clients;
410 if (!client->dynamic) return;
412 rad_assert((client->prefix >= 0) && (client->prefix <= 128));
414 client->dynamic = 2; /* signal to client_free */
416 rbtree_deletebydata(tree_num, client);
417 rbtree_deletebydata(clients->trees[client->prefix], client);
423 * Find a client in the RADCLIENTS list by number.
424 * This is a support function for the statistics code.
426 RADCLIENT *client_findbynumber(const RADCLIENT_LIST *clients,
430 if (!clients) clients = root_clients;
432 if (!clients) return NULL;
434 if (number >= tree_num_max) return NULL;
439 myclient.number = number;
441 return rbtree_finddata(tree_num, &myclient);
444 clients = clients; /* -Wunused */
445 number = number; /* -Wunused */
452 * Find a client in the RADCLIENTS list.
454 RADCLIENT *client_find(const RADCLIENT_LIST *clients,
455 const fr_ipaddr_t *ipaddr)
460 if (!clients) clients = root_clients;
462 if (!clients || !ipaddr) return NULL;
464 switch (ipaddr->af) {
477 for (i = max_prefix; i >= clients->min_prefix; i--) {
481 myclient.ipaddr = *ipaddr;
482 client_sane(&myclient); /* clean up the ipaddress */
484 if (!clients->trees[i]) continue;
486 data = rbtree_finddata(clients->trees[i], &myclient);
497 * Old wrapper for client_find
499 RADCLIENT *client_find_old(const fr_ipaddr_t *ipaddr)
501 return client_find(root_clients, ipaddr);
504 static struct in_addr cl_ip4addr;
505 static struct in6_addr cl_ip6addr;
507 static const CONF_PARSER client_config[] = {
508 { "ipaddr", PW_TYPE_IPADDR,
509 0, &cl_ip4addr, NULL },
510 { "ipv6addr", PW_TYPE_IPV6ADDR,
511 0, &cl_ip6addr, NULL },
512 { "netmask", PW_TYPE_INTEGER,
513 offsetof(RADCLIENT, prefix), 0, NULL },
515 { "require_message_authenticator", PW_TYPE_BOOLEAN,
516 offsetof(RADCLIENT, message_authenticator), 0, "no" },
518 { "secret", PW_TYPE_STRING_PTR,
519 offsetof(RADCLIENT, secret), 0, NULL },
520 { "shortname", PW_TYPE_STRING_PTR,
521 offsetof(RADCLIENT, shortname), 0, NULL },
522 { "nastype", PW_TYPE_STRING_PTR,
523 offsetof(RADCLIENT, nastype), 0, NULL },
524 { "login", PW_TYPE_STRING_PTR,
525 offsetof(RADCLIENT, login), 0, NULL },
526 { "password", PW_TYPE_STRING_PTR,
527 offsetof(RADCLIENT, password), 0, NULL },
528 { "virtual_server", PW_TYPE_STRING_PTR,
529 offsetof(RADCLIENT, server), 0, NULL },
530 { "server", PW_TYPE_STRING_PTR, /* compatability with 2.0-pre */
531 offsetof(RADCLIENT, server), 0, NULL },
533 #ifdef WITH_DYNAMIC_CLIENTS
534 { "dynamic_clients", PW_TYPE_STRING_PTR,
535 offsetof(RADCLIENT, client_server), 0, NULL },
536 { "lifetime", PW_TYPE_INTEGER,
537 offsetof(RADCLIENT, lifetime), 0, NULL },
538 { "rate_limit", PW_TYPE_BOOLEAN,
539 offsetof(RADCLIENT, rate_limit), 0, NULL },
543 { "coa_server", PW_TYPE_STRING_PTR,
544 offsetof(RADCLIENT, coa_name), 0, NULL },
547 { NULL, -1, 0, NULL, NULL }
551 static RADCLIENT *client_parse(CONF_SECTION *cs, int in_server)
556 name2 = cf_section_name2(cs);
558 cf_log_err(cf_sectiontoitem(cs),
559 "Missing client name");
564 * The size is fine.. Let's create the buffer
566 c = rad_malloc(sizeof(*c));
567 memset(c, 0, sizeof(*c));
571 c->auth = rad_malloc(sizeof(*c->auth));
572 memset(c->auth, 0, sizeof(*c->auth));
574 #ifdef WITH_ACCOUNTING
575 c->acct = rad_malloc(sizeof(*c->acct));
576 memset(c->acct, 0, sizeof(*c->acct));
580 memset(&cl_ip4addr, 0, sizeof(cl_ip4addr));
581 memset(&cl_ip6addr, 0, sizeof(cl_ip6addr));
584 if (cf_section_parse(cs, c, client_config) < 0) {
586 cf_log_err(cf_sectiontoitem(cs),
587 "Error parsing client section.");
592 * Global clients can set servers to use,
593 * per-server clients cannot.
595 if (in_server && c->server) {
597 cf_log_err(cf_sectiontoitem(cs),
598 "Clients inside of an server section cannot point to a server.");
603 * No "ipaddr" or "ipv6addr", use old-style
604 * "client <ipaddr> {" syntax.
606 if (!cf_pair_find(cs, "ipaddr") &&
607 !cf_pair_find(cs, "ipv6addr")) {
610 prefix_ptr = strchr(name2, '/');
616 c->prefix = atoi(prefix_ptr + 1);
617 if ((c->prefix < 0) || (c->prefix > 128)) {
619 cf_log_err(cf_sectiontoitem(cs),
620 "Invalid Prefix value '%s' for IP.",
624 /* Replace '/' with '\0' */
629 * Always get the numeric representation of IP
631 if (ip_hton(name2, AF_UNSPEC, &c->ipaddr) < 0) {
633 cf_log_err(cf_sectiontoitem(cs),
634 "Failed to look up hostname %s: %s",
635 name2, fr_strerror());
639 if (prefix_ptr) *prefix_ptr = '/';
640 c->longname = strdup(name2);
642 if (!c->shortname) c->shortname = strdup(c->longname);
648 * Figure out which one to use.
650 if (cf_pair_find(cs, "ipaddr")) {
651 c->ipaddr.af = AF_INET;
652 c->ipaddr.ipaddr.ip4addr = cl_ip4addr;
654 if ((c->prefix < -1) || (c->prefix > 32)) {
656 cf_log_err(cf_sectiontoitem(cs),
657 "Netmask must be between 0 and 32");
661 } else if (cf_pair_find(cs, "ipv6addr")) {
662 c->ipaddr.af = AF_INET6;
663 c->ipaddr.ipaddr.ip6addr = cl_ip6addr;
665 if ((c->prefix < -1) || (c->prefix > 128)) {
667 cf_log_err(cf_sectiontoitem(cs),
668 "Netmask must be between 0 and 128");
672 cf_log_err(cf_sectiontoitem(cs),
673 "No IP address defined for the client");
678 ip_ntoh(&c->ipaddr, buffer, sizeof(buffer));
679 c->longname = strdup(buffer);
682 * Set the short name to the name2
684 if (!c->shortname) c->shortname = strdup(name2);
687 if (c->prefix < 0) switch (c->ipaddr.af) {
698 #ifdef WITH_DYNAMIC_CLIENTS
699 if (c->client_server) {
701 c->secret = strdup("testing123");
703 if (((c->ipaddr.af == AF_INET) &&
704 (c->prefix == 32)) ||
705 ((c->ipaddr.af == AF_INET6) &&
706 (c->prefix == 128))) {
707 cf_log_err(cf_sectiontoitem(cs),
708 "Dynamic clients MUST be a network, not a single IP address.");
717 if (!c->secret || !*c->secret) {
719 const char *value = NULL;
720 CONF_PAIR *cp = cf_pair_find(cs, "dhcp");
722 if (cp) value = cf_pair_value(cp);
725 * Secrets aren't needed for DHCP.
727 if (value && (strcmp(value, "yes") == 0)) return c;
731 cf_log_err(cf_sectiontoitem(cs),
732 "secret must be at least 1 character long");
738 * Point the client to the home server pool, OR to the
739 * home server. This gets around the problem of figuring
740 * out which port to use.
743 c->coa_pool = home_pool_byname(c->coa_name, HOME_TYPE_COA);
745 c->coa_server = home_server_byname(c->coa_name,
748 if (!c->coa_pool && !c->coa_server) {
750 cf_log_err(cf_sectiontoitem(cs), "No such home_server or home_server_pool \"%s\"", c->coa_name);
761 * Create the linked list of clients from the new configuration
762 * type. This way we don't have to change too much in the other
765 RADCLIENT_LIST *clients_parse_section(CONF_SECTION *section)
767 int global = FALSE, in_server = FALSE;
770 RADCLIENT_LIST *clients;
773 * Be forgiving. If there's already a clients, return
774 * it. Otherwise create a new one.
776 clients = cf_data_find(section, "clients");
777 if (clients) return clients;
779 clients = clients_init();
780 if (!clients) return NULL;
782 if (cf_top_section(section) == section) global = TRUE;
784 if (strcmp("server", cf_section_name1(section)) == 0) in_server = TRUE;
787 * Associate the clients structure with the section, where
788 * it will be freed once the section is freed.
790 if (cf_data_add(section, "clients", clients, (void *) clients_free) < 0) {
791 cf_log_err(cf_sectiontoitem(section),
792 "Failed to associate clients with section %s",
793 cf_section_name1(section));
794 clients_free(clients);
798 for (cs = cf_subsection_find_next(section, NULL, "client");
800 cs = cf_subsection_find_next(section, cs, "client")) {
801 c = client_parse(cs, in_server);
807 * FIXME: Add the client as data via cf_data_add,
808 * for migration issues.
811 #ifdef WITH_DYNAMIC_CLIENTS
813 if (c->client_server) {
818 struct stat stat_buf;
822 * Find the directory where individual
823 * client definitions are stored.
825 cp = cf_pair_find(cs, "directory");
826 if (!cp) goto add_client;
828 value = cf_pair_value(cp);
830 cf_log_err(cf_sectiontoitem(cs),
831 "The \"directory\" entry must not be empty");
836 DEBUG("including dynamic clients in %s", value);
838 dir = opendir(value);
840 cf_log_err(cf_sectiontoitem(cs), "Error reading directory %s: %s", value, strerror(errno));
846 * Read the directory, ignoring "." files.
848 while ((dp = readdir(dir)) != NULL) {
852 if (dp->d_name[0] == '.') continue;
855 * Check for valid characters
857 for (p = dp->d_name; *p != '\0'; p++) {
858 if (isalpha((int)*p) ||
861 (*p == '.')) continue;
864 if (*p != '\0') continue;
866 snprintf(buf2, sizeof(buf2), "%s/%s",
869 if ((stat(buf2, &stat_buf) != 0) ||
870 S_ISDIR(stat_buf.st_mode)) continue;
872 dc = client_read(buf2, in_server, TRUE);
874 cf_log_err(cf_sectiontoitem(cs),
875 "Failed reading client file \"%s\"", buf2);
881 * Validate, and add to the list.
883 if (!client_validate(clients, c, dc)) {
888 } /* loop over the directory */
890 #endif /* HAVE_DIRENT_H */
891 #endif /* WITH_DYNAMIC_CLIENTS */
894 if (!client_add(clients, c)) {
895 cf_log_err(cf_sectiontoitem(cs),
896 "Failed to add client %s",
897 cf_section_name2(cs));
905 * Replace the global list of clients with the new one.
906 * The old one is still referenced from the original
907 * configuration, and will be freed when that is freed.
910 root_clients = clients;
916 #ifdef WITH_DYNAMIC_CLIENTS
918 * We overload this structure a lot.
920 static const CONF_PARSER dynamic_config[] = {
921 { "FreeRADIUS-Client-IP-Address", PW_TYPE_IPADDR,
922 offsetof(RADCLIENT, ipaddr), 0, NULL },
923 { "FreeRADIUS-Client-IPv6-Address", PW_TYPE_IPV6ADDR,
924 offsetof(RADCLIENT, ipaddr), 0, NULL },
926 { "FreeRADIUS-Client-Require-MA", PW_TYPE_BOOLEAN,
927 offsetof(RADCLIENT, message_authenticator), NULL, NULL },
929 { "FreeRADIUS-Client-Secret", PW_TYPE_STRING_PTR,
930 offsetof(RADCLIENT, secret), 0, "" },
931 { "FreeRADIUS-Client-Shortname", PW_TYPE_STRING_PTR,
932 offsetof(RADCLIENT, shortname), 0, "" },
933 { "FreeRADIUS-Client-NAS-Type", PW_TYPE_STRING_PTR,
934 offsetof(RADCLIENT, nastype), 0, NULL },
935 { "FreeRADIUS-Client-Virtual-Server", PW_TYPE_STRING_PTR,
936 offsetof(RADCLIENT, server), 0, NULL },
938 { NULL, -1, 0, NULL, NULL }
942 int client_validate(RADCLIENT_LIST *clients, RADCLIENT *master, RADCLIENT *c)
947 * No virtual server defined. Inherit the parent's
950 if (master->server && !c->server) {
951 c->server = strdup(master->server);
955 * If the client network isn't global (not tied to a
956 * virtual server), then ensure that this clients server
957 * is the same as the enclosing networks virtual server.
959 if (master->server &&
960 (strcmp(master->server, c->server) != 0)) {
961 DEBUG("- Cannot add client %s: Virtual server %s is not the same as the virtual server for the network.",
963 buffer, sizeof(buffer)),
969 if (!client_add(clients, c)) {
970 DEBUG("- Cannot add client %s: Internal error",
972 buffer, sizeof(buffer)));
978 * Initialize the remaining fields.
981 c->lifetime = master->lifetime;
982 c->created = time(NULL);
983 c->longname = strdup(c->shortname);
985 DEBUG("- Added client %s with shared secret %s",
986 ip_ntoh(&c->ipaddr, buffer, sizeof(buffer)),
997 RADCLIENT *client_create(RADCLIENT_LIST *clients, REQUEST *request)
1004 if (!clients || !request) return NULL;
1006 c = rad_malloc(sizeof(*c));
1007 memset(c, 0, sizeof(*c));
1008 c->cs = request->client->cs;
1009 c->ipaddr.af = AF_UNSPEC;
1011 for (i = 0; dynamic_config[i].name != NULL; i++) {
1015 da = dict_attrbyname(dynamic_config[i].name);
1017 DEBUG("- Cannot add client %s: attribute \"%s\"is not in the dictionary",
1018 ip_ntoh(&request->packet->src_ipaddr,
1019 buffer, sizeof(buffer)),
1020 dynamic_config[i].name);
1026 vp = pairfind(request->config_items, da->attr);
1029 * Not required. Skip it.
1031 if (!dynamic_config[i].dflt) continue;
1033 DEBUG("- Cannot add client %s: Required attribute \"%s\" is missing.",
1034 ip_ntoh(&request->packet->src_ipaddr,
1035 buffer, sizeof(buffer)),
1036 dynamic_config[i].name);
1040 switch (dynamic_config[i].type) {
1041 case PW_TYPE_IPADDR:
1042 c->ipaddr.af = AF_INET;
1043 c->ipaddr.ipaddr.ip4addr.s_addr = vp->vp_ipaddr;
1047 case PW_TYPE_IPV6ADDR:
1048 c->ipaddr.af = AF_INET6;
1049 c->ipaddr.ipaddr.ip6addr = vp->vp_ipv6addr;
1053 case PW_TYPE_STRING_PTR:
1054 p = (char **) ((char *) c + dynamic_config[i].offset);
1056 *p = strdup(vp->vp_strvalue);
1059 case PW_TYPE_BOOLEAN:
1060 pi = (int *) ((char *) c + dynamic_config[i].offset);
1061 *pi = vp->vp_integer;
1069 if (c->ipaddr.af == AF_UNSPEC) {
1070 DEBUG("- Cannot add client %s: No IP address was specified.",
1071 ip_ntoh(&request->packet->src_ipaddr,
1072 buffer, sizeof(buffer)));
1077 if (fr_ipaddr_cmp(&request->packet->src_ipaddr, &c->ipaddr) != 0) {
1080 DEBUG("- Cannot add client %s: IP address %s do not match",
1081 ip_ntoh(&request->packet->src_ipaddr,
1082 buffer, sizeof(buffer)),
1084 buf2, sizeof(buf2)));
1088 if (!client_validate(clients, request->client, c)) {
1096 * Read a client definition from the given filename.
1098 RADCLIENT *client_read(const char *filename, int in_server, int flag)
1105 if (!filename) return NULL;
1107 cs = cf_file_read(filename);
1108 if (!cs) return NULL;
1110 c = client_parse(cf_section_sub_find(cs, "client"), in_server);
1112 p = strrchr(filename, FR_DIR_SEP);
1119 if (!flag) return c;
1122 * Additional validations
1124 ip_ntoh(&c->ipaddr, buffer, sizeof(buffer));
1125 if (strcmp(p, buffer) != 0) {
1126 DEBUG("Invalid client definition in %s: IP address %s does not match name %s", filename, buffer, p);