]> git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/dhcpmessage.hh
and the final bit of whitespace/tab cleanup
[thirdparty/pdns.git] / pdns / dhcpmessage.hh
1 #ifndef DHCPMESSAGE_HH
2 #define DHCPMESSAGE_HH
3
4
5 /*
6 * Copyright 2006, 2007 Stefan Rompf <sux@loplof.de>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation
11 */
12
13 #include <sys/types.h>
14 #include <netinet/in.h>
15 #include <string>
16 extern "C" {
17
18 #define MAX_OPT_LEN 512 // RFC 2131 Minimumsize: 312 FIXME: add OPTION_MAXSIZE to use additional bytes
19
20
21 // RFC 2132, 3.3
22 #define BOOTP_OPTION_NETMASK 1
23 // RFC 2132, 3.5
24 #define BOOTP_OPTION_GATEWAY 3
25 // RFC 2132, 3.8
26 #define BOOTP_OPTION_DNS 6
27 // RFC 2132, 3.14
28 #define BOOTP_OPTION_HOSTNAME 12
29 // RFC 2132, 3.15
30 #define BOOTP_OPTION_BOOTFILE_SIZE 13
31 // RFC 2132, 3.17
32 #define BOOTP_OPTION_DOMAIN 15
33 // RFC 2132, 5.3
34 #define BOOTP_OPTION_BROADCAST 28
35 // RFC 2132, 8.1
36 #define BOOTP_OPTION_NISDOMAIN 40
37
38 // RFC 2132, 3.9
39 #define DHCP_OPTION_LOGSRVS 7
40 // RFC 2132, 3.11
41 #define DHCP_OPTION_LPRSRVS 9
42 // RFC 2132, 8.3
43 #define DHCP_OPTION_NTPSRVS 42
44 // RFC 2132, 8.9
45 #define DHCP_OPTION_XFNTSRVS 48
46 // RFC 2132, 8.10
47 #define DHCP_OPTION_XDMSRVS 49
48 // RFC 2132, 9.1
49 #define DHCP_OPTION_REQADDR 50
50 // RFC 2132, 9.2
51 #define DHCP_OPTION_LEASE 51
52 // RFC 2132, 9.3
53 #define DHCP_OPTION_OVERLOAD 52
54 // RFC 2132, 9.6
55 #define DHCP_OPTION_TYPE 53
56 // RFC 2132, 9.7
57 #define DHCP_OPTION_SERVER 54
58 // RFC 2132, 9.8
59 #define DHCP_OPTION_OPTIONREQ 55
60 // RFC 2132, 9.10
61 #define DHCP_OPTION_PARAMREQ 56
62
63 #define DHCP_OPTION_MAXSIZE 57
64 // RFC 2132, 9.11
65 #define DHCP_OPTION_T1 58
66 // RFC 2132, 9.12
67 #define DHCP_OPTION_T2 59
68 // RFC 2132, 9.13
69 #define DHCP_OPTION_CLASS_IDENTIFIER 60
70 // RFC 2132, 9.14
71 #define DHCP_OPTION_CLIENT_IDENTIFIER 61
72 // RFC 4039
73 #define DHCP_OPTION_RAPID_COMMIT 80
74
75 #define BOOTP_CLIENT_PORT 68
76 #define BOOTP_SERVER_PORT 67
77
78 #define BOOTP_OPCODE_REQUEST 1
79 #define BOOTP_OPCODE_REPLY 2
80
81 #define NORESPONSE -10
82 #define DHCP_TYPE_DISCOVER 1
83 #define DHCP_TYPE_OFFER 2
84 #define DHCP_TYPE_REQUEST 3
85 #define DHCP_TYPE_DECLINE 4
86 #define DHCP_TYPE_ACK 5
87 #define DHCP_TYPE_NAK 6
88 #define DHCP_TYPE_RELEASE 7
89 #define DHCP_TYPE_INFORM 8
90
91 typedef enum {
92 DHCP_OVERLOAD_NONE,
93 DHCP_OVERLOAD_FILE,
94 DHCP_OVERLOAD_SNAME,
95 DHCP_OVERLOAD_BOTH
96 } dhcp_overload_opts;
97
98 struct dhcp_message {
99 u_int8_t *pos, *last;
100 dhcp_overload_opts overload, currentblock;
101
102 /* embedded DHCP message */
103 u_int8_t op;
104 u_int8_t htype;
105 u_int8_t hlen;
106 u_int8_t hops;
107 u_int32_t xid;
108 u_int16_t secs;
109 u_int16_t flags;
110 u_int32_t ciaddr;
111 u_int32_t yiaddr;
112 u_int32_t siaddr;
113 u_int32_t giaddr;
114 u_int8_t chaddr[16];
115 u_int8_t sname[64];
116 u_int8_t file[128];
117 u_int8_t options[MAX_OPT_LEN];
118 } __attribute__((packed)) ;
119
120
121 void dm_init(struct dhcp_message *msg);
122
123 void dm_finish_options(struct dhcp_message *msg);
124
125 void dm_add_option(struct dhcp_message *msg, u_int8_t option,
126 u_int8_t length, void *opt);
127
128 u_int8_t *dm_next_option(struct dhcp_message *msg);
129
130
131 int dm_parse_msg_raw(char *dframe, int plen,
132 struct in_addr *from_ip, struct dhcp_message *msg);
133
134 }
135
136 class DHCPCommunicator
137 {
138 public:
139 DHCPCommunicator(const std::string& remote);
140 std::string getMac(const std::string& ip);
141 private:
142 int d_socket;
143 };
144
145 #endif
146