dhcp-protocol.h revision 324f818781a250b60f2fcfa74ff1c9101d2d1315
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen#pragma once
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen/***
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen This file is part of systemd.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen Copyright (C) 2013 Intel Corporation. All rights reserved.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen systemd is free software; you can redistribute it and/or modify it
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen under the terms of the GNU Lesser General Public License as published by
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen (at your option) any later version.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen systemd is distributed in the hope that it will be useful, but
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen Lesser General Public License for more details.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen You should have received a copy of the GNU Lesser General Public License
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen***/
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen#include <netinet/udp.h>
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen#include <netinet/ip.h>
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen#include <stdint.h>
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen#include "macro.h"
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen#include "sparse-endian.h"
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen
d122f9ee3a0e3c02ff8100a3dcd1866e90a6537aTom Gundersenstruct DHCPMessage {
4dc355680460fdc8e0d590d8572dff1b6a257d88Tom Gundersen uint8_t op;
a6f1e036de8f212f33ead7f5387c297afd8be26eTom Gundersen uint8_t htype;
a6f1e036de8f212f33ead7f5387c297afd8be26eTom Gundersen uint8_t hlen;
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen uint8_t hops;
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen be32_t xid;
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen be16_t secs;
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen be16_t flags;
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen be32_t ciaddr;
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen be32_t yiaddr;
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen be32_t siaddr;
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen be32_t giaddr;
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen uint8_t chaddr[16];
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen uint8_t sname[64];
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen uint8_t file[128];
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen be32_t magic;
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen uint8_t options[0];
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen} _packed_;
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersentypedef struct DHCPMessage DHCPMessage;
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersenstruct DHCPPacket {
2dead8129f7b6fe644e17e1dc1739bebacfe1364Tom Gundersen struct iphdr ip;
a6f1e036de8f212f33ead7f5387c297afd8be26eTom Gundersen struct udphdr udp;
a6f1e036de8f212f33ead7f5387c297afd8be26eTom Gundersen DHCPMessage dhcp;
20af7091de0cdf92bf299addfc3f96c3ef805bd8Tom Gundersen} _packed_;
20af7091de0cdf92bf299addfc3f96c3ef805bd8Tom Gundersen
20af7091de0cdf92bf299addfc3f96c3ef805bd8Tom Gundersentypedef struct DHCPPacket DHCPPacket;
59b8f6b628145586e87b8a4f6e29c755ad7d61edTom Gundersen
20af7091de0cdf92bf299addfc3f96c3ef805bd8Tom Gundersen#define DHCP_IP_SIZE (int32_t)(sizeof(struct iphdr))
59b8f6b628145586e87b8a4f6e29c755ad7d61edTom Gundersen#define DHCP_IP_UDP_SIZE (int32_t)(sizeof(struct udphdr) + DHCP_IP_SIZE)
20af7091de0cdf92bf299addfc3f96c3ef805bd8Tom Gundersen#define DHCP_MESSAGE_SIZE (int32_t)(sizeof(DHCPMessage))
20af7091de0cdf92bf299addfc3f96c3ef805bd8Tom Gundersen#define DHCP_DEFAULT_MIN_SIZE 576 /* the minimum internet hosts must be able to receive */
59b8f6b628145586e87b8a4f6e29c755ad7d61edTom Gundersen#define DHCP_MIN_OPTIONS_SIZE DHCP_DEFAULT_MIN_SIZE - DHCP_IP_UDP_SIZE - DHCP_MESSAGE_SIZE
20af7091de0cdf92bf299addfc3f96c3ef805bd8Tom Gundersen#define DHCP_MAGIC_COOKIE (uint32_t)(0x63825363)
20af7091de0cdf92bf299addfc3f96c3ef805bd8Tom Gundersen
20af7091de0cdf92bf299addfc3f96c3ef805bd8Tom Gundersenenum {
20af7091de0cdf92bf299addfc3f96c3ef805bd8Tom Gundersen DHCP_PORT_SERVER = 67,
7c16313f11e3953f3fe4dbf544f2d36f58d14138Tom Gundersen DHCP_PORT_CLIENT = 68,
756775814cf69471f74ce853745bba69f2ba94efThomas Hindoe Paaboel Andersen};
7c16313f11e3953f3fe4dbf544f2d36f58d14138Tom Gundersen
7c16313f11e3953f3fe4dbf544f2d36f58d14138Tom Gundersenenum DHCPState {
7c16313f11e3953f3fe4dbf544f2d36f58d14138Tom Gundersen DHCP_STATE_INIT = 0,
7c16313f11e3953f3fe4dbf544f2d36f58d14138Tom Gundersen DHCP_STATE_SELECTING = 1,
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen DHCP_STATE_INIT_REBOOT = 2,
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen DHCP_STATE_REBOOTING = 3,
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen DHCP_STATE_REQUESTING = 4,
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen DHCP_STATE_BOUND = 5,
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen DHCP_STATE_RENEWING = 6,
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen DHCP_STATE_REBINDING = 7,
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen DHCP_STATE_STOPPED = 8,
a6f1e036de8f212f33ead7f5387c297afd8be26eTom Gundersen};
a6f1e036de8f212f33ead7f5387c297afd8be26eTom Gundersen
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersentypedef enum DHCPState DHCPState;
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersenenum {
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen BOOTREQUEST = 1,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen BOOTREPLY = 2,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen};
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersenenum {
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_DISCOVER = 1,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_OFFER = 2,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_REQUEST = 3,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_DECLINE = 4,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_ACK = 5,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_NAK = 6,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_RELEASE = 7,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_INFORM = 8,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_FORCERENEW = 9,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen};
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersenenum {
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_OVERLOAD_FILE = 1,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_OVERLOAD_SNAME = 2,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen};
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersenenum {
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_OPTION_PAD = 0,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_OPTION_SUBNET_MASK = 1,
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt DHCP_OPTION_TIME_OFFSET = 2,
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt DHCP_OPTION_ROUTER = 3,
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt DHCP_OPTION_DOMAIN_NAME_SERVER = 6,
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt DHCP_OPTION_HOST_NAME = 12,
d5099efc47d4e6ac60816b5381a5f607ab03f06eMichal Schmidt DHCP_OPTION_BOOT_FILE_SIZE = 13,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_OPTION_DOMAIN_NAME = 15,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_OPTION_ROOT_PATH = 17,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_OPTION_ENABLE_IP_FORWARDING = 19,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_OPTION_ENABLE_IP_FORWARDING_NL = 20,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_OPTION_POLICY_FILTER = 21,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_OPTION_INTERFACE_MDR = 22,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_OPTION_INTERFACE_TTL = 23,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_OPTION_INTERFACE_MTU_AGING_TIMEOUT = 24,
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen DHCP_OPTION_INTERFACE_MTU = 26,
3bdace9bf779ce051f00c14914b35c3a26164aa9Lennart Poettering DHCP_OPTION_BROADCAST = 28,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_OPTION_STATIC_ROUTE = 33,
3bdace9bf779ce051f00c14914b35c3a26164aa9Lennart Poettering DHCP_OPTION_NTP_SERVER = 42,
3bdace9bf779ce051f00c14914b35c3a26164aa9Lennart Poettering DHCP_OPTION_REQUESTED_IP_ADDRESS = 50,
b44cd8821087f2afebf85fec5b588f5720a9415cTom Gundersen DHCP_OPTION_IP_ADDRESS_LEASE_TIME = 51,
3bdace9bf779ce051f00c14914b35c3a26164aa9Lennart Poettering DHCP_OPTION_OVERLOAD = 52,
3bdace9bf779ce051f00c14914b35c3a26164aa9Lennart Poettering DHCP_OPTION_MESSAGE_TYPE = 53,
ff734080aa02cd70b13bc0fdeec4a5886166163aTom Gundersen DHCP_OPTION_SERVER_IDENTIFIER = 54,
3bdace9bf779ce051f00c14914b35c3a26164aa9Lennart Poettering DHCP_OPTION_PARAMETER_REQUEST_LIST = 55,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_OPTION_MAXIMUM_MESSAGE_SIZE = 57,
3bdace9bf779ce051f00c14914b35c3a26164aa9Lennart Poettering DHCP_OPTION_RENEWAL_T1_TIME = 58,
87322b3aee0dc649ff1ae7a403dcc9d7305baba2Tom Gundersen DHCP_OPTION_REBINDING_T2_TIME = 59,
3bdace9bf779ce051f00c14914b35c3a26164aa9Lennart Poettering DHCP_OPTION_VENDOR_CLASS_IDENTIFIER = 60,
3bdace9bf779ce051f00c14914b35c3a26164aa9Lennart Poettering DHCP_OPTION_CLIENT_IDENTIFIER = 61,
8eb9058dc1f99a5eb9b8726a978fcc0720837a10Lennart Poettering DHCP_OPTION_CLASSLESS_STATIC_ROUTE = 121,
8eb9058dc1f99a5eb9b8726a978fcc0720837a10Lennart Poettering DHCP_OPTION_END = 255,
3bdace9bf779ce051f00c14914b35c3a26164aa9Lennart Poettering};
3bdace9bf779ce051f00c14914b35c3a26164aa9Lennart Poettering