FD.io VPP  v20.05.1-6-gf53edbc3b
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 
24  const ip_adjacency_t * adj,
25  vlib_buffer_t * b)
26 {
29 
30  flags = pointer_to_uword (adj->sub_type.midchain.fixup_data);
31 
32  ip4 = vlib_buffer_get_current (b);
33  ip4->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b));
34 
35  if (PREDICT_TRUE(TUNNEL_ENCAP_DECAP_FLAG_NONE == flags))
36  {
37  ip_csum_t sum;
38  u16 old,new;
39 
40  old = 0;
41  new = ip4->length;
42 
43  sum = ip4->checksum;
44  sum = ip_csum_update (sum, old, new, ip4_header_t, length);
45  ip4->checksum = ip_csum_fold (sum);
46  }
47  else
48  {
49  tunnel_encap_fixup_4o4 (flags, ip4 + 1, ip4);
50  ip4->checksum = ip4_header_checksum (ip4);
51  }
52 }
53 
56  const ip_adjacency_t *adj,
57  vlib_buffer_t * b)
58 {
59  if (PREDICT_TRUE(adj->rewrite_header.flags & VNET_REWRITE_FIXUP_IP4_O_4))
60  adj_midchain_ipip44_fixup (vm, adj, b);
61  else if (adj->sub_type.midchain.fixup_func)
62  adj->sub_type.midchain.fixup_func
63  (vm, adj, b, adj->sub_type.midchain.fixup_data);
64 }
65 
66 #endif
#define PREDICT_TRUE(x)
Definition: clib.h:119
IP unicast adjacency.
Definition: adj.h:227
uword ip_csum_t
Definition: ip_packet.h:244
union ip_adjacency_t_::@137 sub_type
static_always_inline void adj_midchain_fixup(vlib_main_t *vm, const ip_adjacency_t *adj, vlib_buffer_t *b)
Definition: adj_dp.h:55
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:402
#define static_always_inline
Definition: clib.h:106
this adj performs IP4 over IP4 fixup
Definition: rewrite.h:62
struct ip_adjacency_t_::@137::@139 midchain
IP_LOOKUP_NEXT_MIDCHAIN.
unsigned short u16
Definition: types.h:57
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:229
vl_api_ip4_address_t ip4
Definition: one.api:376
enum tunnel_encap_decap_flags_t_ tunnel_encap_decap_flags_t
vlib_main_t * vm
Definition: in2out_ed.c:1599
u32 flags
Definition: vhost_user.h:248
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:24
static uword pointer_to_uword(const void *p)
Definition: types.h:131
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:23
VLIB buffer representation.
Definition: buffer.h:102
#define ip_csum_update(sum, old, new, type, field)
Definition: ip_packet.h:294
static u16 ip4_header_checksum(ip4_header_t *i)
Definition: ip4_packet.h:247
static u16 ip_csum_fold(ip_csum_t c)
Definition: ip_packet.h:300