]>
Commit | Line | Data |
---|---|---|
1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ | |
2 | #pragma once | |
3 | ||
4 | /*** | |
5 | Copyright © 2013 Intel Corporation. All rights reserved. | |
6 | ***/ | |
7 | ||
8 | #include <netinet/ip.h> | |
9 | #include <netinet/udp.h> | |
10 | ||
11 | #include "sd-dhcp-protocol.h" | |
12 | ||
13 | #include "forward.h" | |
14 | #include "sparse-endian.h" | |
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) | |
20 | ||
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]; \ | |
36 | be32_t magic; | |
37 | ||
38 | struct DHCPMessage { | |
39 | DHCP_MESSAGE_HEADER_DEFINITION; | |
40 | uint8_t options[]; | |
41 | } _packed_; | |
42 | ||
43 | typedef struct DHCPMessage DHCPMessage; | |
44 | ||
45 | struct DHCPPacket { | |
46 | struct iphdr ip; | |
47 | struct udphdr udp; | |
48 | DHCPMessage dhcp; | |
49 | } _packed_; | |
50 | ||
51 | typedef struct DHCPPacket DHCPPacket; | |
52 | ||
53 | #define DHCP_IP_SIZE (int32_t)(sizeof(struct iphdr)) | |
54 | #define DHCP_IP_UDP_SIZE (int32_t)(sizeof(struct udphdr) + DHCP_IP_SIZE) | |
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) | |
59 | #define DHCP_MAGIC_COOKIE (uint32_t)(0x63825363) | |
60 | ||
61 | enum { | |
62 | DHCP_PORT_SERVER = 67, | |
63 | DHCP_PORT_CLIENT = 68, | |
64 | }; | |
65 | ||
66 | enum { | |
67 | BOOTREQUEST = 1, | |
68 | BOOTREPLY = 2, | |
69 | }; | |
70 | ||
71 | enum { | |
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] */ | |
90 | }; | |
91 | ||
92 | enum { | |
93 | DHCP_OVERLOAD_FILE = 1, | |
94 | DHCP_OVERLOAD_SNAME = 2, | |
95 | }; | |
96 | ||
97 | #define DHCP_MAX_FQDN_LENGTH 255 | |
98 | ||
99 | enum { | |
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 | }; |