Annotation of embedaddon/dhcp/server/stables.c, revision 1.1.1.1
1.1 misho 1: /* stables.c
2:
3: Tables of information only used by server... */
4:
5: /*
6: * Copyright (c) 2004-2011 by Internet Systems Consortium, Inc. ("ISC")
7: * Copyright (c) 1995-2003 by Internet Software Consortium
8: *
9: * Permission to use, copy, modify, and distribute this software for any
10: * purpose with or without fee is hereby granted, provided that the above
11: * copyright notice and this permission notice appear in all copies.
12: *
13: * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
14: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
16: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
19: * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20: *
21: * Internet Systems Consortium, Inc.
22: * 950 Charter Street
23: * Redwood City, CA 94063
24: * <info@isc.org>
25: * https://www.isc.org/
26: *
27: * This software has been written for Internet Systems Consortium
28: * by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
29: * To learn more about Internet Systems Consortium, see
30: * ``https://www.isc.org/''. To learn more about Vixie Enterprises,
31: * see ``http://www.vix.com''. To learn more about Nominum, Inc., see
32: * ``http://www.nominum.com''.
33: */
34:
35: #include "dhcpd.h"
36: #include <syslog.h>
37:
38: #if defined (FAILOVER_PROTOCOL)
39:
40: /* This is used to indicate some kind of failure when generating a
41: failover option. */
42: failover_option_t null_failover_option = { 0, 0 };
43: failover_option_t skip_failover_option = { 0, 0 };
44:
45: /* Information about failover options, for printing, encoding
46: and decoding. */
47: struct failover_option_info ft_options [] =
48: {
49: { 0, "unused", FT_UNDEF, 0, 0, 0 },
50: { FTO_ADDRESSES_TRANSFERRED, "addresses-transferred", FT_UINT32, 1,
51: FM_OFFSET(addresses_transferred), FTB_ADDRESSES_TRANSFERRED },
52: { FTO_ASSIGNED_IP_ADDRESS, "assigned-IP-address", FT_IPADDR, 1,
53: FM_OFFSET(assigned_addr), FTB_ASSIGNED_IP_ADDRESS },
54: { FTO_BINDING_STATUS, "binding-status", FT_UINT8, 1,
55: FM_OFFSET(binding_status), FTB_BINDING_STATUS },
56: { FTO_CLIENT_IDENTIFIER, "client-identifier", FT_BYTES, 0,
57: FM_OFFSET(client_identifier), FTB_CLIENT_IDENTIFIER },
58: { FTO_CHADDR, "client-hardware-address", FT_BYTES, 0,
59: FM_OFFSET(chaddr), FTB_CHADDR },
60: { FTO_CLTT, "client-last-transaction-time", FT_UINT32, 1,
61: FM_OFFSET(cltt), FTB_CLTT },
62: { FTO_REPLY_OPTIONS, "client-reply-options", FT_BYTES, 0,
63: FM_OFFSET(reply_options), FTB_REPLY_OPTIONS },
64: { FTO_REQUEST_OPTIONS, "client-request-options", FT_BYTES, 0,
65: FM_OFFSET(request_options), FTB_REQUEST_OPTIONS },
66: { FTO_DDNS, "DDNS", FT_DDNS, 1, FM_OFFSET(ddns), FTB_DDNS },
67: { FTO_DELAYED_SERVICE, "delayed-service", FT_UINT8, 1,
68: FM_OFFSET(delayed_service), FTB_DELAYED_SERVICE },
69: { FTO_HBA, "hash-bucket-assignment", FT_BYTES, 0,
70: FM_OFFSET(hba), FTB_HBA },
71: { FTO_IP_FLAGS, "IP-flags", FT_UINT16, 1,
72: FM_OFFSET(ip_flags), FTB_IP_FLAGS },
73: { FTO_LEASE_EXPIRY, "lease-expiration-time", FT_UINT32, 1,
74: FM_OFFSET(expiry), FTB_LEASE_EXPIRY },
75: { FTO_MAX_UNACKED, "max-unacked-bndupd", FT_UINT32, 1,
76: FM_OFFSET(max_unacked), FTB_MAX_UNACKED },
77: { FTO_MCLT, "MCLT", FT_UINT32, 1, FM_OFFSET(mclt), FTB_MCLT },
78: { FTO_MESSAGE, "message", FT_TEXT, 0,
79: FM_OFFSET(message), FTB_MESSAGE },
80: { FTO_MESSAGE_DIGEST, "message-digest", FT_BYTES, 0,
81: FM_OFFSET(message_digest), FTB_MESSAGE_DIGEST },
82: { FTO_POTENTIAL_EXPIRY, "potential-expiration-time", FT_UINT32, 1,
83: FM_OFFSET(potential_expiry), FTB_POTENTIAL_EXPIRY },
84: { FTO_RECEIVE_TIMER, "receive-timer", FT_UINT32, 1,
85: FM_OFFSET(receive_timer), FTB_RECEIVE_TIMER },
86: { FTO_PROTOCOL_VERSION, "protocol-version", FT_UINT8, 1,
87: FM_OFFSET(protocol_version), FTB_PROTOCOL_VERSION },
88: { FTO_REJECT_REASON, "reject-reason", FT_UINT8, 1,
89: FM_OFFSET(reject_reason), FTB_REJECT_REASON },
90: { FTO_RELATIONSHIP_NAME, "relationship-name", FT_BYTES, 0,
91: FM_OFFSET(relationship_name), FTB_RELATIONSHIP_NAME },
92: { FTO_SERVER_FLAGS, "server-flags", FT_UINT8, 1,
93: FM_OFFSET(server_flags), FTB_SERVER_FLAGS },
94: { FTO_SERVER_STATE, "server-state", FT_UINT8, 1,
95: FM_OFFSET(server_state), FTB_SERVER_STATE },
96: { FTO_STOS, "start-time-of-state", FT_UINT32, 1,
97: FM_OFFSET(stos), FTB_STOS },
98: { FTO_TLS_REPLY, "TLS-reply", FT_UINT8, 1,
99: FM_OFFSET(tls_reply), FTB_TLS_REPLY },
100: { FTO_TLS_REQUEST, "TLS-request", FT_UINT8, 1,
101: FM_OFFSET(tls_request), FTB_TLS_REQUEST },
102: { FTO_VENDOR_CLASS, "vendor-class-identifier", FT_BYTES, 0,
103: FM_OFFSET(vendor_class), FTB_VENDOR_CLASS },
104: { FTO_VENDOR_OPTIONS, "vendor-specific-options", FT_BYTES, 0,
105: FM_OFFSET(vendor_options), FTB_VENDOR_OPTIONS }
106: };
107:
108: /* These are really options that make sense for a particular request - if
109: some other option comes in, we're not going to use it, so we can just
110: discard it. Note that the message-digest option is allowed for all
111: message types, but is not saved - it's just used to validate the message
112: and then discarded - so it's not mentioned here. */
113:
114: u_int32_t fto_allowed [] = {
115: 0, /* 0 unused */
116: 0, /* 1 POOLREQ */
117: FTB_ADDRESSES_TRANSFERRED, /* 2 POOLRESP */
118: (FTB_ASSIGNED_IP_ADDRESS | FTB_BINDING_STATUS | FTB_CLIENT_IDENTIFIER |
119: FTB_CHADDR | FTB_DDNS | FTB_IP_FLAGS | FTB_LEASE_EXPIRY |
120: FTB_POTENTIAL_EXPIRY | FTB_STOS | FTB_CLTT | FTB_REQUEST_OPTIONS |
121: FTB_REPLY_OPTIONS), /* 3 BNDUPD */
122: (FTB_ASSIGNED_IP_ADDRESS | FTB_BINDING_STATUS | FTB_CLIENT_IDENTIFIER |
123: FTB_CHADDR | FTB_DDNS | FTB_IP_FLAGS | FTB_LEASE_EXPIRY |
124: FTB_POTENTIAL_EXPIRY | FTB_STOS | FTB_CLTT | FTB_REQUEST_OPTIONS |
125: FTB_REPLY_OPTIONS | FTB_REJECT_REASON | FTB_MESSAGE), /* 4 BNDACK */
126: (FTB_RELATIONSHIP_NAME | FTB_MAX_UNACKED | FTB_RECEIVE_TIMER |
127: FTB_VENDOR_CLASS | FTB_PROTOCOL_VERSION | FTB_TLS_REQUEST |
128: FTB_MCLT | FTB_HBA), /* 5 CONNECT */
129: (FTB_RELATIONSHIP_NAME | FTB_MAX_UNACKED | FTB_RECEIVE_TIMER |
130: FTB_VENDOR_CLASS | FTB_PROTOCOL_VERSION | FTB_TLS_REPLY |
131: FTB_REJECT_REASON | FTB_MESSAGE), /* CONNECTACK */
132: 0, /* 7 UPDREQALL */
133: 0, /* 8 UPDDONE */
134: 0, /* 9 UPDREQ */
135: (FTB_SERVER_STATE | FTB_SERVER_FLAGS | FTB_STOS), /* 10 STATE */
136: 0, /* 11 CONTACT */
137: (FTB_REJECT_REASON | FTB_MESSAGE) /* 12 DISCONNECT */
138: };
139:
140: /* Sizes of the various types. */
141: int ft_sizes [] = {
142: 1, /* FT_UINT8 */
143: 4, /* FT_IPADDR */
144: 4, /* FT_UINT32 */
145: 1, /* FT_BYTES */
146: 1, /* FT_TEXT_OR_BYTES */
147: 0, /* FT_DDNS */
148: 0, /* FT_DDNS1 */
149: 2, /* FT_UINT16 */
150: 1, /* FT_TEXT */
151: 0, /* FT_UNDEF */
152: 0, /* FT_DIGEST */
153: };
154:
155: /* Names of the various failover link states. */
156: const char *dhcp_flink_state_names [] = {
157: "invalid state 0",
158: "startup",
159: "message length wait",
160: "message wait",
161: "disconnected"
162: };
163: #endif /* FAILOVER_PROTOCOL */
164:
165: /* Failover binding state names. These are used even if there is no
166: failover protocol support. */
167: const char *binding_state_names [] = {
168: "free", "active", "expired", "released", "abandoned",
169: "reset", "backup" };
170:
171: struct universe agent_universe;
172: static struct option agent_options[] = {
173: { "circuit-id", "X", &agent_universe, 1, 1 },
174: { "remote-id", "X", &agent_universe, 2, 1 },
175: { "agent-id", "I", &agent_universe, 3, 1 },
176: { "DOCSIS-device-class", "L", &agent_universe, 4, 1 },
177: { "link-selection", "I", &agent_universe, 5, 1 },
178: { NULL, NULL, NULL, 0, 0 }
179: };
180:
181: struct universe server_universe;
182: static struct option server_options[] = {
183: { "default-lease-time", "T", &server_universe, 1, 1 },
184: { "max-lease-time", "T", &server_universe, 2, 1 },
185: { "min-lease-time", "T", &server_universe, 3, 1 },
186: { "dynamic-bootp-lease-cutoff", "T", &server_universe, 4, 1 },
187: { "dynamic-bootp-lease-length", "L", &server_universe, 5, 1 },
188: { "boot-unknown-clients", "f", &server_universe, 6, 1 },
189: { "dynamic-bootp", "f", &server_universe, 7, 1 },
190: { "allow-bootp", "f", &server_universe, 8, 1 },
191: { "allow-booting", "f", &server_universe, 9, 1 },
192: { "one-lease-per-client", "f", &server_universe, 10, 1 },
193: { "get-lease-hostnames", "f", &server_universe, 11, 1 },
194: { "use-host-decl-names", "f", &server_universe, 12, 1 },
195: { "use-lease-addr-for-default-route", "f",
196: &server_universe, 13, 1 },
197: { "min-secs", "B", &server_universe, 14, 1 },
198: { "filename", "t", &server_universe, 15, 1 },
199: { "server-name", "t", &server_universe, 16, 1 },
200: { "next-server", "I", &server_universe, 17, 1 },
201: { "authoritative", "f", &server_universe, 18, 1 },
202: { "vendor-option-space", "U", &server_universe, 19, 1 },
203: { "always-reply-rfc1048", "f", &server_universe, 20, 1 },
204: { "site-option-space", "X", &server_universe, 21, 1 },
205: { "always-broadcast", "f", &server_universe, 22, 1 },
206: { "ddns-domainname", "t", &server_universe, 23, 1 },
207: { "ddns-hostname", "t", &server_universe, 24, 1 },
208: { "ddns-rev-domainname", "t", &server_universe, 25, 1 },
209: { "lease-file-name", "t", &server_universe, 26, 1 },
210: { "pid-file-name", "t", &server_universe, 27, 1 },
211: { "duplicates", "f", &server_universe, 28, 1 },
212: { "declines", "f", &server_universe, 29, 1 },
213: { "ddns-updates", "f", &server_universe, 30, 1 },
214: { "omapi-port", "S", &server_universe, 31, 1 },
215: { "local-port", "S", &server_universe, 32, 1 },
216: { "limited-broadcast-address", "I", &server_universe, 33, 1 },
217: { "remote-port", "S", &server_universe, 34, 1 },
218: { "local-address", "I", &server_universe, 35, 1 },
219: { "omapi-key", "d", &server_universe, 36, 1 },
220: { "stash-agent-options", "f", &server_universe, 37, 1 },
221: { "ddns-ttl", "T", &server_universe, 38, 1 },
222: { "ddns-update-style", "Nddns-styles.", &server_universe, 39, 1 },
223: { "client-updates", "f", &server_universe, 40, 1 },
224: { "update-optimization", "f", &server_universe, 41, 1 },
225: { "ping-check", "f", &server_universe, 42, 1 },
226: { "update-static-leases", "f", &server_universe, 43, 1 },
227: { "log-facility", "Nsyslog-facilities.",
228: &server_universe, 44, 1 },
229: { "do-forward-updates", "f", &server_universe, 45, 1 },
230: { "ping-timeout", "T", &server_universe, 46, 1 },
231: { "infinite-is-reserved", "f", &server_universe, 47, 1 },
232: { "update-conflict-detection", "f", &server_universe, 48, 1 },
233: { "leasequery", "f", &server_universe, 49, 1 },
234: { "adaptive-lease-time-threshold", "B", &server_universe, 50, 1 },
235: { "do-reverse-updates", "f", &server_universe, 51, 1 },
236: { "fqdn-reply", "f", &server_universe, 52, 1 },
237: { "preferred-lifetime", "T", &server_universe, 53, 1 },
238: { "dhcpv6-lease-file-name", "t", &server_universe, 54, 1 },
239: { "dhcpv6-pid-file-name", "t", &server_universe, 55, 1 },
240: { "limit-addrs-per-ia", "L", &server_universe, 56, 1 },
241: { "limit-prefs-per-ia", "L", &server_universe, 57, 1 },
242: /* Assert a configuration parsing error if delayed-ack isn't compiled in. */
243: #if defined(DELAYED_ACK)
244: { "delayed-ack", "S", &server_universe, 58, 1 },
245: { "max-ack-delay", "L", &server_universe, 59, 1 },
246: #endif
247: { NULL, NULL, NULL, 0, 0 }
248: };
249:
250: struct enumeration_value ddns_styles_values [] = {
251: { "none", 0 },
252: { "ad-hoc", 1 },
253: { "interim", 2 },
254: { (char *)0, 0 }
255: };
256:
257: struct enumeration ddns_styles = {
258: (struct enumeration *)0,
259: "ddns-styles", 1,
260: ddns_styles_values
261: };
262:
263: struct enumeration_value syslog_values [] = {
264: #if defined (LOG_KERN)
265: { "kern", LOG_KERN },
266: #endif
267: #if defined (LOG_USER)
268: { "user", LOG_USER },
269: #endif
270: #if defined (LOG_MAIL)
271: { "mail", LOG_MAIL },
272: #endif
273: #if defined (LOG_DAEMON)
274: { "daemon", LOG_DAEMON },
275: #endif
276: #if defined (LOG_AUTH)
277: { "auth", LOG_AUTH },
278: #endif
279: #if defined (LOG_SYSLOG)
280: { "syslog", LOG_SYSLOG },
281: #endif
282: #if defined (LOG_LPR)
283: { "lpr", LOG_LPR },
284: #endif
285: #if defined (LOG_NEWS)
286: { "news", LOG_NEWS },
287: #endif
288: #if defined (LOG_UUCP)
289: { "uucp", LOG_UUCP },
290: #endif
291: #if defined (LOG_CRON)
292: { "cron", LOG_CRON },
293: #endif
294: #if defined (LOG_AUTHPRIV)
295: { "authpriv", LOG_AUTHPRIV },
296: #endif
297: #if defined (LOG_FTP)
298: { "ftp", LOG_FTP },
299: #endif
300: #if defined (LOG_LOCAL0)
301: { "local0", LOG_LOCAL0 },
302: #endif
303: #if defined (LOG_LOCAL1)
304: { "local1", LOG_LOCAL1 },
305: #endif
306: #if defined (LOG_LOCAL2)
307: { "local2", LOG_LOCAL2 },
308: #endif
309: #if defined (LOG_LOCAL3)
310: { "local3", LOG_LOCAL3 },
311: #endif
312: #if defined (LOG_LOCAL4)
313: { "local4", LOG_LOCAL4 },
314: #endif
315: #if defined (LOG_LOCAL5)
316: { "local5", LOG_LOCAL5 },
317: #endif
318: #if defined (LOG_LOCAL6)
319: { "local6", LOG_LOCAL6 },
320: #endif
321: #if defined (LOG_LOCAL7)
322: { "local7", LOG_LOCAL7 },
323: #endif
324: { (char *)0, 0 }
325: };
326:
327: struct enumeration syslog_enum = {
328: (struct enumeration *)0,
329: "syslog-facilities", 1,
330: syslog_values
331: };
332:
333: void initialize_server_option_spaces()
334: {
335: int i;
336: unsigned code;
337:
338: /* Set up the Relay Agent Information Option suboption space... */
339: agent_universe.name = "agent";
340: agent_universe.concat_duplicates = 0;
341: agent_universe.option_state_dereference =
342: linked_option_state_dereference;
343: agent_universe.lookup_func = lookup_linked_option;
344: agent_universe.save_func = save_linked_option;
345: agent_universe.delete_func = delete_linked_option;
346: agent_universe.encapsulate = linked_option_space_encapsulate;
347: agent_universe.foreach = linked_option_space_foreach;
348: agent_universe.decode = parse_option_buffer;
349: agent_universe.index = universe_count++;
350: agent_universe.length_size = 1;
351: agent_universe.tag_size = 1;
352: agent_universe.get_tag = getUChar;
353: agent_universe.store_tag = putUChar;
354: agent_universe.get_length = getUChar;
355: agent_universe.store_length = putUChar;
356: agent_universe.site_code_min = 0;
357: agent_universe.end = 0;
358: universes [agent_universe.index] = &agent_universe;
359: if (!option_name_new_hash(&agent_universe.name_hash,
360: AGENT_HASH_SIZE, MDL) ||
361: !option_code_new_hash(&agent_universe.code_hash,
362: AGENT_HASH_SIZE, MDL))
363: log_fatal ("Can't allocate agent option hash table.");
364: for (i = 0 ; agent_options[i].name ; i++) {
365: option_code_hash_add(agent_universe.code_hash,
366: &agent_options[i].code, 0,
367: &agent_options[i], MDL);
368: option_name_hash_add(agent_universe.name_hash,
369: agent_options[i].name, 0,
370: &agent_options[i], MDL);
371: }
372: #if defined(REPORT_HASH_PERFORMANCE)
373: log_info("Relay Agent name hash: %s",
374: option_name_hash_report(agent_universe.name_hash));
375: log_info("Relay Agent code hash: %s",
376: option_code_hash_report(agent_universe.code_hash));
377: #endif
378: code = DHO_DHCP_AGENT_OPTIONS;
379: option_code_hash_lookup(&agent_universe.enc_opt,
380: dhcp_universe.code_hash, &code, 0, MDL);
381:
382: /* Set up the server option universe... */
383: server_universe.name = "server";
384: server_universe.concat_duplicates = 0;
385: server_universe.lookup_func = lookup_hashed_option;
386: server_universe.option_state_dereference =
387: hashed_option_state_dereference;
388: server_universe.save_func = save_hashed_option;
389: server_universe.delete_func = delete_hashed_option;
390: server_universe.encapsulate = hashed_option_space_encapsulate;
391: server_universe.foreach = hashed_option_space_foreach;
392: server_universe.length_size = 1; /* Never used ... */
393: server_universe.tag_size = 4;
394: server_universe.store_tag = putUChar;
395: server_universe.store_length = putUChar;
396: server_universe.site_code_min = 0;
397: server_universe.end = 0;
398: server_universe.index = universe_count++;
399: universes [server_universe.index] = &server_universe;
400: if (!option_name_new_hash(&server_universe.name_hash,
401: SERVER_HASH_SIZE, MDL) ||
402: !option_code_new_hash(&server_universe.code_hash,
403: SERVER_HASH_SIZE, MDL))
404: log_fatal ("Can't allocate server option hash table.");
405: for (i = 0 ; server_options[i].name ; i++) {
406: option_code_hash_add(server_universe.code_hash,
407: &server_options[i].code, 0,
408: &server_options[i], MDL);
409: option_name_hash_add(server_universe.name_hash,
410: server_options[i].name, 0,
411: &server_options[i], MDL);
412: }
413: #if defined(REPORT_HASH_PERFORMANCE)
414: log_info("Server-Config Option name hash: %s",
415: option_name_hash_report(server_universe.name_hash));
416: log_info("Server-Config Option code hash: %s",
417: option_code_hash_report(server_universe.code_hash));
418: #endif
419:
420: /* Add the server and agent option spaces to the option space hash. */
421: universe_hash_add (universe_hash,
422: agent_universe.name, 0, &agent_universe, MDL);
423: universe_hash_add (universe_hash,
424: server_universe.name, 0, &server_universe, MDL);
425:
426: /* Make the server universe the configuration option universe. */
427: config_universe = &server_universe;
428:
429: code = SV_VENDOR_OPTION_SPACE;
430: option_code_hash_lookup(&vendor_cfg_option, server_universe.code_hash,
431: &code, 0, MDL);
432: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>