FD.io VPP  v18.07.1-19-g511ce25
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 <vnet/dhcp/dhcp_proxy.h>
21 #include <vnet/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 */
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",
73  else
74  s = format (s, "DHCPV6 proxy: sent to client from %U",
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  ({
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
126 {
127  dst->as_u64[0] = src->as_u64[0];
128  dst->as_u64[1] = src->as_u64[1];
129 }
130 
131 static uword
133  vlib_node_runtime_t * node,
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];
183  dhcp_vss_t *vss;
184  u8 is_solicit = 0;
185 
186  bi0 = from[0];
187  from += 1;
188  n_left_from -= 1;
189 
190  b0 = vlib_get_buffer (vm, bi0);
191 
192  h0 = vlib_buffer_get_current (b0);
193 
194  /*
195  * udp_local hands us the DHCPV6 header.
196  */
197  u0 = (void *) h0 - (sizeof (*u0));
198  ip0 = (void *) u0 - (sizeof (*ip0));
199  e_h0 = (void *) ip0 - ethernet_buffer_header_size (b0);
200 
201  clib_memcpy (client_src_mac, e_h0->src_address, 6);
202 
203  switch (h0->msg_type)
204  {
205  case DHCPV6_MSG_SOLICIT:
206  case DHCPV6_MSG_REQUEST:
207  case DHCPV6_MSG_CONFIRM:
208  case DHCPV6_MSG_RENEW:
209  case DHCPV6_MSG_REBIND:
210  case DHCPV6_MSG_RELEASE:
211  case DHCPV6_MSG_DECLINE:
214  /* send to server */
215  break;
217  /* send to client */
218  next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_SEND_TO_CLIENT;
219  error0 = 0;
220  pkts_to_client++;
221  goto do_enqueue;
222  default:
223  /* drop the packet */
224  pkts_wrong_msg_type++;
225  error0 = DHCPV6_PROXY_ERROR_WRONG_MESSAGE_TYPE;
226  next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
227  goto do_trace;
228 
229  }
230 
231  /* Send to DHCPV6 server via the configured FIB */
232  rx_sw_if_index = sw_if_index =
233  vnet_buffer (b0)->sw_if_index[VLIB_RX];
234  rx_fib_idx = im->mfib_index_by_sw_if_index[rx_sw_if_index];
235  proxy = dhcp_get_proxy (dpm, rx_fib_idx, FIB_PROTOCOL_IP6);
236 
237  if (PREDICT_FALSE (NULL == proxy))
238  {
239  error0 = DHCPV6_PROXY_ERROR_NO_SERVER;
240  next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
241  pkts_no_server++;
242  goto do_trace;
243  }
244 
245  server = &proxy->dhcp_servers[0];
246  server_fib_idx = server->server_fib_index;
247  vnet_buffer (b0)->sw_if_index[VLIB_TX] = server_fib_idx;
248 
249 
250  /* relay-option header pointer */
251  vlib_buffer_advance (b0, -(sizeof (*fwd_opt)));
252  fwd_opt = vlib_buffer_get_current (b0);
253  /* relay message header pointer */
254  vlib_buffer_advance (b0, -(sizeof (*r1)));
255  r1 = vlib_buffer_get_current (b0);
256 
257  vlib_buffer_advance (b0, -(sizeof (*u1)));
258  u1 = vlib_buffer_get_current (b0);
259 
260  vlib_buffer_advance (b0, -(sizeof (*ip1)));
261  ip1 = vlib_buffer_get_current (b0);
262 
263  /* fill in all that rubbish... */
264  len = clib_net_to_host_u16 (u0->length) - sizeof (udp_header_t);
265  copy_ip6_address (&r1->peer_addr, &ip0->src_address);
266 
267  r1->msg_type = DHCPV6_MSG_RELAY_FORW;
268  fwd_opt->length = clib_host_to_net_u16 (len);
269  fwd_opt->option = clib_host_to_net_u16 (DHCPV6_OPTION_RELAY_MSG);
270 
271  r1->hop_count++;
272  r1->hop_count =
273  (h0->msg_type != DHCPV6_MSG_RELAY_FORW) ? 0 : r1->hop_count;
274 
275  if (PREDICT_FALSE (r1->hop_count >= HOP_COUNT_LIMIT))
276  {
278  next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
279  pkts_no_exceeding_max_hop++;
280  goto do_trace;
281  }
282 
283 
284  /* If relay-fwd and src address is site or global unicast address */
285  if (h0->msg_type == DHCPV6_MSG_RELAY_FORW &&
286  ((ip0->src_address.as_u8[0] & 0xe0) == 0x20 ||
287  (ip0->src_address.as_u8[0] & 0xfe) == 0xfc))
288  {
289  /* Set link address to zero */
290  r1->link_addr.as_u64[0] = 0;
291  r1->link_addr.as_u64[1] = 0;
292  goto link_address_set;
293  }
294 
295  /* if receiving interface is unnumbered, use receiving interface
296  * IP address as link address, otherwise use the loopback interface
297  * IP address as link address.
298  */
299 
300  swif = vnet_get_sw_interface (vnm, rx_sw_if_index);
302  sw_if_index = swif->unnumbered_sw_if_index;
303 
304  ia0 =
306  sw_if_index);
307  if (ia0 == 0)
308  {
309  error0 = DHCPV6_PROXY_ERROR_NO_INTERFACE_ADDRESS;
310  next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
311  pkts_no_interface_address++;
312  goto do_trace;
313  }
314 
315  copy_ip6_address (&r1->link_addr, ia0);
316 
317  link_address_set:
318  fl =
321 
322  if ((b0->current_length + sizeof (*id1) + sizeof (*vss1) +
323  sizeof (*cmac)) > fl->n_data_bytes)
324  {
325  error0 = DHCPV6_PROXY_ERROR_PKT_TOO_BIG;
326  next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
327  pkts_too_big++;
328  goto do_trace;
329  }
330 
331  id1 = (dhcpv6_int_id_t *) (((uword) ip1) + b0->current_length);
332  b0->current_length += (sizeof (*id1));
333 
334  id1->opt.option = clib_host_to_net_u16 (DHCPV6_OPTION_INTERFACE_ID);
335  id1->opt.length = clib_host_to_net_u16 (sizeof (rx_sw_if_index));
336  id1->int_idx = clib_host_to_net_u32 (rx_sw_if_index);
337 
338  u1->length = 0;
339  if (h0->msg_type != DHCPV6_MSG_RELAY_FORW)
340  {
341  cmac =
342  (dhcpv6_client_mac_t *) (((uword) ip1) + b0->current_length);
343  b0->current_length += (sizeof (*cmac));
344  cmac->opt.length = clib_host_to_net_u16 (sizeof (*cmac) -
345  sizeof (cmac->opt));
346  cmac->opt.option =
347  clib_host_to_net_u16
348  (DHCPV6_OPTION_CLIENT_LINK_LAYER_ADDRESS);
349  cmac->link_type = clib_host_to_net_u16 (1); /* ethernet */
350  clib_memcpy (cmac->data, client_src_mac, 6);
351  u1->length += sizeof (*cmac);
352  }
353 
354  vss = dhcp_get_vss_info (dpm, rx_fib_idx, FIB_PROTOCOL_IP6);
355 
356  if (vss)
357  {
358  u16 id_len; /* length of VPN ID */
359  u16 type_len = sizeof (vss1->vss_type);
360 
361  vss1 = (dhcpv6_vss_t *) (((uword) ip1) + b0->current_length);
362  vss1->vss_type = vss->vss_type;
363  if (vss->vss_type == VSS_TYPE_VPN_ID)
364  {
365  id_len = sizeof (vss->vpn_id); /* vpn_id is 7 bytes */
366  memcpy (vss1->data, vss->vpn_id, id_len);
367  }
368  else if (vss->vss_type == VSS_TYPE_ASCII)
369  {
370  id_len = vec_len (vss->vpn_ascii_id);
371  memcpy (vss1->data, vss->vpn_ascii_id, id_len);
372  }
373  else /* must be VSS_TYPE_DEFAULT, no VPN ID */
374  id_len = 0;
375 
376  vss1->opt.option = clib_host_to_net_u16 (DHCPV6_OPTION_VSS);
377  vss1->opt.length = clib_host_to_net_u16 (type_len + id_len);
378  u1->length += type_len + id_len + sizeof (vss1->opt);
379  b0->current_length += type_len + id_len + sizeof (vss1->opt);
380  }
381 
382  pkts_to_server++;
383  u1->checksum = 0;
384  u1->src_port = clib_host_to_net_u16 (UDP_DST_PORT_dhcpv6_to_client);
385  u1->dst_port = clib_host_to_net_u16 (UDP_DST_PORT_dhcpv6_to_server);
386 
387  u1->length =
388  clib_host_to_net_u16 (clib_net_to_host_u16 (fwd_opt->length) +
389  sizeof (*r1) + sizeof (*fwd_opt) +
390  sizeof (*u1) + sizeof (*id1) + u1->length);
391 
392  memset (ip1, 0, sizeof (*ip1));
393  ip1->ip_version_traffic_class_and_flow_label = 0x60;
394  ip1->payload_length = u1->length;
395  ip1->protocol = PROTO_UDP;
396  ip1->hop_limit = HOP_COUNT_LIMIT;
397  src = ((server->dhcp_server.ip6.as_u64[0] ||
398  server->dhcp_server.ip6.as_u64[1]) ?
399  &server->dhcp_server.ip6 : &all_dhcpv6_server_address);
400  copy_ip6_address (&ip1->dst_address, src);
401 
402 
404  (&ip6_main, vnet_buffer (b0)->sw_if_index[VLIB_RX]);
405 
406  src = (proxy->dhcp_src_address.ip6.as_u64[0] ||
407  proxy->dhcp_src_address.ip6.as_u64[1]) ?
408  &proxy->dhcp_src_address.ip6 : ia0;
409  if (ia0 == 0)
410  {
411  error0 = DHCPV6_PROXY_ERROR_NO_SRC_ADDRESS;
412  next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
413  pkts_no_src_address++;
414  goto do_trace;
415  }
416 
417  copy_ip6_address (&ip1->src_address, src);
418 
419 
420  u1->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip1,
421  &bogus_length);
422  ASSERT (bogus_length == 0);
423 
424  next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP;
425 
426  is_solicit = (DHCPV6_MSG_SOLICIT == h0->msg_type);
427 
428  /*
429  * If we have multiple servers configured and this is the
430  * client's discover message, then send copies to each of
431  * those servers
432  */
433  if (is_solicit && vec_len (proxy->dhcp_servers) > 1)
434  {
435  u32 ii;
436 
437  for (ii = 1; ii < vec_len (proxy->dhcp_servers); ii++)
438  {
439  vlib_buffer_t *c0;
440  u32 ci0;
441 
442  c0 = vlib_buffer_copy (vm, b0);
443  ci0 = vlib_get_buffer_index (vm, c0);
444  server = &proxy->dhcp_servers[ii];
445 
446  ip0 = vlib_buffer_get_current (c0);
447 
448  src = ((server->dhcp_server.ip6.as_u64[0] ||
449  server->dhcp_server.ip6.as_u64[1]) ?
450  &server->dhcp_server.ip6 :
451  &all_dhcpv6_server_address);
452  copy_ip6_address (&ip1->dst_address, src);
453 
454  to_next[0] = ci0;
455  to_next += 1;
456  n_left_to_next -= 1;
457 
458  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
459  to_next, n_left_to_next,
460  ci0, next0);
461 
462  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
463  {
465 
466  tr = vlib_add_trace (vm, node, c0, sizeof (*tr));
467  tr->which = 0; /* to server */
468  tr->error = error0;
469  tr->original_sw_if_index = rx_sw_if_index;
470  tr->sw_if_index = sw_if_index;
471  if (next0 == DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP)
473  tr->packet_data[0],
474  &server->dhcp_server.ip6);
475  }
476 
477  if (PREDICT_FALSE (0 == n_left_to_next))
478  {
479  vlib_put_next_frame (vm, node, next_index,
480  n_left_to_next);
481  vlib_get_next_frame (vm, node, next_index,
482  to_next, n_left_to_next);
483  }
484  }
485  }
486 
487  do_trace:
488  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
489  {
490  dhcpv6_proxy_trace_t *tr = vlib_add_trace (vm, node,
491  b0, sizeof (*tr));
492  tr->which = 0; /* to server */
493  tr->error = error0;
494  tr->original_sw_if_index = rx_sw_if_index;
495  tr->sw_if_index = sw_if_index;
496  if (DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP == next0)
498  &server->dhcp_server.ip6);
499  }
500 
501  do_enqueue:
502  to_next[0] = bi0;
503  to_next += 1;
504  n_left_to_next -= 1;
505 
506  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
507  to_next, n_left_to_next,
508  bi0, next0);
509  }
510 
511  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
512  }
513 
515  DHCPV6_PROXY_ERROR_RELAY_TO_CLIENT,
516  pkts_to_client);
518  DHCPV6_PROXY_ERROR_RELAY_TO_SERVER,
519  pkts_to_server);
521  DHCPV6_PROXY_ERROR_NO_INTERFACE_ADDRESS,
522  pkts_no_interface_address);
524  DHCPV6_PROXY_ERROR_WRONG_MESSAGE_TYPE,
525  pkts_wrong_msg_type);
527  DHCPV6_PROXY_ERROR_NO_SRC_ADDRESS,
528  pkts_no_src_address);
530  DHCPV6_PROXY_ERROR_PKT_TOO_BIG, pkts_too_big);
531  return from_frame->n_vectors;
532 }
533 
534 /* *INDENT-OFF* */
536  .function = dhcpv6_proxy_to_server_input,
537  .name = "dhcpv6-proxy-to-server",
538  /* Takes a vector of packets. */
539  .vector_size = sizeof (u32),
540 
541  .n_errors = DHCPV6_PROXY_N_ERROR,
542  .error_strings = dhcpv6_proxy_error_strings,
543 
544  .n_next_nodes = DHCPV6_PROXY_TO_SERVER_INPUT_N_NEXT,
545  .next_nodes = {
546 #define _(s,n) [DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_##s] = n,
548 #undef _
549  },
550 
552  .format_trace = format_dhcpv6_proxy_trace,
553 #if 0
554  .unformat_buffer = unformat_dhcpv6_proxy_header,
555 #endif
556 };
557 /* *INDENT-ON* */
558 
559 static uword
561  vlib_node_runtime_t * node,
562  vlib_frame_t * from_frame)
563 {
564 
565  u32 n_left_from, *from;
568  dhcp_proxy_t *proxy;
569  dhcp_server_t *server;
570  vnet_main_t *vnm = vnet_get_main ();
571  int bogus_length;
572 
573  from = vlib_frame_vector_args (from_frame);
574  n_left_from = from_frame->n_vectors;
575 
576  while (n_left_from > 0)
577  {
578  u32 bi0;
579  vlib_buffer_t *b0;
580  udp_header_t *u0, *u1 = 0;
581  dhcpv6_relay_hdr_t *h0;
582  ip6_header_t *ip1 = 0, *ip0;
583  ip6_address_t _ia0, *ia0 = &_ia0;
584  ip6_address_t client_address;
586  ethernet_header_t *mac0;
587  vnet_hw_interface_t *hi0;
588  vlib_frame_t *f0;
589  u32 *to_next0;
590  u32 sw_if_index = ~0;
591  u32 original_sw_if_index = ~0;
592  vnet_sw_interface_t *si0;
593  u32 error0 = (u32) ~ 0;
594  vnet_sw_interface_t *swif;
595  dhcpv6_option_t *r0 = 0, *o;
596  u16 len = 0;
597  u8 interface_opt_flag = 0;
598  u8 relay_msg_opt_flag = 0;
599  ip6_main_t *im = &ip6_main;
600  u32 server_fib_idx, client_fib_idx;
601 
602  bi0 = from[0];
603  from += 1;
604  n_left_from -= 1;
605 
606  b0 = vlib_get_buffer (vm, bi0);
607  h0 = vlib_buffer_get_current (b0);
608 
609  if (DHCPV6_MSG_RELAY_REPL != h0->msg_type)
610  {
611  error0 = DHCPV6_PROXY_ERROR_WRONG_MESSAGE_TYPE;
612 
613  drop_packet:
615  error0, 1);
616 
618  to_next0 = vlib_frame_vector_args (f0);
619  to_next0[0] = bi0;
620  f0->n_vectors = 1;
622  goto do_trace;
623  }
624  /* hop count seems not need to be checked */
625  if (HOP_COUNT_LIMIT < h0->hop_count)
626  {
628  goto drop_packet;
629  }
630  u0 = (void *) h0 - (sizeof (*u0));
631  ip0 = (void *) u0 - (sizeof (*ip0));
632 
633  vlib_buffer_advance (b0, sizeof (*h0));
634  o = vlib_buffer_get_current (b0);
635 
636  /* Parse through TLVs looking for option 18 (DHCPV6_OPTION_INTERFACE_ID)
637  _and_ option 9 (DHCPV6_OPTION_RELAY_MSG) option which must be there.
638  Currently assuming no other options need to be processed
639  The interface-ID is the FIB number we need
640  to track down the client-facing interface */
641 
642  while ((u8 *) o < (b0->data + b0->current_data + b0->current_length))
643  {
644  if (DHCPV6_OPTION_INTERFACE_ID == clib_net_to_host_u16 (o->option))
645  {
646  interface_opt_flag = 1;
647  if (clib_net_to_host_u16 (o->length) == sizeof (sw_if_index))
648  sw_if_index =
649  clib_net_to_host_u32 (((dhcpv6_int_id_t *) o)->int_idx);
650  if (sw_if_index >= vec_len (im->fib_index_by_sw_if_index))
651  {
652  error0 = DHCPV6_PROXY_ERROR_WRONG_INTERFACE_ID_OPTION;
653  goto drop_packet;
654  }
655  }
656  if (DHCPV6_OPTION_RELAY_MSG == clib_net_to_host_u16 (o->option))
657  {
658  relay_msg_opt_flag = 1;
659  r0 = vlib_buffer_get_current (b0);
660  }
661  if ((relay_msg_opt_flag == 1) && (interface_opt_flag == 1))
662  break;
664  sizeof (*o) +
665  clib_net_to_host_u16 (o->length));
666  o =
667  (dhcpv6_option_t *) (((uword) o) +
668  clib_net_to_host_u16 (o->length) +
669  sizeof (*o));
670  }
671 
672  if ((relay_msg_opt_flag == 0) || (r0 == 0))
673  {
674  error0 = DHCPV6_PROXY_ERROR_NO_RELAY_MESSAGE_OPTION;
675  goto drop_packet;
676  }
677 
678  if ((u32) ~ 0 == sw_if_index)
679  {
680  error0 = DHCPV6_PROXY_ERROR_NO_CIRCUIT_ID_OPTION;
681  goto drop_packet;
682  }
683 
684  //Advance buffer to start of encapsulated DHCPv6 message
685  vlib_buffer_advance (b0, sizeof (*r0));
686 
687  client_fib_idx = im->mfib_index_by_sw_if_index[sw_if_index];
688  proxy = dhcp_get_proxy (dm, client_fib_idx, FIB_PROTOCOL_IP6);
689 
690  if (NULL == proxy)
691  {
692  error0 = DHCPV6_PROXY_ERROR_NO_SERVER;
693  goto drop_packet;
694  }
695 
696  server_fib_idx = im->fib_index_by_sw_if_index
697  [vnet_buffer (b0)->sw_if_index[VLIB_RX]];
698 
699  vec_foreach (server, proxy->dhcp_servers)
700  {
701  if (server_fib_idx == server->server_fib_index &&
702  ip0->src_address.as_u64[0] == server->dhcp_server.ip6.as_u64[0] &&
703  ip0->src_address.as_u64[1] == server->dhcp_server.ip6.as_u64[1])
704  {
705  goto server_found;
706  }
707  }
708 
709  //drop packet if not from server with configured address or FIB
710  error0 = DHCPV6_PROXY_ERROR_BAD_SVR_FIB_OR_ADDRESS;
711  goto drop_packet;
712 
713  server_found:
714  vnet_buffer (b0)->sw_if_index[VLIB_TX] = original_sw_if_index
715  = sw_if_index;
716 
717  swif = vnet_get_sw_interface (vnm, original_sw_if_index);
719  sw_if_index = swif->unnumbered_sw_if_index;
720 
721 
722  /*
723  * udp_local hands us the DHCPV6 header, need udp hdr,
724  * ip hdr to relay to client
725  */
726  vlib_buffer_advance (b0, -(sizeof (*u1)));
727  u1 = vlib_buffer_get_current (b0);
728 
729  vlib_buffer_advance (b0, -(sizeof (*ip1)));
730  ip1 = vlib_buffer_get_current (b0);
731 
732  copy_ip6_address (&client_address, &h0->peer_addr);
733 
734  ia0 = ip6_interface_first_address (&ip6_main, sw_if_index);
735  if (ia0 == 0)
736  {
737  error0 = DHCPV6_PROXY_ERROR_NO_INTERFACE_ADDRESS;
738  goto drop_packet;
739  }
740 
741  len = clib_net_to_host_u16 (r0->length);
742  memset (ip1, 0, sizeof (*ip1));
743  copy_ip6_address (&ip1->dst_address, &client_address);
744  u1->checksum = 0;
745  u1->src_port = clib_net_to_host_u16 (UDP_DST_PORT_dhcpv6_to_server);
746  u1->dst_port = clib_net_to_host_u16 (UDP_DST_PORT_dhcpv6_to_client);
747  u1->length = clib_host_to_net_u16 (len + sizeof (udp_header_t));
748 
750  ip0->ip_version_traffic_class_and_flow_label & 0x00000fff;
751  ip1->payload_length = u1->length;
752  ip1->protocol = PROTO_UDP;
753  ip1->hop_limit = HOP_COUNT_LIMIT;
754  copy_ip6_address (&ip1->src_address, ia0);
755 
756  u1->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip1,
757  &bogus_length);
758  ASSERT (bogus_length == 0);
759 
760  vlib_buffer_advance (b0, -(sizeof (ethernet_header_t)));
761  si0 = vnet_get_sw_interface (vnm, original_sw_if_index);
762  if (si0->type == VNET_SW_INTERFACE_TYPE_SUB)
763  vlib_buffer_advance (b0, -4 /* space for VLAN tag */ );
764 
765  mac0 = vlib_buffer_get_current (b0);
766 
767  hi0 = vnet_get_sup_hw_interface (vnm, original_sw_if_index);
768  ei0 = pool_elt_at_index (em->interfaces, hi0->hw_instance);
769  clib_memcpy (mac0->src_address, ei0->address, sizeof (ei0->address));
770  memset (&mac0->dst_address, 0xff, sizeof (mac0->dst_address));
771  mac0->type = (si0->type == VNET_SW_INTERFACE_TYPE_SUB) ?
772  clib_net_to_host_u16 (0x8100) : clib_net_to_host_u16 (0x86dd);
773 
774  if (si0->type == VNET_SW_INTERFACE_TYPE_SUB)
775  {
776  u32 *vlan_tag = (u32 *) (mac0 + 1);
777  u32 tmp;
778  tmp = (si0->sub.id << 16) | 0x0800;
779  *vlan_tag = clib_host_to_net_u32 (tmp);
780  }
781 
782  /* $$$ consider adding a dynamic next to the graph node, for performance */
784  to_next0 = vlib_frame_vector_args (f0);
785  to_next0[0] = bi0;
786  f0->n_vectors = 1;
788 
789  do_trace:
790  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
791  {
792  dhcpv6_proxy_trace_t *tr = vlib_add_trace (vm, node,
793  b0, sizeof (*tr));
794  tr->which = 1; /* to client */
795  if (ia0)
797  tr->error = error0;
798  tr->original_sw_if_index = original_sw_if_index;
799  tr->sw_if_index = sw_if_index;
800  }
801  }
802  return from_frame->n_vectors;
803 
804 }
805 
806 /* *INDENT-OFF* */
808  .function = dhcpv6_proxy_to_client_input,
809  .name = "dhcpv6-proxy-to-client",
810  /* Takes a vector of packets. */
811  .vector_size = sizeof (u32),
812 
813  .n_errors = DHCPV6_PROXY_N_ERROR,
814  .error_strings = dhcpv6_proxy_error_strings,
816  .format_trace = format_dhcpv6_proxy_trace,
817 #if 0
818  .unformat_buffer = unformat_dhcpv6_proxy_header,
819 #endif
820 };
821 /* *INDENT-ON* */
822 
823 static clib_error_t *
825 {
827  vlib_node_t *error_drop_node;
828 
829  error_drop_node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
830  dm->error_drop_node_index = error_drop_node->index;
831 
832  /* RFC says this is the dhcpv6 server address */
833  all_dhcpv6_server_address.as_u64[0] =
834  clib_host_to_net_u64 (0xFF05000000000000);
835  all_dhcpv6_server_address.as_u64[1] = clib_host_to_net_u64 (0x00010003);
836 
837  /* RFC says this is the server and agent address */
838  all_dhcpv6_server_relay_agent_address.as_u64[0] =
839  clib_host_to_net_u64 (0xFF02000000000000);
840  all_dhcpv6_server_relay_agent_address.as_u64[1] =
841  clib_host_to_net_u64 (0x00010002);
842 
843  return 0;
844 }
845 
847 
848 int
849 dhcp6_proxy_set_server (ip46_address_t * addr,
850  ip46_address_t * src_addr,
851  u32 rx_table_id, u32 server_table_id, int is_del)
852 {
854  u32 rx_fib_index = 0;
855  int rc = 0;
856 
857  const mfib_prefix_t all_dhcp_servers = {
858  .fp_len = 128,
859  .fp_proto = FIB_PROTOCOL_IP6,
860  .fp_grp_addr = {
862  }
863  };
864 
865  if (ip46_address_is_zero (addr))
866  return VNET_API_ERROR_INVALID_DST_ADDRESS;
867 
868  if (ip46_address_is_zero (src_addr))
869  return VNET_API_ERROR_INVALID_SRC_ADDRESS;
870 
872  rx_table_id,
874 
875  if (is_del)
876  {
877  if (dhcp_proxy_server_del (FIB_PROTOCOL_IP6, rx_fib_index,
878  addr, server_table_id))
879  {
880  mfib_table_entry_delete (rx_fib_index,
881  &all_dhcp_servers, MFIB_SOURCE_DHCP);
882  mfib_table_unlock (rx_fib_index, FIB_PROTOCOL_IP6,
884 
885  udp_unregister_dst_port (vm, UDP_DST_PORT_dhcpv6_to_client,
886  0 /* is_ip6 */ );
887  udp_unregister_dst_port (vm, UDP_DST_PORT_dhcpv6_to_server,
888  0 /* is_ip6 */ );
889  }
890  }
891  else
892  {
893  const fib_route_path_t path_for_us = {
895  .frp_addr = zero_addr,
896  .frp_sw_if_index = 0xffffffff,
897  .frp_fib_index = ~0,
898  .frp_weight = 0,
899  .frp_flags = FIB_ROUTE_PATH_LOCAL,
900  };
901  if (dhcp_proxy_server_add (FIB_PROTOCOL_IP6, addr, src_addr,
902  rx_fib_index, server_table_id))
903  {
904  mfib_table_entry_path_update (rx_fib_index,
905  &all_dhcp_servers,
907  &path_for_us, MFIB_ITF_FLAG_FORWARD);
908  /*
909  * Each interface that is enabled in this table, needs to be added
910  * as an accepting interface, but this is not easily doable in VPP.
911  * So we cheat. Add a flag to the entry that indicates accept form
912  * any interface.
913  * We will still only accept on v6 enabled interfaces, since the
914  * input feature ensures this.
915  */
916  mfib_table_entry_update (rx_fib_index,
917  &all_dhcp_servers,
922 
923  udp_register_dst_port (vm, UDP_DST_PORT_dhcpv6_to_client,
925  0 /* is_ip6 */ );
926  udp_register_dst_port (vm, UDP_DST_PORT_dhcpv6_to_server,
928  0 /* is_ip6 */ );
929  }
930  }
931 
933 
934  return (rc);
935 }
936 
937 static clib_error_t *
939  unformat_input_t * input,
940  vlib_cli_command_t * cmd)
941 {
942  ip46_address_t addr, src_addr;
943  int set_server = 0, set_src_address = 0;
944  u32 rx_table_id = 0, server_table_id = 0;
945  int is_del = 0;
946 
948  {
949  if (unformat (input, "server %U", unformat_ip6_address, &addr.ip6))
950  set_server = 1;
951  else if (unformat (input, "src-address %U",
952  unformat_ip6_address, &src_addr.ip6))
953  set_src_address = 1;
954  else if (unformat (input, "server-fib-id %d", &server_table_id))
955  ;
956  else if (unformat (input, "rx-fib-id %d", &rx_table_id))
957  ;
958  else if (unformat (input, "delete") || unformat (input, "del"))
959  is_del = 1;
960  else
961  break;
962  }
963 
964  if (is_del || (set_server && set_src_address))
965  {
966  int rv;
967 
968  rv = dhcp6_proxy_set_server (&addr, &src_addr, rx_table_id,
969  server_table_id, is_del);
970 
971  //TODO: Complete the errors
972  switch (rv)
973  {
974  case 0:
975  return 0;
976 
977  case VNET_API_ERROR_INVALID_DST_ADDRESS:
978  return clib_error_return (0, "Invalid server address");
979 
980  case VNET_API_ERROR_INVALID_SRC_ADDRESS:
981  return clib_error_return (0, "Invalid src address");
982 
983  case VNET_API_ERROR_NO_SUCH_ENTRY:
984  return clib_error_return
985  (0, "Fib id %d: no per-fib DHCP server configured", rx_table_id);
986 
987  default:
988  return clib_error_return (0, "BUG: rv %d", rv);
989  }
990  }
991  else
992  return clib_error_return (0, "parse error`%U'",
993  format_unformat_error, input);
994 }
995 
996 /* *INDENT-OFF* */
997 VLIB_CLI_COMMAND (dhcpv6_proxy_set_command, static) = {
998  .path = "set dhcpv6 proxy",
999  .short_help = "set dhcpv6 proxy [del] server <ipv6-addr> src-address <ipv6-addr> "
1000  "[server-fib-id <fib-id>] [rx-fib-id <fib-id>] ",
1001  .function = dhcpv6_proxy_set_command_fn,
1002 };
1003 /* *INDENT-ON* */
1004 
1005 static u8 *
1006 format_dhcp6_proxy_server (u8 * s, va_list * args)
1007 {
1008  dhcp_proxy_t *proxy = va_arg (*args, dhcp_proxy_t *);
1009  fib_table_t *server_fib;
1010  dhcp_server_t *server;
1011  ip6_mfib_t *rx_fib;
1012 
1013  if (proxy == 0)
1014  {
1015  s = format (s, "%=14s%=16s%s", "RX FIB", "Src Address",
1016  "Servers FIB,Address");
1017  return s;
1018  }
1019 
1020  rx_fib = ip6_mfib_get (proxy->rx_fib_index);
1021 
1022  s = format (s, "%=14u%=16U",
1023  rx_fib->table_id,
1025 
1026  vec_foreach (server, proxy->dhcp_servers)
1027  {
1028  server_fib = fib_table_get (server->server_fib_index, FIB_PROTOCOL_IP6);
1029  s = format (s, "%u,%U ",
1030  server_fib->ft_table_id,
1032  }
1033 
1034  return s;
1035 }
1036 
1037 static int
1039 {
1040  vlib_main_t *vm = ctx;
1041 
1042  vlib_cli_output (vm, "%U", format_dhcp6_proxy_server, proxy);
1043 
1044  return (1);
1045 }
1046 
1047 static clib_error_t *
1049  unformat_input_t * input,
1050  vlib_cli_command_t * cmd)
1051 {
1053  NULL /* header line */ );
1054 
1056 
1057  return (NULL);
1058 }
1059 
1060 /* *INDENT-OFF* */
1061 VLIB_CLI_COMMAND (dhcpv6_proxy_show_command, static) = {
1062  .path = "show dhcpv6 proxy",
1063  .short_help = "Display dhcpv6 proxy info",
1064  .function = dhcpv6_proxy_show_command_fn,
1065 };
1066 /* *INDENT-ON* */
1067 
1068 static clib_error_t *
1070  unformat_input_t * input, vlib_cli_command_t * cmd)
1071 {
1072  u8 is_del = 0, vss_type = VSS_TYPE_DEFAULT;
1073  u8 *vpn_ascii_id = 0;
1074  u32 oui = 0, fib_id = 0, tbl_id = ~0;
1075 
1076  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1077  {
1078  if (unformat (input, "table %d", &tbl_id))
1079  ;
1080  else if (unformat (input, "oui %d", &oui))
1081  vss_type = VSS_TYPE_VPN_ID;
1082  else if (unformat (input, "vpn-id %d", &fib_id))
1083  vss_type = VSS_TYPE_VPN_ID;
1084  else if (unformat (input, "vpn-ascii-id %s", &vpn_ascii_id))
1085  vss_type = VSS_TYPE_ASCII;
1086  else if (unformat (input, "delete") || unformat (input, "del"))
1087  is_del = 1;
1088  else
1089  break;
1090  }
1091 
1092  if (tbl_id == ~0)
1093  return clib_error_return (0, "no table ID specified.");
1094 
1095  int rv = dhcp_proxy_set_vss (FIB_PROTOCOL_IP6, tbl_id, vss_type,
1096  vpn_ascii_id, oui, fib_id, is_del);
1097  switch (rv)
1098  {
1099  case 0:
1100  return 0;
1101  case VNET_API_ERROR_NO_SUCH_ENTRY:
1102  return clib_error_return (0, "vss for table %d not found in pool.",
1103  tbl_id);
1104  default:
1105  return clib_error_return (0, "BUG: rv %d", rv);
1106  }
1107 }
1108 
1109 /* *INDENT-OFF* */
1110 VLIB_CLI_COMMAND (dhcpv6_proxy_vss_command, static) = {
1111  .path = "set dhcpv6 vss",
1112  .short_help = "set dhcpv6 vss table <table-id> [oui <n> vpn-id <n> | vpn-ascii-id <text>]",
1113  .function = dhcpv6_vss_command_fn,
1114 };
1115 /* *INDENT-ON* */
1116 
1117 static clib_error_t *
1119  unformat_input_t * input,
1120  vlib_cli_command_t * cmd)
1121 {
1123 
1124  return (NULL);
1125 }
1126 
1127 /* *INDENT-OFF* */
1128 VLIB_CLI_COMMAND (dhcpv6_proxy_vss_show_command, static) = {
1129  .path = "show dhcpv6 vss",
1130  .short_help = "show dhcpv6 VSS",
1131  .function = dhcpv6_vss_show_command_fn,
1132 };
1133 /* *INDENT-ON* */
1134 
1135 static clib_error_t *
1137  unformat_input_t * input,
1138  vlib_cli_command_t * cmd)
1139 {
1140  vnet_main_t *vnm = vnet_get_main ();
1141  u32 sw_if_index0 = 0, sw_if_index;
1142  vnet_sw_interface_t *swif;
1143  ip6_address_t *ia0;
1144 
1145  while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1146  {
1147 
1148  if (unformat (input, "%U",
1149  unformat_vnet_sw_interface, vnm, &sw_if_index0))
1150  {
1151  swif = vnet_get_sw_interface (vnm, sw_if_index0);
1152  sw_if_index = (swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) ?
1153  swif->unnumbered_sw_if_index : sw_if_index0;
1154  ia0 = ip6_interface_first_address (&ip6_main, sw_if_index);
1155  if (ia0)
1156  {
1157  vlib_cli_output (vm, "%=20s%=48s", "interface", "link-address");
1158 
1159  vlib_cli_output (vm, "%=20U%=48U",
1161  sw_if_index0, format_ip6_address, ia0);
1162  }
1163  else
1164  vlib_cli_output (vm, "%=34s%=20U",
1165  "No IPv6 address configured on",
1166  format_vnet_sw_if_index_name, vnm, sw_if_index);
1167  }
1168  else
1169  break;
1170  }
1171 
1172  return 0;
1173 }
1174 
1175 /* *INDENT-OFF* */
1176 VLIB_CLI_COMMAND (dhcpv6_proxy_address_show_command, static) = {
1177  .path = "show dhcpv6 link-address interface",
1178  .short_help = "show dhcpv6 link-address interface <interface>",
1180 };
1181 /* *INDENT-ON* */
1182 
1183 /*
1184  * fd.io coding-style-patch-verification: ON
1185  *
1186  * Local Variables:
1187  * eval: (c-set-style "gnu")
1188  * End:
1189  */
#define foreach_ip_interface_address(lm, a, sw_if_index, loop, body)
Definition: lookup.h:179
#define VNET_SW_INTERFACE_FLAG_UNNUMBERED
Definition: interface.h:668
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:356
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:467
static dhcp_vss_t * dhcp_get_vss_info(dhcp_proxy_main_t *dm, u32 rx_fib_index, fib_protocol_t proto)
Get the VSS data for the FIB index.
Definition: dhcp_proxy.h:237
#define CLIB_UNUSED(x)
Definition: clib.h:79
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:179
A representation of a path as described by a route producer.
Definition: fib_types.h:460
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:47
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:105
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
u8 as_u8[16]
Definition: ip6_packet.h:48
u64 as_u64[2]
Definition: ip6_packet.h:51
#define NULL
Definition: clib.h:55
u32 index
Definition: node.h:273
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:424
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
ip46_address_t dhcp_src_address
The source address to use in relayed messaes.
Definition: dhcp_proxy.h:120
The Virtual Sub-net Selection information for a given RX FIB.
Definition: dhcp_proxy.h:51
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:174
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:126
format_function_t format_ip46_address
Definition: format.h:61
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
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:165
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
dpo_proto_t frp_proto
The protocol of the address below.
Definition: fib_types.h:465
unformat_function_t unformat_vnet_sw_interface
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:59
vhost_vring_addr_t addr
Definition: vhost_user.h:116
ip6_address_t src_address
Definition: ip6_packet.h:347
format_function_t format_vnet_sw_if_index_name
unsigned char u8
Definition: types.h:56
static vlib_buffer_t * vlib_buffer_copy(vlib_main_t *vm, vlib_buffer_t *b)
Definition: buffer_funcs.h:715
static clib_error_t * dhcp6_proxy_init(vlib_main_t *vm)
static char * dhcpv6_proxy_error_strings[]
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:104
#define MFIB_RPF_ID_NONE
Definition: fib_types.h:383
dhcpv6_proxy_to_server_input_next_t
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:156
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:257
#define clib_error_return(e, args...)
Definition: error.h:99
#define VSS_TYPE_ASCII
Definition: dhcp_proxy.h:60
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, mfib_itf_flags_t itf_flags)
Add n paths to an entry (aka route) in the FIB.
Definition: mfib_table.c:219
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:63
static u32 vlib_get_buffer_index(vlib_main_t *vm, void *p)
Translate buffer pointer into buffer index.
Definition: buffer_funcs.h:141
#define fl(x, y)
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:89
Collection of global DHCP proxy data.
Definition: dhcp_proxy.h:134
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:464
vnet_sub_interface_t sub
Definition: interface.h:698
static clib_error_t * dhcpv6_proxy_show_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u16 current_length
Nbytes between current data and the end of this buffer.
Definition: buffer.h:108
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:558
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:191
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:202
#define PREDICT_FALSE(x)
Definition: clib.h:105
#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:587
#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:218
#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:364
Definition: ip6.h:79
static void vlib_node_increment_counter(vlib_main_t *vm, u32 node_index, u32 counter_index, u64 increment)
Definition: node_funcs.h:1168
unformat_function_t unformat_ip6_address
Definition: format.h:97
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:153
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
u8 * vpn_ascii_id
Type 0 ASCII VPN Identifier.
Definition: dhcp_proxy.h:71
u16 n_vectors
Definition: node.h:380
u32 ft_table_id
Table ID (hash key) for this FIB.
Definition: fib_table.h:89
format_function_t format_ip6_address
Definition: format.h:99
vlib_main_t * vm
Definition: buffer.c:294
void udp_unregister_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u8 is_ip4)
Definition: udp_local.c:530
static clib_error_t * dhcpv6_link_address_show_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define clib_memcpy(a, b, c)
Definition: string.h:75
A representation of a single DHCP Server within a given VRF config.
Definition: dhcp_proxy.h:77
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:454
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
Aggregrate type for a prefix.
Definition: mfib_types.h:24
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
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:910
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:492
ip46_address_t dhcp_server
The address of the DHCP server to which to relay the client&#39;s messages.
Definition: dhcp_proxy.h:83
#define ASSERT(truth)
ip6_main_t ip6_main
Definition: ip6_forward.c:2574
ip_lookup_main_t lookup_main
Definition: ip6.h:161
long ctx[MAX_CONNS]
Definition: main.c:126
static vlib_buffer_free_list_index_t vlib_buffer_get_free_list_index(vlib_buffer_t *b)
Definition: buffer_funcs.h:401
u32 table_id
Definition: ip6.h:82
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:215
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)
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
struct _vlib_node_registration vlib_node_registration_t
A DHCP proxy represenation fpr per-client VRF config.
Definition: dhcp_proxy.h:95
u32 ip_version_traffic_class_and_flow_label
Definition: ip6_packet.h:334
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:338
A for-us/local path.
Definition: fib_types.h:322
#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:67
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:267
#define VSS_TYPE_VPN_ID
Definition: dhcp_proxy.h:61
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:27
static ethernet_main_t * vnet_get_ethernet_main(void)
Definition: ethernet.h:550
static ip6_mfib_t * ip6_mfib_get(u32 index)
Get the FIB at the given index.
Definition: ip6_mfib.h:65
#define vnet_buffer(b)
Definition: buffer.h:360
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
vnet_sw_interface_type_t type
Definition: interface.h:656
u8 data[0]
Packet data.
Definition: buffer.h:172
#define vec_foreach(var, vec)
Vector iterator.
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:492
static vlib_buffer_free_list_t * vlib_buffer_get_free_list(vlib_main_t *vm, vlib_buffer_free_list_index_t free_list_index)
Definition: buffer_funcs.h:662
static void * ip_interface_address_get_address(ip_lookup_main_t *lm, ip_interface_address_t *a)
Definition: lookup.h:172
u16 fp_len
The mask length.
Definition: mfib_types.h:28
ethernet_interface_t * interfaces
Definition: ethernet.h:278
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:111
static int dhcp6_proxy_show_walk(dhcp_proxy_t *proxy, void *ctx)
#define ip46_address_is_zero(ip46)
Definition: ip6_packet.h:86
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:681
u32 * fib_index_by_sw_if_index
Definition: ip6.h:176
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57
static u8 * format_dhcp6_proxy_server(u8 *s, va_list *args)
const ip46_address_t zero_addr
Definition: lookup.c:318
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
Definition: defs.h:46
ip6_address_t dst_address
Definition: ip6_packet.h:347
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170
A protocol Independent FIB table.
Definition: fib_table.h:69
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)