buffers: remove free-list information from buffer metadata
[vpp.git] / src / vnet / dhcp / dhcp6_proxy_node.c
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,
28 #include <vnet/dhcp/dhcp6_proxy_error.def>
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,
41   foreach_dhcpv6_proxy_to_server_input_next
42 #undef _
43     DHCPV6_PROXY_TO_SERVER_INPUT_N_NEXT,
44 } dhcpv6_proxy_to_server_input_next_t;
45
46 typedef struct
47 {
48   /* 0 => to server, 1 => to client */
49   int which;
50   u8 packet_data[64];
51   u32 error;
52   u32 sw_if_index;
53   u32 original_sw_if_index;
54 } dhcpv6_proxy_trace_t;
55
56 static vlib_node_registration_t dhcpv6_proxy_to_server_node;
57 static vlib_node_registration_t dhcpv6_proxy_to_client_node;
58
59 /* all DHCP servers address */
60 static ip6_address_t all_dhcpv6_server_address;
61 static ip6_address_t all_dhcpv6_server_relay_agent_address;
62
63 static u8 *
64 format_dhcpv6_proxy_trace (u8 * s, va_list * args)
65 {
66   CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
67   CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
68   dhcpv6_proxy_trace_t *t = va_arg (*args, dhcpv6_proxy_trace_t *);
69
70   if (t->which == 0)
71     s = format (s, "DHCPV6 proxy: sent to server %U",
72                 format_ip6_address, &t->packet_data, sizeof (ip6_address_t));
73   else
74     s = format (s, "DHCPV6 proxy: sent to client from %U",
75                 format_ip6_address, &t->packet_data, sizeof (ip6_address_t));
76   if (t->error != (u32) ~ 0)
77     s = format (s, " error: %s\n", dhcpv6_proxy_error_strings[t->error]);
78
79   s = format (s, "  original_sw_if_index: %d, sw_if_index: %d\n",
80               t->original_sw_if_index, t->sw_if_index);
81
82   return s;
83 }
84
85 static u8 *
86 format_dhcpv6_proxy_header_with_length (u8 * s, va_list * args)
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 *
103 ip6_interface_first_global_or_site_address (ip6_main_t * im, u32 sw_if_index)
104 {
105   ip_lookup_main_t *lm = &im->lookup_main;
106   ip_interface_address_t *ia = 0;
107   ip6_address_t *result = 0;
108
109   /* *INDENT-OFF* */
110   foreach_ip_interface_address (lm, ia, sw_if_index,
111                                 1 /* honor unnumbered */,
112   ({
113     ip6_address_t * a = ip_interface_address_get_address (lm, ia);
114     if ((a->as_u8[0] & 0xe0) == 0x20 ||
115         (a->as_u8[0] & 0xfe) == 0xfc)  {
116         result = a;
117         break;
118     }
119   }));
120   /* *INDENT-ON* */
121   return result;
122 }
123
124 static inline void
125 copy_ip6_address (ip6_address_t * dst, ip6_address_t * src)
126 {
127   dst->as_u64[0] = src->as_u64[0];
128   dst->as_u64[1] = src->as_u64[1];
129 }
130
131 static uword
132 dhcpv6_proxy_to_server_input (vlib_main_t * vm,
133                               vlib_node_runtime_t * node,
134                               vlib_frame_t * from_frame)
135 {
136   u32 n_left_from, next_index, *from, *to_next;
137   dhcp_proxy_main_t *dpm = &dhcp_proxy_main;
138   from = vlib_frame_vector_args (from_frame);
139   n_left_from = from_frame->n_vectors;
140   u32 pkts_to_server = 0, pkts_to_client = 0, pkts_no_server = 0;
141   u32 pkts_no_interface_address = 0, pkts_no_exceeding_max_hop = 0;
142   u32 pkts_no_src_address = 0;
143   u32 pkts_wrong_msg_type = 0;
144   u32 pkts_too_big = 0;
145   ip6_main_t *im = &ip6_main;
146   ip6_address_t *src;
147   int bogus_length;
148   dhcp_proxy_t *proxy;
149   dhcp_server_t *server;
150   u32 rx_fib_idx = 0, server_fib_idx = 0;
151
152   next_index = node->cached_next_index;
153
154   while (n_left_from > 0)
155     {
156       u32 n_left_to_next;
157
158       vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
159
160       while (n_left_from > 0 && n_left_to_next > 0)
161         {
162           vnet_main_t *vnm = vnet_get_main ();
163           u32 sw_if_index = 0;
164           u32 rx_sw_if_index = 0;
165           vnet_sw_interface_t *swif;
166           u32 bi0;
167           vlib_buffer_t *b0;
168           udp_header_t *u0, *u1;
169           dhcpv6_header_t *h0;  // client msg hdr
170           ip6_header_t *ip0, *ip1;
171           ip6_address_t _ia0, *ia0 = &_ia0;
172           u32 next0;
173           u32 error0 = (u32) ~ 0;
174           dhcpv6_option_t *fwd_opt;
175           dhcpv6_relay_hdr_t *r1;
176           u16 len;
177           dhcpv6_int_id_t *id1;
178           dhcpv6_vss_t *vss1;
179           dhcpv6_client_mac_t *cmac;    // client mac
180           ethernet_header_t *e_h0;
181           u8 client_src_mac[6];
182           vlib_buffer_free_list_t *fl;
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:
212             case DHCPV6_MSG_INFORMATION_REQUEST:
213             case DHCPV6_MSG_RELAY_FORW:
214               /* send to server */
215               break;
216             case DHCPV6_MSG_RELAY_REPL:
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             {
277               error0 = DHCPV6_RELAY_PKT_DROP_MAX_HOPS;
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);
301           if (swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
302             sw_if_index = swif->unnumbered_sw_if_index;
303
304           ia0 =
305             ip6_interface_first_global_or_site_address (&ip6_main,
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 = vlib_buffer_get_free_list
319             (vm, VLIB_BUFFER_DEFAULT_FREE_LIST_INDEX);
320
321           if ((b0->current_length + sizeof (*id1) + sizeof (*vss1) +
322                sizeof (*cmac)) > fl->n_data_bytes)
323             {
324               error0 = DHCPV6_PROXY_ERROR_PKT_TOO_BIG;
325               next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
326               pkts_too_big++;
327               goto do_trace;
328             }
329
330           id1 = (dhcpv6_int_id_t *) (((uword) ip1) + b0->current_length);
331           b0->current_length += (sizeof (*id1));
332
333           id1->opt.option = clib_host_to_net_u16 (DHCPV6_OPTION_INTERFACE_ID);
334           id1->opt.length = clib_host_to_net_u16 (sizeof (rx_sw_if_index));
335           id1->int_idx = clib_host_to_net_u32 (rx_sw_if_index);
336
337           u1->length = 0;
338           if (h0->msg_type != DHCPV6_MSG_RELAY_FORW)
339             {
340               cmac =
341                 (dhcpv6_client_mac_t *) (((uword) ip1) + b0->current_length);
342               b0->current_length += (sizeof (*cmac));
343               cmac->opt.length = clib_host_to_net_u16 (sizeof (*cmac) -
344                                                        sizeof (cmac->opt));
345               cmac->opt.option =
346                 clib_host_to_net_u16
347                 (DHCPV6_OPTION_CLIENT_LINK_LAYER_ADDRESS);
348               cmac->link_type = clib_host_to_net_u16 (1);       /* ethernet */
349               clib_memcpy (cmac->data, client_src_mac, 6);
350               u1->length += sizeof (*cmac);
351             }
352
353           vss = dhcp_get_vss_info (dpm, rx_fib_idx, FIB_PROTOCOL_IP6);
354
355           if (vss)
356             {
357               u16 id_len;       /* length of VPN ID */
358               u16 type_len = sizeof (vss1->vss_type);
359
360               vss1 = (dhcpv6_vss_t *) (((uword) ip1) + b0->current_length);
361               vss1->vss_type = vss->vss_type;
362               if (vss->vss_type == VSS_TYPE_VPN_ID)
363                 {
364                   id_len = sizeof (vss->vpn_id);        /* vpn_id is 7 bytes */
365                   memcpy (vss1->data, vss->vpn_id, id_len);
366                 }
367               else if (vss->vss_type == VSS_TYPE_ASCII)
368                 {
369                   id_len = vec_len (vss->vpn_ascii_id);
370                   memcpy (vss1->data, vss->vpn_ascii_id, id_len);
371                 }
372               else              /* must be VSS_TYPE_DEFAULT, no VPN ID */
373                 id_len = 0;
374
375               vss1->opt.option = clib_host_to_net_u16 (DHCPV6_OPTION_VSS);
376               vss1->opt.length = clib_host_to_net_u16 (type_len + id_len);
377               u1->length += type_len + id_len + sizeof (vss1->opt);
378               b0->current_length += type_len + id_len + sizeof (vss1->opt);
379             }
380
381           pkts_to_server++;
382           u1->checksum = 0;
383           u1->src_port = clib_host_to_net_u16 (UDP_DST_PORT_dhcpv6_to_client);
384           u1->dst_port = clib_host_to_net_u16 (UDP_DST_PORT_dhcpv6_to_server);
385
386           u1->length =
387             clib_host_to_net_u16 (clib_net_to_host_u16 (fwd_opt->length) +
388                                   sizeof (*r1) + sizeof (*fwd_opt) +
389                                   sizeof (*u1) + sizeof (*id1) + u1->length);
390
391           clib_memset (ip1, 0, sizeof (*ip1));
392           ip1->ip_version_traffic_class_and_flow_label = 0x60;
393           ip1->payload_length = u1->length;
394           ip1->protocol = PROTO_UDP;
395           ip1->hop_limit = HOP_COUNT_LIMIT;
396           src = ((server->dhcp_server.ip6.as_u64[0] ||
397                   server->dhcp_server.ip6.as_u64[1]) ?
398                  &server->dhcp_server.ip6 : &all_dhcpv6_server_address);
399           copy_ip6_address (&ip1->dst_address, src);
400
401
402           ia0 = ip6_interface_first_global_or_site_address
403             (&ip6_main, vnet_buffer (b0)->sw_if_index[VLIB_RX]);
404
405           src = (proxy->dhcp_src_address.ip6.as_u64[0] ||
406                  proxy->dhcp_src_address.ip6.as_u64[1]) ?
407             &proxy->dhcp_src_address.ip6 : ia0;
408           if (ia0 == 0)
409             {
410               error0 = DHCPV6_PROXY_ERROR_NO_SRC_ADDRESS;
411               next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
412               pkts_no_src_address++;
413               goto do_trace;
414             }
415
416           copy_ip6_address (&ip1->src_address, src);
417
418
419           u1->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip1,
420                                                             &bogus_length);
421           ASSERT (bogus_length == 0);
422
423           next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP;
424
425           is_solicit = (DHCPV6_MSG_SOLICIT == h0->msg_type);
426
427           /*
428            * If we have multiple servers configured and this is the
429            * client's discover message, then send copies to each of
430            * those servers
431            */
432           if (is_solicit && vec_len (proxy->dhcp_servers) > 1)
433             {
434               u32 ii;
435
436               for (ii = 1; ii < vec_len (proxy->dhcp_servers); ii++)
437                 {
438                   vlib_buffer_t *c0;
439                   u32 ci0;
440
441                   c0 = vlib_buffer_copy (vm, b0);
442                   vlib_buffer_copy_trace_flag (vm, c0, bi0);
443                   VLIB_BUFFER_TRACE_TRAJECTORY_INIT (c0);
444                   ci0 = vlib_get_buffer_index (vm, c0);
445                   server = &proxy->dhcp_servers[ii];
446
447                   ip0 = vlib_buffer_get_current (c0);
448
449                   src = ((server->dhcp_server.ip6.as_u64[0] ||
450                           server->dhcp_server.ip6.as_u64[1]) ?
451                          &server->dhcp_server.ip6 :
452                          &all_dhcpv6_server_address);
453                   copy_ip6_address (&ip1->dst_address, src);
454
455                   to_next[0] = ci0;
456                   to_next += 1;
457                   n_left_to_next -= 1;
458
459                   vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
460                                                    to_next, n_left_to_next,
461                                                    ci0, next0);
462
463                   if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
464                     {
465                       dhcpv6_proxy_trace_t *tr;
466
467                       tr = vlib_add_trace (vm, node, c0, sizeof (*tr));
468                       tr->which = 0;    /* to server */
469                       tr->error = error0;
470                       tr->original_sw_if_index = rx_sw_if_index;
471                       tr->sw_if_index = sw_if_index;
472                       if (next0 == DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP)
473                         copy_ip6_address ((ip6_address_t *) &
474                                           tr->packet_data[0],
475                                           &server->dhcp_server.ip6);
476                     }
477
478                   if (PREDICT_FALSE (0 == n_left_to_next))
479                     {
480                       vlib_put_next_frame (vm, node, next_index,
481                                            n_left_to_next);
482                       vlib_get_next_frame (vm, node, next_index,
483                                            to_next, n_left_to_next);
484                     }
485                 }
486             }
487
488         do_trace:
489           if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
490             {
491               dhcpv6_proxy_trace_t *tr = vlib_add_trace (vm, node,
492                                                          b0, sizeof (*tr));
493               tr->which = 0;    /* to server */
494               tr->error = error0;
495               tr->original_sw_if_index = rx_sw_if_index;
496               tr->sw_if_index = sw_if_index;
497               if (DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP == next0)
498                 copy_ip6_address ((ip6_address_t *) & tr->packet_data[0],
499                                   &server->dhcp_server.ip6);
500             }
501
502         do_enqueue:
503           to_next[0] = bi0;
504           to_next += 1;
505           n_left_to_next -= 1;
506
507           vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
508                                            to_next, n_left_to_next,
509                                            bi0, next0);
510         }
511
512       vlib_put_next_frame (vm, node, next_index, n_left_to_next);
513     }
514
515   vlib_node_increment_counter (vm, dhcpv6_proxy_to_server_node.index,
516                                DHCPV6_PROXY_ERROR_RELAY_TO_CLIENT,
517                                pkts_to_client);
518   vlib_node_increment_counter (vm, dhcpv6_proxy_to_server_node.index,
519                                DHCPV6_PROXY_ERROR_RELAY_TO_SERVER,
520                                pkts_to_server);
521   vlib_node_increment_counter (vm, dhcpv6_proxy_to_server_node.index,
522                                DHCPV6_PROXY_ERROR_NO_INTERFACE_ADDRESS,
523                                pkts_no_interface_address);
524   vlib_node_increment_counter (vm, dhcpv6_proxy_to_server_node.index,
525                                DHCPV6_PROXY_ERROR_WRONG_MESSAGE_TYPE,
526                                pkts_wrong_msg_type);
527   vlib_node_increment_counter (vm, dhcpv6_proxy_to_server_node.index,
528                                DHCPV6_PROXY_ERROR_NO_SRC_ADDRESS,
529                                pkts_no_src_address);
530   vlib_node_increment_counter (vm, dhcpv6_proxy_to_server_node.index,
531                                DHCPV6_PROXY_ERROR_PKT_TOO_BIG, pkts_too_big);
532   return from_frame->n_vectors;
533 }
534
535 /* *INDENT-OFF* */
536 VLIB_REGISTER_NODE (dhcpv6_proxy_to_server_node, static) = {
537   .function = dhcpv6_proxy_to_server_input,
538   .name = "dhcpv6-proxy-to-server",
539   /* Takes a vector of packets. */
540   .vector_size = sizeof (u32),
541
542   .n_errors = DHCPV6_PROXY_N_ERROR,
543   .error_strings = dhcpv6_proxy_error_strings,
544
545   .n_next_nodes = DHCPV6_PROXY_TO_SERVER_INPUT_N_NEXT,
546   .next_nodes = {
547 #define _(s,n) [DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_##s] = n,
548     foreach_dhcpv6_proxy_to_server_input_next
549 #undef _
550   },
551
552   .format_buffer = format_dhcpv6_proxy_header_with_length,
553   .format_trace = format_dhcpv6_proxy_trace,
554 #if 0
555   .unformat_buffer = unformat_dhcpv6_proxy_header,
556 #endif
557 };
558 /* *INDENT-ON* */
559
560 static uword
561 dhcpv6_proxy_to_client_input (vlib_main_t * vm,
562                               vlib_node_runtime_t * node,
563                               vlib_frame_t * from_frame)
564 {
565
566   u32 n_left_from, *from;
567   ethernet_main_t *em = vnet_get_ethernet_main ();
568   dhcp_proxy_main_t *dm = &dhcp_proxy_main;
569   dhcp_proxy_t *proxy;
570   dhcp_server_t *server;
571   vnet_main_t *vnm = vnet_get_main ();
572   int bogus_length;
573
574   from = vlib_frame_vector_args (from_frame);
575   n_left_from = from_frame->n_vectors;
576
577   while (n_left_from > 0)
578     {
579       u32 bi0;
580       vlib_buffer_t *b0;
581       udp_header_t *u0, *u1 = 0;
582       dhcpv6_relay_hdr_t *h0;
583       ip6_header_t *ip1 = 0, *ip0;
584       ip6_address_t _ia0, *ia0 = &_ia0;
585       ip6_address_t client_address;
586       ethernet_interface_t *ei0;
587       ethernet_header_t *mac0;
588       vnet_hw_interface_t *hi0;
589       vlib_frame_t *f0;
590       u32 *to_next0;
591       u32 sw_if_index = ~0;
592       u32 original_sw_if_index = ~0;
593       vnet_sw_interface_t *si0;
594       u32 error0 = (u32) ~ 0;
595       vnet_sw_interface_t *swif;
596       dhcpv6_option_t *r0 = 0, *o;
597       u16 len = 0;
598       u8 interface_opt_flag = 0;
599       u8 relay_msg_opt_flag = 0;
600       ip6_main_t *im = &ip6_main;
601       u32 server_fib_idx, client_fib_idx;
602
603       bi0 = from[0];
604       from += 1;
605       n_left_from -= 1;
606
607       b0 = vlib_get_buffer (vm, bi0);
608       h0 = vlib_buffer_get_current (b0);
609
610       if (DHCPV6_MSG_RELAY_REPL != h0->msg_type)
611         {
612           error0 = DHCPV6_PROXY_ERROR_WRONG_MESSAGE_TYPE;
613
614         drop_packet:
615           vlib_node_increment_counter (vm, dhcpv6_proxy_to_client_node.index,
616                                        error0, 1);
617
618           f0 = vlib_get_frame_to_node (vm, dm->error_drop_node_index);
619           to_next0 = vlib_frame_vector_args (f0);
620           to_next0[0] = bi0;
621           f0->n_vectors = 1;
622           vlib_put_frame_to_node (vm, dm->error_drop_node_index, f0);
623           goto do_trace;
624         }
625       /* hop count seems not need to be checked */
626       if (HOP_COUNT_LIMIT < h0->hop_count)
627         {
628           error0 = DHCPV6_RELAY_PKT_DROP_MAX_HOPS;
629           goto drop_packet;
630         }
631       u0 = (void *) h0 - (sizeof (*u0));
632       ip0 = (void *) u0 - (sizeof (*ip0));
633
634       vlib_buffer_advance (b0, sizeof (*h0));
635       o = vlib_buffer_get_current (b0);
636
637       /* Parse through TLVs looking for option 18 (DHCPV6_OPTION_INTERFACE_ID)
638          _and_ option 9 (DHCPV6_OPTION_RELAY_MSG) option which must be there.
639          Currently assuming no other options need to be processed
640          The interface-ID is the FIB number we need
641          to track down the client-facing interface */
642
643       while ((u8 *) o < (b0->data + b0->current_data + b0->current_length))
644         {
645           if (DHCPV6_OPTION_INTERFACE_ID == clib_net_to_host_u16 (o->option))
646             {
647               interface_opt_flag = 1;
648               if (clib_net_to_host_u16 (o->length) == sizeof (sw_if_index))
649                 sw_if_index =
650                   clib_net_to_host_u32 (((dhcpv6_int_id_t *) o)->int_idx);
651               if (sw_if_index >= vec_len (im->fib_index_by_sw_if_index))
652                 {
653                   error0 = DHCPV6_PROXY_ERROR_WRONG_INTERFACE_ID_OPTION;
654                   goto drop_packet;
655                 }
656             }
657           if (DHCPV6_OPTION_RELAY_MSG == clib_net_to_host_u16 (o->option))
658             {
659               relay_msg_opt_flag = 1;
660               r0 = vlib_buffer_get_current (b0);
661             }
662           if ((relay_msg_opt_flag == 1) && (interface_opt_flag == 1))
663             break;
664           vlib_buffer_advance (b0,
665                                sizeof (*o) +
666                                clib_net_to_host_u16 (o->length));
667           o =
668             (dhcpv6_option_t *) (((uword) o) +
669                                  clib_net_to_host_u16 (o->length) +
670                                  sizeof (*o));
671         }
672
673       if ((relay_msg_opt_flag == 0) || (r0 == 0))
674         {
675           error0 = DHCPV6_PROXY_ERROR_NO_RELAY_MESSAGE_OPTION;
676           goto drop_packet;
677         }
678
679       if ((u32) ~ 0 == sw_if_index)
680         {
681           error0 = DHCPV6_PROXY_ERROR_NO_CIRCUIT_ID_OPTION;
682           goto drop_packet;
683         }
684
685       //Advance buffer to start of encapsulated DHCPv6 message
686       vlib_buffer_advance (b0, sizeof (*r0));
687
688       client_fib_idx = im->mfib_index_by_sw_if_index[sw_if_index];
689       proxy = dhcp_get_proxy (dm, client_fib_idx, FIB_PROTOCOL_IP6);
690
691       if (NULL == proxy)
692         {
693           error0 = DHCPV6_PROXY_ERROR_NO_SERVER;
694           goto drop_packet;
695         }
696
697       server_fib_idx = im->fib_index_by_sw_if_index
698         [vnet_buffer (b0)->sw_if_index[VLIB_RX]];
699
700       vec_foreach (server, proxy->dhcp_servers)
701       {
702         if (server_fib_idx == server->server_fib_index &&
703             ip0->src_address.as_u64[0] == server->dhcp_server.ip6.as_u64[0] &&
704             ip0->src_address.as_u64[1] == server->dhcp_server.ip6.as_u64[1])
705           {
706             goto server_found;
707           }
708       }
709
710       //drop packet if not from server with configured address or FIB
711       error0 = DHCPV6_PROXY_ERROR_BAD_SVR_FIB_OR_ADDRESS;
712       goto drop_packet;
713
714     server_found:
715       vnet_buffer (b0)->sw_if_index[VLIB_TX] = original_sw_if_index
716         = sw_if_index;
717
718       swif = vnet_get_sw_interface (vnm, original_sw_if_index);
719       if (swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
720         sw_if_index = swif->unnumbered_sw_if_index;
721
722
723       /*
724        * udp_local hands us the DHCPV6 header, need udp hdr,
725        * ip hdr to relay to client
726        */
727       vlib_buffer_advance (b0, -(sizeof (*u1)));
728       u1 = vlib_buffer_get_current (b0);
729
730       vlib_buffer_advance (b0, -(sizeof (*ip1)));
731       ip1 = vlib_buffer_get_current (b0);
732
733       copy_ip6_address (&client_address, &h0->peer_addr);
734
735       ia0 = ip6_interface_first_address (&ip6_main, sw_if_index);
736       if (ia0 == 0)
737         {
738           error0 = DHCPV6_PROXY_ERROR_NO_INTERFACE_ADDRESS;
739           goto drop_packet;
740         }
741
742       len = clib_net_to_host_u16 (r0->length);
743       clib_memset (ip1, 0, sizeof (*ip1));
744       copy_ip6_address (&ip1->dst_address, &client_address);
745       u1->checksum = 0;
746       u1->src_port = clib_net_to_host_u16 (UDP_DST_PORT_dhcpv6_to_server);
747       u1->dst_port = clib_net_to_host_u16 (UDP_DST_PORT_dhcpv6_to_client);
748       u1->length = clib_host_to_net_u16 (len + sizeof (udp_header_t));
749
750       ip1->ip_version_traffic_class_and_flow_label =
751         ip0->ip_version_traffic_class_and_flow_label & 0x00000fff;
752       ip1->payload_length = u1->length;
753       ip1->protocol = PROTO_UDP;
754       ip1->hop_limit = HOP_COUNT_LIMIT;
755       copy_ip6_address (&ip1->src_address, ia0);
756
757       u1->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip1,
758                                                         &bogus_length);
759       ASSERT (bogus_length == 0);
760
761       vlib_buffer_advance (b0, -(sizeof (ethernet_header_t)));
762       si0 = vnet_get_sw_interface (vnm, original_sw_if_index);
763       if (si0->type == VNET_SW_INTERFACE_TYPE_SUB)
764         vlib_buffer_advance (b0, -4 /* space for VLAN tag */ );
765
766       mac0 = vlib_buffer_get_current (b0);
767
768       hi0 = vnet_get_sup_hw_interface (vnm, original_sw_if_index);
769       ei0 = pool_elt_at_index (em->interfaces, hi0->hw_instance);
770       clib_memcpy (mac0->src_address, ei0->address, sizeof (ei0->address));
771       clib_memset (&mac0->dst_address, 0xff, sizeof (mac0->dst_address));
772       mac0->type = (si0->type == VNET_SW_INTERFACE_TYPE_SUB) ?
773         clib_net_to_host_u16 (0x8100) : clib_net_to_host_u16 (0x86dd);
774
775       if (si0->type == VNET_SW_INTERFACE_TYPE_SUB)
776         {
777           u32 *vlan_tag = (u32 *) (mac0 + 1);
778           u32 tmp;
779           tmp = (si0->sub.id << 16) | 0x0800;
780           *vlan_tag = clib_host_to_net_u32 (tmp);
781         }
782
783       /* $$$ consider adding a dynamic next to the graph node, for performance */
784       f0 = vlib_get_frame_to_node (vm, hi0->output_node_index);
785       to_next0 = vlib_frame_vector_args (f0);
786       to_next0[0] = bi0;
787       f0->n_vectors = 1;
788       vlib_put_frame_to_node (vm, hi0->output_node_index, f0);
789
790     do_trace:
791       if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
792         {
793           dhcpv6_proxy_trace_t *tr = vlib_add_trace (vm, node,
794                                                      b0, sizeof (*tr));
795           tr->which = 1;        /* to client */
796           if (ia0)
797             copy_ip6_address ((ip6_address_t *) tr->packet_data, ia0);
798           tr->error = error0;
799           tr->original_sw_if_index = original_sw_if_index;
800           tr->sw_if_index = sw_if_index;
801         }
802     }
803   return from_frame->n_vectors;
804
805 }
806
807 /* *INDENT-OFF* */
808 VLIB_REGISTER_NODE (dhcpv6_proxy_to_client_node, static) = {
809   .function = dhcpv6_proxy_to_client_input,
810   .name = "dhcpv6-proxy-to-client",
811   /* Takes a vector of packets. */
812   .vector_size = sizeof (u32),
813
814   .n_errors = DHCPV6_PROXY_N_ERROR,
815   .error_strings = dhcpv6_proxy_error_strings,
816   .format_buffer = format_dhcpv6_proxy_header_with_length,
817   .format_trace = format_dhcpv6_proxy_trace,
818 #if 0
819   .unformat_buffer = unformat_dhcpv6_proxy_header,
820 #endif
821 };
822 /* *INDENT-ON* */
823
824 static clib_error_t *
825 dhcp6_proxy_init (vlib_main_t * vm)
826 {
827   dhcp_proxy_main_t *dm = &dhcp_proxy_main;
828   vlib_node_t *error_drop_node;
829
830   error_drop_node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
831   dm->error_drop_node_index = error_drop_node->index;
832
833   /* RFC says this is the dhcpv6 server address  */
834   all_dhcpv6_server_address.as_u64[0] =
835     clib_host_to_net_u64 (0xFF05000000000000);
836   all_dhcpv6_server_address.as_u64[1] = clib_host_to_net_u64 (0x00010003);
837
838   /* RFC says this is the server and agent address */
839   all_dhcpv6_server_relay_agent_address.as_u64[0] =
840     clib_host_to_net_u64 (0xFF02000000000000);
841   all_dhcpv6_server_relay_agent_address.as_u64[1] =
842     clib_host_to_net_u64 (0x00010002);
843
844   return 0;
845 }
846
847 VLIB_INIT_FUNCTION (dhcp6_proxy_init);
848
849 int
850 dhcp6_proxy_set_server (ip46_address_t * addr,
851                         ip46_address_t * src_addr,
852                         u32 rx_table_id, u32 server_table_id, int is_del)
853 {
854   vlib_main_t *vm = vlib_get_main ();
855   u32 rx_fib_index = 0;
856   int rc = 0;
857
858   const mfib_prefix_t all_dhcp_servers = {
859     .fp_len = 128,
860     .fp_proto = FIB_PROTOCOL_IP6,
861     .fp_grp_addr = {
862                     .ip6 = all_dhcpv6_server_relay_agent_address,
863                     }
864   };
865
866   if (ip46_address_is_zero (addr))
867     return VNET_API_ERROR_INVALID_DST_ADDRESS;
868
869   if (ip46_address_is_zero (src_addr))
870     return VNET_API_ERROR_INVALID_SRC_ADDRESS;
871
872   rx_fib_index = mfib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
873                                                      rx_table_id,
874                                                      MFIB_SOURCE_DHCP);
875
876   if (is_del)
877     {
878       if (dhcp_proxy_server_del (FIB_PROTOCOL_IP6, rx_fib_index,
879                                  addr, server_table_id))
880         {
881           mfib_table_entry_delete (rx_fib_index,
882                                    &all_dhcp_servers, MFIB_SOURCE_DHCP);
883           mfib_table_unlock (rx_fib_index, FIB_PROTOCOL_IP6,
884                              MFIB_SOURCE_DHCP);
885
886           udp_unregister_dst_port (vm, UDP_DST_PORT_dhcpv6_to_client,
887                                    0 /* is_ip6 */ );
888           udp_unregister_dst_port (vm, UDP_DST_PORT_dhcpv6_to_server,
889                                    0 /* is_ip6 */ );
890         }
891     }
892   else
893     {
894       const fib_route_path_t path_for_us = {
895         .frp_proto = DPO_PROTO_IP6,
896         .frp_addr = zero_addr,
897         .frp_sw_if_index = 0xffffffff,
898         .frp_fib_index = ~0,
899         .frp_weight = 0,
900         .frp_flags = FIB_ROUTE_PATH_LOCAL,
901       };
902       if (dhcp_proxy_server_add (FIB_PROTOCOL_IP6, addr, src_addr,
903                                  rx_fib_index, server_table_id))
904         {
905           mfib_table_entry_path_update (rx_fib_index,
906                                         &all_dhcp_servers,
907                                         MFIB_SOURCE_DHCP,
908                                         &path_for_us, MFIB_ITF_FLAG_FORWARD);
909           /*
910            * Each interface that is enabled in this table, needs to be added
911            * as an accepting interface, but this is not easily doable in VPP.
912            * So we cheat. Add a flag to the entry that indicates accept form
913            * any interface.
914            * We will still only accept on v6 enabled interfaces, since the
915            * input feature ensures this.
916            */
917           mfib_table_entry_update (rx_fib_index,
918                                    &all_dhcp_servers,
919                                    MFIB_SOURCE_DHCP,
920                                    MFIB_RPF_ID_NONE,
921                                    MFIB_ENTRY_FLAG_ACCEPT_ALL_ITF);
922           mfib_table_lock (rx_fib_index, FIB_PROTOCOL_IP6, MFIB_SOURCE_DHCP);
923
924           udp_register_dst_port (vm, UDP_DST_PORT_dhcpv6_to_client,
925                                  dhcpv6_proxy_to_client_node.index,
926                                  0 /* is_ip6 */ );
927           udp_register_dst_port (vm, UDP_DST_PORT_dhcpv6_to_server,
928                                  dhcpv6_proxy_to_server_node.index,
929                                  0 /* is_ip6 */ );
930         }
931     }
932
933   mfib_table_unlock (rx_fib_index, FIB_PROTOCOL_IP6, MFIB_SOURCE_DHCP);
934
935   return (rc);
936 }
937
938 static clib_error_t *
939 dhcpv6_proxy_set_command_fn (vlib_main_t * vm,
940                              unformat_input_t * input,
941                              vlib_cli_command_t * cmd)
942 {
943   ip46_address_t addr, src_addr;
944   int set_server = 0, set_src_address = 0;
945   u32 rx_table_id = 0, server_table_id = 0;
946   int is_del = 0;
947
948   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
949     {
950       if (unformat (input, "server %U", unformat_ip6_address, &addr.ip6))
951         set_server = 1;
952       else if (unformat (input, "src-address %U",
953                          unformat_ip6_address, &src_addr.ip6))
954         set_src_address = 1;
955       else if (unformat (input, "server-fib-id %d", &server_table_id))
956         ;
957       else if (unformat (input, "rx-fib-id %d", &rx_table_id))
958         ;
959       else if (unformat (input, "delete") || unformat (input, "del"))
960         is_del = 1;
961       else
962         break;
963     }
964
965   if (is_del || (set_server && set_src_address))
966     {
967       int rv;
968
969       rv = dhcp6_proxy_set_server (&addr, &src_addr, rx_table_id,
970                                    server_table_id, is_del);
971
972       //TODO: Complete the errors
973       switch (rv)
974         {
975         case 0:
976           return 0;
977
978         case VNET_API_ERROR_INVALID_DST_ADDRESS:
979           return clib_error_return (0, "Invalid server address");
980
981         case VNET_API_ERROR_INVALID_SRC_ADDRESS:
982           return clib_error_return (0, "Invalid src address");
983
984         case VNET_API_ERROR_NO_SUCH_ENTRY:
985           return clib_error_return
986             (0, "Fib id %d: no per-fib DHCP server configured", rx_table_id);
987
988         default:
989           return clib_error_return (0, "BUG: rv %d", rv);
990         }
991     }
992   else
993     return clib_error_return (0, "parse error`%U'",
994                               format_unformat_error, input);
995 }
996
997 /* *INDENT-OFF* */
998 VLIB_CLI_COMMAND (dhcpv6_proxy_set_command, static) = {
999   .path = "set dhcpv6 proxy",
1000   .short_help = "set dhcpv6 proxy [del] server <ipv6-addr> src-address <ipv6-addr> "
1001                   "[server-fib-id <fib-id>] [rx-fib-id <fib-id>] ",
1002   .function = dhcpv6_proxy_set_command_fn,
1003 };
1004 /* *INDENT-ON* */
1005
1006 static u8 *
1007 format_dhcp6_proxy_server (u8 * s, va_list * args)
1008 {
1009   dhcp_proxy_t *proxy = va_arg (*args, dhcp_proxy_t *);
1010   fib_table_t *server_fib;
1011   dhcp_server_t *server;
1012   ip6_mfib_t *rx_fib;
1013
1014   if (proxy == 0)
1015     {
1016       s = format (s, "%=14s%=16s%s", "RX FIB", "Src Address",
1017                   "Servers FIB,Address");
1018       return s;
1019     }
1020
1021   rx_fib = ip6_mfib_get (proxy->rx_fib_index);
1022
1023   s = format (s, "%=14u%=16U",
1024               rx_fib->table_id,
1025               format_ip46_address, &proxy->dhcp_src_address, IP46_TYPE_ANY);
1026
1027   vec_foreach (server, proxy->dhcp_servers)
1028   {
1029     server_fib = fib_table_get (server->server_fib_index, FIB_PROTOCOL_IP6);
1030     s = format (s, "%u,%U  ",
1031                 server_fib->ft_table_id,
1032                 format_ip46_address, &server->dhcp_server, IP46_TYPE_ANY);
1033   }
1034
1035   return s;
1036 }
1037
1038 static int
1039 dhcp6_proxy_show_walk (dhcp_proxy_t * proxy, void *ctx)
1040 {
1041   vlib_main_t *vm = ctx;
1042
1043   vlib_cli_output (vm, "%U", format_dhcp6_proxy_server, proxy);
1044
1045   return (1);
1046 }
1047
1048 static clib_error_t *
1049 dhcpv6_proxy_show_command_fn (vlib_main_t * vm,
1050                               unformat_input_t * input,
1051                               vlib_cli_command_t * cmd)
1052 {
1053   vlib_cli_output (vm, "%U", format_dhcp6_proxy_server,
1054                    NULL /* header line */ );
1055
1056   dhcp_proxy_walk (FIB_PROTOCOL_IP6, dhcp6_proxy_show_walk, vm);
1057
1058   return (NULL);
1059 }
1060
1061 /* *INDENT-OFF* */
1062 VLIB_CLI_COMMAND (dhcpv6_proxy_show_command, static) = {
1063   .path = "show dhcpv6 proxy",
1064   .short_help = "Display dhcpv6 proxy info",
1065   .function = dhcpv6_proxy_show_command_fn,
1066 };
1067 /* *INDENT-ON* */
1068
1069 static clib_error_t *
1070 dhcpv6_vss_command_fn (vlib_main_t * vm,
1071                        unformat_input_t * input, vlib_cli_command_t * cmd)
1072 {
1073   u8 is_del = 0, vss_type = VSS_TYPE_DEFAULT;
1074   u8 *vpn_ascii_id = 0;
1075   u32 oui = 0, fib_id = 0, tbl_id = ~0;
1076
1077   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1078     {
1079       if (unformat (input, "table %d", &tbl_id))
1080         ;
1081       else if (unformat (input, "oui %d", &oui))
1082         vss_type = VSS_TYPE_VPN_ID;
1083       else if (unformat (input, "vpn-id %d", &fib_id))
1084         vss_type = VSS_TYPE_VPN_ID;
1085       else if (unformat (input, "vpn-ascii-id %s", &vpn_ascii_id))
1086         vss_type = VSS_TYPE_ASCII;
1087       else if (unformat (input, "delete") || unformat (input, "del"))
1088         is_del = 1;
1089       else
1090         break;
1091     }
1092
1093   if (tbl_id == ~0)
1094     return clib_error_return (0, "no table ID specified.");
1095
1096   int rv = dhcp_proxy_set_vss (FIB_PROTOCOL_IP6, tbl_id, vss_type,
1097                                vpn_ascii_id, oui, fib_id, is_del);
1098   switch (rv)
1099     {
1100     case 0:
1101       return 0;
1102     case VNET_API_ERROR_NO_SUCH_ENTRY:
1103       return clib_error_return (0, "vss for table %d not found in pool.",
1104                                 tbl_id);
1105     default:
1106       return clib_error_return (0, "BUG: rv %d", rv);
1107     }
1108 }
1109
1110 /* *INDENT-OFF* */
1111 VLIB_CLI_COMMAND (dhcpv6_proxy_vss_command, static) = {
1112   .path = "set dhcpv6 vss",
1113   .short_help = "set dhcpv6 vss table <table-id> [oui <n> vpn-id <n> | vpn-ascii-id <text>]",
1114   .function = dhcpv6_vss_command_fn,
1115 };
1116 /* *INDENT-ON* */
1117
1118 static clib_error_t *
1119 dhcpv6_vss_show_command_fn (vlib_main_t * vm,
1120                             unformat_input_t * input,
1121                             vlib_cli_command_t * cmd)
1122 {
1123   dhcp_vss_walk (FIB_PROTOCOL_IP6, dhcp_vss_show_walk, vm);
1124
1125   return (NULL);
1126 }
1127
1128 /* *INDENT-OFF* */
1129 VLIB_CLI_COMMAND (dhcpv6_proxy_vss_show_command, static) = {
1130   .path = "show dhcpv6 vss",
1131   .short_help = "show dhcpv6 VSS",
1132   .function = dhcpv6_vss_show_command_fn,
1133 };
1134 /* *INDENT-ON* */
1135
1136 static clib_error_t *
1137 dhcpv6_link_address_show_command_fn (vlib_main_t * vm,
1138                                      unformat_input_t * input,
1139                                      vlib_cli_command_t * cmd)
1140 {
1141   vnet_main_t *vnm = vnet_get_main ();
1142   u32 sw_if_index0 = 0, sw_if_index;
1143   vnet_sw_interface_t *swif;
1144   ip6_address_t *ia0;
1145
1146   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1147     {
1148
1149       if (unformat (input, "%U",
1150                     unformat_vnet_sw_interface, vnm, &sw_if_index0))
1151         {
1152           swif = vnet_get_sw_interface (vnm, sw_if_index0);
1153           sw_if_index = (swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) ?
1154             swif->unnumbered_sw_if_index : sw_if_index0;
1155           ia0 = ip6_interface_first_address (&ip6_main, sw_if_index);
1156           if (ia0)
1157             {
1158               vlib_cli_output (vm, "%=20s%=48s", "interface", "link-address");
1159
1160               vlib_cli_output (vm, "%=20U%=48U",
1161                                format_vnet_sw_if_index_name, vnm,
1162                                sw_if_index0, format_ip6_address, ia0);
1163             }
1164           else
1165             vlib_cli_output (vm, "%=34s%=20U",
1166                              "No IPv6 address configured on",
1167                              format_vnet_sw_if_index_name, vnm, sw_if_index);
1168         }
1169       else
1170         break;
1171     }
1172
1173   return 0;
1174 }
1175
1176 /* *INDENT-OFF* */
1177 VLIB_CLI_COMMAND (dhcpv6_proxy_address_show_command, static) = {
1178   .path = "show dhcpv6 link-address interface",
1179   .short_help = "show dhcpv6 link-address interface <interface>",
1180   .function = dhcpv6_link_address_show_command_fn,
1181 };
1182 /* *INDENT-ON* */
1183
1184 /*
1185  * fd.io coding-style-patch-verification: ON
1186  *
1187  * Local Variables:
1188  * eval: (c-set-style "gnu")
1189  * End:
1190  */