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 DHCP proxy server represenation
63 typedef struct dhcp_server_t_ {
65 * @brief The address of the DHCP server to which to relay the client's
68 ip46_address_t dhcp_server;
71 * @brief The source address to use in relayed messaes
73 ip46_address_t dhcp_src_address;
76 * @brief The FIB index (not the external Table-ID) in which the server
82 * @brief The FIB index (not the external Table-ID) in which the client
88 #define DHCP_N_PROTOS (FIB_PROTOCOL_IP6 + 1)
91 * @brief Collection of global DHCP proxy data
94 /* Pool of DHCP servers */
95 dhcp_server_t *dhcp_servers[DHCP_N_PROTOS];
97 /* Pool of selected DHCP server. Zero is the default server */
98 u32 * dhcp_server_index_by_rx_fib_index[DHCP_N_PROTOS];
100 /* to drop pkts in server-to-client direction */
101 u32 error_drop_node_index;
103 dhcp_vss_t *vss[DHCP_N_PROTOS];
105 /* hash lookup specific vrf_id -> option 82 vss suboption */
106 u32 *vss_index_by_rx_fib_index[DHCP_N_PROTOS];
110 extern dhcp_proxy_main_t dhcp_proxy_main;
113 * @brief Send the details of a proxy session to the API client during a dump
115 void dhcp_send_details (fib_protocol_t proto,
118 const ip46_address_t *server,
119 const ip46_address_t *src,
126 * @brief Show (on CLI) a VSS config during a show walk
128 int dhcp_vss_show_walk (dhcp_vss_t *vss,
133 * @brief Configure/set a new VSS info
135 int dhcp_proxy_set_vss(fib_protocol_t proto,
142 * @brief Dump the proxy configs to the API
144 void dhcp_proxy_dump(fib_protocol_t proto,
149 * @brief Add a new DHCP proxy server configuration.
150 * @return 1 is the config is new,
151 * 0 otherwise (implying a modify of an existing)
153 int dhcp_proxy_server_add(fib_protocol_t proto,
154 ip46_address_t *addr,
155 ip46_address_t *src_address,
157 u32 server_table_id);
160 * @brief Delete a DHCP proxy config
161 * @return 0 is deleted, otherwise an error code
163 int dhcp_proxy_server_del(fib_protocol_t proto,
167 * @brief Callback function invoked for each DHCP proxy entry
168 * return 0 to break the walk, non-zero otherwise.
170 typedef int (*dhcp_proxy_walk_fn_t)(dhcp_server_t *server,
174 * @brief Walk/Visit each DHCP proxy server
176 void dhcp_proxy_walk(fib_protocol_t proto,
177 dhcp_proxy_walk_fn_t fn,
181 * @brief Callback function invoked for each DHCP VSS entry
182 * return 0 to break the walk, non-zero otherwise.
184 typedef int (*dhcp_vss_walk_fn_t)(dhcp_vss_t *server,
189 * @brief Walk/Visit each DHCP proxy VSS
191 void dhcp_vss_walk(fib_protocol_t proto,
192 dhcp_vss_walk_fn_t fn,
196 * @brief Get the VSS data for the FIB index
198 static inline dhcp_vss_t *
199 dhcp_get_vss_info (dhcp_proxy_main_t *dm,
201 fib_protocol_t proto)
203 dhcp_vss_t *v = NULL;
205 if (vec_len(dm->vss_index_by_rx_fib_index[proto]) > rx_fib_index &&
206 dm->vss_index_by_rx_fib_index[proto][rx_fib_index] != ~0)
208 v = pool_elt_at_index (
210 dm->vss_index_by_rx_fib_index[proto][rx_fib_index]);
217 * @brief Get the DHCP proxy server data for the FIB index
219 static inline dhcp_server_t *
220 dhcp_get_server (dhcp_proxy_main_t *dm,
222 fib_protocol_t proto)
224 dhcp_server_t *s = NULL;
226 if (vec_len(dm->dhcp_server_index_by_rx_fib_index[proto]) > rx_fib_index &&
227 dm->dhcp_server_index_by_rx_fib_index[proto][rx_fib_index] != ~0)
229 s = pool_elt_at_index (
230 dm->dhcp_servers[proto],
231 dm->dhcp_server_index_by_rx_fib_index[proto][rx_fib_index]);
237 int dhcp6_proxy_set_server (ip46_address_t *addr,
238 ip46_address_t *src_addr,
242 int dhcp4_proxy_set_server (ip46_address_t *addr,
243 ip46_address_t *src_addr,
248 #endif /* included_dhcp_proxy_h */