config: fix ra_flags none setting
[project/odhcpd.git] / src / dhcpv6.h
1 /**
2 * Copyright (C) 2012 Steven Barth <steven@midlink.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License version 2 for more details.
12 *
13 */
14 #pragma once
15
16 #include "odhcpd.h"
17
18 #define ALL_DHCPV6_RELAYS "ff02::1:2"
19
20 #define ALL_DHCPV6_SERVERS "ff05::1:3"
21
22 #define DHCPV6_CLIENT_PORT 546
23 #define DHCPV6_SERVER_PORT 547
24
25 #define DHCPV6_MSG_SOLICIT 1
26 #define DHCPV6_MSG_ADVERTISE 2
27 #define DHCPV6_MSG_REQUEST 3
28 #define DHCPV6_MSG_CONFIRM 4
29 #define DHCPV6_MSG_RENEW 5
30 #define DHCPV6_MSG_REBIND 6
31 #define DHCPV6_MSG_REPLY 7
32 #define DHCPV6_MSG_RELEASE 8
33 #define DHCPV6_MSG_DECLINE 9
34 #define DHCPV6_MSG_RECONFIGURE 10
35 #define DHCPV6_MSG_INFORMATION_REQUEST 11
36 #define DHCPV6_MSG_RELAY_FORW 12
37 #define DHCPV6_MSG_RELAY_REPL 13
38 #define DHCPV6_MSG_DHCPV4_QUERY 20
39 #define DHCPV6_MSG_DHCPV4_RESPONSE 21
40
41 #define DHCPV6_OPT_CLIENTID 1
42 #define DHCPV6_OPT_SERVERID 2
43 #define DHCPV6_OPT_IA_NA 3
44 #define DHCPV6_OPT_IA_ADDR 5
45 #define DHCPV6_OPT_ORO 6
46 #define DHCPV6_OPT_STATUS 13
47 #define DHCPV6_OPT_RELAY_MSG 9
48 #define DHCPV6_OPT_AUTH 11
49 #define DHCPV6_OPT_RAPID_COMMIT 14
50 #define DHCPV6_OPT_USER_CLASS 15
51 #define DHCPV6_OPT_INTERFACE_ID 18
52 #define DHCPV6_OPT_RECONF_MSG 19
53 #define DHCPV6_OPT_RECONF_ACCEPT 20
54 #define DHCPV6_OPT_DNS_SERVERS 23
55 #define DHCPV6_OPT_DNS_DOMAIN 24
56 #define DHCPV6_OPT_IA_PD 25
57 #define DHCPV6_OPT_IA_PREFIX 26
58 #define DHCPV6_OPT_INFO_REFRESH 32
59 #define DHCPV6_OPT_FQDN 39
60 #define DHCPV6_OPT_SOL_MAX_RT 82
61 #define DHCPV6_OPT_INF_MAX_RT 83
62 #define DHCPV6_OPT_DHCPV4_MSG 87
63 #define DHCPV6_OPT_4O6_SERVER 88
64
65 #define DHCPV6_DUID_VENDOR 2
66
67 #define DHCPV6_STATUS_OK 0
68 #define DHCPV6_STATUS_NOADDRSAVAIL 2
69 #define DHCPV6_STATUS_NOBINDING 3
70 #define DHCPV6_STATUS_NOTONLINK 4
71 #define DHCPV6_STATUS_USEMULTICAST 5
72 #define DHCPV6_STATUS_NOPREFIXAVAIL 6
73
74 // I just remembered I have an old one lying around...
75 #define DHCPV6_ENT_NO 30462
76 #define DHCPV6_ENT_TYPE 1
77
78
79 #define DHCPV6_HOP_COUNT_LIMIT 32
80
81 #define DHCPV6_REC_TIMEOUT 2000 /* msec */
82 #define DHCPV6_REC_MAX_RC 8
83
84 struct dhcpv6_client_header {
85 uint8_t msg_type;
86 uint8_t transaction_id[3];
87 } __attribute__((packed));
88
89 struct dhcpv6_relay_header {
90 uint8_t msg_type;
91 uint8_t hop_count;
92 struct in6_addr link_address;
93 struct in6_addr peer_address;
94 uint8_t options[];
95 } __attribute__((packed));
96
97 struct dhcpv6_relay_forward_envelope {
98 uint8_t msg_type;
99 uint8_t hop_count;
100 struct in6_addr link_address;
101 struct in6_addr peer_address;
102 uint16_t interface_id_type;
103 uint16_t interface_id_len;
104 uint32_t interface_id_data;
105 uint16_t relay_message_type;
106 uint16_t relay_message_len;
107 } __attribute__((packed));
108
109 struct dhcpv6_auth_reconfigure {
110 uint16_t type;
111 uint16_t len;
112 uint8_t protocol;
113 uint8_t algorithm;
114 uint8_t rdm;
115 uint32_t replay[2];
116 uint8_t reconf_type;
117 uint8_t key[16];
118 } _packed;
119
120 struct dhcpv6_ia_hdr {
121 uint16_t type;
122 uint16_t len;
123 uint32_t iaid;
124 uint32_t t1;
125 uint32_t t2;
126 } _packed;
127
128 struct dhcpv6_ia_prefix {
129 uint16_t type;
130 uint16_t len;
131 uint32_t preferred;
132 uint32_t valid;
133 uint8_t prefix;
134 struct in6_addr addr;
135 } _packed;
136
137 struct dhcpv6_ia_addr {
138 uint16_t type;
139 uint16_t len;
140 struct in6_addr addr;
141 uint32_t preferred;
142 uint32_t valid;
143 } _packed;
144
145 struct dhcpv6_cer_id {
146 uint16_t type;
147 uint16_t len;
148 uint16_t reserved;
149 uint16_t auth_type;
150 uint8_t auth[16];
151 struct in6_addr addr;
152 };
153
154 #define dhcpv6_for_each_option(start, end, otype, olen, odata)\
155 for (uint8_t *_o = (uint8_t*)(start); _o + 4 <= (end) &&\
156 ((otype) = _o[0] << 8 | _o[1]) && ((odata) = (void*)&_o[4]) &&\
157 ((olen) = _o[2] << 8 | _o[3]) + (odata) <= (end); \
158 _o += 4 + (_o[2] << 8 | _o[3]))