FD.io VPP  v21.01.1
Vector Packet Processing
dhcp_proxy.h
Go to the documentation of this file.
1 /*
2  * dhcp_proxy.h: DHCP v4 & v6 proxy common functions/types
3  *
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:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17 
18 #ifndef included_dhcp_proxy_h
19 #define included_dhcp_proxy_h
20 
21 #include <vnet/vnet.h>
22 #include <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/ip/format.h>
28 #include <vnet/udp/udp_local.h>
29 
30 typedef enum
31 {
32 #define dhcp_proxy_error(n,s) DHCP_PROXY_ERROR_##n,
34 #undef dhcp_proxy_error
37 
38 typedef enum
39 {
40 #define dhcpv6_proxy_error(n,s) DHCPV6_PROXY_ERROR_##n,
42 #undef dhcpv6_proxy_error
45 
46 /* flags to indicate which DHCP ports should be or have been registered */
47 typedef enum
48 {
52 
53 /**
54  * @brief The Virtual Sub-net Selection information for a given RX FIB
55  */
56 typedef struct dhcp_vss_t_
57 {
58  /**
59  * @brief VSS type as defined in RFC 6607:
60  * 0 for NVT ASCII VPN Identifier
61  * 1 for RFC 2685 VPN-ID of 7 octects - 3 bytes OUI & 4 bytes VPN index
62  * 255 for global default VPN
63  */
65 #define VSS_TYPE_ASCII 0
66 #define VSS_TYPE_VPN_ID 1
67 #define VSS_TYPE_INVALID 123
68 #define VSS_TYPE_DEFAULT 255
69  /**
70  * @brief Type 1 VPN-ID
71  */
72  u8 vpn_id[7];
73  /**
74  * @brief Type 0 ASCII VPN Identifier
75  */
77 } dhcp_vss_t;
78 
79 /**
80  * @brief A representation of a single DHCP Server within a given VRF config
81  */
82 typedef struct dhcp_server_t_
83 {
84  /**
85  * @brief The address of the DHCP server to which to relay the client's
86  * messages
87  */
88  ip46_address_t dhcp_server;
89 
90  /**
91  * @brief The FIB index (not the external Table-ID) in which the server
92  * is reachable.
93  */
96 
97 /**
98  * @brief A DHCP proxy representation fpr per-client VRF config
99  */
100 typedef struct dhcp_proxy_t_
101 {
102  /**
103  * @brief The set of DHCP servers to which messages are relayed.
104  * If multiple servers are configured then discover/solict messages
105  * are relayed to each. A cookie is maintained for the relay, and only
106  * one message is replayed to the client, based on the presence of the
107  * cookie.
108  * The expectation is there are only 1 or 2 servers, hence no fancy DB.
109  */
111 
112  /**
113  * @brief Hash table of pending requets key'd on the clients MAC address
114  */
116 
117  /**
118  * @brief A lock for the pending request DB.
119  */
120  int lock;
121 
122  /**
123  * @brief The source address to use in relayed messaes
124  */
125  ip46_address_t dhcp_src_address;
126 
127  /**
128  * @brief The FIB index (not the external Table-ID) in which the client
129  * is resides.
130  */
132 } dhcp_proxy_t;
133 
134 #define DHCP_N_PROTOS (FIB_PROTOCOL_IP6 + 1)
135 
136 /**
137  * @brief Collection of global DHCP proxy data
138  */
139 typedef struct
140 {
141  /* Pool of DHCP servers */
142  dhcp_proxy_t *dhcp_servers[DHCP_N_PROTOS];
143 
144  /* Pool of selected DHCP server. Zero is the default server */
145  u32 *dhcp_server_index_by_rx_fib_index[DHCP_N_PROTOS];
146 
147  /* to drop pkts in server-to-client direction */
149 
151 
152  /* hash lookup specific vrf_id -> option 82 vss suboption */
153  u32 *vss_index_by_rx_fib_index[DHCP_N_PROTOS];
154 
155  /* flags to indicate which udp ports have been registered */
157 
158  /* convenience */
160 
162 
164 
165 /**
166  * @brief Register the dhcp client and/or server ports, if not already done
167  */
169 
170 /**
171  * @brief Send the details of a proxy session to the API client during a dump
172  */
174  void *opaque, u32 context, dhcp_proxy_t * proxy);
175 
176 /**
177  * @brief Show (on CLI) a VSS config during a show walk
178  */
179 int dhcp_vss_show_walk (dhcp_vss_t * vss, u32 rx_table_id, void *ctx);
180 
181 /**
182  * @brief Configure/set a new VSS info
183  */
185  u32 tbl_id,
186  u8 vss_type,
187  u8 * vpn_ascii_id, u32 oui, u32 vpn_index, u8 is_del);
188 
189 /**
190  * @brief Dump the proxy configs to the API
191  */
192 void dhcp_proxy_dump (fib_protocol_t proto, void *opaque, u32 context);
193 
194 /**
195  * @brief Add a new DHCP proxy server configuration.
196  * @return 1 is the config is new,
197  * 0 otherwise (implying a modify of an existing)
198  */
200  ip46_address_t * addr,
201  ip46_address_t * src_address,
202  u32 rx_fib_iindex, u32 server_table_id);
203 
204 /**
205  * @brief Delete a DHCP proxy config
206  * @return 1 if the proxy is deleted, 0 otherwise
207  */
209  u32 rx_fib_index,
210  ip46_address_t * addr, u32 server_table_id);
211 
213 
214 /**
215  * @brief Callback function invoked for each DHCP proxy entry
216  * return 0 to break the walk, non-zero otherwise.
217  */
218 typedef int (*dhcp_proxy_walk_fn_t) (dhcp_proxy_t * server, void *ctx);
219 
220 /**
221  * @brief Walk/Visit each DHCP proxy server
222  */
224  dhcp_proxy_walk_fn_t fn, void *ctx);
225 
226 /**
227  * @brief Callback function invoked for each DHCP VSS entry
228  * return 0 to break the walk, non-zero otherwise.
229  */
230 typedef int (*dhcp_vss_walk_fn_t) (dhcp_vss_t * server,
231  u32 rx_table_id, void *ctx);
232 
233 /**
234  * @brief Walk/Visit each DHCP proxy VSS
235  */
237 
238 /**
239  * @brief Lock a proxy object to prevent simultaneous access of its
240  * pending store
241  */
242 void dhcp_proxy_lock (dhcp_proxy_t * server);
243 
244 /**
245  * @brief Lock a proxy object to prevent simultaneous access of its
246  * pending store
247  */
248 void dhcp_proxy_unlock (dhcp_proxy_t * server);
249 
250 /**
251  * @brief Get the VSS data for the FIB index
252  */
253 static inline dhcp_vss_t *
255  u32 rx_fib_index, fib_protocol_t proto)
256 {
257  dhcp_vss_t *v = NULL;
258 
259  if (vec_len (dm->vss_index_by_rx_fib_index[proto]) > rx_fib_index &&
260  dm->vss_index_by_rx_fib_index[proto][rx_fib_index] != ~0)
261  {
262  v = pool_elt_at_index (dm->vss[proto],
263  dm->vss_index_by_rx_fib_index[proto]
264  [rx_fib_index]);
265  }
266 
267  return (v);
268 }
269 
270 /**
271  * @brief Get the DHCP proxy server data for the FIB index
272  */
273 static inline dhcp_proxy_t *
275  u32 rx_fib_index, fib_protocol_t proto)
276 {
277  dhcp_proxy_t *s = NULL;
278 
279  if (vec_len (dm->dhcp_server_index_by_rx_fib_index[proto]) > rx_fib_index &&
280  dm->dhcp_server_index_by_rx_fib_index[proto][rx_fib_index] != ~0)
281  {
282  s = pool_elt_at_index (dm->dhcp_servers[proto],
284  [rx_fib_index]);
285  }
286 
287  return (s);
288 }
289 
290 int dhcp6_proxy_set_server (ip46_address_t * addr,
291  ip46_address_t * src_addr,
292  u32 rx_table_id, u32 server_table_id, int is_del);
293 int dhcp4_proxy_set_server (ip46_address_t * addr,
294  ip46_address_t * src_addr,
295  u32 rx_table_id, u32 server_table_id, int is_del);
296 
297 #endif /* included_dhcp_proxy_h */
298 
299 /*
300  * fd.io coding-style-patch-verification: ON
301  *
302  * Local Variables:
303  * eval: (c-set-style "gnu")
304  * End:
305  */
#define DHCP_N_PROTOS
Definition: dhcp_proxy.h:134
static dhcp_vss_t * dhcp_get_vss_info(dhcp_proxy_main_t *dm, u32 rx_fib_index, fib_protocol_t proto)
Get the VSS data for the FIB index.
Definition: dhcp_proxy.h:254
void dhcp_maybe_register_udp_ports(dhcp_port_reg_flags_t ports)
Register the dhcp client and/or server ports, if not already done.
vss_type
Definition: dhcp.api:22
void dhcp_proxy_dump(fib_protocol_t proto, void *opaque, u32 context)
Dump the proxy configs to the API.
Definition: dhcp_proxy.c:248
struct dhcp_proxy_t_ dhcp_proxy_t
A DHCP proxy representation fpr per-client VRF config.
struct dhcp_server_t_ dhcp_server_t
A representation of a single DHCP Server within a given VRF config.
dhcp_server_t * dhcp_servers
The set of DHCP servers to which messages are relayed.
Definition: dhcp_proxy.h:110
int dhcp_vss_show_walk(dhcp_vss_t *vss, u32 rx_table_id, void *ctx)
Show (on CLI) a VSS config during a show walk.
Definition: dhcp_proxy.c:259
int dhcp4_proxy_set_server(ip46_address_t *addr, ip46_address_t *src_addr, u32 rx_table_id, u32 server_table_id, int is_del)
ip46_address_t dhcp_src_address
The source address to use in relayed messaes.
Definition: dhcp_proxy.h:125
The Virtual Sub-net Selection information for a given RX FIB.
Definition: dhcp_proxy.h:56
u32 * dhcp_server_index_by_rx_fib_index[DHCP_N_PROTOS]
Definition: dhcp_proxy.h:145
u32 rx_fib_index
The FIB index (not the external Table-ID) in which the client is resides.
Definition: dhcp_proxy.h:131
u8 vss_type
VSS type as defined in RFC 6607: 0 for NVT ASCII VPN Identifier 1 for RFC 2685 VPN-ID of 7 octects - ...
Definition: dhcp_proxy.h:64
vhost_vring_addr_t addr
Definition: vhost_user.h:111
void dhcp_proxy_lock(dhcp_proxy_t *server)
Lock a proxy object to prevent simultaneous access of its pending store.
unsigned char u8
Definition: types.h:56
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
static dhcp_proxy_t * dhcp_get_proxy(dhcp_proxy_main_t *dm, u32 rx_fib_index, fib_protocol_t proto)
Get the DHCP proxy server data for the FIB index.
Definition: dhcp_proxy.h:274
u32 * vss_index_by_rx_fib_index[DHCP_N_PROTOS]
Definition: dhcp_proxy.h:153
unsigned int u32
Definition: types.h:88
dhcp_proxy_error_t
Definition: dhcp_proxy.h:30
dhcp_proxy_t * dhcp_servers[DHCP_N_PROTOS]
Definition: dhcp_proxy.h:142
dhcpv6_proxy_error_t
Definition: dhcp_proxy.h:38
u32 server_fib_index
The FIB index (not the external Table-ID) in which the server is reachable.
Definition: dhcp_proxy.h:94
dhcp_port_reg_flags_t
Definition: dhcp_proxy.h:47
Collection of global DHCP proxy data.
Definition: dhcp_proxy.h:139
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:546
vl_api_ip_proto_t proto
Definition: acl_types.api:51
long ctx[MAX_CONNS]
Definition: main.c:144
int(* dhcp_vss_walk_fn_t)(dhcp_vss_t *server, u32 rx_table_id, void *ctx)
Callback function invoked for each DHCP VSS entry return 0 to break the walk, non-zero otherwise...
Definition: dhcp_proxy.h:230
vl_api_mac_address_t src_addr
Definition: flow_types.api:64
vlib_main_t * vlib_main
Definition: dhcp_proxy.h:159
vl_api_address_union_t src_address
Definition: ip_types.api:122
int lock
A lock for the pending request DB.
Definition: dhcp_proxy.h:120
u8 * vpn_ascii_id
Type 0 ASCII VPN Identifier.
Definition: dhcp_proxy.h:76
void dhcp_vss_walk(fib_protocol_t proto, dhcp_vss_walk_fn_t fn, void *ctx)
Walk/Visit each DHCP proxy VSS.
Definition: dhcp_proxy.c:87
A representation of a single DHCP Server within a given VRF config.
Definition: dhcp_proxy.h:82
struct dhcp_vss_t_ dhcp_vss_t
The Virtual Sub-net Selection information for a given RX FIB.
int(* dhcp_proxy_walk_fn_t)(dhcp_proxy_t *server, void *ctx)
Callback function invoked for each DHCP proxy entry return 0 to break the walk, non-zero otherwise...
Definition: dhcp_proxy.h:218
int dhcp_proxy_server_del(fib_protocol_t proto, u32 rx_fib_index, ip46_address_t *addr, u32 server_table_id)
Delete a DHCP proxy config.
Definition: dhcp_proxy.c:144
ip46_address_t dhcp_server
The address of the DHCP server to which to relay the client&#39;s messages.
Definition: dhcp_proxy.h:88
int dhcp6_proxy_set_server(ip46_address_t *addr, ip46_address_t *src_addr, u32 rx_table_id, u32 server_table_id, int is_del)
int dhcp_proxy_set_vss(fib_protocol_t proto, u32 tbl_id, u8 vss_type, u8 *vpn_ascii_id, u32 oui, u32 vpn_index, u8 is_del)
Configure/set a new VSS info.
Definition: dhcp_proxy.c:309
uword * dhcp_pending
Hash table of pending requets key&#39;d on the clients MAC address.
Definition: dhcp_proxy.h:115
void dhcp_proxy_walk(fib_protocol_t proto, dhcp_proxy_walk_fn_t fn, void *ctx)
Walk/Visit each DHCP proxy server.
Definition: dhcp_proxy.c:67
dhcp_proxy_main_t dhcp_proxy_main
Shard 4/6 instance of DHCP main.
Definition: dhcp_proxy.c:25
int dhcp_proxy_server_add(fib_protocol_t proto, ip46_address_t *addr, ip46_address_t *src_address, u32 rx_fib_iindex, u32 server_table_id)
Add a new DHCP proxy server configuration.
Definition: dhcp_proxy.c:184
A DHCP proxy representation fpr per-client VRF config.
Definition: dhcp_proxy.h:100
void dhcp_send_details(fib_protocol_t proto, void *opaque, u32 context, dhcp_proxy_t *proxy)
Send the details of a proxy session to the API client during a dump.
Definition: dhcp_api.c:176
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u8 vpn_id[7]
Type 1 VPN-ID.
Definition: dhcp_proxy.h:72
u64 uword
Definition: types.h:112
dhcp_vss_t * vss[DHCP_N_PROTOS]
Definition: dhcp_proxy.h:150
u32 dhcp_proxy_rx_table_get_table_id(fib_protocol_t proto, u32 fib_index)
Definition: dhcp_proxy.c:46
void dhcp_proxy_unlock(dhcp_proxy_t *server)
Lock a proxy object to prevent simultaneous access of its pending store.