Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 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 | |
Mohsin Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 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> |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 23 | #include <vnet/vnet.h> |
| 24 | |
| 25 | typedef struct |
| 26 | { |
Mohsin Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 27 | i16 l2_hdr_offset; |
| 28 | i16 l3_hdr_offset; |
| 29 | i16 l4_hdr_offset; |
| 30 | u16 l4_hdr_sz; |
| 31 | i16 outer_l2_hdr_offset; |
| 32 | i16 outer_l3_hdr_offset; |
| 33 | i16 outer_l4_hdr_offset; |
| 34 | } gso_header_offset_t; |
| 35 | |
| 36 | typedef struct |
| 37 | { |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 38 | vlib_main_t *vlib_main; |
| 39 | vnet_main_t *vnet_main; |
| 40 | u16 msg_id_base; |
| 41 | } gso_main_t; |
| 42 | |
| 43 | extern gso_main_t gso_main; |
| 44 | |
| 45 | int vnet_sw_interface_gso_enable_disable (u32 sw_if_index, u8 enable); |
| 46 | |
Mohsin Kazmi | 72e7312 | 2019-10-22 13:33:13 +0200 | [diff] [blame] | 47 | static_always_inline gso_header_offset_t |
| 48 | vnet_gso_header_offset_parser (vlib_buffer_t * b0, int is_ip6) |
| 49 | { |
| 50 | gso_header_offset_t gho = { 0 }; |
| 51 | u8 l4_proto = 0; |
| 52 | u8 l4_hdr_sz = 0; |
| 53 | |
| 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))) |
| 60 | { |
| 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; |
| 65 | return gho; |
| 66 | } |
| 67 | |
| 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); |
| 71 | |
| 72 | if (ethernet_frame_is_tagged (ethertype)) |
| 73 | { |
| 74 | ethernet_vlan_header_t *vlan = (ethernet_vlan_header_t *) (eh + 1); |
| 75 | |
| 76 | ethertype = clib_net_to_host_u16 (vlan->type); |
| 77 | l2hdr_sz += sizeof (*vlan); |
| 78 | if (ethertype == ETHERNET_TYPE_VLAN) |
| 79 | { |
| 80 | vlan++; |
| 81 | ethertype = clib_net_to_host_u16 (vlan->type); |
| 82 | l2hdr_sz += sizeof (*vlan); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | gho.l2_hdr_offset = b0->current_data; |
| 87 | gho.l3_hdr_offset = l2hdr_sz; |
| 88 | |
| 89 | if (PREDICT_TRUE (is_ip6 == 0)) |
| 90 | { |
| 91 | ip4_header_t *ip4 = |
| 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; |
| 95 | } |
| 96 | else if (PREDICT_TRUE (is_ip6)) |
| 97 | { |
| 98 | ip6_header_t *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; |
| 103 | } |
| 104 | if (l4_proto == IP_PROTOCOL_TCP) |
| 105 | { |
| 106 | tcp_header_t *tcp = (tcp_header_t *) (vlib_buffer_get_current (b0) + |
| 107 | gho.l4_hdr_offset); |
| 108 | l4_hdr_sz = tcp_header_bytes (tcp); |
| 109 | tcp->checksum = 0; |
| 110 | } |
| 111 | else if (l4_proto == IP_PROTOCOL_UDP) |
| 112 | { |
| 113 | udp_header_t *udp = (udp_header_t *) (vlib_buffer_get_current (b0) + |
| 114 | gho.l4_hdr_offset); |
| 115 | l4_hdr_sz = sizeof (*udp); |
| 116 | udp->checksum = 0; |
| 117 | } |
| 118 | |
| 119 | if (b0->flags & (VNET_BUFFER_F_IS_IP4 | VNET_BUFFER_F_IS_IP6)) |
| 120 | { |
| 121 | gho.l4_hdr_sz = l4_hdr_sz; |
| 122 | } |
| 123 | |
| 124 | return gho; |
| 125 | } |
| 126 | |
Mohsin Kazmi | 29467b5 | 2019-10-08 19:42:38 +0200 | [diff] [blame] | 127 | #endif /* included_gso_h */ |
| 128 | |
| 129 | /* |
| 130 | * fd.io coding-style-patch-verification: ON |
| 131 | * |
| 132 | * Local Variables: |
| 133 | * eval: (c-set-style "gnu") |
| 134 | * End: |
| 135 | */ |