Upgrade to OpenVPN 2.1.0
[tomato.git] / release / src / router / openvpn / tap-win32 / dhcp.h
blobbabe31eca7b86f670ba70bb668d71208554b8499
1 /*
2 * TAP-Win32/TAP-Win64 -- A kernel driver to provide virtual tap
3 * device functionality on Windows.
5 * This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
7 * This source code is Copyright (C) 2002-2009 OpenVPN Technologies, Inc.,
8 * and is released under the GPL version 2 (see below).
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program (see the file COPYING included with this
21 * distribution); if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #pragma pack(1)
27 //===================================================
28 // How many bad DHCPREQUESTs do we receive before we
29 // return a NAK?
31 // A bad DHCPREQUEST is defined to be one where the
32 // requestor doesn't know its IP address.
33 //===================================================
35 #define BAD_DHCPREQUEST_NAK_THRESHOLD 3
37 //==============================================
38 // Maximum number of DHCP options bytes supplied
39 //==============================================
41 #define DHCP_USER_SUPPLIED_OPTIONS_BUFFER_SIZE 256
42 #define DHCP_OPTIONS_BUFFER_SIZE 256
44 //===================================
45 // UDP port numbers of DHCP messages.
46 //===================================
48 #define BOOTPS_PORT 67
49 #define BOOTPC_PORT 68
51 //===========================
52 // The DHCP message structure
53 //===========================
55 typedef struct {
56 # define BOOTREQUEST 1
57 # define BOOTREPLY 2
58 UCHAR op; /* message op */
60 UCHAR htype; /* hardware address type (e.g. '1' = 10Mb Ethernet) */
61 UCHAR hlen; /* hardware address length (e.g. '6' for 10Mb Ethernet) */
62 UCHAR hops; /* client sets to 0, may be used by relay agents */
63 ULONG xid; /* transaction ID, chosen by client */
64 USHORT secs; /* seconds since request process began, set by client */
65 USHORT flags;
66 ULONG ciaddr; /* client IP address, client sets if known */
67 ULONG yiaddr; /* 'your' IP address -- server's response to client */
68 ULONG siaddr; /* server IP address */
69 ULONG giaddr; /* relay agent IP address */
70 UCHAR chaddr[16]; /* client hardware address */
71 UCHAR sname[64]; /* optional server host name */
72 UCHAR file[128]; /* boot file name */
73 ULONG magic; /* must be 0x63825363 (network order) */
74 } DHCP;
76 typedef struct {
77 ETH_HEADER eth;
78 IPHDR ip;
79 UDPHDR udp;
80 DHCP dhcp;
81 } DHCPPre;
83 typedef struct {
84 DHCPPre pre;
85 UCHAR options[DHCP_OPTIONS_BUFFER_SIZE];
86 } DHCPFull;
88 typedef struct {
89 unsigned int optlen;
90 BOOLEAN overflow;
91 DHCPFull msg;
92 } DHCPMsg;
94 //===================
95 // Macros for DHCPMSG
96 //===================
98 #define DHCPMSG_LEN_BASE(p) (sizeof (DHCPPre))
99 #define DHCPMSG_LEN_OPT(p) ((p)->optlen)
100 #define DHCPMSG_LEN_FULL(p) (DHCPMSG_LEN_BASE(p) + DHCPMSG_LEN_OPT(p))
101 #define DHCPMSG_BUF(p) ((UCHAR*) &(p)->msg)
102 #define DHCPMSG_OVERFLOW(p) ((p)->overflow)
104 //========================================
105 // structs to hold individual DHCP options
106 //========================================
108 typedef struct {
109 UCHAR type;
110 } DHCPOPT0;
112 typedef struct {
113 UCHAR type;
114 UCHAR len;
115 UCHAR data;
116 } DHCPOPT8;
118 typedef struct {
119 UCHAR type;
120 UCHAR len;
121 ULONG data;
122 } DHCPOPT32;
124 #pragma pack()
126 //==================
127 // DHCP Option types
128 //==================
130 #define DHCP_MSG_TYPE 53 /* message type (u8) */
131 #define DHCP_PARM_REQ 55 /* parameter request list: c1 (u8), ... */
132 #define DHCP_CLIENT_ID 61 /* client ID: type (u8), i1 (u8), ... */
133 #define DHCP_IP 50 /* requested IP addr (u32) */
134 #define DHCP_NETMASK 1 /* subnet mask (u32) */
135 #define DHCP_LEASE_TIME 51 /* lease time sec (u32) */
136 #define DHCP_RENEW_TIME 58 /* renewal time sec (u32) */
137 #define DHCP_REBIND_TIME 59 /* rebind time sec (u32) */
138 #define DHCP_SERVER_ID 54 /* server ID: IP addr (u32) */
139 #define DHCP_PAD 0
140 #define DHCP_END 255
142 //====================
143 // DHCP Messages types
144 //====================
146 #define DHCPDISCOVER 1
147 #define DHCPOFFER 2
148 #define DHCPREQUEST 3
149 #define DHCPDECLINE 4
150 #define DHCPACK 5
151 #define DHCPNAK 6
152 #define DHCPRELEASE 7
153 #define DHCPINFORM 8
155 #if DBG
157 VOID
158 DumpDHCP (const ETH_HEADER *eth,
159 const IPHDR *ip,
160 const UDPHDR *udp,
161 const DHCP *dhcp,
162 const int optlen);
164 #endif