dhcpv4: implement router configuration option
[project/odhcpd.git] / src / dhcpv4.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 #define DHCPV4_CLIENT_PORT 68
17 #define DHCPV4_SERVER_PORT 67
18
19 #define DHCPV4_FLAG_BROADCAST  0x8000
20
21 enum dhcpv4_op {
22         DHCPV4_BOOTREQUEST = 1,
23         DHCPV4_BOOTREPLY = 2
24 };
25
26 enum dhcpv4_msg {
27         DHCPV4_MSG_DISCOVER = 1,
28         DHCPV4_MSG_OFFER = 2,
29         DHCPV4_MSG_REQUEST = 3,
30         DHCPV4_MSG_DECLINE = 4,
31         DHCPV4_MSG_ACK = 5,
32         DHCPV4_MSG_NAK = 6,
33         DHCPV4_MSG_RELEASE = 7,
34         DHCPV4_MSG_INFORM = 8,
35 };
36
37 enum dhcpv4_opt {
38         DHCPV4_OPT_NETMASK = 1,
39         DHCPV4_OPT_ROUTER = 3,
40         DHCPV4_OPT_DNSSERVER = 6,
41         DHCPV4_OPT_DOMAIN = 15,
42         DHCPV4_OPT_MTU = 26,
43         DHCPV4_OPT_BROADCAST = 28,
44         DHCPV4_OPT_NTPSERVER = 42,
45         DHCPV4_OPT_LEASETIME = 51,
46         DHCPV4_OPT_MESSAGE = 53,
47         DHCPV4_OPT_SERVERID = 54,
48         DHCPV4_OPT_RENEW = 58,
49         DHCPV4_OPT_REBIND = 59,
50         DHCPV4_OPT_IPADDRESS = 50,
51         DHCPV4_OPT_HOSTNAME = 12,
52         DHCPV4_OPT_REQUEST = 17,
53         DHCPV4_OPT_USER_CLASS = 77,
54         DHCPV4_OPT_SEARCH_DOMAIN = 119,
55         DHCPV4_OPT_END = 255,
56 };
57
58 struct dhcpv4_message {
59         uint8_t op;
60         uint8_t htype;
61         uint8_t hlen;
62         uint8_t hops;
63         uint32_t xid;
64         uint16_t secs;
65         uint16_t flags;
66         struct in_addr ciaddr;
67         struct in_addr yiaddr;
68         struct in_addr siaddr;
69         struct in_addr giaddr;
70         uint8_t chaddr[16];
71         char sname[64];
72         char file[128];
73         uint8_t options[312];
74 };
75
76 struct dhcpv4_assignment {
77         struct list_head head;
78         uint32_t addr;
79         time_t valid_until;
80         uint8_t hwaddr[6];
81         char hostname[];
82 };
83
84 struct dhcpv4_option {
85         uint8_t type;
86         uint8_t len;
87         uint8_t data[];
88 };
89
90
91 #define dhcpv4_for_each_option(start, end, opt)\
92         for (opt = (struct dhcpv4_option*)(start); \
93                 &opt[1] <= (struct dhcpv4_option*)(end) && \
94                         &opt->data[opt->len] <= (end); \
95                 opt = (struct dhcpv4_option*)&opt->data[opt->len])