2 * dhcp_proxy.h: DHCP v4 & v6 proxy common functions/types
4 * Copyright (c) 2013 Cisco and/or its affiliates.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #ifndef included_dhcp_proxy_h
19 #define included_dhcp_proxy_h
21 #include <vnet/vnet.h>
22 #include <vnet/dhcp/dhcp4_packet.h>
23 #include <vnet/ethernet/ethernet.h>
24 #include <vnet/ip/ip.h>
25 #include <vnet/ip/ip4.h>
26 #include <vnet/ip/ip4_packet.h>
27 #include <vnet/pg/pg.h>
28 #include <vnet/ip/format.h>
29 #include <vnet/udp/udp.h>
32 #define dhcp_proxy_error(n,s) DHCP_PROXY_ERROR_##n,
33 #include <vnet/dhcp/dhcp4_proxy_error.def>
34 #undef dhcp_proxy_error
39 #define dhcpv6_proxy_error(n,s) DHCPV6_PROXY_ERROR_##n,
40 #include <vnet/dhcp/dhcp6_proxy_error.def>
41 #undef dhcpv6_proxy_error
43 } dhcpv6_proxy_error_t;
47 * @brief The Virtual Sub-net Selection information for a given RX FIB
49 typedef struct dhcp_vss_t_ {
51 * @brief ?? RFC doesn't say
61 * @brief A representation of a single DHCP Server within a given VRF config
63 typedef struct dhcp_server_t_
66 * @brief The address of the DHCP server to which to relay the client's
69 ip46_address_t dhcp_server;
72 * @brief The FIB index (not the external Table-ID) in which the server
79 * @brief A DHCP proxy represenation fpr per-client VRF config
81 typedef struct dhcp_proxy_t_ {
83 * @brief The set of DHCP servers to which messages are relayed.
84 * If multiple servers are configured then discover/solict messages
85 * are relayed to each. A cookie is maintained for the relay, and only
86 * one message is replayed to the client, based on the presence of the
88 * The expectation is there are only 1 or 2 servers, hence no fancy DB.
90 dhcp_server_t *dhcp_servers;
93 * @brief Hash table of pending requets key'd on the clients MAC address
98 * @brief A lock for the pending request DB.
103 * @brief The source address to use in relayed messaes
105 ip46_address_t dhcp_src_address;
108 * @brief The FIB index (not the external Table-ID) in which the client
114 #define DHCP_N_PROTOS (FIB_PROTOCOL_IP6 + 1)
117 * @brief Collection of global DHCP proxy data
120 /* Pool of DHCP servers */
121 dhcp_proxy_t *dhcp_servers[DHCP_N_PROTOS];
123 /* Pool of selected DHCP server. Zero is the default server */
124 u32 * dhcp_server_index_by_rx_fib_index[DHCP_N_PROTOS];
126 /* to drop pkts in server-to-client direction */
127 u32 error_drop_node_index;
129 dhcp_vss_t *vss[DHCP_N_PROTOS];
131 /* hash lookup specific vrf_id -> option 82 vss suboption */
132 u32 *vss_index_by_rx_fib_index[DHCP_N_PROTOS];
135 extern dhcp_proxy_main_t dhcp_proxy_main;
138 * @brief Send the details of a proxy session to the API client during a dump
140 void dhcp_send_details (fib_protocol_t proto,
143 dhcp_proxy_t *proxy);
146 * @brief Show (on CLI) a VSS config during a show walk
148 int dhcp_vss_show_walk (dhcp_vss_t *vss,
153 * @brief Configure/set a new VSS info
155 int dhcp_proxy_set_vss(fib_protocol_t proto,
162 * @brief Dump the proxy configs to the API
164 void dhcp_proxy_dump(fib_protocol_t proto,
169 * @brief Add a new DHCP proxy server configuration.
170 * @return 1 is the config is new,
171 * 0 otherwise (implying a modify of an existing)
173 int dhcp_proxy_server_add(fib_protocol_t proto,
174 ip46_address_t *addr,
175 ip46_address_t *src_address,
177 u32 server_table_id);
180 * @brief Delete a DHCP proxy config
181 * @return 1 if the proxy is deleted, 0 otherwise
183 int dhcp_proxy_server_del(fib_protocol_t proto,
185 ip46_address_t *addr,
186 u32 server_table_id);
189 dhcp_proxy_rx_table_get_table_id (fib_protocol_t proto,
193 * @brief Callback function invoked for each DHCP proxy entry
194 * return 0 to break the walk, non-zero otherwise.
196 typedef int (*dhcp_proxy_walk_fn_t)(dhcp_proxy_t *server,
200 * @brief Walk/Visit each DHCP proxy server
202 void dhcp_proxy_walk(fib_protocol_t proto,
203 dhcp_proxy_walk_fn_t fn,
207 * @brief Callback function invoked for each DHCP VSS entry
208 * return 0 to break the walk, non-zero otherwise.
210 typedef int (*dhcp_vss_walk_fn_t)(dhcp_vss_t *server,
215 * @brief Walk/Visit each DHCP proxy VSS
217 void dhcp_vss_walk(fib_protocol_t proto,
218 dhcp_vss_walk_fn_t fn,
222 * @brief Lock a proxy object to prevent simultaneous access of its
225 void dhcp_proxy_lock (dhcp_proxy_t *server);
228 * @brief Lock a proxy object to prevent simultaneous access of its
231 void dhcp_proxy_unlock (dhcp_proxy_t *server);
234 * @brief Get the VSS data for the FIB index
236 static inline dhcp_vss_t *
237 dhcp_get_vss_info (dhcp_proxy_main_t *dm,
239 fib_protocol_t proto)
241 dhcp_vss_t *v = NULL;
243 if (vec_len(dm->vss_index_by_rx_fib_index[proto]) > rx_fib_index &&
244 dm->vss_index_by_rx_fib_index[proto][rx_fib_index] != ~0)
246 v = pool_elt_at_index (
248 dm->vss_index_by_rx_fib_index[proto][rx_fib_index]);
255 * @brief Get the DHCP proxy server data for the FIB index
257 static inline dhcp_proxy_t *
258 dhcp_get_proxy (dhcp_proxy_main_t *dm,
260 fib_protocol_t proto)
262 dhcp_proxy_t *s = NULL;
264 if (vec_len(dm->dhcp_server_index_by_rx_fib_index[proto]) > rx_fib_index &&
265 dm->dhcp_server_index_by_rx_fib_index[proto][rx_fib_index] != ~0)
267 s = pool_elt_at_index (
268 dm->dhcp_servers[proto],
269 dm->dhcp_server_index_by_rx_fib_index[proto][rx_fib_index]);
275 int dhcp6_proxy_set_server (ip46_address_t *addr,
276 ip46_address_t *src_addr,
280 int dhcp4_proxy_set_server (ip46_address_t *addr,
281 ip46_address_t *src_addr,
286 #endif /* included_dhcp_proxy_h */