blob: 432bc8dbe68664a8fbb52194134f4fa63de431a3 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
Neale Ranns2dd68522017-02-16 03:38:59 -08002 * dhcp6_proxy_node.c: dhcpv6 proxy node processing
Ed Warnickecb9cada2015-12-08 15:45:58 -07003 *
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>
Neale Ranns2dd68522017-02-16 03:38:59 -080020#include <vnet/dhcp/dhcp_proxy.h>
21#include <vnet/dhcp/dhcp6_packet.h>
Neale Ranns32e1c012016-11-22 17:07:28 +000022#include <vnet/mfib/mfib_table.h>
23#include <vnet/mfib/ip6_mfib.h>
Neale Ranns630198f2017-05-22 09:20:20 -040024#include <vnet/fib/fib.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070025
khemendra kumar34719e32017-12-08 18:06:52 +053026static char *dhcpv6_proxy_error_strings[] = {
Ed Warnickecb9cada2015-12-08 15:45:58 -070027#define dhcpv6_proxy_error(n,s) s,
Neale Ranns2dd68522017-02-16 03:38:59 -080028#include <vnet/dhcp/dhcp6_proxy_error.def>
Ed Warnickecb9cada2015-12-08 15:45:58 -070029#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")
Wojciech Dec558d5eb2016-11-01 16:44:06 +010036
Ed Warnickecb9cada2015-12-08 15:45:58 -070037
khemendra kumar34719e32017-12-08 18:06:52 +053038typedef enum
39{
Ed Warnickecb9cada2015-12-08 15:45:58 -070040#define _(s,n) DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_##s,
41 foreach_dhcpv6_proxy_to_server_input_next
42#undef _
khemendra kumar34719e32017-12-08 18:06:52 +053043 DHCPV6_PROXY_TO_SERVER_INPUT_N_NEXT,
Ed Warnickecb9cada2015-12-08 15:45:58 -070044} dhcpv6_proxy_to_server_input_next_t;
45
khemendra kumar34719e32017-12-08 18:06:52 +053046typedef struct
47{
Ed Warnickecb9cada2015-12-08 15:45:58 -070048 /* 0 => to server, 1 => to client */
Wojciech Dec558d5eb2016-11-01 16:44:06 +010049 int which;
50 u8 packet_data[64];
Ed Warnickecb9cada2015-12-08 15:45:58 -070051 u32 error;
52 u32 sw_if_index;
53 u32 original_sw_if_index;
54} dhcpv6_proxy_trace_t;
55
Neale Ranns2dd68522017-02-16 03:38:59 -080056static vlib_node_registration_t dhcpv6_proxy_to_server_node;
57static vlib_node_registration_t dhcpv6_proxy_to_client_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -070058
Neale Ranns2dd68522017-02-16 03:38:59 -080059/* all DHCP servers address */
60static ip6_address_t all_dhcpv6_server_address;
61static ip6_address_t all_dhcpv6_server_relay_agent_address;
Ed Warnickecb9cada2015-12-08 15:45:58 -070062
Neale Ranns2dd68522017-02-16 03:38:59 -080063static u8 *
64format_dhcpv6_proxy_trace (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070065{
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 *);
khemendra kumar34719e32017-12-08 18:06:52 +053068 dhcpv6_proxy_trace_t *t = va_arg (*args, dhcpv6_proxy_trace_t *);
Wojciech Dec558d5eb2016-11-01 16:44:06 +010069
Ed Warnickecb9cada2015-12-08 15:45:58 -070070 if (t->which == 0)
71 s = format (s, "DHCPV6 proxy: sent to server %U",
khemendra kumar34719e32017-12-08 18:06:52 +053072 format_ip6_address, &t->packet_data, sizeof (ip6_address_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -070073 else
74 s = format (s, "DHCPV6 proxy: sent to client from %U",
khemendra kumar34719e32017-12-08 18:06:52 +053075 format_ip6_address, &t->packet_data, sizeof (ip6_address_t));
76 if (t->error != (u32) ~ 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -070077 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",
khemendra kumar34719e32017-12-08 18:06:52 +053080 t->original_sw_if_index, t->sw_if_index);
Wojciech Dec558d5eb2016-11-01 16:44:06 +010081
Ed Warnickecb9cada2015-12-08 15:45:58 -070082 return s;
83}
84
Neale Ranns2dd68522017-02-16 03:38:59 -080085static u8 *
86format_dhcpv6_proxy_header_with_length (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070087{
khemendra kumar34719e32017-12-08 18:06:52 +053088 dhcpv6_header_t *h = va_arg (*args, dhcpv6_header_t *);
Ed Warnickecb9cada2015-12-08 15:45:58 -070089 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}
khemendra kumar34719e32017-12-08 18:06:52 +0530100
Ed Warnickecb9cada2015-12-08 15:45:58 -0700101/* get first interface address */
102static ip6_address_t *
103ip6_interface_first_global_or_site_address (ip6_main_t * im, u32 sw_if_index)
104{
khemendra kumar34719e32017-12-08 18:06:52 +0530105 ip_lookup_main_t *lm = &im->lookup_main;
106 ip_interface_address_t *ia = 0;
107 ip6_address_t *result = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700108
khemendra kumar34719e32017-12-08 18:06:52 +0530109 /* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700110 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 }));
khemendra kumar34719e32017-12-08 18:06:52 +0530120 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700121 return result;
122}
123
khemendra kumar34719e32017-12-08 18:06:52 +0530124static inline void
125copy_ip6_address (ip6_address_t * dst, ip6_address_t * src)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700126{
Ed Warnickecb9cada2015-12-08 15:45:58 -0700127 dst->as_u64[0] = src->as_u64[0];
128 dst->as_u64[1] = src->as_u64[1];
khemendra kumar34719e32017-12-08 18:06:52 +0530129}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700130
131static uword
132dhcpv6_proxy_to_server_input (vlib_main_t * vm,
khemendra kumar34719e32017-12-08 18:06:52 +0530133 vlib_node_runtime_t * node,
134 vlib_frame_t * from_frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700135{
khemendra kumar34719e32017-12-08 18:06:52 +0530136 u32 n_left_from, next_index, *from, *to_next;
137 dhcp_proxy_main_t *dpm = &dhcp_proxy_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700138 from = vlib_frame_vector_args (from_frame);
139 n_left_from = from_frame->n_vectors;
khemendra kumar34719e32017-12-08 18:06:52 +0530140 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;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700147 int bogus_length;
Neale Ranns3466c302017-02-16 07:45:03 -0800148 dhcp_proxy_t *proxy;
149 dhcp_server_t *server;
khemendra kumar34719e32017-12-08 18:06:52 +0530150 u32 rx_fib_idx = 0, server_fib_idx = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700151
152 next_index = node->cached_next_index;
153
154 while (n_left_from > 0)
155 {
156 u32 n_left_to_next;
157
khemendra kumar34719e32017-12-08 18:06:52 +0530158 vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700159
160 while (n_left_from > 0 && n_left_to_next > 0)
161 {
khemendra kumar34719e32017-12-08 18:06:52 +0530162 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;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700172 u32 next0;
khemendra kumar34719e32017-12-08 18:06:52 +0530173 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;
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100185
Ed Warnickecb9cada2015-12-08 15:45:58 -0700186 bi0 = from[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700187 from += 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700188 n_left_from -= 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700189
190 b0 = vlib_get_buffer (vm, bi0);
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100191
khemendra kumar34719e32017-12-08 18:06:52 +0530192 h0 = vlib_buffer_get_current (b0);
Chris Luke194ebc52016-04-25 14:26:55 -0400193
khemendra kumar34719e32017-12-08 18:06:52 +0530194 /*
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);
Chris Luke194ebc52016-04-25 14:26:55 -0400200
khemendra kumar34719e32017-12-08 18:06:52 +0530201 clib_memcpy (client_src_mac, e_h0->src_address, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700202
Juraj Sloboda81119e82018-05-25 14:02:20 +0200203 switch (h0->msg_type)
khemendra kumar34719e32017-12-08 18:06:52 +0530204 {
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;
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100228
khemendra kumar34719e32017-12-08 18:06:52 +0530229 }
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100230
khemendra kumar34719e32017-12-08 18:06:52 +0530231 /* 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);
Neale Ranns3bd11d72017-01-16 18:09:40 +0100236
khemendra kumar34719e32017-12-08 18:06:52 +0530237 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 }
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100244
khemendra kumar34719e32017-12-08 18:06:52 +0530245 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;
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100248
249
khemendra kumar34719e32017-12-08 18:06:52 +0530250 /* 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);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700256
khemendra kumar34719e32017-12-08 18:06:52 +0530257 vlib_buffer_advance (b0, -(sizeof (*u1)));
258 u1 = vlib_buffer_get_current (b0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700259
khemendra kumar34719e32017-12-08 18:06:52 +0530260 vlib_buffer_advance (b0, -(sizeof (*ip1)));
261 ip1 = vlib_buffer_get_current (b0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700262
khemendra kumar34719e32017-12-08 18:06:52 +0530263 /* 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);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700266
khemendra kumar34719e32017-12-08 18:06:52 +0530267 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);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700270
khemendra kumar34719e32017-12-08 18:06:52 +0530271 r1->hop_count++;
272 r1->hop_count =
Juraj Sloboda81119e82018-05-25 14:02:20 +0200273 (h0->msg_type != DHCPV6_MSG_RELAY_FORW) ? 0 : r1->hop_count;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700274
khemendra kumar34719e32017-12-08 18:06:52 +0530275 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 }
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100282
Ed Warnickecb9cada2015-12-08 15:45:58 -0700283
khemendra kumar34719e32017-12-08 18:06:52 +0530284 /* If relay-fwd and src address is site or global unicast address */
Juraj Sloboda81119e82018-05-25 14:02:20 +0200285 if (h0->msg_type == DHCPV6_MSG_RELAY_FORW &&
khemendra kumar34719e32017-12-08 18:06:52 +0530286 ((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 }
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100294
khemendra kumar34719e32017-12-08 18:06:52 +0530295 /* 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 */
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100299
khemendra kumar34719e32017-12-08 18:06:52 +0530300 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;
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100303
khemendra kumar34719e32017-12-08 18:06:52 +0530304 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 }
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100314
khemendra kumar34719e32017-12-08 18:06:52 +0530315 copy_ip6_address (&r1->link_addr, ia0);
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100316
khemendra kumar34719e32017-12-08 18:06:52 +0530317 link_address_set:
318 fl =
319 vlib_buffer_get_free_list (vm,
320 vlib_buffer_get_free_list_index (b0));
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100321
khemendra kumar34719e32017-12-08 18:06:52 +0530322 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 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700330
khemendra kumar34719e32017-12-08 18:06:52 +0530331 id1 = (dhcpv6_int_id_t *) (((uword) ip1) + b0->current_length);
332 b0->current_length += (sizeof (*id1));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700333
khemendra kumar34719e32017-12-08 18:06:52 +0530334 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);
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100337
khemendra kumar34719e32017-12-08 18:06:52 +0530338 u1->length = 0;
Juraj Sloboda81119e82018-05-25 14:02:20 +0200339 if (h0->msg_type != DHCPV6_MSG_RELAY_FORW)
khemendra kumar34719e32017-12-08 18:06:52 +0530340 {
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 }
Neale Ranns20a175a2017-02-14 07:28:41 -0800353
khemendra kumar34719e32017-12-08 18:06:52 +0530354 vss = dhcp_get_vss_info (dpm, rx_fib_idx, FIB_PROTOCOL_IP6);
Neale Ranns20a175a2017-02-14 07:28:41 -0800355
khemendra kumar34719e32017-12-08 18:06:52 +0530356 if (vss)
John Lo70bfcaf2017-11-14 13:19:26 -0500357 {
358 u16 id_len; /* length of VPN ID */
359 u16 type_len = sizeof (vss1->vss_type);
360
khemendra kumar34719e32017-12-08 18:06:52 +0530361 vss1 = (dhcpv6_vss_t *) (((uword) ip1) + b0->current_length);
John Lo70bfcaf2017-11-14 13:19:26 -0500362 vss1->vss_type = vss->vss_type;
363 if (vss->vss_type == VSS_TYPE_VPN_ID)
khemendra kumar34719e32017-12-08 18:06:52 +0530364 {
John Lo70bfcaf2017-11-14 13:19:26 -0500365 id_len = sizeof (vss->vpn_id); /* vpn_id is 7 bytes */
366 memcpy (vss1->data, vss->vpn_id, id_len);
khemendra kumar34719e32017-12-08 18:06:52 +0530367 }
John Lo70bfcaf2017-11-14 13:19:26 -0500368 else if (vss->vss_type == VSS_TYPE_ASCII)
khemendra kumar34719e32017-12-08 18:06:52 +0530369 {
John Lo70bfcaf2017-11-14 13:19:26 -0500370 id_len = vec_len (vss->vpn_ascii_id);
371 memcpy (vss1->data, vss->vpn_ascii_id, id_len);
khemendra kumar34719e32017-12-08 18:06:52 +0530372 }
373 else /* must be VSS_TYPE_DEFAULT, no VPN ID */
John Lo70bfcaf2017-11-14 13:19:26 -0500374 id_len = 0;
375
khemendra kumar34719e32017-12-08 18:06:52 +0530376 vss1->opt.option = clib_host_to_net_u16 (DHCPV6_OPTION_VSS);
John Lo70bfcaf2017-11-14 13:19:26 -0500377 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);
khemendra kumar34719e32017-12-08 18:06:52 +0530380 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700381
khemendra kumar34719e32017-12-08 18:06:52 +0530382 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);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700386
khemendra kumar34719e32017-12-08 18:06:52 +0530387 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);
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100391
Dave Barachb7b92992018-10-17 10:38:51 -0400392 clib_memset (ip1, 0, sizeof (*ip1));
khemendra kumar34719e32017-12-08 18:06:52 +0530393 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);
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100401
Ed Warnickecb9cada2015-12-08 15:45:58 -0700402
khemendra kumar34719e32017-12-08 18:06:52 +0530403 ia0 = ip6_interface_first_global_or_site_address
404 (&ip6_main, vnet_buffer (b0)->sw_if_index[VLIB_RX]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700405
khemendra kumar34719e32017-12-08 18:06:52 +0530406 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 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700416
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100417 copy_ip6_address (&ip1->src_address, src);
418
419
khemendra kumar34719e32017-12-08 18:06:52 +0530420 u1->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip1,
421 &bogus_length);
422 ASSERT (bogus_length == 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700423
khemendra kumar34719e32017-12-08 18:06:52 +0530424 next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700425
Juraj Sloboda81119e82018-05-25 14:02:20 +0200426 is_solicit = (DHCPV6_MSG_SOLICIT == h0->msg_type);
Neale Ranns3466c302017-02-16 07:45:03 -0800427
khemendra kumar34719e32017-12-08 18:06:52 +0530428 /*
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;
Neale Ranns3466c302017-02-16 07:45:03 -0800436
khemendra kumar34719e32017-12-08 18:06:52 +0530437 for (ii = 1; ii < vec_len (proxy->dhcp_servers); ii++)
438 {
439 vlib_buffer_t *c0;
440 u32 ci0;
Neale Ranns3466c302017-02-16 07:45:03 -0800441
khemendra kumar34719e32017-12-08 18:06:52 +0530442 c0 = vlib_buffer_copy (vm, b0);
Ole Troane87865d2018-11-29 12:39:41 +0100443 vlib_buffer_copy_trace_flag (vm, c0, bi0);
444 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (c0);
khemendra kumar34719e32017-12-08 18:06:52 +0530445 ci0 = vlib_get_buffer_index (vm, c0);
446 server = &proxy->dhcp_servers[ii];
Neale Ranns3466c302017-02-16 07:45:03 -0800447
khemendra kumar34719e32017-12-08 18:06:52 +0530448 ip0 = vlib_buffer_get_current (c0);
Neale Ranns3466c302017-02-16 07:45:03 -0800449
khemendra kumar34719e32017-12-08 18:06:52 +0530450 src = ((server->dhcp_server.ip6.as_u64[0] ||
451 server->dhcp_server.ip6.as_u64[1]) ?
452 &server->dhcp_server.ip6 :
453 &all_dhcpv6_server_address);
454 copy_ip6_address (&ip1->dst_address, src);
Neale Ranns3466c302017-02-16 07:45:03 -0800455
khemendra kumar34719e32017-12-08 18:06:52 +0530456 to_next[0] = ci0;
457 to_next += 1;
458 n_left_to_next -= 1;
Neale Ranns3466c302017-02-16 07:45:03 -0800459
khemendra kumar34719e32017-12-08 18:06:52 +0530460 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
461 to_next, n_left_to_next,
462 ci0, next0);
Neale Ranns3466c302017-02-16 07:45:03 -0800463
khemendra kumar34719e32017-12-08 18:06:52 +0530464 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
465 {
466 dhcpv6_proxy_trace_t *tr;
Neale Ranns3466c302017-02-16 07:45:03 -0800467
khemendra kumar34719e32017-12-08 18:06:52 +0530468 tr = vlib_add_trace (vm, node, c0, sizeof (*tr));
469 tr->which = 0; /* to server */
470 tr->error = error0;
471 tr->original_sw_if_index = rx_sw_if_index;
472 tr->sw_if_index = sw_if_index;
473 if (next0 == DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP)
474 copy_ip6_address ((ip6_address_t *) &
475 tr->packet_data[0],
476 &server->dhcp_server.ip6);
477 }
Neale Ranns3466c302017-02-16 07:45:03 -0800478
khemendra kumar34719e32017-12-08 18:06:52 +0530479 if (PREDICT_FALSE (0 == n_left_to_next))
480 {
481 vlib_put_next_frame (vm, node, next_index,
482 n_left_to_next);
483 vlib_get_next_frame (vm, node, next_index,
484 to_next, n_left_to_next);
485 }
486 }
487 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700488
khemendra kumar34719e32017-12-08 18:06:52 +0530489 do_trace:
490 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
491 {
492 dhcpv6_proxy_trace_t *tr = vlib_add_trace (vm, node,
493 b0, sizeof (*tr));
494 tr->which = 0; /* to server */
495 tr->error = error0;
496 tr->original_sw_if_index = rx_sw_if_index;
497 tr->sw_if_index = sw_if_index;
498 if (DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP == next0)
499 copy_ip6_address ((ip6_address_t *) & tr->packet_data[0],
500 &server->dhcp_server.ip6);
501 }
502
503 do_enqueue:
Neale Ranns3466c302017-02-16 07:45:03 -0800504 to_next[0] = bi0;
505 to_next += 1;
506 n_left_to_next -= 1;
507
Ed Warnickecb9cada2015-12-08 15:45:58 -0700508 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
509 to_next, n_left_to_next,
510 bi0, next0);
511 }
512
513 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
514 }
515
516 vlib_node_increment_counter (vm, dhcpv6_proxy_to_server_node.index,
khemendra kumar34719e32017-12-08 18:06:52 +0530517 DHCPV6_PROXY_ERROR_RELAY_TO_CLIENT,
518 pkts_to_client);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700519 vlib_node_increment_counter (vm, dhcpv6_proxy_to_server_node.index,
khemendra kumar34719e32017-12-08 18:06:52 +0530520 DHCPV6_PROXY_ERROR_RELAY_TO_SERVER,
521 pkts_to_server);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700522 vlib_node_increment_counter (vm, dhcpv6_proxy_to_server_node.index,
khemendra kumar34719e32017-12-08 18:06:52 +0530523 DHCPV6_PROXY_ERROR_NO_INTERFACE_ADDRESS,
524 pkts_no_interface_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700525 vlib_node_increment_counter (vm, dhcpv6_proxy_to_server_node.index,
khemendra kumar34719e32017-12-08 18:06:52 +0530526 DHCPV6_PROXY_ERROR_WRONG_MESSAGE_TYPE,
527 pkts_wrong_msg_type);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700528 vlib_node_increment_counter (vm, dhcpv6_proxy_to_server_node.index,
khemendra kumar34719e32017-12-08 18:06:52 +0530529 DHCPV6_PROXY_ERROR_NO_SRC_ADDRESS,
530 pkts_no_src_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700531 vlib_node_increment_counter (vm, dhcpv6_proxy_to_server_node.index,
khemendra kumar34719e32017-12-08 18:06:52 +0530532 DHCPV6_PROXY_ERROR_PKT_TOO_BIG, pkts_too_big);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700533 return from_frame->n_vectors;
534}
535
khemendra kumar34719e32017-12-08 18:06:52 +0530536/* *INDENT-OFF* */
Neale Ranns2dd68522017-02-16 03:38:59 -0800537VLIB_REGISTER_NODE (dhcpv6_proxy_to_server_node, static) = {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700538 .function = dhcpv6_proxy_to_server_input,
539 .name = "dhcpv6-proxy-to-server",
540 /* Takes a vector of packets. */
541 .vector_size = sizeof (u32),
542
543 .n_errors = DHCPV6_PROXY_N_ERROR,
544 .error_strings = dhcpv6_proxy_error_strings,
545
546 .n_next_nodes = DHCPV6_PROXY_TO_SERVER_INPUT_N_NEXT,
547 .next_nodes = {
548#define _(s,n) [DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_##s] = n,
549 foreach_dhcpv6_proxy_to_server_input_next
550#undef _
551 },
552
553 .format_buffer = format_dhcpv6_proxy_header_with_length,
554 .format_trace = format_dhcpv6_proxy_trace,
555#if 0
556 .unformat_buffer = unformat_dhcpv6_proxy_header,
557#endif
558};
khemendra kumar34719e32017-12-08 18:06:52 +0530559/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700560
561static uword
562dhcpv6_proxy_to_client_input (vlib_main_t * vm,
khemendra kumar34719e32017-12-08 18:06:52 +0530563 vlib_node_runtime_t * node,
564 vlib_frame_t * from_frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700565{
566
khemendra kumar34719e32017-12-08 18:06:52 +0530567 u32 n_left_from, *from;
Matthew Smith7a192832018-02-10 11:11:45 -0600568 ethernet_main_t *em = vnet_get_ethernet_main ();
khemendra kumar34719e32017-12-08 18:06:52 +0530569 dhcp_proxy_main_t *dm = &dhcp_proxy_main;
Neale Ranns3466c302017-02-16 07:45:03 -0800570 dhcp_proxy_t *proxy;
571 dhcp_server_t *server;
khemendra kumar34719e32017-12-08 18:06:52 +0530572 vnet_main_t *vnm = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -0700573 int bogus_length;
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100574
Ed Warnickecb9cada2015-12-08 15:45:58 -0700575 from = vlib_frame_vector_args (from_frame);
576 n_left_from = from_frame->n_vectors;
577
578 while (n_left_from > 0)
579 {
580 u32 bi0;
khemendra kumar34719e32017-12-08 18:06:52 +0530581 vlib_buffer_t *b0;
582 udp_header_t *u0, *u1 = 0;
583 dhcpv6_relay_hdr_t *h0;
584 ip6_header_t *ip1 = 0, *ip0;
585 ip6_address_t _ia0, *ia0 = &_ia0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700586 ip6_address_t client_address;
587 ethernet_interface_t *ei0;
588 ethernet_header_t *mac0;
589 vnet_hw_interface_t *hi0;
590 vlib_frame_t *f0;
khemendra kumar34719e32017-12-08 18:06:52 +0530591 u32 *to_next0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700592 u32 sw_if_index = ~0;
593 u32 original_sw_if_index = ~0;
594 vnet_sw_interface_t *si0;
khemendra kumar34719e32017-12-08 18:06:52 +0530595 u32 error0 = (u32) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700596 vnet_sw_interface_t *swif;
Wojciech Dec96e6f952016-10-20 11:25:37 +0200597 dhcpv6_option_t *r0 = 0, *o;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700598 u16 len = 0;
Wojciech Dec96e6f952016-10-20 11:25:37 +0200599 u8 interface_opt_flag = 0;
600 u8 relay_msg_opt_flag = 0;
khemendra kumar34719e32017-12-08 18:06:52 +0530601 ip6_main_t *im = &ip6_main;
Neale Ranns20a175a2017-02-14 07:28:41 -0800602 u32 server_fib_idx, client_fib_idx;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700603
604 bi0 = from[0];
605 from += 1;
606 n_left_from -= 1;
Wojciech Dec96e6f952016-10-20 11:25:37 +0200607
Ed Warnickecb9cada2015-12-08 15:45:58 -0700608 b0 = vlib_get_buffer (vm, bi0);
609 h0 = vlib_buffer_get_current (b0);
610
611 if (DHCPV6_MSG_RELAY_REPL != h0->msg_type)
khemendra kumar34719e32017-12-08 18:06:52 +0530612 {
613 error0 = DHCPV6_PROXY_ERROR_WRONG_MESSAGE_TYPE;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700614
khemendra kumar34719e32017-12-08 18:06:52 +0530615 drop_packet:
616 vlib_node_increment_counter (vm, dhcpv6_proxy_to_client_node.index,
617 error0, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700618
khemendra kumar34719e32017-12-08 18:06:52 +0530619 f0 = vlib_get_frame_to_node (vm, dm->error_drop_node_index);
620 to_next0 = vlib_frame_vector_args (f0);
621 to_next0[0] = bi0;
622 f0->n_vectors = 1;
623 vlib_put_frame_to_node (vm, dm->error_drop_node_index, f0);
624 goto do_trace;
625 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700626 /* hop count seems not need to be checked */
627 if (HOP_COUNT_LIMIT < h0->hop_count)
khemendra kumar34719e32017-12-08 18:06:52 +0530628 {
629 error0 = DHCPV6_RELAY_PKT_DROP_MAX_HOPS;
630 goto drop_packet;
631 }
632 u0 = (void *) h0 - (sizeof (*u0));
633 ip0 = (void *) u0 - (sizeof (*ip0));
Wojciech Dec96e6f952016-10-20 11:25:37 +0200634
khemendra kumar34719e32017-12-08 18:06:52 +0530635 vlib_buffer_advance (b0, sizeof (*h0));
Wojciech Dec96e6f952016-10-20 11:25:37 +0200636 o = vlib_buffer_get_current (b0);
637
638 /* Parse through TLVs looking for option 18 (DHCPV6_OPTION_INTERFACE_ID)
639 _and_ option 9 (DHCPV6_OPTION_RELAY_MSG) option which must be there.
640 Currently assuming no other options need to be processed
Ed Warnickecb9cada2015-12-08 15:45:58 -0700641 The interface-ID is the FIB number we need
642 to track down the client-facing interface */
Wojciech Dec96e6f952016-10-20 11:25:37 +0200643
Ed Warnickecb9cada2015-12-08 15:45:58 -0700644 while ((u8 *) o < (b0->data + b0->current_data + b0->current_length))
khemendra kumar34719e32017-12-08 18:06:52 +0530645 {
646 if (DHCPV6_OPTION_INTERFACE_ID == clib_net_to_host_u16 (o->option))
647 {
648 interface_opt_flag = 1;
649 if (clib_net_to_host_u16 (o->length) == sizeof (sw_if_index))
650 sw_if_index =
651 clib_net_to_host_u32 (((dhcpv6_int_id_t *) o)->int_idx);
652 if (sw_if_index >= vec_len (im->fib_index_by_sw_if_index))
653 {
654 error0 = DHCPV6_PROXY_ERROR_WRONG_INTERFACE_ID_OPTION;
655 goto drop_packet;
656 }
657 }
658 if (DHCPV6_OPTION_RELAY_MSG == clib_net_to_host_u16 (o->option))
659 {
660 relay_msg_opt_flag = 1;
661 r0 = vlib_buffer_get_current (b0);
662 }
663 if ((relay_msg_opt_flag == 1) && (interface_opt_flag == 1))
664 break;
665 vlib_buffer_advance (b0,
666 sizeof (*o) +
667 clib_net_to_host_u16 (o->length));
668 o =
669 (dhcpv6_option_t *) (((uword) o) +
670 clib_net_to_host_u16 (o->length) +
671 sizeof (*o));
672 }
Wojciech Dec96e6f952016-10-20 11:25:37 +0200673
674 if ((relay_msg_opt_flag == 0) || (r0 == 0))
khemendra kumar34719e32017-12-08 18:06:52 +0530675 {
676 error0 = DHCPV6_PROXY_ERROR_NO_RELAY_MESSAGE_OPTION;
677 goto drop_packet;
678 }
Wojciech Dec96e6f952016-10-20 11:25:37 +0200679
khemendra kumar34719e32017-12-08 18:06:52 +0530680 if ((u32) ~ 0 == sw_if_index)
681 {
682 error0 = DHCPV6_PROXY_ERROR_NO_CIRCUIT_ID_OPTION;
683 goto drop_packet;
684 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700685
Wojciech Dec96e6f952016-10-20 11:25:37 +0200686 //Advance buffer to start of encapsulated DHCPv6 message
khemendra kumar34719e32017-12-08 18:06:52 +0530687 vlib_buffer_advance (b0, sizeof (*r0));
Wojciech Dec96e6f952016-10-20 11:25:37 +0200688
Neale Ranns358425b2017-02-20 09:42:36 -0800689 client_fib_idx = im->mfib_index_by_sw_if_index[sw_if_index];
khemendra kumar34719e32017-12-08 18:06:52 +0530690 proxy = dhcp_get_proxy (dm, client_fib_idx, FIB_PROTOCOL_IP6);
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100691
Neale Ranns3466c302017-02-16 07:45:03 -0800692 if (NULL == proxy)
khemendra kumar34719e32017-12-08 18:06:52 +0530693 {
694 error0 = DHCPV6_PROXY_ERROR_NO_SERVER;
695 goto drop_packet;
696 }
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100697
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100698 server_fib_idx = im->fib_index_by_sw_if_index
khemendra kumar34719e32017-12-08 18:06:52 +0530699 [vnet_buffer (b0)->sw_if_index[VLIB_RX]];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700700
khemendra kumar34719e32017-12-08 18:06:52 +0530701 vec_foreach (server, proxy->dhcp_servers)
Neale Ranns3466c302017-02-16 07:45:03 -0800702 {
khemendra kumar34719e32017-12-08 18:06:52 +0530703 if (server_fib_idx == server->server_fib_index &&
704 ip0->src_address.as_u64[0] == server->dhcp_server.ip6.as_u64[0] &&
705 ip0->src_address.as_u64[1] == server->dhcp_server.ip6.as_u64[1])
706 {
707 goto server_found;
708 }
Neale Ranns3466c302017-02-16 07:45:03 -0800709 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700710
Neale Ranns3466c302017-02-16 07:45:03 -0800711 //drop packet if not from server with configured address or FIB
712 error0 = DHCPV6_PROXY_ERROR_BAD_SVR_FIB_OR_ADDRESS;
713 goto drop_packet;
714
715 server_found:
Wojciech Dec96e6f952016-10-20 11:25:37 +0200716 vnet_buffer (b0)->sw_if_index[VLIB_TX] = original_sw_if_index
khemendra kumar34719e32017-12-08 18:06:52 +0530717 = sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700718
719 swif = vnet_get_sw_interface (vnm, original_sw_if_index);
720 if (swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
khemendra kumar34719e32017-12-08 18:06:52 +0530721 sw_if_index = swif->unnumbered_sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700722
Wojciech Dec96e6f952016-10-20 11:25:37 +0200723
724 /*
725 * udp_local hands us the DHCPV6 header, need udp hdr,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700726 * ip hdr to relay to client
727 */
khemendra kumar34719e32017-12-08 18:06:52 +0530728 vlib_buffer_advance (b0, -(sizeof (*u1)));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700729 u1 = vlib_buffer_get_current (b0);
730
khemendra kumar34719e32017-12-08 18:06:52 +0530731 vlib_buffer_advance (b0, -(sizeof (*ip1)));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700732 ip1 = vlib_buffer_get_current (b0);
733
khemendra kumar34719e32017-12-08 18:06:52 +0530734 copy_ip6_address (&client_address, &h0->peer_addr);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700735
736 ia0 = ip6_interface_first_address (&ip6_main, sw_if_index);
737 if (ia0 == 0)
khemendra kumar34719e32017-12-08 18:06:52 +0530738 {
739 error0 = DHCPV6_PROXY_ERROR_NO_INTERFACE_ADDRESS;
740 goto drop_packet;
741 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700742
khemendra kumar34719e32017-12-08 18:06:52 +0530743 len = clib_net_to_host_u16 (r0->length);
Dave Barachb7b92992018-10-17 10:38:51 -0400744 clib_memset (ip1, 0, sizeof (*ip1));
khemendra kumar34719e32017-12-08 18:06:52 +0530745 copy_ip6_address (&ip1->dst_address, &client_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700746 u1->checksum = 0;
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100747 u1->src_port = clib_net_to_host_u16 (UDP_DST_PORT_dhcpv6_to_server);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700748 u1->dst_port = clib_net_to_host_u16 (UDP_DST_PORT_dhcpv6_to_client);
khemendra kumar34719e32017-12-08 18:06:52 +0530749 u1->length = clib_host_to_net_u16 (len + sizeof (udp_header_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700750
751 ip1->ip_version_traffic_class_and_flow_label =
khemendra kumar34719e32017-12-08 18:06:52 +0530752 ip0->ip_version_traffic_class_and_flow_label & 0x00000fff;
753 ip1->payload_length = u1->length;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700754 ip1->protocol = PROTO_UDP;
755 ip1->hop_limit = HOP_COUNT_LIMIT;
khemendra kumar34719e32017-12-08 18:06:52 +0530756 copy_ip6_address (&ip1->src_address, ia0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700757
khemendra kumar34719e32017-12-08 18:06:52 +0530758 u1->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip1,
759 &bogus_length);
760 ASSERT (bogus_length == 0);
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100761
khemendra kumar34719e32017-12-08 18:06:52 +0530762 vlib_buffer_advance (b0, -(sizeof (ethernet_header_t)));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700763 si0 = vnet_get_sw_interface (vnm, original_sw_if_index);
764 if (si0->type == VNET_SW_INTERFACE_TYPE_SUB)
khemendra kumar34719e32017-12-08 18:06:52 +0530765 vlib_buffer_advance (b0, -4 /* space for VLAN tag */ );
Ed Warnickecb9cada2015-12-08 15:45:58 -0700766
767 mac0 = vlib_buffer_get_current (b0);
768
769 hi0 = vnet_get_sup_hw_interface (vnm, original_sw_if_index);
770 ei0 = pool_elt_at_index (em->interfaces, hi0->hw_instance);
Damjan Marionf1213b82016-03-13 02:22:06 +0100771 clib_memcpy (mac0->src_address, ei0->address, sizeof (ei0->address));
Dave Barachb7b92992018-10-17 10:38:51 -0400772 clib_memset (&mac0->dst_address, 0xff, sizeof (mac0->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700773 mac0->type = (si0->type == VNET_SW_INTERFACE_TYPE_SUB) ?
khemendra kumar34719e32017-12-08 18:06:52 +0530774 clib_net_to_host_u16 (0x8100) : clib_net_to_host_u16 (0x86dd);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700775
776 if (si0->type == VNET_SW_INTERFACE_TYPE_SUB)
777 {
khemendra kumar34719e32017-12-08 18:06:52 +0530778 u32 *vlan_tag = (u32 *) (mac0 + 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700779 u32 tmp;
780 tmp = (si0->sub.id << 16) | 0x0800;
781 *vlan_tag = clib_host_to_net_u32 (tmp);
782 }
783
784 /* $$$ consider adding a dynamic next to the graph node, for performance */
785 f0 = vlib_get_frame_to_node (vm, hi0->output_node_index);
786 to_next0 = vlib_frame_vector_args (f0);
787 to_next0[0] = bi0;
788 f0->n_vectors = 1;
789 vlib_put_frame_to_node (vm, hi0->output_node_index, f0);
790
791 do_trace:
khemendra kumar34719e32017-12-08 18:06:52 +0530792 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
793 {
794 dhcpv6_proxy_trace_t *tr = vlib_add_trace (vm, node,
795 b0, sizeof (*tr));
796 tr->which = 1; /* to client */
797 if (ia0)
798 copy_ip6_address ((ip6_address_t *) tr->packet_data, ia0);
799 tr->error = error0;
800 tr->original_sw_if_index = original_sw_if_index;
801 tr->sw_if_index = sw_if_index;
802 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700803 }
804 return from_frame->n_vectors;
805
806}
807
khemendra kumar34719e32017-12-08 18:06:52 +0530808/* *INDENT-OFF* */
Neale Ranns2dd68522017-02-16 03:38:59 -0800809VLIB_REGISTER_NODE (dhcpv6_proxy_to_client_node, static) = {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700810 .function = dhcpv6_proxy_to_client_input,
811 .name = "dhcpv6-proxy-to-client",
812 /* Takes a vector of packets. */
813 .vector_size = sizeof (u32),
814
815 .n_errors = DHCPV6_PROXY_N_ERROR,
816 .error_strings = dhcpv6_proxy_error_strings,
817 .format_buffer = format_dhcpv6_proxy_header_with_length,
818 .format_trace = format_dhcpv6_proxy_trace,
819#if 0
820 .unformat_buffer = unformat_dhcpv6_proxy_header,
821#endif
822};
khemendra kumar34719e32017-12-08 18:06:52 +0530823/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700824
Neale Ranns2dd68522017-02-16 03:38:59 -0800825static clib_error_t *
826dhcp6_proxy_init (vlib_main_t * vm)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700827{
khemendra kumar34719e32017-12-08 18:06:52 +0530828 dhcp_proxy_main_t *dm = &dhcp_proxy_main;
829 vlib_node_t *error_drop_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700830
Ed Warnickecb9cada2015-12-08 15:45:58 -0700831 error_drop_node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
832 dm->error_drop_node_index = error_drop_node->index;
833
834 /* RFC says this is the dhcpv6 server address */
khemendra kumar34719e32017-12-08 18:06:52 +0530835 all_dhcpv6_server_address.as_u64[0] =
836 clib_host_to_net_u64 (0xFF05000000000000);
Neale Ranns2dd68522017-02-16 03:38:59 -0800837 all_dhcpv6_server_address.as_u64[1] = clib_host_to_net_u64 (0x00010003);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700838
839 /* RFC says this is the server and agent address */
khemendra kumar34719e32017-12-08 18:06:52 +0530840 all_dhcpv6_server_relay_agent_address.as_u64[0] =
841 clib_host_to_net_u64 (0xFF02000000000000);
842 all_dhcpv6_server_relay_agent_address.as_u64[1] =
843 clib_host_to_net_u64 (0x00010002);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700844
Ed Warnickecb9cada2015-12-08 15:45:58 -0700845 return 0;
846}
847
Neale Ranns2dd68522017-02-16 03:38:59 -0800848VLIB_INIT_FUNCTION (dhcp6_proxy_init);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700849
Neale Ranns2dd68522017-02-16 03:38:59 -0800850int
khemendra kumar34719e32017-12-08 18:06:52 +0530851dhcp6_proxy_set_server (ip46_address_t * addr,
852 ip46_address_t * src_addr,
853 u32 rx_table_id, u32 server_table_id, int is_del)
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100854{
Juraj Sloboda81119e82018-05-25 14:02:20 +0200855 vlib_main_t *vm = vlib_get_main ();
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100856 u32 rx_fib_index = 0;
Neale Ranns20a175a2017-02-14 07:28:41 -0800857 int rc = 0;
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100858
Neale Ranns20a175a2017-02-14 07:28:41 -0800859 const mfib_prefix_t all_dhcp_servers = {
khemendra kumar34719e32017-12-08 18:06:52 +0530860 .fp_len = 128,
861 .fp_proto = FIB_PROTOCOL_IP6,
862 .fp_grp_addr = {
863 .ip6 = all_dhcpv6_server_relay_agent_address,
864 }
Neale Ranns20a175a2017-02-14 07:28:41 -0800865 };
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100866
khemendra kumar34719e32017-12-08 18:06:52 +0530867 if (ip46_address_is_zero (addr))
Neale Ranns2dd68522017-02-16 03:38:59 -0800868 return VNET_API_ERROR_INVALID_DST_ADDRESS;
khemendra kumar34719e32017-12-08 18:06:52 +0530869
870 if (ip46_address_is_zero (src_addr))
Neale Ranns2dd68522017-02-16 03:38:59 -0800871 return VNET_API_ERROR_INVALID_SRC_ADDRESS;
872
khemendra kumar34719e32017-12-08 18:06:52 +0530873 rx_fib_index = mfib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
874 rx_table_id,
875 MFIB_SOURCE_DHCP);
Neale Ranns2dd68522017-02-16 03:38:59 -0800876
Ed Warnickecb9cada2015-12-08 15:45:58 -0700877 if (is_del)
Neale Ranns20a175a2017-02-14 07:28:41 -0800878 {
Neale Ranns3466c302017-02-16 07:45:03 -0800879 if (dhcp_proxy_server_del (FIB_PROTOCOL_IP6, rx_fib_index,
khemendra kumar34719e32017-12-08 18:06:52 +0530880 addr, server_table_id))
881 {
882 mfib_table_entry_delete (rx_fib_index,
883 &all_dhcp_servers, MFIB_SOURCE_DHCP);
884 mfib_table_unlock (rx_fib_index, FIB_PROTOCOL_IP6,
885 MFIB_SOURCE_DHCP);
Juraj Sloboda81119e82018-05-25 14:02:20 +0200886
887 udp_unregister_dst_port (vm, UDP_DST_PORT_dhcpv6_to_client,
888 0 /* is_ip6 */ );
889 udp_unregister_dst_port (vm, UDP_DST_PORT_dhcpv6_to_server,
890 0 /* is_ip6 */ );
khemendra kumar34719e32017-12-08 18:06:52 +0530891 }
Neale Ranns20a175a2017-02-14 07:28:41 -0800892 }
893 else
894 {
khemendra kumar34719e32017-12-08 18:06:52 +0530895 const fib_route_path_t path_for_us = {
896 .frp_proto = DPO_PROTO_IP6,
897 .frp_addr = zero_addr,
898 .frp_sw_if_index = 0xffffffff,
899 .frp_fib_index = ~0,
900 .frp_weight = 0,
901 .frp_flags = FIB_ROUTE_PATH_LOCAL,
Neale Ranns2dd68522017-02-16 03:38:59 -0800902 };
khemendra kumar34719e32017-12-08 18:06:52 +0530903 if (dhcp_proxy_server_add (FIB_PROTOCOL_IP6, addr, src_addr,
904 rx_fib_index, server_table_id))
905 {
906 mfib_table_entry_path_update (rx_fib_index,
907 &all_dhcp_servers,
908 MFIB_SOURCE_DHCP,
909 &path_for_us, MFIB_ITF_FLAG_FORWARD);
910 /*
911 * Each interface that is enabled in this table, needs to be added
912 * as an accepting interface, but this is not easily doable in VPP.
913 * So we cheat. Add a flag to the entry that indicates accept form
914 * any interface.
915 * We will still only accept on v6 enabled interfaces, since the
916 * input feature ensures this.
917 */
918 mfib_table_entry_update (rx_fib_index,
919 &all_dhcp_servers,
920 MFIB_SOURCE_DHCP,
921 MFIB_RPF_ID_NONE,
922 MFIB_ENTRY_FLAG_ACCEPT_ALL_ITF);
923 mfib_table_lock (rx_fib_index, FIB_PROTOCOL_IP6, MFIB_SOURCE_DHCP);
Juraj Sloboda81119e82018-05-25 14:02:20 +0200924
925 udp_register_dst_port (vm, UDP_DST_PORT_dhcpv6_to_client,
926 dhcpv6_proxy_to_client_node.index,
927 0 /* is_ip6 */ );
928 udp_register_dst_port (vm, UDP_DST_PORT_dhcpv6_to_server,
929 dhcpv6_proxy_to_server_node.index,
930 0 /* is_ip6 */ );
khemendra kumar34719e32017-12-08 18:06:52 +0530931 }
Neale Ranns2dd68522017-02-16 03:38:59 -0800932 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700933
khemendra kumar34719e32017-12-08 18:06:52 +0530934 mfib_table_unlock (rx_fib_index, FIB_PROTOCOL_IP6, MFIB_SOURCE_DHCP);
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100935
Neale Ranns20a175a2017-02-14 07:28:41 -0800936 return (rc);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700937}
938
939static clib_error_t *
940dhcpv6_proxy_set_command_fn (vlib_main_t * vm,
khemendra kumar34719e32017-12-08 18:06:52 +0530941 unformat_input_t * input,
942 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700943{
Neale Ranns2dd68522017-02-16 03:38:59 -0800944 ip46_address_t addr, src_addr;
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100945 int set_server = 0, set_src_address = 0;
Neale Ranns2dd68522017-02-16 03:38:59 -0800946 u32 rx_table_id = 0, server_table_id = 0;
Neale Ranns20a175a2017-02-14 07:28:41 -0800947 int is_del = 0;
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100948
khemendra kumar34719e32017-12-08 18:06:52 +0530949 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700950 {
khemendra kumar34719e32017-12-08 18:06:52 +0530951 if (unformat (input, "server %U", unformat_ip6_address, &addr.ip6))
952 set_server = 1;
953 else if (unformat (input, "src-address %U",
954 unformat_ip6_address, &src_addr.ip6))
955 set_src_address = 1;
956 else if (unformat (input, "server-fib-id %d", &server_table_id))
957 ;
958 else if (unformat (input, "rx-fib-id %d", &rx_table_id))
959 ;
960 else if (unformat (input, "delete") || unformat (input, "del"))
961 is_del = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700962 else
khemendra kumar34719e32017-12-08 18:06:52 +0530963 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700964 }
965
966 if (is_del || (set_server && set_src_address))
khemendra kumar34719e32017-12-08 18:06:52 +0530967 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700968 int rv;
969
Neale Ranns2dd68522017-02-16 03:38:59 -0800970 rv = dhcp6_proxy_set_server (&addr, &src_addr, rx_table_id,
khemendra kumar34719e32017-12-08 18:06:52 +0530971 server_table_id, is_del);
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100972
973 //TODO: Complete the errors
Ed Warnickecb9cada2015-12-08 15:45:58 -0700974 switch (rv)
khemendra kumar34719e32017-12-08 18:06:52 +0530975 {
976 case 0:
977 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700978
khemendra kumar34719e32017-12-08 18:06:52 +0530979 case VNET_API_ERROR_INVALID_DST_ADDRESS:
980 return clib_error_return (0, "Invalid server address");
Neale Ranns2dd68522017-02-16 03:38:59 -0800981
khemendra kumar34719e32017-12-08 18:06:52 +0530982 case VNET_API_ERROR_INVALID_SRC_ADDRESS:
983 return clib_error_return (0, "Invalid src address");
Neale Ranns2dd68522017-02-16 03:38:59 -0800984
khemendra kumar34719e32017-12-08 18:06:52 +0530985 case VNET_API_ERROR_NO_SUCH_ENTRY:
986 return clib_error_return
987 (0, "Fib id %d: no per-fib DHCP server configured", rx_table_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700988
khemendra kumar34719e32017-12-08 18:06:52 +0530989 default:
990 return clib_error_return (0, "BUG: rv %d", rv);
991 }
992 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700993 else
994 return clib_error_return (0, "parse error`%U'",
khemendra kumar34719e32017-12-08 18:06:52 +0530995 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700996}
997
khemendra kumar34719e32017-12-08 18:06:52 +0530998/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700999VLIB_CLI_COMMAND (dhcpv6_proxy_set_command, static) = {
1000 .path = "set dhcpv6 proxy",
Wojciech Dec558d5eb2016-11-01 16:44:06 +01001001 .short_help = "set dhcpv6 proxy [del] server <ipv6-addr> src-address <ipv6-addr> "
Neale Ranns20a175a2017-02-14 07:28:41 -08001002 "[server-fib-id <fib-id>] [rx-fib-id <fib-id>] ",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001003 .function = dhcpv6_proxy_set_command_fn,
1004};
khemendra kumar34719e32017-12-08 18:06:52 +05301005/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001006
Neale Ranns2dd68522017-02-16 03:38:59 -08001007static u8 *
1008format_dhcp6_proxy_server (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001009{
khemendra kumar34719e32017-12-08 18:06:52 +05301010 dhcp_proxy_t *proxy = va_arg (*args, dhcp_proxy_t *);
Neale Ranns630198f2017-05-22 09:20:20 -04001011 fib_table_t *server_fib;
Neale Ranns3466c302017-02-16 07:45:03 -08001012 dhcp_server_t *server;
Neale Ranns358425b2017-02-20 09:42:36 -08001013 ip6_mfib_t *rx_fib;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001014
Neale Ranns3466c302017-02-16 07:45:03 -08001015 if (proxy == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001016 {
khemendra kumar34719e32017-12-08 18:06:52 +05301017 s = format (s, "%=14s%=16s%s", "RX FIB", "Src Address",
1018 "Servers FIB,Address");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001019 return s;
1020 }
1021
khemendra kumar34719e32017-12-08 18:06:52 +05301022 rx_fib = ip6_mfib_get (proxy->rx_fib_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001023
Neale Ranns3466c302017-02-16 07:45:03 -08001024 s = format (s, "%=14u%=16U",
khemendra kumar34719e32017-12-08 18:06:52 +05301025 rx_fib->table_id,
1026 format_ip46_address, &proxy->dhcp_src_address, IP46_TYPE_ANY);
Wojciech Dec558d5eb2016-11-01 16:44:06 +01001027
khemendra kumar34719e32017-12-08 18:06:52 +05301028 vec_foreach (server, proxy->dhcp_servers)
Neale Ranns3466c302017-02-16 07:45:03 -08001029 {
khemendra kumar34719e32017-12-08 18:06:52 +05301030 server_fib = fib_table_get (server->server_fib_index, FIB_PROTOCOL_IP6);
1031 s = format (s, "%u,%U ",
1032 server_fib->ft_table_id,
1033 format_ip46_address, &server->dhcp_server, IP46_TYPE_ANY);
Neale Ranns3466c302017-02-16 07:45:03 -08001034 }
1035
Ed Warnickecb9cada2015-12-08 15:45:58 -07001036 return s;
1037}
1038
Neale Ranns2dd68522017-02-16 03:38:59 -08001039static int
khemendra kumar34719e32017-12-08 18:06:52 +05301040dhcp6_proxy_show_walk (dhcp_proxy_t * proxy, void *ctx)
Neale Ranns2dd68522017-02-16 03:38:59 -08001041{
khemendra kumar34719e32017-12-08 18:06:52 +05301042 vlib_main_t *vm = ctx;
Neale Ranns2dd68522017-02-16 03:38:59 -08001043
khemendra kumar34719e32017-12-08 18:06:52 +05301044 vlib_cli_output (vm, "%U", format_dhcp6_proxy_server, proxy);
Neale Ranns2dd68522017-02-16 03:38:59 -08001045
khemendra kumar34719e32017-12-08 18:06:52 +05301046 return (1);
Neale Ranns2dd68522017-02-16 03:38:59 -08001047}
1048
Ed Warnickecb9cada2015-12-08 15:45:58 -07001049static clib_error_t *
1050dhcpv6_proxy_show_command_fn (vlib_main_t * vm,
khemendra kumar34719e32017-12-08 18:06:52 +05301051 unformat_input_t * input,
1052 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001053{
khemendra kumar34719e32017-12-08 18:06:52 +05301054 vlib_cli_output (vm, "%U", format_dhcp6_proxy_server,
1055 NULL /* header line */ );
Ed Warnickecb9cada2015-12-08 15:45:58 -07001056
khemendra kumar34719e32017-12-08 18:06:52 +05301057 dhcp_proxy_walk (FIB_PROTOCOL_IP6, dhcp6_proxy_show_walk, vm);
Neale Ranns20a175a2017-02-14 07:28:41 -08001058
Neale Ranns2dd68522017-02-16 03:38:59 -08001059 return (NULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001060}
1061
khemendra kumar34719e32017-12-08 18:06:52 +05301062/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001063VLIB_CLI_COMMAND (dhcpv6_proxy_show_command, static) = {
1064 .path = "show dhcpv6 proxy",
1065 .short_help = "Display dhcpv6 proxy info",
1066 .function = dhcpv6_proxy_show_command_fn,
1067};
khemendra kumar34719e32017-12-08 18:06:52 +05301068/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001069
Ed Warnickecb9cada2015-12-08 15:45:58 -07001070static clib_error_t *
1071dhcpv6_vss_command_fn (vlib_main_t * vm,
khemendra kumar34719e32017-12-08 18:06:52 +05301072 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001073{
John Lo70bfcaf2017-11-14 13:19:26 -05001074 u8 is_del = 0, vss_type = VSS_TYPE_DEFAULT;
1075 u8 *vpn_ascii_id = 0;
1076 u32 oui = 0, fib_id = 0, tbl_id = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001077
khemendra kumar34719e32017-12-08 18:06:52 +05301078 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001079 {
John Lo70bfcaf2017-11-14 13:19:26 -05001080 if (unformat (input, "table %d", &tbl_id))
khemendra kumar34719e32017-12-08 18:06:52 +05301081 ;
John Lo70bfcaf2017-11-14 13:19:26 -05001082 else if (unformat (input, "oui %d", &oui))
khemendra kumar34719e32017-12-08 18:06:52 +05301083 vss_type = VSS_TYPE_VPN_ID;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001084 else if (unformat (input, "vpn-id %d", &fib_id))
khemendra kumar34719e32017-12-08 18:06:52 +05301085 vss_type = VSS_TYPE_VPN_ID;
John Lo70bfcaf2017-11-14 13:19:26 -05001086 else if (unformat (input, "vpn-ascii-id %s", &vpn_ascii_id))
khemendra kumar34719e32017-12-08 18:06:52 +05301087 vss_type = VSS_TYPE_ASCII;
1088 else if (unformat (input, "delete") || unformat (input, "del"))
1089 is_del = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001090 else
khemendra kumar34719e32017-12-08 18:06:52 +05301091 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001092 }
1093
khemendra kumar34719e32017-12-08 18:06:52 +05301094 if (tbl_id == ~0)
1095 return clib_error_return (0, "no table ID specified.");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001096
khemendra kumar34719e32017-12-08 18:06:52 +05301097 int rv = dhcp_proxy_set_vss (FIB_PROTOCOL_IP6, tbl_id, vss_type,
1098 vpn_ascii_id, oui, fib_id, is_del);
John Lo70bfcaf2017-11-14 13:19:26 -05001099 switch (rv)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001100 {
John Lo70bfcaf2017-11-14 13:19:26 -05001101 case 0:
khemendra kumar34719e32017-12-08 18:06:52 +05301102 return 0;
John Lo70bfcaf2017-11-14 13:19:26 -05001103 case VNET_API_ERROR_NO_SUCH_ENTRY:
khemendra kumar34719e32017-12-08 18:06:52 +05301104 return clib_error_return (0, "vss for table %d not found in pool.",
1105 tbl_id);
John Lo70bfcaf2017-11-14 13:19:26 -05001106 default:
khemendra kumar34719e32017-12-08 18:06:52 +05301107 return clib_error_return (0, "BUG: rv %d", rv);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001108 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001109}
1110
khemendra kumar34719e32017-12-08 18:06:52 +05301111/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001112VLIB_CLI_COMMAND (dhcpv6_proxy_vss_command, static) = {
1113 .path = "set dhcpv6 vss",
John Lo70bfcaf2017-11-14 13:19:26 -05001114 .short_help = "set dhcpv6 vss table <table-id> [oui <n> vpn-id <n> | vpn-ascii-id <text>]",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001115 .function = dhcpv6_vss_command_fn,
1116};
khemendra kumar34719e32017-12-08 18:06:52 +05301117/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001118
1119static clib_error_t *
1120dhcpv6_vss_show_command_fn (vlib_main_t * vm,
khemendra kumar34719e32017-12-08 18:06:52 +05301121 unformat_input_t * input,
1122 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001123{
khemendra kumar34719e32017-12-08 18:06:52 +05301124 dhcp_vss_walk (FIB_PROTOCOL_IP6, dhcp_vss_show_walk, vm);
Wojciech Dec558d5eb2016-11-01 16:44:06 +01001125
Neale Ranns2dd68522017-02-16 03:38:59 -08001126 return (NULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001127}
1128
khemendra kumar34719e32017-12-08 18:06:52 +05301129/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001130VLIB_CLI_COMMAND (dhcpv6_proxy_vss_show_command, static) = {
1131 .path = "show dhcpv6 vss",
1132 .short_help = "show dhcpv6 VSS",
1133 .function = dhcpv6_vss_show_command_fn,
1134};
khemendra kumar34719e32017-12-08 18:06:52 +05301135/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001136
1137static clib_error_t *
1138dhcpv6_link_address_show_command_fn (vlib_main_t * vm,
khemendra kumar34719e32017-12-08 18:06:52 +05301139 unformat_input_t * input,
1140 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001141{
khemendra kumar34719e32017-12-08 18:06:52 +05301142 vnet_main_t *vnm = vnet_get_main ();
1143 u32 sw_if_index0 = 0, sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001144 vnet_sw_interface_t *swif;
Neale Ranns2dd68522017-02-16 03:38:59 -08001145 ip6_address_t *ia0;
Wojciech Dec558d5eb2016-11-01 16:44:06 +01001146
khemendra kumar34719e32017-12-08 18:06:52 +05301147 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001148 {
1149
khemendra kumar34719e32017-12-08 18:06:52 +05301150 if (unformat (input, "%U",
1151 unformat_vnet_sw_interface, vnm, &sw_if_index0))
1152 {
1153 swif = vnet_get_sw_interface (vnm, sw_if_index0);
1154 sw_if_index = (swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) ?
1155 swif->unnumbered_sw_if_index : sw_if_index0;
1156 ia0 = ip6_interface_first_address (&ip6_main, sw_if_index);
1157 if (ia0)
1158 {
1159 vlib_cli_output (vm, "%=20s%=48s", "interface", "link-address");
Wojciech Dec558d5eb2016-11-01 16:44:06 +01001160
khemendra kumar34719e32017-12-08 18:06:52 +05301161 vlib_cli_output (vm, "%=20U%=48U",
1162 format_vnet_sw_if_index_name, vnm,
1163 sw_if_index0, format_ip6_address, ia0);
1164 }
1165 else
1166 vlib_cli_output (vm, "%=34s%=20U",
1167 "No IPv6 address configured on",
1168 format_vnet_sw_if_index_name, vnm, sw_if_index);
1169 }
1170 else
1171 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001172 }
1173
1174 return 0;
1175}
1176
khemendra kumar34719e32017-12-08 18:06:52 +05301177/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001178VLIB_CLI_COMMAND (dhcpv6_proxy_address_show_command, static) = {
1179 .path = "show dhcpv6 link-address interface",
1180 .short_help = "show dhcpv6 link-address interface <interface>",
1181 .function = dhcpv6_link_address_show_command_fn,
1182};
khemendra kumar34719e32017-12-08 18:06:52 +05301183/* *INDENT-ON* */
1184
1185/*
1186 * fd.io coding-style-patch-verification: ON
1187 *
1188 * Local Variables:
1189 * eval: (c-set-style "gnu")
1190 * End:
1191 */