Changeset 1770 in MondoRescue for branches/stable/mindi-busybox/networking/udhcp/options.c
- Timestamp:
- Nov 6, 2007, 11:01:53 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/stable/mindi-busybox/networking/udhcp/options.c
r821 r1770 1 /* vi: set sw=4 ts=4: */ 1 2 /* 2 3 * options.c -- DHCP server option packet tools … … 4 5 */ 5 6 6 #include <stdlib.h>7 #include <string.h>8 9 7 #include "common.h" 10 8 #include "dhcpd.h" 11 9 #include "options.h" 12 #include "files.h"13 10 14 11 15 12 /* supported options are easily added here */ 16 struct dhcp_option dhcp_options[] = { 17 /* name[10] flags code */ 18 {"subnet", OPTION_IP | OPTION_REQ, 0x01}, 19 {"timezone", OPTION_S32, 0x02}, 20 {"router", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x03}, 21 {"timesvr", OPTION_IP | OPTION_LIST, 0x04}, 22 {"namesvr", OPTION_IP | OPTION_LIST, 0x05}, 23 {"dns", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x06}, 24 {"logsvr", OPTION_IP | OPTION_LIST, 0x07}, 25 {"cookiesvr", OPTION_IP | OPTION_LIST, 0x08}, 26 {"lprsvr", OPTION_IP | OPTION_LIST, 0x09}, 27 {"hostname", OPTION_STRING | OPTION_REQ, 0x0c}, 28 {"bootsize", OPTION_U16, 0x0d}, 29 {"domain", OPTION_STRING | OPTION_REQ, 0x0f}, 30 {"swapsvr", OPTION_IP, 0x10}, 31 {"rootpath", OPTION_STRING, 0x11}, 32 {"ipttl", OPTION_U8, 0x17}, 33 {"mtu", OPTION_U16, 0x1a}, 34 {"broadcast", OPTION_IP | OPTION_REQ, 0x1c}, 35 {"nisdomain", OPTION_STRING | OPTION_REQ, 0x28}, 36 {"nissrv", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x29}, 37 {"ntpsrv", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x2a}, 38 {"wins", OPTION_IP | OPTION_LIST, 0x2c}, 39 {"requestip", OPTION_IP, 0x32}, 40 {"lease", OPTION_U32, 0x33}, 41 {"dhcptype", OPTION_U8, 0x35}, 42 {"serverid", OPTION_IP, 0x36}, 43 {"message", OPTION_STRING, 0x38}, 44 {"tftp", OPTION_STRING, 0x42}, 45 {"bootfile", OPTION_STRING, 0x43}, 46 {"", 0x00, 0x00} 13 const struct dhcp_option dhcp_options[] = { 14 /* name[12] flags code */ 15 {"subnet", OPTION_IP | OPTION_REQ, 0x01}, 16 {"timezone", OPTION_S32, 0x02}, 17 {"router", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x03}, 18 {"timesvr", OPTION_IP | OPTION_LIST, 0x04}, 19 {"namesvr", OPTION_IP | OPTION_LIST, 0x05}, 20 {"dns", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x06}, 21 {"logsvr", OPTION_IP | OPTION_LIST, 0x07}, 22 {"cookiesvr", OPTION_IP | OPTION_LIST, 0x08}, 23 {"lprsvr", OPTION_IP | OPTION_LIST, 0x09}, 24 {"hostname", OPTION_STRING | OPTION_REQ, 0x0c}, 25 {"bootsize", OPTION_U16, 0x0d}, 26 {"domain", OPTION_STRING | OPTION_LIST | OPTION_REQ, 0x0f}, 27 {"swapsvr", OPTION_IP, 0x10}, 28 {"rootpath", OPTION_STRING, 0x11}, 29 {"ipttl", OPTION_U8, 0x17}, 30 {"mtu", OPTION_U16, 0x1a}, 31 {"broadcast", OPTION_IP | OPTION_REQ, 0x1c}, 32 {"nisdomain", OPTION_STRING | OPTION_REQ, 0x28}, 33 {"nissrv", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x29}, 34 {"ntpsrv", OPTION_IP | OPTION_LIST | OPTION_REQ, 0x2a}, 35 {"wins", OPTION_IP | OPTION_LIST, 0x2c}, 36 {"requestip", OPTION_IP, 0x32}, 37 {"lease", OPTION_U32, 0x33}, 38 {"dhcptype", OPTION_U8, 0x35}, 39 {"serverid", OPTION_IP, 0x36}, 40 {"message", OPTION_STRING, 0x38}, 41 {"vendorclass", OPTION_STRING, 0x3C}, 42 {"clientid", OPTION_STRING, 0x3D}, 43 {"tftp", OPTION_STRING, 0x42}, 44 {"bootfile", OPTION_STRING, 0x43}, 45 {"userclass", OPTION_STRING, 0x4D}, 46 #if ENABLE_FEATURE_RFC3397 47 {"search", OPTION_STR1035 | OPTION_LIST | OPTION_REQ, 0x77}, 48 #endif 49 /* MSIE's "Web Proxy Autodiscovery Protocol" support */ 50 {"wpad", OPTION_STRING, 0xfc}, 51 {"", 0x00, 0x00} 47 52 }; 48 53 49 54 /* Lengths of the different option types */ 50 int option_lengths[] = { 51 [OPTION_IP] = 4, 52 [OPTION_IP_PAIR] = 8, 53 [OPTION_BOOLEAN] = 1, 54 [OPTION_STRING] = 1, 55 [OPTION_U8] = 1, 56 [OPTION_U16] = 2, 57 [OPTION_S16] = 2, 58 [OPTION_U32] = 4, 59 [OPTION_S32] = 4 55 const unsigned char option_lengths[] ALIGN1 = { 56 [OPTION_IP] = 4, 57 [OPTION_IP_PAIR] = 8, 58 [OPTION_BOOLEAN] = 1, 59 [OPTION_STRING] = 1, 60 #if ENABLE_FEATURE_RFC3397 61 [OPTION_STR1035] = 1, 62 #endif 63 [OPTION_U8] = 1, 64 [OPTION_U16] = 2, 65 [OPTION_S16] = 2, 66 [OPTION_U32] = 4, 67 [OPTION_S32] = 4 60 68 }; 61 69 … … 73 81 while (!done) { 74 82 if (i >= length) { 75 LOG(LOG_WARNING, "bogus packet, option fields too long.");83 bb_error_msg("bogus packet, option fields too long"); 76 84 return NULL; 77 85 } 78 86 if (optionptr[i + OPT_CODE] == code) { 79 87 if (i + 1 + optionptr[i + OPT_LEN] >= length) { 80 LOG(LOG_WARNING, "bogus packet, option fields too long.");88 bb_error_msg("bogus packet, option fields too long"); 81 89 return NULL; 82 90 } … … 89 97 case DHCP_OPTION_OVER: 90 98 if (i + 1 + optionptr[i + OPT_LEN] >= length) { 91 LOG(LOG_WARNING, "bogus packet, option fields too long.");99 bb_error_msg("bogus packet, option fields too long"); 92 100 return NULL; 93 101 } … … 137 145 /* end position + string length + option code/length + end option */ 138 146 if (end + string[OPT_LEN] + 2 + 1 >= 308) { 139 LOG(LOG_ERR, "Option 0x%02x did not fit into the packet!", string[OPT_CODE]); 147 bb_error_msg("option 0x%02x did not fit into the packet", 148 string[OPT_CODE]); 140 149 return 0; 141 150 } 142 DEBUG( LOG_INFO,"adding option 0x%02x", string[OPT_CODE]);151 DEBUG("adding option 0x%02x", string[OPT_CODE]); 143 152 memcpy(optionptr + end, string, string[OPT_LEN] + 2); 144 153 optionptr[end + string[OPT_LEN] + 2] = DHCP_END; … … 150 159 int add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data) 151 160 { 152 struct dhcp_option *dh;161 const struct dhcp_option *dh; 153 162 154 for (dh =dhcp_options; dh->code; dh++) {163 for (dh = dhcp_options; dh->code; dh++) { 155 164 if (dh->code == code) { 156 165 uint8_t option[6], len; … … 167 176 } 168 177 169 DEBUG(LOG_ERR, "Couldnot add option 0x%02x", code);178 bb_error_msg("cannot add option 0x%02x", code); 170 179 return 0; 171 180 }
Note:
See TracChangeset
for help on using the changeset viewer.