Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | /* |
| 16 | * ip4/packet.h: ip4 packet format |
| 17 | * |
| 18 | * Copyright (c) 2008 Eliot Dresselhaus |
| 19 | * |
| 20 | * Permission is hereby granted, free of charge, to any person obtaining |
| 21 | * a copy of this software and associated documentation files (the |
| 22 | * "Software"), to deal in the Software without restriction, including |
| 23 | * without limitation the rights to use, copy, modify, merge, publish, |
| 24 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 25 | * permit persons to whom the Software is furnished to do so, subject to |
| 26 | * the following conditions: |
| 27 | * |
| 28 | * The above copyright notice and this permission notice shall be |
| 29 | * included in all copies or substantial portions of the Software. |
| 30 | * |
| 31 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 32 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 33 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 34 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 35 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 36 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 37 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 38 | */ |
| 39 | |
| 40 | #ifndef included_ip4_packet_h |
| 41 | #define included_ip4_packet_h |
| 42 | |
| 43 | #include <vnet/ip/ip_packet.h> /* for ip_csum_t */ |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 44 | #include <vnet/tcp/tcp_packet.h> /* for tcp_header_t */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 45 | #include <vppinfra/byte_order.h> /* for clib_net_to_host_u16 */ |
| 46 | |
| 47 | /* IP4 address which can be accessed either as 4 bytes |
| 48 | or as a 32-bit number. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 49 | typedef union |
| 50 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 51 | u8 data[4]; |
| 52 | u32 data_u32; |
| 53 | /* Aliases. */ |
| 54 | u8 as_u8[4]; |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 55 | u16 as_u16[2]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 56 | u32 as_u32; |
| 57 | } ip4_address_t; |
| 58 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 59 | typedef struct |
| 60 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 61 | /* IP address must be first for ip_interface_address_get_address() to work */ |
| 62 | ip4_address_t ip4_addr; |
| 63 | u32 fib_index; |
| 64 | } ip4_address_fib_t; |
| 65 | |
| 66 | always_inline void |
Neale Ranns | d69f439 | 2018-08-31 06:30:16 -0400 | [diff] [blame] | 67 | ip4_addr_fib_init (ip4_address_fib_t * addr_fib, |
| 68 | const ip4_address_t * address, u32 fib_index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 69 | { |
Dave Barach | 178cf49 | 2018-11-13 16:34:13 -0500 | [diff] [blame] | 70 | clib_memcpy_fast (&addr_fib->ip4_addr, address, |
| 71 | sizeof (addr_fib->ip4_addr)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 72 | addr_fib->fib_index = fib_index; |
| 73 | } |
| 74 | |
| 75 | /* (src,dst) pair of addresses as found in packet header. */ |
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 | ip4_address_t src, dst; |
| 79 | } ip4_address_pair_t; |
| 80 | |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 81 | typedef struct |
| 82 | { |
| 83 | ip4_address_t addr, mask; |
| 84 | } ip4_address_and_mask_t; |
| 85 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 86 | /* If address is a valid netmask, return length of mask. */ |
| 87 | always_inline uword |
Neale Ranns | d69f439 | 2018-08-31 06:30:16 -0400 | [diff] [blame] | 88 | ip4_address_netmask_length (const ip4_address_t * a) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 89 | { |
| 90 | uword result = 0; |
| 91 | uword i; |
| 92 | for (i = 0; i < ARRAY_LEN (a->as_u8); i++) |
| 93 | { |
| 94 | switch (a->as_u8[i]) |
| 95 | { |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 96 | case 0xff: |
| 97 | result += 8; |
| 98 | break; |
| 99 | case 0xfe: |
| 100 | result += 7; |
| 101 | goto done; |
| 102 | case 0xfc: |
| 103 | result += 6; |
| 104 | goto done; |
| 105 | case 0xf8: |
| 106 | result += 5; |
| 107 | goto done; |
| 108 | case 0xf0: |
| 109 | result += 4; |
| 110 | goto done; |
| 111 | case 0xe0: |
| 112 | result += 3; |
| 113 | goto done; |
| 114 | case 0xc0: |
| 115 | result += 2; |
| 116 | goto done; |
| 117 | case 0x80: |
| 118 | result += 1; |
| 119 | goto done; |
| 120 | case 0x00: |
| 121 | result += 0; |
| 122 | goto done; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 123 | default: |
| 124 | /* Not a valid netmask mask. */ |
| 125 | return ~0; |
| 126 | } |
| 127 | } |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 128 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 129 | return result; |
| 130 | } |
| 131 | |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 132 | typedef union |
| 133 | { |
| 134 | struct |
| 135 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 136 | /* 4 bit packet length (in 32bit units) and version VVVVLLLL. |
| 137 | e.g. for packets w/ no options ip_version_and_header_length == 0x45. */ |
| 138 | u8 ip_version_and_header_length; |
| 139 | |
| 140 | /* Type of service. */ |
| 141 | u8 tos; |
| 142 | |
| 143 | /* Total layer 3 packet length including this header. */ |
| 144 | u16 length; |
| 145 | |
| 146 | /* Fragmentation ID. */ |
| 147 | u16 fragment_id; |
| 148 | |
| 149 | /* 3 bits of flags and 13 bits of fragment offset (in units |
| 150 | of 8 byte quantities). */ |
| 151 | u16 flags_and_fragment_offset; |
| 152 | #define IP4_HEADER_FLAG_MORE_FRAGMENTS (1 << 13) |
| 153 | #define IP4_HEADER_FLAG_DONT_FRAGMENT (1 << 14) |
| 154 | #define IP4_HEADER_FLAG_CONGESTION (1 << 15) |
| 155 | |
| 156 | /* Time to live decremented by router at each hop. */ |
| 157 | u8 ttl; |
| 158 | |
| 159 | /* Next level protocol packet. */ |
| 160 | u8 protocol; |
| 161 | |
| 162 | /* Checksum. */ |
| 163 | u16 checksum; |
| 164 | |
| 165 | /* Source and destination address. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 166 | union |
| 167 | { |
| 168 | struct |
| 169 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 170 | ip4_address_t src_address, dst_address; |
| 171 | }; |
| 172 | ip4_address_pair_t address_pair; |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 173 | }; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | /* For checksumming we'll want to access IP header in word sized chunks. */ |
| 177 | /* For 64 bit machines. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 178 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 179 | CLIB_PACKED (struct { |
| 180 | u64 checksum_data_64[2]; |
| 181 | u32 checksum_data_64_32[1]; |
| 182 | }); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 183 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 184 | |
| 185 | /* For 32 bit machines. */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 186 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 187 | CLIB_PACKED (struct { |
| 188 | u32 checksum_data_32[5]; |
| 189 | }); |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 190 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 191 | } ip4_header_t; |
| 192 | |
| 193 | /* Value of ip_version_and_header_length for packets w/o options. */ |
| 194 | #define IP4_VERSION_AND_HEADER_LENGTH_NO_OPTIONS \ |
| 195 | ((4 << 4) | (sizeof (ip4_header_t) / sizeof (u32))) |
| 196 | |
Neale Ranns | c667ffd | 2018-06-27 18:59:03 -0700 | [diff] [blame] | 197 | #define IP4_ROUTER_ALERT_OPTION 20 |
| 198 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 199 | always_inline int |
Neale Ranns | d69f439 | 2018-08-31 06:30:16 -0400 | [diff] [blame] | 200 | ip4_get_fragment_offset (const ip4_header_t * i) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 201 | { |
| 202 | return clib_net_to_host_u16 (i->flags_and_fragment_offset) & 0x1fff; |
| 203 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 204 | |
| 205 | always_inline int |
Neale Ranns | d69f439 | 2018-08-31 06:30:16 -0400 | [diff] [blame] | 206 | ip4_get_fragment_more (const ip4_header_t * i) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 207 | { |
| 208 | return clib_net_to_host_u16 (i->flags_and_fragment_offset) & |
| 209 | IP4_HEADER_FLAG_MORE_FRAGMENTS; |
| 210 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 211 | |
| 212 | always_inline int |
Neale Ranns | d69f439 | 2018-08-31 06:30:16 -0400 | [diff] [blame] | 213 | ip4_is_fragment (const ip4_header_t * i) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 214 | { |
| 215 | return (i->flags_and_fragment_offset & |
| 216 | clib_net_to_host_u16 (0x1fff | IP4_HEADER_FLAG_MORE_FRAGMENTS)); |
| 217 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 218 | |
| 219 | always_inline int |
Neale Ranns | d69f439 | 2018-08-31 06:30:16 -0400 | [diff] [blame] | 220 | ip4_is_first_fragment (const ip4_header_t * i) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 221 | { |
| 222 | return (i->flags_and_fragment_offset & |
| 223 | clib_net_to_host_u16 (0x1fff | IP4_HEADER_FLAG_MORE_FRAGMENTS)) == |
| 224 | clib_net_to_host_u16 (IP4_HEADER_FLAG_MORE_FRAGMENTS); |
| 225 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 226 | |
| 227 | /* Fragment offset in bytes. */ |
| 228 | always_inline int |
Neale Ranns | d69f439 | 2018-08-31 06:30:16 -0400 | [diff] [blame] | 229 | ip4_get_fragment_offset_bytes (const ip4_header_t * i) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 230 | { |
| 231 | return 8 * ip4_get_fragment_offset (i); |
| 232 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 233 | |
| 234 | always_inline int |
Neale Ranns | d69f439 | 2018-08-31 06:30:16 -0400 | [diff] [blame] | 235 | ip4_header_bytes (const ip4_header_t * i) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 236 | { |
| 237 | return sizeof (u32) * (i->ip_version_and_header_length & 0xf); |
| 238 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 239 | |
| 240 | always_inline void * |
| 241 | ip4_next_header (ip4_header_t * i) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 242 | { |
| 243 | return (void *) i + ip4_header_bytes (i); |
| 244 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 245 | |
| 246 | always_inline u16 |
| 247 | ip4_header_checksum (ip4_header_t * i) |
| 248 | { |
| 249 | u16 save, csum; |
| 250 | ip_csum_t sum; |
| 251 | |
| 252 | save = i->checksum; |
| 253 | i->checksum = 0; |
| 254 | sum = ip_incremental_checksum (0, i, ip4_header_bytes (i)); |
| 255 | csum = ~ip_csum_fold (sum); |
| 256 | |
| 257 | i->checksum = save; |
| 258 | |
| 259 | /* Make checksum agree for special case where either |
| 260 | 0 or 0xffff would give same 1s complement sum. */ |
| 261 | if (csum == 0 && save == 0xffff) |
| 262 | csum = save; |
| 263 | |
| 264 | return csum; |
| 265 | } |
| 266 | |
| 267 | static inline uword |
| 268 | ip4_header_checksum_is_valid (ip4_header_t * i) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 269 | { |
| 270 | return i->checksum == ip4_header_checksum (i); |
| 271 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 272 | |
| 273 | #define ip4_partial_header_checksum_x1(ip0,sum0) \ |
| 274 | do { \ |
| 275 | if (BITS (ip_csum_t) > 32) \ |
| 276 | { \ |
| 277 | sum0 = ip0->checksum_data_64[0]; \ |
| 278 | sum0 = ip_csum_with_carry (sum0, ip0->checksum_data_64[1]); \ |
| 279 | sum0 = ip_csum_with_carry (sum0, ip0->checksum_data_64_32[0]); \ |
| 280 | } \ |
| 281 | else \ |
| 282 | { \ |
| 283 | sum0 = ip0->checksum_data_32[0]; \ |
| 284 | sum0 = ip_csum_with_carry (sum0, ip0->checksum_data_32[1]); \ |
| 285 | sum0 = ip_csum_with_carry (sum0, ip0->checksum_data_32[2]); \ |
| 286 | sum0 = ip_csum_with_carry (sum0, ip0->checksum_data_32[3]); \ |
| 287 | sum0 = ip_csum_with_carry (sum0, ip0->checksum_data_32[4]); \ |
| 288 | } \ |
| 289 | } while (0) |
| 290 | |
| 291 | #define ip4_partial_header_checksum_x2(ip0,ip1,sum0,sum1) \ |
| 292 | do { \ |
| 293 | if (BITS (ip_csum_t) > 32) \ |
| 294 | { \ |
| 295 | sum0 = ip0->checksum_data_64[0]; \ |
| 296 | sum1 = ip1->checksum_data_64[0]; \ |
| 297 | sum0 = ip_csum_with_carry (sum0, ip0->checksum_data_64[1]); \ |
| 298 | sum1 = ip_csum_with_carry (sum1, ip1->checksum_data_64[1]); \ |
| 299 | sum0 = ip_csum_with_carry (sum0, ip0->checksum_data_64_32[0]); \ |
| 300 | sum1 = ip_csum_with_carry (sum1, ip1->checksum_data_64_32[0]); \ |
| 301 | } \ |
| 302 | else \ |
| 303 | { \ |
| 304 | sum0 = ip0->checksum_data_32[0]; \ |
| 305 | sum1 = ip1->checksum_data_32[0]; \ |
| 306 | sum0 = ip_csum_with_carry (sum0, ip0->checksum_data_32[1]); \ |
| 307 | sum1 = ip_csum_with_carry (sum1, ip1->checksum_data_32[1]); \ |
| 308 | sum0 = ip_csum_with_carry (sum0, ip0->checksum_data_32[2]); \ |
| 309 | sum1 = ip_csum_with_carry (sum1, ip1->checksum_data_32[2]); \ |
| 310 | sum0 = ip_csum_with_carry (sum0, ip0->checksum_data_32[3]); \ |
| 311 | sum1 = ip_csum_with_carry (sum1, ip1->checksum_data_32[3]); \ |
| 312 | sum0 = ip_csum_with_carry (sum0, ip0->checksum_data_32[4]); \ |
| 313 | sum1 = ip_csum_with_carry (sum1, ip1->checksum_data_32[4]); \ |
| 314 | } \ |
| 315 | } while (0) |
| 316 | |
| 317 | always_inline uword |
Neale Ranns | d69f439 | 2018-08-31 06:30:16 -0400 | [diff] [blame] | 318 | ip4_address_is_multicast (const ip4_address_t * a) |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 319 | { |
| 320 | return (a->data[0] & 0xf0) == 0xe0; |
| 321 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 322 | |
| 323 | always_inline void |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 324 | ip4_multicast_address_set_for_group (ip4_address_t * a, |
| 325 | ip_multicast_group_t g) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 326 | { |
Damjan Marion | 2c29d75 | 2015-12-18 10:26:56 +0100 | [diff] [blame] | 327 | ASSERT ((u32) g < (1 << 28)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 328 | a->as_u32 = clib_host_to_net_u32 ((0xe << 28) + g); |
| 329 | } |
| 330 | |
| 331 | always_inline void |
Neale Ranns | d69f439 | 2018-08-31 06:30:16 -0400 | [diff] [blame] | 332 | ip4_multicast_ethernet_address (u8 * ethernet_address, |
| 333 | const ip4_address_t * a) |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 334 | { |
Neale Ranns | d69f439 | 2018-08-31 06:30:16 -0400 | [diff] [blame] | 335 | const u8 *d = a->as_u8; |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 336 | |
| 337 | ethernet_address[0] = 0x01; |
| 338 | ethernet_address[1] = 0x00; |
| 339 | ethernet_address[2] = 0x5e; |
| 340 | ethernet_address[3] = d[1] & 0x7f; |
| 341 | ethernet_address[4] = d[2]; |
| 342 | ethernet_address[5] = d[3]; |
| 343 | } |
| 344 | |
| 345 | always_inline void |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 346 | ip4_tcp_reply_x1 (ip4_header_t * ip0, tcp_header_t * tcp0) |
| 347 | { |
| 348 | u32 src0, dst0; |
| 349 | |
| 350 | src0 = ip0->src_address.data_u32; |
| 351 | dst0 = ip0->dst_address.data_u32; |
| 352 | ip0->src_address.data_u32 = dst0; |
| 353 | ip0->dst_address.data_u32 = src0; |
| 354 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 355 | src0 = tcp0->src; |
| 356 | dst0 = tcp0->dst; |
| 357 | tcp0->src = dst0; |
| 358 | tcp0->dst = src0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | always_inline void |
| 362 | ip4_tcp_reply_x2 (ip4_header_t * ip0, ip4_header_t * ip1, |
| 363 | tcp_header_t * tcp0, tcp_header_t * tcp1) |
| 364 | { |
| 365 | u32 src0, dst0, src1, dst1; |
| 366 | |
| 367 | src0 = ip0->src_address.data_u32; |
| 368 | src1 = ip1->src_address.data_u32; |
| 369 | dst0 = ip0->dst_address.data_u32; |
| 370 | dst1 = ip1->dst_address.data_u32; |
| 371 | ip0->src_address.data_u32 = dst0; |
| 372 | ip1->src_address.data_u32 = dst1; |
| 373 | ip0->dst_address.data_u32 = src0; |
| 374 | ip1->dst_address.data_u32 = src1; |
| 375 | |
Dave Barach | 68b0fb0 | 2017-02-28 15:15:56 -0500 | [diff] [blame] | 376 | src0 = tcp0->src; |
| 377 | src1 = tcp1->src; |
| 378 | dst0 = tcp0->dst; |
| 379 | dst1 = tcp1->dst; |
| 380 | tcp0->src = dst0; |
| 381 | tcp1->src = dst1; |
| 382 | tcp0->dst = src0; |
| 383 | tcp1->dst = src1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | #endif /* included_ip4_packet_h */ |
Dave Barach | d7cb1b5 | 2016-12-09 09:52:16 -0500 | [diff] [blame] | 387 | |
| 388 | /* |
| 389 | * fd.io coding-style-patch-verification: ON |
| 390 | * |
| 391 | * Local Variables: |
| 392 | * eval: (c-set-style "gnu") |
| 393 | * End: |
| 394 | */ |