summaryrefslogtreecommitdiffstats
path: root/src/vnet/gso/hdr_offset_parser.h
diff options
context:
space:
mode:
authorMohsin Kazmi <sykazmi@cisco.com>2020-04-17 16:50:56 +0000
committerAndrew Yourtchenko <ayourtch@gmail.com>2020-04-22 15:03:34 +0000
commit0b04209edac55487c108ff5f2faf51cbd4c2cee7 (patch)
tree4628b2c65f15bc9b4c628046c72a3c77fadfbab5 /src/vnet/gso/hdr_offset_parser.h
parent6440b7a602fdeb41674911cc3baf0b39a7521b96 (diff)
gso: add vxlan tunnel support
Type: feature Change-Id: I85f6ec77187a4983c66c5e22fd39fbb2cef82902 Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
Diffstat (limited to 'src/vnet/gso/hdr_offset_parser.h')
-rw-r--r--src/vnet/gso/hdr_offset_parser.h408
1 files changed, 408 insertions, 0 deletions
diff --git a/src/vnet/gso/hdr_offset_parser.h b/src/vnet/gso/hdr_offset_parser.h
new file mode 100644
index 00000000000..8f9e0cda984
--- /dev/null
+++ b/src/vnet/gso/hdr_offset_parser.h
@@ -0,0 +1,408 @@
+/*
+ * Copyright (c) 2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef included_hdr_offset_parser_h
+#define included_hdr_offset_parser_h
+
+#include <vnet/ethernet/ethernet.h>
+#include <vnet/ip/ip4_packet.h>
+#include <vnet/ip/ip6_packet.h>
+#include <vnet/udp/udp.h>
+#include <vnet/udp/udp_packet.h>
+#include <vnet/vnet.h>
+#include <vnet/vxlan/vxlan_packet.h>
+
+#define foreach_gho_flag \
+ _( 0, IP4) \
+ _( 1, IP6) \
+ _( 2, TCP) \
+ _( 3, UDP) \
+ _( 4, OUTER_IP4) \
+ _( 5, OUTER_IP6) \
+ _( 6, OUTER_TCP) \
+ _( 7, OUTER_UDP) \
+ _( 8, VXLAN_TUNNEL) \
+ _( 9, GRE_TUNNEL) \
+ _( 10, IPIP_TUNNEL) \
+ _( 11, GENEVE_TUNNEL)
+
+typedef enum gho_flag_t_
+{
+#define _(bit, name) GHO_F_##name = (1 << bit),
+ foreach_gho_flag
+#undef _
+} gho_flag_t;
+
+#define GHO_F_TUNNEL (GHO_F_VXLAN_TUNNEL | \
+ GHO_F_GENEVE_TUNNEL | \
+ GHO_F_IPIP_TUNNEL | \
+ GHO_F_GRE_TUNNEL)
+
+#define GHO_F_OUTER_HDR (GHO_F_OUTER_IP4 | \
+ GHO_F_OUTER_IP6 | \
+ GHO_F_OUTER_TCP | \
+ GHO_F_OUTER_UDP)
+
+#define GHO_F_INNER_HDR (GHO_F_IP4 | \
+ GHO_F_IP6 | \
+ GHO_F_UDP | \
+ GHO_F_TCP)
+
+typedef struct
+{
+ i16 outer_l2_hdr_offset;
+ i16 outer_l3_hdr_offset;
+ i16 outer_l4_hdr_offset;
+ u16 outer_l4_hdr_sz;
+ u16 outer_hdr_sz;
+ i16 l2_hdr_offset;
+ i16 l3_hdr_offset;
+ i16 l4_hdr_offset;
+ u16 l4_hdr_sz;
+ u16 hdr_sz;
+ gho_flag_t gho_flags;
+} generic_header_offset_t;
+
+static_always_inline u8 *
+format_generic_header_offset (u8 * s, va_list * args)
+{
+ generic_header_offset_t *gho = va_arg (*args, generic_header_offset_t *);
+
+ s = format (s, "\n\t");
+ if (gho->gho_flags & GHO_F_TUNNEL)
+ {
+ if (gho->gho_flags & GHO_F_VXLAN_TUNNEL)
+ s = format (s, "vxlan-tunnel ");
+ else if (gho->gho_flags & GHO_F_IPIP_TUNNEL)
+ s = format (s, "ipip-tunnel ");
+ else if (gho->gho_flags & GHO_F_GRE_TUNNEL)
+ s = format (s, "gre-tunnel ");
+ else if (gho->gho_flags & GHO_F_GENEVE_TUNNEL)
+ s = format (s, "geneve-tunnel ");
+
+ if (gho->gho_flags & GHO_F_OUTER_IP4)
+ s = format (s, "outer-ipv4 ");
+ else if (gho->gho_flags & GHO_F_OUTER_IP6)
+ s = format (s, "outer-ipv6 ");
+
+ if (gho->gho_flags & GHO_F_OUTER_UDP)
+ s = format (s, "outer-udp ");
+ else if (gho->gho_flags & GHO_F_OUTER_TCP)
+ s = format (s, "outer-tcp ");
+
+ s = format (s, "outer-hdr-sz %u outer-l2-hdr-offset %d "
+ "outer-l3-hdr-offset %d outer-l4-hdr-offset %d "
+ "outer-l4-hdr-sz %u\n\t",
+ gho->outer_hdr_sz, gho->outer_l2_hdr_offset,
+ gho->outer_l3_hdr_offset, gho->outer_l4_hdr_offset,
+ gho->outer_l4_hdr_sz);
+ }
+
+ if (gho->gho_flags & GHO_F_IP4)
+ s = format (s, "ipv4 ");
+ else if (gho->gho_flags & GHO_F_IP6)
+ s = format (s, "ipv6 ");
+
+ if (gho->gho_flags & GHO_F_TCP)
+ s = format (s, "tcp ");
+ else if (gho->gho_flags & GHO_F_UDP)
+ s = format (s, "udp ");
+
+ s = format (s, "hdr-sz %u l2-hdr-offset %d "
+ "l3-hdr-offset %d l4-hdr-offset %d "
+ "l4-hdr-sz %u",
+ gho->hdr_sz, gho->l2_hdr_offset, gho->l3_hdr_offset,
+ gho->l4_hdr_offset, gho->l4_hdr_sz);
+
+ return s;
+}
+
+static_always_inline void
+vnet_get_inner_header (vlib_buffer_t * b0, generic_header_offset_t * gho)
+{
+ if ((gho->gho_flags & GHO_F_TUNNEL)
+ && (gho->gho_flags & GHO_F_OUTER_HDR)
+ && (b0->current_data == gho->outer_l2_hdr_offset))
+ vlib_buffer_advance (b0, gho->outer_hdr_sz);
+}
+
+static_always_inline void
+vnet_get_outer_header (vlib_buffer_t * b0, generic_header_offset_t * gho)
+{
+ if ((gho->gho_flags & GHO_F_TUNNEL)
+ && (gho->gho_flags & GHO_F_OUTER_HDR)
+ && (b0->current_data == gho->l2_hdr_offset))
+ vlib_buffer_advance (b0, -gho->outer_hdr_sz);
+}
+
+static_always_inline void
+vnet_geneve_inner_header_parser_inline (vlib_buffer_t * b0,
+ generic_header_offset_t * gho)
+{
+ /* not supported yet */
+ if ((gho->gho_flags & GHO_F_GENEVE_TUNNEL) == 0)
+ return;
+
+ ASSERT (0);
+}
+
+static_always_inline void
+vnet_gre_inner_header_parser_inline (vlib_buffer_t * b0,
+ generic_header_offset_t * gho)
+{
+ /* not supported yet */
+ if ((gho->gho_flags & GHO_F_GRE_TUNNEL) == 0)
+ return;
+
+ ASSERT (0);
+}
+
+static_always_inline void
+vnet_ipip_inner_header_parser_inline (vlib_buffer_t * b0,
+ generic_header_offset_t * gho)
+{
+ /* not supported yet */
+ if ((gho->gho_flags & GHO_F_IPIP_TUNNEL) == 0)
+ return;
+
+ ASSERT (0);
+}
+
+static_always_inline void
+vnet_vxlan_inner_header_parser_inline (vlib_buffer_t * b0,
+ generic_header_offset_t * gho)
+{
+ u8 l4_proto = 0;
+ u8 l4_hdr_sz = 0;
+
+ if ((gho->gho_flags & GHO_F_VXLAN_TUNNEL) == 0)
+ return;
+
+ gho->outer_l2_hdr_offset = gho->l2_hdr_offset;
+ gho->outer_l3_hdr_offset = gho->l3_hdr_offset;
+ gho->outer_l4_hdr_offset = gho->l4_hdr_offset;
+ gho->outer_l4_hdr_sz = gho->l4_hdr_sz;
+ gho->outer_hdr_sz = gho->hdr_sz;
+
+ gho->l2_hdr_offset = 0;
+ gho->l3_hdr_offset = 0;
+ gho->l4_hdr_offset = 0;
+ gho->l4_hdr_sz = 0;
+ gho->hdr_sz = 0;
+
+ if (gho->gho_flags & GHO_F_IP4)
+ {
+ gho->gho_flags |= GHO_F_OUTER_IP4;
+ }
+ else if (gho->gho_flags & GHO_F_IP6)
+ {
+ gho->gho_flags |= GHO_F_OUTER_IP6;
+ }
+
+ if (gho->gho_flags & GHO_F_UDP)
+ {
+ gho->gho_flags |= GHO_F_OUTER_UDP;
+ }
+
+ gho->gho_flags &= ~GHO_F_INNER_HDR;
+
+ vnet_get_inner_header (b0, gho);
+
+ gho->l2_hdr_offset = b0->current_data;
+
+ ethernet_header_t *eh = (ethernet_header_t *) vlib_buffer_get_current (b0);
+ u16 ethertype = clib_net_to_host_u16 (eh->type);
+ u16 l2hdr_sz = sizeof (ethernet_header_t);
+
+ if (ethernet_frame_is_tagged (ethertype))
+ {
+ ethernet_vlan_header_t *vlan = (ethernet_vlan_header_t *) (eh + 1);
+
+ ethertype = clib_net_to_host_u16 (vlan->type);
+ l2hdr_sz += sizeof (*vlan);
+ if (ethertype == ETHERNET_TYPE_VLAN)
+ {
+ vlan++;
+ ethertype = clib_net_to_host_u16 (vlan->type);
+ l2hdr_sz += sizeof (*vlan);
+ }
+ }
+
+ gho->l3_hdr_offset = l2hdr_sz;
+
+ if (PREDICT_TRUE (ethertype == ETHERNET_TYPE_IP4))
+ {
+ ip4_header_t *ip4 =
+ (ip4_header_t *) (vlib_buffer_get_current (b0) + gho->l3_hdr_offset);
+ gho->l4_hdr_offset = gho->l3_hdr_offset + ip4_header_bytes (ip4);
+ l4_proto = ip4->protocol;
+ gho->gho_flags |= GHO_F_IP4;
+ }
+ else if (PREDICT_TRUE (ethertype == ETHERNET_TYPE_IP6))
+ {
+ ip6_header_t *ip6 =
+ (ip6_header_t *) (vlib_buffer_get_current (b0) + gho->l3_hdr_offset);
+ /* FIXME IPv6 EH traversal */
+ gho->l4_hdr_offset = gho->l3_hdr_offset + sizeof (ip6_header_t);
+ l4_proto = ip6->protocol;
+ gho->gho_flags |= GHO_F_IP6;
+ }
+ if (l4_proto == IP_PROTOCOL_TCP)
+ {
+ tcp_header_t *tcp = (tcp_header_t *) (vlib_buffer_get_current (b0) +
+ gho->l4_hdr_offset);
+ l4_hdr_sz = tcp_header_bytes (tcp);
+
+ gho->gho_flags |= GHO_F_TCP;
+
+ }
+ else if (l4_proto == IP_PROTOCOL_UDP)
+ {
+ udp_header_t *udp = (udp_header_t *) (vlib_buffer_get_current (b0) +
+ gho->l4_hdr_offset);
+ l4_hdr_sz = sizeof (*udp);
+
+ gho->gho_flags |= GHO_F_UDP;
+ }
+
+ gho->l4_hdr_sz = l4_hdr_sz;
+ gho->hdr_sz += gho->l4_hdr_offset + l4_hdr_sz;
+
+ vnet_get_outer_header (b0, gho);
+}
+
+static_always_inline void
+vnet_generic_inner_header_parser_inline (vlib_buffer_t * b0,
+ generic_header_offset_t * gho)
+{
+
+ if (gho->gho_flags & GHO_F_VXLAN_TUNNEL)
+ vnet_vxlan_inner_header_parser_inline (b0, gho);
+ else if (gho->gho_flags & GHO_F_IPIP_TUNNEL)
+ vnet_ipip_inner_header_parser_inline (b0, gho);
+ else if (gho->gho_flags & GHO_F_GRE_TUNNEL)
+ vnet_gre_inner_header_parser_inline (b0, gho);
+ else if (gho->gho_flags & GHO_F_GENEVE_TUNNEL)
+ vnet_geneve_inner_header_parser_inline (b0, gho);
+}
+
+static_always_inline void
+vnet_generic_outer_header_parser_inline (vlib_buffer_t * b0,
+ generic_header_offset_t * gho)
+{
+ u8 l4_proto = 0;
+ u8 l4_hdr_sz = 0;
+
+ ethernet_header_t *eh = (ethernet_header_t *) vlib_buffer_get_current (b0);
+ u16 ethertype = clib_net_to_host_u16 (eh->type);
+ u16 l2hdr_sz = sizeof (ethernet_header_t);
+
+ if (ethernet_frame_is_tagged (ethertype))
+ {
+ ethernet_vlan_header_t *vlan = (ethernet_vlan_header_t *) (eh + 1);
+
+ ethertype = clib_net_to_host_u16 (vlan->type);
+ l2hdr_sz += sizeof (*vlan);
+ if (ethertype == ETHERNET_TYPE_VLAN)
+ {
+ vlan++;
+ ethertype = clib_net_to_host_u16 (vlan->type);
+ l2hdr_sz += sizeof (*vlan);
+ }
+ }
+
+ gho->l2_hdr_offset = b0->current_data;
+ gho->l3_hdr_offset = l2hdr_sz;
+
+ if (PREDICT_TRUE (ethertype == ETHERNET_TYPE_IP4))
+ {
+ ip4_header_t *ip4 =
+ (ip4_header_t *) (vlib_buffer_get_current (b0) + l2hdr_sz);
+ gho->l4_hdr_offset = l2hdr_sz + ip4_header_bytes (ip4);
+ l4_proto = ip4->protocol;
+ gho->gho_flags |= GHO_F_IP4;
+ }
+ else if (PREDICT_TRUE (ethertype == ETHERNET_TYPE_IP6))
+ {
+ ip6_header_t *ip6 =
+ (ip6_header_t *) (vlib_buffer_get_current (b0) + l2hdr_sz);
+ /* FIXME IPv6 EH traversal */
+ gho->l4_hdr_offset = l2hdr_sz + sizeof (ip6_header_t);
+ l4_proto = ip6->protocol;
+ gho->gho_flags |= GHO_F_IP6;
+ }
+ if (l4_proto == IP_PROTOCOL_TCP)
+ {
+ tcp_header_t *tcp = (tcp_header_t *) (vlib_buffer_get_current (b0) +
+ gho->l4_hdr_offset);
+ l4_hdr_sz = tcp_header_bytes (tcp);
+
+ gho->gho_flags |= GHO_F_TCP;
+ }
+ else if (l4_proto == IP_PROTOCOL_UDP)
+ {
+ udp_header_t *udp = (udp_header_t *) (vlib_buffer_get_current (b0) +
+ gho->l4_hdr_offset);
+ l4_hdr_sz = sizeof (*udp);
+
+ gho->gho_flags |= GHO_F_UDP;
+
+ if (UDP_DST_PORT_vxlan == clib_net_to_host_u16 (udp->dst_port))
+ {
+ gho->gho_flags |= GHO_F_VXLAN_TUNNEL;
+ gho->hdr_sz += sizeof (vxlan_header_t);
+ }
+ else if (UDP_DST_PORT_geneve == clib_net_to_host_u16 (udp->dst_port))
+ {
+ gho->gho_flags |= GHO_F_GENEVE_TUNNEL;
+ }
+ }
+ else if ((l4_proto == IP_PROTOCOL_IP_IN_IP)
+ || (l4_proto == IP_PROTOCOL_IPV6))
+ {
+ l4_hdr_sz = 0;
+ gho->gho_flags |= GHO_F_IPIP_TUNNEL;
+ }
+ else if (l4_proto == IP_PROTOCOL_GRE)
+ {
+ l4_hdr_sz = 0;
+ gho->gho_flags |= GHO_F_GRE_TUNNEL;
+ }
+
+ gho->l4_hdr_sz = l4_hdr_sz;
+ gho->hdr_sz += gho->l4_hdr_offset + l4_hdr_sz;
+}
+
+static_always_inline void
+vnet_generic_header_offset_parser (vlib_buffer_t * b0,
+ generic_header_offset_t * gho)
+{
+ vnet_generic_outer_header_parser_inline (b0, gho);
+
+ if (gho->gho_flags & GHO_F_TUNNEL)
+ {
+ vnet_generic_inner_header_parser_inline (b0, gho);
+ }
+}
+
+#endif /* included_hdr_offset_parser_h */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
ss="o">=redefined-variable-type, locally-disabled [REPORTS] # Set the output format. Available formats are text, parseable, colorized, msvs # (visual studio) and html. You can also give a reporter class, eg # mypackage.mymodule.MyReporterClass. output-format=parseable # Put messages in a separate file for each module / package specified on the # command line instead of printing them on stdout. Reports (if any) will be # written in a file name "pylint_global.[txt|html]". files-output=no # Tells whether to display a full report or only the messages reports=yes # Python expression which should return a note less than 10 (10 is the highest # note). You have access to the variables errors warning, statement which # respectively contain the number of errors / warnings messages and the total # number of statements analyzed. This is used by the global evaluation report # (RP0004). evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) # Add a comment according to your evaluation note. This is used by the global # evaluation report (RP0004). comment=no # Template used to display messages. This is a python new-style format string # used to format the message information. See doc for all details #msg-template= [FORMAT] # Maximum number of characters on a single line. max-line-length=80 # Regexp for a line that is allowed to be longer than the limit. ignore-long-lines=^\s*(# )?<?https?://\S+>?$ # Allow the body of an if to be on the same line as the test if there is no # else. single-line-if-stmt=no # List of optional constructs for which whitespace checking is disabled no-space-check=trailing-comma,dict-separator # Maximum number of lines in a module max-module-lines=2000 # String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 # tab). indent-string=' ' [VARIABLES] # Tells whether we should check for unused import in __init__ files. init-import=no # A regular expression matching the beginning of the name of dummy variables # (i.e. not used). dummy-variables-rgx=_$|dummy # List of additional names supposed to be defined in builtins. Remember that # you should avoid to define new builtins when possible. additional-builtins= [SIMILARITIES] # Minimum lines number of a similarity. min-similarity-lines=14 # Ignore comments when computing similarities. ignore-comments=yes # Ignore docstrings when computing similarities. ignore-docstrings=no # Ignore imports when computing similarities. ignore-imports=no [BASIC] # Required attributes for module, separated by a comma required-attributes= # List of builtins function names that should not be used, separated by a comma bad-functions=map,filter,apply,input # Regular expression which should only match correct module names module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ # Regular expression which should only match correct module level names const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ # Regular expression which should only match correct class names class-rgx=[A-Z_][a-zA-Z0-9]+$ # Regular expression which should only match correct function names function-rgx=[a-z_][a-z0-9_]{2,30}$ # Regular expression which should only match correct method names method-rgx=[a-z_][a-z0-9_]{2,50}$ # Regular expression which should only match correct instance attribute names attr-rgx=[a-z_][a-z0-9_]{2,30}$ # Regular expression which should only match correct argument names argument-rgx=[a-z_][a-z0-9_]{2,30}$ # Regular expression which should only match correct variable names variable-rgx=[a-z_][a-z0-9_]{2,30}$ # Regular expression which should only match correct attribute names in class # bodies class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ # Regular expression which should only match correct list comprehension / # generator expression variable names inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ # Good variable names which should always be accepted, separated by a comma good-names=i,j,k,ex,Run,_ # Bad variable names which should always be refused, separated by a comma bad-names=foo,bar,baz,toto,tutu,tata # Regular expression which should only match function or class names that do # not require a docstring. no-docstring-rgx=__.*__ # Minimum line length for functions/classes that require docstrings, shorter # ones are exempt. docstring-min-length=-1 [MISCELLANEOUS] # List of note tags to take in consideration, separated by a comma. notes=FIXME [TYPECHECK] # Tells whether missing members accessed in mixin class should be ignored. A # mixin class is detected if its name ends with "mixin" (case insensitive). ignore-mixin-members=yes # List of classes names for which member attributes should not be checked # (useful for classes with attributes dynamically set). ignored-classes=SQLObject # When zope mode is activated, add a predefined set of Zope acquired attributes # to generated-members. zope=no # List of members which are set dynamically and missed by pylint inference # system, and so shouldn't trigger E0201 when accessed. Python regular # expressions are accepted. generated-members=REQUEST,acl_users,aq_parent [CLASSES] # List of interface methods to ignore, separated by a comma. This is used for # instance to not check methods defines in Zope's Interface base class. ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by # List of method names used to declare (i.e. assign) instance attributes. defining-attr-methods=__init__,__new__,setUp # List of valid names for the first argument in a class method. valid-classmethod-first-arg=cls # List of valid names for the first argument in a metaclass class method. valid-metaclass-classmethod-first-arg=mcs [IMPORTS] # Deprecated modules which should not be used, separated by a comma deprecated-modules=regsub,TERMIOS,Bastion,rexec # Create a graph of every (i.e. internal and external) dependencies in the # given file (report RP0402 must not be disabled) import-graph= # Create a graph of external dependencies in the given file (report RP0402 must # not be disabled) ext-import-graph= # Create a graph of internal dependencies in the given file (report RP0402 must # not be disabled) int-import-graph= [DESIGN] # Maximum number of arguments for function / method max-args=12 # Argument names that match this expression will be ignored. Default to name # with leading underscore ignored-argument-names=_.* # Maximum number of locals for function / method body max-locals=20 # Maximum number of return / yield for function / method body max-returns=6 # Maximum number of branch for function / method body max-branches=20 # Maximum number of statements in function / method body max-statements=60 # Maximum number of parents for a class (see R0901). max-parents=7 # Maximum number of attributes for a class (see R0902). max-attributes=10 # Minimum number of public methods for a class (see R0903). min-public-methods=0 # Maximum number of public methods for a class (see R0904). max-public-methods=60 [EXCEPTIONS] # Exceptions that will emit a warning when being caught. Defaults to # "Exception" overgeneral-exceptions=Exception