FD.io VPP  v20.05.1-6-gf53edbc3b
Vector Packet Processing
dhcp4_proxy_node.c
Go to the documentation of this file.
1 /*
2  * proxy_node.c: dhcp proxy node processing
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 #include <vlib/vlib.h>
19 #include <vnet/pg/pg.h>
20 #include <dhcp/dhcp_proxy.h>
21 #include <dhcp/client.h>
22 #include <vnet/fib/ip4_fib.h>
23 
24 static char *dhcp_proxy_error_strings[] = {
25 #define dhcp_proxy_error(n,s) s,
27 #undef dhcp_proxy_error
28 };
29 
30 #define foreach_dhcp_proxy_to_server_input_next \
31  _ (DROP, "error-drop") \
32  _ (LOOKUP, "ip4-lookup") \
33  _ (SEND_TO_CLIENT, "dhcp-proxy-to-client")
34 
35 typedef enum
36 {
37 #define _(s,n) DHCP_PROXY_TO_SERVER_INPUT_NEXT_##s,
39 #undef _
42 
43 typedef struct
44 {
45  /* 0 => to server, 1 => to client */
46  int which;
51 
52  /* enough space for the DHCP header plus some options */
53  u8 packet_data[2 * sizeof (dhcp_header_t)];
54 }
56 
57 #define VPP_DHCP_OPTION82_SUB1_SIZE 6
58 #define VPP_DHCP_OPTION82_SUB5_SIZE 6
59 #define VPP_DHCP_OPTION82_VSS_SIZE 12
60 #define VPP_DHCP_OPTION82_SIZE (VPP_DHCP_OPTION82_SUB1_SIZE + \
61  VPP_DHCP_OPTION82_SUB5_SIZE + \
62  VPP_DHCP_OPTION82_VSS_SIZE +3)
63 
66 
67 static u8 *
68 format_dhcp_proxy_trace (u8 * s, va_list * args)
69 {
70  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
71  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
72  dhcp_proxy_trace_t *t = va_arg (*args, dhcp_proxy_trace_t *);
73 
74  if (t->which == 0)
75  s = format (s, "DHCP proxy: sent to server %U\n",
77  else
78  s = format (s, "DHCP proxy: broadcast to client from %U\n",
80 
81  if (t->error != (u32) ~ 0)
82  s = format (s, " error: %s\n", dhcp_proxy_error_strings[t->error]);
83 
84  s = format (s, " original_sw_if_index: %d, sw_if_index: %d\n",
86  s = format (s, " %U",
87  format_dhcp_header, t->packet_data, sizeof (t->packet_data));
88 
89  return s;
90 }
91 
92 static u8 *
94 {
95  dhcp_header_t *h = va_arg (*args, dhcp_header_t *);
96  u32 max_header_bytes = va_arg (*args, u32);
97  u32 header_bytes;
98 
99  header_bytes = sizeof (h[0]);
100  if (max_header_bytes != 0 && header_bytes > max_header_bytes)
101  return format (s, "dhcp header truncated");
102 
103  s = format (s, "DHCP Proxy");
104 
105  return s;
106 }
107 
108 static uword
111  vlib_frame_t * from_frame)
112 {
113  u32 n_left_from, next_index, *from, *to_next;
115  from = vlib_frame_vector_args (from_frame);
116  n_left_from = from_frame->n_vectors;
117  u32 pkts_to_server = 0, pkts_to_client = 0, pkts_no_server = 0;
118  u32 pkts_no_interface_address = 0;
119  u32 pkts_too_big = 0;
120  ip4_main_t *im = &ip4_main;
121 
122  next_index = node->cached_next_index;
123 
124  while (n_left_from > 0)
125  {
126  u32 n_left_to_next;
127 
128  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
129 
130  while (n_left_from > 0 && n_left_to_next > 0)
131  {
132  u32 bi0;
133  vlib_buffer_t *b0;
134  udp_header_t *u0;
135  dhcp_header_t *h0;
136  ip4_header_t *ip0;
137  u32 next0;
138  u32 old0, new0;
139  ip_csum_t sum0;
140  u32 error0 = (u32) ~ 0;
141  u32 sw_if_index = 0;
142  u32 original_sw_if_index = 0;
143  u32 fib_index;
144  dhcp_proxy_t *proxy;
145  dhcp_server_t *server;
146  u32 rx_sw_if_index;
147  dhcp_option_t *o, *end;
148  u32 len = 0;
149  u8 is_discover = 0;
150  int space_left;
151 
152  bi0 = from[0];
153  from += 1;
154  n_left_from -= 1;
155 
156  b0 = vlib_get_buffer (vm, bi0);
157 
158  h0 = vlib_buffer_get_current (b0);
159 
160  /*
161  * udp_local hands us the DHCP header, need udp hdr,
162  * ip hdr to relay to server
163  */
164  vlib_buffer_advance (b0, -(sizeof (*u0)));
165  u0 = vlib_buffer_get_current (b0);
166 
167  /* This blows. Return traffic has src_port = 67, dst_port = 67 */
168  if (u0->src_port ==
169  clib_net_to_host_u16 (UDP_DST_PORT_dhcp_to_server))
170  {
171  vlib_buffer_advance (b0, sizeof (*u0));
172  next0 = DHCP_PROXY_TO_SERVER_INPUT_NEXT_SEND_TO_CLIENT;
173  error0 = 0;
174  pkts_to_client++;
175  goto do_enqueue;
176  }
177 
178  rx_sw_if_index = vnet_buffer (b0)->sw_if_index[VLIB_RX];
179  fib_index = im->fib_index_by_sw_if_index[rx_sw_if_index];
180  proxy = dhcp_get_proxy (dpm, fib_index, FIB_PROTOCOL_IP4);
181 
182  if (PREDICT_FALSE (NULL == proxy))
183  {
184  error0 = DHCP_PROXY_ERROR_NO_SERVER;
185  next0 = DHCP_PROXY_TO_SERVER_INPUT_NEXT_DROP;
186  pkts_no_server++;
187  goto do_trace;
188  }
189 
190  if (!vlib_buffer_chain_linearize (vm, b0))
191  {
192  error0 = DHCP_PROXY_ERROR_PKT_TOO_BIG;
193  next0 = DHCP_PROXY_TO_SERVER_INPUT_NEXT_DROP;
194  pkts_too_big++;
195  goto do_trace;
196  }
197  space_left = vlib_buffer_space_left_at_end (vm, b0);
198  /* cant parse chains...
199  * and we need some space for option 82*/
200  if ((b0->flags & VLIB_BUFFER_NEXT_PRESENT) != 0 ||
201  space_left < VPP_DHCP_OPTION82_SIZE)
202  {
203  error0 = DHCP_PROXY_ERROR_PKT_TOO_BIG;
204  next0 = DHCP_PROXY_TO_SERVER_INPUT_NEXT_DROP;
205  pkts_too_big++;
206  goto do_trace;
207  }
208 
209  server = &proxy->dhcp_servers[0];
210  vlib_buffer_advance (b0, -(sizeof (*ip0)));
211  ip0 = vlib_buffer_get_current (b0);
212 
213  /* disable UDP checksum */
214  u0->checksum = 0;
215  sum0 = ip0->checksum;
216  old0 = ip0->dst_address.as_u32;
217  new0 = server->dhcp_server.ip4.as_u32;
218  ip0->dst_address.as_u32 = server->dhcp_server.ip4.as_u32;
219  sum0 = ip_csum_update (sum0, old0, new0,
220  ip4_header_t /* structure */ ,
221  dst_address /* changed member */ );
222  ip0->checksum = ip_csum_fold (sum0);
223 
224  sum0 = ip0->checksum;
225  old0 = ip0->src_address.as_u32;
226  new0 = proxy->dhcp_src_address.ip4.as_u32;
227  ip0->src_address.as_u32 = new0;
228  sum0 = ip_csum_update (sum0, old0, new0,
229  ip4_header_t /* structure */ ,
230  src_address /* changed member */ );
231  ip0->checksum = ip_csum_fold (sum0);
232 
233  /* Send to DHCP server via the configured FIB */
234  vnet_buffer (b0)->sw_if_index[VLIB_TX] = server->server_fib_index;
235 
236  h0->gateway_ip_address = proxy->dhcp_src_address.ip4;
237  pkts_to_server++;
238 
239  o = h0->options;
240  end = (void *) vlib_buffer_get_tail (b0);
241 
242  /* TLVs are not performance-friendly... */
243  while (o->option != DHCP_PACKET_OPTION_END && o < end)
244  {
246  {
247  if (DHCP_PACKET_DISCOVER == o->data[0])
248  {
249  is_discover = 1;
250  }
251  }
252  o = (dhcp_option_t *) (o->data + o->length);
253  }
254 
255  if (o->option == DHCP_PACKET_OPTION_END && o <= end)
256  {
257  vnet_main_t *vnm = vnet_get_main ();
258  u16 old_l0, new_l0;
259  ip4_address_t _ia0, *ia0 = &_ia0;
260  dhcp_vss_t *vss;
261  vnet_sw_interface_t *swif;
262 
263  original_sw_if_index = sw_if_index =
264  vnet_buffer (b0)->sw_if_index[VLIB_RX];
265  swif = vnet_get_sw_interface (vnm, sw_if_index);
267  sw_if_index = swif->unnumbered_sw_if_index;
268 
269  /*
270  * Get the first ip4 address on the [client-side]
271  * RX interface, if not unnumbered. otherwise use
272  * the loopback interface's ip address.
273  */
274  ia0 = ip4_interface_first_address (&ip4_main, sw_if_index, 0);
275 
276  if (ia0 == 0)
277  {
278  error0 = DHCP_PROXY_ERROR_NO_INTERFACE_ADDRESS;
279  next0 = DHCP_PROXY_TO_SERVER_INPUT_NEXT_DROP;
280  pkts_no_interface_address++;
281  goto do_trace;
282  }
283 
284  /* Add option 82 */
285  o->option = 82; /* option 82 */
286  o->length = 12; /* 12 octets to follow */
287  o->data[0] = 1; /* suboption 1, circuit ID (=FIB id) */
288  o->data[1] = 4; /* length of suboption */
289  u32 *o_ifid = (u32 *) & o->data[2];
290  *o_ifid = clib_host_to_net_u32 (original_sw_if_index);
291  o->data[6] = 5; /* suboption 5 (client RX intfc address) */
292  o->data[7] = 4; /* length 4 */
293  u32 *o_addr = (u32 *) & o->data[8];
294  *o_addr = ia0->as_u32;
295  o->data[12] = DHCP_PACKET_OPTION_END;
296 
297  vss = dhcp_get_vss_info (dpm, fib_index, FIB_PROTOCOL_IP4);
298  if (vss)
299  {
300  u32 id_len; /* length of VPN ID */
301 
302  if (vss->vss_type == VSS_TYPE_VPN_ID)
303  {
304  id_len = sizeof (vss->vpn_id); /* vpn_id is 7 bytes */
305  memcpy (&o->data[15], vss->vpn_id, id_len);
306  }
307  else if (vss->vss_type == VSS_TYPE_ASCII)
308  {
309  id_len = vec_len (vss->vpn_ascii_id);
310  memcpy (&o->data[15], vss->vpn_ascii_id, id_len);
311  }
312  else /* must be VSS_TYPE_DEFAULT, no VPN ID */
313  id_len = 0;
314 
315  o->data[12] = 151; /* vss suboption */
316  o->data[13] = id_len + 1; /* length: vss_type + id_len */
317  o->data[14] = vss->vss_type; /* vss option type */
318  o->data[15 + id_len] = 152; /* vss control suboption */
319  o->data[16 + id_len] = 0; /* length */
320  o->data[17 + id_len] = DHCP_PACKET_OPTION_END; /* "end-of-options" (0xFF) */
321  /* 5 bytes for suboption headers 151+len, 152+len and 0xFF */
322  o->length += id_len + 5;
323  }
324 
325  len = o->length + 3;
326  b0->current_length += len;
327  /* Fix IP header length and checksum */
328  old_l0 = ip0->length;
329  new_l0 = clib_net_to_host_u16 (old_l0);
330  new_l0 += len;
331  new_l0 = clib_host_to_net_u16 (new_l0);
332  ip0->length = new_l0;
333  sum0 = ip0->checksum;
334  sum0 = ip_csum_update (sum0, old_l0, new_l0, ip4_header_t,
335  length /* changed member */ );
336  ip0->checksum = ip_csum_fold (sum0);
337 
338  /* Fix UDP length */
339  new_l0 = clib_net_to_host_u16 (u0->length);
340  new_l0 += len;
341  u0->length = clib_host_to_net_u16 (new_l0);
342  }
343  else
344  {
346  (vm, dhcp_proxy_to_server_node.index,
347  DHCP_PROXY_ERROR_OPTION_82_ERROR, 1);
348  }
349 
350  next0 = DHCP_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP;
351 
352  /*
353  * If we have multiple servers configured and this is the
354  * client's discover message, then send copies to each of
355  * those servers
356  */
357  if (is_discover && vec_len (proxy->dhcp_servers) > 1)
358  {
359  u32 ii;
360 
361  for (ii = 1; ii < vec_len (proxy->dhcp_servers); ii++)
362  {
363  vlib_buffer_t *c0;
364  u32 ci0;
365 
366  c0 = vlib_buffer_copy (vm, b0);
367  if (c0 == NULL)
368  {
370  (vm, dhcp_proxy_to_server_node.index,
371  DHCP_PROXY_ERROR_ALLOC_FAIL, 1);
372  continue;
373  }
375  ci0 = vlib_get_buffer_index (vm, c0);
376  server = &proxy->dhcp_servers[ii];
377 
378  ip0 = vlib_buffer_get_current (c0);
379 
380  sum0 = ip0->checksum;
381  old0 = ip0->dst_address.as_u32;
382  new0 = server->dhcp_server.ip4.as_u32;
383  ip0->dst_address.as_u32 = server->dhcp_server.ip4.as_u32;
384  sum0 = ip_csum_update (sum0, old0, new0,
385  ip4_header_t /* structure */ ,
386  dst_address /* changed member */ );
387  ip0->checksum = ip_csum_fold (sum0);
388 
389  to_next[0] = ci0;
390  to_next += 1;
391  n_left_to_next -= 1;
392 
393  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
394  to_next, n_left_to_next,
395  ci0, next0);
396 
397  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
398  {
399  dhcp_proxy_trace_t *tr;
400 
401  tr = vlib_add_trace (vm, node, c0, sizeof (*tr));
402  tr->which = 0; /* to server */
403  tr->error = error0;
404  tr->original_sw_if_index = original_sw_if_index;
405  tr->sw_if_index = sw_if_index;
406  if (next0 == DHCP_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP)
408  server->dhcp_server.ip4.as_u32;
409 
410  clib_memcpy_fast (tr->packet_data, h0,
411  sizeof (tr->packet_data));
412 
413  }
414 
415  if (PREDICT_FALSE (0 == n_left_to_next))
416  {
417  vlib_put_next_frame (vm, node, next_index,
418  n_left_to_next);
419  vlib_get_next_frame (vm, node, next_index,
420  to_next, n_left_to_next);
421  }
422  }
423  }
424  do_trace:
425  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
426  {
427  dhcp_proxy_trace_t *tr = vlib_add_trace (vm, node,
428  b0, sizeof (*tr));
429  tr->which = 0; /* to server */
430  tr->error = error0;
431  tr->original_sw_if_index = original_sw_if_index;
432  tr->sw_if_index = sw_if_index;
433  if (next0 == DHCP_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP)
435  proxy->dhcp_servers[0].dhcp_server.ip4.as_u32;
436  clib_memcpy_fast (tr->packet_data, h0,
437  sizeof (tr->packet_data));
438  }
439 
440  do_enqueue:
441  to_next[0] = bi0;
442  to_next += 1;
443  n_left_to_next -= 1;
444 
445  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
446  to_next, n_left_to_next,
447  bi0, next0);
448  }
449 
450  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
451  }
453  DHCP_PROXY_ERROR_RELAY_TO_CLIENT,
454  pkts_to_client);
456  DHCP_PROXY_ERROR_RELAY_TO_SERVER,
457  pkts_to_server);
459  DHCP_PROXY_ERROR_NO_SERVER, pkts_no_server);
461  DHCP_PROXY_ERROR_NO_INTERFACE_ADDRESS,
462  pkts_no_interface_address);
464  DHCP_PROXY_ERROR_PKT_TOO_BIG, pkts_too_big);
465  return from_frame->n_vectors;
466 }
467 
468 /* *INDENT-OFF* */
470  .function = dhcp_proxy_to_server_input,
471  .name = "dhcp-proxy-to-server",
472  /* Takes a vector of packets. */
473  .vector_size = sizeof (u32),
474 
475  .n_errors = DHCP_PROXY_N_ERROR,
476  .error_strings = dhcp_proxy_error_strings,
477 
478  .n_next_nodes = DHCP_PROXY_TO_SERVER_INPUT_N_NEXT,
479  .next_nodes = {
480 #define _(s,n) [DHCP_PROXY_TO_SERVER_INPUT_NEXT_##s] = n,
482 #undef _
483  },
484 
485  .format_buffer = format_dhcp_proxy_header_with_length,
486  .format_trace = format_dhcp_proxy_trace,
487 #if 0
488  .unformat_buffer = unformat_dhcp_proxy_header,
489 #endif
490 };
491 /* *INDENT-ON* */
492 
493 typedef enum
494 {
498 } dhcp4_next_t;
499 
500 static uword
503  vlib_frame_t * from_frame)
504 {
505  u32 n_left_from, *from, *to_next, n_left_to_next;
508  vnet_main_t *vnm = vnet_get_main ();
509  ip4_main_t *im = &ip4_main;
510  u32 next_index;
511 
512  from = vlib_frame_vector_args (from_frame);
513  n_left_from = from_frame->n_vectors;
514  next_index = node->cached_next_index;
515 
516  while (n_left_from > 0)
517  {
518  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
519 
520  while (n_left_from > 0 && n_left_to_next > 0)
521  {
522  u32 bi0;
523  vlib_buffer_t *b0;
524  udp_header_t *u0;
525  dhcp_header_t *h0;
526  ip4_header_t *ip0 = 0;
527  ip4_address_t *ia0 = 0;
528  u32 old0, new0;
529  ip_csum_t sum0;
531  ethernet_header_t *mac0;
532  vnet_hw_interface_t *hi0;
533  u32 sw_if_index = ~0;
534  vnet_sw_interface_t *si0;
535  u32 inner_vlan = (u32) ~ 0;
536  u32 outer_vlan = (u32) ~ 0;
537  u32 error0 = (u32) ~ 0;
538  vnet_sw_interface_t *swif;
539  u32 fib_index;
540  dhcp_proxy_t *proxy;
541  dhcp_server_t *server;
542  u32 original_sw_if_index = (u32) ~ 0;
544  ip4_address_t relay_addr = {
545  .as_u32 = 0,
546  };
547 
548  bi0 = to_next[0] = from[0];
549  from += 1;
550  to_next += 1;
551  n_left_from -= 1;
552  n_left_to_next -= 1;
553 
554  b0 = vlib_get_buffer (vm, bi0);
555  h0 = vlib_buffer_get_current (b0);
556 
557  /*
558  * udp_local hands us the DHCP header, need udp hdr,
559  * ip hdr to relay to client
560  */
561  vlib_buffer_advance (b0, -(sizeof (*u0)));
562  u0 = vlib_buffer_get_current (b0);
563 
564  vlib_buffer_advance (b0, -(sizeof (*ip0)));
565  ip0 = vlib_buffer_get_current (b0);
566 
567  /* Consumed by dhcp client code? */
568  if (dhcp_client_for_us (bi0, b0, ip0, u0, h0))
569  {
570  error0 = DHCP_PROXY_ERROR_FOR_US;
571  goto drop_packet;
572  }
573 
574  // if (1 /* dpm->insert_option_82 */ )
575  /* linearize needed to "unclone" and scan options */
576  int rv = vlib_buffer_chain_linearize (vm, b0);
577  if ((b0->flags & VLIB_BUFFER_NEXT_PRESENT) != 0 || !rv)
578  {
579  error0 = DHCP_PROXY_ERROR_PKT_TOO_BIG;
580  goto drop_packet;
581  }
582 
583  dhcp_option_t *o = h0->options, *end =
584  (void *) vlib_buffer_get_tail (b0);
585 
586  /* Parse through TLVs looking for option 82.
587  The circuit-ID is the FIB number we need
588  to track down the client-facing interface */
589 
590  while (o->option != DHCP_PACKET_OPTION_END && o < end)
591  {
592  if (o->option == 82)
593  {
594  u32 vss_exist = 0;
595  u32 vss_ctrl = 0;
596  dhcp_option_t *sub = (dhcp_option_t *) & o->data[0];
597  dhcp_option_t *subend =
598  (dhcp_option_t *) (o->data + o->length);
599  while (sub->option != DHCP_PACKET_OPTION_END
600  && sub < subend)
601  {
602  /* If this is one of ours, it will have
603  total length 12, circuit-id suboption type,
604  and the sw_if_index */
605  if (sub->option == 1 && sub->length == 4)
606  {
607  sw_if_index = ((sub->data[0] << 24) |
608  (sub->data[1] << 16) |
609  (sub->data[2] << 8) |
610  (sub->data[3]));
611  }
612  else if (sub->option == 5 && sub->length == 4)
613  {
614  relay_addr.as_u8[0] = sub->data[0];
615  relay_addr.as_u8[1] = sub->data[1];
616  relay_addr.as_u8[2] = sub->data[2];
617  relay_addr.as_u8[3] = sub->data[3];
618  }
619  else if (sub->option == 151 &&
620  sub->length == 7 && sub->data[0] == 1)
621  vss_exist = 1;
622  else if (sub->option == 152 && sub->length == 0)
623  vss_ctrl = 1;
624  sub = (dhcp_option_t *) (sub->data + sub->length);
625  }
626  if (vss_ctrl && vss_exist)
628  (vm, dhcp_proxy_to_client_node.index,
629  DHCP_PROXY_ERROR_OPTION_82_VSS_NOT_PROCESSED, 1);
630 
631  }
632  o = (dhcp_option_t *) (o->data + o->length);
633  }
634 
635  if (sw_if_index == (u32) ~ 0)
636  {
637  error0 = DHCP_PROXY_ERROR_NO_OPTION_82;
638 
639  drop_packet:
642  error0, 1);
643  b0->error = node->errors[error0];
644  next0 = DHCP4_PROXY_NEXT_DROP;
645  goto do_trace;
646  }
647 
648  if (relay_addr.as_u32 == 0)
649  {
650  error0 = DHCP_PROXY_ERROR_BAD_OPTION_82_ADDR;
651  goto drop_packet;
652  }
653 
654  if (sw_if_index >= vec_len (im->fib_index_by_sw_if_index))
655  {
656  error0 = DHCP_PROXY_ERROR_BAD_OPTION_82_ITF;
657  goto drop_packet;
658  }
659 
660  fib_index = im->fib_index_by_sw_if_index[sw_if_index];
661  proxy = dhcp_get_proxy (dpm, fib_index, FIB_PROTOCOL_IP4);
662 
663  if (PREDICT_FALSE (NULL == proxy))
664  {
665  error0 = DHCP_PROXY_ERROR_NO_SERVER;
666  goto drop_packet;
667  }
668 
669  vec_foreach (server, proxy->dhcp_servers)
670  {
671  if (ip0->src_address.as_u32 == server->dhcp_server.ip4.as_u32)
672  {
673  goto server_found;
674  }
675  }
676 
677  error0 = DHCP_PROXY_ERROR_BAD_SVR_FIB_OR_ADDRESS;
678  goto drop_packet;
679 
680  server_found:
681  vnet_buffer (b0)->sw_if_index[VLIB_TX] = sw_if_index;
682 
683  swif = vnet_get_sw_interface (vnm, sw_if_index);
684  original_sw_if_index = sw_if_index;
686  sw_if_index = swif->unnumbered_sw_if_index;
687 
688  ia0 = ip4_interface_first_address (&ip4_main, sw_if_index, 0);
689  if (ia0 == 0)
690  {
691  error0 = DHCP_PROXY_ERROR_NO_INTERFACE_ADDRESS;
692  goto drop_packet;
693  }
694 
695  if (relay_addr.as_u32 != ia0->as_u32)
696  {
697  error0 = DHCP_PROXY_ERROR_BAD_YIADDR;
698  goto drop_packet;
699  }
700 
701  u0->checksum = 0;
702  u0->dst_port = clib_net_to_host_u16 (UDP_DST_PORT_dhcp_to_client);
703  sum0 = ip0->checksum;
704  old0 = ip0->dst_address.as_u32;
705  new0 = 0xFFFFFFFF;
706  ip0->dst_address.as_u32 = new0;
707  sum0 =
708  ip_csum_update (sum0, old0, new0, ip4_header_t /* structure */ ,
709  dst_address /* offset of changed member */ );
710  ip0->checksum = ip_csum_fold (sum0);
711 
712  sum0 = ip0->checksum;
713  old0 = ip0->src_address.as_u32;
714  new0 = ia0->as_u32;
715  ip0->src_address.as_u32 = new0;
716  sum0 =
717  ip_csum_update (sum0, old0, new0, ip4_header_t /* structure */ ,
718  src_address /* offset of changed member */ );
719  ip0->checksum = ip_csum_fold (sum0);
720 
721  vlib_buffer_advance (b0, -(sizeof (ethernet_header_t)));
722  si0 = vnet_get_sw_interface (vnm, original_sw_if_index);
723  if (si0->type == VNET_SW_INTERFACE_TYPE_SUB)
724  {
725  if (si0->sub.eth.flags.one_tag == 1)
726  {
727  vlib_buffer_advance (b0, -4 /* space for 1 VLAN tag */ );
728  outer_vlan = (si0->sub.eth.outer_vlan_id << 16) | 0x0800;
729  }
730  else if (si0->sub.eth.flags.two_tags == 1)
731  {
732  vlib_buffer_advance (b0, -8 /* space for 2 VLAN tag */ );
733  outer_vlan = (si0->sub.eth.outer_vlan_id << 16) | 0x8100;
734  inner_vlan = (si0->sub.eth.inner_vlan_id << 16) | 0x0800;
735  }
736  }
737 
738  mac0 = vlib_buffer_get_current (b0);
739 
740  hi0 = vnet_get_sup_hw_interface (vnm, original_sw_if_index);
741  ei0 = pool_elt_at_index (em->interfaces, hi0->hw_instance);
742  clib_memcpy (mac0->src_address, ei0->address,
743  sizeof (ei0->address));
744  clib_memset (mac0->dst_address, 0xff, sizeof (mac0->dst_address));
745 
746  if (si0->type == VNET_SW_INTERFACE_TYPE_SUB
747  && outer_vlan != (u32) ~ 0)
748  {
749  mac0->type = (si0->sub.eth.flags.dot1ad == 1) ?
750  clib_net_to_host_u16 (0x88a8) : clib_net_to_host_u16 (0x8100);
751  u32 *vlan_tag = (u32 *) (mac0 + 1);
752  *vlan_tag = clib_host_to_net_u32 (outer_vlan);
753  if (inner_vlan != (u32) ~ 0)
754  {
755  u32 *inner_vlan_tag = (u32 *) (vlan_tag + 1);
756  *inner_vlan_tag = clib_host_to_net_u32 (inner_vlan);
757  }
758  }
759  else
760  {
761  mac0->type = clib_net_to_host_u16 (0x0800);
762  }
763 
764  do_trace:
765  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
766  {
767  dhcp_proxy_trace_t *tr = vlib_add_trace (vm, node,
768  b0, sizeof (*tr));
769  tr->which = 1; /* to client */
770  tr->trace_ip4_address.as_u32 = ia0 ? ia0->as_u32 : 0;
771  tr->error = error0;
772  tr->original_sw_if_index = original_sw_if_index;
773  tr->sw_if_index = sw_if_index;
774  clib_memcpy_fast (tr->packet_data, h0,
775  sizeof (tr->packet_data));
776  }
777 
778  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
779  to_next, n_left_to_next,
780  bi0, next0);
781  }
782  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
783  }
784 
785  return from_frame->n_vectors;
786 }
787 
788 /* *INDENT-OFF* */
790  .function = dhcp_proxy_to_client_input,
791  .name = "dhcp-proxy-to-client",
792  /* Takes a vector of packets. */
793  .vector_size = sizeof (u32),
794 
795  .n_errors = DHCP_PROXY_N_ERROR,
796  .error_strings = dhcp_proxy_error_strings,
797  .format_buffer = format_dhcp_proxy_header_with_length,
798  .format_trace = format_dhcp_proxy_trace,
799 #if 0
800  .unformat_buffer = unformat_dhcp_proxy_header,
801 #endif
802  .n_next_nodes = DHCP4_PROXY_N_NEXT,
803  .next_nodes = {
804  [DHCP4_PROXY_NEXT_DROP] = "error-drop",
805  [DHCP4_PROXY_NEXT_TX] = "interface-output",
806  },
807 };
808 /* *INDENT-ON* */
809 
810 void
812 {
814  vlib_main_t *vm = dm->vlib_main;
815  int port_regs_diff = dm->udp_ports_registered ^ ports;
816 
817  if (!port_regs_diff)
818  return;
819 
820  if ((port_regs_diff & DHCP_PORT_REG_CLIENT) & ports)
821  udp_register_dst_port (vm, UDP_DST_PORT_dhcp_to_client,
822  dhcp_proxy_to_client_node.index, 1 /* is_ip4 */ );
823 
824  if ((port_regs_diff & DHCP_PORT_REG_SERVER) & ports)
825  udp_register_dst_port (vm, UDP_DST_PORT_dhcp_to_server,
826  dhcp_proxy_to_server_node.index, 1 /* is_ip4 */ );
827 
828  dm->udp_ports_registered |= ports;
829 }
830 
831 static clib_error_t *
833 {
836 
837  error_drop_node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
838  dm->error_drop_node_index = error_drop_node->index;
839  dm->vlib_main = vm;
840 
841  return 0;
842 }
843 
844 
846 
847 int
848 dhcp4_proxy_set_server (ip46_address_t * addr,
849  ip46_address_t * src_addr,
850  u32 rx_table_id, u32 server_table_id, int is_del)
851 {
852  u32 rx_fib_index = 0;
853  int rc = 0;
854 
855  const fib_prefix_t all_1s = {
856  .fp_len = 32,
857  .fp_addr.ip4.as_u32 = 0xffffffff,
858  .fp_proto = FIB_PROTOCOL_IP4,
859  };
860 
861  if (ip46_address_is_zero (addr))
862  return VNET_API_ERROR_INVALID_DST_ADDRESS;
863 
864  if (ip46_address_is_zero (src_addr))
865  return VNET_API_ERROR_INVALID_SRC_ADDRESS;
866 
868 
870  rx_table_id,
872 
873  if (is_del)
874  {
875  if (dhcp_proxy_server_del (FIB_PROTOCOL_IP4, rx_fib_index,
876  addr, server_table_id))
877  {
878  fib_table_entry_special_remove (rx_fib_index,
879  &all_1s, FIB_SOURCE_DHCP);
881  }
882  }
883  else
884  {
886  addr, src_addr,
887  rx_fib_index, server_table_id))
888  {
889  fib_table_entry_special_add (rx_fib_index,
890  &all_1s,
893  }
894  }
896 
897  return (rc);
898 }
899 
900 static clib_error_t *
902  unformat_input_t * input,
903  vlib_cli_command_t * cmd)
904 {
905  ip46_address_t server_addr, src_addr;
906  u32 server_table_id = 0, rx_table_id = 0;
907  int is_del = 0;
908  int set_src = 0, set_server = 0;
909 
910  clib_memset (&server_addr, 0, sizeof (server_addr));
911  clib_memset (&src_addr, 0, sizeof (src_addr));
912 
914  {
915  if (unformat (input, "server %U",
916  unformat_ip4_address, &server_addr.ip4))
917  set_server = 1;
918  else if (unformat (input, "server-fib-id %d", &server_table_id))
919  ;
920  else if (unformat (input, "rx-fib-id %d", &rx_table_id))
921  ;
922  else if (unformat (input, "src-address %U",
923  unformat_ip4_address, &src_addr.ip4))
924  set_src = 1;
925  else if (unformat (input, "delete") || unformat (input, "del"))
926  is_del = 1;
927  else
928  break;
929  }
930 
931  if (is_del || (set_server && set_src))
932  {
933  int rv;
934 
935  rv = dhcp4_proxy_set_server (&server_addr, &src_addr, rx_table_id,
936  server_table_id, is_del);
937  switch (rv)
938  {
939  case 0:
940  return 0;
941 
942  case VNET_API_ERROR_INVALID_DST_ADDRESS:
943  return clib_error_return (0, "Invalid server address");
944 
945  case VNET_API_ERROR_INVALID_SRC_ADDRESS:
946  return clib_error_return (0, "Invalid src address");
947 
948  case VNET_API_ERROR_NO_SUCH_ENTRY:
949  return clib_error_return
950  (0, "Fib id %d: no per-fib DHCP server configured", rx_table_id);
951 
952  default:
953  return clib_error_return (0, "BUG: rv %d", rv);
954  }
955  }
956  else
957  return clib_error_return (0, "parse error`%U'",
958  format_unformat_error, input);
959 }
960 
961 /* *INDENT-OFF* */
962 VLIB_CLI_COMMAND (dhcp_proxy_set_command, static) = {
963  .path = "set dhcp proxy",
964  .short_help = "set dhcp proxy [del] server <ip-addr> src-address <ip-addr> [server-fib-id <n>] [rx-fib-id <n>]",
965  .function = dhcp4_proxy_set_command_fn,
966 };
967 /* *INDENT-ON* */
968 
969 static u8 *
970 format_dhcp4_proxy_server (u8 * s, va_list * args)
971 {
972  dhcp_proxy_t *proxy = va_arg (*args, dhcp_proxy_t *);
973  ip4_fib_t *rx_fib, *server_fib;
974  dhcp_server_t *server;
975 
976  if (proxy == 0)
977  {
978  s = format (s, "%=14s%=16s%s", "RX FIB", "Src Address",
979  "Servers FIB,Address");
980  return s;
981  }
982 
983  rx_fib = ip4_fib_get (proxy->rx_fib_index);
984 
985  s = format (s, "%=14u%=16U",
986  rx_fib->table_id,
988 
989  vec_foreach (server, proxy->dhcp_servers)
990  {
991  server_fib = ip4_fib_get (server->server_fib_index);
992  s = format (s, "%u,%U ",
993  server_fib->table_id,
995  }
996  return s;
997 }
998 
999 static int
1001 {
1002  vlib_main_t *vm = ctx;
1003 
1004  vlib_cli_output (vm, "%U", format_dhcp4_proxy_server, server);
1005 
1006  return (1);
1007 }
1008 
1009 static clib_error_t *
1011  unformat_input_t * input,
1012  vlib_cli_command_t * cmd)
1013 {
1015  NULL /* header line */ );
1016 
1018 
1019  return (NULL);
1020 }
1021 
1022 /* *INDENT-OFF* */
1023 VLIB_CLI_COMMAND (dhcp_proxy_show_command, static) = {
1024  .path = "show dhcp proxy",
1025  .short_help = "Display dhcp proxy server info",
1026  .function = dhcp4_proxy_show_command_fn,
1027 };
1028 /* *INDENT-ON* */
1029 
1030 static clib_error_t *
1032  unformat_input_t * input, vlib_cli_command_t * cmd)
1033 {
1034  u8 is_del = 0, vss_type = VSS_TYPE_DEFAULT;
1035  u32 oui = 0, fib_id = 0, tbl_id = ~0;
1036  u8 *vpn_ascii_id = 0;
1037 
1038  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1039  {
1040  if (unformat (input, "table %d", &tbl_id))
1041  ;
1042  else if (unformat (input, "oui %d", &oui))
1044  else if (unformat (input, "vpn-id %d", &fib_id))
1046  else if (unformat (input, "vpn-ascii-id %s", &vpn_ascii_id))
1048  else if (unformat (input, "delete") || unformat (input, "del"))
1049  is_del = 1;
1050  else
1051  break;
1052  }
1053 
1054  if (tbl_id == ~0)
1055  return clib_error_return (0, "no table ID specified.");
1056 
1057  int rv = dhcp_proxy_set_vss (FIB_PROTOCOL_IP4, tbl_id, vss_type,
1058  vpn_ascii_id, oui, fib_id, is_del);
1059  switch (rv)
1060  {
1061  case 0:
1062  return 0;
1063  case VNET_API_ERROR_NO_SUCH_ENTRY:
1064  return clib_error_return (0,
1065  "option 82 vss for table %d not found in in pool.",
1066  tbl_id);
1067  default:
1068  return clib_error_return (0, "BUG: rv %d", rv);
1069 
1070  }
1071 }
1072 
1073 /* *INDENT-OFF* */
1074 VLIB_CLI_COMMAND (dhcp_proxy_vss_command,static) = {
1075  .path = "set dhcp option-82 vss",
1076  .short_help = "set dhcp option-82 vss [del] table <table id> [oui <n> vpn-id <n> | vpn-ascii-id <text>]",
1077  .function = dhcp_option_82_vss_fn,
1078 };
1079 /* *INDENT-ON* */
1080 
1081 static clib_error_t *
1083  unformat_input_t * input, vlib_cli_command_t * cmd)
1084 {
1086 
1087  return (NULL);
1088 }
1089 
1090 /* *INDENT-OFF* */
1091 VLIB_CLI_COMMAND (dhcp_proxy_vss_show_command, static) = {
1092  .path = "show dhcp vss",
1093  .short_help = "show dhcp VSS",
1094  .function = dhcp_vss_show_command_fn,
1095 };
1096 /* *INDENT-ON* */
1097 
1098 static clib_error_t *
1100  unformat_input_t * input,
1101  vlib_cli_command_t * cmd)
1102 {
1103  vnet_main_t *vnm = vnet_get_main ();
1104  u32 sw_if_index0 = 0, sw_if_index;
1105  vnet_sw_interface_t *swif;
1106  ip4_address_t *ia0;
1107 
1108  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1109  {
1110 
1111  if (unformat (input, "%U",
1112  unformat_vnet_sw_interface, vnm, &sw_if_index0))
1113  {
1114  swif = vnet_get_sw_interface (vnm, sw_if_index0);
1116  swif->unnumbered_sw_if_index : sw_if_index0;
1118  if (ia0)
1119  {
1120  vlib_cli_output (vm, "%=20s%=20s", "interface",
1121  "source IP address");
1122 
1123  vlib_cli_output (vm, "%=20U%=20U",
1125  vnm, sw_if_index0, format_ip4_address, ia0);
1126  }
1127  else
1128  vlib_cli_output (vm, "%=34s %=20U",
1129  "No IPv4 address configured on",
1131  }
1132  else
1133  break;
1134  }
1135 
1136  return 0;
1137 }
1138 
1139 /* *INDENT-OFF* */
1140 VLIB_CLI_COMMAND (dhcp_proxy_address_show_command,static) = {
1141  .path = "show dhcp option-82-address interface",
1142  .short_help = "show dhcp option-82-address interface <interface>",
1144 };
1145 /* *INDENT-ON* */
1146 
1147 /*
1148  * fd.io coding-style-patch-verification: ON
1149  *
1150  * Local Variables:
1151  * eval: (c-set-style "gnu")
1152  * End:
1153  */
static vlib_node_registration_t dhcp_proxy_to_client_node
(constructor) VLIB_REGISTER_NODE (dhcp_proxy_to_client_node)
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:124
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:255
static u8 * vlib_buffer_get_tail(vlib_buffer_t *b)
Get pointer to the end of buffer&#39;s data.
Definition: buffer.h:310
vss_type
Definition: dhcp.api:22
#define CLIB_UNUSED(x)
Definition: clib.h:86
ip4_address_t src_address
Definition: ip4_packet.h:170
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
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
dhcp_server_t * dhcp_servers
The set of DHCP servers to which messages are relayed.
Definition: dhcp_proxy.h:111
static uword dhcp_proxy_to_client_input(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
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
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
static clib_error_t * dhcp4_proxy_show_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define VPP_DHCP_OPTION82_SIZE
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u32 index
Definition: node.h:282
ip4_address_t * ip4_interface_first_address(ip4_main_t *im, u32 sw_if_index, ip_interface_address_t **result_ia)
Definition: ip4_forward.c:281
ethernet_interface_t * interfaces
Definition: ethernet.h:293
dhcp_proxy_main_t dhcp_proxy_main
Shard 4/6 instance of DHCP main.
Definition: dhcp_proxy.c:25
u8 src_address[6]
Definition: packet.h:56
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
static uword dhcp_proxy_to_server_input(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:113
ip46_address_t dhcp_src_address
The source address to use in relayed messaes.
Definition: dhcp_proxy.h:126
The Virtual Sub-net Selection information for a given RX FIB.
Definition: dhcp_proxy.h:57
u32 rx_fib_index
The FIB index (not the external Table-ID) in which the client is resides.
Definition: dhcp_proxy.h:132
uword ip_csum_t
Definition: ip_packet.h:244
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
Definition: ip4.h:122
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
unformat_function_t unformat_vnet_sw_interface
vlib_node_registration_t error_drop_node
(constructor) VLIB_REGISTER_NODE (error_drop_node)
Definition: drop.c:258
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:65
vlib_error_t * errors
Vector of errors for this node.
Definition: node.h:472
vhost_vring_addr_t addr
Definition: vhost_user.h:254
format_function_t format_vnet_sw_if_index_name
unsigned char u8
Definition: types.h:56
static vlib_buffer_t * vlib_buffer_copy(vlib_main_t *vm, vlib_buffer_t *b)
#define clib_memcpy(d, s, n)
Definition: string.h:180
format_function_t format_ip4_address
Definition: format.h:73
unformat_function_t unformat_ip4_address
Definition: format.h:68
vl_api_interface_index_t sw_if_index
Definition: gre.api:53
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
u32 table_id
Definition: ip4_fib.h:54
void fib_table_entry_special_remove(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source)
Remove a &#39;special&#39; entry from the FIB.
Definition: fib_table.c:424
ip4_address_t dst_address
Definition: ip4_packet.h:170
u8 dst_address[6]
Definition: packet.h:55
static vlib_node_registration_t dhcp_proxy_to_server_node
(constructor) VLIB_REGISTER_NODE (dhcp_proxy_to_server_node)
Aggregate type for a prefix.
Definition: fib_types.h:203
static clib_error_t * dhcp4_proxy_set_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
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:275
#define clib_error_return(e, args...)
Definition: error.h:99
#define VSS_TYPE_ASCII
Definition: dhcp_proxy.h:66
int dhcp_proxy_server_add(fib_protocol_t proto, ip46_address_t *addr, ip46_address_t *src_address, u32 rx_fib_index, u32 server_table_id)
Add a new DHCP proxy server configuration.
Definition: dhcp_proxy.c:184
unsigned int u32
Definition: types.h:88
u16 fp_len
The mask length.
Definition: fib_types.h:207
#define VSS_TYPE_DEFAULT
Definition: dhcp_proxy.h:69
static u32 vlib_get_buffer_index(vlib_main_t *vm, void *p)
Translate buffer pointer into buffer index.
Definition: buffer_funcs.h:293
dhcp4_next_t
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:136
u32 server_fib_index
The FIB index (not the external Table-ID) in which the server is reachable.
Definition: dhcp_proxy.h:95
static u8 * format_dhcp4_proxy_server(u8 *s, va_list *args)
static u32 vlib_buffer_chain_linearize(vlib_main_t *vm, vlib_buffer_t *b)
Definition: fib_entry.h:117
dhcp_port_reg_flags_t
Definition: dhcp_proxy.h:48
Collection of global DHCP proxy data.
Definition: dhcp_proxy.h:140
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
vnet_sub_interface_t sub
Definition: interface.h:744
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
static u8 ip46_address_is_zero(const ip46_address_t *ip46)
Definition: ip46_address.h:87
long ctx[MAX_CONNS]
Definition: main.c:144
u8 * format_dhcp_header(u8 *s, va_list *args)
Definition: dhcp4_packet.c:48
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
dhcp_proxy_to_server_input_next_t
vec_header_t h
Definition: buffer.c:322
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:229
#define PREDICT_FALSE(x)
Definition: clib.h:118
vnet_sw_interface_flags_t flags
Definition: interface.h:724
vlib_main_t * vlib_main
Definition: dhcp_proxy.h:160
vl_api_address_union_t src_address
Definition: ip_types.api:99
static char * dhcp_proxy_error_strings[]
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
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:224
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:338
void fib_table_unlock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Take a reference counting lock on the table.
Definition: fib_table.c:1291
vlib_main_t * vm
Definition: in2out_ed.c:1599
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1150
u8 len
Definition: ip_types.api:92
format_function_t format_ip46_address
Definition: ip46_address.h:50
static clib_error_t * dhcp4_proxy_init(vlib_main_t *vm)
fib_node_index_t fib_table_entry_special_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags)
Add a &#39;special&#39; entry to the FIB.
Definition: fib_table.c:405
The IPv4 FIB.
Definition: ip4_fib.h:39
dhcp_option_t options[0]
Definition: dhcp4_packet.h:51
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
u8 * vpn_ascii_id
Type 0 ASCII VPN Identifier.
Definition: dhcp_proxy.h:77
u16 n_vectors
Definition: node.h:399
static clib_error_t * dhcp_option_82_address_show_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static ip4_fib_t * ip4_fib_get(u32 index)
Get the FIB at the given index.
Definition: ip4_fib.h:113
A representation of a single DHCP Server within a given VRF config.
Definition: dhcp_proxy.h:83
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:483
static u32 vlib_buffer_space_left_at_end(vlib_main_t *vm, vlib_buffer_t *b)
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1599
void fib_table_lock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Release a reference counting lock on the table.
Definition: fib_table.c:1310
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:152
int dhcp_client_for_us(u32 bi, vlib_buffer_t *b, ip4_header_t *ip, udp_header_t *udp, dhcp_header_t *dhcp)
Definition: client.c:274
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)
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:517
ip46_address_t dhcp_server
The address of the DHCP server to which to relay the client&#39;s messages.
Definition: dhcp_proxy.h:89
static u8 * format_dhcp_proxy_trace(u8 *s, va_list *args)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:689
#define foreach_dhcp_proxy_to_server_input_next
ip4_address_t gateway_ip_address
Definition: dhcp4_packet.h:46
static clib_error_t * dhcp_option_82_vss_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
IPv4 main type.
Definition: ip4.h:106
u32 fib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id, fib_source_t src)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1156
struct vnet_sub_interface_t::@327::@328::@330 flags
u8 packet_data[2 *sizeof(dhcp_header_t)]
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:248
static clib_error_t * dhcp_vss_show_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
ip4_address_t trace_ip4_address
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
struct _vlib_node_registration vlib_node_registration_t
A DHCP proxy representation fpr per-client VRF config.
Definition: dhcp_proxy.h:101
Definition: defs.h:47
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
#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:73
#define VLIB_BUFFER_TRACE_TRAJECTORY_INIT(b)
Definition: buffer.h:492
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:244
#define ip_csum_update(sum, old, new, type, field)
Definition: ip_packet.h:294
void dhcp_maybe_register_udp_ports(dhcp_port_reg_flags_t ports)
Register the dhcp client and/or server ports, if not already done.
#define VSS_TYPE_VPN_ID
Definition: dhcp_proxy.h:67
static u8 * format_dhcp_proxy_header_with_length(u8 *s, va_list *args)
static ethernet_main_t * vnet_get_ethernet_main(void)
Definition: ethernet.h:571
#define vnet_buffer(b)
Definition: buffer.h:417
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
vnet_sw_interface_type_t type
Definition: interface.h:722
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1144
#define vec_foreach(var, vec)
Vector iterator.
f64 end
end of the time range
Definition: mactime.api:44
void udp_register_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u32 node_index, u8 is_ip4)
Definition: udp_local.c:468
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
static int dhcp4_proxy_show_walk(dhcp_proxy_t *server, void *ctx)
static u16 ip_csum_fold(ip_csum_t c)
Definition: ip_packet.h:300
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
struct vnet_sub_interface_t::@327 eth
Definition: defs.h:46
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171