34 #define NUM_DEFAULT_REQUESTED_OPTS 15 37 static void parse_client_default_duid(
struct parse *cfile);
38 static void parse_client6_lease_statement(
struct parse *cfile);
40 static struct dhc6_ia *parse_client6_ia_na_statement(
struct parse *cfile);
41 static struct dhc6_ia *parse_client6_ia_ta_statement(
struct parse *cfile);
42 static struct dhc6_ia *parse_client6_ia_pd_statement(
struct parse *cfile);
43 static struct dhc6_addr *parse_client6_iaaddr_statement(
struct parse *cfile);
44 static struct dhc6_addr *parse_client6_iaprefix_statement(
struct parse *cfile);
69 memset(default_requested_options, 0,
sizeof(default_requested_options));
73 option_code_hash_lookup(&default_requested_options[0],
78 option_code_hash_lookup(&default_requested_options[1],
83 option_code_hash_lookup(&default_requested_options[2],
92 option_code_hash_lookup(&default_requested_options[3],
97 option_code_hash_lookup(&default_requested_options[4],
102 option_code_hash_lookup(&default_requested_options[5],
107 option_code_hash_lookup(&default_requested_options[6],
112 option_code_hash_lookup(&default_requested_options[7],
117 option_code_hash_lookup(&default_requested_options[8],
122 option_code_hash_lookup(&default_requested_options[9],
127 option_code_hash_lookup(&default_requested_options[10],
132 option_code_hash_lookup(&default_requested_options[11],
137 option_code_hash_lookup(&default_requested_options[12],
142 option_code_hash_lookup(&default_requested_options[13],
147 option_code_hash_lookup(&default_requested_options[14],
151 if (default_requested_options[code] == NULL)
152 log_fatal(
"Unable to find option definition for " 153 "index %u during default parameter request " 189 log_fatal (
"no memory for top-level on_receipt group");
193 log_fatal (
"no memory for top-level on_transmission group");
199 if (status != ISC_R_SUCCESS) {
203 status =
new_parse(&parse, -1, default_client_config,
204 sizeof(default_client_config) - 1,
205 "default client configuration", 0);
206 if (status != ISC_R_SUCCESS)
207 log_fatal (
"can't begin default client config!");
229 log_fatal (
"no memory for client state.");
230 memset (ip -> client, 0,
sizeof *(ip -> client));
231 ip -> client ->
interface = ip;
234 if (!ip -> client -> config) {
240 log_fatal (
"no memory for client config.");
244 ip -> client -> config = config;
259 if ((file = open (name, O_RDONLY | O_CLOEXEC)) < 0)
264 if (status != ISC_R_SUCCESS || cfile == NULL)
268 token =
peek_token (&val, (
unsigned *)0, cfile);
304 if (status != ISC_R_SUCCESS || cfile == NULL)
314 parse_client_default_duid(cfile);
340 if (status != ISC_R_SUCCESS || cfile == NULL)
344 token =
next_token (&val, (
unsigned *)0, cfile);
350 parse_client_default_duid(cfile);
358 parse_client6_lease_statement(cfile);
362 log_error (
"Corrupt lease file - possible data loss!");
409 struct option ***append_list, **new_list, **cat_list;
411 switch (
peek_token (&val, (
unsigned *)0, cfile)) {
414 token =
next_token (&val, (
unsigned *)0, cfile);
416 parse_warn (cfile,
"filename string expected.");
420 if (status != ISC_R_SUCCESS)
441 parse_warn (cfile,
"key definition not allowed here.");
460 parse_warn(cfile,
"expected REQUEST or REQUIRE list");
466 if (*append_list == NULL) {
472 for (i = 0 ; (*append_list)[i] != NULL ; i++)
483 if (tmp == 0 || new_list == NULL)
487 cat_list =
dmalloc(
sizeof(
struct option *) * (i + tmp + 1),
490 if (cat_list == NULL) {
491 log_error(
"Unable to allocate memory for new " 497 for (i = 0 ; (*append_list)[i] != NULL ; i++)
502 for (i = 0 ; new_list[i] != 0 ; i++)
511 *append_list = cat_list;
519 token =
peek_token (&val, (
unsigned *)0, cfile);
548 token =
next_token (&val, (
unsigned *)0, cfile);
554 "invalid authentication policy.");
558 config -> auth_policy =
policy;
567 config -> bootp_policy =
policy;
569 parse_warn (cfile,
"expecting a policy type.");
577 token =
peek_token (&val, (
unsigned *)0, cfile);
578 if (token ==
SPACE) {
581 "option space definitions %s",
582 " may not be scoped.");
592 if (status != ISC_R_SUCCESS || option == NULL)
595 token =
next_token (&val, (
unsigned *)0, cfile);
597 parse_warn (cfile,
"expecting \"code\" keyword.");
604 "option definitions may only appear in %s",
605 "the outermost scope.");
636 parse_warn (cfile,
"hardware address parameter %s",
637 "not allowed here.");
647 parse_warn(cfile,
"anycast mac address parameter " 648 "not allowed here.");
655 if (config -> requested_options == default_requested_options)
656 config -> requested_options = NULL;
677 token =
next_token (&val, (
unsigned *)0, cfile);
680 "unexpected omapi subtype: %s", val);
684 token =
next_token (&val, (
unsigned *)0, cfile);
686 parse_warn (cfile,
"invalid port number: `%s'", val);
691 if (tmp < 0 || tmp > 65535)
692 parse_warn (cfile,
"invalid omapi port %d.", tmp);
695 "omapi port only works at top level.");
703 token =
next_token (&val, (
unsigned *)0, cfile);
704 if (!strcasecmp (val,
"on") ||
705 !strcasecmp (val,
"true"))
706 config -> do_forward_update = 1;
707 else if (!strcasecmp (val,
"off") ||
708 !strcasecmp (val,
"false"))
709 config -> do_forward_update = 0;
711 parse_warn (cfile,
"expecting boolean value.");
740 parse_string (cfile, &config -> script_name, (
unsigned *)0);
745 token =
next_token (&val, (
unsigned *)0, cfile);
747 parse_warn (cfile,
"expecting 'vendor option space'");
751 token =
next_token (&val, (
unsigned *)0, cfile);
752 if (token !=
SPACE) {
753 parse_warn (cfile,
"expecting 'vendor option space'");
757 token =
next_token (&val, (
unsigned *)0, cfile);
759 parse_warn (cfile,
"expecting an identifier.");
763 config -> vendor_space_name =
dmalloc (strlen (val) + 1,
MDL);
764 if (!config -> vendor_space_name)
765 log_fatal (
"no memory for vendor option space name.");
766 strcpy (config -> vendor_space_name, val);
769 config -> vendor_space_name))
771 if (i == universe_count) {
772 log_error (
"vendor option space %s not found.",
773 config -> vendor_space_name);
781 parse_warn (cfile,
"nested interface declaration.");
787 token =
next_token (&val, (
unsigned *)0, cfile);
790 log_fatal (
"no memory for pseudo interface name");
811 token =
next_token(&val, (
unsigned*)0, cfile);
831 eptr = &config -> on_transmission ->
statements;
836 stmt ->
data.on.statements,
MDL);
849 for (; *eptr; eptr = &(*eptr) ->
next)
876 token =
peek_token (&val, (
unsigned *)0, cfile);
878 token =
next_token (&val, (
unsigned *)0, cfile);
882 parse_warn (cfile,
"%s: expected option name.", val);
888 if (status != ISC_R_SUCCESS || option == NULL) {
889 parse_warn (cfile,
"%s: expected option name.", val);
894 log_fatal (
"can't allocate pair for option code.");
896 r->car = (caddr_t)option;
905 token =
next_token (&val, (
unsigned *)0, cfile);
906 }
while (token ==
COMMA);
916 *list =
dmalloc ((ix + 1) *
sizeof(
struct option *),
MDL);
918 log_error (
"no memory for option list.");
921 for (q = p; q; q = q -> cdr)
923 (
struct option *)q->car,
MDL);
949 token =
next_token (&val, (
unsigned *)0, cfile);
951 parse_warn (cfile,
"expecting interface name (in quotes).");
957 log_fatal (
"Can't allocate interface %s.", val);
962 client -> name =
name;
963 client ->
interface = ip;
964 for (cp = &ip -> client; *cp; cp = &((*cp) -> next))
970 ip -> client ->
interface = ip;
972 client = ip -> client;
975 if (!client -> config)
981 token =
next_token (&val, (
unsigned *)0, cfile);
989 token =
peek_token (&val, (
unsigned *)0, cfile);
992 "unterminated interface declaration.");
1006 isc_result_t status;
1010 if (!strcmp (i -> name, name)) {
1011 interface_reference (&ip, i,
MDL);
1019 if (!strcmp (ip -> name, name)) {
1020 interface_reference (&ip, i,
MDL);
1029 if ((status = interface_allocate (&ip,
MDL)) != ISC_R_SUCCESS)
1030 log_fatal (
"Can't record interface %s: %s",
1031 name, isc_result_totext (status));
1033 if (strlen(name) >=
sizeof(ip->
name)) {
1034 interface_dereference(&ip,
MDL);
1037 strcpy(ip->
name, name);
1040 interface_reference (&ip ->
next,
1047 status = interface_reference (pi, ip,
MDL);
1049 status = ISC_R_FAILURE;
1050 interface_dereference (&ip,
MDL);
1051 if (status != ISC_R_SUCCESS)
1061 log_fatal (
"no memory for client state\n");
1062 memset (*state, 0,
sizeof **state);
1071 if (!client -> config)
1072 log_fatal (
"no memory for client config\n");
1073 memcpy (client -> config, config,
sizeof *config);
1078 log_fatal (
"no memory for client state groups.");
1091 struct
parse *cfile;
1100 token =
next_token (&val, (
unsigned *)0, cfile);
1111 memset (lease, 0,
sizeof *lease);
1114 log_fatal (
"no memory for lease options.\n");
1117 token =
peek_token (&val, (
unsigned *)0, cfile);
1119 parse_warn (cfile,
"unterminated lease declaration.");
1136 if (!ip -> client) {
1138 ip -> client ->
interface = ip;
1141 client = ip -> client;
1144 if (is_static == 2) {
1145 ip -> client -> alias = lease;
1154 for (lp = client -> leases; lp; lp =
next) {
1162 client -> leases =
next;
1172 lease -> next = client -> leases;
1173 client -> leases = lease;
1188 if (client -> active) {
1198 client -> active -> next = client -> leases;
1199 client -> leases = client -> active;
1202 client -> active = lease;
1220 struct
parse *cfile;
1231 switch (
next_token (&val, (
unsigned *)0, cfile)) {
1233 token =
next_token (&val, (
unsigned *)0, cfile);
1245 lease -> is_bootp = 1;
1249 token =
next_token (&val, (
unsigned *)0, cfile);
1252 "expecting interface name (in quotes).");
1257 log_fatal (
"Can't allocate interface %s.", val);
1261 token =
next_token (&val, (
unsigned *)0, cfile);
1264 parse_warn (cfile,
"state name precedes interface.");
1267 for (client = ip -> client; client; client = client ->
next)
1268 if (client ->
name && !strcmp (client ->
name, val))
1272 "lease specified for unknown pseudo.");
1286 parse_string (cfile, &lease -> filename, (
unsigned *)0);
1290 parse_string (cfile, &lease -> server_name, (
unsigned *)0);
1314 parse_warn (cfile,
"expecting lease declaration.");
1318 token =
next_token (&val, (
unsigned *)0, cfile);
1319 if (token !=
SEMI) {
1328 parse_client_default_duid(
struct parse *cfile)
1331 const char *val = NULL;
1335 memset(&new_duid, 0,
sizeof(new_duid));
1351 parse_warn(cfile,
"Out of memory parsing default DUID.");
1376 parse_client6_lease_statement(
struct parse *cfile)
1378 #if !defined(DHCPv6) 1390 int token, has_ia, no_semi, has_name;
1394 parse_warn(cfile,
"Expecting open curly brace.");
1400 if (lease == NULL) {
1401 parse_warn(cfile,
"Unable to allocate lease state.");
1408 parse_warn(cfile,
"Unable to allocate option cache.");
1418 while (token !=
RBRACE) {
1423 *ia = parse_client6_ia_na_statement(cfile);
1434 *ia = parse_client6_ia_ta_statement(cfile);
1445 *ia = parse_client6_ia_pd_statement(cfile);
1456 if (iface != NULL) {
1457 parse_warn(cfile,
"Multiple interface names?");
1473 iface = iface->
next) {
1474 if (strcmp(iface->
name, val) == 0)
1478 if (iface == NULL) {
1488 if (client != NULL) {
1495 if (iface == NULL) {
1507 for (client = iface->
client ; client != NULL ;
1508 client = client->
next) {
1509 if ((client->
name != NULL) &&
1510 (strcmp(client->
name, val) == 0))
1514 if (client == NULL) {
1515 parse_warn(cfile,
"Unknown client state %s.",
1537 parse_warn(cfile,
"Unexpected token, %s.", val);
1549 parse_warn(cfile,
"Unexpected end of file.");
1555 log_debug(
"Lease with no IA's discarded from lease db.");
1561 parse_warn(cfile,
"Lease has no interface designation.");
1562 else if (!has_name && (client == NULL)) {
1563 for (client = iface->
client ; client != NULL ;
1564 client = client->
next) {
1565 if (client->
name == NULL)
1570 if (client == NULL) {
1571 parse_warn(cfile,
"No matching client state.");
1577 memset(&ds, 0,
sizeof(ds));
1583 log_error(
"Invalid length of DHCPv6 Preference option " 1584 "(%d != 1)", ds.
len);
1602 log_error(
"Invalid SERVERID option cache.");
1618 parse_client6_ia_na_statement(
struct parse *cfile)
1624 int token, no_semi, len;
1629 parse_warn(cfile,
"Out of memory allocating IA_NA state.");
1638 memcpy(ia->
iaid, buf, 4);
1640 parse_warn(cfile,
"Expecting IAID of length 4, got %d.", len);
1648 parse_warn(cfile,
"Expecting open curly brace.");
1656 parse_warn(cfile,
"Unable to allocate option state.");
1664 while (token !=
RBRACE) {
1682 ia->
renew = atoi(val);
1702 *addr = parse_client6_iaaddr_statement(cfile);
1705 addr = &(*addr)->
next;
1733 parse_warn(cfile,
"Unexpected end of file.");
1746 parse_client6_ia_ta_statement(
struct parse *cfile)
1752 int token, no_semi, len;
1757 parse_warn(cfile,
"Out of memory allocating IA_TA state.");
1766 memcpy(ia->
iaid, buf, 4);
1768 parse_warn(cfile,
"Expecting IAID of length 4, got %d.", len);
1776 parse_warn(cfile,
"Expecting open curly brace.");
1784 parse_warn(cfile,
"Unable to allocate option state.");
1792 while (token !=
RBRACE) {
1810 *addr = parse_client6_iaaddr_statement(cfile);
1813 addr = &(*addr)->
next;
1841 parse_warn(cfile,
"Unexpected end of file.");
1854 parse_client6_ia_pd_statement(
struct parse *cfile)
1860 int token, no_semi, len;
1865 parse_warn(cfile,
"Out of memory allocating IA_PD state.");
1874 memcpy(ia->
iaid, buf, 4);
1876 parse_warn(cfile,
"Expecting IAID of length 4, got %d.", len);
1884 parse_warn(cfile,
"Expecting open curly brace.");
1892 parse_warn(cfile,
"Unable to allocate option state.");
1900 while (token !=
RBRACE) {
1918 ia->
renew = atoi(val);
1938 *pref = parse_client6_iaprefix_statement(cfile);
1941 pref = &(*pref)->
next;
1969 parse_warn(cfile,
"Unexpected end of file.");
1981 parse_client6_iaaddr_statement(
struct parse *cfile)
1990 parse_warn(cfile,
"Unable to allocate IAADDR state.");
2004 parse_warn(cfile,
"Expecting open curly bracket.");
2012 parse_warn(cfile,
"Unable to allocate option state.");
2019 while (token !=
RBRACE) {
2026 addr->
starts = atoi(val);
2077 parse_warn(cfile,
"Unexpected end of file.");
2089 parse_client6_iaprefix_statement(
struct parse *cfile)
2098 parse_warn(cfile,
"Unable to allocate IAPREFIX state.");
2112 parse_warn(cfile,
"Expecting open curly bracket.");
2120 parse_warn(cfile,
"Unable to allocate option state.");
2127 while (token !=
RBRACE) {
2134 pref->
starts = atoi(val);
2185 parse_warn(cfile,
"Unexpected end of file.");
2195 struct
parse *cfile;
2205 for (cur = *lp; cur ->
next; cur = cur ->
next)
2212 token =
next_token (&val, (
unsigned *)0, cfile);
2214 parse_warn (cfile,
"Expecting media options.");
2223 log_fatal (
"no memory for string list entry.");
2225 strcpy (tmp ->
string, val);
2235 token =
next_token (&val, (
unsigned *)0, cfile);
2236 }
while (multiple && token ==
COMMA);
2238 if (token !=
SEMI) {
2245 struct
parse *cfile;
2272 for (i=0 ; i < match.
mask.
len ; i++) {
2280 parse_warn(cfile,
"zero-length prefix is not permitted " 2281 "for reject statement");
2288 log_fatal (
"no memory for reject list!");
2294 token =
next_token (&val, (
unsigned *)0, cfile);
2295 }
while (token ==
COMMA);
2297 if (token !=
SEMI) {
2310 struct
parse *cfile;
2313 parse_warn (cfile,
"allow/deny/ignore not permitted here.");
void parse_option_space_decl(struct parse *cfile)
int parse_X(struct parse *cfile, u_int8_t *buf, unsigned max)
int executable_statement_reference(struct executable_statement **ptr, struct executable_statement *bp, const char *file, int line)
isc_result_t parse_option_name(struct parse *cfile, int allocate, int *known, struct option **opt)
struct binding_scope * global_scope
int parse_option_code_definition(struct parse *cfile, struct option *option)
struct universe * universe
struct group * on_receipt
void save_option(struct universe *universe, struct option_state *options, struct option_cache *oc)
int executable_statement_dereference(struct executable_statement **ptr, const char *file, int line)
int parse_ip_addr_with_subnet(struct parse *cfile, struct iaddrmatch *match)
#define DHO_DOMAIN_SEARCH
int interface_or_dummy(struct interface_info **pi, const char *name)
isc_result_t end_parse(struct parse **cfile)
const char * path_dhclient_db
int parse_key(struct parse *cfile)
void * dmalloc(unsigned, const char *, int)
int option_cache_dereference(struct option_cache **ptr, const char *file, int line)
struct group * on_transmission
int int int log_debug(const char *,...) __attribute__((__format__(__printf__
struct client_state * client
enum executable_statement::statement_op op
void parse_client_lease_statement(struct parse *cfile, int is_static)
isc_result_t omapi_auth_key_lookup_name(omapi_auth_key_t **, const char *)
struct client_state * next
pair new_pair(char *file, int line) const
void parse_interface_declaration(struct parse *cfile, struct client_config *outer_config, char *name)
int option_reference(struct option **dest, struct option *src, const char *file, int line)
struct universe dhcp_universe
struct option_state * options
void data_string_forget(struct data_string *data, const char *file, int line)
#define DHO_INTERFACE_MTU
int parse_allow_deny(struct option_cache **oc, struct parse *cfile, int flag)
int log_error(const char *,...) __attribute__((__format__(__printf__
int parse_semi(struct parse *cfile)
struct executable_statement * next
#define NUM_DEFAULT_REQUESTED_OPTS
#define DHO_DOMAIN_NAME_SERVERS
struct dhc6_ia * bindings
void parse_string_list(struct parse *cfile, struct string_list **lp, int multiple)
const char * path_dhclient_duid
enum dhcp_token peek_token(const char **rval, unsigned *rlen, struct parse *cfile)
struct data_string default_duid
void make_client_config(struct client_state *client, struct client_config *config)
int parse_string(struct parse *cfile, char **sptr, unsigned *lptr)
int read_client_conf_file(const char *name, struct interface_info *ip, struct client_config *client)
void log_fatal(const char *,...) __attribute__((__format__(__printf__
int parse_option_list(struct parse *cfile, struct option ***list)
#define INTERFACE_AUTOMATIC
void read_client_leases()
struct option_state * options
enum dhcp_token next_token(const char **rval, unsigned *rlen, struct parse *cfile)
int option_state_allocate(struct option_state **ptr, const char *file, int line)
struct iaddrmatchlist * next
int evaluate_option_cache(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, struct option_cache *oc, const char *file, int line)
struct option_state * options
void dhc6_lease_destroy(struct dhc6_lease **src, const char *file, int line)
struct option ** requested_options
int buffer_allocate(struct buffer **ptr, unsigned len, const char *file, int line)
#define DHO_BROADCAST_ADDRESS
struct data_string server_id
int group_allocate(struct group **ptr, const char *file, int line)
#define skip_token(a, b, c)
option_name_hash_t * name_hash
void parse_client_lease_declaration(struct parse *cfile, struct client_lease *lease, struct interface_info **ipp, struct client_state **clientp)
#define D6O_DOMAIN_SEARCH
TIME parse_date(struct parse *cfile)
void parse_reject_statement(struct parse *cfile, struct client_config *config)
void dfree(void *, const char *, int)
struct client_lease * next
#define DHO_CLASSLESS_STATIC_ROUTES
const char * path_dhclient_conf
int parse_ip6_addr(struct parse *cfile, struct iaddr *addr)
struct option_cache * lookup_option(struct universe *universe, struct option_state *options, unsigned code)
isc_result_t uerr2isc(int)
struct option_state * options
int parse_option_decl(struct option_cache **oc, struct parse *cfile)
int bootp_broadcast_always
void skip_to_semi(struct parse *cfile)
void skip_to_rbrace(struct parse *cfile, int brace_count)
struct interface_info * interfaces
struct client_config top_level_config
struct option ** required_options
union executable_statement::@7 data
void destroy_client_lease(struct client_lease *lease)
char * path_dhclient_script
void parse_client_statement(struct parse *cfile, struct interface_info *ip, struct client_config *config)
struct universe ** universes
void make_client_state(struct client_state **state)
struct interface_info * next
struct universe dhcpv6_universe
void free_pair(pair foo, const char *file, int line)
struct string_list * next
isc_result_t read_client_conf()
struct interface_info * dummy_interfaces
int parse_ip6_prefix(struct parse *cfile, struct iaddr *addr, u_int8_t *plen)
void parse_lease_time(struct parse *cfile, TIME *timep)
struct executable_statement * statements
struct iaddrmatchlist * reject_list
struct client_config * config
struct hardware anycast_mac_addr
option_code_hash_t * code_hash
struct string_list * medium
int parse_ip_addr(struct parse *cfile, struct iaddr *addr)
const unsigned char * data
void data_string_copy(struct data_string *dest, const struct data_string *src, const char *file, int line)
int parse_executable_statement(struct executable_statement **result, struct parse *cfile, int *lose, enum expression_context case_context)
void parse_hardware_param(struct parse *cfile, struct hardware *hardware)
u_int32_t requested_lease
int clone_group(struct group **gp, struct group *group, const char *file, int line)
int parse_warn(struct parse *cfile, const char *fmt,...)
isc_result_t new_parse(struct parse **cfile, int file, char *inbuf, unsigned buflen, const char *name, int eolp)
struct dhc6_lease * active_lease
struct option * default_requested_options[NUM_DEFAULT_REQUESTED_OPTS+1]
int option_dereference(struct option **dest, const char *file, int line)
int bootp_broadcast_always