OpenVPN
dhcp.h
Go to the documentation of this file.
1 /*
2  * OpenVPN -- An application to securely tunnel IP networks
3  * over a single TCP/UDP port, with support for SSL/TLS-based
4  * session authentication and key exchange,
5  * packet encryption, packet authentication, and
6  * packet compression.
7  *
8  * Copyright (C) 2002-2024 OpenVPN Inc <sales@openvpn.net>
9  *
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.
13  *
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.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #ifndef DHCP_H
25 #define DHCP_H
26 
27 #include "common.h"
28 #include "buffer.h"
29 #include "proto.h"
30 
31 #pragma pack(1)
32 
33 /* DHCP Option types */
34 #define DHCP_PAD 0
35 #define DHCP_ROUTER 3
36 #define DHCP_MSG_TYPE 53 /* message type (u8) */
37 #define DHCP_END 255
38 
39 /* DHCP Messages types */
40 #define DHCPDISCOVER 1
41 #define DHCPOFFER 2
42 #define DHCPREQUEST 3
43 #define DHCPDECLINE 4
44 #define DHCPACK 5
45 #define DHCPNAK 6
46 #define DHCPRELEASE 7
47 #define DHCPINFORM 8
48 
49 /* DHCP UDP port numbers */
50 #define BOOTPS_PORT 67
51 #define BOOTPC_PORT 68
52 
53 struct dhcp {
54 #define BOOTREQUEST 1
55 #define BOOTREPLY 2
56  uint8_t op; /* message op */
57 
58  uint8_t htype; /* hardware address type (e.g. '1' = 10Mb Ethernet) */
59  uint8_t hlen; /* hardware address length (e.g. '6' for 10Mb Ethernet) */
60  uint8_t hops; /* client sets to 0, may be used by relay agents */
61  uint32_t xid; /* transaction ID, chosen by client */
62  uint16_t secs; /* seconds since request process began, set by client */
63  uint16_t flags;
64  uint32_t ciaddr; /* client IP address, client sets if known */
65  uint32_t yiaddr; /* 'your' IP address -- server's response to client */
66  uint32_t siaddr; /* server IP address */
67  uint32_t giaddr; /* relay agent IP address */
68  uint8_t chaddr[16]; /* client hardware address */
69  uint8_t sname[64]; /* optional server host name */
70  uint8_t file[128]; /* boot file name */
71  uint32_t magic; /* must be 0x63825363 (network order) */
72 };
73 
74 struct dhcp_full {
75  struct openvpn_iphdr ip;
77  struct dhcp dhcp;
78 #define DHCP_OPTIONS_BUFFER_SIZE 256
80 };
81 
82 #pragma pack()
83 
84 in_addr_t dhcp_extract_router_msg(struct buffer *ipbuf);
85 
86 #endif /* ifndef DHCP_H */
dhcp_full::ip
struct openvpn_iphdr ip
Definition: dhcp.h:75
dhcp::file
uint8_t file[128]
Definition: dhcp.h:70
dhcp::magic
uint32_t magic
Definition: dhcp.h:71
dhcp::hlen
uint8_t hlen
Definition: dhcp.h:59
dhcp_full::udp
struct openvpn_udphdr udp
Definition: dhcp.h:76
dhcp::yiaddr
uint32_t yiaddr
Definition: dhcp.h:65
dhcp::flags
uint16_t flags
Definition: dhcp.h:63
openvpn_udphdr
Definition: proto.h:168
dhcp::hops
uint8_t hops
Definition: dhcp.h:60
proto.h
dhcp::xid
uint32_t xid
Definition: dhcp.h:61
options
Definition: options.h:236
dhcp::op
uint8_t op
Definition: dhcp.h:56
buffer
Wrapper structure for dynamically allocated memory.
Definition: buffer.h:60
buffer.h
dhcp::sname
uint8_t sname[64]
Definition: dhcp.h:69
DHCP_OPTIONS_BUFFER_SIZE
#define DHCP_OPTIONS_BUFFER_SIZE
Definition: dhcp.h:78
common.h
dhcp::siaddr
uint32_t siaddr
Definition: dhcp.h:66
dhcp::htype
uint8_t htype
Definition: dhcp.h:58
dhcp::secs
uint16_t secs
Definition: dhcp.h:62
dhcp_extract_router_msg
in_addr_t dhcp_extract_router_msg(struct buffer *ipbuf)
Definition: dhcp.c:149
dhcp::chaddr
uint8_t chaddr[16]
Definition: dhcp.h:68
openvpn_iphdr
Definition: proto.h:106
dhcp::ciaddr
uint32_t ciaddr
Definition: dhcp.h:64
dhcp_full
Definition: dhcp.h:74
dhcp
Definition: dhcp.h:53
dhcp::giaddr
uint32_t giaddr
Definition: dhcp.h:67