chiark / gitweb /
dhcp: Add DHCP discover sending
[elogind.git] / src / libsystemd-dhcp / dhcp-protocol.h
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
31 struct 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;
39         uint32_t ciaddr;
40         uint32_t yiaddr;
41         uint32_t siaddr;
42         uint32_t giaddr;
43         uint8_t chaddr[16];
44         uint8_t sname[64];
45         uint8_t file[128];
46 } _packed_;
47
48 typedef struct DHCPMessage DHCPMessage;
49
50 struct DHCPPacket {
51         struct iphdr ip;
52         struct udphdr udp;
53         DHCPMessage dhcp;
54 } _packed_;
55
56 typedef struct DHCPPacket DHCPPacket;
57
58 enum {
59         DHCP_PORT_SERVER                        = 67,
60         DHCP_PORT_CLIENT                        = 68,
61 };
62
63 enum DHCPState {
64         DHCP_STATE_INIT                         = 0,
65         DHCP_STATE_SELECTING                    = 1,
66         DHCP_STATE_INIT_REBOOT                  = 2,
67         DHCP_STATE_REBOOTING                    = 3,
68         DHCP_STATE_REQUESTING                   = 4,
69         DHCP_STATE_BOUND                        = 5,
70         DHCP_STATE_RENEWING                     = 6,
71         DHCP_STATE_REBINDING                    = 7,
72 };
73
74 typedef enum DHCPState DHCPState;
75
76 enum {
77         BOOTREQUEST                             = 1,
78         BOOTREPLY                               = 2,
79 };
80
81 enum {
82         DHCP_DISCOVER                           = 1,
83         DHCP_OFFER                              = 2,
84         DHCP_REQUEST                            = 3,
85         DHCP_DECLINE                            = 4,
86         DHCP_ACK                                = 5,
87         DHCP_NAK                                = 6,
88         DHCP_RELEASE                            = 7,
89 };
90
91 enum {
92         DHCP_OVERLOAD_FILE                      = 1,
93         DHCP_OVERLOAD_SNAME                     = 2,
94 };
95
96 enum {
97         DHCP_OPTION_PAD                         = 0,
98         DHCP_OPTION_SUBNET_MASK                 = 1,
99         DHCP_OPTION_ROUTER                      = 3,
100         DHCP_OPTION_DOMAIN_NAME_SERVER          = 6,
101         DHCP_OPTION_HOST_NAME                   = 12,
102         DHCP_OPTION_DOMAIN_NAME                 = 15,
103         DHCP_OPTION_NTP_SERVER                  = 42,
104         DHCP_OPTION_REQUESTED_IP_ADDRESS        = 50,
105         DHCP_OPTION_OVERLOAD                    = 52,
106         DHCP_OPTION_MESSAGE_TYPE                = 53,
107         DHCP_OPTION_PARAMETER_REQUEST_LIST      = 55,
108         DHCP_OPTION_CLIENT_IDENTIFIER           = 61,
109         DHCP_OPTION_END                         = 255,
110 };