]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libsystemd-network/dhcp-protocol.h
dhcp6-option: Add helper function for uncompressed domain names
[thirdparty/systemd.git] / src / libsystemd-network / dhcp-protocol.h
CommitLineData
5f404b1e
PF
1/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3#pragma once
4
5/***
6 This file is part of systemd.
7
8 Copyright (C) 2013 Intel Corporation. All rights reserved.
9
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22***/
23
24#include <netinet/udp.h>
25#include <netinet/ip.h>
26#include <stdint.h>
27
28#include "macro.h"
29#include "sparse-endian.h"
30
31struct DHCPMessage {
32 uint8_t op;
33 uint8_t htype;
34 uint8_t hlen;
35 uint8_t hops;
36 be32_t xid;
37 be16_t secs;
38 be16_t flags;
3b349af6
PF
39 be32_t ciaddr;
40 be32_t yiaddr;
41 be32_t siaddr;
42 be32_t giaddr;
5f404b1e
PF
43 uint8_t chaddr[16];
44 uint8_t sname[64];
45 uint8_t file[128];
3b7ca119 46 be32_t magic;
20b958bf 47 uint8_t options[0];
5f404b1e
PF
48} _packed_;
49
50typedef struct DHCPMessage DHCPMessage;
51
52struct DHCPPacket {
53 struct iphdr ip;
54 struct udphdr udp;
55 DHCPMessage dhcp;
56} _packed_;
57
58typedef struct DHCPPacket DHCPPacket;
59
8c00042c
PF
60#define DHCP_IP_SIZE (int32_t)(sizeof(struct iphdr))
61#define DHCP_IP_UDP_SIZE (int32_t)(sizeof(struct udphdr) + DHCP_IP_SIZE)
62#define DHCP_MESSAGE_SIZE (int32_t)(sizeof(DHCPMessage))
324f8187
TG
63#define DHCP_DEFAULT_MIN_SIZE 576 /* the minimum internet hosts must be able to receive */
64#define DHCP_MIN_OPTIONS_SIZE DHCP_DEFAULT_MIN_SIZE - DHCP_IP_UDP_SIZE - DHCP_MESSAGE_SIZE
3b7ca119 65#define DHCP_MAGIC_COOKIE (uint32_t)(0x63825363)
8c00042c 66
46a66b79
PF
67enum {
68 DHCP_PORT_SERVER = 67,
69 DHCP_PORT_CLIENT = 68,
70};
71
5f404b1e
PF
72enum DHCPState {
73 DHCP_STATE_INIT = 0,
74 DHCP_STATE_SELECTING = 1,
75 DHCP_STATE_INIT_REBOOT = 2,
76 DHCP_STATE_REBOOTING = 3,
77 DHCP_STATE_REQUESTING = 4,
78 DHCP_STATE_BOUND = 5,
79 DHCP_STATE_RENEWING = 6,
80 DHCP_STATE_REBINDING = 7,
781ca7a1 81 DHCP_STATE_STOPPED = 8,
5f404b1e
PF
82};
83
84typedef enum DHCPState DHCPState;
85
86enum {
87 BOOTREQUEST = 1,
88 BOOTREPLY = 2,
89};
90
91enum {
92 DHCP_DISCOVER = 1,
93 DHCP_OFFER = 2,
94 DHCP_REQUEST = 3,
95 DHCP_DECLINE = 4,
96 DHCP_ACK = 5,
97 DHCP_NAK = 6,
98 DHCP_RELEASE = 7,
615c1467
TG
99 DHCP_INFORM = 8,
100 DHCP_FORCERENEW = 9,
5f404b1e
PF
101};
102
103enum {
104 DHCP_OVERLOAD_FILE = 1,
105 DHCP_OVERLOAD_SNAME = 2,
106};
107
108enum {
109 DHCP_OPTION_PAD = 0,
110 DHCP_OPTION_SUBNET_MASK = 1,
f5c0c00f 111 DHCP_OPTION_TIME_OFFSET = 2,
5f404b1e
PF
112 DHCP_OPTION_ROUTER = 3,
113 DHCP_OPTION_DOMAIN_NAME_SERVER = 6,
114 DHCP_OPTION_HOST_NAME = 12,
f5c0c00f 115 DHCP_OPTION_BOOT_FILE_SIZE = 13,
5f404b1e 116 DHCP_OPTION_DOMAIN_NAME = 15,
ce78df79 117 DHCP_OPTION_ROOT_PATH = 17,
f5c0c00f
TG
118 DHCP_OPTION_ENABLE_IP_FORWARDING = 19,
119 DHCP_OPTION_ENABLE_IP_FORWARDING_NL = 20,
120 DHCP_OPTION_POLICY_FILTER = 21,
121 DHCP_OPTION_INTERFACE_MDR = 22,
122 DHCP_OPTION_INTERFACE_TTL = 23,
123 DHCP_OPTION_INTERFACE_MTU_AGING_TIMEOUT = 24,
4f882b2a 124 DHCP_OPTION_INTERFACE_MTU = 26,
f5c0c00f
TG
125 DHCP_OPTION_BROADCAST = 28,
126 DHCP_OPTION_STATIC_ROUTE = 33,
5f404b1e 127 DHCP_OPTION_NTP_SERVER = 42,
e43a8393 128 DHCP_OPTION_VENDOR_SPECIFIC = 43,
5f404b1e 129 DHCP_OPTION_REQUESTED_IP_ADDRESS = 50,
8c00042c 130 DHCP_OPTION_IP_ADDRESS_LEASE_TIME = 51,
5f404b1e
PF
131 DHCP_OPTION_OVERLOAD = 52,
132 DHCP_OPTION_MESSAGE_TYPE = 53,
8c00042c 133 DHCP_OPTION_SERVER_IDENTIFIER = 54,
5f404b1e 134 DHCP_OPTION_PARAMETER_REQUEST_LIST = 55,
564ba3b0 135 DHCP_OPTION_MAXIMUM_MESSAGE_SIZE = 57,
51debc1e
PF
136 DHCP_OPTION_RENEWAL_T1_TIME = 58,
137 DHCP_OPTION_REBINDING_T2_TIME = 59,
edb85f0d 138 DHCP_OPTION_VENDOR_CLASS_IDENTIFIER = 60,
46a66b79 139 DHCP_OPTION_CLIENT_IDENTIFIER = 61,
e1ea665e 140 DHCP_OPTION_CLASSLESS_STATIC_ROUTE = 121,
85e22bfc
AC
141 DHCP_OPTION_PRIVATE_BASE = 224,
142 DHCP_OPTION_PRIVATE_LAST = 254,
5f404b1e
PF
143 DHCP_OPTION_END = 255,
144};