[go: up one dir, main page]

File: DHCPConst.h

package info (click to toggle)
dibbler 0.7.3-1.3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 11,148 kB
  • ctags: 8,720
  • sloc: cpp: 54,863; sh: 9,389; ansic: 8,659; yacc: 2,570; makefile: 1,061; lex: 842; perl: 49; xml: 6
file content (312 lines) | stat: -rw-r--r-- 8,430 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*
 * Dibbler - a portable DHCPv6
 *
 * authors: Tomasz Mrugalski <thomson@klub.com.pl>
 *          Marek Senderski <msend@o2.pl>
 * changes: Michal Kowalczuk <michal@kowalczuk.eu>
 *
 * Released under GNU GPL v2 licence
 *
 */

#include "limits.h"

#ifndef DHCPCONST_H
#define DHCPCONST_H

#define ALL_DHCP_RELAY_AGENTS_AND_SERVERS  "ff02::1:2"
#define ALL_DHCP_SERVERS                   "ff05::1:3"

#define DHCPCLIENT_PORT 546
#define DHCPSERVER_PORT 547

// messages
#define SOLICIT_MSG    1
#define ADVERTISE_MSG  2
#define REQUEST_MSG    3
#define CONFIRM_MSG    4
#define RENEW_MSG      5
#define REBIND_MSG     6
#define REPLY_MSG      7
#define RELEASE_MSG    8
#define DECLINE_MSG    9
#define RECONFIGURE_MSG 10
#define INFORMATION_REQUEST_MSG 11
#define RELAY_FORW_MSG 12
#define RELAY_REPL_MSG 13
#define LEASEQUERY_MSG       14
#define LEASEQUERY_REPLY_MSG 15

// implementation specific
#define CONTROL_MSG    255

// timers, timeouts

#define SOL_MAX_DELAY 1
#define SOL_TIMEOUT   1
#define SOL_MAX_RT    120
#define REQ_TIMEOUT   1
#define REQ_MAX_RT    30
#define REQ_MAX_RC    10
#define CNF_MAX_DELAY 1
#define CNF_TIMEOUT   1
#define CNF_MAX_RT    4
#define CNF_MAX_RD    10
#define REN_TIMEOUT   10
#define REN_MAX_RT    600
#define REB_TIMEOUT   10
#define REB_MAX_RT    600
#define INF_MAX_DELAY 1
#define INF_TIMEOUT   1
#define INF_MAX_RT    120
#define REL_TIMEOUT   1
#define REL_MAX_RC    5
#define DEC_TIMEOUT   1
#define DEC_MAX_RC    5
#define REC_TIMEOUT   2
#define REC_MAX_RC    8

#define HOP_COUNT_LIMIT 32

// how long does server caches its replies?
#define SERVER_REPLY_CACHE_TIMEOUT 60

// RFC3315: supported options
#define OPTION_CLIENTID         1
#define OPTION_SERVERID         2
#define OPTION_IA_NA            3
#define OPTION_IA_TA            4
#define OPTION_IAADDR           5
#define OPTION_ORO              6
#define OPTION_PREFERENCE       7
#define OPTION_ELAPSED_TIME     8
#define OPTION_UNICAST          12
#define OPTION_STATUS_CODE      13
#define OPTION_RAPID_COMMIT     14

// RFC3315: options not supported yet
#define OPTION_RELAY_MSG        9
#define OPTION_AUTH             11
#define OPTION_USER_CLASS       15
#define OPTION_VENDOR_CLASS     16
#define OPTION_VENDOR_OPTS      17
#define OPTION_INTERFACE_ID     18
#define OPTION_RECONF_MSG       19
#define OPTION_RECONF_ACCEPT    20

// additional options

// RFC3319: SIP servers and domains
#define OPTION_SIP_SERVER_D      21
#define OPTION_SIP_SERVER_A      22

// RFC3646: DNS servers and domains
#define OPTION_DNS_SERVERS	23
#define OPTION_DOMAIN_LIST      24

// RFC3633: Prefix options
#define OPTION_IA_PD            25
#define OPTION_IAPREFIX         26

// RFC3898: NIS options
#define OPTION_NIS_SERVERS	27
#define OPTION_NISP_SERVERS	28
#define OPTION_NIS_DOMAIN_NAME  29
#define OPTION_NISP_DOMAIN_NAME 30

// RFC4075: Simple Network Time Protocol (SNTP)
#define OPTION_SNTP_SERVERS     31

// RFC4242: Information Refresh Time Option
#define OPTION_INFORMATION_REFRESH_TIME     32

// RFC4280: Broadcast and Multicast Control Servers
#define OPTION_BCMCS_SERVER_D   33
#define OPTION_BCMCS_SERVER_A   34

// RFC4776: Option for Civic Addresses Configuration Information
#define OPTION_GEOCONF_CIVIC    36

// RFC4649: Relay Agent Remote-ID Option
#define OPTION_REMOTE_ID        37

// RFC4580: Relay Agent Subscriber-ID Option
#define OPTION_SUBSCRIBER_ID    38

// RFC4704: Client Fully Qualified Domain Name (FQDN) Option
#define OPTION_FQDN             39

// RFC-ietf-dhc-paa-option-05.txt
#define OPTION_PANA_AGENT       40

// RFC4833: Timezone options for DHCP 
#define OPTION_NEW_POSIX_TIMEZONE 41
#define OPTION_NEW_TZDB_TIMEZONE  42

// RFC-ietf-dhc-dhcpv6-ero-01.txt
#define OPTION_ERO              43

// RFC5007: Leasequery
#define OPTION_LQ_QUERY         44
#define OPTION_CLIENT_DATA      45
#define OPTION_CLT_TIME         46
#define OPTION_LQ_RELAY_DATA    47
#define OPTION_LQ_CLIENT_LINK   48

// The following option numbers are not yet standardized and
// won't interoperate with other implementations
// option formats taken from:
// draft-ram-dhc-dhcpv6-aakey-01.txt
#define OPTION_AAAAUTH              240
#define OPTION_KEYGEN               241

// Experimental implementation for address prefix length information
// See: http://klub.com.pl/dhcpv6/doc/draft-mrugalski-addropts-XX-2007-04-17.txt
#define OPTION_ADDRPARAMS           251

// -- Query types (RFC5007) --
typedef enum {
    QUERY_BY_ADDRESS = 1,
    QUERY_BY_CLIENTID = 2
} ELeaseQueryType;


// --- experimental: tunnel-mode ---
#define OPTION_VENDORSPEC_TUNNEL_TYPE 1
#define OPTION_VENDORSPEC_ENDPOINT    2

// --- Option lengths --
// (value of the len field, so actual option length is +4 bytes)
#define OPTION_ELAPSED_TIME_LEN     2
#define OPTION_INFORMATION_REFRESH_TIME_LEN         4

// --- Status Codes --- 
#define STATUSCODE_SUCCESS       0
#define STATUSCODE_UNSPECFAIL    1
#define STATUSCODE_NOADDRSAVAIL  2
#define STATUSCODE_NOBINDING     3
#define STATUSCODE_NOTONLINK     4
#define STATUSCODE_USEMULTICAST  5
#define STATUSCODE_NOPREFIXAVAIL 6 
// Leasequery status codes
#define STATUSCODE_UNKNOWNQUERYTYPE 7
#define STATUSCODE_MALFORMEDQUERY 8
#define STATUSCODE_NOTCONFIGURED 9
#define STATUSCODE_NOTALLOWED    10

// INFINITY + 1 is 0. Hihi, cool
#define DHCPV6_INFINITY (unsigned) 0xffffffff

// How long should we wait before we assume that OS detected duplicated addresses (in secs)
#define DADTIMEOUT (unsigned) 3

// addresses reported as DECLINED are not used for 2 hours
#define DECLINED_TIMEOUT (unsigned) 7200

// DHCPv6 server default values
#define SERVER_DEFAULT_DOMAIN ""
#define SERVER_DEFAULT_TIMEZONE ""
#define SERVER_DEFAULT_CLNTMAXLEASE ULONG_MAX
#define SERVER_DEFAULT_IFACEMAXLEASE ULONG_MAX
#define SERVER_DEFAULT_PREFERENCE 0
#define SERVER_DEFAULT_RAPIDCOMMIT false

#define SERVER_DEFAULT_MIN_T1    5
#define SERVER_DEFAULT_MAX_T1    3600      /* 1 hour */
#define SERVER_DEFAULT_MIN_T2    10
#define SERVER_DEFAULT_MAX_T2    5400      /* 1,5 hour */
#define SERVER_DEFAULT_MIN_PREF  7200      /* 2 hours */
#define SERVER_DEFAULT_MAX_PREF  86400     /* 1 day */
#define SERVER_DEFAULT_MIN_VALID 10800     /* 3 hours */
#define SERVER_DEFAULT_MAX_VALID 172800    /* 2 days */
#define SERVER_DEFAULT_CLASS_SHARE 100
#define SERVER_DEFAULT_CLASS_MAX_LEASE ULONG_MAX
#define SERVER_DEFAULT_TA_PREF_LIFETIME 3600
#define SERVER_DEFAULT_TA_VALID_LIFETIME 7200
#define SERVER_DEFAULT_CACHE_SIZE 1048576   /* cache size, specified in bytes */
#define CLIENT_DEFAULT_T1 ULONG_MAX
#define CLIENT_DEFAULT_T2 ULONG_MAX

#define CLIENT_DEFAULT_UNICAST false
#define CLIENT_DEFAULT_RAPID_COMMIT false

#define CLIENT_DEFAULT_PREFIX_LENGTH 64
#define CLIENT_DEFAULT_DIGEST DIGEST_NONE

enum ETentative {
    TENTATIVE_UNKNOWN = -1,
    TENTATIVE_NO      = 0,
    TENTATIVE_YES     = 1
};

enum EState {
    STATE_NOTCONFIGURED, 
    STATE_INPROCESS, 
    STATE_CONFIGURED, 
    STATE_FAILED, 
    STATE_DISABLED, 
    STATE_CONFIRMME,
    STATE_TENTATIVECHECK, 
    STATE_TENTATIVE};

// FQDN option flags
#define FQDN_N 0x4
#define FQDN_O 0x2
#define FQDN_S 0x1

// --- Bitfield in ADDRPARAMS option ---
#define ADDRPARAMS_MASK_PREFIX    0x01
#define ADDRPARAMS_MASK_ANYCAST   0x02
#define ADDRPARAMS_MASK_MULTICAST 0x04

    
int allowOptInOpt(int msgType, int optOut, int optIn);
int allowOptInMsg(int msgType, int optType);

#ifdef WIN32
//#define uint8_t  unsigned char
//#define uint16_t unsigned short int
//#define uint32_t unsigned int

#ifndef uint8_t
#define uint8_t  unsigned char
#endif

#ifndef uint16_t
#define uint16_t unsigned short int
#endif

#ifndef uint32_t
#define uint32_t unsigned int
#endif

#ifndef uint64_t
#define uint64_t unsigned long long int
#endif

#else
#include <stdint.h>
#endif

enum DigestTypes {
        DIGEST_NONE = 0,
        DIGEST_PLAIN = 1,
        DIGEST_HMAC_MD5 = 2,
        DIGEST_HMAC_SHA1 = 3,
        DIGEST_HMAC_SHA224 = 4,
        DIGEST_HMAC_SHA256 = 5,
        DIGEST_HMAC_SHA384 = 6,
        DIGEST_HMAC_SHA512 = 7,
        //this must be last, increase it if necessary
        DIGEST_INVALID = 8
};

unsigned getDigestSize(enum DigestTypes type);
char *getDigestName(enum DigestTypes type);
        
// key is generated this way:
// key = HMAC-SHA1 (AAA-key, {Key Generation Nonce || client identifier})
// so it's size is always size of HMAC-SHA1 result which is 160bits = 20bytes
#define AUTHKEYLEN 20

#endif