]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd-network/dhcp-protocol.h
Add SPDX license identifiers to source files under the LGPL
[thirdparty/systemd.git] / src / libsystemd-network / dhcp-protocol.h
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
5f404b1e
PF
2#pragma once
3
4/***
5 This file is part of systemd.
6
7 Copyright (C) 2013 Intel Corporation. All rights reserved.
8
9 systemd is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13
14 systemd is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21***/
22
5f404b1e 23#include <netinet/ip.h>
71d35b6b 24#include <netinet/udp.h>
5f404b1e
PF
25#include <stdint.h>
26
27#include "macro.h"
28#include "sparse-endian.h"
29
30struct DHCPMessage {
31 uint8_t op;
32 uint8_t htype;
33 uint8_t hlen;
34 uint8_t hops;
35 be32_t xid;
36 be16_t secs;
37 be16_t flags;
3b349af6
PF
38 be32_t ciaddr;
39 be32_t yiaddr;
40 be32_t siaddr;
41 be32_t giaddr;
5f404b1e
PF
42 uint8_t chaddr[16];
43 uint8_t sname[64];
44 uint8_t file[128];
3b7ca119 45 be32_t magic;
20b958bf 46 uint8_t options[0];
5f404b1e
PF
47} _packed_;
48
49typedef struct DHCPMessage DHCPMessage;
50
51struct DHCPPacket {
52 struct iphdr ip;
53 struct udphdr udp;
54 DHCPMessage dhcp;
55} _packed_;
56
57typedef struct DHCPPacket DHCPPacket;
58
8c00042c
PF
59#define DHCP_IP_SIZE (int32_t)(sizeof(struct iphdr))
60#define DHCP_IP_UDP_SIZE (int32_t)(sizeof(struct udphdr) + DHCP_IP_SIZE)
61#define DHCP_MESSAGE_SIZE (int32_t)(sizeof(DHCPMessage))
324f8187 62#define DHCP_DEFAULT_MIN_SIZE 576 /* the minimum internet hosts must be able to receive */
671eaa74 63#define DHCP_MIN_OPTIONS_SIZE (DHCP_DEFAULT_MIN_SIZE - DHCP_IP_UDP_SIZE - DHCP_MESSAGE_SIZE)
3b7ca119 64#define DHCP_MAGIC_COOKIE (uint32_t)(0x63825363)
8c00042c 65
46a66b79
PF
66enum {
67 DHCP_PORT_SERVER = 67,
68 DHCP_PORT_CLIENT = 68,
69};
70
5f404b1e
PF
71enum DHCPState {
72 DHCP_STATE_INIT = 0,
73 DHCP_STATE_SELECTING = 1,
74 DHCP_STATE_INIT_REBOOT = 2,
75 DHCP_STATE_REBOOTING = 3,
76 DHCP_STATE_REQUESTING = 4,
77 DHCP_STATE_BOUND = 5,
78 DHCP_STATE_RENEWING = 6,
79 DHCP_STATE_REBINDING = 7,
781ca7a1 80 DHCP_STATE_STOPPED = 8,
5f404b1e
PF
81};
82
83typedef enum DHCPState DHCPState;
84
85enum {
86 BOOTREQUEST = 1,
87 BOOTREPLY = 2,
88};
89
90enum {
91 DHCP_DISCOVER = 1,
92 DHCP_OFFER = 2,
93 DHCP_REQUEST = 3,
94 DHCP_DECLINE = 4,
95 DHCP_ACK = 5,
96 DHCP_NAK = 6,
97 DHCP_RELEASE = 7,
615c1467
TG
98 DHCP_INFORM = 8,
99 DHCP_FORCERENEW = 9,
5f404b1e
PF
100};
101
102enum {
103 DHCP_OVERLOAD_FILE = 1,
104 DHCP_OVERLOAD_SNAME = 2,
105};
106
23873e25
BG
107#define DHCP_MAX_FQDN_LENGTH 255
108
109enum {
110 DHCP_FQDN_FLAG_S = (1 << 0),
111 DHCP_FQDN_FLAG_O = (1 << 1),
112 DHCP_FQDN_FLAG_E = (1 << 2),
113 DHCP_FQDN_FLAG_N = (1 << 3),
114};