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 VSS type as defined in RFC 6607:
52 * 0 for NVT ASCII VPN Identifier
53 * 1 for RFC 2685 VPN-ID of 7 octects - 3 bytes OUI & 4 bytes VPN index
54 * 255 for global default VPN
57 #define VSS_TYPE_ASCII 0
58 #define VSS_TYPE_VPN_ID 1
59 #define VSS_TYPE_INVALID 123
60 #define VSS_TYPE_DEFAULT 255
62 * @brief Type 1 VPN-ID
66 * @brief Type 0 ASCII VPN Identifier
72 * @brief A representation of a single DHCP Server within a given VRF config
74 typedef struct dhcp_server_t_
77 * @brief The address of the DHCP server to which to relay the client's
80 ip46_address_t dhcp_server;
83 * @brief The FIB index (not the external Table-ID) in which the server
90 * @brief A DHCP proxy represenation fpr per-client VRF config
92 typedef struct dhcp_proxy_t_ {
94 * @brief The set of DHCP servers to which messages are relayed.
95 * If multiple servers are configured then discover/solict messages
96 * are relayed to each. A cookie is maintained for the relay, and only
97 * one message is replayed to the client, based on the presence of the
99 * The expectation is there are only 1 or 2 servers, hence no fancy DB.
101 dhcp_server_t *dhcp_servers;
104 * @brief Hash table of pending requets key'd on the clients MAC address
109 * @brief A lock for the pending request DB.
114 * @brief The source address to use in relayed messaes
116 ip46_address_t dhcp_src_address;
119 * @brief The FIB index (not the external Table-ID) in which the client
125 #define DHCP_N_PROTOS (FIB_PROTOCOL_IP6 + 1)
128 * @brief Collection of global DHCP proxy data
131 /* Pool of DHCP servers */
132 dhcp_proxy_t *dhcp_servers[DHCP_N_PROTOS];
134 /* Pool of selected DHCP server. Zero is the default server */
135 u32 * dhcp_server_index_by_rx_fib_index[DHCP_N_PROTOS];
137 /* to drop pkts in server-to-client direction */
138 u32 error_drop_node_index;
140 dhcp_vss_t *vss[DHCP_N_PROTOS];
142 /* hash lookup specific vrf_id -> option 82 vss suboption */
143 u32 *vss_index_by_rx_fib_index[DHCP_N_PROTOS];
146 extern dhcp_proxy_main_t dhcp_proxy_main;
149 * @brief Send the details of a proxy session to the API client during a dump
151 void dhcp_send_details (fib_protocol_t proto,
154 dhcp_proxy_t *proxy);
157 * @brief Show (on CLI) a VSS config during a show walk
159 int dhcp_vss_show_walk (dhcp_vss_t *vss,
164 * @brief Configure/set a new VSS info
166 int dhcp_proxy_set_vss (fib_protocol_t proto,
175 * @brief Dump the proxy configs to the API
177 void dhcp_proxy_dump(fib_protocol_t proto,
182 * @brief Add a new DHCP proxy server configuration.
183 * @return 1 is the config is new,
184 * 0 otherwise (implying a modify of an existing)
186 int dhcp_proxy_server_add(fib_protocol_t proto,
187 ip46_address_t *addr,
188 ip46_address_t *src_address,
190 u32 server_table_id);
193 * @brief Delete a DHCP proxy config
194 * @return 1 if the proxy is deleted, 0 otherwise
196 int dhcp_proxy_server_del(fib_protocol_t proto,
198 ip46_address_t *addr,
199 u32 server_table_id);
202 dhcp_proxy_rx_table_get_table_id (fib_protocol_t proto,
206 * @brief Callback function invoked for each DHCP proxy entry
207 * return 0 to break the walk, non-zero otherwise.
209 typedef int (*dhcp_proxy_walk_fn_t)(dhcp_proxy_t *server,
213 * @brief Walk/Visit each DHCP proxy server
215 void dhcp_proxy_walk(fib_protocol_t proto,
216 dhcp_proxy_walk_fn_t fn,
220 * @brief Callback function invoked for each DHCP VSS entry
221 * return 0 to break the walk, non-zero otherwise.
223 typedef int (*dhcp_vss_walk_fn_t)(dhcp_vss_t *server,
228 * @brief Walk/Visit each DHCP proxy VSS
230 void dhcp_vss_walk(fib_protocol_t proto,
231 dhcp_vss_walk_fn_t fn,
235 * @brief Lock a proxy object to prevent simultaneous access of its
238 void dhcp_proxy_lock (dhcp_proxy_t *server);
241 * @brief Lock a proxy object to prevent simultaneous access of its
244 void dhcp_proxy_unlock (dhcp_proxy_t *server);
247 * @brief Get the VSS data for the FIB index
249 static inline dhcp_vss_t *
250 dhcp_get_vss_info (dhcp_proxy_main_t *dm,
252 fib_protocol_t proto)
254 dhcp_vss_t *v = NULL;
256 if (vec_len(dm->vss_index_by_rx_fib_index[proto]) > rx_fib_index &&
257 dm->vss_index_by_rx_fib_index[proto][rx_fib_index] != ~0)
259 v = pool_elt_at_index (
261 dm->vss_index_by_rx_fib_index[proto][rx_fib_index]);
268 * @brief Get the DHCP proxy server data for the FIB index
270 static inline dhcp_proxy_t *
271 dhcp_get_proxy (dhcp_proxy_main_t *dm,
273 fib_protocol_t proto)
275 dhcp_proxy_t *s = NULL;
277 if (vec_len(dm->dhcp_server_index_by_rx_fib_index[proto]) > rx_fib_index &&
278 dm->dhcp_server_index_by_rx_fib_index[proto][rx_fib_index] != ~0)
280 s = pool_elt_at_index (
281 dm->dhcp_servers[proto],
282 dm->dhcp_server_index_by_rx_fib_index[proto][rx_fib_index]);
288 int dhcp6_proxy_set_server (ip46_address_t *addr,
289 ip46_address_t *src_addr,
293 int dhcp4_proxy_set_server (ip46_address_t *addr,
294 ip46_address_t *src_addr,
299 #endif /* included_dhcp_proxy_h */