blob: 186044b90ad926c273b485018d627ad6ab0c6227 [file] [log] [blame]
Neale Ranns4ec36c52020-03-31 09:21:29 -04001/*
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 Ranns5c544c82020-11-17 09:47:07 +000021#include <vnet/ip/ip4_inlines.h>
22#include <vnet/ip/ip6_inlines.h>
23#include <vnet/mpls/mpls_lookup.h>
Neale Ranns4ec36c52020-03-31 09:21:29 -040024
25static_always_inline void
26adj_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))
Arthur de Kerhor2f4586d2021-09-22 14:53:24 +020039 {
40 if (PREDICT_FALSE (b->flags & VNET_BUFFER_F_GSO))
41 {
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);
45 }
46 else
47 {
48 ip_csum_t sum;
49 u16 old,new;
50 old = 0;
51 new = ip4->length;
52 sum = ip4->checksum;
53 sum = ip_csum_update (sum, old, new, ip4_header_t, length);
54 ip4->checksum = ip_csum_fold (sum);
55 }
56 }
Neale Ranns4ec36c52020-03-31 09:21:29 -040057 else
Arthur de Kerhor2f4586d2021-09-22 14:53:24 +020058 {
Neale Ranns4ec36c52020-03-31 09:21:29 -040059 tunnel_encap_fixup_4o4 (flags, ip4 + 1, ip4);
Arthur de Kerhor2f4586d2021-09-22 14:53:24 +020060 if (PREDICT_FALSE (b->flags & VNET_BUFFER_F_GSO))
61 {
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);
65 }
66 else
67 ip4->checksum = ip4_header_checksum (ip4);
68 }
Neale Ranns4ec36c52020-03-31 09:21:29 -040069}
70
71static_always_inline void
72adj_midchain_fixup (vlib_main_t *vm,
73 const ip_adjacency_t *adj,
Neale Ranns5c544c82020-11-17 09:47:07 +000074 vlib_buffer_t * b,
75 vnet_link_t lt)
Neale Ranns4ec36c52020-03-31 09:21:29 -040076{
Neale Ranns5c544c82020-11-17 09:47:07 +000077 if (PREDICT_TRUE(adj->rewrite_header.flags &
78 VNET_REWRITE_FIXUP_IP4_O_4))
Neale Ranns4ec36c52020-03-31 09:21:29 -040079 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);
Neale Ranns5c544c82020-11-17 09:47:07 +000083
84 if (PREDICT_FALSE(adj->rewrite_header.flags &
85 VNET_REWRITE_FIXUP_FLOW_HASH))
86 {
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);
99 }
Neale Ranns4ec36c52020-03-31 09:21:29 -0400100}
101
102#endif