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