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];
109 extern dhcp_proxy_main_t dhcp_proxy_main;
112 * @brief Send the details of a proxy session to the API client during a dump
114 void dhcp_send_details (fib_protocol_t proto,
117 const ip46_address_t *server,
118 const ip46_address_t *src,
125 * @brief Show (on CLI) a VSS config during a show walk
127 int dhcp_vss_show_walk (dhcp_vss_t *vss,
132 * @brief Configure/set a new VSS info
134 int dhcp_proxy_set_vss(fib_protocol_t proto,
141 * @brief Dump the proxy configs to the API
143 void dhcp_proxy_dump(fib_protocol_t proto,
148 * @brief Add a new DHCP proxy server configuration.
149 * @return 1 is the config is new,
150 * 0 otherwise (implying a modify of an existing)
152 int dhcp_proxy_server_add(fib_protocol_t proto,
153 ip46_address_t *addr,
154 ip46_address_t *src_address,
156 u32 server_table_id);
159 * @brief Delete a DHCP proxy config
160 * @return 0 is deleted, otherwise an error code
162 int dhcp_proxy_server_del(fib_protocol_t proto,
166 * @brief Callback function invoked for each DHCP proxy entry
167 * return 0 to break the walk, non-zero otherwise.
169 typedef int (*dhcp_proxy_walk_fn_t)(dhcp_server_t *server,
173 * @brief Walk/Visit each DHCP proxy server
175 void dhcp_proxy_walk(fib_protocol_t proto,
176 dhcp_proxy_walk_fn_t fn,
180 * @brief Callback function invoked for each DHCP VSS entry
181 * return 0 to break the walk, non-zero otherwise.
183 typedef int (*dhcp_vss_walk_fn_t)(dhcp_vss_t *server,
188 * @brief Walk/Visit each DHCP proxy VSS
190 void dhcp_vss_walk(fib_protocol_t proto,
191 dhcp_vss_walk_fn_t fn,
195 * @brief Get the VSS data for the FIB index
197 static inline dhcp_vss_t *
198 dhcp_get_vss_info (dhcp_proxy_main_t *dm,
200 fib_protocol_t proto)
202 dhcp_vss_t *v = NULL;
204 if (vec_len(dm->vss_index_by_rx_fib_index[proto]) > rx_fib_index &&
205 dm->vss_index_by_rx_fib_index[proto][rx_fib_index] != ~0)
207 v = pool_elt_at_index (
209 dm->vss_index_by_rx_fib_index[proto][rx_fib_index]);
216 * @brief Get the DHCP proxy server data for the FIB index
218 static inline dhcp_server_t *
219 dhcp_get_server (dhcp_proxy_main_t *dm,
221 fib_protocol_t proto)
223 dhcp_server_t *s = NULL;
225 if (vec_len(dm->dhcp_server_index_by_rx_fib_index[proto]) > rx_fib_index &&
226 dm->dhcp_server_index_by_rx_fib_index[proto][rx_fib_index] != ~0)
228 s = pool_elt_at_index (
229 dm->dhcp_servers[proto],
230 dm->dhcp_server_index_by_rx_fib_index[proto][rx_fib_index]);
236 int dhcp6_proxy_set_server (ip46_address_t *addr,
237 ip46_address_t *src_addr,
241 int dhcp4_proxy_set_server (ip46_address_t *addr,
242 ip46_address_t *src_addr,
247 #endif /* included_dhcp_proxy_h */