blob: 72cbf66733f0aee59dab8a5b861f19adaf780bcd [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
Neale Rannsdaff1782018-05-16 04:12:18 -070037struct dhcp_client_t_;
38
39/**
40 * Callback function for DHCP complete events
41 */
42typedef void (*dhcp_event_cb_t) (u32 client_index,
43 const struct dhcp_client_t_ * client);
44
45typedef struct dhcp_client_t_
khemendra kumar34719e32017-12-08 18:06:52 +053046{
Ed Warnickecb9cada2015-12-08 15:45:58 -070047 dhcp_client_state_t state;
48
49 /* the interface in question */
50 u32 sw_if_index;
51
52 /* State machine retry counter */
53 u32 retry_count;
54
55 /* Send next pkt at this time */
56 f64 next_transmit;
57 f64 lease_expires;
58
59 /* DHCP transaction ID, a random number */
60 u32 transaction_id;
61
62 /* leased address, other learned info DHCP */
khemendra kumar34719e32017-12-08 18:06:52 +053063 ip4_address_t leased_address; /* from your_ip_address field */
Ed Warnickecb9cada2015-12-08 15:45:58 -070064 ip4_address_t dhcp_server;
khemendra kumar34719e32017-12-08 18:06:52 +053065 u32 subnet_mask_width; /* option 1 */
66 ip4_address_t router_address; /* option 3 */
67 u32 lease_renewal_interval; /* option 51 */
68 u32 lease_lifetime; /* option 59 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070069
70 /* Requested data (option 55) */
khemendra kumar34719e32017-12-08 18:06:52 +053071 u8 *option_55_data;
Ed Warnickecb9cada2015-12-08 15:45:58 -070072
khemendra kumar34719e32017-12-08 18:06:52 +053073 u8 *l2_rewrite;
Ed Warnickecb9cada2015-12-08 15:45:58 -070074
75 /* hostname and software client identifiers */
khemendra kumar34719e32017-12-08 18:06:52 +053076 u8 *hostname;
77 u8 *client_identifier; /* software version, e.g. vpe 1.0 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070078
79 /* Information used for event callback */
80 u32 client_index;
81 u32 pid;
Neale Ranns54c6dc42018-01-17 10:29:10 -080082
83 /* Set the broadcast Flag in the Discover/Request messages */
84 u8 set_broadcast_flag;
Dave Barach4585eb82018-03-23 09:52:52 -040085 /* Interface MAC address, so we can do an rx-packet-for-us check */
86 u8 client_hardware_address[6];
Dave Barach525c9d02018-05-26 10:48:55 -040087 u8 client_detect_feature_enabled;
Neale Ranns54c6dc42018-01-17 10:29:10 -080088
Neale Rannsdaff1782018-05-16 04:12:18 -070089 dhcp_event_cb_t event_callback;
Ed Warnickecb9cada2015-12-08 15:45:58 -070090} dhcp_client_t;
91
khemendra kumar34719e32017-12-08 18:06:52 +053092typedef struct
93{
Ed Warnickecb9cada2015-12-08 15:45:58 -070094 /* DHCP client pool */
khemendra kumar34719e32017-12-08 18:06:52 +053095 dhcp_client_t *clients;
96 uword *client_by_sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -070097 u32 seed;
98
99 /* convenience */
khemendra kumar34719e32017-12-08 18:06:52 +0530100 vlib_main_t *vlib_main;
101 vnet_main_t *vnet_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700102} dhcp_client_main_t;
103
khemendra kumar34719e32017-12-08 18:06:52 +0530104typedef struct
105{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700106 int is_add;
107 u32 sw_if_index;
Neale Ranns54c6dc42018-01-17 10:29:10 -0800108 u8 set_broadcast_flag;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700109
110 /* vectors, consumed by dhcp client code */
khemendra kumar34719e32017-12-08 18:06:52 +0530111 u8 *hostname;
112 u8 *client_identifier;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700113
114 /* Bytes containing requested option numbers */
khemendra kumar34719e32017-12-08 18:06:52 +0530115 u8 *option_55_data;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700116
117 /* Information used for event callback */
118 u32 client_index;
119 u32 pid;
Neale Rannsdaff1782018-05-16 04:12:18 -0700120 dhcp_event_cb_t event_callback;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700121} dhcp_client_add_del_args_t;
122
Dave Wallace71612d62017-10-24 01:32:41 -0400123extern dhcp_client_main_t dhcp_client_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700124
125#define EVENT_DHCP_CLIENT_WAKEUP 1
126
khemendra kumar34719e32017-12-08 18:06:52 +0530127int dhcp_client_for_us (u32 bi0,
128 vlib_buffer_t * b0,
129 ip4_header_t * ip0,
130 udp_header_t * u0, dhcp_header_t * dh0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700131
Neale Rannsdaff1782018-05-16 04:12:18 -0700132/**
133 * Add/Delete DHCP clients
134 */
135extern int dhcp_client_config (u32 is_add,
136 u32 client_index,
137 vlib_main_t * vm,
138 u32 sw_if_index,
139 u8 * hostname,
140 u8 * client_id,
141 dhcp_event_cb_t event_callback,
142 u8 set_broadcast_flag, u32 pid);
143
144/**
145 * callback function for clients walking the DHCP client configurations
146 *
147 * @param client The client being visitsed
148 * @param data The data passed during the call to 'walk'
149 * @return !0 to continue walking 0 to stop.
150 */
151typedef int (*dhcp_client_walk_cb_t) (const dhcp_client_t * client,
152 void *data);
153
154/**
155 * Walk (visit each) DHCP client configuration
156 *
157 * @param cb The callback function invoked as each client is visited
158 * @param ctx Context data passed back to the client in the invocation of
159 * the callback.
160 */
161extern void dhcp_client_walk (dhcp_client_walk_cb_t cb, void *ctx);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700162
163#endif /* included_dhcp_client_h */
khemendra kumar34719e32017-12-08 18:06:52 +0530164
165/*
166 * fd.io coding-style-patch-verification: ON
167 *
168 * Local Variables:
169 * eval: (c-set-style "gnu")
170 * End:
171 */