dhcp-protocol.h revision 22805d9207d5242681e5667ee304572e4abf9b94
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#pragma once
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen/***
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen This file is part of systemd.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Copyright (C) 2013 Intel Corporation. All rights reserved.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen systemd is free software; you can redistribute it and/or modify it
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen under the terms of the GNU Lesser General Public License as published by
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen the Free Software Foundation; either version 2.1 of the License, or
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen (at your option) any later version.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen systemd is distributed in the hope that it will be useful, but
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen Lesser General Public License for more details.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen You should have received a copy of the GNU Lesser General Public License
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen***/
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include <netinet/ip.h>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include <netinet/udp.h>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen#include <stdint.h>
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
1346b1f0388f4100bb3c2a2bb23bc881769c020cTom Gundersen#include "macro.h"
f5be560181d092c5f52a2b819aedcd48220f36abTom Gundersen#include "sparse-endian.h"
dd43110f781a9245ec00531456fee68ed763a179Tom Gundersen
5c1d3fc93d91384bbac29adf01074fa4375317eaUmut Tezduyar Lindskogstruct DHCPMessage {
4138fb2c7936758da709eaed3f6b4f3df1d04effPatrik Flykt uint8_t op;
4138fb2c7936758da709eaed3f6b4f3df1d04effPatrik Flykt uint8_t htype;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen uint8_t hlen;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen uint8_t hops;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen be32_t xid;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen be16_t secs;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen be16_t flags;
06f021a8048583d66202e3ac5cd0a12386d33ac2Tom Gundersen be32_t ciaddr;
134e56dcc53970a20a858283650bb92cd5da1d17Lennart Poettering be32_t yiaddr;
3b653205cf7bd3851befd0a9f6a3ded6e267c173Lennart Poettering be32_t siaddr;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen be32_t giaddr;
aba496a58acf9d9c61314de71353550e579f85eeUmut Tezduyar Lindskog uint8_t chaddr[16];
4faefc7ff884eae65a80e82313fd9f4bb859d6dbLennart Poettering uint8_t sname[64];
4faefc7ff884eae65a80e82313fd9f4bb859d6dbLennart Poettering uint8_t file[128];
aba496a58acf9d9c61314de71353550e579f85eeUmut Tezduyar Lindskog be32_t magic;
1a436809498faf6486815baa0338fb6b8e5def07Tom Gundersen uint8_t options[0];
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen} _packed_;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersentypedef struct DHCPMessage DHCPMessage;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenstruct DHCPPacket {
11bf3cced13c885ca215c108cb0bdb7a148520d6Lennart Poettering struct iphdr ip;
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen struct udphdr udp;
ed942a9eb22d50f667909ad6184b45015d28d054Tom Gundersen DHCPMessage dhcp;
ed942a9eb22d50f667909ad6184b45015d28d054Tom Gundersen} _packed_;
ed942a9eb22d50f667909ad6184b45015d28d054Tom Gundersen
ed942a9eb22d50f667909ad6184b45015d28d054Tom Gundersentypedef struct DHCPPacket DHCPPacket;
ed942a9eb22d50f667909ad6184b45015d28d054Tom Gundersen
ed942a9eb22d50f667909ad6184b45015d28d054Tom Gundersen#define DHCP_IP_SIZE (int32_t)(sizeof(struct iphdr))
ed942a9eb22d50f667909ad6184b45015d28d054Tom Gundersen#define DHCP_IP_UDP_SIZE (int32_t)(sizeof(struct udphdr) + DHCP_IP_SIZE)
ed942a9eb22d50f667909ad6184b45015d28d054Tom Gundersen#define DHCP_MESSAGE_SIZE (int32_t)(sizeof(DHCPMessage))
ed942a9eb22d50f667909ad6184b45015d28d054Tom Gundersen#define DHCP_DEFAULT_MIN_SIZE 576 /* the minimum internet hosts must be able to receive */
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen#define DHCP_MIN_OPTIONS_SIZE DHCP_DEFAULT_MIN_SIZE - DHCP_IP_UDP_SIZE - DHCP_MESSAGE_SIZE
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen#define DHCP_MAGIC_COOKIE (uint32_t)(0x63825363)
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersenenum {
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen DHCP_PORT_SERVER = 67,
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen DHCP_PORT_CLIENT = 68,
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen};
bd8f65387673e29f46136a4ed172097035002c23Tom Gundersen
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersenenum DHCPState {
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen DHCP_STATE_INIT = 0,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen DHCP_STATE_SELECTING = 1,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen DHCP_STATE_INIT_REBOOT = 2,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen DHCP_STATE_REBOOTING = 3,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen DHCP_STATE_REQUESTING = 4,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen DHCP_STATE_BOUND = 5,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen DHCP_STATE_RENEWING = 6,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen DHCP_STATE_REBINDING = 7,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen DHCP_STATE_STOPPED = 8,
edb85f0d8d0a84f27308a3728f3fde3c52b9dce2Susant Sahani};
edb85f0d8d0a84f27308a3728f3fde3c52b9dce2Susant Sahani
2cc412b59353576cece2d5b30c6a39c70552f0a0Tom Gundersentypedef enum DHCPState DHCPState;
2cc412b59353576cece2d5b30c6a39c70552f0a0Tom Gundersen
2cc412b59353576cece2d5b30c6a39c70552f0a0Tom Gundersenenum {
edbb03e95a3c31bf719d5c6c46eec14d0bcb9c8fTom Gundersen BOOTREQUEST = 1,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen BOOTREPLY = 2,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen};
1a436809498faf6486815baa0338fb6b8e5def07Tom Gundersen
1a436809498faf6486815baa0338fb6b8e5def07Tom Gundersenenum {
6a0a2f860f1ca4a10932da3b41dbc3c0139757ccTom Gundersen DHCP_DISCOVER = 1,
ed942a9eb22d50f667909ad6184b45015d28d054Tom Gundersen DHCP_OFFER = 2,
5be4d38e31281727b6f45ae869136bb01a1f7790Tom Gundersen DHCP_REQUEST = 3,
bcb7a07e0a785bda1eed658e984ff6b4a11cba9aTom Gundersen DHCP_DECLINE = 4,
4f882b2a5007e51032459e29d15a86df6b5ea9f4Tom Gundersen DHCP_ACK = 5,
1346b1f0388f4100bb3c2a2bb23bc881769c020cTom Gundersen DHCP_NAK = 6,
ad0734e890b25751ef8229e47210ff11ae8fa3f3Tom Gundersen DHCP_RELEASE = 7,
4cc7a82c9490a3c5ae03b1d6d168ce40ba499e23Eugene Yakubovich DHCP_INFORM = 8,
f5de5b00204f041aaec828d336c8afd9e860a5c3Tom Gundersen DHCP_FORCERENEW = 9,
eb27aeca247a4cf8816fffc4c0dbcab55ead3864Tom Gundersen};
e1ea665edac17d75fce01b72dadfa3211b60df2cEugene Yakubovich
84b5b79a8f7b423c5b7cad4170eb68d57fe5e26cAngus Gibsonenum {
5c1d3fc93d91384bbac29adf01074fa4375317eaUmut Tezduyar Lindskog DHCP_OVERLOAD_FILE = 1,
bfa695b5cc37aeb78737c57c84e9e69ea08152c0Tom Gundersen DHCP_OVERLOAD_SNAME = 2,
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen};
dd43110f781a9245ec00531456fee68ed763a179Tom Gundersen
dd43110f781a9245ec00531456fee68ed763a179Tom Gundersen#define DHCP_MAX_FQDN_LENGTH 255
e1853b00ef7cb56cafd908327dd44b3ab48b402cSusant Sahani
e1853b00ef7cb56cafd908327dd44b3ab48b402cSusant Sahanienum {
c106cc36b9b8e8998eb95299b02f1db9c1209122Tom Gundersen DHCP_FQDN_FLAG_S = (1 << 0),
c106cc36b9b8e8998eb95299b02f1db9c1209122Tom Gundersen DHCP_FQDN_FLAG_O = (1 << 1),
c106cc36b9b8e8998eb95299b02f1db9c1209122Tom Gundersen DHCP_FQDN_FLAG_E = (1 << 2),
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersen DHCP_FQDN_FLAG_N = (1 << 3),
f048a16b464295a4e0a4f4c1210f06343ad31231Tom Gundersen};
f579559b3a14c1f1ef96c372e7626c4733e6ef7dTom Gundersen