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