Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 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 | #ifndef __ADJ_DP_H__ |
| 17 | #define __ADJ_DP_H__ |
| 18 | |
| 19 | #include <vnet/adj/adj.h> |
| 20 | #include <vnet/tunnel/tunnel_dp.h> |
Neale Ranns | 5c544c8 | 2020-11-17 09:47:07 +0000 | [diff] [blame] | 21 | #include <vnet/ip/ip4_inlines.h> |
| 22 | #include <vnet/ip/ip6_inlines.h> |
| 23 | #include <vnet/mpls/mpls_lookup.h> |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 24 | |
| 25 | static_always_inline void |
| 26 | adj_midchain_ipip44_fixup (vlib_main_t * vm, |
| 27 | const ip_adjacency_t * adj, |
| 28 | vlib_buffer_t * b) |
| 29 | { |
| 30 | tunnel_encap_decap_flags_t flags; |
| 31 | ip4_header_t *ip4; |
| 32 | |
| 33 | flags = pointer_to_uword (adj->sub_type.midchain.fixup_data); |
| 34 | |
| 35 | ip4 = vlib_buffer_get_current (b); |
| 36 | ip4->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b)); |
| 37 | |
| 38 | if (PREDICT_TRUE(TUNNEL_ENCAP_DECAP_FLAG_NONE == flags)) |
| 39 | { |
| 40 | ip_csum_t sum; |
| 41 | u16 old,new; |
| 42 | |
| 43 | old = 0; |
| 44 | new = ip4->length; |
| 45 | |
| 46 | sum = ip4->checksum; |
| 47 | sum = ip_csum_update (sum, old, new, ip4_header_t, length); |
| 48 | ip4->checksum = ip_csum_fold (sum); |
| 49 | } |
| 50 | else |
| 51 | { |
| 52 | tunnel_encap_fixup_4o4 (flags, ip4 + 1, ip4); |
| 53 | ip4->checksum = ip4_header_checksum (ip4); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | static_always_inline void |
| 58 | adj_midchain_fixup (vlib_main_t *vm, |
| 59 | const ip_adjacency_t *adj, |
Neale Ranns | 5c544c8 | 2020-11-17 09:47:07 +0000 | [diff] [blame] | 60 | vlib_buffer_t * b, |
| 61 | vnet_link_t lt) |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 62 | { |
Neale Ranns | 5c544c8 | 2020-11-17 09:47:07 +0000 | [diff] [blame] | 63 | if (PREDICT_TRUE(adj->rewrite_header.flags & |
| 64 | VNET_REWRITE_FIXUP_IP4_O_4)) |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 65 | adj_midchain_ipip44_fixup (vm, adj, b); |
| 66 | else if (adj->sub_type.midchain.fixup_func) |
| 67 | adj->sub_type.midchain.fixup_func |
| 68 | (vm, adj, b, adj->sub_type.midchain.fixup_data); |
Neale Ranns | 5c544c8 | 2020-11-17 09:47:07 +0000 | [diff] [blame] | 69 | |
| 70 | if (PREDICT_FALSE(adj->rewrite_header.flags & |
| 71 | VNET_REWRITE_FIXUP_FLOW_HASH)) |
| 72 | { |
| 73 | if (VNET_LINK_IP4 == lt) |
| 74 | vnet_buffer (b)->ip.flow_hash = |
| 75 | ip4_compute_flow_hash (vlib_buffer_get_current (b) + adj->rewrite_header.data_bytes, |
| 76 | IP_FLOW_HASH_DEFAULT); |
| 77 | else if (VNET_LINK_IP6 == lt) |
| 78 | vnet_buffer (b)->ip.flow_hash = |
| 79 | ip6_compute_flow_hash (vlib_buffer_get_current (b) + adj->rewrite_header.data_bytes, |
| 80 | IP_FLOW_HASH_DEFAULT); |
| 81 | else if (VNET_LINK_MPLS == lt) |
| 82 | vnet_buffer (b)->ip.flow_hash = |
| 83 | mpls_compute_flow_hash (vlib_buffer_get_current (b) + adj->rewrite_header.data_bytes, |
| 84 | IP_FLOW_HASH_DEFAULT); |
| 85 | } |
Neale Ranns | 4ec36c5 | 2020-03-31 09:21:29 -0400 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | #endif |