blob: d9c7e25d0b216fb3bbc3201557c477a19a89c46a [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15/*
16 * client.h: dhcp client
17 */
18
19#ifndef included_dhcp_client_h
20#define included_dhcp_client_h
21
Neale Ranns20a175a2017-02-14 07:28:41 -080022#include <vnet/ip/ip.h>
Neale Ranns2dd68522017-02-16 03:38:59 -080023#include <vnet/dhcp/dhcp4_packet.h>
Neale Ranns20a175a2017-02-14 07:28:41 -080024
Ed Warnickecb9cada2015-12-08 15:45:58 -070025#define foreach_dhcp_client_state \
26_(DHCP_DISCOVER) \
27_(DHCP_REQUEST) \
28_(DHCP_BOUND)
29
khemendra kumar34719e32017-12-08 18:06:52 +053030typedef enum
31{
Ed Warnickecb9cada2015-12-08 15:45:58 -070032#define _(a) a,
33 foreach_dhcp_client_state
34#undef _
35} dhcp_client_state_t;
36
khemendra kumar34719e32017-12-08 18:06:52 +053037typedef struct
38{
Ed Warnickecb9cada2015-12-08 15:45:58 -070039 dhcp_client_state_t state;
40
41 /* the interface in question */
42 u32 sw_if_index;
43
44 /* State machine retry counter */
45 u32 retry_count;
46
47 /* Send next pkt at this time */
48 f64 next_transmit;
49 f64 lease_expires;
50
51 /* DHCP transaction ID, a random number */
52 u32 transaction_id;
53
54 /* leased address, other learned info DHCP */
khemendra kumar34719e32017-12-08 18:06:52 +053055 ip4_address_t leased_address; /* from your_ip_address field */
Ed Warnickecb9cada2015-12-08 15:45:58 -070056 ip4_address_t dhcp_server;
khemendra kumar34719e32017-12-08 18:06:52 +053057 u32 subnet_mask_width; /* option 1 */
58 ip4_address_t router_address; /* option 3 */
59 u32 lease_renewal_interval; /* option 51 */
60 u32 lease_lifetime; /* option 59 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070061
62 /* Requested data (option 55) */
khemendra kumar34719e32017-12-08 18:06:52 +053063 u8 *option_55_data;
Ed Warnickecb9cada2015-12-08 15:45:58 -070064
khemendra kumar34719e32017-12-08 18:06:52 +053065 u8 *l2_rewrite;
Ed Warnickecb9cada2015-12-08 15:45:58 -070066
67 /* hostname and software client identifiers */
khemendra kumar34719e32017-12-08 18:06:52 +053068 u8 *hostname;
69 u8 *client_identifier; /* software version, e.g. vpe 1.0 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070070
71 /* Information used for event callback */
72 u32 client_index;
73 u32 pid;
khemendra kumar34719e32017-12-08 18:06:52 +053074 void *event_callback;
Ed Warnickecb9cada2015-12-08 15:45:58 -070075} dhcp_client_t;
76
khemendra kumar34719e32017-12-08 18:06:52 +053077typedef struct
78{
Ed Warnickecb9cada2015-12-08 15:45:58 -070079 /* DHCP client pool */
khemendra kumar34719e32017-12-08 18:06:52 +053080 dhcp_client_t *clients;
81 uword *client_by_sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -070082 u32 seed;
83
84 /* convenience */
khemendra kumar34719e32017-12-08 18:06:52 +053085 vlib_main_t *vlib_main;
86 vnet_main_t *vnet_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070087} dhcp_client_main_t;
88
khemendra kumar34719e32017-12-08 18:06:52 +053089typedef struct
90{
Ed Warnickecb9cada2015-12-08 15:45:58 -070091 int is_add;
92 u32 sw_if_index;
93
94 /* vectors, consumed by dhcp client code */
khemendra kumar34719e32017-12-08 18:06:52 +053095 u8 *hostname;
96 u8 *client_identifier;
Ed Warnickecb9cada2015-12-08 15:45:58 -070097
98 /* Bytes containing requested option numbers */
khemendra kumar34719e32017-12-08 18:06:52 +053099 u8 *option_55_data;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700100
101 /* Information used for event callback */
102 u32 client_index;
103 u32 pid;
khemendra kumar34719e32017-12-08 18:06:52 +0530104 void *event_callback;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700105} dhcp_client_add_del_args_t;
106
Dave Wallace71612d62017-10-24 01:32:41 -0400107extern dhcp_client_main_t dhcp_client_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700108
109#define EVENT_DHCP_CLIENT_WAKEUP 1
110
khemendra kumar34719e32017-12-08 18:06:52 +0530111int dhcp_client_for_us (u32 bi0,
112 vlib_buffer_t * b0,
113 ip4_header_t * ip0,
114 udp_header_t * u0, dhcp_header_t * dh0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700115
116int dhcp_client_config (vlib_main_t * vm,
khemendra kumar34719e32017-12-08 18:06:52 +0530117 u32 sw_if_index,
118 u8 * hostname,
119 u8 * client_id,
120 u32 is_add,
121 u32 client_index, void *event_callback, u32 pid);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700122
123#endif /* included_dhcp_client_h */
khemendra kumar34719e32017-12-08 18:06:52 +0530124
125/*
126 * fd.io coding-style-patch-verification: ON
127 *
128 * Local Variables:
129 * eval: (c-set-style "gnu")
130 * End:
131 */