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:
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.
16 #ifndef included_gso_h
17 #define included_gso_h
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>
31 i16 outer_l2_hdr_offset;
32 i16 outer_l3_hdr_offset;
33 i16 outer_l4_hdr_offset;
34 } gso_header_offset_t;
38 vlib_main_t *vlib_main;
39 vnet_main_t *vnet_main;
43 extern gso_main_t gso_main;
45 int vnet_sw_interface_gso_enable_disable (u32 sw_if_index, u8 enable);
47 static_always_inline gso_header_offset_t
48 vnet_gso_header_offset_parser (vlib_buffer_t * b0, int is_ip6)
50 gso_header_offset_t gho = { 0 };
54 if (PREDICT_TRUE ((b0->flags & (VNET_BUFFER_F_L2_HDR_OFFSET_VALID |
55 VNET_BUFFER_F_L3_HDR_OFFSET_VALID |
56 VNET_BUFFER_F_L4_HDR_OFFSET_VALID)) ==
57 (VNET_BUFFER_F_L2_HDR_OFFSET_VALID |
58 VNET_BUFFER_F_L3_HDR_OFFSET_VALID |
59 VNET_BUFFER_F_L4_HDR_OFFSET_VALID)))
61 gho.l2_hdr_offset = vnet_buffer (b0)->l2_hdr_offset;
62 gho.l3_hdr_offset = vnet_buffer (b0)->l3_hdr_offset;
63 gho.l4_hdr_offset = vnet_buffer (b0)->l4_hdr_offset;
64 gho.l4_hdr_sz = vnet_buffer2 (b0)->gso_l4_hdr_sz;
68 ethernet_header_t *eh = (ethernet_header_t *) vlib_buffer_get_current (b0);
69 u16 ethertype = clib_net_to_host_u16 (eh->type);
70 u16 l2hdr_sz = sizeof (ethernet_header_t);
72 if (ethernet_frame_is_tagged (ethertype))
74 ethernet_vlan_header_t *vlan = (ethernet_vlan_header_t *) (eh + 1);
76 ethertype = clib_net_to_host_u16 (vlan->type);
77 l2hdr_sz += sizeof (*vlan);
78 if (ethertype == ETHERNET_TYPE_VLAN)
81 ethertype = clib_net_to_host_u16 (vlan->type);
82 l2hdr_sz += sizeof (*vlan);
86 gho.l2_hdr_offset = b0->current_data;
87 gho.l3_hdr_offset = l2hdr_sz;
89 if (PREDICT_TRUE (is_ip6 == 0))
92 (ip4_header_t *) (vlib_buffer_get_current (b0) + l2hdr_sz);
93 gho.l4_hdr_offset = l2hdr_sz + ip4_header_bytes (ip4);
94 l4_proto = ip4->protocol;
96 else if (PREDICT_TRUE (is_ip6))
99 (ip6_header_t *) (vlib_buffer_get_current (b0) + l2hdr_sz);
100 /* FIXME IPv6 EH traversal */
101 gho.l4_hdr_offset = l2hdr_sz + sizeof (ip6_header_t);
102 l4_proto = ip6->protocol;
104 if (l4_proto == IP_PROTOCOL_TCP)
106 tcp_header_t *tcp = (tcp_header_t *) (vlib_buffer_get_current (b0) +
108 l4_hdr_sz = tcp_header_bytes (tcp);
111 else if (l4_proto == IP_PROTOCOL_UDP)
113 udp_header_t *udp = (udp_header_t *) (vlib_buffer_get_current (b0) +
115 l4_hdr_sz = sizeof (*udp);
119 if (b0->flags & (VNET_BUFFER_F_IS_IP4 | VNET_BUFFER_F_IS_IP6))
121 gho.l4_hdr_sz = l4_hdr_sz;
127 #endif /* included_gso_h */
130 * fd.io coding-style-patch-verification: ON
133 * eval: (c-set-style "gnu")