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