ignore hnet internal routers
[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 = 10,
52 DHCPV4_OPT_REQUEST = 17,
53 DHCPV4_OPT_VENDOR_SPECIFIC_INFORMATION = 125,
54 DHCPV4_OPT_END = 255,
55 };
56
57 struct dhcpv4_message {
58 uint8_t op;
59 uint8_t htype;
60 uint8_t hlen;
61 uint8_t hops;
62 uint32_t xid;
63 uint16_t secs;
64 uint16_t flags;
65 struct in_addr ciaddr;
66 struct in_addr yiaddr;
67 struct in_addr siaddr;
68 struct in_addr giaddr;
69 uint8_t chaddr[16];
70 char sname[64];
71 char file[128];
72 uint8_t options[312];
73 };
74
75 struct dhcpv4_assignment {
76 struct list_head head;
77 uint32_t addr;
78 time_t valid_until;
79 uint8_t hwaddr[6];
80 char hostname[];
81 };
82
83 struct dhcpv4_option {
84 uint8_t type;
85 uint8_t len;
86 uint8_t data[];
87 };
88
89
90 #define dhcpv4_for_each_option(start, end, opt)\
91 for (opt = (struct dhcpv4_option*)(start); \
92 &opt[1] <= (struct dhcpv4_option*)(end) && \
93 &opt->data[opt->len] <= (end); \
94 opt = (struct dhcpv4_option*)&opt->data[opt->len])