summaryrefslogtreecommitdiff
path: root/networking/udhcp/common.h
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/common.h')
-rw-r--r--networking/udhcp/common.h182
1 files changed, 142 insertions, 40 deletions
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h
index d740ca56c..2ce67598d 100644
--- a/networking/udhcp/common.h
+++ b/networking/udhcp/common.h
@@ -15,17 +15,14 @@
15 15
16PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN 16PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
17 17
18#define DEFAULT_SCRIPT CONFIG_UDHCPC_DEFAULT_SCRIPT
19
20extern const uint8_t MAC_BCAST_ADDR[6]; /* six all-ones */ 18extern const uint8_t MAC_BCAST_ADDR[6]; /* six all-ones */
21 19
22/*** packet.h ***/ 20
21/*** DHCP packet ***/
23 22
24/* DHCP protocol. See RFC 2131 */ 23/* DHCP protocol. See RFC 2131 */
25#define DHCP_MAGIC 0x63825363 24#define DHCP_MAGIC 0x63825363
26
27#define DHCP_OPTIONS_BUFSIZE 308 25#define DHCP_OPTIONS_BUFSIZE 308
28
29#define BOOTREQUEST 1 26#define BOOTREQUEST 1
30#define BOOTREPLY 2 27#define BOOTREPLY 2
31 28
@@ -67,6 +64,116 @@ struct BUG_bad_sizeof_struct_ip_udp_dhcp_packet {
67 [(sizeof(struct ip_udp_dhcp_packet) != 576 + CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS) ? -1 : 1]; 64 [(sizeof(struct ip_udp_dhcp_packet) != 576 + CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS) ? -1 : 1];
68}; 65};
69 66
67
68/*** Options ***/
69
70enum {
71 OPTION_IP = 1,
72 OPTION_IP_PAIR,
73 OPTION_STRING,
74#if ENABLE_FEATURE_UDHCP_RFC3397
75 OPTION_STR1035, /* RFC1035 compressed domain name list */
76#endif
77 OPTION_BOOLEAN,
78 OPTION_U8,
79 OPTION_U16,
80 OPTION_S16,
81 OPTION_U32,
82 OPTION_S32,
83 OPTION_STATIC_ROUTES,
84
85 OPTION_TYPE_MASK = 0x0f,
86 /* Client requests this option by default */
87 OPTION_REQ = 0x10,
88 /* There can be a list of 1 or more of these */
89 OPTION_LIST = 0x20,
90};
91
92/* DHCP option codes (partial list). See RFC 2132 and
93 * http://www.iana.org/assignments/bootp-dhcp-parameters/
94 * Commented out options are handled by common option machinery,
95 * uncommented ones have spacial cases (grep for them to see).
96 */
97#define DHCP_PADDING 0x00
98#define DHCP_SUBNET 0x01
99//#define DHCP_TIME_OFFSET 0x02 /* (localtime - UTC_time) in seconds. signed */
100//#define DHCP_ROUTER 0x03
101//#define DHCP_TIME_SERVER 0x04 /* RFC 868 time server (32-bit, 0 = 1.1.1900) */
102//#define DHCP_NAME_SERVER 0x05 /* IEN 116 _really_ ancient kind of NS */
103//#define DHCP_DNS_SERVER 0x06
104//#define DHCP_LOG_SERVER 0x07 /* port 704 UDP log (not syslog)
105//#define DHCP_COOKIE_SERVER 0x08 /* "quote of the day" server */
106//#define DHCP_LPR_SERVER 0x09
107#define DHCP_HOST_NAME 0x0c /* either client informs server or server gives name to client */
108//#define DHCP_BOOT_SIZE 0x0d
109//#define DHCP_DOMAIN_NAME 0x0f /* server gives domain suffix */
110//#define DHCP_SWAP_SERVER 0x10
111//#define DHCP_ROOT_PATH 0x11
112//#define DHCP_IP_TTL 0x17
113//#define DHCP_MTU 0x1a
114//#define DHCP_BROADCAST 0x1c
115//#define DHCP_NIS_DOMAIN 0x28
116//#define DHCP_NIS_SERVER 0x29
117//#define DHCP_NTP_SERVER 0x2a
118//#define DHCP_WINS_SERVER 0x2c
119#define DHCP_REQUESTED_IP 0x32 /* sent by client if specific IP is wanted */
120#define DHCP_LEASE_TIME 0x33
121#define DHCP_OPTION_OVERLOAD 0x34
122#define DHCP_MESSAGE_TYPE 0x35
123#define DHCP_SERVER_ID 0x36 /* by default server's IP */
124#define DHCP_PARAM_REQ 0x37 /* list of options client wants */
125//#define DHCP_ERR_MESSAGE 0x38 /* error message when sending NAK etc */
126#define DHCP_MAX_SIZE 0x39
127#define DHCP_VENDOR 0x3c /* client's vendor (a string) */
128#define DHCP_CLIENT_ID 0x3d /* by default client's MAC addr, but may be arbitrarily long */
129//#define DHCP_TFTP_SERVER_NAME 0x42 /* same as 'sname' field */
130//#define DHCP_BOOT_FILE 0x43 /* same as 'file' field */
131//#define DHCP_USER_CLASS 0x4d /* RFC 3004. set of LASCII strings. "I am a printer" etc */
132#define DHCP_FQDN 0x51 /* client asks to update DNS to map its FQDN to its new IP */
133//#define DHCP_DOMAIN_SEARCH 0x77 /* RFC 3397. set of ASCIZ string, DNS-style compressed */
134//#define DHCP_STATIC_ROUTES 0x79 /* RFC 3442. (mask,ip,router) tuples */
135//#define DHCP_WPAD 0xfc /* MSIE's Web Proxy Autodiscovery Protocol */
136#define DHCP_END 0xff
137
138/* Offsets in option byte sequence */
139#define OPT_CODE 0
140#define OPT_LEN 1
141#define OPT_DATA 2
142/* Bits in "overload" option */
143#define OPTION_FIELD 0
144#define FILE_FIELD 1
145#define SNAME_FIELD 2
146
147/* DHCP_MESSAGE_TYPE values */
148#define DHCPDISCOVER 1 /* client -> server */
149#define DHCPOFFER 2 /* client <- server */
150#define DHCPREQUEST 3 /* client -> server */
151#define DHCPDECLINE 4 /* client -> server */
152#define DHCPACK 5 /* client <- server */
153#define DHCPNAK 6 /* client <- server */
154#define DHCPRELEASE 7 /* client -> server */
155#define DHCPINFORM 8 /* client -> server */
156#define DHCP_MINTYPE DHCPDISCOVER
157#define DHCP_MAXTYPE DHCPINFORM
158
159struct dhcp_option {
160 uint8_t flags;
161 uint8_t code;
162};
163
164extern const struct dhcp_option dhcp_options[];
165extern const char dhcp_option_strings[];
166extern const uint8_t dhcp_option_lengths[];
167
168uint8_t *udhcp_get_option(struct dhcp_packet *packet, int code) FAST_FUNC;
169int udhcp_end_option(uint8_t *optionptr) FAST_FUNC;
170void udhcp_add_option_string(uint8_t *optionptr, uint8_t *string) FAST_FUNC;
171void udhcp_add_simple_option(uint8_t *optionptr, uint8_t code, uint32_t data) FAST_FUNC;
172#if ENABLE_FEATURE_UDHCP_RFC3397
173char *dname_dec(const uint8_t *cstr, int clen, const char *pre) FAST_FUNC;
174uint8_t *dname_enc(const uint8_t *cstr, int clen, const char *src, int *retlen) FAST_FUNC;
175#endif
176
70// RFC 2131 Table 5: Fields and options used by DHCP clients 177// RFC 2131 Table 5: Fields and options used by DHCP clients
71// 178//
72// Field DHCPDISCOVER DHCPREQUEST DHCPDECLINE, 179// Field DHCPDISCOVER DHCPREQUEST DHCPDECLINE,
@@ -132,6 +239,33 @@ struct BUG_bad_sizeof_struct_ip_udp_dhcp_packet {
132// All others MAY MAY MUST NOT 239// All others MAY MAY MUST NOT
133 240
134 241
242/*** Logging ***/
243
244#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
245extern unsigned dhcp_verbose;
246# define log1(...) do { if (dhcp_verbose >= 1) bb_info_msg(__VA_ARGS__); } while (0)
247# if CONFIG_UDHCP_DEBUG >= 2
248void udhcp_dump_packet(struct dhcp_packet *packet) FAST_FUNC;
249# define log2(...) do { if (dhcp_verbose >= 2) bb_info_msg(__VA_ARGS__); } while (0)
250# else
251# define udhcp_dump_packet(...) ((void)0)
252# define log2(...) ((void)0)
253# endif
254# if CONFIG_UDHCP_DEBUG >= 3
255# define log3(...) do { if (dhcp_verbose >= 3) bb_info_msg(__VA_ARGS__); } while (0)
256# else
257# define log3(...) ((void)0)
258# endif
259#else
260# define udhcp_dump_packet(...) ((void)0)
261# define log1(...) ((void)0)
262# define log2(...) ((void)0)
263# define log3(...) ((void)0)
264#endif
265
266
267/*** Other shared functions ***/
268
135uint16_t udhcp_checksum(void *addr, int count) FAST_FUNC; 269uint16_t udhcp_checksum(void *addr, int count) FAST_FUNC;
136 270
137void udhcp_init_header(struct dhcp_packet *packet, char type) FAST_FUNC; 271void udhcp_init_header(struct dhcp_packet *packet, char type) FAST_FUNC;
@@ -147,24 +281,14 @@ int udhcp_send_kernel_packet(struct dhcp_packet *dhcp_pkt,
147 uint32_t source_ip, int source_port, 281 uint32_t source_ip, int source_port,
148 uint32_t dest_ip, int dest_port) FAST_FUNC; 282 uint32_t dest_ip, int dest_port) FAST_FUNC;
149 283
150
151/**/
152
153void udhcp_run_script(struct dhcp_packet *packet, const char *name) FAST_FUNC;
154
155// Still need to clean these up...
156
157/* from options.h */
158#define get_option udhcp_get_option
159#define end_option udhcp_end_option
160#define add_option_string udhcp_add_option_string
161#define add_simple_option udhcp_add_simple_option
162
163void udhcp_sp_setup(void) FAST_FUNC; 284void udhcp_sp_setup(void) FAST_FUNC;
164int udhcp_sp_fd_set(fd_set *rfds, int extra_fd) FAST_FUNC; 285int udhcp_sp_fd_set(fd_set *rfds, int extra_fd) FAST_FUNC;
165int udhcp_sp_read(const fd_set *rfds) FAST_FUNC; 286int udhcp_sp_read(const fd_set *rfds) FAST_FUNC;
287
166int udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac) FAST_FUNC; 288int udhcp_read_interface(const char *interface, int *ifindex, uint32_t *nip, uint8_t *mac) FAST_FUNC;
289
167int udhcp_listen_socket(/*uint32_t ip,*/ int port, const char *inf) FAST_FUNC; 290int udhcp_listen_socket(/*uint32_t ip,*/ int port, const char *inf) FAST_FUNC;
291
168/* Returns 1 if no reply received */ 292/* Returns 1 if no reply received */
169int arpping(uint32_t test_nip, 293int arpping(uint32_t test_nip,
170 const uint8_t *safe_mac, 294 const uint8_t *safe_mac,
@@ -172,28 +296,6 @@ int arpping(uint32_t test_nip,
172 uint8_t *from_mac, 296 uint8_t *from_mac,
173 const char *interface) FAST_FUNC; 297 const char *interface) FAST_FUNC;
174 298
175#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 1
176extern unsigned dhcp_verbose;
177# define log1(...) do { if (dhcp_verbose >= 1) bb_info_msg(__VA_ARGS__); } while (0)
178# if CONFIG_UDHCP_DEBUG >= 2
179void udhcp_dump_packet(struct dhcp_packet *packet) FAST_FUNC;
180# define log2(...) do { if (dhcp_verbose >= 2) bb_info_msg(__VA_ARGS__); } while (0)
181# else
182# define udhcp_dump_packet(...) ((void)0)
183# define log2(...) ((void)0)
184# endif
185# if CONFIG_UDHCP_DEBUG >= 3
186# define log3(...) do { if (dhcp_verbose >= 3) bb_info_msg(__VA_ARGS__); } while (0)
187# else
188# define log3(...) ((void)0)
189# endif
190#else
191# define udhcp_dump_packet(...) ((void)0)
192# define log1(...) ((void)0)
193# define log2(...) ((void)0)
194# define log3(...) ((void)0)
195#endif
196
197POP_SAVED_FUNCTION_VISIBILITY 299POP_SAVED_FUNCTION_VISIBILITY
198 300
199#endif 301#endif