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