]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd-network/dhcp-protocol.h
tree-wide: use proper unicode © instead of (C) where we can
[thirdparty/systemd.git] / src / libsystemd-network / dhcp-protocol.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
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 #include <stdint.h>
11
12 #include "macro.h"
13 #include "sparse-endian.h"
14
15 struct DHCPMessage {
16 uint8_t op;
17 uint8_t htype;
18 uint8_t hlen;
19 uint8_t hops;
20 be32_t xid;
21 be16_t secs;
22 be16_t flags;
23 be32_t ciaddr;
24 be32_t yiaddr;
25 be32_t siaddr;
26 be32_t giaddr;
27 uint8_t chaddr[16];
28 uint8_t sname[64];
29 uint8_t file[128];
30 be32_t magic;
31 uint8_t options[0];
32 } _packed_;
33
34 typedef struct DHCPMessage DHCPMessage;
35
36 struct DHCPPacket {
37 struct iphdr ip;
38 struct udphdr udp;
39 DHCPMessage dhcp;
40 } _packed_;
41
42 typedef struct DHCPPacket DHCPPacket;
43
44 #define DHCP_IP_SIZE (int32_t)(sizeof(struct iphdr))
45 #define DHCP_IP_UDP_SIZE (int32_t)(sizeof(struct udphdr) + DHCP_IP_SIZE)
46 #define DHCP_MESSAGE_SIZE (int32_t)(sizeof(DHCPMessage))
47 #define DHCP_DEFAULT_MIN_SIZE 576 /* the minimum internet hosts must be able to receive */
48 #define DHCP_MIN_OPTIONS_SIZE (DHCP_DEFAULT_MIN_SIZE - DHCP_IP_UDP_SIZE - DHCP_MESSAGE_SIZE)
49 #define DHCP_MAGIC_COOKIE (uint32_t)(0x63825363)
50
51 enum {
52 DHCP_PORT_SERVER = 67,
53 DHCP_PORT_CLIENT = 68,
54 };
55
56 enum DHCPState {
57 DHCP_STATE_INIT = 0,
58 DHCP_STATE_SELECTING = 1,
59 DHCP_STATE_INIT_REBOOT = 2,
60 DHCP_STATE_REBOOTING = 3,
61 DHCP_STATE_REQUESTING = 4,
62 DHCP_STATE_BOUND = 5,
63 DHCP_STATE_RENEWING = 6,
64 DHCP_STATE_REBINDING = 7,
65 DHCP_STATE_STOPPED = 8,
66 };
67
68 typedef enum DHCPState DHCPState;
69
70 enum {
71 BOOTREQUEST = 1,
72 BOOTREPLY = 2,
73 };
74
75 enum {
76 DHCP_DISCOVER = 1,
77 DHCP_OFFER = 2,
78 DHCP_REQUEST = 3,
79 DHCP_DECLINE = 4,
80 DHCP_ACK = 5,
81 DHCP_NAK = 6,
82 DHCP_RELEASE = 7,
83 DHCP_INFORM = 8,
84 DHCP_FORCERENEW = 9,
85 };
86
87 enum {
88 DHCP_OVERLOAD_FILE = 1,
89 DHCP_OVERLOAD_SNAME = 2,
90 };
91
92 #define DHCP_MAX_FQDN_LENGTH 255
93
94 enum {
95 DHCP_FQDN_FLAG_S = (1 << 0),
96 DHCP_FQDN_FLAG_O = (1 << 1),
97 DHCP_FQDN_FLAG_E = (1 << 2),
98 DHCP_FQDN_FLAG_N = (1 << 3),
99 };