FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
gso.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 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 included_gso_h
17 #define included_gso_h
18 
19 #include <vnet/ethernet/ethernet.h>
20 #include <vnet/ip/ip4_packet.h>
21 #include <vnet/ip/ip6_packet.h>
22 #include <vnet/udp/udp_packet.h>
23 #include <vnet/vnet.h>
24 
25 typedef struct
26 {
35 
36 typedef struct
37 {
41 } gso_main_t;
42 
43 extern gso_main_t gso_main;
44 
46 
49 {
50  gso_header_offset_t gho = { 0 };
51  u8 l4_proto = 0;
52  u8 l4_hdr_sz = 0;
53 
55  u16 ethertype = clib_net_to_host_u16 (eh->type);
56  u16 l2hdr_sz = sizeof (ethernet_header_t);
57 
58  if (ethernet_frame_is_tagged (ethertype))
59  {
61 
62  ethertype = clib_net_to_host_u16 (vlan->type);
63  l2hdr_sz += sizeof (*vlan);
64  if (ethertype == ETHERNET_TYPE_VLAN)
65  {
66  vlan++;
67  ethertype = clib_net_to_host_u16 (vlan->type);
68  l2hdr_sz += sizeof (*vlan);
69  }
70  }
71 
72  gho.l2_hdr_offset = b0->current_data;
73  gho.l3_hdr_offset = l2hdr_sz;
74 
75  if (PREDICT_TRUE (is_ip6 == 0))
76  {
77  ip4_header_t *ip4 =
78  (ip4_header_t *) (vlib_buffer_get_current (b0) + l2hdr_sz);
79  gho.l4_hdr_offset = l2hdr_sz + ip4_header_bytes (ip4);
80  l4_proto = ip4->protocol;
81  }
82  else if (PREDICT_TRUE (is_ip6))
83  {
84  ip6_header_t *ip6 =
85  (ip6_header_t *) (vlib_buffer_get_current (b0) + l2hdr_sz);
86  /* FIXME IPv6 EH traversal */
87  gho.l4_hdr_offset = l2hdr_sz + sizeof (ip6_header_t);
88  l4_proto = ip6->protocol;
89  }
90  if (l4_proto == IP_PROTOCOL_TCP)
91  {
93  gho.l4_hdr_offset);
94  l4_hdr_sz = tcp_header_bytes (tcp);
95  tcp->checksum = 0;
96  }
97  else if (l4_proto == IP_PROTOCOL_UDP)
98  {
100  gho.l4_hdr_offset);
101  l4_hdr_sz = sizeof (*udp);
102  udp->checksum = 0;
103  }
104 
105  if (b0->flags & (VNET_BUFFER_F_IS_IP4 | VNET_BUFFER_F_IS_IP6))
106  {
107  gho.l4_hdr_sz = l4_hdr_sz;
108  }
109 
110  return gho;
111 }
112 
113 #endif /* included_gso_h */
114 
115 /*
116  * fd.io coding-style-patch-verification: ON
117  *
118  * Local Variables:
119  * eval: (c-set-style "gnu")
120  * End:
121  */
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:124
#define PREDICT_TRUE(x)
Definition: clib.h:112
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
Definition: buffer.h:110
struct _tcp_header tcp_header_t
vlib_main_t * vlib_main
Definition: gso.h:38
i16 l2_hdr_offset
Definition: gso.h:27
unsigned char u8
Definition: types.h:56
#define static_always_inline
Definition: clib.h:99
i16 l3_hdr_offset
Definition: gso.h:28
vl_api_interface_index_t sw_if_index
Definition: gre.api:59
unsigned int u32
Definition: types.h:88
bool is_ip6
Definition: ip.api:43
gso_main_t gso_main
Definition: gso.c:23
u16 msg_id_base
Definition: gso.h:40
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
u8 ip6[16]
Definition: one.api:477
i16 l4_hdr_offset
Definition: gso.h:29
vnet_main_t * vnet_main
Definition: gso.h:39
i16 outer_l2_hdr_offset
Definition: gso.h:31
static_always_inline int ethernet_frame_is_tagged(u16 type)
Definition: ethernet.h:78
int vnet_sw_interface_gso_enable_disable(u32 sw_if_index, u8 enable)
Definition: gso.c:26
VLIB buffer representation.
Definition: buffer.h:102
static int tcp_header_bytes(tcp_header_t *t)
Definition: tcp_packet.h:93
Definition: gso.h:36
i16 outer_l4_hdr_offset
Definition: gso.h:33
static int ip4_header_bytes(const ip4_header_t *i)
Definition: ip4_packet.h:235
u32 ip4
Definition: one.api:440
i16 outer_l3_hdr_offset
Definition: gso.h:32
static_always_inline gso_header_offset_t vnet_gso_header_offset_parser(vlib_buffer_t *b0, int is_ip6)
Definition: gso.h:48
signed short i16
Definition: types.h:46