FD.io VPP  v20.09-64-g4f7b92f0a
Vector Packet Processing
dhcp6_proxy_node.c
Go to the documentation of this file.
1 /*
2  * dhcp6_proxy_node.c: dhcpv6 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/dhcp6_packet.h>
22 #include <vnet/mfib/mfib_table.h>
23 #include <vnet/mfib/ip6_mfib.h>
24 #include <vnet/fib/fib.h>
25 
26 static char *dhcpv6_proxy_error_strings[] = {
27 #define dhcpv6_proxy_error(n,s) s,
29 #undef dhcpv6_proxy_error
30 };
31 
32 #define foreach_dhcpv6_proxy_to_server_input_next \
33  _ (DROP, "error-drop") \
34  _ (LOOKUP, "ip6-lookup") \
35  _ (SEND_TO_CLIENT, "dhcpv6-proxy-to-client")
36 
37 
38 typedef enum
39 {
40 #define _(s,n) DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_##s,
42 #undef _
45 
46 typedef struct
47 {
48  /* 0 => to server, 1 => to client */
49  int which;
50  u8 packet_data[64];
55 
58 
59 /* all DHCP servers address */
60 static ip6_address_t all_dhcpv6_server_address;
62 
63 static u8 *
64 format_dhcpv6_proxy_trace (u8 * s, va_list * args)
65 {
66  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
67  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
68  dhcpv6_proxy_trace_t *t = va_arg (*args, dhcpv6_proxy_trace_t *);
69 
70  if (t->which == 0)
71  s = format (s, "DHCPV6 proxy: sent to server %U",
72  format_ip6_address, &t->packet_data, sizeof (ip6_address_t));
73  else
74  s = format (s, "DHCPV6 proxy: sent to client from %U",
75  format_ip6_address, &t->packet_data, sizeof (ip6_address_t));
76  if (t->error != (u32) ~ 0)
77  s = format (s, " error: %s\n", dhcpv6_proxy_error_strings[t->error]);
78 
79  s = format (s, " original_sw_if_index: %d, sw_if_index: %d\n",
81 
82  return s;
83 }
84 
85 static u8 *
87 {
88  dhcpv6_header_t *h = va_arg (*args, dhcpv6_header_t *);
89  u32 max_header_bytes = va_arg (*args, u32);
90  u32 header_bytes;
91 
92  header_bytes = sizeof (h[0]);
93  if (max_header_bytes != 0 && header_bytes > max_header_bytes)
94  return format (s, "dhcpv6 header truncated");
95 
96  s = format (s, "DHCPV6 Proxy");
97 
98  return s;
99 }
100 
101 /* get first interface address */
102 static ip6_address_t *
104 {
105  ip_lookup_main_t *lm = &im->lookup_main;
106  ip_interface_address_t *ia = 0;
107  ip6_address_t *result = 0;
108 
109  /* *INDENT-OFF* */
110  foreach_ip_interface_address (lm, ia, sw_if_index,
111  1 /* honor unnumbered */,
112  ({
113  ip6_address_t * a = ip_interface_address_get_address (lm, ia);
114  if ((a->as_u8[0] & 0xe0) == 0x20 ||
115  (a->as_u8[0] & 0xfe) == 0xfc) {
116  result = a;
117  break;
118  }
119  }));
120  /* *INDENT-ON* */
121  return result;
122 }
123 
124 static inline void
125 copy_ip6_address (ip6_address_t * dst, ip6_address_t * src)
126 {
127  dst->as_u64[0] = src->as_u64[0];
128  dst->as_u64[1] = src->as_u64[1];
129 }
130 
131 static uword
134  vlib_frame_t * from_frame)
135 {
136  u32 n_left_from, next_index, *from, *to_next;
138  from = vlib_frame_vector_args (from_frame);
139  n_left_from = from_frame->n_vectors;
140  u32 pkts_to_server = 0, pkts_to_client = 0, pkts_no_server = 0;
141  u32 pkts_no_interface_address = 0, pkts_no_exceeding_max_hop = 0;
142  u32 pkts_no_src_address = 0;
143  u32 pkts_wrong_msg_type = 0;
144  u32 pkts_too_big = 0;
145  ip6_main_t *im = &ip6_main;
146  ip6_address_t *src;
147  int bogus_length;
148  dhcp_proxy_t *proxy;
149  dhcp_server_t *server;
150  u32 rx_fib_idx = 0, server_fib_idx = 0;
151 
152  next_index = node->cached_next_index;
153 
154  while (n_left_from > 0)
155  {
156  u32 n_left_to_next;
157 
158  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
159 
160  while (n_left_from > 0 && n_left_to_next > 0)
161  {
162  vnet_main_t *vnm = vnet_get_main ();
163  u32 sw_if_index = 0;
164  u32 rx_sw_if_index = 0;
165  vnet_sw_interface_t *swif;
166  u32 bi0;
167  vlib_buffer_t *b0;
168  udp_header_t *u0, *u1;
169  dhcpv6_header_t *h0; // client msg hdr
170  ip6_header_t *ip0, *ip1;
171  ip6_address_t _ia0, *ia0 = &_ia0;
172  u32 next0;
173  u32 error0 = (u32) ~ 0;
174  dhcpv6_option_t *fwd_opt;
175  dhcpv6_relay_hdr_t *r1;
176  u16 len;
177  dhcpv6_int_id_t *id1;
178  dhcpv6_vss_t *vss1;
179  dhcpv6_client_mac_t *cmac; // client mac
180  ethernet_header_t *e_h0;
181  u8 client_src_mac[6];
182  dhcp_vss_t *vss;
183  u8 is_solicit = 0;
184 
185  bi0 = from[0];
186  from += 1;
187  n_left_from -= 1;
188 
189  b0 = vlib_get_buffer (vm, bi0);
190 
191  h0 = vlib_buffer_get_current (b0);
192 
193  /*
194  * udp_local hands us the DHCPV6 header.
195  */
196  u0 = (void *) h0 - (sizeof (*u0));
197  ip0 = (void *) u0 - (sizeof (*ip0));
198  e_h0 = (void *) ip0 - ethernet_buffer_header_size (b0);
199 
200  clib_memcpy (client_src_mac, e_h0->src_address, 6);
201 
202  switch (h0->msg_type)
203  {
204  case DHCPV6_MSG_SOLICIT:
205  case DHCPV6_MSG_REQUEST:
206  case DHCPV6_MSG_CONFIRM:
207  case DHCPV6_MSG_RENEW:
208  case DHCPV6_MSG_REBIND:
209  case DHCPV6_MSG_RELEASE:
210  case DHCPV6_MSG_DECLINE:
213  /* send to server */
214  break;
216  /* send to client */
217  next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_SEND_TO_CLIENT;
218  error0 = 0;
219  pkts_to_client++;
220  goto do_enqueue;
221  default:
222  /* drop the packet */
223  pkts_wrong_msg_type++;
224  error0 = DHCPV6_PROXY_ERROR_WRONG_MESSAGE_TYPE;
225  next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
226  goto do_trace;
227 
228  }
229 
230  /* Send to DHCPV6 server via the configured FIB */
231  rx_sw_if_index = sw_if_index =
232  vnet_buffer (b0)->sw_if_index[VLIB_RX];
233  rx_fib_idx = im->mfib_index_by_sw_if_index[rx_sw_if_index];
234  proxy = dhcp_get_proxy (dpm, rx_fib_idx, FIB_PROTOCOL_IP6);
235 
236  if (PREDICT_FALSE (NULL == proxy))
237  {
238  error0 = DHCPV6_PROXY_ERROR_NO_SERVER;
239  next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
240  pkts_no_server++;
241  goto do_trace;
242  }
243 
244  server = &proxy->dhcp_servers[0];
245  server_fib_idx = server->server_fib_index;
246  vnet_buffer (b0)->sw_if_index[VLIB_TX] = server_fib_idx;
247 
248 
249  /* relay-option header pointer */
250  vlib_buffer_advance (b0, -(sizeof (*fwd_opt)));
251  fwd_opt = vlib_buffer_get_current (b0);
252  /* relay message header pointer */
253  vlib_buffer_advance (b0, -(sizeof (*r1)));
254  r1 = vlib_buffer_get_current (b0);
255 
256  vlib_buffer_advance (b0, -(sizeof (*u1)));
257  u1 = vlib_buffer_get_current (b0);
258 
259  vlib_buffer_advance (b0, -(sizeof (*ip1)));
260  ip1 = vlib_buffer_get_current (b0);
261 
262  /* fill in all that rubbish... */
263  len = clib_net_to_host_u16 (u0->length) - sizeof (udp_header_t);
264  copy_ip6_address (&r1->peer_addr, &ip0->src_address);
265 
266  r1->msg_type = DHCPV6_MSG_RELAY_FORW;
267  fwd_opt->length = clib_host_to_net_u16 (len);
268  fwd_opt->option = clib_host_to_net_u16 (DHCPV6_OPTION_RELAY_MSG);
269 
270  r1->hop_count++;
271  r1->hop_count =
272  (h0->msg_type != DHCPV6_MSG_RELAY_FORW) ? 0 : r1->hop_count;
273 
274  if (PREDICT_FALSE (r1->hop_count >= HOP_COUNT_LIMIT))
275  {
277  next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
278  pkts_no_exceeding_max_hop++;
279  goto do_trace;
280  }
281 
282 
283  /* If relay-fwd and src address is site or global unicast address */
284  if (h0->msg_type == DHCPV6_MSG_RELAY_FORW &&
285  ((ip0->src_address.as_u8[0] & 0xe0) == 0x20 ||
286  (ip0->src_address.as_u8[0] & 0xfe) == 0xfc))
287  {
288  /* Set link address to zero */
289  r1->link_addr.as_u64[0] = 0;
290  r1->link_addr.as_u64[1] = 0;
291  goto link_address_set;
292  }
293 
294  /* if receiving interface is unnumbered, use receiving interface
295  * IP address as link address, otherwise use the loopback interface
296  * IP address as link address.
297  */
298 
299  swif = vnet_get_sw_interface (vnm, rx_sw_if_index);
301  sw_if_index = swif->unnumbered_sw_if_index;
302 
303  ia0 =
305  sw_if_index);
306  if (ia0 == 0)
307  {
308  error0 = DHCPV6_PROXY_ERROR_NO_INTERFACE_ADDRESS;
309  next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
310  pkts_no_interface_address++;
311  goto do_trace;
312  }
313 
314  copy_ip6_address (&r1->link_addr, ia0);
315 
316  link_address_set:
317 
318  if ((b0->current_data + b0->current_length + sizeof (*id1) +
319  sizeof (*vss1) + sizeof (*cmac)) >
321  {
322  error0 = DHCPV6_PROXY_ERROR_PKT_TOO_BIG;
323  next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
324  pkts_too_big++;
325  goto do_trace;
326  }
327 
328  id1 = (dhcpv6_int_id_t *) (((uword) ip1) + b0->current_length);
329  b0->current_length += (sizeof (*id1));
330 
331  id1->opt.option = clib_host_to_net_u16 (DHCPV6_OPTION_INTERFACE_ID);
332  id1->opt.length = clib_host_to_net_u16 (sizeof (rx_sw_if_index));
333  id1->int_idx = clib_host_to_net_u32 (rx_sw_if_index);
334 
335  u1->length = 0;
336  if (h0->msg_type != DHCPV6_MSG_RELAY_FORW)
337  {
338  cmac =
339  (dhcpv6_client_mac_t *) (((uword) ip1) + b0->current_length);
340  b0->current_length += (sizeof (*cmac));
341  cmac->opt.length = clib_host_to_net_u16 (sizeof (*cmac) -
342  sizeof (cmac->opt));
343  cmac->opt.option =
344  clib_host_to_net_u16
345  (DHCPV6_OPTION_CLIENT_LINK_LAYER_ADDRESS);
346  cmac->link_type = clib_host_to_net_u16 (1); /* ethernet */
347  clib_memcpy (cmac->data, client_src_mac, 6);
348  u1->length += sizeof (*cmac);
349  }
350 
351  vss = dhcp_get_vss_info (dpm, rx_fib_idx, FIB_PROTOCOL_IP6);
352 
353  if (vss)
354  {
355  u16 id_len; /* length of VPN ID */
356  u16 type_len = sizeof (vss1->vss_type);
357 
358  vss1 = (dhcpv6_vss_t *) (((uword) ip1) + b0->current_length);
359  vss1->vss_type = vss->vss_type;
360  if (vss->vss_type == VSS_TYPE_VPN_ID)
361  {
362  id_len = sizeof (vss->vpn_id); /* vpn_id is 7 bytes */
363  memcpy (vss1->data, vss->vpn_id, id_len);
364  }
365  else if (vss->vss_type == VSS_TYPE_ASCII)
366  {
367  id_len = vec_len (vss->vpn_ascii_id);
368  memcpy (vss1->data, vss->vpn_ascii_id, id_len);
369  }
370  else /* must be VSS_TYPE_DEFAULT, no VPN ID */
371  id_len = 0;
372 
373  vss1->opt.option = clib_host_to_net_u16 (DHCPV6_OPTION_VSS);
374  vss1->opt.length = clib_host_to_net_u16 (type_len + id_len);
375  u1->length += type_len + id_len + sizeof (vss1->opt);
376  b0->current_length += type_len + id_len + sizeof (vss1->opt);
377  }
378 
379  pkts_to_server++;
380  u1->checksum = 0;
381  u1->src_port = clib_host_to_net_u16 (UDP_DST_PORT_dhcpv6_to_client);
382  u1->dst_port = clib_host_to_net_u16 (UDP_DST_PORT_dhcpv6_to_server);
383 
384  u1->length =
385  clib_host_to_net_u16 (clib_net_to_host_u16 (fwd_opt->length) +
386  sizeof (*r1) + sizeof (*fwd_opt) +
387  sizeof (*u1) + sizeof (*id1) + u1->length);
388 
389  clib_memset (ip1, 0, sizeof (*ip1));
390  ip1->ip_version_traffic_class_and_flow_label = 0x60;
391  ip1->payload_length = u1->length;
392  ip1->protocol = PROTO_UDP;
393  ip1->hop_limit = HOP_COUNT_LIMIT;
394  src = ((server->dhcp_server.ip6.as_u64[0] ||
395  server->dhcp_server.ip6.as_u64[1]) ?
396  &server->dhcp_server.ip6 : &all_dhcpv6_server_address);
397  copy_ip6_address (&ip1->dst_address, src);
398 
399 
401  (&ip6_main, vnet_buffer (b0)->sw_if_index[VLIB_RX]);
402 
403  src = (proxy->dhcp_src_address.ip6.as_u64[0] ||
404  proxy->dhcp_src_address.ip6.as_u64[1]) ?
405  &proxy->dhcp_src_address.ip6 : ia0;
406  if (ia0 == 0)
407  {
408  error0 = DHCPV6_PROXY_ERROR_NO_SRC_ADDRESS;
409  next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
410  pkts_no_src_address++;
411  goto do_trace;
412  }
413 
414  copy_ip6_address (&ip1->src_address, src);
415 
416 
417  u1->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip1,
418  &bogus_length);
419  ASSERT (bogus_length == 0);
420 
421  next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP;
422 
423  is_solicit = (DHCPV6_MSG_SOLICIT == h0->msg_type);
424 
425  /*
426  * If we have multiple servers configured and this is the
427  * client's discover message, then send copies to each of
428  * those servers
429  */
430  if (is_solicit && vec_len (proxy->dhcp_servers) > 1)
431  {
432  u32 ii;
433 
434  for (ii = 1; ii < vec_len (proxy->dhcp_servers); ii++)
435  {
436  vlib_buffer_t *c0;
437  u32 ci0;
438 
439  c0 = vlib_buffer_copy (vm, b0);
440  if (c0 == NULL)
441  {
443  (vm, dhcpv6_proxy_to_server_node.index,
444  DHCPV6_PROXY_ERROR_ALLOC_FAIL, 1);
445  continue;
446  }
448  ci0 = vlib_get_buffer_index (vm, c0);
449  server = &proxy->dhcp_servers[ii];
450 
451  ip0 = vlib_buffer_get_current (c0);
452 
453  src = ((server->dhcp_server.ip6.as_u64[0] ||
454  server->dhcp_server.ip6.as_u64[1]) ?
455  &server->dhcp_server.ip6 :
457  copy_ip6_address (&ip1->dst_address, src);
458 
459  to_next[0] = ci0;
460  to_next += 1;
461  n_left_to_next -= 1;
462 
463  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
464  to_next, n_left_to_next,
465  ci0, next0);
466 
467  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
468  {
470 
471  tr = vlib_add_trace (vm, node, c0, sizeof (*tr));
472  tr->which = 0; /* to server */
473  tr->error = error0;
474  tr->original_sw_if_index = rx_sw_if_index;
475  tr->sw_if_index = sw_if_index;
476  if (next0 == DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP)
477  copy_ip6_address ((ip6_address_t *) &
478  tr->packet_data[0],
479  &server->dhcp_server.ip6);
480  }
481 
482  if (PREDICT_FALSE (0 == n_left_to_next))
483  {
484  vlib_put_next_frame (vm, node, next_index,
485  n_left_to_next);
486  vlib_get_next_frame (vm, node, next_index,
487  to_next, n_left_to_next);
488  }
489  }
490  }
491 
492  do_trace:
493  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
494  {
495  dhcpv6_proxy_trace_t *tr = vlib_add_trace (vm, node,
496  b0, sizeof (*tr));
497  tr->which = 0; /* to server */
498  tr->error = error0;
499  tr->original_sw_if_index = rx_sw_if_index;
500  tr->sw_if_index = sw_if_index;
501  if (DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP == next0)
502  copy_ip6_address ((ip6_address_t *) & tr->packet_data[0],
503  &server->dhcp_server.ip6);
504  }
505 
506  do_enqueue:
507  to_next[0] = bi0;
508  to_next += 1;
509  n_left_to_next -= 1;
510 
511  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
512  to_next, n_left_to_next,
513  bi0, next0);
514  }
515 
516  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
517  }
518 
520  DHCPV6_PROXY_ERROR_RELAY_TO_CLIENT,
521  pkts_to_client);
523  DHCPV6_PROXY_ERROR_RELAY_TO_SERVER,
524  pkts_to_server);
526  DHCPV6_PROXY_ERROR_NO_INTERFACE_ADDRESS,
527  pkts_no_interface_address);
529  DHCPV6_PROXY_ERROR_WRONG_MESSAGE_TYPE,
530  pkts_wrong_msg_type);
532  DHCPV6_PROXY_ERROR_NO_SRC_ADDRESS,
533  pkts_no_src_address);
535  DHCPV6_PROXY_ERROR_PKT_TOO_BIG, pkts_too_big);
536  return from_frame->n_vectors;
537 }
538 
539 /* *INDENT-OFF* */
541  .function = dhcpv6_proxy_to_server_input,
542  .name = "dhcpv6-proxy-to-server",
543  /* Takes a vector of packets. */
544  .vector_size = sizeof (u32),
545 
546  .n_errors = DHCPV6_PROXY_N_ERROR,
547  .error_strings = dhcpv6_proxy_error_strings,
548 
549  .n_next_nodes = DHCPV6_PROXY_TO_SERVER_INPUT_N_NEXT,
550  .next_nodes = {
551 #define _(s,n) [DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_##s] = n,
553 #undef _
554  },
555 
557  .format_trace = format_dhcpv6_proxy_trace,
558 #if 0
559  .unformat_buffer = unformat_dhcpv6_proxy_header,
560 #endif
561 };
562 /* *INDENT-ON* */
563 
564 static uword
567  vlib_frame_t * from_frame)
568 {
569 
570  u32 n_left_from, *from;
573  dhcp_proxy_t *proxy;
574  dhcp_server_t *server;
575  vnet_main_t *vnm = vnet_get_main ();
576  int bogus_length;
577 
578  from = vlib_frame_vector_args (from_frame);
579  n_left_from = from_frame->n_vectors;
580 
581  while (n_left_from > 0)
582  {
583  u32 bi0;
584  vlib_buffer_t *b0;
585  udp_header_t *u0, *u1 = 0;
586  dhcpv6_relay_hdr_t *h0;
587  ip6_header_t *ip1 = 0, *ip0;
588  ip6_address_t _ia0, *ia0 = &_ia0;
589  ip6_address_t client_address;
591  ethernet_header_t *mac0;
592  vnet_hw_interface_t *hi0;
593  vlib_frame_t *f0;
594  u32 *to_next0;
595  u32 sw_if_index = ~0;
596  u32 original_sw_if_index = ~0;
597  vnet_sw_interface_t *si0;
598  u32 inner_vlan = (u32) ~ 0;
599  u32 outer_vlan = (u32) ~ 0;
600  u32 error0 = (u32) ~ 0;
601  vnet_sw_interface_t *swif;
602  dhcpv6_option_t *r0 = 0, *o;
603  u16 len = 0;
604  u8 interface_opt_flag = 0;
605  u8 relay_msg_opt_flag = 0;
606  ip6_main_t *im = &ip6_main;
607  u32 server_fib_idx, client_fib_idx;
608 
609  bi0 = from[0];
610  from += 1;
611  n_left_from -= 1;
612 
613  b0 = vlib_get_buffer (vm, bi0);
614  h0 = vlib_buffer_get_current (b0);
615 
616  if (DHCPV6_MSG_RELAY_REPL != h0->msg_type)
617  {
618  error0 = DHCPV6_PROXY_ERROR_WRONG_MESSAGE_TYPE;
619 
620  drop_packet:
622  error0, 1);
623 
625  to_next0 = vlib_frame_vector_args (f0);
626  to_next0[0] = bi0;
627  f0->n_vectors = 1;
629  goto do_trace;
630  }
631  /* hop count seems not need to be checked */
632  if (HOP_COUNT_LIMIT < h0->hop_count)
633  {
635  goto drop_packet;
636  }
637  u0 = (void *) h0 - (sizeof (*u0));
638  ip0 = (void *) u0 - (sizeof (*ip0));
639 
640  vlib_buffer_advance (b0, sizeof (*h0));
641  o = vlib_buffer_get_current (b0);
642 
643  /* Parse through TLVs looking for option 18 (DHCPV6_OPTION_INTERFACE_ID)
644  _and_ option 9 (DHCPV6_OPTION_RELAY_MSG) option which must be there.
645  Currently assuming no other options need to be processed
646  The interface-ID is the FIB number we need
647  to track down the client-facing interface */
648 
649  while ((u8 *) o < (b0->data + b0->current_data + b0->current_length))
650  {
651  if (DHCPV6_OPTION_INTERFACE_ID == clib_net_to_host_u16 (o->option))
652  {
653  interface_opt_flag = 1;
654  if (clib_net_to_host_u16 (o->length) == sizeof (sw_if_index))
655  sw_if_index =
656  clib_net_to_host_u32 (((dhcpv6_int_id_t *) o)->int_idx);
657  if (sw_if_index >= vec_len (im->fib_index_by_sw_if_index))
658  {
659  error0 = DHCPV6_PROXY_ERROR_WRONG_INTERFACE_ID_OPTION;
660  goto drop_packet;
661  }
662  }
663  if (DHCPV6_OPTION_RELAY_MSG == clib_net_to_host_u16 (o->option))
664  {
665  relay_msg_opt_flag = 1;
666  r0 = vlib_buffer_get_current (b0);
667  }
668  if ((relay_msg_opt_flag == 1) && (interface_opt_flag == 1))
669  break;
671  sizeof (*o) +
672  clib_net_to_host_u16 (o->length));
673  o =
674  (dhcpv6_option_t *) (((uword) o) +
675  clib_net_to_host_u16 (o->length) +
676  sizeof (*o));
677  }
678 
679  if ((relay_msg_opt_flag == 0) || (r0 == 0))
680  {
681  error0 = DHCPV6_PROXY_ERROR_NO_RELAY_MESSAGE_OPTION;
682  goto drop_packet;
683  }
684 
685  if ((u32) ~ 0 == sw_if_index)
686  {
687  error0 = DHCPV6_PROXY_ERROR_NO_CIRCUIT_ID_OPTION;
688  goto drop_packet;
689  }
690 
691  //Advance buffer to start of encapsulated DHCPv6 message
692  vlib_buffer_advance (b0, sizeof (*r0));
693 
694  client_fib_idx = im->mfib_index_by_sw_if_index[sw_if_index];
695  proxy = dhcp_get_proxy (dm, client_fib_idx, FIB_PROTOCOL_IP6);
696 
697  if (NULL == proxy)
698  {
699  error0 = DHCPV6_PROXY_ERROR_NO_SERVER;
700  goto drop_packet;
701  }
702 
703  server_fib_idx = im->fib_index_by_sw_if_index
704  [vnet_buffer (b0)->sw_if_index[VLIB_RX]];
705 
706  vec_foreach (server, proxy->dhcp_servers)
707  {
708  if (server_fib_idx == server->server_fib_index &&
709  ip0->src_address.as_u64[0] == server->dhcp_server.ip6.as_u64[0] &&
710  ip0->src_address.as_u64[1] == server->dhcp_server.ip6.as_u64[1])
711  {
712  goto server_found;
713  }
714  }
715 
716  //drop packet if not from server with configured address or FIB
717  error0 = DHCPV6_PROXY_ERROR_BAD_SVR_FIB_OR_ADDRESS;
718  goto drop_packet;
719 
720  server_found:
721  vnet_buffer (b0)->sw_if_index[VLIB_TX] = original_sw_if_index
722  = sw_if_index;
723 
724  swif = vnet_get_sw_interface (vnm, original_sw_if_index);
726  sw_if_index = swif->unnumbered_sw_if_index;
727 
728 
729  /*
730  * udp_local hands us the DHCPV6 header, need udp hdr,
731  * ip hdr to relay to client
732  */
733  vlib_buffer_advance (b0, -(sizeof (*u1)));
734  u1 = vlib_buffer_get_current (b0);
735 
736  vlib_buffer_advance (b0, -(sizeof (*ip1)));
737  ip1 = vlib_buffer_get_current (b0);
738 
739  copy_ip6_address (&client_address, &h0->peer_addr);
740 
741  ia0 = ip6_interface_first_address (&ip6_main, sw_if_index);
742  if (ia0 == 0)
743  {
744  error0 = DHCPV6_PROXY_ERROR_NO_INTERFACE_ADDRESS;
745  goto drop_packet;
746  }
747 
748  len = clib_net_to_host_u16 (r0->length);
749  clib_memset (ip1, 0, sizeof (*ip1));
750  copy_ip6_address (&ip1->dst_address, &client_address);
751  u1->checksum = 0;
752  u1->src_port = clib_net_to_host_u16 (UDP_DST_PORT_dhcpv6_to_server);
753  u1->dst_port = clib_net_to_host_u16 (UDP_DST_PORT_dhcpv6_to_client);
754  u1->length = clib_host_to_net_u16 (len + sizeof (udp_header_t));
755 
757  ip0->ip_version_traffic_class_and_flow_label & 0x00000fff;
758  ip1->payload_length = u1->length;
759  ip1->protocol = PROTO_UDP;
760  ip1->hop_limit = HOP_COUNT_LIMIT;
761  copy_ip6_address (&ip1->src_address, ia0);
762 
763  u1->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip1,
764  &bogus_length);
765  ASSERT (bogus_length == 0);
766 
767  vlib_buffer_advance (b0, -(sizeof (ethernet_header_t)));
768  si0 = vnet_get_sw_interface (vnm, original_sw_if_index);
769  if (si0->type == VNET_SW_INTERFACE_TYPE_SUB)
770  {
771  if (si0->sub.eth.flags.one_tag == 1)
772  {
773  vlib_buffer_advance (b0, -4 /* space for 1 VLAN tag */ );
774  outer_vlan = (si0->sub.eth.outer_vlan_id << 16) | 0x86dd;
775  }
776  else if (si0->sub.eth.flags.two_tags == 1)
777  {
778  vlib_buffer_advance (b0, -8 /* space for 2 VLAN tag */ );
779  outer_vlan = (si0->sub.eth.outer_vlan_id << 16) | 0x8100;
780  inner_vlan = (si0->sub.eth.inner_vlan_id << 16) | 0x86dd;
781  }
782  }
783 
784  mac0 = vlib_buffer_get_current (b0);
785 
786  hi0 = vnet_get_sup_hw_interface (vnm, original_sw_if_index);
787  ei0 = pool_elt_at_index (em->interfaces, hi0->hw_instance);
788  clib_memcpy (mac0->src_address, ei0->address, sizeof (ei0->address));
789  clib_memset (&mac0->dst_address, 0xff, sizeof (mac0->dst_address));
790 
791  if (si0->type == VNET_SW_INTERFACE_TYPE_SUB && outer_vlan != (u32) ~ 0)
792  {
793  mac0->type = (si0->sub.eth.flags.dot1ad == 1) ?
794  clib_net_to_host_u16 (0x88a8) : clib_net_to_host_u16 (0x8100);
795  u32 *vlan_tag = (u32 *) (mac0 + 1);
796  *vlan_tag = clib_host_to_net_u32 (outer_vlan);
797  if (inner_vlan != (u32) ~ 0)
798  {
799  u32 *inner_vlan_tag = (u32 *) (vlan_tag + 1);
800  *inner_vlan_tag = clib_host_to_net_u32 (inner_vlan);
801  }
802  }
803  else
804  {
805  mac0->type = clib_net_to_host_u16 (0x86dd);
806  }
807 
808  /* $$$ consider adding a dynamic next to the graph node, for performance */
810  to_next0 = vlib_frame_vector_args (f0);
811  to_next0[0] = bi0;
812  f0->n_vectors = 1;
814 
815  do_trace:
816  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
817  {
818  dhcpv6_proxy_trace_t *tr = vlib_add_trace (vm, node,
819  b0, sizeof (*tr));
820  tr->which = 1; /* to client */
821  if (ia0)
822  copy_ip6_address ((ip6_address_t *) tr->packet_data, ia0);
823  tr->error = error0;
824  tr->original_sw_if_index = original_sw_if_index;
825  tr->sw_if_index = sw_if_index;
826  }
827  }
828  return from_frame->n_vectors;
829 
830 }
831 
832 /* *INDENT-OFF* */
834  .function = dhcpv6_proxy_to_client_input,
835  .name = "dhcpv6-proxy-to-client",
836  /* Takes a vector of packets. */
837  .vector_size = sizeof (u32),
838 
839  .n_errors = DHCPV6_PROXY_N_ERROR,
840  .error_strings = dhcpv6_proxy_error_strings,
842  .format_trace = format_dhcpv6_proxy_trace,
843 #if 0
844  .unformat_buffer = unformat_dhcpv6_proxy_header,
845 #endif
846 };
847 /* *INDENT-ON* */
848 
849 static clib_error_t *
851 {
854 
855  error_drop_node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
856  dm->error_drop_node_index = error_drop_node->index;
857 
858  /* RFC says this is the dhcpv6 server address */
859  all_dhcpv6_server_address.as_u64[0] =
860  clib_host_to_net_u64 (0xFF05000000000000);
861  all_dhcpv6_server_address.as_u64[1] = clib_host_to_net_u64 (0x00010003);
862 
863  /* RFC says this is the server and agent address */
865  clib_host_to_net_u64 (0xFF02000000000000);
867  clib_host_to_net_u64 (0x00010002);
868 
869  return 0;
870 }
871 
873 
874 int
875 dhcp6_proxy_set_server (ip46_address_t * addr,
876  ip46_address_t * src_addr,
877  u32 rx_table_id, u32 server_table_id, int is_del)
878 {
880  u32 rx_fib_index = 0;
881  int rc = 0;
882 
883  const mfib_prefix_t all_dhcp_servers = {
884  .fp_len = 128,
885  .fp_proto = FIB_PROTOCOL_IP6,
886  .fp_grp_addr = {
888  }
889  };
890 
891  if (ip46_address_is_zero (addr))
892  return VNET_API_ERROR_INVALID_DST_ADDRESS;
893 
894  if (ip46_address_is_zero (src_addr))
895  return VNET_API_ERROR_INVALID_SRC_ADDRESS;
896 
898  rx_table_id,
900 
901  if (is_del)
902  {
903  if (dhcp_proxy_server_del (FIB_PROTOCOL_IP6, rx_fib_index,
904  addr, server_table_id))
905  {
906  mfib_table_entry_delete (rx_fib_index,
907  &all_dhcp_servers, MFIB_SOURCE_DHCP);
908  mfib_table_unlock (rx_fib_index, FIB_PROTOCOL_IP6,
910 
911  udp_unregister_dst_port (vm, UDP_DST_PORT_dhcpv6_to_client,
912  0 /* is_ip6 */ );
913  udp_unregister_dst_port (vm, UDP_DST_PORT_dhcpv6_to_server,
914  0 /* is_ip6 */ );
915  }
916  }
917  else
918  {
919  const fib_route_path_t path_for_us = {
921  .frp_addr = zero_addr,
922  .frp_sw_if_index = 0xffffffff,
923  .frp_fib_index = ~0,
924  .frp_weight = 1,
925  .frp_flags = FIB_ROUTE_PATH_LOCAL,
926  .frp_mitf_flags = MFIB_ITF_FLAG_FORWARD,
927  };
928  if (dhcp_proxy_server_add (FIB_PROTOCOL_IP6, addr, src_addr,
929  rx_fib_index, server_table_id))
930  {
931  mfib_table_entry_path_update (rx_fib_index,
932  &all_dhcp_servers,
933  MFIB_SOURCE_DHCP, &path_for_us);
934  /*
935  * Each interface that is enabled in this table, needs to be added
936  * as an accepting interface, but this is not easily doable in VPP.
937  * So we cheat. Add a flag to the entry that indicates accept form
938  * any interface.
939  * We will still only accept on v6 enabled interfaces, since the
940  * input feature ensures this.
941  */
942  mfib_table_entry_update (rx_fib_index,
943  &all_dhcp_servers,
948 
949  udp_register_dst_port (vm, UDP_DST_PORT_dhcpv6_to_client,
951  0 /* is_ip6 */ );
952  udp_register_dst_port (vm, UDP_DST_PORT_dhcpv6_to_server,
954  0 /* is_ip6 */ );
955  }
956  }
957 
959 
960  return (rc);
961 }
962 
963 static clib_error_t *
965  unformat_input_t * input,
966  vlib_cli_command_t * cmd)
967 {
968  ip46_address_t addr, src_addr;
969  int set_server = 0, set_src_address = 0;
970  u32 rx_table_id = 0, server_table_id = 0;
971  int is_del = 0;
972 
974  {
975  if (unformat (input, "server %U", unformat_ip6_address, &addr.ip6))
976  set_server = 1;
977  else if (unformat (input, "src-address %U",
978  unformat_ip6_address, &src_addr.ip6))
979  set_src_address = 1;
980  else if (unformat (input, "server-fib-id %d", &server_table_id))
981  ;
982  else if (unformat (input, "rx-fib-id %d", &rx_table_id))
983  ;
984  else if (unformat (input, "delete") || unformat (input, "del"))
985  is_del = 1;
986  else
987  break;
988  }
989 
990  if (is_del || (set_server && set_src_address))
991  {
992  int rv;
993 
994  rv = dhcp6_proxy_set_server (&addr, &src_addr, rx_table_id,
995  server_table_id, is_del);
996 
997  //TODO: Complete the errors
998  switch (rv)
999  {
1000  case 0:
1001  return 0;
1002 
1003  case VNET_API_ERROR_INVALID_DST_ADDRESS:
1004  return clib_error_return (0, "Invalid server address");
1005 
1006  case VNET_API_ERROR_INVALID_SRC_ADDRESS:
1007  return clib_error_return (0, "Invalid src address");
1008 
1009  case VNET_API_ERROR_NO_SUCH_ENTRY:
1010  return clib_error_return
1011  (0, "Fib id %d: no per-fib DHCP server configured", rx_table_id);
1012 
1013  default:
1014  return clib_error_return (0, "BUG: rv %d", rv);
1015  }
1016  }
1017  else
1018  return clib_error_return (0, "parse error`%U'",
1019  format_unformat_error, input);
1020 }
1021 
1022 /* *INDENT-OFF* */
1023 VLIB_CLI_COMMAND (dhcpv6_proxy_set_command, static) = {
1024  .path = "set dhcpv6 proxy",
1025  .short_help = "set dhcpv6 proxy [del] server <ipv6-addr> src-address <ipv6-addr> "
1026  "[server-fib-id <fib-id>] [rx-fib-id <fib-id>] ",
1027  .function = dhcpv6_proxy_set_command_fn,
1028 };
1029 /* *INDENT-ON* */
1030 
1031 static u8 *
1032 format_dhcp6_proxy_server (u8 * s, va_list * args)
1033 {
1034  dhcp_proxy_t *proxy = va_arg (*args, dhcp_proxy_t *);
1035  fib_table_t *server_fib;
1036  dhcp_server_t *server;
1037  ip6_mfib_t *rx_fib;
1038 
1039  if (proxy == 0)
1040  {
1041  s = format (s, "%=14s%=16s%s", "RX FIB", "Src Address",
1042  "Servers FIB,Address");
1043  return s;
1044  }
1045 
1046  rx_fib = ip6_mfib_get (proxy->rx_fib_index);
1047 
1048  s = format (s, "%=14u%=16U",
1049  rx_fib->table_id,
1051 
1052  vec_foreach (server, proxy->dhcp_servers)
1053  {
1054  server_fib = fib_table_get (server->server_fib_index, FIB_PROTOCOL_IP6);
1055  s = format (s, "%u,%U ",
1056  server_fib->ft_table_id,
1058  }
1059 
1060  return s;
1061 }
1062 
1063 static int
1065 {
1066  vlib_main_t *vm = ctx;
1067 
1068  vlib_cli_output (vm, "%U", format_dhcp6_proxy_server, proxy);
1069 
1070  return (1);
1071 }
1072 
1073 static clib_error_t *
1075  unformat_input_t * input,
1076  vlib_cli_command_t * cmd)
1077 {
1079  NULL /* header line */ );
1080 
1082 
1083  return (NULL);
1084 }
1085 
1086 /* *INDENT-OFF* */
1087 VLIB_CLI_COMMAND (dhcpv6_proxy_show_command, static) = {
1088  .path = "show dhcpv6 proxy",
1089  .short_help = "Display dhcpv6 proxy info",
1090  .function = dhcpv6_proxy_show_command_fn,
1091 };
1092 /* *INDENT-ON* */
1093 
1094 static clib_error_t *
1096  unformat_input_t * input, vlib_cli_command_t * cmd)
1097 {
1098  u8 is_del = 0, vss_type = VSS_TYPE_DEFAULT;
1099  u8 *vpn_ascii_id = 0;
1100  u32 oui = 0, fib_id = 0, tbl_id = ~0;
1101 
1102  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1103  {
1104  if (unformat (input, "table %d", &tbl_id))
1105  ;
1106  else if (unformat (input, "oui %d", &oui))
1108  else if (unformat (input, "vpn-id %d", &fib_id))
1110  else if (unformat (input, "vpn-ascii-id %s", &vpn_ascii_id))
1112  else if (unformat (input, "delete") || unformat (input, "del"))
1113  is_del = 1;
1114  else
1115  break;
1116  }
1117 
1118  if (tbl_id == ~0)
1119  return clib_error_return (0, "no table ID specified.");
1120 
1121  int rv = dhcp_proxy_set_vss (FIB_PROTOCOL_IP6, tbl_id, vss_type,
1122  vpn_ascii_id, oui, fib_id, is_del);
1123  switch (rv)
1124  {
1125  case 0:
1126  return 0;
1127  case VNET_API_ERROR_NO_SUCH_ENTRY:
1128  return clib_error_return (0, "vss for table %d not found in pool.",
1129  tbl_id);
1130  default:
1131  return clib_error_return (0, "BUG: rv %d", rv);
1132  }
1133 }
1134 
1135 /* *INDENT-OFF* */
1136 VLIB_CLI_COMMAND (dhcpv6_proxy_vss_command, static) = {
1137  .path = "set dhcpv6 vss",
1138  .short_help = "set dhcpv6 vss table <table-id> [oui <n> vpn-id <n> | vpn-ascii-id <text>]",
1139  .function = dhcpv6_vss_command_fn,
1140 };
1141 /* *INDENT-ON* */
1142 
1143 static clib_error_t *
1145  unformat_input_t * input,
1146  vlib_cli_command_t * cmd)
1147 {
1149 
1150  return (NULL);
1151 }
1152 
1153 /* *INDENT-OFF* */
1154 VLIB_CLI_COMMAND (dhcpv6_proxy_vss_show_command, static) = {
1155  .path = "show dhcpv6 vss",
1156  .short_help = "show dhcpv6 VSS",
1157  .function = dhcpv6_vss_show_command_fn,
1158 };
1159 /* *INDENT-ON* */
1160 
1161 static clib_error_t *
1163  unformat_input_t * input,
1164  vlib_cli_command_t * cmd)
1165 {
1166  vnet_main_t *vnm = vnet_get_main ();
1167  u32 sw_if_index0 = 0, sw_if_index;
1168  vnet_sw_interface_t *swif;
1169  ip6_address_t *ia0;
1170 
1171  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1172  {
1173 
1174  if (unformat (input, "%U",
1175  unformat_vnet_sw_interface, vnm, &sw_if_index0))
1176  {
1177  swif = vnet_get_sw_interface (vnm, sw_if_index0);
1179  swif->unnumbered_sw_if_index : sw_if_index0;
1181  if (ia0)
1182  {
1183  vlib_cli_output (vm, "%=20s%=48s", "interface", "link-address");
1184 
1185  vlib_cli_output (vm, "%=20U%=48U",
1187  sw_if_index0, format_ip6_address, ia0);
1188  }
1189  else
1190  vlib_cli_output (vm, "%=34s%=20U",
1191  "No IPv6 address configured on",
1193  }
1194  else
1195  break;
1196  }
1197 
1198  return 0;
1199 }
1200 
1201 /* *INDENT-OFF* */
1202 VLIB_CLI_COMMAND (dhcpv6_proxy_address_show_command, static) = {
1203  .path = "show dhcpv6 link-address interface",
1204  .short_help = "show dhcpv6 link-address interface <interface>",
1206 };
1207 /* *INDENT-ON* */
1208 
1209 /*
1210  * fd.io coding-style-patch-verification: ON
1211  *
1212  * Local Variables:
1213  * eval: (c-set-style "gnu")
1214  * End:
1215  */
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
void mfib_table_entry_delete(u32 fib_index, const mfib_prefix_t *prefix, mfib_source_t source)
Delete a FIB entry.
Definition: mfib_table.c:493
static ip6_address_t all_dhcpv6_server_relay_agent_address
u32 mfib_table_find_or_create_and_lock(fib_protocol_t proto, u32 table_id, mfib_source_t src)
Get the index of the FIB for a Table-ID.
Definition: mfib_table.c:613
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
vss_type
Definition: dhcp.api:22
#define CLIB_UNUSED(x)
Definition: clib.h:87
a
Definition: bitmap.h:538
static u8 * format_dhcpv6_proxy_trace(u8 *s, va_list *args)
u32 * mfib_index_by_sw_if_index
Table index indexed by software interface.
Definition: ip6.h:199
A representation of a path as described by a route producer.
Definition: fib_types.h:490
static clib_error_t * dhcpv6_proxy_set_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
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
fib_node_index_t mfib_table_entry_path_update(u32 fib_index, const mfib_prefix_t *prefix, mfib_source_t source, const fib_route_path_t *rpath)
Add n paths to an entry (aka route) in the FIB.
Definition: mfib_table.c:325
static u8 * format_dhcpv6_proxy_header_with_length(u8 *s, va_list *args)
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
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:110
static void * ip_interface_address_get_address(ip_lookup_main_t *lm, ip_interface_address_t *a)
Definition: ip_interface.h:43
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u32 index
Definition: node.h:279
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
static ip6_address_t all_dhcpv6_server_address
int dhcp6_proxy_set_server(ip46_address_t *addr, ip46_address_t *src_addr, u32 rx_table_id, u32 server_table_id, int is_del)
#define ethernet_buffer_header_size(b)
Determine the size of the Ethernet headers of the current frame in the buffer.
Definition: ethernet.h:452
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
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
static clib_error_t * dhcpv6_vss_show_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
ip6_address_t * ip6_interface_first_address(ip6_main_t *im, u32 sw_if_index)
get first IPv6 interface address
Definition: ip6_forward.c:278
vl_api_address_t src
Definition: gre.api:54
static vlib_node_registration_t dhcpv6_proxy_to_server_node
(constructor) VLIB_REGISTER_NODE (dhcpv6_proxy_to_server_node)
u32 rx_fib_index
The FIB index (not the external Table-ID) in which the client is resides.
Definition: dhcp_proxy.h:132
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
vlib_main_t * vm
Definition: in2out_ed.c:1582
fib_node_index_t mfib_table_entry_update(u32 fib_index, const mfib_prefix_t *prefix, mfib_source_t source, fib_rpf_id_t rpf_id, mfib_entry_flags_t entry_flags)
Add a new (with no replication) or lock an existing entry.
Definition: mfib_table.c:237
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
dpo_proto_t frp_proto
The protocol of the address below.
Definition: fib_types.h:495
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
static ip6_address_t * ip6_interface_first_global_or_site_address(ip6_main_t *im, u32 sw_if_index)
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
vhost_vring_addr_t addr
Definition: vhost_user.h:111
ip6_address_t src_address
Definition: ip6_packet.h:310
format_function_t format_vnet_sw_if_index_name
unsigned char u8
Definition: types.h:56
struct vnet_sub_interface_t::@356::@357::@359 flags
static vlib_buffer_t * vlib_buffer_copy(vlib_main_t *vm, vlib_buffer_t *b)
static clib_error_t * dhcp6_proxy_init(vlib_main_t *vm)
static char * dhcpv6_proxy_error_strings[]
#define clib_memcpy(d, s, n)
Definition: string.h:180
#define MFIB_RPF_ID_NONE
Definition: fib_types.h:413
dhcpv6_proxy_to_server_input_next_t
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
u8 dst_address[6]
Definition: packet.h:55
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
Definition: main.c:182
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
static clib_error_t * dhcpv6_vss_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
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
#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
static vlib_node_registration_t dhcpv6_proxy_to_client_node
(constructor) VLIB_REGISTER_NODE (dhcpv6_proxy_to_client_node)
#define foreach_dhcpv6_proxy_to_server_input_next
u32 server_fib_index
The FIB index (not the external Table-ID) in which the server is reachable.
Definition: dhcp_proxy.h:95
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:758
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
static clib_error_t * dhcpv6_proxy_show_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
void mfib_table_unlock(u32 fib_index, fib_protocol_t proto, mfib_source_t source)
Take a reference counting lock on the table.
Definition: mfib_table.c:777
struct vnet_sub_interface_t::@356 eth
static u8 ip46_address_is_zero(const ip46_address_t *ip46)
Definition: ip46_address.h:87
long ctx[MAX_CONNS]
Definition: main.c:144
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
Definition: main.c:216
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
vl_api_mac_address_t src_addr
Definition: flow_types.api:64
#define PREDICT_FALSE(x)
Definition: clib.h:120
vnet_sw_interface_flags_t flags
Definition: interface.h:738
ip6_main_t ip6_main
Definition: ip6_forward.c:2781
#define HOP_COUNT_LIMIT
Definition: dhcp6_packet.h:28
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
void mfib_table_lock(u32 fib_index, fib_protocol_t proto, mfib_source_t source)
Release a reference counting lock on the table.
Definition: mfib_table.c:806
#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
vl_api_address_t dst
Definition: gre.api:55
#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:391
Definition: ip6.h:83
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1231
u8 len
Definition: ip_types.api:92
format_function_t format_ip46_address
Definition: ip46_address.h:50
unformat_function_t unformat_ip6_address
Definition: format.h:89
static_always_inline u32 vlib_buffer_get_default_data_size(vlib_main_t *vm)
Definition: buffer_funcs.h:96
#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:396
u32 ft_table_id
Table ID (hash key) for this FIB.
Definition: fib_table.h:92
format_function_t format_ip6_address
Definition: format.h:91
void udp_unregister_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u8 is_ip4)
Definition: udp_local.c:506
static clib_error_t * dhcpv6_link_address_show_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u8 data[]
Packet data.
Definition: buffer.h:181
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
Aggregate type for a prefix.
Definition: mfib_types.h:24
vlib_main_t vlib_node_runtime_t * node
Definition: in2out_ed.c:1582
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:158
u16 ip6_tcp_udp_icmp_compute_checksum(vlib_main_t *vm, vlib_buffer_t *p0, ip6_header_t *ip0, int *bogus_lengthp)
Definition: ip6_forward.c:1095
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:510
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
#define ASSERT(truth)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:696
ip_lookup_main_t lookup_main
Definition: ip6.h:181
u32 table_id
Definition: ip6.h:89
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 vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
static void copy_ip6_address(ip6_address_t *dst, ip6_address_t *src)
struct _vlib_node_registration vlib_node_registration_t
A DHCP proxy representation fpr per-client VRF config.
Definition: dhcp_proxy.h:101
u32 ip_version_traffic_class_and_flow_label
Definition: ip6_packet.h:297
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
u16 payload_length
Definition: ip6_packet.h:301
A for-us/local path.
Definition: fib_types.h:338
#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 foreach_ip_interface_address(lm, a, sw_if_index, loop, body)
Definition: ip_interface.h:57
#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:297
#define VSS_TYPE_VPN_ID
Definition: dhcp_proxy.h:67
fib_table_t * fib_table_get(fib_node_index_t index, fib_protocol_t proto)
Get a pointer to a FIB table.
Definition: fib_table.c:29
static ethernet_main_t * vnet_get_ethernet_main(void)
Definition: ethernet.h:571
static ip6_mfib_t * ip6_mfib_get(u32 index)
Get the FIB at the given index.
Definition: ip6_mfib.h:72
#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:736
#define vec_foreach(var, vec)
Vector iterator.
void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace.c:577
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
u16 fp_len
The mask length.
Definition: mfib_types.h:28
static int dhcp6_proxy_show_walk(dhcp_proxy_t *proxy, void *ctx)
u32 * fib_index_by_sw_if_index
Definition: ip6.h:196
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 u8 * format_dhcp6_proxy_server(u8 *s, va_list *args)
const ip46_address_t zero_addr
Definition: lookup.c:181
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:33
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
Definition: defs.h:46
ip6_address_t dst_address
Definition: ip6_packet.h:310
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
A protocol Independent FIB table.
Definition: fib_table.h:71
static uword dhcpv6_proxy_to_server_input(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
#define PROTO_UDP
Definition: dhcp6_packet.h:25
static uword dhcpv6_proxy_to_client_input(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)