1 | /*
|
---|
2 | * TINET (TCP/IP Protocol Stack)
|
---|
3 | *
|
---|
4 | * Copyright (C) 2001-2017 by Dep. of Computer Science and Engineering
|
---|
5 | * Tomakomai National College of Technology, JAPAN
|
---|
6 | *
|
---|
7 | * 上記著作権者は,以下の (1)~(4) の条件か,Free Software Foundation
|
---|
8 | * によって公表されている GNU General Public License の Version 2 に記
|
---|
9 | * 述されている条件を満たす場合に限り,本ソフトウェア(本ソフトウェア
|
---|
10 | * を改変したものを含む.以下同じ)を使用・複製・改変・再配布(以下,
|
---|
11 | * 利用と呼ぶ)することを無償で許諾する.
|
---|
12 | * (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
13 | * 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
14 | * スコード中に含まれていること.
|
---|
15 | * (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
16 | * 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
17 | * 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
18 | * の無保証規定を掲載すること.
|
---|
19 | * (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
20 | * 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
21 | * と.
|
---|
22 | * (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
23 | * 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
24 | * (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
25 | * 報告すること.
|
---|
26 | * (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
27 | * 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
28 | *
|
---|
29 | * 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
30 | * よびTOPPERSプロジェクトは,本ソフトウェアに関して,その適用可能性も
|
---|
31 | * 含めて,いかなる保証も行わない.また,本ソフトウェアの利用により直
|
---|
32 | * 接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
|
---|
33 | *
|
---|
34 | * @(#) $Id: dhcp4.h 315 2017-07-23 05:29:40Z coas-nagasima $
|
---|
35 | */
|
---|
36 |
|
---|
37 | #ifndef DHCP4_H
|
---|
38 | #define DHCP4_H
|
---|
39 |
|
---|
40 | /*
|
---|
41 | * DHCP に関する定義
|
---|
42 | *
|
---|
43 | * RFC2131
|
---|
44 | */
|
---|
45 |
|
---|
46 | /*
|
---|
47 | * DHCP メッセージの定数の定義
|
---|
48 | */
|
---|
49 |
|
---|
50 | #define DHCP4_CHADDR_LEN 16
|
---|
51 | #define DHCP4_SNAME_LEN 64
|
---|
52 | #define DHCP4_FILE_LEN 128
|
---|
53 | #define DHCP4_DFLT_OPT_LEN 312
|
---|
54 | #define DHCP4_UDP_MSG_LENGTH (sizeof(uint32_t)*7+DHCP4_CHADDR_LEN \
|
---|
55 | +DHCP4_SNAME_LEN+DHCP4_FILE_LEN+DHCP4_DFLT_OPT_LEN)
|
---|
56 | #define DHCP4_SNAME_OFFSET (sizeof(uint32_t)*7+DHCP4_CHADDR_LEN)
|
---|
57 | #define DHCP4_FILE_OFFSET (DHCP4_SNAME_OFFSET+DHCP4_SNAME_LEN)
|
---|
58 | #define DHCP4_OPTION_OFFSET (DHCP4_FILE_OFFSET+DHCP4_FILE_LEN)
|
---|
59 | #define DHCP4_TIME_INFINITY UINT_C(0xffffffff)
|
---|
60 |
|
---|
61 | /*
|
---|
62 | * DHCP メッセージ
|
---|
63 | */
|
---|
64 |
|
---|
65 | typedef struct dhcp4_msg {
|
---|
66 | uint8_t op; /* packet type */
|
---|
67 | uint8_t htype; /* hardware address type */
|
---|
68 | uint8_t hlen; /* hardware address length */
|
---|
69 | uint8_t hops; /* gateway hops */
|
---|
70 | uint32_t xid; /* transaction ID */
|
---|
71 | uint16_t secs; /* seconds since boot began */
|
---|
72 | uint16_t flags;
|
---|
73 | uint32_t ciaddr; /* client IP address */
|
---|
74 | uint32_t yiaddr; /* your IP address */
|
---|
75 | uint32_t siaddr; /* server IP address */
|
---|
76 | uint32_t giaddr; /* relay agent IP address */
|
---|
77 | uint8_t chaddr [DHCP4_CHADDR_LEN]; /* client hardware address */
|
---|
78 | uint8_t sname [DHCP4_SNAME_LEN]; /* server host name */
|
---|
79 | uint8_t file [DHCP4_FILE_LEN]; /* boot file name */
|
---|
80 | uint8_t options[DHCP4_DFLT_OPT_LEN]; /* optional parameters field */
|
---|
81 | } T_DHCP4_MSG;
|
---|
82 |
|
---|
83 | /* packet type の定義 */
|
---|
84 |
|
---|
85 | #define DHCP4_REQUEST UINT_C(1)
|
---|
86 | #define DHCP4_REPLY UINT_C(2)
|
---|
87 |
|
---|
88 | /* hardware address type の定義 */
|
---|
89 |
|
---|
90 | #define DHCP4_HWA_TYPE_ETHER UINT_C(1)
|
---|
91 | #define DHCP4_HWA_TYPE_IEEE802 UINT_C(6)
|
---|
92 |
|
---|
93 | /*
|
---|
94 | * DHCP オプション
|
---|
95 | *
|
---|
96 | * RFC1533
|
---|
97 | */
|
---|
98 |
|
---|
99 | /*
|
---|
100 | * オプションの穴埋め
|
---|
101 | */
|
---|
102 | #define DHCP4_OPT_PAD UINT_C(0)
|
---|
103 |
|
---|
104 | /*
|
---|
105 | * サブネットマスク
|
---|
106 | *
|
---|
107 | * code len subnet mask
|
---|
108 | * +------+-----+-----+-----+-----+-----+
|
---|
109 | * | 1 | 4 | m1 | m2 | m3 | m4 |
|
---|
110 | * +------+-----+-----+-----+-----+-----+
|
---|
111 | */
|
---|
112 | #define DHCP4_OPT_SUBNET_MASK UINT_C(1)
|
---|
113 |
|
---|
114 | /*
|
---|
115 | * ルータ
|
---|
116 | *
|
---|
117 | * code len addres #1 address #2
|
---|
118 | * +------+-----+-----+-----+-----+-----+-----+-----+---
|
---|
119 | * | 3 | n | a1 | a2 | a3 | a4 | a1 | a2 | ...
|
---|
120 | * +------+-----+-----+-----+-----+-----+-----+-----+---
|
---|
121 | */
|
---|
122 | #define DHCP4_OPT_ROUTER UINT_C(3)
|
---|
123 |
|
---|
124 | /*
|
---|
125 | * DNS サーバ
|
---|
126 | *
|
---|
127 | * code len addres #1 address #2
|
---|
128 | * +------+-----+-----+-----+-----+-----+-----+-----+---
|
---|
129 | * | 6 | n | a1 | a2 | a3 | a4 | a1 | a2 | ...
|
---|
130 | * +------+-----+-----+-----+-----+-----+-----+-----+---
|
---|
131 | */
|
---|
132 | #define DHCP4_OPT_DNS_SERVER UINT_C(6)
|
---|
133 |
|
---|
134 | /*
|
---|
135 | * ホスト名
|
---|
136 | *
|
---|
137 | * code len host name
|
---|
138 | * +------+-----+-----+-----+-----+-----+---
|
---|
139 | * | 12 | n | h1 | h2 | h3 | h4 | ...
|
---|
140 | * +------+-----+-----+-----+-----+-----+---
|
---|
141 | */
|
---|
142 | #define DHCP4_OPT_HOST_NAME UINT_C(12)
|
---|
143 |
|
---|
144 | /*
|
---|
145 | * ドメイン名
|
---|
146 | *
|
---|
147 | * code len domain name
|
---|
148 | * +------+-----+-----+-----+-----+-----+---
|
---|
149 | * | 15 | n | d1 | d2 | d3 | d4 | ...
|
---|
150 | * +------+-----+-----+-----+-----+-----+---
|
---|
151 | */
|
---|
152 | #define DHCP4_OPT_DOMAIN_NAME UINT_C(15)
|
---|
153 |
|
---|
154 | /*
|
---|
155 | * ルータ探索
|
---|
156 | *
|
---|
157 | * code len value
|
---|
158 | * +------+-----+-----+
|
---|
159 | * | 31 | 1 | 0/1 |
|
---|
160 | * +------+-----+-----+
|
---|
161 | */
|
---|
162 | #define DHCP4_OPT_RTR_DISOVERY UINT_C(31)
|
---|
163 |
|
---|
164 | /*
|
---|
165 | * 静的経路
|
---|
166 | *
|
---|
167 | * code len destination #1 router #1
|
---|
168 | * +------+-----+-----+-----+-----+-----+-----+-----+---
|
---|
169 | * | 33 | n | d1 | d2 | d3 | d4 | r1 | r2 | ...
|
---|
170 | * +------+-----+-----+-----+-----+-----+-----+-----+---
|
---|
171 | */
|
---|
172 | #define DHCP4_OPT_STATIC_ROUTE UINT_C(33)
|
---|
173 |
|
---|
174 | /*
|
---|
175 | * ベンダー固有情報
|
---|
176 | *
|
---|
177 | * code len vendor-specific informations
|
---|
178 | * +------+-----+-----+-----+-----+---
|
---|
179 | * | 43 | n | i1 | i2 | i3 | ...
|
---|
180 | * +------+-----+-----+-----+-----+---
|
---|
181 | *
|
---|
182 | */
|
---|
183 | #define DHCP4_OPT_VENDOR_INFO UINT_C(43)
|
---|
184 |
|
---|
185 | /*
|
---|
186 | * NetBIOS over TCP/IP ネームサーバ
|
---|
187 | *
|
---|
188 | * code len addres #1 address #2
|
---|
189 | * +------+-----+-----+-----+-----+-----+-----+-----+---
|
---|
190 | * | 44 | n | a1 | a2 | a3 | a4 | a1 | a2 | ...
|
---|
191 | * +------+-----+-----+-----+-----+-----+-----+-----+---
|
---|
192 | */
|
---|
193 | #define DHCP4_OPT_NETBIOS_NS UINT_C(44)
|
---|
194 |
|
---|
195 | /*
|
---|
196 | * NetBIOS over TCP/IP ノードタイプ
|
---|
197 | *
|
---|
198 | * code len type
|
---|
199 | * +------+-----+-----+
|
---|
200 | * | 46 | 1 | type|
|
---|
201 | * +------+-----+-----+
|
---|
202 | */
|
---|
203 | #define DHCP4_OPT_NETBIOS_NODE UINT_C(46)
|
---|
204 |
|
---|
205 | /*
|
---|
206 | * NetBIOS over TCP/IP スコープ
|
---|
207 | *
|
---|
208 | * code len NetBIOS scope
|
---|
209 | * +------+-----+-----+-----+-----+-----+---
|
---|
210 | * | 44 | n | s1 | s2 | s3 | s4 | ...
|
---|
211 | * +------+-----+-----+-----+-----+-----+---
|
---|
212 | */
|
---|
213 | #define DHCP4_OPT_NETBIOS_SCOPE UINT_C(47)
|
---|
214 |
|
---|
215 | /*
|
---|
216 | * 特定の IPv4 アドレス要求
|
---|
217 | *
|
---|
218 | * code len IPv4 address
|
---|
219 | * +------+-----+-----+-----+-----+-----+
|
---|
220 | * | 50 | 4 | a1 | a2 | a3 | a4 |
|
---|
221 | * +------+-----+-----+-----+-----+-----+
|
---|
222 | */
|
---|
223 | #define DHCP4_OPT_REQ_IPV4 UINT_C(50)
|
---|
224 |
|
---|
225 | /*
|
---|
226 | * リース時間
|
---|
227 | *
|
---|
228 | * code len lease time
|
---|
229 | * +------+-----+-----+-----+-----+-----+
|
---|
230 | * | 51 | 4 | t1 | t2 | t3 | t4 |
|
---|
231 | * +------+-----+-----+-----+-----+-----+
|
---|
232 | */
|
---|
233 | #define DHCP4_OPT_LEASE_TIME UINT_C(51)
|
---|
234 |
|
---|
235 | /*
|
---|
236 | * オプションオーバーロード
|
---|
237 | *
|
---|
238 | * code len value
|
---|
239 | * +------+-----+-----+
|
---|
240 | * | 52 | 1 | 1-3 |
|
---|
241 | * +------+-----+-----+
|
---|
242 | */
|
---|
243 | #define DHCP4_OPT_OPT_OVERLOAD UINT_C(52)
|
---|
244 |
|
---|
245 | /* value の定義 */
|
---|
246 |
|
---|
247 | #define DHCP4_OPTOL_FILE UINT_C(0x01)
|
---|
248 | #define DHCP4_OPTOL_SNAME UINT_C(0x02)
|
---|
249 | #define DHCP4_OPTOL_BOTH UINT_C(0x03)
|
---|
250 |
|
---|
251 | /*
|
---|
252 | * DHCP メッセージタイプ
|
---|
253 | *
|
---|
254 | * code len type
|
---|
255 | * +------+-----+-----+
|
---|
256 | * | 53 | 1 | 1-7 |
|
---|
257 | * +------+-----+-----+
|
---|
258 | */
|
---|
259 | #define DHCP4_OPT_MSG_TYPE UINT_C(53)
|
---|
260 |
|
---|
261 | /* type の定義 */
|
---|
262 |
|
---|
263 | #define DHCP4_MTYPE_BOOTP UINT_C(0)
|
---|
264 | #define DHCP4_MTYPE_DISCOVER UINT_C(1)
|
---|
265 | #define DHCP4_MTYPE_OFFER UINT_C(2)
|
---|
266 | #define DHCP4_MTYPE_REQUEST UINT_C(3)
|
---|
267 | #define DHCP4_MTYPE_DECLINE UINT_C(4)
|
---|
268 | #define DHCP4_MTYPE_ACK UINT_C(5)
|
---|
269 | #define DHCP4_MTYPE_NAK UINT_C(6)
|
---|
270 | #define DHCP4_MTYPE_RELEASE UINT_C(7)
|
---|
271 | #define DHCP4_MTYPE_INFOMATION UINT_C(8)
|
---|
272 |
|
---|
273 | /*
|
---|
274 | * サーバ ID
|
---|
275 | *
|
---|
276 | * code len IPv4 address
|
---|
277 | * +------+-----+-----+-----+-----+-----+
|
---|
278 | * | 54 | 4 | a1 | a2 | a3 | a4 |
|
---|
279 | * +------+-----+-----+-----+-----+-----+
|
---|
280 | */
|
---|
281 | #define DHCP4_OPT_SERVER_ID UINT_C(54)
|
---|
282 |
|
---|
283 | /*
|
---|
284 | * 要求パラメータリスト
|
---|
285 | *
|
---|
286 | * code len option code
|
---|
287 | * +------+-----+-----+-----+-----+---
|
---|
288 | * | 55 | n | c1 | c2 | c3 | ...
|
---|
289 | * +------+-----+-----+-----+-----+---
|
---|
290 | *
|
---|
291 | */
|
---|
292 | #define DHCP4_OPT_REQ_PARAM UINT_C(55)
|
---|
293 |
|
---|
294 | /*
|
---|
295 | * Renewal (T1) 時間
|
---|
296 | *
|
---|
297 | * code len T1 interval
|
---|
298 | * +------+-----+-----+-----+-----+-----+
|
---|
299 | * | 58 | 4 | t1 | t2 | t3 | t4 |
|
---|
300 | * +------+-----+-----+-----+-----+-----+
|
---|
301 | */
|
---|
302 | #define DHCP4_OPT_RENEWAL_T1 UINT_C(58)
|
---|
303 |
|
---|
304 | /*
|
---|
305 | * Rebinding (T2) 時間
|
---|
306 | *
|
---|
307 | * code len T2 interval
|
---|
308 | * +------+-----+-----+-----+-----+-----+
|
---|
309 | * | 59 | 4 | t1 | t2 | t3 | t4 |
|
---|
310 | * +------+-----+-----+-----+-----+-----+
|
---|
311 | */
|
---|
312 | #define DHCP4_OPT_REBINDING_T2 UINT_C(59)
|
---|
313 |
|
---|
314 | /*
|
---|
315 | * ベンダークラス ID(RFC2132)
|
---|
316 | *
|
---|
317 | * code len vendor class ID
|
---|
318 | * +------+-----+-----+-----+-----+---
|
---|
319 | * | 60 | n | i1 | i2 | i3 | ...
|
---|
320 | * +------+-----+-----+-----+-----+---
|
---|
321 | *
|
---|
322 | */
|
---|
323 | #define DHCP4_OPT_VCLASS_ID UINT_C(60)
|
---|
324 |
|
---|
325 | /*
|
---|
326 | * クライアント ID
|
---|
327 | *
|
---|
328 | * code len type client ID
|
---|
329 | * +------+-----+-----+-----+-----+---
|
---|
330 | * | 61 | n | type| i1 | i2 | ...
|
---|
331 | * +------+-----+-----+-----+-----+---
|
---|
332 | *
|
---|
333 | * type : ハードウェアアドレスタイプ
|
---|
334 | * i1, i2, ...: 通常 MAC アドレス
|
---|
335 | */
|
---|
336 | #define DHCP4_OPT_CLIENT_ID UINT_C(61)
|
---|
337 |
|
---|
338 | /*
|
---|
339 | * クラスなし静的経路(RFC3442)
|
---|
340 | *
|
---|
341 | * code len destination #1 router #1
|
---|
342 | * +------+-----+-----+------+-----+-----+-----+-----+---
|
---|
343 | * | 121 | n | d1 | ... | dN | r1 | r2 | r3 | ...
|
---|
344 | * +------+-----+-----+------+-----+-----+-----+-----+---
|
---|
345 | */
|
---|
346 | #define DHCP4_OPT_CLASSLESS_RTE UINT_C(121)
|
---|
347 |
|
---|
348 | /*
|
---|
349 | * オプションの終了
|
---|
350 | */
|
---|
351 | #define DHCP4_OPT_END UINT_C(255)
|
---|
352 |
|
---|
353 | /*
|
---|
354 | * magic 番号(RFC1048)
|
---|
355 | */
|
---|
356 |
|
---|
357 | #define DHCP4_RFC1048_MAGIC { UINT_C(99), UINT_C(130), UINT_C(83), UINT_C(99), }
|
---|
358 | #define DHCP4_MAGIC_LEN 4
|
---|
359 |
|
---|
360 | /*
|
---|
361 | * UDP ポート番号
|
---|
362 | */
|
---|
363 |
|
---|
364 | #ifndef DHCP4_SRV_CFG_PORTNO
|
---|
365 | #define DHCP4_SRV_CFG_PORTNO 67 /* server */
|
---|
366 | #endif
|
---|
367 |
|
---|
368 | #ifndef DHCP4_CLI_CFG_PORTNO
|
---|
369 | #define DHCP4_CLI_CFG_PORTNO 68 /* client */
|
---|
370 | #endif
|
---|
371 |
|
---|
372 | #endif /* of #ifndef DHCP4_H */
|
---|