dhcpv4: force renew nonce authentication support
[project/odhcpd.git] / src / dhcpv4.h
1 /**
2 * Copyright (C) 2012 Steven Barth <steven@midlink.org>
3 * Copyright (C) 2016 Hans Dedecker <dedeckeh@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License version 2 for more details.
13 *
14 */
15 #pragma once
16
17 #define DHCPV4_CLIENT_PORT 68
18 #define DHCPV4_SERVER_PORT 67
19
20 #define DHCPV4_FLAG_BROADCAST 0x8000
21
22 enum dhcpv4_op {
23 DHCPV4_BOOTREQUEST = 1,
24 DHCPV4_BOOTREPLY = 2
25 };
26
27 enum dhcpv4_msg {
28 DHCPV4_MSG_DISCOVER = 1,
29 DHCPV4_MSG_OFFER = 2,
30 DHCPV4_MSG_REQUEST = 3,
31 DHCPV4_MSG_DECLINE = 4,
32 DHCPV4_MSG_ACK = 5,
33 DHCPV4_MSG_NAK = 6,
34 DHCPV4_MSG_RELEASE = 7,
35 DHCPV4_MSG_INFORM = 8,
36 DHCPV4_MSG_FORCERENEW = 9,
37 };
38
39 enum dhcpv4_opt {
40 DHCPV4_OPT_NETMASK = 1,
41 DHCPV4_OPT_ROUTER = 3,
42 DHCPV4_OPT_DNSSERVER = 6,
43 DHCPV4_OPT_DOMAIN = 15,
44 DHCPV4_OPT_MTU = 26,
45 DHCPV4_OPT_BROADCAST = 28,
46 DHCPV4_OPT_NTPSERVER = 42,
47 DHCPV4_OPT_LEASETIME = 51,
48 DHCPV4_OPT_MESSAGE = 53,
49 DHCPV4_OPT_SERVERID = 54,
50 DHCPV4_OPT_RENEW = 58,
51 DHCPV4_OPT_REBIND = 59,
52 DHCPV4_OPT_IPADDRESS = 50,
53 DHCPV4_OPT_HOSTNAME = 12,
54 DHCPV4_OPT_REQUEST = 17,
55 DHCPV4_OPT_USER_CLASS = 77,
56 DHCPV4_OPT_AUTHENTICATION = 90,
57 DHCPV4_OPT_SEARCH_DOMAIN = 119,
58 DHCPV4_OPT_FORCERENEW_NONCE_CAPABLE = 145,
59 DHCPV4_OPT_END = 255,
60 };
61
62 struct dhcpv4_message {
63 uint8_t op;
64 uint8_t htype;
65 uint8_t hlen;
66 uint8_t hops;
67 uint32_t xid;
68 uint16_t secs;
69 uint16_t flags;
70 struct in_addr ciaddr;
71 struct in_addr yiaddr;
72 struct in_addr siaddr;
73 struct in_addr giaddr;
74 uint8_t chaddr[16];
75 char sname[64];
76 char file[128];
77 uint8_t options[312];
78 };
79
80 struct dhcpv4_auth_forcerenew {
81 uint8_t protocol;
82 uint8_t algorithm;
83 uint8_t rdm;
84 uint32_t replay[2];
85 uint8_t type;
86 uint8_t key[16];
87 } _packed;
88
89 struct odhcpd_ref_ip;
90
91 struct dhcpv4_assignment {
92 struct list_head head;
93 struct interface *iface;
94
95 struct uloop_timeout fr_timer;
96 struct odhcpd_ref_ip *fr_ip;
97 bool accept_fr_nonce;
98 int fr_cnt;
99 uint8_t key[16];
100
101 unsigned int flags;
102
103 uint32_t addr;
104 time_t valid_until;
105 uint8_t hwaddr[6];
106 uint32_t leasetime;
107 char *hostname;
108 };
109
110 struct dhcpv4_option {
111 uint8_t type;
112 uint8_t len;
113 uint8_t data[];
114 };
115
116
117 #define dhcpv4_for_each_option(start, end, opt)\
118 for (opt = (struct dhcpv4_option*)(start); \
119 &opt[1] <= (struct dhcpv4_option*)(end) && \
120 &opt->data[opt->len] <= (end); \
121 opt = (struct dhcpv4_option*)&opt->data[opt->len])