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-2025 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, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifndef DHCP_H
24#define DHCP_H
25
26#include "common.h"
27#include "buffer.h"
28#include "proto.h"
29
30#pragma pack(1)
31
32/* DHCP Option types */
33#define DHCP_PAD 0
34#define DHCP_ROUTER 3
35#define DHCP_DOMAIN_SERVER 6
36#define DHCP_DOMAIN_NAME 15
37#define DHCP_NTP_SERVER 42
38#define DHCP_VENDOR 43
39#define DHCP_NETBIOS_DOMAIN_SERVER 44
40#define DHCP_NETBIOS_DIST_SERVER 45
41#define DHCP_NETBIOS_NODE_TYPE 46
42#define DHCP_NETBIOS_SCOPE 47
43#define DHCP_MSG_TYPE 53
44#define DHCP_DOMAIN_SEARCH 119
45#define DHCP_END 255
46
47/* DHCP Messages types */
48#define DHCPDISCOVER 1
49#define DHCPOFFER 2
50#define DHCPREQUEST 3
51#define DHCPDECLINE 4
52#define DHCPACK 5
53#define DHCPNAK 6
54#define DHCPRELEASE 7
55#define DHCPINFORM 8
56
57/* DHCP UDP port numbers */
58#define BOOTPS_PORT 67
59#define BOOTPC_PORT 68
60
61struct dhcp
62{
63#define BOOTREQUEST 1
64#define BOOTREPLY 2
65 uint8_t op; /* message op */
66
67 uint8_t htype; /* hardware address type (e.g. '1' = 10Mb Ethernet) */
68 uint8_t hlen; /* hardware address length (e.g. '6' for 10Mb Ethernet) */
69 uint8_t hops; /* client sets to 0, may be used by relay agents */
70 uint32_t xid; /* transaction ID, chosen by client */
71 uint16_t secs; /* seconds since request process began, set by client */
72 uint16_t flags;
73 uint32_t ciaddr; /* client IP address, client sets if known */
74 uint32_t yiaddr; /* 'your' IP address -- server's response to client */
75 uint32_t siaddr; /* server IP address */
76 uint32_t giaddr; /* relay agent IP address */
77 uint8_t chaddr[16]; /* client hardware address */
78 uint8_t sname[64]; /* optional server host name */
79 uint8_t file[128]; /* boot file name */
80 uint32_t magic; /* must be 0x63825363 (network order) */
81};
82
84{
87 struct dhcp dhcp;
88#define DHCP_OPTIONS_BUFFER_SIZE 256
90};
91
92#pragma pack()
93
94in_addr_t dhcp_extract_router_msg(struct buffer *ipbuf);
95
96#if defined(_WIN32) || defined(DHCP_UNIT_TEST)
97#include "tun.h"
98
99bool build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o);
100#endif
101
102#endif /* ifndef DHCP_H */
in_addr_t dhcp_extract_router_msg(struct buffer *ipbuf)
Definition dhcp.c:148
#define DHCP_OPTIONS_BUFFER_SIZE
Definition dhcp.h:88
bool build_dhcp_options_string(struct buffer *buf, const struct tuntap_options *o)
Definition dhcp.c:330
Wrapper structure for dynamically allocated memory.
Definition buffer.h:60
struct openvpn_udphdr udp
Definition dhcp.h:86
struct openvpn_iphdr ip
Definition dhcp.h:85
Definition dhcp.h:62
uint32_t giaddr
Definition dhcp.h:76
uint32_t yiaddr
Definition dhcp.h:74
uint8_t op
Definition dhcp.h:65
uint8_t chaddr[16]
Definition dhcp.h:77
uint16_t flags
Definition dhcp.h:72
uint8_t htype
Definition dhcp.h:67
uint32_t ciaddr
Definition dhcp.h:73
uint8_t file[128]
Definition dhcp.h:79
uint32_t magic
Definition dhcp.h:80
uint8_t sname[64]
Definition dhcp.h:78
uint32_t siaddr
Definition dhcp.h:75
uint16_t secs
Definition dhcp.h:71
uint8_t hlen
Definition dhcp.h:68
uint8_t hops
Definition dhcp.h:69
uint32_t xid
Definition dhcp.h:70