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))
40 if (PREDICT_FALSE (b->flags & VNET_BUFFER_F_GSO))
42 vnet_buffer2 (b)->outer_l3_hdr_offset = (u8 *) ip4 - b->data;
43 vnet_buffer_offload_flags_set (b, VNET_BUFFER_OFFLOAD_F_TNL_IPIP |
44 VNET_BUFFER_OFFLOAD_F_OUTER_IP_CKSUM);
53 sum = ip_csum_update (sum, old, new, ip4_header_t, length);
54 ip4->checksum = ip_csum_fold (sum);
59 tunnel_encap_fixup_4o4 (flags, ip4 + 1, ip4);
60 if (PREDICT_FALSE (b->flags & VNET_BUFFER_F_GSO))
62 vnet_buffer2 (b)->outer_l3_hdr_offset = (u8 *) ip4 - b->data;
63 vnet_buffer_offload_flags_set (b, VNET_BUFFER_OFFLOAD_F_TNL_IPIP |
64 VNET_BUFFER_OFFLOAD_F_OUTER_IP_CKSUM);
67 ip4->checksum = ip4_header_checksum (ip4);
71 static_always_inline void
72 adj_midchain_fixup (vlib_main_t *vm,
73 const ip_adjacency_t *adj,
77 if (PREDICT_TRUE(adj->rewrite_header.flags &
78 VNET_REWRITE_FIXUP_IP4_O_4))
79 adj_midchain_ipip44_fixup (vm, adj, b);
80 else if (adj->sub_type.midchain.fixup_func)
81 adj->sub_type.midchain.fixup_func
82 (vm, adj, b, adj->sub_type.midchain.fixup_data);
84 if (PREDICT_FALSE(adj->rewrite_header.flags &
85 VNET_REWRITE_FIXUP_FLOW_HASH))
87 if (VNET_LINK_IP4 == lt)
88 vnet_buffer (b)->ip.flow_hash =
89 ip4_compute_flow_hash (vlib_buffer_get_current (b) + adj->rewrite_header.data_bytes,
90 IP_FLOW_HASH_DEFAULT);
91 else if (VNET_LINK_IP6 == lt)
92 vnet_buffer (b)->ip.flow_hash =
93 ip6_compute_flow_hash (vlib_buffer_get_current (b) + adj->rewrite_header.data_bytes,
94 IP_FLOW_HASH_DEFAULT);
95 else if (VNET_LINK_MPLS == lt)
96 vnet_buffer (b)->ip.flow_hash =
97 mpls_compute_flow_hash (vlib_buffer_get_current (b) + adj->rewrite_header.data_bytes,
98 IP_FLOW_HASH_DEFAULT);