From: Ted Lemon Date: Tue, 28 Nov 2000 23:10:28 +0000 (+0000) Subject: - Pass client state to eval functions. X-Git-Tag: V3-BETA-1-PATCH-11~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd15a833d1324e8d0169389c4f84d5c544b63747;p=thirdparty%2Fdhcp.git - Pass client state to eval functions. - Fix a couple of bugs in agent option handling. --- diff --git a/common/options.c b/common/options.c index c4667080b..cfbc5e82a 100644 --- a/common/options.c +++ b/common/options.c @@ -43,7 +43,7 @@ #ifndef lint static char copyright[] = -"$Id: options.c,v 1.69 2000/11/24 04:00:04 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n"; +"$Id: options.c,v 1.70 2000/11/28 23:10:28 mellon Exp $ Copyright (c) 1995-2000 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #define DHCP_OPTION_DATA @@ -142,14 +142,22 @@ int parse_option_buffer (options, buffer, length, universe) continue; } + /* Don't look for length if the buffer isn't that big. */ + if (offset + 2 > length) { + len = 65536; + goto bogus; + } + /* All other fields (except end, see above) have a one-byte length. */ len = buffer [offset + 1]; /* If the length is outrageous, the options are bad. */ if (offset + len + 2 > length) { - log_error ("Client option %s (%d) larger than buffer.", - dhcp_options [code].name, len); + bogus: + log_error ("parse_option_buffer: option %s (%d) %s.", + dhcp_options [code].name, len, + "larger than buffer"); buffer_dereference (&bp, MDL); return 0; } @@ -353,11 +361,13 @@ int fqdn_universe_decode (struct option_state *options, three seperate buffers if needed. This allows us to cons up a set of vendor options using the same routine. */ -int cons_options (inpacket, outpacket, lease, mms, in_options, cfg_options, +int cons_options (inpacket, outpacket, lease, client_state, + mms, in_options, cfg_options, scope, overload, terminate, bootpp, prl, vuname) struct packet *inpacket; struct dhcp_packet *outpacket; struct lease *lease; + struct client_state *client_state; int mms; struct option_state *in_options; struct option_state *cfg_options; @@ -390,7 +400,8 @@ int cons_options (inpacket, outpacket, lease, mms, in_options, cfg_options, if (!mms && inpacket && (op = lookup_option (&dhcp_universe, inpacket -> options, DHO_DHCP_MAX_MESSAGE_SIZE))) { - evaluate_option_cache (&ds, inpacket, lease, in_options, + evaluate_option_cache (&ds, inpacket, + lease, client_state, in_options, cfg_options, scope, op, MDL); if (ds.len >= sizeof (u_int16_t)) mms = getUShort (ds.data); @@ -520,8 +531,7 @@ int cons_options (inpacket, outpacket, lease, mms, in_options, cfg_options, (main_buffer_size - 7 + ((overload & 1) ? DHCP_FILE_LEN : 0) + ((overload & 2) ? DHCP_SNAME_LEN : 0)), - inpacket, - lease, + inpacket, lease, client_state, in_options, cfg_options, scope, priority_list, priority_len, main_buffer_size, @@ -595,10 +605,10 @@ int cons_options (inpacket, outpacket, lease, mms, in_options, cfg_options, /* Now hack in the agent options if there are any. */ priority_list [0] = DHO_DHCP_AGENT_OPTIONS; priority_len = 1; - agentix += + length += store_options (&outpacket -> options [agentix], 1500 - DHCP_FIXED_LEN - agentix, - inpacket, lease, + inpacket, lease, client_state, in_options, cfg_options, scope, priority_list, priority_len, 1500 - DHCP_FIXED_LEN - agentix, @@ -608,13 +618,14 @@ int cons_options (inpacket, outpacket, lease, mms, in_options, cfg_options, /* Store all the requested options into the requested buffer. */ -int store_options (buffer, buflen, packet, lease, +int store_options (buffer, buflen, packet, lease, client_state, in_options, cfg_options, scope, priority_list, priority_len, first_cutoff, second_cutoff, terminate, vuname) unsigned char *buffer; unsigned buflen; struct packet *packet; struct lease *lease; + struct client_state *client_state; struct option_state *in_options; struct option_state *cfg_options; struct binding_scope **scope; @@ -701,6 +712,7 @@ int store_options (buffer, buflen, packet, lease, vendor_cfg_option -> code); if (tmp) evaluate_option_cache (&name, packet, lease, + client_state, in_options, cfg_options, scope, tmp, MDL); @@ -719,7 +731,7 @@ int store_options (buffer, buflen, packet, lease, memset (&encapsulation, 0, sizeof encapsulation); have_encapsulation = (option_space_encapsulate - (&encapsulation, packet, lease, + (&encapsulation, packet, lease, client_state, in_options, cfg_options, scope, &name)); data_string_forget (&name, MDL); } @@ -741,7 +753,8 @@ int store_options (buffer, buflen, packet, lease, /* Find the value of the option... */ if (oc) { - evaluate_option_cache (&od, packet, lease, in_options, + evaluate_option_cache (&od, packet, + lease, client_state, in_options, cfg_options, scope, oc, MDL); if (!od.len) { data_string_forget (&encapsulation, MDL); @@ -1043,12 +1056,13 @@ const char *pretty_print_option (option, data, len, emit_commas, emit_quotes) return optbuf; } -int get_option (result, universe, packet, lease, +int get_option (result, universe, packet, lease, client_state, in_options, cfg_options, options, scope, code) struct data_string *result; struct universe *universe; struct packet *packet; struct lease *lease; + struct client_state *client_state; struct option_state *in_options; struct option_state *cfg_options; struct option_state *options; @@ -1062,8 +1076,8 @@ int get_option (result, universe, packet, lease, oc = ((*universe -> lookup_func) (universe, options, code)); if (!oc) return 0; - if (!evaluate_option_cache (result, packet, lease, in_options, - cfg_options, scope, oc, MDL)) + if (!evaluate_option_cache (result, packet, lease, client_state, + in_options, cfg_options, scope, oc, MDL)) return 0; return 1; } @@ -1435,12 +1449,13 @@ int hashed_option_state_dereference (universe, state, file, line) return 1; } -int store_option (result, universe, packet, lease, +int store_option (result, universe, packet, lease, client_state, in_options, cfg_options, scope, oc) struct data_string *result; struct universe *universe; struct packet *packet; struct lease *lease; + struct client_state *client_state; struct option_state *in_options; struct option_state *cfg_options; struct binding_scope **scope; @@ -1451,8 +1466,8 @@ int store_option (result, universe, packet, lease, memset (&d1, 0, sizeof d1); memset (&d2, 0, sizeof d2); - if (evaluate_option_cache (&d2, packet, lease, in_options, - cfg_options, scope, oc, MDL)) { + if (evaluate_option_cache (&d2, packet, lease, client_state, + in_options, cfg_options, scope, oc, MDL)) { if (!buffer_allocate (&d1.buffer, (result -> len + universe -> length_size + @@ -1483,11 +1498,12 @@ int store_option (result, universe, packet, lease, return 0; } -int option_space_encapsulate (result, packet, lease, +int option_space_encapsulate (result, packet, lease, client_state, in_options, cfg_options, scope, name) struct data_string *result; struct packet *packet; struct lease *lease; + struct client_state *client_state; struct option_state *in_options; struct option_state *cfg_options; struct binding_scope **scope; @@ -1503,17 +1519,19 @@ int option_space_encapsulate (result, packet, lease, if (u -> encapsulate) return (*u -> encapsulate) (result, packet, lease, + client_state, in_options, cfg_options, scope, u); log_error ("encapsulation requested for %s with no support.", name -> data); return 0; } -int hashed_option_space_encapsulate (result, packet, lease, +int hashed_option_space_encapsulate (result, packet, lease, client_state, in_options, cfg_options, scope, universe) struct data_string *result; struct packet *packet; struct lease *lease; + struct client_state *client_state; struct option_state *in_options; struct option_state *cfg_options; struct binding_scope **scope; @@ -1533,8 +1551,9 @@ int hashed_option_space_encapsulate (result, packet, lease, status = 0; for (i = 0; i < OPTION_HASH_SIZE; i++) { for (p = hash [i]; p; p = p -> cdr) { - if (store_option (result, universe, packet, lease, - in_options, cfg_options, scope, + if (store_option (result, universe, packet, + lease, client_state, in_options, + cfg_options, scope, (struct option_cache *)p -> car)) status = 1; } @@ -1543,11 +1562,12 @@ int hashed_option_space_encapsulate (result, packet, lease, return status; } -int nwip_option_space_encapsulate (result, packet, lease, +int nwip_option_space_encapsulate (result, packet, lease, client_state, in_options, cfg_options, scope, universe) struct data_string *result; struct packet *packet; struct lease *lease; + struct client_state *client_state; struct option_state *in_options; struct option_state *cfg_options; struct binding_scope **scope; @@ -1566,8 +1586,9 @@ int nwip_option_space_encapsulate (result, packet, lease, status = 0; for (i = 0; hash && i < OPTION_HASH_SIZE; i++) { for (p = hash [i]; p; p = p -> cdr) { - if (store_option (result, universe, packet, lease, - in_options, cfg_options, scope, + if (store_option (result, universe, packet, + lease, client_state, in_options, + cfg_options, scope, (struct option_cache *)p -> car)) status = 1; } @@ -1587,8 +1608,8 @@ int nwip_option_space_encapsulate (result, packet, lease, } if (no_nwip) { if (store_option (result, universe, packet, lease, - in_options, cfg_options, - scope, no_nwip)) + client_state, in_options, + cfg_options, scope, no_nwip)) status = 1; } } else { @@ -1610,11 +1631,12 @@ int nwip_option_space_encapsulate (result, packet, lease, return status; } -int fqdn_option_space_encapsulate (result, packet, lease, +int fqdn_option_space_encapsulate (result, packet, lease, client_state, in_options, cfg_options, scope, universe) struct data_string *result; struct packet *packet; struct lease *lease; + struct client_state *client_state; struct option_state *in_options; struct option_state *cfg_options; struct binding_scope **scope; @@ -1638,7 +1660,7 @@ int fqdn_option_space_encapsulate (result, packet, lease, if (oc -> option -> code > FQDN_SUBOPTION_COUNT) continue; evaluate_option_cache (&results [oc -> option -> code], - packet, lease, in_options, + packet, lease, client_state, in_options, cfg_options, scope, oc, MDL); } len = 4 + results [FQDN_NAME].len; @@ -1707,30 +1729,34 @@ int fqdn_option_space_encapsulate (result, packet, lease, } void option_space_foreach (struct packet *packet, struct lease *lease, + struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct universe *u, void *stuff, void (*func) (struct option_cache *, struct packet *, - struct lease *, struct option_state *, + struct lease *, struct client_state *, + struct option_state *, struct option_state *, struct binding_scope **, struct universe *, void *)) { if (u -> foreach) - (*u -> foreach) (packet, lease, in_options, cfg_options, - scope, u, stuff, func); + (*u -> foreach) (packet, lease, client_state, in_options, + cfg_options, scope, u, stuff, func); } void suboption_foreach (struct packet *packet, struct lease *lease, + struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct universe *u, void *stuff, void (*func) (struct option_cache *, struct packet *, - struct lease *, struct option_state *, + struct lease *, struct client_state *, + struct option_state *, struct option_state *, struct binding_scope **, struct universe *, void *), @@ -1742,11 +1768,13 @@ void suboption_foreach (struct packet *packet, struct lease *lease, int i; if (universe -> foreach) - (*universe -> foreach) (packet, lease, in_options, cfg_options, + (*universe -> foreach) (packet, lease, client_state, + in_options, cfg_options, scope, universe, stuff, func); } void hashed_option_space_foreach (struct packet *packet, struct lease *lease, + struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, @@ -1754,6 +1782,7 @@ void hashed_option_space_foreach (struct packet *packet, struct lease *lease, void (*func) (struct option_cache *, struct packet *, struct lease *, + struct client_state *, struct option_state *, struct option_state *, struct binding_scope **, @@ -1774,7 +1803,7 @@ void hashed_option_space_foreach (struct packet *packet, struct lease *lease, /* XXX save _all_ options! XXX */ for (p = hash [i]; p; p = p -> cdr) { oc = (struct option_cache *)p -> car; - (*func) (oc, packet, lease, + (*func) (oc, packet, lease, client_state, in_options, cfg_options, scope, u, stuff); } } @@ -1804,11 +1833,12 @@ void save_linked_option (universe, options, oc) option_cache_reference (tail, oc, MDL); } -int linked_option_space_encapsulate (result, packet, lease, +int linked_option_space_encapsulate (result, packet, lease, client_state, in_options, cfg_options, scope, universe) struct data_string *result; struct packet *packet; struct lease *lease; + struct client_state *client_state; struct option_state *in_options; struct option_state *cfg_options; struct binding_scope **scope; @@ -1824,8 +1854,9 @@ int linked_option_space_encapsulate (result, packet, lease, for (oc = ((struct option_cache *) cfg_options -> universes [universe -> index]); oc; oc = oc -> next) { - if (store_option (result, universe, packet, lease, - in_options, cfg_options, scope, oc)) + if (store_option (result, universe, packet, + lease, client_state, in_options, cfg_options, + scope, oc)) status = 1; } @@ -1896,17 +1927,19 @@ int linked_option_state_dereference (universe, state, file, line) } void linked_option_space_foreach (struct packet *packet, struct lease *lease, - struct option_state *in_options, - struct option_state *cfg_options, - struct binding_scope **scope, - struct universe *u, void *stuff, - void (*func) (struct option_cache *, - struct packet *, - struct lease *, - struct option_state *, - struct option_state *, - struct binding_scope **, - struct universe *, void *)) + struct client_state *client_state, + struct option_state *in_options, + struct option_state *cfg_options, + struct binding_scope **scope, + struct universe *u, void *stuff, + void (*func) (struct option_cache *, + struct packet *, + struct lease *, + struct client_state *, + struct option_state *, + struct option_state *, + struct binding_scope **, + struct universe *, void *)) { struct option_cache *oc; @@ -1916,7 +1949,7 @@ void linked_option_space_foreach (struct packet *packet, struct lease *lease, for (oc = ((struct option_cache *) cfg_options -> universes [u -> index]); oc; oc = oc -> next) { - (*func) (oc, packet, lease, + (*func) (oc, packet, lease, client_state, in_options, cfg_options, scope, u, stuff); } } @@ -1972,6 +2005,7 @@ void do_packet (interface, packet, len, from_port, from, hfrom) memset (&dp, 0, sizeof dp); evaluate_option_cache (&dp, decoded_packet, (struct lease *)0, + (struct client_state *)0, decoded_packet -> options, (struct option_state *)0, (struct binding_scope **)0,