[systemd-devel] [PATCH 01/28] dhcp: Add DHCP protocol structures and initial defines

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Wed Nov 13 15:33:14 PST 2013


On Wed, Nov 13, 2013 at 11:22:29PM +0200, Patrik Flykt wrote:
> Create a new directory to host DHCP components.
> ---
>  src/dhcp/protocol.h |   93 +++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 93 insertions(+)
>  create mode 100644 src/dhcp/protocol.h
> 
> diff --git a/src/dhcp/protocol.h b/src/dhcp/protocol.h
> new file mode 100644
> index 0000000..3fc4baf
> --- /dev/null
> +++ b/src/dhcp/protocol.h
> @@ -0,0 +1,93 @@
> +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
> +
> +#pragma once
> +
> +/***
> +  This file is part of systemd.
> +
> +  Copyright (C) 2013 Intel Corporation. All rights reserved.
> +
> +  systemd is free software; you can redistribute it and/or modify it
> +  under the terms of the GNU Lesser General Public License as published by
> +  the Free Software Foundation; either version 2.1 of the License, or
> +  (at your option) any later version.
> +
> +  systemd is distributed in the hope that it will be useful, but
> +  WITHOUT ANY WARRANTY; without even the implied warranty of
> +  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> +  Lesser General Public License for more details.
> +
> +  You should have received a copy of the GNU Lesser General Public License
> +  along with systemd; If not, see <http://www.gnu.org/licenses/>.
> +***/
> +
> +#include <netinet/udp.h>
> +#include <netinet/ip.h>
> +#include <stdint.h>
> +
> +struct DHCPMessage {
> +        uint8_t op;
> +        uint8_t htype;
> +        uint8_t hlen;
> +        uint8_t hops;
> +        uint32_t xid;
> +        uint16_t secs;
> +        uint16_t flags;
> +        uint32_t ciaddr;
> +        uint32_t yiaddr;
> +        uint32_t siaddr;
> +        uint32_t giaddr;
> +        uint8_t chaddr[16];
> +        uint8_t sname[64];
> +        uint8_t file[128];
> +} __attribute__((packed));
We have _packed_.

> +
> +typedef struct DHCPMessage DHCPMessage;
> +
> +struct DHCPPacket {
> +        struct iphdr ip;
> +        struct udphdr udp;
> +        DHCPMessage dhcp;
> +} __attribute__((packed));
> +
> +typedef struct DHCPPacket DHCPPacket;
> +
> +enum DHCPState {
> +        DHCP_STATE_INIT                         = 0,
> +        DHCP_STATE_SELECTING                    = 1,
> +        DHCP_STATE_INIT_REBOOT                  = 2,
> +        DHCP_STATE_REBOOTING                    = 3,
> +        DHCP_STATE_REQUESTING                   = 4,
> +        DHCP_STATE_BOUND                        = 5,
> +        DHCP_STATE_RENEWING                     = 6,
> +        DHCP_STATE_REBINDING                    = 7,
> +};
> +
> +typedef enum DHCPState DHCPState;
> +
> +#define BOOTREQUEST                             1
> +#define BOOTREPLY                               2
> +
> +#define DHCP_DISCOVER                           1
> +#define DHCP_OFFER                              2
> +#define DHCP_REQUEST                            3
> +#define DHCP_DECLINE                            4
> +#define DHCP_ACK                                5
> +#define DHCP_NAK                                6
> +#define DHCP_RELEASE                            7
> +
> +#define DHCP_OVERLOAD_FILE                      1
> +#define DHCP_OVERLOAD_SNAME                     2
> +
> +#define DHCP_OPTION_PAD                         0
> +#define DHCP_OPTION_SUBNET_MASK                 1
> +#define DHCP_OPTION_ROUTER                      3
> +#define DHCP_OPTION_DOMAIN_NAME_SERVER          6
> +#define DHCP_OPTION_HOST_NAME                   12
> +#define DHCP_OPTION_DOMAIN_NAME                 15
> +#define DHCP_OPTION_NTP_SERVER                  42
> +#define DHCP_OPTION_REQUESTED_IP_ADDRESS        50
> +#define DHCP_OPTION_OVERLOAD                    52
> +#define DHCP_OPTION_MESSAGE_TYPE                53
> +#define DHCP_OPTION_PARAMETER_REQUEST_LIST      55
> +#define DHCP_OPTION_END                         255

Zbyszek


More information about the systemd-devel mailing list