blob: a199b7a34e47a769626d476c74b47c7ad0883a82 [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];
khemendra kumar34719e32017-12-08 18:06:52 +0530182 dhcp_vss_t *vss;
183 u8 is_solicit = 0;
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100184
Ed Warnickecb9cada2015-12-08 15:45:58 -0700185 bi0 = from[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700186 from += 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700187 n_left_from -= 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700188
189 b0 = vlib_get_buffer (vm, bi0);
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100190
khemendra kumar34719e32017-12-08 18:06:52 +0530191 h0 = vlib_buffer_get_current (b0);
Chris Luke194ebc52016-04-25 14:26:55 -0400192
khemendra kumar34719e32017-12-08 18:06:52 +0530193 /*
194 * udp_local hands us the DHCPV6 header.
195 */
196 u0 = (void *) h0 - (sizeof (*u0));
197 ip0 = (void *) u0 - (sizeof (*ip0));
198 e_h0 = (void *) ip0 - ethernet_buffer_header_size (b0);
Chris Luke194ebc52016-04-25 14:26:55 -0400199
khemendra kumar34719e32017-12-08 18:06:52 +0530200 clib_memcpy (client_src_mac, e_h0->src_address, 6);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700201
Juraj Sloboda81119e82018-05-25 14:02:20 +0200202 switch (h0->msg_type)
khemendra kumar34719e32017-12-08 18:06:52 +0530203 {
204 case DHCPV6_MSG_SOLICIT:
205 case DHCPV6_MSG_REQUEST:
206 case DHCPV6_MSG_CONFIRM:
207 case DHCPV6_MSG_RENEW:
208 case DHCPV6_MSG_REBIND:
209 case DHCPV6_MSG_RELEASE:
210 case DHCPV6_MSG_DECLINE:
211 case DHCPV6_MSG_INFORMATION_REQUEST:
212 case DHCPV6_MSG_RELAY_FORW:
213 /* send to server */
214 break;
215 case DHCPV6_MSG_RELAY_REPL:
216 /* send to client */
217 next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_SEND_TO_CLIENT;
218 error0 = 0;
219 pkts_to_client++;
220 goto do_enqueue;
221 default:
222 /* drop the packet */
223 pkts_wrong_msg_type++;
224 error0 = DHCPV6_PROXY_ERROR_WRONG_MESSAGE_TYPE;
225 next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
226 goto do_trace;
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100227
khemendra kumar34719e32017-12-08 18:06:52 +0530228 }
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100229
khemendra kumar34719e32017-12-08 18:06:52 +0530230 /* Send to DHCPV6 server via the configured FIB */
231 rx_sw_if_index = sw_if_index =
232 vnet_buffer (b0)->sw_if_index[VLIB_RX];
233 rx_fib_idx = im->mfib_index_by_sw_if_index[rx_sw_if_index];
234 proxy = dhcp_get_proxy (dpm, rx_fib_idx, FIB_PROTOCOL_IP6);
Neale Ranns3bd11d72017-01-16 18:09:40 +0100235
khemendra kumar34719e32017-12-08 18:06:52 +0530236 if (PREDICT_FALSE (NULL == proxy))
237 {
238 error0 = DHCPV6_PROXY_ERROR_NO_SERVER;
239 next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
240 pkts_no_server++;
241 goto do_trace;
242 }
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100243
khemendra kumar34719e32017-12-08 18:06:52 +0530244 server = &proxy->dhcp_servers[0];
245 server_fib_idx = server->server_fib_index;
246 vnet_buffer (b0)->sw_if_index[VLIB_TX] = server_fib_idx;
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100247
248
khemendra kumar34719e32017-12-08 18:06:52 +0530249 /* relay-option header pointer */
250 vlib_buffer_advance (b0, -(sizeof (*fwd_opt)));
251 fwd_opt = vlib_buffer_get_current (b0);
252 /* relay message header pointer */
253 vlib_buffer_advance (b0, -(sizeof (*r1)));
254 r1 = vlib_buffer_get_current (b0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700255
khemendra kumar34719e32017-12-08 18:06:52 +0530256 vlib_buffer_advance (b0, -(sizeof (*u1)));
257 u1 = vlib_buffer_get_current (b0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700258
khemendra kumar34719e32017-12-08 18:06:52 +0530259 vlib_buffer_advance (b0, -(sizeof (*ip1)));
260 ip1 = vlib_buffer_get_current (b0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700261
khemendra kumar34719e32017-12-08 18:06:52 +0530262 /* fill in all that rubbish... */
263 len = clib_net_to_host_u16 (u0->length) - sizeof (udp_header_t);
264 copy_ip6_address (&r1->peer_addr, &ip0->src_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700265
khemendra kumar34719e32017-12-08 18:06:52 +0530266 r1->msg_type = DHCPV6_MSG_RELAY_FORW;
267 fwd_opt->length = clib_host_to_net_u16 (len);
268 fwd_opt->option = clib_host_to_net_u16 (DHCPV6_OPTION_RELAY_MSG);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700269
khemendra kumar34719e32017-12-08 18:06:52 +0530270 r1->hop_count++;
271 r1->hop_count =
Juraj Sloboda81119e82018-05-25 14:02:20 +0200272 (h0->msg_type != DHCPV6_MSG_RELAY_FORW) ? 0 : r1->hop_count;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700273
khemendra kumar34719e32017-12-08 18:06:52 +0530274 if (PREDICT_FALSE (r1->hop_count >= HOP_COUNT_LIMIT))
275 {
276 error0 = DHCPV6_RELAY_PKT_DROP_MAX_HOPS;
277 next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
278 pkts_no_exceeding_max_hop++;
279 goto do_trace;
280 }
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100281
Ed Warnickecb9cada2015-12-08 15:45:58 -0700282
khemendra kumar34719e32017-12-08 18:06:52 +0530283 /* If relay-fwd and src address is site or global unicast address */
Juraj Sloboda81119e82018-05-25 14:02:20 +0200284 if (h0->msg_type == DHCPV6_MSG_RELAY_FORW &&
khemendra kumar34719e32017-12-08 18:06:52 +0530285 ((ip0->src_address.as_u8[0] & 0xe0) == 0x20 ||
286 (ip0->src_address.as_u8[0] & 0xfe) == 0xfc))
287 {
288 /* Set link address to zero */
289 r1->link_addr.as_u64[0] = 0;
290 r1->link_addr.as_u64[1] = 0;
291 goto link_address_set;
292 }
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100293
khemendra kumar34719e32017-12-08 18:06:52 +0530294 /* if receiving interface is unnumbered, use receiving interface
295 * IP address as link address, otherwise use the loopback interface
296 * IP address as link address.
297 */
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100298
khemendra kumar34719e32017-12-08 18:06:52 +0530299 swif = vnet_get_sw_interface (vnm, rx_sw_if_index);
300 if (swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
301 sw_if_index = swif->unnumbered_sw_if_index;
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100302
khemendra kumar34719e32017-12-08 18:06:52 +0530303 ia0 =
304 ip6_interface_first_global_or_site_address (&ip6_main,
305 sw_if_index);
306 if (ia0 == 0)
307 {
308 error0 = DHCPV6_PROXY_ERROR_NO_INTERFACE_ADDRESS;
309 next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
310 pkts_no_interface_address++;
311 goto do_trace;
312 }
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100313
khemendra kumar34719e32017-12-08 18:06:52 +0530314 copy_ip6_address (&r1->link_addr, ia0);
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100315
khemendra kumar34719e32017-12-08 18:06:52 +0530316 link_address_set:
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100317
khemendra kumar34719e32017-12-08 18:06:52 +0530318 if ((b0->current_length + sizeof (*id1) + sizeof (*vss1) +
Damjan Marion8934a042019-02-09 23:29:26 +0100319 sizeof (*cmac)) > vlib_buffer_get_default_data_size (vm))
khemendra kumar34719e32017-12-08 18:06:52 +0530320 {
321 error0 = DHCPV6_PROXY_ERROR_PKT_TOO_BIG;
322 next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
323 pkts_too_big++;
324 goto do_trace;
325 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700326
khemendra kumar34719e32017-12-08 18:06:52 +0530327 id1 = (dhcpv6_int_id_t *) (((uword) ip1) + b0->current_length);
328 b0->current_length += (sizeof (*id1));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700329
khemendra kumar34719e32017-12-08 18:06:52 +0530330 id1->opt.option = clib_host_to_net_u16 (DHCPV6_OPTION_INTERFACE_ID);
331 id1->opt.length = clib_host_to_net_u16 (sizeof (rx_sw_if_index));
332 id1->int_idx = clib_host_to_net_u32 (rx_sw_if_index);
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100333
khemendra kumar34719e32017-12-08 18:06:52 +0530334 u1->length = 0;
Juraj Sloboda81119e82018-05-25 14:02:20 +0200335 if (h0->msg_type != DHCPV6_MSG_RELAY_FORW)
khemendra kumar34719e32017-12-08 18:06:52 +0530336 {
337 cmac =
338 (dhcpv6_client_mac_t *) (((uword) ip1) + b0->current_length);
339 b0->current_length += (sizeof (*cmac));
340 cmac->opt.length = clib_host_to_net_u16 (sizeof (*cmac) -
341 sizeof (cmac->opt));
342 cmac->opt.option =
343 clib_host_to_net_u16
344 (DHCPV6_OPTION_CLIENT_LINK_LAYER_ADDRESS);
345 cmac->link_type = clib_host_to_net_u16 (1); /* ethernet */
346 clib_memcpy (cmac->data, client_src_mac, 6);
347 u1->length += sizeof (*cmac);
348 }
Neale Ranns20a175a2017-02-14 07:28:41 -0800349
khemendra kumar34719e32017-12-08 18:06:52 +0530350 vss = dhcp_get_vss_info (dpm, rx_fib_idx, FIB_PROTOCOL_IP6);
Neale Ranns20a175a2017-02-14 07:28:41 -0800351
khemendra kumar34719e32017-12-08 18:06:52 +0530352 if (vss)
John Lo70bfcaf2017-11-14 13:19:26 -0500353 {
354 u16 id_len; /* length of VPN ID */
355 u16 type_len = sizeof (vss1->vss_type);
356
khemendra kumar34719e32017-12-08 18:06:52 +0530357 vss1 = (dhcpv6_vss_t *) (((uword) ip1) + b0->current_length);
John Lo70bfcaf2017-11-14 13:19:26 -0500358 vss1->vss_type = vss->vss_type;
359 if (vss->vss_type == VSS_TYPE_VPN_ID)
khemendra kumar34719e32017-12-08 18:06:52 +0530360 {
John Lo70bfcaf2017-11-14 13:19:26 -0500361 id_len = sizeof (vss->vpn_id); /* vpn_id is 7 bytes */
362 memcpy (vss1->data, vss->vpn_id, id_len);
khemendra kumar34719e32017-12-08 18:06:52 +0530363 }
John Lo70bfcaf2017-11-14 13:19:26 -0500364 else if (vss->vss_type == VSS_TYPE_ASCII)
khemendra kumar34719e32017-12-08 18:06:52 +0530365 {
John Lo70bfcaf2017-11-14 13:19:26 -0500366 id_len = vec_len (vss->vpn_ascii_id);
367 memcpy (vss1->data, vss->vpn_ascii_id, id_len);
khemendra kumar34719e32017-12-08 18:06:52 +0530368 }
369 else /* must be VSS_TYPE_DEFAULT, no VPN ID */
John Lo70bfcaf2017-11-14 13:19:26 -0500370 id_len = 0;
371
khemendra kumar34719e32017-12-08 18:06:52 +0530372 vss1->opt.option = clib_host_to_net_u16 (DHCPV6_OPTION_VSS);
John Lo70bfcaf2017-11-14 13:19:26 -0500373 vss1->opt.length = clib_host_to_net_u16 (type_len + id_len);
374 u1->length += type_len + id_len + sizeof (vss1->opt);
375 b0->current_length += type_len + id_len + sizeof (vss1->opt);
khemendra kumar34719e32017-12-08 18:06:52 +0530376 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700377
khemendra kumar34719e32017-12-08 18:06:52 +0530378 pkts_to_server++;
379 u1->checksum = 0;
380 u1->src_port = clib_host_to_net_u16 (UDP_DST_PORT_dhcpv6_to_client);
381 u1->dst_port = clib_host_to_net_u16 (UDP_DST_PORT_dhcpv6_to_server);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700382
khemendra kumar34719e32017-12-08 18:06:52 +0530383 u1->length =
384 clib_host_to_net_u16 (clib_net_to_host_u16 (fwd_opt->length) +
385 sizeof (*r1) + sizeof (*fwd_opt) +
386 sizeof (*u1) + sizeof (*id1) + u1->length);
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100387
Dave Barachb7b92992018-10-17 10:38:51 -0400388 clib_memset (ip1, 0, sizeof (*ip1));
khemendra kumar34719e32017-12-08 18:06:52 +0530389 ip1->ip_version_traffic_class_and_flow_label = 0x60;
390 ip1->payload_length = u1->length;
391 ip1->protocol = PROTO_UDP;
392 ip1->hop_limit = HOP_COUNT_LIMIT;
393 src = ((server->dhcp_server.ip6.as_u64[0] ||
394 server->dhcp_server.ip6.as_u64[1]) ?
395 &server->dhcp_server.ip6 : &all_dhcpv6_server_address);
396 copy_ip6_address (&ip1->dst_address, src);
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100397
Ed Warnickecb9cada2015-12-08 15:45:58 -0700398
khemendra kumar34719e32017-12-08 18:06:52 +0530399 ia0 = ip6_interface_first_global_or_site_address
400 (&ip6_main, vnet_buffer (b0)->sw_if_index[VLIB_RX]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700401
khemendra kumar34719e32017-12-08 18:06:52 +0530402 src = (proxy->dhcp_src_address.ip6.as_u64[0] ||
403 proxy->dhcp_src_address.ip6.as_u64[1]) ?
404 &proxy->dhcp_src_address.ip6 : ia0;
405 if (ia0 == 0)
406 {
407 error0 = DHCPV6_PROXY_ERROR_NO_SRC_ADDRESS;
408 next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_DROP;
409 pkts_no_src_address++;
410 goto do_trace;
411 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700412
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100413 copy_ip6_address (&ip1->src_address, src);
414
415
khemendra kumar34719e32017-12-08 18:06:52 +0530416 u1->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip1,
417 &bogus_length);
418 ASSERT (bogus_length == 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700419
khemendra kumar34719e32017-12-08 18:06:52 +0530420 next0 = DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700421
Juraj Sloboda81119e82018-05-25 14:02:20 +0200422 is_solicit = (DHCPV6_MSG_SOLICIT == h0->msg_type);
Neale Ranns3466c302017-02-16 07:45:03 -0800423
khemendra kumar34719e32017-12-08 18:06:52 +0530424 /*
425 * If we have multiple servers configured and this is the
426 * client's discover message, then send copies to each of
427 * those servers
428 */
429 if (is_solicit && vec_len (proxy->dhcp_servers) > 1)
430 {
431 u32 ii;
Neale Ranns3466c302017-02-16 07:45:03 -0800432
khemendra kumar34719e32017-12-08 18:06:52 +0530433 for (ii = 1; ii < vec_len (proxy->dhcp_servers); ii++)
434 {
435 vlib_buffer_t *c0;
436 u32 ci0;
Neale Ranns3466c302017-02-16 07:45:03 -0800437
khemendra kumar34719e32017-12-08 18:06:52 +0530438 c0 = vlib_buffer_copy (vm, b0);
Ole Troane87865d2018-11-29 12:39:41 +0100439 VLIB_BUFFER_TRACE_TRAJECTORY_INIT (c0);
khemendra kumar34719e32017-12-08 18:06:52 +0530440 ci0 = vlib_get_buffer_index (vm, c0);
441 server = &proxy->dhcp_servers[ii];
Neale Ranns3466c302017-02-16 07:45:03 -0800442
khemendra kumar34719e32017-12-08 18:06:52 +0530443 ip0 = vlib_buffer_get_current (c0);
Neale Ranns3466c302017-02-16 07:45:03 -0800444
khemendra kumar34719e32017-12-08 18:06:52 +0530445 src = ((server->dhcp_server.ip6.as_u64[0] ||
446 server->dhcp_server.ip6.as_u64[1]) ?
447 &server->dhcp_server.ip6 :
448 &all_dhcpv6_server_address);
449 copy_ip6_address (&ip1->dst_address, src);
Neale Ranns3466c302017-02-16 07:45:03 -0800450
khemendra kumar34719e32017-12-08 18:06:52 +0530451 to_next[0] = ci0;
452 to_next += 1;
453 n_left_to_next -= 1;
Neale Ranns3466c302017-02-16 07:45:03 -0800454
khemendra kumar34719e32017-12-08 18:06:52 +0530455 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
456 to_next, n_left_to_next,
457 ci0, next0);
Neale Ranns3466c302017-02-16 07:45:03 -0800458
khemendra kumar34719e32017-12-08 18:06:52 +0530459 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
460 {
461 dhcpv6_proxy_trace_t *tr;
Neale Ranns3466c302017-02-16 07:45:03 -0800462
Neale Rannsa3337952019-02-18 06:20:46 -0800463 vlib_buffer_copy_trace_flag (vm, b0, ci0);
khemendra kumar34719e32017-12-08 18:06:52 +0530464 tr = vlib_add_trace (vm, node, c0, sizeof (*tr));
465 tr->which = 0; /* to server */
466 tr->error = error0;
467 tr->original_sw_if_index = rx_sw_if_index;
468 tr->sw_if_index = sw_if_index;
469 if (next0 == DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP)
470 copy_ip6_address ((ip6_address_t *) &
471 tr->packet_data[0],
472 &server->dhcp_server.ip6);
473 }
Neale Ranns3466c302017-02-16 07:45:03 -0800474
khemendra kumar34719e32017-12-08 18:06:52 +0530475 if (PREDICT_FALSE (0 == n_left_to_next))
476 {
477 vlib_put_next_frame (vm, node, next_index,
478 n_left_to_next);
479 vlib_get_next_frame (vm, node, next_index,
480 to_next, n_left_to_next);
481 }
482 }
483 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700484
khemendra kumar34719e32017-12-08 18:06:52 +0530485 do_trace:
486 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
487 {
488 dhcpv6_proxy_trace_t *tr = vlib_add_trace (vm, node,
489 b0, sizeof (*tr));
490 tr->which = 0; /* to server */
491 tr->error = error0;
492 tr->original_sw_if_index = rx_sw_if_index;
493 tr->sw_if_index = sw_if_index;
494 if (DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_LOOKUP == next0)
495 copy_ip6_address ((ip6_address_t *) & tr->packet_data[0],
496 &server->dhcp_server.ip6);
497 }
498
499 do_enqueue:
Neale Ranns3466c302017-02-16 07:45:03 -0800500 to_next[0] = bi0;
501 to_next += 1;
502 n_left_to_next -= 1;
503
Ed Warnickecb9cada2015-12-08 15:45:58 -0700504 vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
505 to_next, n_left_to_next,
506 bi0, next0);
507 }
508
509 vlib_put_next_frame (vm, node, next_index, n_left_to_next);
510 }
511
512 vlib_node_increment_counter (vm, dhcpv6_proxy_to_server_node.index,
khemendra kumar34719e32017-12-08 18:06:52 +0530513 DHCPV6_PROXY_ERROR_RELAY_TO_CLIENT,
514 pkts_to_client);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700515 vlib_node_increment_counter (vm, dhcpv6_proxy_to_server_node.index,
khemendra kumar34719e32017-12-08 18:06:52 +0530516 DHCPV6_PROXY_ERROR_RELAY_TO_SERVER,
517 pkts_to_server);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700518 vlib_node_increment_counter (vm, dhcpv6_proxy_to_server_node.index,
khemendra kumar34719e32017-12-08 18:06:52 +0530519 DHCPV6_PROXY_ERROR_NO_INTERFACE_ADDRESS,
520 pkts_no_interface_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700521 vlib_node_increment_counter (vm, dhcpv6_proxy_to_server_node.index,
khemendra kumar34719e32017-12-08 18:06:52 +0530522 DHCPV6_PROXY_ERROR_WRONG_MESSAGE_TYPE,
523 pkts_wrong_msg_type);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700524 vlib_node_increment_counter (vm, dhcpv6_proxy_to_server_node.index,
khemendra kumar34719e32017-12-08 18:06:52 +0530525 DHCPV6_PROXY_ERROR_NO_SRC_ADDRESS,
526 pkts_no_src_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700527 vlib_node_increment_counter (vm, dhcpv6_proxy_to_server_node.index,
khemendra kumar34719e32017-12-08 18:06:52 +0530528 DHCPV6_PROXY_ERROR_PKT_TOO_BIG, pkts_too_big);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700529 return from_frame->n_vectors;
530}
531
khemendra kumar34719e32017-12-08 18:06:52 +0530532/* *INDENT-OFF* */
Neale Ranns2dd68522017-02-16 03:38:59 -0800533VLIB_REGISTER_NODE (dhcpv6_proxy_to_server_node, static) = {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700534 .function = dhcpv6_proxy_to_server_input,
535 .name = "dhcpv6-proxy-to-server",
536 /* Takes a vector of packets. */
537 .vector_size = sizeof (u32),
538
539 .n_errors = DHCPV6_PROXY_N_ERROR,
540 .error_strings = dhcpv6_proxy_error_strings,
541
542 .n_next_nodes = DHCPV6_PROXY_TO_SERVER_INPUT_N_NEXT,
543 .next_nodes = {
544#define _(s,n) [DHCPV6_PROXY_TO_SERVER_INPUT_NEXT_##s] = n,
545 foreach_dhcpv6_proxy_to_server_input_next
546#undef _
547 },
548
549 .format_buffer = format_dhcpv6_proxy_header_with_length,
550 .format_trace = format_dhcpv6_proxy_trace,
551#if 0
552 .unformat_buffer = unformat_dhcpv6_proxy_header,
553#endif
554};
khemendra kumar34719e32017-12-08 18:06:52 +0530555/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700556
557static uword
558dhcpv6_proxy_to_client_input (vlib_main_t * vm,
khemendra kumar34719e32017-12-08 18:06:52 +0530559 vlib_node_runtime_t * node,
560 vlib_frame_t * from_frame)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700561{
562
khemendra kumar34719e32017-12-08 18:06:52 +0530563 u32 n_left_from, *from;
Matthew Smith7a192832018-02-10 11:11:45 -0600564 ethernet_main_t *em = vnet_get_ethernet_main ();
khemendra kumar34719e32017-12-08 18:06:52 +0530565 dhcp_proxy_main_t *dm = &dhcp_proxy_main;
Neale Ranns3466c302017-02-16 07:45:03 -0800566 dhcp_proxy_t *proxy;
567 dhcp_server_t *server;
khemendra kumar34719e32017-12-08 18:06:52 +0530568 vnet_main_t *vnm = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -0700569 int bogus_length;
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100570
Ed Warnickecb9cada2015-12-08 15:45:58 -0700571 from = vlib_frame_vector_args (from_frame);
572 n_left_from = from_frame->n_vectors;
573
574 while (n_left_from > 0)
575 {
576 u32 bi0;
khemendra kumar34719e32017-12-08 18:06:52 +0530577 vlib_buffer_t *b0;
578 udp_header_t *u0, *u1 = 0;
579 dhcpv6_relay_hdr_t *h0;
580 ip6_header_t *ip1 = 0, *ip0;
581 ip6_address_t _ia0, *ia0 = &_ia0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700582 ip6_address_t client_address;
583 ethernet_interface_t *ei0;
584 ethernet_header_t *mac0;
585 vnet_hw_interface_t *hi0;
586 vlib_frame_t *f0;
khemendra kumar34719e32017-12-08 18:06:52 +0530587 u32 *to_next0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700588 u32 sw_if_index = ~0;
589 u32 original_sw_if_index = ~0;
590 vnet_sw_interface_t *si0;
khemendra kumar34719e32017-12-08 18:06:52 +0530591 u32 error0 = (u32) ~ 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700592 vnet_sw_interface_t *swif;
Wojciech Dec96e6f952016-10-20 11:25:37 +0200593 dhcpv6_option_t *r0 = 0, *o;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700594 u16 len = 0;
Wojciech Dec96e6f952016-10-20 11:25:37 +0200595 u8 interface_opt_flag = 0;
596 u8 relay_msg_opt_flag = 0;
khemendra kumar34719e32017-12-08 18:06:52 +0530597 ip6_main_t *im = &ip6_main;
Neale Ranns20a175a2017-02-14 07:28:41 -0800598 u32 server_fib_idx, client_fib_idx;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700599
600 bi0 = from[0];
601 from += 1;
602 n_left_from -= 1;
Wojciech Dec96e6f952016-10-20 11:25:37 +0200603
Ed Warnickecb9cada2015-12-08 15:45:58 -0700604 b0 = vlib_get_buffer (vm, bi0);
605 h0 = vlib_buffer_get_current (b0);
606
607 if (DHCPV6_MSG_RELAY_REPL != h0->msg_type)
khemendra kumar34719e32017-12-08 18:06:52 +0530608 {
609 error0 = DHCPV6_PROXY_ERROR_WRONG_MESSAGE_TYPE;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700610
khemendra kumar34719e32017-12-08 18:06:52 +0530611 drop_packet:
612 vlib_node_increment_counter (vm, dhcpv6_proxy_to_client_node.index,
613 error0, 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700614
khemendra kumar34719e32017-12-08 18:06:52 +0530615 f0 = vlib_get_frame_to_node (vm, dm->error_drop_node_index);
616 to_next0 = vlib_frame_vector_args (f0);
617 to_next0[0] = bi0;
618 f0->n_vectors = 1;
619 vlib_put_frame_to_node (vm, dm->error_drop_node_index, f0);
620 goto do_trace;
621 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700622 /* hop count seems not need to be checked */
623 if (HOP_COUNT_LIMIT < h0->hop_count)
khemendra kumar34719e32017-12-08 18:06:52 +0530624 {
625 error0 = DHCPV6_RELAY_PKT_DROP_MAX_HOPS;
626 goto drop_packet;
627 }
628 u0 = (void *) h0 - (sizeof (*u0));
629 ip0 = (void *) u0 - (sizeof (*ip0));
Wojciech Dec96e6f952016-10-20 11:25:37 +0200630
khemendra kumar34719e32017-12-08 18:06:52 +0530631 vlib_buffer_advance (b0, sizeof (*h0));
Wojciech Dec96e6f952016-10-20 11:25:37 +0200632 o = vlib_buffer_get_current (b0);
633
634 /* Parse through TLVs looking for option 18 (DHCPV6_OPTION_INTERFACE_ID)
635 _and_ option 9 (DHCPV6_OPTION_RELAY_MSG) option which must be there.
636 Currently assuming no other options need to be processed
Ed Warnickecb9cada2015-12-08 15:45:58 -0700637 The interface-ID is the FIB number we need
638 to track down the client-facing interface */
Wojciech Dec96e6f952016-10-20 11:25:37 +0200639
Ed Warnickecb9cada2015-12-08 15:45:58 -0700640 while ((u8 *) o < (b0->data + b0->current_data + b0->current_length))
khemendra kumar34719e32017-12-08 18:06:52 +0530641 {
642 if (DHCPV6_OPTION_INTERFACE_ID == clib_net_to_host_u16 (o->option))
643 {
644 interface_opt_flag = 1;
645 if (clib_net_to_host_u16 (o->length) == sizeof (sw_if_index))
646 sw_if_index =
647 clib_net_to_host_u32 (((dhcpv6_int_id_t *) o)->int_idx);
648 if (sw_if_index >= vec_len (im->fib_index_by_sw_if_index))
649 {
650 error0 = DHCPV6_PROXY_ERROR_WRONG_INTERFACE_ID_OPTION;
651 goto drop_packet;
652 }
653 }
654 if (DHCPV6_OPTION_RELAY_MSG == clib_net_to_host_u16 (o->option))
655 {
656 relay_msg_opt_flag = 1;
657 r0 = vlib_buffer_get_current (b0);
658 }
659 if ((relay_msg_opt_flag == 1) && (interface_opt_flag == 1))
660 break;
661 vlib_buffer_advance (b0,
662 sizeof (*o) +
663 clib_net_to_host_u16 (o->length));
664 o =
665 (dhcpv6_option_t *) (((uword) o) +
666 clib_net_to_host_u16 (o->length) +
667 sizeof (*o));
668 }
Wojciech Dec96e6f952016-10-20 11:25:37 +0200669
670 if ((relay_msg_opt_flag == 0) || (r0 == 0))
khemendra kumar34719e32017-12-08 18:06:52 +0530671 {
672 error0 = DHCPV6_PROXY_ERROR_NO_RELAY_MESSAGE_OPTION;
673 goto drop_packet;
674 }
Wojciech Dec96e6f952016-10-20 11:25:37 +0200675
khemendra kumar34719e32017-12-08 18:06:52 +0530676 if ((u32) ~ 0 == sw_if_index)
677 {
678 error0 = DHCPV6_PROXY_ERROR_NO_CIRCUIT_ID_OPTION;
679 goto drop_packet;
680 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700681
Wojciech Dec96e6f952016-10-20 11:25:37 +0200682 //Advance buffer to start of encapsulated DHCPv6 message
khemendra kumar34719e32017-12-08 18:06:52 +0530683 vlib_buffer_advance (b0, sizeof (*r0));
Wojciech Dec96e6f952016-10-20 11:25:37 +0200684
Neale Ranns358425b2017-02-20 09:42:36 -0800685 client_fib_idx = im->mfib_index_by_sw_if_index[sw_if_index];
khemendra kumar34719e32017-12-08 18:06:52 +0530686 proxy = dhcp_get_proxy (dm, client_fib_idx, FIB_PROTOCOL_IP6);
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100687
Neale Ranns3466c302017-02-16 07:45:03 -0800688 if (NULL == proxy)
khemendra kumar34719e32017-12-08 18:06:52 +0530689 {
690 error0 = DHCPV6_PROXY_ERROR_NO_SERVER;
691 goto drop_packet;
692 }
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100693
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100694 server_fib_idx = im->fib_index_by_sw_if_index
khemendra kumar34719e32017-12-08 18:06:52 +0530695 [vnet_buffer (b0)->sw_if_index[VLIB_RX]];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700696
khemendra kumar34719e32017-12-08 18:06:52 +0530697 vec_foreach (server, proxy->dhcp_servers)
Neale Ranns3466c302017-02-16 07:45:03 -0800698 {
khemendra kumar34719e32017-12-08 18:06:52 +0530699 if (server_fib_idx == server->server_fib_index &&
700 ip0->src_address.as_u64[0] == server->dhcp_server.ip6.as_u64[0] &&
701 ip0->src_address.as_u64[1] == server->dhcp_server.ip6.as_u64[1])
702 {
703 goto server_found;
704 }
Neale Ranns3466c302017-02-16 07:45:03 -0800705 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700706
Neale Ranns3466c302017-02-16 07:45:03 -0800707 //drop packet if not from server with configured address or FIB
708 error0 = DHCPV6_PROXY_ERROR_BAD_SVR_FIB_OR_ADDRESS;
709 goto drop_packet;
710
711 server_found:
Wojciech Dec96e6f952016-10-20 11:25:37 +0200712 vnet_buffer (b0)->sw_if_index[VLIB_TX] = original_sw_if_index
khemendra kumar34719e32017-12-08 18:06:52 +0530713 = sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700714
715 swif = vnet_get_sw_interface (vnm, original_sw_if_index);
716 if (swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
khemendra kumar34719e32017-12-08 18:06:52 +0530717 sw_if_index = swif->unnumbered_sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700718
Wojciech Dec96e6f952016-10-20 11:25:37 +0200719
720 /*
721 * udp_local hands us the DHCPV6 header, need udp hdr,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700722 * ip hdr to relay to client
723 */
khemendra kumar34719e32017-12-08 18:06:52 +0530724 vlib_buffer_advance (b0, -(sizeof (*u1)));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700725 u1 = vlib_buffer_get_current (b0);
726
khemendra kumar34719e32017-12-08 18:06:52 +0530727 vlib_buffer_advance (b0, -(sizeof (*ip1)));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700728 ip1 = vlib_buffer_get_current (b0);
729
khemendra kumar34719e32017-12-08 18:06:52 +0530730 copy_ip6_address (&client_address, &h0->peer_addr);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700731
732 ia0 = ip6_interface_first_address (&ip6_main, sw_if_index);
733 if (ia0 == 0)
khemendra kumar34719e32017-12-08 18:06:52 +0530734 {
735 error0 = DHCPV6_PROXY_ERROR_NO_INTERFACE_ADDRESS;
736 goto drop_packet;
737 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700738
khemendra kumar34719e32017-12-08 18:06:52 +0530739 len = clib_net_to_host_u16 (r0->length);
Dave Barachb7b92992018-10-17 10:38:51 -0400740 clib_memset (ip1, 0, sizeof (*ip1));
khemendra kumar34719e32017-12-08 18:06:52 +0530741 copy_ip6_address (&ip1->dst_address, &client_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700742 u1->checksum = 0;
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100743 u1->src_port = clib_net_to_host_u16 (UDP_DST_PORT_dhcpv6_to_server);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700744 u1->dst_port = clib_net_to_host_u16 (UDP_DST_PORT_dhcpv6_to_client);
khemendra kumar34719e32017-12-08 18:06:52 +0530745 u1->length = clib_host_to_net_u16 (len + sizeof (udp_header_t));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700746
747 ip1->ip_version_traffic_class_and_flow_label =
khemendra kumar34719e32017-12-08 18:06:52 +0530748 ip0->ip_version_traffic_class_and_flow_label & 0x00000fff;
749 ip1->payload_length = u1->length;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700750 ip1->protocol = PROTO_UDP;
751 ip1->hop_limit = HOP_COUNT_LIMIT;
khemendra kumar34719e32017-12-08 18:06:52 +0530752 copy_ip6_address (&ip1->src_address, ia0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700753
khemendra kumar34719e32017-12-08 18:06:52 +0530754 u1->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip1,
755 &bogus_length);
756 ASSERT (bogus_length == 0);
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100757
khemendra kumar34719e32017-12-08 18:06:52 +0530758 vlib_buffer_advance (b0, -(sizeof (ethernet_header_t)));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700759 si0 = vnet_get_sw_interface (vnm, original_sw_if_index);
760 if (si0->type == VNET_SW_INTERFACE_TYPE_SUB)
khemendra kumar34719e32017-12-08 18:06:52 +0530761 vlib_buffer_advance (b0, -4 /* space for VLAN tag */ );
Ed Warnickecb9cada2015-12-08 15:45:58 -0700762
763 mac0 = vlib_buffer_get_current (b0);
764
765 hi0 = vnet_get_sup_hw_interface (vnm, original_sw_if_index);
766 ei0 = pool_elt_at_index (em->interfaces, hi0->hw_instance);
Damjan Marionf1213b82016-03-13 02:22:06 +0100767 clib_memcpy (mac0->src_address, ei0->address, sizeof (ei0->address));
Dave Barachb7b92992018-10-17 10:38:51 -0400768 clib_memset (&mac0->dst_address, 0xff, sizeof (mac0->dst_address));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700769 mac0->type = (si0->type == VNET_SW_INTERFACE_TYPE_SUB) ?
khemendra kumar34719e32017-12-08 18:06:52 +0530770 clib_net_to_host_u16 (0x8100) : clib_net_to_host_u16 (0x86dd);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700771
772 if (si0->type == VNET_SW_INTERFACE_TYPE_SUB)
773 {
khemendra kumar34719e32017-12-08 18:06:52 +0530774 u32 *vlan_tag = (u32 *) (mac0 + 1);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700775 u32 tmp;
776 tmp = (si0->sub.id << 16) | 0x0800;
777 *vlan_tag = clib_host_to_net_u32 (tmp);
778 }
779
780 /* $$$ consider adding a dynamic next to the graph node, for performance */
781 f0 = vlib_get_frame_to_node (vm, hi0->output_node_index);
782 to_next0 = vlib_frame_vector_args (f0);
783 to_next0[0] = bi0;
784 f0->n_vectors = 1;
785 vlib_put_frame_to_node (vm, hi0->output_node_index, f0);
786
787 do_trace:
khemendra kumar34719e32017-12-08 18:06:52 +0530788 if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
789 {
790 dhcpv6_proxy_trace_t *tr = vlib_add_trace (vm, node,
791 b0, sizeof (*tr));
792 tr->which = 1; /* to client */
793 if (ia0)
794 copy_ip6_address ((ip6_address_t *) tr->packet_data, ia0);
795 tr->error = error0;
796 tr->original_sw_if_index = original_sw_if_index;
797 tr->sw_if_index = sw_if_index;
798 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700799 }
800 return from_frame->n_vectors;
801
802}
803
khemendra kumar34719e32017-12-08 18:06:52 +0530804/* *INDENT-OFF* */
Neale Ranns2dd68522017-02-16 03:38:59 -0800805VLIB_REGISTER_NODE (dhcpv6_proxy_to_client_node, static) = {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700806 .function = dhcpv6_proxy_to_client_input,
807 .name = "dhcpv6-proxy-to-client",
808 /* Takes a vector of packets. */
809 .vector_size = sizeof (u32),
810
811 .n_errors = DHCPV6_PROXY_N_ERROR,
812 .error_strings = dhcpv6_proxy_error_strings,
813 .format_buffer = format_dhcpv6_proxy_header_with_length,
814 .format_trace = format_dhcpv6_proxy_trace,
815#if 0
816 .unformat_buffer = unformat_dhcpv6_proxy_header,
817#endif
818};
khemendra kumar34719e32017-12-08 18:06:52 +0530819/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700820
Neale Ranns2dd68522017-02-16 03:38:59 -0800821static clib_error_t *
822dhcp6_proxy_init (vlib_main_t * vm)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700823{
khemendra kumar34719e32017-12-08 18:06:52 +0530824 dhcp_proxy_main_t *dm = &dhcp_proxy_main;
825 vlib_node_t *error_drop_node;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700826
Ed Warnickecb9cada2015-12-08 15:45:58 -0700827 error_drop_node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
828 dm->error_drop_node_index = error_drop_node->index;
829
830 /* RFC says this is the dhcpv6 server address */
khemendra kumar34719e32017-12-08 18:06:52 +0530831 all_dhcpv6_server_address.as_u64[0] =
832 clib_host_to_net_u64 (0xFF05000000000000);
Neale Ranns2dd68522017-02-16 03:38:59 -0800833 all_dhcpv6_server_address.as_u64[1] = clib_host_to_net_u64 (0x00010003);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700834
835 /* RFC says this is the server and agent address */
khemendra kumar34719e32017-12-08 18:06:52 +0530836 all_dhcpv6_server_relay_agent_address.as_u64[0] =
837 clib_host_to_net_u64 (0xFF02000000000000);
838 all_dhcpv6_server_relay_agent_address.as_u64[1] =
839 clib_host_to_net_u64 (0x00010002);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700840
Ed Warnickecb9cada2015-12-08 15:45:58 -0700841 return 0;
842}
843
Neale Ranns2dd68522017-02-16 03:38:59 -0800844VLIB_INIT_FUNCTION (dhcp6_proxy_init);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700845
Neale Ranns2dd68522017-02-16 03:38:59 -0800846int
khemendra kumar34719e32017-12-08 18:06:52 +0530847dhcp6_proxy_set_server (ip46_address_t * addr,
848 ip46_address_t * src_addr,
849 u32 rx_table_id, u32 server_table_id, int is_del)
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100850{
Juraj Sloboda81119e82018-05-25 14:02:20 +0200851 vlib_main_t *vm = vlib_get_main ();
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100852 u32 rx_fib_index = 0;
Neale Ranns20a175a2017-02-14 07:28:41 -0800853 int rc = 0;
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100854
Neale Ranns20a175a2017-02-14 07:28:41 -0800855 const mfib_prefix_t all_dhcp_servers = {
khemendra kumar34719e32017-12-08 18:06:52 +0530856 .fp_len = 128,
857 .fp_proto = FIB_PROTOCOL_IP6,
858 .fp_grp_addr = {
859 .ip6 = all_dhcpv6_server_relay_agent_address,
860 }
Neale Ranns20a175a2017-02-14 07:28:41 -0800861 };
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100862
khemendra kumar34719e32017-12-08 18:06:52 +0530863 if (ip46_address_is_zero (addr))
Neale Ranns2dd68522017-02-16 03:38:59 -0800864 return VNET_API_ERROR_INVALID_DST_ADDRESS;
khemendra kumar34719e32017-12-08 18:06:52 +0530865
866 if (ip46_address_is_zero (src_addr))
Neale Ranns2dd68522017-02-16 03:38:59 -0800867 return VNET_API_ERROR_INVALID_SRC_ADDRESS;
868
khemendra kumar34719e32017-12-08 18:06:52 +0530869 rx_fib_index = mfib_table_find_or_create_and_lock (FIB_PROTOCOL_IP6,
870 rx_table_id,
871 MFIB_SOURCE_DHCP);
Neale Ranns2dd68522017-02-16 03:38:59 -0800872
Ed Warnickecb9cada2015-12-08 15:45:58 -0700873 if (is_del)
Neale Ranns20a175a2017-02-14 07:28:41 -0800874 {
Neale Ranns3466c302017-02-16 07:45:03 -0800875 if (dhcp_proxy_server_del (FIB_PROTOCOL_IP6, rx_fib_index,
khemendra kumar34719e32017-12-08 18:06:52 +0530876 addr, server_table_id))
877 {
878 mfib_table_entry_delete (rx_fib_index,
879 &all_dhcp_servers, MFIB_SOURCE_DHCP);
880 mfib_table_unlock (rx_fib_index, FIB_PROTOCOL_IP6,
881 MFIB_SOURCE_DHCP);
Juraj Sloboda81119e82018-05-25 14:02:20 +0200882
883 udp_unregister_dst_port (vm, UDP_DST_PORT_dhcpv6_to_client,
884 0 /* is_ip6 */ );
885 udp_unregister_dst_port (vm, UDP_DST_PORT_dhcpv6_to_server,
886 0 /* is_ip6 */ );
khemendra kumar34719e32017-12-08 18:06:52 +0530887 }
Neale Ranns20a175a2017-02-14 07:28:41 -0800888 }
889 else
890 {
khemendra kumar34719e32017-12-08 18:06:52 +0530891 const fib_route_path_t path_for_us = {
892 .frp_proto = DPO_PROTO_IP6,
893 .frp_addr = zero_addr,
894 .frp_sw_if_index = 0xffffffff,
895 .frp_fib_index = ~0,
896 .frp_weight = 0,
897 .frp_flags = FIB_ROUTE_PATH_LOCAL,
Neale Ranns2dd68522017-02-16 03:38:59 -0800898 };
khemendra kumar34719e32017-12-08 18:06:52 +0530899 if (dhcp_proxy_server_add (FIB_PROTOCOL_IP6, addr, src_addr,
900 rx_fib_index, server_table_id))
901 {
902 mfib_table_entry_path_update (rx_fib_index,
903 &all_dhcp_servers,
904 MFIB_SOURCE_DHCP,
905 &path_for_us, MFIB_ITF_FLAG_FORWARD);
906 /*
907 * Each interface that is enabled in this table, needs to be added
908 * as an accepting interface, but this is not easily doable in VPP.
909 * So we cheat. Add a flag to the entry that indicates accept form
910 * any interface.
911 * We will still only accept on v6 enabled interfaces, since the
912 * input feature ensures this.
913 */
914 mfib_table_entry_update (rx_fib_index,
915 &all_dhcp_servers,
916 MFIB_SOURCE_DHCP,
917 MFIB_RPF_ID_NONE,
918 MFIB_ENTRY_FLAG_ACCEPT_ALL_ITF);
919 mfib_table_lock (rx_fib_index, FIB_PROTOCOL_IP6, MFIB_SOURCE_DHCP);
Juraj Sloboda81119e82018-05-25 14:02:20 +0200920
921 udp_register_dst_port (vm, UDP_DST_PORT_dhcpv6_to_client,
922 dhcpv6_proxy_to_client_node.index,
923 0 /* is_ip6 */ );
924 udp_register_dst_port (vm, UDP_DST_PORT_dhcpv6_to_server,
925 dhcpv6_proxy_to_server_node.index,
926 0 /* is_ip6 */ );
khemendra kumar34719e32017-12-08 18:06:52 +0530927 }
Neale Ranns2dd68522017-02-16 03:38:59 -0800928 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700929
khemendra kumar34719e32017-12-08 18:06:52 +0530930 mfib_table_unlock (rx_fib_index, FIB_PROTOCOL_IP6, MFIB_SOURCE_DHCP);
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100931
Neale Ranns20a175a2017-02-14 07:28:41 -0800932 return (rc);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700933}
934
935static clib_error_t *
936dhcpv6_proxy_set_command_fn (vlib_main_t * vm,
khemendra kumar34719e32017-12-08 18:06:52 +0530937 unformat_input_t * input,
938 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700939{
Neale Ranns2dd68522017-02-16 03:38:59 -0800940 ip46_address_t addr, src_addr;
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100941 int set_server = 0, set_src_address = 0;
Neale Ranns2dd68522017-02-16 03:38:59 -0800942 u32 rx_table_id = 0, server_table_id = 0;
Neale Ranns20a175a2017-02-14 07:28:41 -0800943 int is_del = 0;
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100944
khemendra kumar34719e32017-12-08 18:06:52 +0530945 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700946 {
khemendra kumar34719e32017-12-08 18:06:52 +0530947 if (unformat (input, "server %U", unformat_ip6_address, &addr.ip6))
948 set_server = 1;
949 else if (unformat (input, "src-address %U",
950 unformat_ip6_address, &src_addr.ip6))
951 set_src_address = 1;
952 else if (unformat (input, "server-fib-id %d", &server_table_id))
953 ;
954 else if (unformat (input, "rx-fib-id %d", &rx_table_id))
955 ;
956 else if (unformat (input, "delete") || unformat (input, "del"))
957 is_del = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700958 else
khemendra kumar34719e32017-12-08 18:06:52 +0530959 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700960 }
961
962 if (is_del || (set_server && set_src_address))
khemendra kumar34719e32017-12-08 18:06:52 +0530963 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700964 int rv;
965
Neale Ranns2dd68522017-02-16 03:38:59 -0800966 rv = dhcp6_proxy_set_server (&addr, &src_addr, rx_table_id,
khemendra kumar34719e32017-12-08 18:06:52 +0530967 server_table_id, is_del);
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100968
969 //TODO: Complete the errors
Ed Warnickecb9cada2015-12-08 15:45:58 -0700970 switch (rv)
khemendra kumar34719e32017-12-08 18:06:52 +0530971 {
972 case 0:
973 return 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700974
khemendra kumar34719e32017-12-08 18:06:52 +0530975 case VNET_API_ERROR_INVALID_DST_ADDRESS:
976 return clib_error_return (0, "Invalid server address");
Neale Ranns2dd68522017-02-16 03:38:59 -0800977
khemendra kumar34719e32017-12-08 18:06:52 +0530978 case VNET_API_ERROR_INVALID_SRC_ADDRESS:
979 return clib_error_return (0, "Invalid src address");
Neale Ranns2dd68522017-02-16 03:38:59 -0800980
khemendra kumar34719e32017-12-08 18:06:52 +0530981 case VNET_API_ERROR_NO_SUCH_ENTRY:
982 return clib_error_return
983 (0, "Fib id %d: no per-fib DHCP server configured", rx_table_id);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700984
khemendra kumar34719e32017-12-08 18:06:52 +0530985 default:
986 return clib_error_return (0, "BUG: rv %d", rv);
987 }
988 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700989 else
990 return clib_error_return (0, "parse error`%U'",
khemendra kumar34719e32017-12-08 18:06:52 +0530991 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700992}
993
khemendra kumar34719e32017-12-08 18:06:52 +0530994/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700995VLIB_CLI_COMMAND (dhcpv6_proxy_set_command, static) = {
996 .path = "set dhcpv6 proxy",
Wojciech Dec558d5eb2016-11-01 16:44:06 +0100997 .short_help = "set dhcpv6 proxy [del] server <ipv6-addr> src-address <ipv6-addr> "
Neale Ranns20a175a2017-02-14 07:28:41 -0800998 "[server-fib-id <fib-id>] [rx-fib-id <fib-id>] ",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700999 .function = dhcpv6_proxy_set_command_fn,
1000};
khemendra kumar34719e32017-12-08 18:06:52 +05301001/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001002
Neale Ranns2dd68522017-02-16 03:38:59 -08001003static u8 *
1004format_dhcp6_proxy_server (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001005{
khemendra kumar34719e32017-12-08 18:06:52 +05301006 dhcp_proxy_t *proxy = va_arg (*args, dhcp_proxy_t *);
Neale Ranns630198f2017-05-22 09:20:20 -04001007 fib_table_t *server_fib;
Neale Ranns3466c302017-02-16 07:45:03 -08001008 dhcp_server_t *server;
Neale Ranns358425b2017-02-20 09:42:36 -08001009 ip6_mfib_t *rx_fib;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001010
Neale Ranns3466c302017-02-16 07:45:03 -08001011 if (proxy == 0)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001012 {
khemendra kumar34719e32017-12-08 18:06:52 +05301013 s = format (s, "%=14s%=16s%s", "RX FIB", "Src Address",
1014 "Servers FIB,Address");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001015 return s;
1016 }
1017
khemendra kumar34719e32017-12-08 18:06:52 +05301018 rx_fib = ip6_mfib_get (proxy->rx_fib_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001019
Neale Ranns3466c302017-02-16 07:45:03 -08001020 s = format (s, "%=14u%=16U",
khemendra kumar34719e32017-12-08 18:06:52 +05301021 rx_fib->table_id,
1022 format_ip46_address, &proxy->dhcp_src_address, IP46_TYPE_ANY);
Wojciech Dec558d5eb2016-11-01 16:44:06 +01001023
khemendra kumar34719e32017-12-08 18:06:52 +05301024 vec_foreach (server, proxy->dhcp_servers)
Neale Ranns3466c302017-02-16 07:45:03 -08001025 {
khemendra kumar34719e32017-12-08 18:06:52 +05301026 server_fib = fib_table_get (server->server_fib_index, FIB_PROTOCOL_IP6);
1027 s = format (s, "%u,%U ",
1028 server_fib->ft_table_id,
1029 format_ip46_address, &server->dhcp_server, IP46_TYPE_ANY);
Neale Ranns3466c302017-02-16 07:45:03 -08001030 }
1031
Ed Warnickecb9cada2015-12-08 15:45:58 -07001032 return s;
1033}
1034
Neale Ranns2dd68522017-02-16 03:38:59 -08001035static int
khemendra kumar34719e32017-12-08 18:06:52 +05301036dhcp6_proxy_show_walk (dhcp_proxy_t * proxy, void *ctx)
Neale Ranns2dd68522017-02-16 03:38:59 -08001037{
khemendra kumar34719e32017-12-08 18:06:52 +05301038 vlib_main_t *vm = ctx;
Neale Ranns2dd68522017-02-16 03:38:59 -08001039
khemendra kumar34719e32017-12-08 18:06:52 +05301040 vlib_cli_output (vm, "%U", format_dhcp6_proxy_server, proxy);
Neale Ranns2dd68522017-02-16 03:38:59 -08001041
khemendra kumar34719e32017-12-08 18:06:52 +05301042 return (1);
Neale Ranns2dd68522017-02-16 03:38:59 -08001043}
1044
Ed Warnickecb9cada2015-12-08 15:45:58 -07001045static clib_error_t *
1046dhcpv6_proxy_show_command_fn (vlib_main_t * vm,
khemendra kumar34719e32017-12-08 18:06:52 +05301047 unformat_input_t * input,
1048 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001049{
khemendra kumar34719e32017-12-08 18:06:52 +05301050 vlib_cli_output (vm, "%U", format_dhcp6_proxy_server,
1051 NULL /* header line */ );
Ed Warnickecb9cada2015-12-08 15:45:58 -07001052
khemendra kumar34719e32017-12-08 18:06:52 +05301053 dhcp_proxy_walk (FIB_PROTOCOL_IP6, dhcp6_proxy_show_walk, vm);
Neale Ranns20a175a2017-02-14 07:28:41 -08001054
Neale Ranns2dd68522017-02-16 03:38:59 -08001055 return (NULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001056}
1057
khemendra kumar34719e32017-12-08 18:06:52 +05301058/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001059VLIB_CLI_COMMAND (dhcpv6_proxy_show_command, static) = {
1060 .path = "show dhcpv6 proxy",
1061 .short_help = "Display dhcpv6 proxy info",
1062 .function = dhcpv6_proxy_show_command_fn,
1063};
khemendra kumar34719e32017-12-08 18:06:52 +05301064/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001065
Ed Warnickecb9cada2015-12-08 15:45:58 -07001066static clib_error_t *
1067dhcpv6_vss_command_fn (vlib_main_t * vm,
khemendra kumar34719e32017-12-08 18:06:52 +05301068 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001069{
John Lo70bfcaf2017-11-14 13:19:26 -05001070 u8 is_del = 0, vss_type = VSS_TYPE_DEFAULT;
1071 u8 *vpn_ascii_id = 0;
1072 u32 oui = 0, fib_id = 0, tbl_id = ~0;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001073
khemendra kumar34719e32017-12-08 18:06:52 +05301074 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001075 {
John Lo70bfcaf2017-11-14 13:19:26 -05001076 if (unformat (input, "table %d", &tbl_id))
khemendra kumar34719e32017-12-08 18:06:52 +05301077 ;
John Lo70bfcaf2017-11-14 13:19:26 -05001078 else if (unformat (input, "oui %d", &oui))
khemendra kumar34719e32017-12-08 18:06:52 +05301079 vss_type = VSS_TYPE_VPN_ID;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001080 else if (unformat (input, "vpn-id %d", &fib_id))
khemendra kumar34719e32017-12-08 18:06:52 +05301081 vss_type = VSS_TYPE_VPN_ID;
John Lo70bfcaf2017-11-14 13:19:26 -05001082 else if (unformat (input, "vpn-ascii-id %s", &vpn_ascii_id))
khemendra kumar34719e32017-12-08 18:06:52 +05301083 vss_type = VSS_TYPE_ASCII;
1084 else if (unformat (input, "delete") || unformat (input, "del"))
1085 is_del = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001086 else
khemendra kumar34719e32017-12-08 18:06:52 +05301087 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001088 }
1089
khemendra kumar34719e32017-12-08 18:06:52 +05301090 if (tbl_id == ~0)
1091 return clib_error_return (0, "no table ID specified.");
Ed Warnickecb9cada2015-12-08 15:45:58 -07001092
khemendra kumar34719e32017-12-08 18:06:52 +05301093 int rv = dhcp_proxy_set_vss (FIB_PROTOCOL_IP6, tbl_id, vss_type,
1094 vpn_ascii_id, oui, fib_id, is_del);
John Lo70bfcaf2017-11-14 13:19:26 -05001095 switch (rv)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001096 {
John Lo70bfcaf2017-11-14 13:19:26 -05001097 case 0:
khemendra kumar34719e32017-12-08 18:06:52 +05301098 return 0;
John Lo70bfcaf2017-11-14 13:19:26 -05001099 case VNET_API_ERROR_NO_SUCH_ENTRY:
khemendra kumar34719e32017-12-08 18:06:52 +05301100 return clib_error_return (0, "vss for table %d not found in pool.",
1101 tbl_id);
John Lo70bfcaf2017-11-14 13:19:26 -05001102 default:
khemendra kumar34719e32017-12-08 18:06:52 +05301103 return clib_error_return (0, "BUG: rv %d", rv);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001104 }
Ed Warnickecb9cada2015-12-08 15:45:58 -07001105}
1106
khemendra kumar34719e32017-12-08 18:06:52 +05301107/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001108VLIB_CLI_COMMAND (dhcpv6_proxy_vss_command, static) = {
1109 .path = "set dhcpv6 vss",
John Lo70bfcaf2017-11-14 13:19:26 -05001110 .short_help = "set dhcpv6 vss table <table-id> [oui <n> vpn-id <n> | vpn-ascii-id <text>]",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001111 .function = dhcpv6_vss_command_fn,
1112};
khemendra kumar34719e32017-12-08 18:06:52 +05301113/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001114
1115static clib_error_t *
1116dhcpv6_vss_show_command_fn (vlib_main_t * vm,
khemendra kumar34719e32017-12-08 18:06:52 +05301117 unformat_input_t * input,
1118 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001119{
khemendra kumar34719e32017-12-08 18:06:52 +05301120 dhcp_vss_walk (FIB_PROTOCOL_IP6, dhcp_vss_show_walk, vm);
Wojciech Dec558d5eb2016-11-01 16:44:06 +01001121
Neale Ranns2dd68522017-02-16 03:38:59 -08001122 return (NULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001123}
1124
khemendra kumar34719e32017-12-08 18:06:52 +05301125/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001126VLIB_CLI_COMMAND (dhcpv6_proxy_vss_show_command, static) = {
1127 .path = "show dhcpv6 vss",
1128 .short_help = "show dhcpv6 VSS",
1129 .function = dhcpv6_vss_show_command_fn,
1130};
khemendra kumar34719e32017-12-08 18:06:52 +05301131/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001132
1133static clib_error_t *
1134dhcpv6_link_address_show_command_fn (vlib_main_t * vm,
khemendra kumar34719e32017-12-08 18:06:52 +05301135 unformat_input_t * input,
1136 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001137{
khemendra kumar34719e32017-12-08 18:06:52 +05301138 vnet_main_t *vnm = vnet_get_main ();
1139 u32 sw_if_index0 = 0, sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001140 vnet_sw_interface_t *swif;
Neale Ranns2dd68522017-02-16 03:38:59 -08001141 ip6_address_t *ia0;
Wojciech Dec558d5eb2016-11-01 16:44:06 +01001142
khemendra kumar34719e32017-12-08 18:06:52 +05301143 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001144 {
1145
khemendra kumar34719e32017-12-08 18:06:52 +05301146 if (unformat (input, "%U",
1147 unformat_vnet_sw_interface, vnm, &sw_if_index0))
1148 {
1149 swif = vnet_get_sw_interface (vnm, sw_if_index0);
1150 sw_if_index = (swif->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) ?
1151 swif->unnumbered_sw_if_index : sw_if_index0;
1152 ia0 = ip6_interface_first_address (&ip6_main, sw_if_index);
1153 if (ia0)
1154 {
1155 vlib_cli_output (vm, "%=20s%=48s", "interface", "link-address");
Wojciech Dec558d5eb2016-11-01 16:44:06 +01001156
khemendra kumar34719e32017-12-08 18:06:52 +05301157 vlib_cli_output (vm, "%=20U%=48U",
1158 format_vnet_sw_if_index_name, vnm,
1159 sw_if_index0, format_ip6_address, ia0);
1160 }
1161 else
1162 vlib_cli_output (vm, "%=34s%=20U",
1163 "No IPv6 address configured on",
1164 format_vnet_sw_if_index_name, vnm, sw_if_index);
1165 }
1166 else
1167 break;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001168 }
1169
1170 return 0;
1171}
1172
khemendra kumar34719e32017-12-08 18:06:52 +05301173/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001174VLIB_CLI_COMMAND (dhcpv6_proxy_address_show_command, static) = {
1175 .path = "show dhcpv6 link-address interface",
1176 .short_help = "show dhcpv6 link-address interface <interface>",
1177 .function = dhcpv6_link_address_show_command_fn,
1178};
khemendra kumar34719e32017-12-08 18:06:52 +05301179/* *INDENT-ON* */
1180
1181/*
1182 * fd.io coding-style-patch-verification: ON
1183 *
1184 * Local Variables:
1185 * eval: (c-set-style "gnu")
1186 * End:
1187 */