FD.io VPP  v21.06-3-gbb25fbf28
Vector Packet Processing
adj_dp.h
Go to the documentation of this file.
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 
27  const ip_adjacency_t * adj,
28  vlib_buffer_t * b)
29 {
32 
33  flags = pointer_to_uword (adj->sub_type.midchain.fixup_data);
34 
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  {
53  ip4->checksum = ip4_header_checksum (ip4);
54  }
55 }
56 
59  const ip_adjacency_t *adj,
60  vlib_buffer_t * b,
61  vnet_link_t lt)
62 {
63  if (PREDICT_TRUE(adj->rewrite_header.flags &
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);
69 
70  if (PREDICT_FALSE(adj->rewrite_header.flags &
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,
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,
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,
85  }
86 }
87 
88 #endif
adj.h
tunnel_encap_decap_flags_t
enum tunnel_encap_decap_flags_t_ tunnel_encap_decap_flags_t
ip4
vl_api_ip4_address_t ip4
Definition: one.api:376
pointer_to_uword
static uword pointer_to_uword(const void *p)
Definition: types.h:131
ip4_inlines.h
VNET_REWRITE_FIXUP_FLOW_HASH
@ VNET_REWRITE_FIXUP_FLOW_HASH
this adj performs the flow hash fixup
Definition: rewrite.h:67
u16
unsigned short u16
Definition: types.h:57
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
vlib_buffer_length_in_chain
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
Definition: buffer_funcs.h:433
ip4_header_t
Definition: ip4_packet.h:87
VNET_LINK_IP4
@ VNET_LINK_IP4
Definition: interface.h:344
ip6_compute_flow_hash
static u32 ip6_compute_flow_hash(const ip6_header_t *ip, flow_hash_config_t flow_hash_config)
Definition: ip6_inlines.h:49
vnet_buffer
#define vnet_buffer(b)
Definition: buffer.h:437
PREDICT_FALSE
#define PREDICT_FALSE(x)
Definition: clib.h:124
static_always_inline
#define static_always_inline
Definition: clib.h:112
IP_FLOW_HASH_DEFAULT
#define IP_FLOW_HASH_DEFAULT
Default: 5-tuple + flowlabel without the "reverse" bit.
Definition: ip_flow_hash.h:22
VNET_LINK_MPLS
@ VNET_LINK_MPLS
Definition: interface.h:349
mpls_compute_flow_hash
static u32 mpls_compute_flow_hash(const mpls_unicast_header_t *hdr, flow_hash_config_t flow_hash_config)
Definition: mpls_lookup.h:43
tunnel_encap_fixup_4o4
static_always_inline void tunnel_encap_fixup_4o4(tunnel_encap_decap_flags_t flags, const ip4_header_t *inner, ip4_header_t *outer)
Definition: tunnel_dp.h:25
ip_adjacency_t_
IP unicast adjacency.
Definition: adj.h:235
ip6_inlines.h
VNET_REWRITE_FIXUP_IP4_O_4
@ VNET_REWRITE_FIXUP_IP4_O_4
this adj performs IP4 over IP4 fixup
Definition: rewrite.h:62
mpls_lookup.h
ip_adjacency_t_::sub_type
union ip_adjacency_t_::@144 sub_type
adj_midchain_ipip44_fixup
static_always_inline void adj_midchain_ipip44_fixup(vlib_main_t *vm, const ip_adjacency_t *adj, vlib_buffer_t *b)
Definition: adj_dp.h:26
ip4_compute_flow_hash
static u32 ip4_compute_flow_hash(const ip4_header_t *ip, flow_hash_config_t flow_hash_config)
Definition: ip4_inlines.h:51
length
char const int length
Definition: cJSON.h:163
vlib_main_t
Definition: main.h:102
ip_csum_update
#define ip_csum_update(sum, old, new, type, field)
Definition: ip_packet.h:295
vnet_link_t
enum vnet_link_t_ vnet_link_t
Link Type: A description of the protocol of packets on the link.
b
vlib_buffer_t ** b
Definition: nat44_ei_out2in.c:717
VNET_LINK_IP6
@ VNET_LINK_IP6
Definition: interface.h:348
vlib_buffer_get_current
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:257
ip4_header_checksum
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:314
ip_csum_t
uword ip_csum_t
Definition: ip_packet.h:245
adj_midchain_fixup
static_always_inline void adj_midchain_fixup(vlib_main_t *vm, const ip_adjacency_t *adj, vlib_buffer_t *b, vnet_link_t lt)
Definition: adj_dp.h:58
PREDICT_TRUE
#define PREDICT_TRUE(x)
Definition: clib.h:125
ip_csum_fold
static u16 ip_csum_fold(ip_csum_t c)
Definition: ip_packet.h:301
tunnel_dp.h
vlib_buffer_t
VLIB buffer representation.
Definition: buffer.h:111
ip_adjacency_t_::midchain
struct ip_adjacency_t_::@144::@146 midchain
IP_LOOKUP_NEXT_MIDCHAIN.
flags
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105