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