Line data Source code
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> 21 : #include <vnet/ip/ip4_inlines.h> 22 : #include <vnet/ip/ip6_inlines.h> 23 : #include <vnet/mpls/mpls_lookup.h> 24 : 25 : static_always_inline void 26 6250 : 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 6250 : flags = pointer_to_uword (adj->sub_type.midchain.fixup_data); 34 : 35 6250 : ip4 = vlib_buffer_get_current (b); 36 6250 : ip4->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b)); 37 : 38 6250 : if (PREDICT_TRUE(TUNNEL_ENCAP_DECAP_FLAG_NONE == flags)) 39 : { 40 : ip_csum_t sum; 41 : u16 old,new; 42 : 43 5212 : old = 0; 44 5212 : new = ip4->length; 45 : 46 5212 : sum = ip4->checksum; 47 5212 : sum = ip_csum_update (sum, old, new, ip4_header_t, length); 48 5212 : ip4->checksum = ip_csum_fold (sum); 49 : } 50 : else 51 : { 52 1038 : tunnel_encap_fixup_4o4 (flags, ip4 + 1, ip4); 53 1038 : ip4->checksum = ip4_header_checksum (ip4); 54 : } 55 6250 : } 56 : 57 : static_always_inline void 58 34340 : adj_midchain_fixup (vlib_main_t *vm, 59 : const ip_adjacency_t *adj, 60 : vlib_buffer_t * b, 61 : vnet_link_t lt) 62 : { 63 34340 : if (PREDICT_TRUE(adj->rewrite_header.flags & 64 : VNET_REWRITE_FIXUP_IP4_O_4)) 65 6250 : adj_midchain_ipip44_fixup (vm, adj, b); 66 28090 : else if (adj->sub_type.midchain.fixup_func) 67 21301 : adj->sub_type.midchain.fixup_func 68 : (vm, adj, b, adj->sub_type.midchain.fixup_data); 69 : 70 34340 : if (PREDICT_FALSE(adj->rewrite_header.flags & 71 : VNET_REWRITE_FIXUP_FLOW_HASH)) 72 : { 73 0 : if (VNET_LINK_IP4 == lt) 74 0 : vnet_buffer (b)->ip.flow_hash = 75 0 : ip4_compute_flow_hash (vlib_buffer_get_current (b) + adj->rewrite_header.data_bytes, 76 : IP_FLOW_HASH_DEFAULT); 77 0 : else if (VNET_LINK_IP6 == lt) 78 0 : vnet_buffer (b)->ip.flow_hash = 79 0 : ip6_compute_flow_hash (vlib_buffer_get_current (b) + adj->rewrite_header.data_bytes, 80 : IP_FLOW_HASH_DEFAULT); 81 0 : else if (VNET_LINK_MPLS == lt) 82 0 : vnet_buffer (b)->ip.flow_hash = 83 0 : mpls_compute_flow_hash (vlib_buffer_get_current (b) + adj->rewrite_header.data_bytes, 84 : IP_FLOW_HASH_DEFAULT); 85 : } 86 34340 : } 87 : 88 : #endif