config: fix typo in reload_cb
[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 <libubox/ustream.h>
17
18 #define ALL_DHCPV6_RELAYS {{{0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
19                 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x02}}}
20
21 #define ALL_DHCPV6_SERVERS {{{0xff, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
22                 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x03}}}
23
24 #define DHCPV6_CLIENT_PORT 546
25 #define DHCPV6_SERVER_PORT 547
26
27 #define DHCPV6_MSG_SOLICIT 1
28 #define DHCPV6_MSG_ADVERTISE 2
29 #define DHCPV6_MSG_REQUEST 3
30 #define DHCPV6_MSG_CONFIRM 4
31 #define DHCPV6_MSG_RENEW 5
32 #define DHCPV6_MSG_REBIND 6
33 #define DHCPV6_MSG_REPLY 7
34 #define DHCPV6_MSG_RELEASE 8
35 #define DHCPV6_MSG_DECLINE 9
36 #define DHCPV6_MSG_RECONFIGURE 10
37 #define DHCPV6_MSG_INFORMATION_REQUEST 11
38 #define DHCPV6_MSG_RELAY_FORW 12
39 #define DHCPV6_MSG_RELAY_REPL 13
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_USER_CLASS 15
50 #define DHCPV6_OPT_INTERFACE_ID 18
51 #define DHCPV6_OPT_RECONF_MSG 19
52 #define DHCPV6_OPT_RECONF_ACCEPT 20
53 #define DHCPV6_OPT_DNS_SERVERS 23
54 #define DHCPV6_OPT_DNS_DOMAIN 24
55 #define DHCPV6_OPT_IA_PD 25
56 #define DHCPV6_OPT_IA_PREFIX 26
57 #define DHCPV6_OPT_INFO_REFRESH 32
58 #define DHCPV6_OPT_FQDN 39
59 #define DHCPV6_OPT_SOL_MAX_RT 82
60 #define DHCPV6_OPT_INF_MAX_RT 83
61
62 #define DHCPV6_DUID_VENDOR 2
63
64 #define DHCPV6_STATUS_OK 0
65 #define DHCPV6_STATUS_NOADDRSAVAIL 2
66 #define DHCPV6_STATUS_NOBINDING 3
67 #define DHCPV6_STATUS_NOTONLINK 4
68 #define DHCPV6_STATUS_USEMULTICAST 5
69 #define DHCPV6_STATUS_NOPREFIXAVAIL 6
70
71 // I just remembered I have an old one lying around...
72 #define DHCPV6_ENT_NO  30462
73 #define DHCPV6_ENT_TYPE 1
74
75
76 #define DHCPV6_HOP_COUNT_LIMIT 32
77
78 struct dhcpv6_client_header {
79         uint8_t msg_type;
80         uint8_t transaction_id[3];
81 } __attribute__((packed));
82
83 struct dhcpv6_relay_header {
84         uint8_t msg_type;
85         uint8_t hop_count;
86         struct in6_addr link_address;
87         struct in6_addr peer_address;
88         uint8_t options[];
89 } __attribute__((packed));
90
91 struct dhcpv6_relay_forward_envelope {
92         uint8_t msg_type;
93         uint8_t hop_count;
94         struct in6_addr link_address;
95         struct in6_addr peer_address;
96         uint16_t interface_id_type;
97         uint16_t interface_id_len;
98         uint32_t interface_id_data;
99         uint16_t relay_message_type;
100         uint16_t relay_message_len;
101 } __attribute__((packed));
102
103 struct dhcpv6_auth_reconfigure {
104         uint16_t type;
105         uint16_t len;
106         uint8_t protocol;
107         uint8_t algorithm;
108         uint8_t rdm;
109         uint32_t replay[2];
110         uint8_t reconf_type;
111         uint8_t key[16];
112 } _packed;
113
114 struct dhcpv6_ia_hdr {
115         uint16_t type;
116         uint16_t len;
117         uint32_t iaid;
118         uint32_t t1;
119         uint32_t t2;
120 } _packed;
121
122 struct dhcpv6_ia_prefix {
123         uint16_t type;
124         uint16_t len;
125         uint32_t preferred;
126         uint32_t valid;
127         uint8_t prefix;
128         struct in6_addr addr;
129 } _packed;
130
131 struct dhcpv6_ia_addr {
132         uint16_t type;
133         uint16_t len;
134         struct in6_addr addr;
135         uint32_t preferred;
136         uint32_t valid;
137 } _packed;
138
139 struct dhcpv6_assignment {
140         struct list_head head;
141         struct sockaddr_in6 peer;
142         time_t valid_until;
143         time_t reconf_sent;
144         int reconf_cnt;
145         char *hostname;
146         uint8_t key[16];
147         uint32_t assigned;
148         uint32_t iaid;
149         uint8_t mac[6];
150         uint8_t length; // length == 128 -> IA_NA, length <= 64 -> IA_PD
151         bool accept_reconf;
152
153         struct odhcpd_ipaddr *managed;
154         ssize_t managed_size;
155         struct ustream_fd managed_sock;
156
157         uint8_t clid_len;
158         uint8_t clid_data[];
159 };
160
161 struct dhcpv6_cer_id {
162         uint16_t type;
163         uint16_t len;
164         uint16_t reserved;
165         uint16_t auth_type;
166         uint8_t auth[16];
167         struct in6_addr addr;
168 };
169
170
171
172 #define dhcpv6_for_each_option(start, end, otype, olen, odata)\
173         for (uint8_t *_o = (uint8_t*)(start); _o + 4 <= (end) &&\
174                 ((otype) = _o[0] << 8 | _o[1]) && ((odata) = (void*)&_o[4]) &&\
175                 ((olen) = _o[2] << 8 | _o[3]) + (odata) <= (end); \
176                 _o += 4 + (_o[2] << 8 | _o[3]))
177
178 int dhcpv6_init_ia(struct interface *iface, int socket);
179 ssize_t dhcpv6_handle_ia(uint8_t *buf, size_t buflen, struct interface *iface,
180                 const struct sockaddr_in6 *addr, const void *data, const uint8_t *end);
181 int dhcpv6_ia_init(void);
182 int setup_dhcpv6_ia_interface(struct interface *iface, bool enable);
183 void dhcpv6_write_statefile(void);