dhcpv6-ia: apply lease delete based on assignment bound state
[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 };
37
38 enum dhcpv4_opt {
39         DHCPV4_OPT_NETMASK = 1,
40         DHCPV4_OPT_ROUTER = 3,
41         DHCPV4_OPT_DNSSERVER = 6,
42         DHCPV4_OPT_DOMAIN = 15,
43         DHCPV4_OPT_MTU = 26,
44         DHCPV4_OPT_BROADCAST = 28,
45         DHCPV4_OPT_NTPSERVER = 42,
46         DHCPV4_OPT_LEASETIME = 51,
47         DHCPV4_OPT_MESSAGE = 53,
48         DHCPV4_OPT_SERVERID = 54,
49         DHCPV4_OPT_RENEW = 58,
50         DHCPV4_OPT_REBIND = 59,
51         DHCPV4_OPT_IPADDRESS = 50,
52         DHCPV4_OPT_HOSTNAME = 12,
53         DHCPV4_OPT_REQUEST = 17,
54         DHCPV4_OPT_USER_CLASS = 77,
55         DHCPV4_OPT_SEARCH_DOMAIN = 119,
56         DHCPV4_OPT_END = 255,
57 };
58
59 struct dhcpv4_message {
60         uint8_t op;
61         uint8_t htype;
62         uint8_t hlen;
63         uint8_t hops;
64         uint32_t xid;
65         uint16_t secs;
66         uint16_t flags;
67         struct in_addr ciaddr;
68         struct in_addr yiaddr;
69         struct in_addr siaddr;
70         struct in_addr giaddr;
71         uint8_t chaddr[16];
72         char sname[64];
73         char file[128];
74         uint8_t options[312];
75 };
76
77 struct dhcpv4_assignment {
78         struct list_head head;
79         uint32_t addr;
80         time_t valid_until;
81         uint8_t hwaddr[6];
82         uint32_t leasetime;
83         unsigned int flags;
84         char *hostname;
85 };
86
87 struct dhcpv4_option {
88         uint8_t type;
89         uint8_t len;
90         uint8_t data[];
91 };
92
93
94 #define dhcpv4_for_each_option(start, end, opt)\
95         for (opt = (struct dhcpv4_option*)(start); \
96                 &opt[1] <= (struct dhcpv4_option*)(end) && \
97                         &opt->data[opt->len] <= (end); \
98                 opt = (struct dhcpv4_option*)&opt->data[opt->len])