diff options
Diffstat (limited to 'networking/udhcp/options.c')
-rw-r--r-- | networking/udhcp/options.c | 138 |
1 files changed, 92 insertions, 46 deletions
diff --git a/networking/udhcp/options.c b/networking/udhcp/options.c index ffc0ed127..c224f3670 100644 --- a/networking/udhcp/options.c +++ b/networking/udhcp/options.c | |||
@@ -11,54 +11,97 @@ | |||
11 | 11 | ||
12 | /* Supported options are easily added here */ | 12 | /* Supported options are easily added here */ |
13 | const struct dhcp_option dhcp_options[] = { | 13 | const struct dhcp_option dhcp_options[] = { |
14 | /* opt_name[12] flags code */ | 14 | /* flags code */ |
15 | {"subnet", OPTION_IP | OPTION_REQ, 0x01}, /* DHCP_SUBNET */ | 15 | { OPTION_IP | OPTION_REQ, 0x01 }, /* DHCP_SUBNET */ |
16 | {"timezone", OPTION_S32, 0x02}, /* DHCP_TIME_OFFSET */ | 16 | { OPTION_S32, 0x02 }, /* DHCP_TIME_OFFSET */ |
17 | {"router", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x03}, /* DHCP_ROUTER */ | 17 | { OPTION_IP | OPTION_LIST | OPTION_REQ, 0x03 }, /* DHCP_ROUTER */ |
18 | {"timesvr", OPTION_IP | OPTION_LIST, 0x04}, /* DHCP_TIME_SERVER */ | 18 | { OPTION_IP | OPTION_LIST, 0x04 }, /* DHCP_TIME_SERVER */ |
19 | {"namesvr", OPTION_IP | OPTION_LIST, 0x05}, /* DHCP_NAME_SERVER */ | 19 | { OPTION_IP | OPTION_LIST, 0x05 }, /* DHCP_NAME_SERVER */ |
20 | {"dns", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x06}, /* DHCP_DNS_SERVER */ | 20 | { OPTION_IP | OPTION_LIST | OPTION_REQ, 0x06 }, /* DHCP_DNS_SERVER */ |
21 | {"logsvr", OPTION_IP | OPTION_LIST, 0x07}, /* DHCP_LOG_SERVER */ | 21 | { OPTION_IP | OPTION_LIST, 0x07 }, /* DHCP_LOG_SERVER */ |
22 | {"cookiesvr", OPTION_IP | OPTION_LIST, 0x08}, /* DHCP_COOKIE_SERVER */ | 22 | { OPTION_IP | OPTION_LIST, 0x08 }, /* DHCP_COOKIE_SERVER */ |
23 | {"lprsvr", OPTION_IP | OPTION_LIST, 0x09}, /* DHCP_LPR_SERVER */ | 23 | { OPTION_IP | OPTION_LIST, 0x09 }, /* DHCP_LPR_SERVER */ |
24 | {"hostname", OPTION_STRING | OPTION_REQ, 0x0c}, /* DHCP_HOST_NAME */ | 24 | { OPTION_STRING | OPTION_REQ, 0x0c }, /* DHCP_HOST_NAME */ |
25 | {"bootsize", OPTION_U16, 0x0d}, /* DHCP_BOOT_SIZE */ | 25 | { OPTION_U16, 0x0d }, /* DHCP_BOOT_SIZE */ |
26 | {"domain", OPTION_STRING | OPTION_LIST | OPTION_REQ, 0x0f}, /* DHCP_DOMAIN_NAME */ | 26 | { OPTION_STRING | OPTION_LIST | OPTION_REQ, 0x0f }, /* DHCP_DOMAIN_NAME */ |
27 | {"swapsvr", OPTION_IP, 0x10}, /* DHCP_SWAP_SERVER */ | 27 | { OPTION_IP, 0x10 }, /* DHCP_SWAP_SERVER */ |
28 | {"rootpath", OPTION_STRING, 0x11}, /* DHCP_ROOT_PATH */ | 28 | { OPTION_STRING, 0x11 }, /* DHCP_ROOT_PATH */ |
29 | {"ipttl", OPTION_U8, 0x17}, /* DHCP_IP_TTL */ | 29 | { OPTION_U8, 0x17 }, /* DHCP_IP_TTL */ |
30 | {"mtu", OPTION_U16, 0x1a}, /* DHCP_MTU */ | 30 | { OPTION_U16, 0x1a }, /* DHCP_MTU */ |
31 | {"broadcast", OPTION_IP | OPTION_REQ, 0x1c}, /* DHCP_BROADCAST */ | 31 | { OPTION_IP | OPTION_REQ, 0x1c }, /* DHCP_BROADCAST */ |
32 | {"nisdomain", OPTION_STRING | OPTION_REQ, 0x28}, /* DHCP_NTP_SERVER */ | 32 | { OPTION_STRING | OPTION_REQ, 0x28 }, /* DHCP_NTP_SERVER */ |
33 | {"nissrv", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x29}, /* DHCP_WINS_SERVER */ | 33 | { OPTION_IP | OPTION_LIST | OPTION_REQ, 0x29 }, /* DHCP_WINS_SERVER */ |
34 | {"ntpsrv", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x2a}, /* DHCP_REQUESTED_IP */ | 34 | { OPTION_IP | OPTION_LIST | OPTION_REQ, 0x2a }, /* DHCP_REQUESTED_IP */ |
35 | {"wins", OPTION_IP | OPTION_LIST, 0x2c}, /* DHCP_LEASE_TIME */ | 35 | { OPTION_IP | OPTION_LIST, 0x2c }, /* DHCP_LEASE_TIME */ |
36 | {"requestip", OPTION_IP, 0x32}, /* DHCP_OPTION_OVER */ | 36 | { OPTION_IP, 0x32 }, /* DHCP_OPTION_OVER */ |
37 | {"lease", OPTION_U32, 0x33}, /* DHCP_MESSAGE_TYPE */ | 37 | { OPTION_U32, 0x33 }, /* DHCP_MESSAGE_TYPE */ |
38 | {"dhcptype", OPTION_U8, 0x35}, /* DHCP_SERVER_ID */ | 38 | { OPTION_U8, 0x35 }, /* DHCP_SERVER_ID */ |
39 | {"serverid", OPTION_IP, 0x36}, /* DHCP_PARAM_REQ */ | 39 | { OPTION_IP, 0x36 }, /* DHCP_PARAM_REQ */ |
40 | {"message", OPTION_STRING, 0x38}, /* DHCP_MESSAGE */ | 40 | { OPTION_STRING, 0x38 }, /* DHCP_MESSAGE */ |
41 | // TODO: 1) some options should not be parsed & passed to script - | 41 | { OPTION_STRING, 0x3C }, /* DHCP_VENDOR */ |
42 | // maxsize sure should not, since it cannot appear in server responses! | 42 | { OPTION_STRING, 0x3D }, /* DHCP_CLIENT_ID */ |
43 | // grep for opt_name is fix the mess. | 43 | { OPTION_STRING, 0x42 }, /* "tftp" */ |
44 | // 2) Using fixed-sized char[] vector wastes space. | 44 | { OPTION_STRING, 0x43 }, /* "bootfile" */ |
45 | {"maxsize", OPTION_U16, 0x39}, /* DHCP_MAX_SIZE */ | 45 | { OPTION_STRING, 0x4D }, /* "userclass" */ |
46 | {"vendorclass", OPTION_STRING, 0x3C}, /* DHCP_VENDOR */ | ||
47 | {"clientid", OPTION_STRING, 0x3D}, /* DHCP_CLIENT_ID */ | ||
48 | {"tftp", OPTION_STRING, 0x42}, | ||
49 | {"bootfile", OPTION_STRING, 0x43}, | ||
50 | {"userclass", OPTION_STRING, 0x4D}, | ||
51 | #if ENABLE_FEATURE_RFC3397 | 46 | #if ENABLE_FEATURE_RFC3397 |
52 | {"search", OPTION_STR1035 | OPTION_LIST | OPTION_REQ, 0x77}, | 47 | { OPTION_STR1035 | OPTION_LIST | OPTION_REQ, 0x77 }, /* "search" */ |
53 | #endif | 48 | #endif |
54 | /* MSIE's "Web Proxy Autodiscovery Protocol" support */ | 49 | /* MSIE's "Web Proxy Autodiscovery Protocol" support */ |
55 | {"wpad", OPTION_STRING, 0xfc}, | 50 | { OPTION_STRING, 0xfc }, /* "wpad" */ |
56 | {} /* zero-padded terminating entry */ | 51 | |
52 | /* Options below have no match in dhcp_option_strings[], | ||
53 | * are not passed to dhcpc scripts, and cannot be specified | ||
54 | * with "option XXX YYY" syntax in dhcpd config file. */ | ||
55 | |||
56 | { OPTION_U16, 0x39 }, /* DHCP_MAX_SIZE */ | ||
57 | { } /* zeroed terminating entry */ | ||
57 | }; | 58 | }; |
58 | 59 | ||
60 | /* Used for converting options from incoming packets to env variables | ||
61 | * for udhcpc stript */ | ||
62 | /* Must match dhcp_options[] order */ | ||
63 | const char dhcp_option_strings[] ALIGN1 = | ||
64 | "subnet" "\0" /* DHCP_SUBNET */ | ||
65 | "timezone" "\0" /* DHCP_TIME_OFFSET */ | ||
66 | "router" "\0" /* DHCP_ROUTER */ | ||
67 | "timesvr" "\0" /* DHCP_TIME_SERVER */ | ||
68 | "namesvr" "\0" /* DHCP_NAME_SERVER */ | ||
69 | "dns" "\0" /* DHCP_DNS_SERVER */ | ||
70 | "logsvr" "\0" /* DHCP_LOG_SERVER */ | ||
71 | "cookiesvr" "\0" /* DHCP_COOKIE_SERVER */ | ||
72 | "lprsvr" "\0" /* DHCP_LPR_SERVER */ | ||
73 | "hostname" "\0" /* DHCP_HOST_NAME */ | ||
74 | "bootsize" "\0" /* DHCP_BOOT_SIZE */ | ||
75 | "domain" "\0" /* DHCP_DOMAIN_NAME */ | ||
76 | "swapsvr" "\0" /* DHCP_SWAP_SERVER */ | ||
77 | "rootpath" "\0" /* DHCP_ROOT_PATH */ | ||
78 | "ipttl" "\0" /* DHCP_IP_TTL */ | ||
79 | "mtu" "\0" /* DHCP_MTU */ | ||
80 | "broadcast" "\0" /* DHCP_BROADCAST */ | ||
81 | "nisdomain" "\0" /* DHCP_NTP_SERVER */ | ||
82 | "nissrv" "\0" /* DHCP_WINS_SERVER */ | ||
83 | "ntpsrv" "\0" /* DHCP_REQUESTED_IP */ | ||
84 | "wins" "\0" /* DHCP_LEASE_TIME */ | ||
85 | "requestip" "\0" /* DHCP_OPTION_OVER */ | ||
86 | "lease" "\0" /* DHCP_MESSAGE_TYPE */ | ||
87 | "dhcptype" "\0" /* DHCP_SERVER_ID */ | ||
88 | "serverid" "\0" /* DHCP_PARAM_REQ */ | ||
89 | "message" "\0" /* DHCP_MESSAGE */ | ||
90 | "vendorclass" "\0" /* DHCP_VENDOR */ | ||
91 | "clientid" "\0" /* DHCP_CLIENT_ID */ | ||
92 | "tftp" "\0" | ||
93 | "bootfile" "\0" | ||
94 | "userclass" "\0" | ||
95 | #if ENABLE_FEATURE_RFC3397 | ||
96 | "search" "\0" | ||
97 | #endif | ||
98 | /* MSIE's "Web Proxy Autodiscovery Protocol" support */ | ||
99 | "wpad" "\0" | ||
100 | ; | ||
101 | |||
59 | 102 | ||
60 | /* Lengths of the different option types */ | 103 | /* Lengths of the different option types */ |
61 | const unsigned char option_lengths[] ALIGN1 = { | 104 | const uint8_t dhcp_option_lengths[] ALIGN1 = { |
62 | [OPTION_IP] = 4, | 105 | [OPTION_IP] = 4, |
63 | [OPTION_IP_PAIR] = 8, | 106 | [OPTION_IP_PAIR] = 8, |
64 | [OPTION_BOOLEAN] = 1, | 107 | [OPTION_BOOLEAN] = 1, |
@@ -137,8 +180,10 @@ int end_option(uint8_t *optionptr) | |||
137 | int i = 0; | 180 | int i = 0; |
138 | 181 | ||
139 | while (optionptr[i] != DHCP_END) { | 182 | while (optionptr[i] != DHCP_END) { |
140 | if (optionptr[i] == DHCP_PADDING) i++; | 183 | if (optionptr[i] == DHCP_PADDING) |
141 | else i += optionptr[i + OPT_LEN] + 2; | 184 | i++; |
185 | else | ||
186 | i += optionptr[i + OPT_LEN] + 2; | ||
142 | } | 187 | } |
143 | return i; | 188 | return i; |
144 | } | 189 | } |
@@ -173,10 +218,11 @@ int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data) | |||
173 | uint8_t option[6], len; | 218 | uint8_t option[6], len; |
174 | 219 | ||
175 | option[OPT_CODE] = code; | 220 | option[OPT_CODE] = code; |
176 | len = option_lengths[dh->flags & TYPE_MASK]; | 221 | len = dhcp_option_lengths[dh->flags & TYPE_MASK]; |
177 | option[OPT_LEN] = len; | 222 | option[OPT_LEN] = len; |
178 | if (BB_BIG_ENDIAN) data <<= 8 * (4 - len); | 223 | if (BB_BIG_ENDIAN) |
179 | /* This memcpy is for broken processors which can't | 224 | data <<= 8 * (4 - len); |
225 | /* This memcpy is for processors which can't | ||
180 | * handle a simple unaligned 32-bit assignment */ | 226 | * handle a simple unaligned 32-bit assignment */ |
181 | memcpy(&option[OPT_DATA], &data, 4); | 227 | memcpy(&option[OPT_DATA], &data, 4); |
182 | return add_option_string(optionptr, option); | 228 | return add_option_string(optionptr, option); |