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