summaryrefslogtreecommitdiffstats
path: root/tap-win32/dhcp.h
blob: ae3815b9209de6d638075dce8bbfc365e18c26f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 *  TAP-Win32/TAP-Win64 -- A kernel driver to provide virtual tap
 *                         device functionality on Windows.
 *
 *  This code was inspired by the CIPE-Win32 driver by Damion K. Wilson.
 *
 *  This source code is Copyright (C) 2002-2007 OpenVPN Solutions LLC,
 *  and is released under the GPL version 2 (see below), however due
 *  to the extra costs of supporting Windows Vista, OpenVPN Solutions
 *  LLC reserves the right to change the terms of the TAP-Win32/TAP-Win64
 *  license for versions 9.1 and higher prior to the official release of
 *  OpenVPN 2.1.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2
 *  as published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program (see the file COPYING included with this
 *  distribution); if not, write to the Free Software Foundation, Inc.,
 *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#pragma pack(1)

//===================================================
// How many bad DHCPREQUESTs do we receive before we
// return a NAK?
//
// A bad DHCPREQUEST is defined to be one where the
// requestor doesn't know its IP address.
//===================================================

#define BAD_DHCPREQUEST_NAK_THRESHOLD 3

//==============================================
// Maximum number of DHCP options bytes supplied
//==============================================

#define DHCP_USER_SUPPLIED_OPTIONS_BUFFER_SIZE 256
#define DHCP_OPTIONS_BUFFER_SIZE               256

//===================================
// UDP port numbers of DHCP messages.
//===================================

#define BOOTPS_PORT 67
#define BOOTPC_PORT 68

//===========================
// The DHCP message structure
//===========================

typedef struct {
# define BOOTREQUEST 1
# define BOOTREPLY   2
  UCHAR op;          /* message op */

  UCHAR  htype;      /* hardware address type (e.g. '1' = 10Mb Ethernet) */
  UCHAR  hlen;       /* hardware address length (e.g. '6' for 10Mb Ethernet) */
  UCHAR  hops;       /* client sets to 0, may be used by relay agents */
  ULONG  xid;        /* transaction ID, chosen by client */
  USHORT secs;       /* seconds since request process began, set by client */
  USHORT flags;
  ULONG  ciaddr;     /* client IP address, client sets if known */
  ULONG  yiaddr;     /* 'your' IP address -- server's response to client */
  ULONG  siaddr;     /* server IP address */
  ULONG  giaddr;     /* relay agent IP address */
  UCHAR  chaddr[16]; /* client hardware address */
  UCHAR  sname[64];  /* optional server host name */
  UCHAR  file[128];  /* boot file name */
  ULONG  magic;      /* must be 0x63825363 (network order) */
} DHCP;

typedef struct {
  ETH_HEADER eth;
  IPHDR ip;
  UDPHDR udp;
  DHCP dhcp;
} DHCPPre;

typedef struct {
  DHCPPre pre;
  UCHAR options[DHCP_OPTIONS_BUFFER_SIZE];
} DHCPFull;

typedef struct {
  unsigned int optlen;
  BOOLEAN overflow;
  DHCPFull msg;
} DHCPMsg;

//===================
// Macros for DHCPMSG
//===================

#define DHCPMSG_LEN_BASE(p) (sizeof (DHCPPre))
#define DHCPMSG_LEN_OPT(p)  ((p)->optlen)
#define DHCPMSG_LEN_FULL(p) (DHCPMSG_LEN_BASE(p) + DHCPMSG_LEN_OPT(p))
#define DHCPMSG_BUF(p)      ((UCHAR*) &(p)->msg)
#define DHCPMSG_OVERFLOW(p) ((p)->overflow)

//========================================
// structs to hold individual DHCP options
//========================================

typedef struct {
  UCHAR type;
} DHCPOPT0;

typedef struct {
  UCHAR type;
  UCHAR len;
  UCHAR data;
} DHCPOPT8;

typedef struct {
  UCHAR type;
  UCHAR len;
  ULONG data;
} DHCPOPT32;

#pragma pack()

//==================
// DHCP Option types
//==================

#define DHCP_MSG_TYPE    53  /* message type (u8) */
#define DHCP_PARM_REQ    55  /* parameter request list: c1 (u8), ... */
#define DHCP_CLIENT_ID   61  /* client ID: type (u8), i1 (u8), ... */
#define DHCP_IP          50  /* requested IP addr (u32) */
#define DHCP_NETMASK      1  /* subnet mask (u32) */
#define DHCP_LEASE_TIME  51  /* lease time sec (u32) */
#define DHCP_RENEW_TIME  58  /* renewal time sec (u32) */
#define DHCP_REBIND_TIME 59  /* rebind time sec (u32) */
#define DHCP_SERVER_ID   54  /* server ID: IP addr (u32) */
#define DHCP_PAD          0
#define DHCP_END        255

//====================
// DHCP Messages types
//====================

#define DHCPDISCOVER 1
#define DHCPOFFER    2
#define DHCPREQUEST  3
#define DHCPDECLINE  4
#define DHCPACK      5
#define DHCPNAK      6
#define DHCPRELEASE  7
#define DHCPINFORM   8

#if DBG

VOID
DumpDHCP (const ETH_HEADER *eth,
	  const IPHDR *ip,
	  const UDPHDR *udp,
	  const DHCP *dhcp,
	  const int optlen);

#endif