FD.io VPP  v18.04-17-g3a0d853
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 <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>
30 
31 typedef enum
32 {
33 #define dhcp_proxy_error(n,s) DHCP_PROXY_ERROR_##n,
35 #undef dhcp_proxy_error
38 
39 typedef enum
40 {
41 #define dhcpv6_proxy_error(n,s) DHCPV6_PROXY_ERROR_##n,
43 #undef dhcpv6_proxy_error
46 
47 
48 /**
49  * @brief The Virtual Sub-net Selection information for a given RX FIB
50  */
51 typedef struct dhcp_vss_t_
52 {
53  /**
54  * @brief VSS type as defined in RFC 6607:
55  * 0 for NVT ASCII VPN Identifier
56  * 1 for RFC 2685 VPN-ID of 7 octects - 3 bytes OUI & 4 bytes VPN index
57  * 255 for global default VPN
58  */
60 #define VSS_TYPE_ASCII 0
61 #define VSS_TYPE_VPN_ID 1
62 #define VSS_TYPE_INVALID 123
63 #define VSS_TYPE_DEFAULT 255
64  /**
65  * @brief Type 1 VPN-ID
66  */
67  u8 vpn_id[7];
68  /**
69  * @brief Type 0 ASCII VPN Identifier
70  */
72 } dhcp_vss_t;
73 
74 /**
75  * @brief A representation of a single DHCP Server within a given VRF config
76  */
77 typedef struct dhcp_server_t_
78 {
79  /**
80  * @brief The address of the DHCP server to which to relay the client's
81  * messages
82  */
83  ip46_address_t dhcp_server;
84 
85  /**
86  * @brief The FIB index (not the external Table-ID) in which the server
87  * is reachable.
88  */
91 
92 /**
93  * @brief A DHCP proxy represenation fpr per-client VRF config
94  */
95 typedef struct dhcp_proxy_t_
96 {
97  /**
98  * @brief The set of DHCP servers to which messages are relayed.
99  * If multiple servers are configured then discover/solict messages
100  * are relayed to each. A cookie is maintained for the relay, and only
101  * one message is replayed to the client, based on the presence of the
102  * cookie.
103  * The expectation is there are only 1 or 2 servers, hence no fancy DB.
104  */
106 
107  /**
108  * @brief Hash table of pending requets key'd on the clients MAC address
109  */
111 
112  /**
113  * @brief A lock for the pending request DB.
114  */
115  int lock;
116 
117  /**
118  * @brief The source address to use in relayed messaes
119  */
120  ip46_address_t dhcp_src_address;
121 
122  /**
123  * @brief The FIB index (not the external Table-ID) in which the client
124  * is resides.
125  */
127 } dhcp_proxy_t;
128 
129 #define DHCP_N_PROTOS (FIB_PROTOCOL_IP6 + 1)
130 
131 /**
132  * @brief Collection of global DHCP proxy data
133  */
134 typedef struct
135 {
136  /* Pool of DHCP servers */
137  dhcp_proxy_t *dhcp_servers[DHCP_N_PROTOS];
138 
139  /* Pool of selected DHCP server. Zero is the default server */
140  u32 *dhcp_server_index_by_rx_fib_index[DHCP_N_PROTOS];
141 
142  /* to drop pkts in server-to-client direction */
144 
146 
147  /* hash lookup specific vrf_id -> option 82 vss suboption */
148  u32 *vss_index_by_rx_fib_index[DHCP_N_PROTOS];
150 
152 
153 /**
154  * @brief Send the details of a proxy session to the API client during a dump
155  */
157  void *opaque, u32 context, dhcp_proxy_t * proxy);
158 
159 /**
160  * @brief Show (on CLI) a VSS config during a show walk
161  */
162 int dhcp_vss_show_walk (dhcp_vss_t * vss, u32 rx_table_id, void *ctx);
163 
164 /**
165  * @brief Configure/set a new VSS info
166  */
168  u32 tbl_id,
169  u8 vss_type,
170  u8 * vpn_ascii_id, u32 oui, u32 vpn_index, u8 is_del);
171 
172 /**
173  * @brief Dump the proxy configs to the API
174  */
175 void dhcp_proxy_dump (fib_protocol_t proto, void *opaque, u32 context);
176 
177 /**
178  * @brief Add a new DHCP proxy server configuration.
179  * @return 1 is the config is new,
180  * 0 otherwise (implying a modify of an existing)
181  */
183  ip46_address_t * addr,
184  ip46_address_t * src_address,
185  u32 rx_fib_iindex, u32 server_table_id);
186 
187 /**
188  * @brief Delete a DHCP proxy config
189  * @return 1 if the proxy is deleted, 0 otherwise
190  */
192  u32 rx_fib_index,
193  ip46_address_t * addr, u32 server_table_id);
194 
196 
197 /**
198  * @brief Callback function invoked for each DHCP proxy entry
199  * return 0 to break the walk, non-zero otherwise.
200  */
201 typedef int (*dhcp_proxy_walk_fn_t) (dhcp_proxy_t * server, void *ctx);
202 
203 /**
204  * @brief Walk/Visit each DHCP proxy server
205  */
206 void dhcp_proxy_walk (fib_protocol_t proto,
207  dhcp_proxy_walk_fn_t fn, void *ctx);
208 
209 /**
210  * @brief Callback function invoked for each DHCP VSS entry
211  * return 0 to break the walk, non-zero otherwise.
212  */
213 typedef int (*dhcp_vss_walk_fn_t) (dhcp_vss_t * server,
214  u32 rx_table_id, void *ctx);
215 
216 /**
217  * @brief Walk/Visit each DHCP proxy VSS
218  */
219 void dhcp_vss_walk (fib_protocol_t proto, dhcp_vss_walk_fn_t fn, void *ctx);
220 
221 /**
222  * @brief Lock a proxy object to prevent simultaneous access of its
223  * pending store
224  */
225 void dhcp_proxy_lock (dhcp_proxy_t * server);
226 
227 /**
228  * @brief Lock a proxy object to prevent simultaneous access of its
229  * pending store
230  */
231 void dhcp_proxy_unlock (dhcp_proxy_t * server);
232 
233 /**
234  * @brief Get the VSS data for the FIB index
235  */
236 static inline dhcp_vss_t *
238  u32 rx_fib_index, fib_protocol_t proto)
239 {
240  dhcp_vss_t *v = NULL;
241 
242  if (vec_len (dm->vss_index_by_rx_fib_index[proto]) > rx_fib_index &&
243  dm->vss_index_by_rx_fib_index[proto][rx_fib_index] != ~0)
244  {
245  v = pool_elt_at_index (dm->vss[proto],
246  dm->vss_index_by_rx_fib_index[proto]
247  [rx_fib_index]);
248  }
249 
250  return (v);
251 }
252 
253 /**
254  * @brief Get the DHCP proxy server data for the FIB index
255  */
256 static inline dhcp_proxy_t *
258  u32 rx_fib_index, fib_protocol_t proto)
259 {
260  dhcp_proxy_t *s = NULL;
261 
262  if (vec_len (dm->dhcp_server_index_by_rx_fib_index[proto]) > rx_fib_index &&
263  dm->dhcp_server_index_by_rx_fib_index[proto][rx_fib_index] != ~0)
264  {
265  s = pool_elt_at_index (dm->dhcp_servers[proto],
267  [rx_fib_index]);
268  }
269 
270  return (s);
271 }
272 
273 int dhcp6_proxy_set_server (ip46_address_t * addr,
274  ip46_address_t * src_addr,
275  u32 rx_table_id, u32 server_table_id, int is_del);
276 int dhcp4_proxy_set_server (ip46_address_t * addr,
277  ip46_address_t * src_addr,
278  u32 rx_table_id, u32 server_table_id, int is_del);
279 
280 #endif /* included_dhcp_proxy_h */
281 
282 /*
283  * fd.io coding-style-patch-verification: ON
284  *
285  * Local Variables:
286  * eval: (c-set-style "gnu")
287  * End:
288  */
#define DHCP_N_PROTOS
Definition: dhcp_proxy.h:129
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:237
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 represenation 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:105
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
#define NULL
Definition: clib.h:55
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:120
The Virtual Sub-net Selection information for a given RX FIB.
Definition: dhcp_proxy.h:51
u32 * dhcp_server_index_by_rx_fib_index[DHCP_N_PROTOS]
Definition: dhcp_proxy.h:140
u32 rx_fib_index
The FIB index (not the external Table-ID) in which the client is resides.
Definition: dhcp_proxy.h:126
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:59
void dhcp_proxy_lock(dhcp_proxy_t *server)
Lock a proxy object to prevent simultaneous access of its pending store.
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:257
u32 * vss_index_by_rx_fib_index[DHCP_N_PROTOS]
Definition: dhcp_proxy.h:148
dhcp_proxy_error_t
Definition: dhcp_proxy.h:31
dhcp_proxy_t * dhcp_servers[DHCP_N_PROTOS]
Definition: dhcp_proxy.h:137
dhcpv6_proxy_error_t
Definition: dhcp_proxy.h:39
u32 server_fib_index
The FIB index (not the external Table-ID) in which the server is reachable.
Definition: dhcp_proxy.h:89
Collection of global DHCP proxy data.
Definition: dhcp_proxy.h:134
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:461
#define v
Definition: acl.c:495
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:213
int lock
A lock for the pending request DB.
Definition: dhcp_proxy.h:115
u8 * vpn_ascii_id
Type 0 ASCII VPN Identifier.
Definition: dhcp_proxy.h:71
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:77
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:201
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:83
unsigned int u32
Definition: types.h:88
long ctx[MAX_CONNS]
Definition: main.c:126
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:110
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
u64 uword
Definition: types.h:112
A DHCP proxy represenation fpr per-client VRF config.
Definition: dhcp_proxy.h:95
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:124
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
u8 vpn_id[7]
Type 1 VPN-ID.
Definition: dhcp_proxy.h:67
dhcp_vss_t * vss[DHCP_N_PROTOS]
Definition: dhcp_proxy.h:145
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.
vhost_vring_addr_t addr
Definition: vhost-user.h:83