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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
25 static_always_inline void
26 adj_midchain_ipip44_fixup (vlib_main_t * vm,
27 const ip_adjacency_t * adj,
30 tunnel_encap_decap_flags_t flags;
33 flags = pointer_to_uword (adj->sub_type.midchain.fixup_data);
35 ip4 = vlib_buffer_get_current (b);
36 ip4->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b));
38 if (PREDICT_TRUE(TUNNEL_ENCAP_DECAP_FLAG_NONE == flags))
47 sum = ip_csum_update (sum, old, new, ip4_header_t, length);
48 ip4->checksum = ip_csum_fold (sum);
52 tunnel_encap_fixup_4o4 (flags, ip4 + 1, ip4);
53 ip4->checksum = ip4_header_checksum (ip4);
57 static_always_inline void
58 adj_midchain_fixup (vlib_main_t *vm,
59 const ip_adjacency_t *adj,
63 if (PREDICT_TRUE(adj->rewrite_header.flags &
64 VNET_REWRITE_FIXUP_IP4_O_4))
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);
70 if (PREDICT_FALSE(adj->rewrite_header.flags &
71 VNET_REWRITE_FIXUP_FLOW_HASH))
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);