]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd-network/dhcp-protocol.h
basic/include: replace _Static_assert() with static_assert()
[thirdparty/systemd.git] / src / libsystemd-network / dhcp-protocol.h
CommitLineData
db9ecf05 1/* SPDX-License-Identifier: LGPL-2.1-or-later */
5f404b1e
PF
2#pragma once
3
4/***
810adae9 5 Copyright © 2013 Intel Corporation. All rights reserved.
5f404b1e
PF
6***/
7
5f404b1e 8#include <netinet/ip.h>
71d35b6b 9#include <netinet/udp.h>
5f404b1e 10
8664ded7
YW
11#include "sd-dhcp-protocol.h"
12
5cdf13c7 13#include "forward.h"
5f404b1e 14#include "sparse-endian.h"
14bd102e
SS
15#include "time-util.h"
16
17/* RFC 8925 - IPv6-Only Preferred Option for DHCPv4 3.4.
18 * MIN_V6ONLY_WAIT: The lower boundary for V6ONLY_WAIT. Value: 300 seconds */
19#define MIN_V6ONLY_WAIT_USEC (300U * USEC_PER_SEC)
5f404b1e 20
5b160db5
YW
21#define DHCP_MESSAGE_HEADER_DEFINITION \
22 uint8_t op; \
23 uint8_t htype; \
24 uint8_t hlen; \
25 uint8_t hops; \
26 be32_t xid; \
27 be16_t secs; \
28 be16_t flags; \
29 be32_t ciaddr; \
30 be32_t yiaddr; \
31 be32_t siaddr; \
32 be32_t giaddr; \
33 uint8_t chaddr[16]; \
34 uint8_t sname[64]; \
35 uint8_t file[128]; \
3b7ca119 36 be32_t magic;
5b160db5
YW
37
38struct DHCPMessage {
39 DHCP_MESSAGE_HEADER_DEFINITION;
d42add3c 40 uint8_t options[];
5f404b1e
PF
41} _packed_;
42
43typedef struct DHCPMessage DHCPMessage;
44
45struct DHCPPacket {
46 struct iphdr ip;
47 struct udphdr udp;
48 DHCPMessage dhcp;
49} _packed_;
50
51typedef struct DHCPPacket DHCPPacket;
52
8c00042c
PF
53#define DHCP_IP_SIZE (int32_t)(sizeof(struct iphdr))
54#define DHCP_IP_UDP_SIZE (int32_t)(sizeof(struct udphdr) + DHCP_IP_SIZE)
4473cd7f
YW
55#define DHCP_HEADER_SIZE (int32_t)(sizeof(DHCPMessage))
56#define DHCP_MIN_MESSAGE_SIZE 576 /* the minimum internet hosts must be able to receive, see RFC 2132 Section 9.10 */
57#define DHCP_MIN_OPTIONS_SIZE (DHCP_MIN_MESSAGE_SIZE - DHCP_HEADER_SIZE)
58#define DHCP_MIN_PACKET_SIZE (DHCP_MIN_MESSAGE_SIZE + DHCP_IP_UDP_SIZE)
3b7ca119 59#define DHCP_MAGIC_COOKIE (uint32_t)(0x63825363)
8c00042c 60
46a66b79
PF
61enum {
62 DHCP_PORT_SERVER = 67,
63 DHCP_PORT_CLIENT = 68,
64};
65
5f404b1e
PF
66enum {
67 BOOTREQUEST = 1,
68 BOOTREPLY = 2,
69};
70
71enum {
71a9e3a3
YW
72 DHCP_DISCOVER = 1, /* [RFC2132] */
73 DHCP_OFFER = 2, /* [RFC2132] */
74 DHCP_REQUEST = 3, /* [RFC2132] */
75 DHCP_DECLINE = 4, /* [RFC2132] */
76 DHCP_ACK = 5, /* [RFC2132] */
77 DHCP_NAK = 6, /* [RFC2132] */
78 DHCP_RELEASE = 7, /* [RFC2132] */
79 DHCP_INFORM = 8, /* [RFC2132] */
80 DHCP_FORCERENEW = 9, /* [RFC3203] */
81 DHCPLEASEQUERY = 10, /* [RFC4388] */
82 DHCPLEASEUNASSIGNED = 11, /* [RFC4388] */
83 DHCPLEASEUNKNOWN = 12, /* [RFC4388] */
84 DHCPLEASEACTIVE = 13, /* [RFC4388] */
85 DHCPBULKLEASEQUERY = 14, /* [RFC6926] */
86 DHCPLEASEQUERYDONE = 15, /* [RFC6926] */
87 DHCPACTIVELEASEQUERY = 16, /* [RFC7724] */
88 DHCPLEASEQUERYSTATUS = 17, /* [RFC7724] */
89 DHCPTLS = 18, /* [RFC7724] */
5f404b1e
PF
90};
91
92enum {
93 DHCP_OVERLOAD_FILE = 1,
94 DHCP_OVERLOAD_SNAME = 2,
95};
96
23873e25
BG
97#define DHCP_MAX_FQDN_LENGTH 255
98
99enum {
100 DHCP_FQDN_FLAG_S = (1 << 0),
101 DHCP_FQDN_FLAG_O = (1 << 1),
102 DHCP_FQDN_FLAG_E = (1 << 2),
103 DHCP_FQDN_FLAG_N = (1 << 3),
104};