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