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