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