Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ip/udp.h: udp protocol |
| 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 | #ifndef included_udp_h |
| 19 | #define included_udp_h |
| 20 | |
| 21 | #include <vnet/vnet.h> |
| 22 | #include <vnet/ip/udp_packet.h> |
| 23 | #include <vnet/ip/ip.h> |
| 24 | #include <vnet/ip/ip4.h> |
| 25 | #include <vnet/ip/ip4_packet.h> |
| 26 | #include <vnet/pg/pg.h> |
| 27 | #include <vnet/ip/format.h> |
| 28 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 29 | typedef enum |
| 30 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 31 | #define udp_error(n,s) UDP_ERROR_##n, |
| 32 | #include <vnet/ip/udp_error.def> |
| 33 | #undef udp_error |
| 34 | UDP_N_ERROR, |
| 35 | } udp_error_t; |
| 36 | |
| 37 | #define foreach_udp4_dst_port \ |
| 38 | _ (67, dhcp_to_server) \ |
| 39 | _ (68, dhcp_to_client) \ |
| 40 | _ (500, ikev2) \ |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 41 | _ (3784, bfd4) \ |
| 42 | _ (3785, bfd_echo4) \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 43 | _ (4341, lisp_gpe) \ |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 44 | _ (4342, lisp_cp) \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 45 | _ (4739, ipfix) \ |
| 46 | _ (4789, vxlan) \ |
Chris Luke | 99cb335 | 2016-04-26 10:49:53 -0400 | [diff] [blame] | 47 | _ (4789, vxlan6) \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 48 | _ (4790, vxlan_gpe) \ |
| 49 | _ (6633, vpath_3) |
| 50 | |
| 51 | |
| 52 | #define foreach_udp6_dst_port \ |
| 53 | _ (547, dhcpv6_to_server) \ |
| 54 | _ (546, dhcpv6_to_client) \ |
Klement Sekera | aeeac3b | 2017-02-14 07:11:52 +0100 | [diff] [blame] | 55 | _ (3784, bfd6) \ |
| 56 | _ (3785, bfd_echo6) \ |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 57 | _ (4341, lisp_gpe6) \ |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 58 | _ (4342, lisp_cp6) \ |
Hongjun Ni | df921cc | 2016-05-25 01:16:19 +0800 | [diff] [blame] | 59 | _ (4790, vxlan6_gpe) \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 60 | _ (6633, vpath6_3) |
| 61 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 62 | typedef enum |
| 63 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 64 | #define _(n,f) UDP_DST_PORT_##f = n, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 65 | foreach_udp4_dst_port foreach_udp6_dst_port |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 66 | #undef _ |
| 67 | } udp_dst_port_t; |
| 68 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 69 | typedef enum |
| 70 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 71 | #define _(n,f) UDP6_DST_PORT_##f = n, |
| 72 | foreach_udp6_dst_port |
| 73 | #undef _ |
| 74 | } udp6_dst_port_t; |
| 75 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 76 | typedef struct |
| 77 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 78 | /* Name (a c string). */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 79 | char *name; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 80 | |
| 81 | /* GRE protocol type in host byte order. */ |
| 82 | udp_dst_port_t dst_port; |
| 83 | |
| 84 | /* Node which handles this type. */ |
| 85 | u32 node_index; |
| 86 | |
| 87 | /* Next index for this type. */ |
| 88 | u32 next_index; |
| 89 | } udp_dst_port_info_t; |
| 90 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 91 | typedef enum |
| 92 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 93 | UDP_IP6 = 0, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 94 | UDP_IP4, /* the code is full of is_ip4... */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 95 | N_UDP_AF, |
| 96 | } udp_af_t; |
| 97 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 98 | typedef struct |
| 99 | { |
| 100 | udp_dst_port_info_t *dst_port_infos[N_UDP_AF]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 101 | |
| 102 | /* Hash tables mapping name/protocol to protocol info index. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 103 | uword *dst_port_info_by_name[N_UDP_AF]; |
| 104 | uword *dst_port_info_by_dst_port[N_UDP_AF]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 105 | |
| 106 | /* convenience */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 107 | vlib_main_t *vlib_main; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 108 | } udp_main_t; |
| 109 | |
| 110 | always_inline udp_dst_port_info_t * |
| 111 | udp_get_dst_port_info (udp_main_t * um, udp_dst_port_t dst_port, u8 is_ip4) |
| 112 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 113 | uword *p = hash_get (um->dst_port_info_by_dst_port[is_ip4], dst_port); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 114 | return p ? vec_elt_at_index (um->dst_port_infos[is_ip4], p[0]) : 0; |
| 115 | } |
| 116 | |
| 117 | format_function_t format_udp_header; |
| 118 | format_function_t format_udp_rx_trace; |
| 119 | |
| 120 | unformat_function_t unformat_udp_header; |
| 121 | |
| 122 | void udp_register_dst_port (vlib_main_t * vm, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 123 | udp_dst_port_t dst_port, |
| 124 | u32 node_index, u8 is_ip4); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 125 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 126 | void udp_punt_unknown (vlib_main_t * vm, u8 is_ip4, u8 is_add); |
Alexander Popovsky (apopovsk) | 740bcdb | 2016-11-15 15:36:23 -0800 | [diff] [blame] | 127 | |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 128 | always_inline void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 129 | ip_udp_fixup_one (vlib_main_t * vm, vlib_buffer_t * b0, u8 is_ip4) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 130 | { |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 131 | u16 new_l0; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 132 | udp_header_t *udp0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 133 | |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 134 | if (is_ip4) |
| 135 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 136 | ip4_header_t *ip0; |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 137 | ip_csum_t sum0; |
| 138 | u16 old_l0 = 0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 139 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 140 | ip0 = vlib_buffer_get_current (b0); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 141 | |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 142 | /* fix the <bleep>ing outer-IP checksum */ |
| 143 | sum0 = ip0->checksum; |
| 144 | /* old_l0 always 0, see the rewrite setup */ |
| 145 | new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0)); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 146 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 147 | sum0 = ip_csum_update (sum0, old_l0, new_l0, ip4_header_t, |
| 148 | length /* changed member */ ); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 149 | ip0->checksum = ip_csum_fold (sum0); |
| 150 | ip0->length = new_l0; |
| 151 | |
| 152 | /* Fix UDP length */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 153 | udp0 = (udp_header_t *) (ip0 + 1); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 154 | new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 155 | - sizeof (*ip0)); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 156 | udp0->length = new_l0; |
| 157 | } |
| 158 | else |
| 159 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 160 | ip6_header_t *ip0; |
Florin Coras | 210bfc8 | 2016-04-29 16:04:33 +0200 | [diff] [blame] | 161 | int bogus0; |
| 162 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 163 | ip0 = vlib_buffer_get_current (b0); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 164 | |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 165 | new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 166 | - sizeof (*ip0)); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 167 | ip0->payload_length = new_l0; |
| 168 | |
| 169 | /* Fix UDP length */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 170 | udp0 = (udp_header_t *) (ip0 + 1); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 171 | udp0->length = new_l0; |
Florin Coras | 210bfc8 | 2016-04-29 16:04:33 +0200 | [diff] [blame] | 172 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 173 | udp0->checksum = |
| 174 | ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip0, &bogus0); |
| 175 | ASSERT (bogus0 == 0); |
Florin Coras | 210bfc8 | 2016-04-29 16:04:33 +0200 | [diff] [blame] | 176 | |
| 177 | if (udp0->checksum == 0) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 178 | udp0->checksum = 0xffff; |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 179 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 180 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 181 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 182 | always_inline void |
| 183 | ip_udp_encap_one (vlib_main_t * vm, vlib_buffer_t * b0, u8 * ec0, word ec_len, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 184 | u8 is_ip4) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 185 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 186 | vlib_buffer_advance (b0, -ec_len); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 187 | |
| 188 | if (is_ip4) |
| 189 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 190 | ip4_header_t *ip0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 191 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 192 | ip0 = vlib_buffer_get_current (b0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 193 | |
| 194 | /* Apply the encap string. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 195 | clib_memcpy (ip0, ec0, ec_len); |
| 196 | ip_udp_fixup_one (vm, b0, 1); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 197 | } |
| 198 | else |
| 199 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 200 | ip6_header_t *ip0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 201 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 202 | ip0 = vlib_buffer_get_current (b0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 203 | |
| 204 | /* Apply the encap string. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 205 | clib_memcpy (ip0, ec0, ec_len); |
| 206 | ip_udp_fixup_one (vm, b0, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 207 | } |
| 208 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 209 | |
| 210 | always_inline void |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 211 | ip_udp_encap_two (vlib_main_t * vm, vlib_buffer_t * b0, vlib_buffer_t * b1, |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 212 | u8 * ec0, u8 * ec1, word ec_len, u8 is_v4) |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 213 | { |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 214 | u16 new_l0, new_l1; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 215 | udp_header_t *udp0, *udp1; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 216 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 217 | ASSERT (_vec_len (ec0) == _vec_len (ec1)); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 218 | |
| 219 | vlib_buffer_advance (b0, -ec_len); |
| 220 | vlib_buffer_advance (b1, -ec_len); |
| 221 | |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 222 | if (is_v4) |
| 223 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 224 | ip4_header_t *ip0, *ip1; |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 225 | ip_csum_t sum0, sum1; |
| 226 | u16 old_l0 = 0, old_l1 = 0; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 227 | |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 228 | ip0 = vlib_buffer_get_current (b0); |
| 229 | ip1 = vlib_buffer_get_current (b1); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 230 | |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 231 | /* Apply the encap string */ |
| 232 | clib_memcpy (ip0, ec0, ec_len); |
| 233 | clib_memcpy (ip1, ec1, ec_len); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 234 | |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 235 | /* fix the <bleep>ing outer-IP checksum */ |
| 236 | sum0 = ip0->checksum; |
| 237 | sum1 = ip1->checksum; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 238 | |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 239 | /* old_l0 always 0, see the rewrite setup */ |
| 240 | new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0)); |
| 241 | new_l1 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b1)); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 242 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 243 | sum0 = ip_csum_update (sum0, old_l0, new_l0, ip4_header_t, |
| 244 | length /* changed member */ ); |
| 245 | sum1 = ip_csum_update (sum1, old_l1, new_l1, ip4_header_t, |
| 246 | length /* changed member */ ); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 247 | |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 248 | ip0->checksum = ip_csum_fold (sum0); |
| 249 | ip1->checksum = ip_csum_fold (sum1); |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 250 | |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 251 | ip0->length = new_l0; |
| 252 | ip1->length = new_l1; |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 253 | |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 254 | /* Fix UDP length */ |
| 255 | udp0 = (udp_header_t *) (ip0 + 1); |
| 256 | udp1 = (udp_header_t *) (ip1 + 1); |
| 257 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 258 | new_l0 = |
| 259 | clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0) - |
| 260 | sizeof (*ip0)); |
| 261 | new_l1 = |
| 262 | clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b1) - |
| 263 | sizeof (*ip1)); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 264 | udp0->length = new_l0; |
| 265 | udp1->length = new_l1; |
| 266 | } |
| 267 | else |
| 268 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 269 | ip6_header_t *ip0, *ip1; |
Florin Coras | 210bfc8 | 2016-04-29 16:04:33 +0200 | [diff] [blame] | 270 | int bogus0, bogus1; |
| 271 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 272 | ip0 = vlib_buffer_get_current (b0); |
| 273 | ip1 = vlib_buffer_get_current (b1); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 274 | |
| 275 | /* Apply the encap string. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 276 | clib_memcpy (ip0, ec0, ec_len); |
| 277 | clib_memcpy (ip1, ec1, ec_len); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 278 | |
| 279 | new_l0 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b0) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 280 | - sizeof (*ip0)); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 281 | new_l1 = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b1) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 282 | - sizeof (*ip1)); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 283 | ip0->payload_length = new_l0; |
| 284 | ip1->payload_length = new_l1; |
| 285 | |
| 286 | /* Fix UDP length */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 287 | udp0 = (udp_header_t *) (ip0 + 1); |
| 288 | udp1 = (udp_header_t *) (ip1 + 1); |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 289 | |
| 290 | udp0->length = new_l0; |
| 291 | udp1->length = new_l1; |
Florin Coras | 210bfc8 | 2016-04-29 16:04:33 +0200 | [diff] [blame] | 292 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 293 | udp0->checksum = |
| 294 | ip6_tcp_udp_icmp_compute_checksum (vm, b0, ip0, &bogus0); |
| 295 | udp1->checksum = |
| 296 | ip6_tcp_udp_icmp_compute_checksum (vm, b1, ip1, &bogus1); |
| 297 | ASSERT (bogus0 == 0); |
| 298 | ASSERT (bogus1 == 0); |
Florin Coras | 210bfc8 | 2016-04-29 16:04:33 +0200 | [diff] [blame] | 299 | |
| 300 | if (udp0->checksum == 0) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 301 | udp0->checksum = 0xffff; |
Florin Coras | 210bfc8 | 2016-04-29 16:04:33 +0200 | [diff] [blame] | 302 | if (udp1->checksum == 0) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 303 | udp1->checksum = 0xffff; |
Florin Coras | 02655bd | 2016-04-26 00:17:24 +0200 | [diff] [blame] | 304 | } |
Florin Coras | e127a7e | 2016-02-18 22:20:01 +0100 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | #endif /* included_udp_h */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 308 | |
| 309 | /* |
| 310 | * fd.io coding-style-patch-verification: ON |
| 311 | * |
| 312 | * Local Variables: |
| 313 | * eval: (c-set-style "gnu") |
| 314 | * End: |
| 315 | */ |