blob: 509d5d4cc15fbd95b927170e1011b58170bb228c [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
30typedef enum {
31#define _(a) a,
32 foreach_dhcp_client_state
33#undef _
34} dhcp_client_state_t;
35
36typedef struct {
37 dhcp_client_state_t state;
38
39 /* the interface in question */
40 u32 sw_if_index;
41
42 /* State machine retry counter */
43 u32 retry_count;
44
45 /* Send next pkt at this time */
46 f64 next_transmit;
47 f64 lease_expires;
48
49 /* DHCP transaction ID, a random number */
50 u32 transaction_id;
51
52 /* leased address, other learned info DHCP */
53 ip4_address_t leased_address; /* from your_ip_address field */
54 ip4_address_t dhcp_server;
55 u32 subnet_mask_width; /* option 1 */
56 ip4_address_t router_address; /* option 3 */
57 u32 lease_renewal_interval; /* option 51 */
58 u32 lease_lifetime; /* option 59 */
59
60 /* Requested data (option 55) */
61 u8 * option_55_data;
62
63 u8 * l2_rewrite;
64
65 /* hostname and software client identifiers */
66 u8 * hostname;
67 u8 * client_identifier; /* software version, e.g. vpe 1.0*/
68
69 /* Information used for event callback */
70 u32 client_index;
71 u32 pid;
72 void * event_callback;
73} dhcp_client_t;
74
75typedef struct {
76 /* DHCP client pool */
77 dhcp_client_t * clients;
78 uword * client_by_sw_if_index;
79 u32 seed;
80
81 /* convenience */
82 vlib_main_t * vlib_main;
83 vnet_main_t * vnet_main;
84} dhcp_client_main_t;
85
86typedef struct {
87 int is_add;
88 u32 sw_if_index;
89
90 /* vectors, consumed by dhcp client code */
91 u8 * hostname;
92 u8 * client_identifier;
93
94 /* Bytes containing requested option numbers */
95 u8 * option_55_data;
96
97 /* Information used for event callback */
98 u32 client_index;
99 u32 pid;
100 void * event_callback;
101} dhcp_client_add_del_args_t;
102
103dhcp_client_main_t dhcp_client_main;
104
105#define EVENT_DHCP_CLIENT_WAKEUP 1
106
107int dhcp_client_for_us (u32 bi0,
108 vlib_buffer_t * b0,
109 ip4_header_t * ip0,
110 udp_header_t * u0,
111 dhcp_header_t * dh0);
112
113int dhcp_client_config (vlib_main_t * vm,
114 u32 sw_if_index,
115 u8 * hostname,
Neale Ranns51822bf2017-07-18 09:26:53 -0700116 u8 * client_id,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117 u32 is_add,
118 u32 client_index,
119 void *event_callback,
120 u32 pid);
121
122#endif /* included_dhcp_client_h */