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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 * client.h: dhcp client
19 #ifndef included_dhcp_client_h
20 #define included_dhcp_client_h
22 #include <vnet/ip/ip.h>
23 #include <dhcp/dhcp4_packet.h>
25 #define foreach_dhcp_client_state \
33 foreach_dhcp_client_state
35 } dhcp_client_state_t;
37 struct dhcp_client_t_;
40 * Callback function for DHCP complete events
42 typedef void (*dhcp_event_cb_t) (u32 client_index,
43 const struct dhcp_client_t_ * client);
46 * The set of addresses/mask that contribute forwarding info
49 typedef struct dhcp_client_fwd_addresses_t_
51 /** the address assigned to this client and it's mask */
52 ip4_address_t leased_address;
53 u32 subnet_mask_width;
55 /** the address of the DHCP server handing out the address.
56 this is used to send any unicast messages */
57 ip4_address_t dhcp_server;
59 /** The address of this client's default gateway - may not be present */
60 ip4_address_t router_address;
61 } dhcp_client_fwd_addresses_t;
63 typedef struct dhcp_client_t_
65 dhcp_client_state_t state;
67 /* the interface in question */
70 /* State machine retry counter */
73 /* Send next pkt at this time */
77 /* DHCP transaction ID, a random number */
81 * leased address, other learned info DHCP
82 * the learned set is updated by new messages recieved in the DP
83 * the installed set is what's actually been added
85 dhcp_client_fwd_addresses_t learned;
86 dhcp_client_fwd_addresses_t installed;
87 /* have local Addresses and default route been installed */
88 u8 addresses_installed;
90 ip4_address_t *domain_server_address; /* option 6 */
91 u32 lease_renewal_interval; /* option 51 */
92 u32 lease_lifetime; /* option 59 */
94 /* Requested data (option 55) */
97 /* hostname and software client identifiers */
99 u8 *client_identifier; /* software version, e.g. vpe 1.0 */
101 /* Information used for event callback */
105 /* Set the broadcast Flag in the Discover/Request messages */
106 u8 set_broadcast_flag;
107 /* Interface MAC address, so we can do an rx-packet-for-us check */
108 u8 client_hardware_address[6];
109 u8 client_detect_feature_enabled;
111 /* the unicast adjacency for the DHCP server */
112 adj_index_t ai_ucast;
113 /* the broadcast adjacency on the link */
114 adj_index_t ai_bcast;
115 /* IP DSCP to set in sent packets */
118 dhcp_event_cb_t event_callback;
123 /* DHCP client pool */
124 dhcp_client_t *clients;
125 uword *client_by_sw_if_index;
129 vlib_main_t *vlib_main;
130 vnet_main_t *vnet_main;
131 } dhcp_client_main_t;
137 u8 set_broadcast_flag;
139 /* vectors, consumed by dhcp client code */
141 u8 *client_identifier;
143 /* Bytes containing requested option numbers */
146 /* Information used for event callback */
150 dhcp_event_cb_t event_callback;
151 } dhcp_client_add_del_args_t;
153 extern dhcp_client_main_t dhcp_client_main;
155 #define EVENT_DHCP_CLIENT_WAKEUP 1
157 int dhcp_client_for_us (u32 bi0,
160 udp_header_t * u0, dhcp_header_t * dh0);
163 * Add/Delete DHCP clients
165 extern int dhcp_client_config (u32 is_add,
171 dhcp_event_cb_t event_callback,
172 u8 set_broadcast_flag,
173 ip_dscp_t dscp, u32 pid);
176 * callback function for clients walking the DHCP client configurations
178 * @param client The client being visitsed
179 * @param data The data passed during the call to 'walk'
180 * @return !0 to continue walking 0 to stop.
182 typedef int (*dhcp_client_walk_cb_t) (const dhcp_client_t * client,
186 * Walk (visit each) DHCP client configuration
188 * @param cb The callback function invoked as each client is visited
189 * @param ctx Context data passed back to the client in the invocation of
192 extern void dhcp_client_walk (dhcp_client_walk_cb_t cb, void *ctx);
194 #endif /* included_dhcp_client_h */
197 * fd.io coding-style-patch-verification: ON
200 * eval: (c-set-style "gnu")