From patchwork Tue Mar 22 23:17:38 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ben@skyportsystems.com X-Patchwork-Id: 601075 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (archives.nicira.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 3qV8430s4Wz9s4x for ; Wed, 23 Mar 2016 10:27:15 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=skyportsystems.com header.i=@skyportsystems.com header.b=s+eGljdd; dkim-atps=neutral Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 658541059F; Tue, 22 Mar 2016 16:27:14 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v3.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id E289E10589 for ; Tue, 22 Mar 2016 16:27:12 -0700 (PDT) Received: from bar6.cudamail.com (localhost [127.0.0.1]) by mx3v3.cudamail.com (Postfix) with ESMTPS id 765FA161D64 for ; Tue, 22 Mar 2016 17:27:12 -0600 (MDT) X-ASG-Debug-ID: 1458688685-0b3237637b0bdb0001-byXFYA Received: from mx1-pf1.cudamail.com ([192.168.24.1]) by bar6.cudamail.com with ESMTP id MB29aD9TZiI0DAP1 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 22 Mar 2016 17:18:05 -0600 (MDT) X-Barracuda-Envelope-From: ben@skyportsystems.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.1 Received: from unknown (HELO mail-pf0-f170.google.com) (209.85.192.170) by mx1-pf1.cudamail.com with ESMTPS (RC4-SHA encrypted); 22 Mar 2016 23:18:05 -0000 Received-SPF: pass (mx1-pf1.cudamail.com: SPF record at _netblocks.google.com designates 209.85.192.170 as permitted sender) X-Barracuda-RBL-Trusted-Forwarder: 209.85.192.170 Received: by mail-pf0-f170.google.com with SMTP id x3so330010244pfb.1 for ; Tue, 22 Mar 2016 16:18:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skyportsystems.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=tRskMp1Q6MzAGCERBDBysskbk6a02tNxAVlYBgNg2kE=; b=s+eGljdde4tj9XwLZMJen25TA3Wt23HqwTMnXd21KiMa3QViRstDxz2kKMaevlvLZl NIYgHIREPUST6EiyMRvYJhHtSHDlpndC1vVdged7OkGo6/EH6eFQlZvUEXZjaseapegB ZmuREOSjvKIQiTl+x/noraZGUgcrM1Mtw7AUQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=tRskMp1Q6MzAGCERBDBysskbk6a02tNxAVlYBgNg2kE=; b=gwMteAV6904/LWL9N0h5veon07g1GdI8gtGPEb3ff/NY9AblYtgDoDjbkpPhN+Aawz Dj9DdVK4nybC71K5LXz4O4AeP071MFeWJ5mr7ai1dLdpGtnkO5U1WzfEKbTNAgIglX3q qy1/H7J8w2b6/wKG0DYUbB7Hh/r94ymrH2K5tLturPmwrbMTG3Euy9UFpbRWoQgLW/Lg Qp5xE4gqwRJe71zpgu5y7qlywqxxrc/xTUzH+oP4TydayHMdfX+zmuIxqaVoymi9bqlp pBNVtSmH4BjzkH/kGcDQFZ48ObWzSUeRExlbr+qMNu/JltHAi1JNkoM0ZztWp4SAi+lD bzrA== X-Gm-Message-State: AD7BkJI8X9aXDi4rZie71y3r2uqoe2j6Mfyldis18TPMJiizx2ep+Z0oHL6iX2unnfcXdZJi X-Received: by 10.66.124.226 with SMTP id ml2mr57534675pab.90.1458688684815; Tue, 22 Mar 2016 16:18:04 -0700 (PDT) Received: from Arrow.corp.skyportsystems.com (67-207-112-138.static.wiline.com. [67.207.112.138]) by smtp.gmail.com with ESMTPSA id 9sm50729385pft.44.2016.03.22.16.18.04 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 22 Mar 2016 16:18:04 -0700 (PDT) X-CudaMail-Envelope-Sender: ben@skyportsystems.com X-Barracuda-Apparent-Source-IP: 67.207.112.138 From: ben@skyportsystems.com To: dev@openvswitch.org X-CudaMail-MID: CM-E1-321097853 X-CudaMail-DTE: 032216 X-CudaMail-Originating-IP: 209.85.192.170 Date: Tue, 22 Mar 2016 16:17:38 -0700 X-ASG-Orig-Subj: [##CM-E1-321097853##][PATCH v4 07/22] Break tun-metadata.h into private and public parts Message-Id: <4708d881a5b0328039ccdabbede7c82e347c6347.1458688105.git.ben@skyportsystems.com> X-Mailer: git-send-email 2.5.4 (Apple Git-61) In-Reply-To: References: In-Reply-To: References: X-Barracuda-Connect: UNKNOWN[192.168.24.1] X-Barracuda-Start-Time: 1458688685 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.60 X-Barracuda-Spam-Status: No, SCORE=0.60 using per-user scores of TAG_LEVEL=3.5 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=4.0 tests=BSF_SC5_MJ1963, DKIM_SIGNED, NO_REAL_NAME, RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.28069 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.00 NO_REAL_NAME From: does not include a real name 0.00 DKIM_SIGNED Domain Keys Identified Mail: message has a signature 0.10 RDNS_NONE Delivered to trusted network by a host with no rDNS 0.50 BSF_SC5_MJ1963 Custom Rule MJ1963 Cc: Ben Warren Subject: [ovs-dev] [PATCH v4 07/22] Break tun-metadata.h into private and public parts X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" From: Ben Warren Public (struct definitions and some prototypes) go in include/openvswitch Signed-off-by: Ben Warren --- include/openvswitch/automake.mk | 1 + include/openvswitch/tun-metadata.h | 101 +++++++++++++++++++++++++++++++++++++ lib/tun-metadata.h | 80 +---------------------------- 3 files changed, 103 insertions(+), 79 deletions(-) create mode 100644 include/openvswitch/tun-metadata.h diff --git a/include/openvswitch/automake.mk b/include/openvswitch/automake.mk index 67c164d..8d253f3 100644 --- a/include/openvswitch/automake.mk +++ b/include/openvswitch/automake.mk @@ -9,6 +9,7 @@ openvswitchinclude_HEADERS = \ include/openvswitch/ofp-parse.h \ include/openvswitch/thread.h \ include/openvswitch/token-bucket.h \ + include/openvswitch/tun-metadata.h \ include/openvswitch/types.h \ include/openvswitch/util.h \ include/openvswitch/version.h \ diff --git a/include/openvswitch/tun-metadata.h b/include/openvswitch/tun-metadata.h new file mode 100644 index 0000000..8e3a13f --- /dev/null +++ b/include/openvswitch/tun-metadata.h @@ -0,0 +1,101 @@ +/* + * Copyright (c) 2015 Nicira, Inc. + * + * 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 OPENVSWITCH_TUN_METADATA_H +#define OPENVSWITCH_TUN_METADATA_H 1 + +#include "openvswitch/geneve.h" + +#define TUN_METADATA_NUM_OPTS 64 +#define TUN_METADATA_TOT_OPT_SIZE 256 + +/* Tunnel option data, plus metadata to aid in their interpretation. + * + * The option data exists in two forms and is interpreted differently depending + * on whether FLOW_TNL_F_UDPIF is set in struct flow_tnl flags: + * + * When FLOW_TNL_F_UDPIF is set, the tunnel metadata is in "userspace datapath + * format". This is typically used for fast-path packet processing to avoid + * the cost of translating options and in situations where we need to maintain + * tunnel metadata exactly as it came in. In this case 'opts.gnv' is raw + * packet data from the tunnel header and 'present.len' indicates the length + * of the data stored there. In these situations, 'tab' is NULL. + * + * In all other cases, we are doing flow-based processing (such as during + * upcalls). FLOW_TNL_F_UDPIF is not set and options are reordered into + * pre-allocated locations. 'present.map' is indexed by type, that is, by the + * in TUN_METADATA, so that e.g. TUN_METADATA5 is present if + * 'present.map & (1ULL << 5)' is nonzero. The actual data for TUN_METADATA5, + * if present, might be anywhere in 'opts.u8' (not necessarily even contiguous), + * and finding it requires referring to 'tab', if set, or the global metadata + * table. */ +struct tun_metadata { + union { /* Valid members of 'opts'. When 'opts' is sorted into known types, + * 'map' is used. When 'opts' is raw packet data, 'len' is used. */ + uint64_t map; /* 1-bit for each present TLV. */ + uint8_t len; /* Length of data in 'opts'. */ + } present; + struct tun_table *tab; /* Types & lengths for 'opts' and 'opt_map'. */ + +#if UINTPTR_MAX == UINT32_MAX + uint8_t pad[4]; /* Pad to 64-bit boundary. */ +#endif + + union { + uint8_t u8[TUN_METADATA_TOT_OPT_SIZE]; /* Values from tunnel TLVs. */ + struct geneve_opt gnv[TLV_TOT_OPT_SIZE / sizeof(struct geneve_opt)]; + } opts; +}; +BUILD_ASSERT_DECL(offsetof(struct tun_metadata, opts) % 8 == 0); +BUILD_ASSERT_DECL(sizeof(((struct tun_metadata *)0)->present.map) * 8 >= + TUN_METADATA_NUM_OPTS); + +/* The location of an option can be stored either as a single offset/len + * pair (hopefully) or if the address space is fragmented then it is a + * linked list of these blocks. */ +struct tun_metadata_loc_chain { + struct tun_metadata_loc_chain *next; + int offset; /* In bytes, from start of 'opts', multiple of 4. */ + int len; /* In bytes, multiple of 4. */ +}; + +struct tun_metadata_loc { + int len; /* Sum of 'len' over elements in chain. */ + struct tun_metadata_loc_chain c; +}; + +/* Bookkeeping information to keep track of an option that was allocated + * inside struct match. */ +struct tun_metadata_match_entry { + struct tun_metadata_loc loc; /* Allocated position. */ + bool masked; /* Source value had a mask. Otherwise we can't tell if the + * entire field was exact matched or only the portion that + * is the same size as the value. */ +}; + +/* Allocation of options inside struct match. This is important if we don't + * have access to a global allocation table - either because there isn't one + * (ovs-ofctl) or if we need to keep the allocation outside of packet + * processing context (Packet-In). These structures never have dynamically + * allocated memory because the address space is never fragmented. */ +struct tun_metadata_allocation { + struct tun_metadata_match_entry entry[TUN_METADATA_NUM_OPTS]; + int alloc_offset; /* Byte offset into 'opts', multiple of 4. */ + bool valid; /* Set to true after any allocation occurs. */ +}; + + +#endif /* tun-metadata.h */ diff --git a/lib/tun-metadata.h b/lib/tun-metadata.h index f52c4fa..4ce0770 100644 --- a/lib/tun-metadata.h +++ b/lib/tun-metadata.h @@ -23,7 +23,7 @@ #include "netlink.h" #include "openvswitch/ofpbuf.h" #include "openflow/openflow.h" -#include "openvswitch/geneve.h" +#include "openvswitch/tun-metadata.h" struct flow_tnl; struct match; @@ -33,84 +33,6 @@ struct ofputil_tlv_table_mod; struct ofputil_tlv_table_reply; struct tun_table; -#define TUN_METADATA_NUM_OPTS 64 -#define TUN_METADATA_TOT_OPT_SIZE 256 - -/* Tunnel option data, plus metadata to aid in their interpretation. - * - * The option data exists in two forms and is interpreted differently depending - * on whether FLOW_TNL_F_UDPIF is set in struct flow_tnl flags: - * - * When FLOW_TNL_F_UDPIF is set, the tunnel metadata is in "userspace datapath - * format". This is typically used for fast-path packet processing to avoid - * the cost of translating options and in situations where we need to maintain - * tunnel metadata exactly as it came in. In this case 'opts.gnv' is raw - * packet data from the tunnel header and 'present.len' indicates the length - * of the data stored there. In these situations, 'tab' is NULL. - * - * In all other cases, we are doing flow-based processing (such as during - * upcalls). FLOW_TNL_F_UDPIF is not set and options are reordered into - * pre-allocated locations. 'present.map' is indexed by type, that is, by the - * in TUN_METADATA, so that e.g. TUN_METADATA5 is present if - * 'present.map & (1ULL << 5)' is nonzero. The actual data for TUN_METADATA5, - * if present, might be anywhere in 'opts.u8' (not necessarily even contiguous), - * and finding it requires referring to 'tab', if set, or the global metadata - * table. */ -struct tun_metadata { - union { /* Valid members of 'opts'. When 'opts' is sorted into known types, - * 'map' is used. When 'opts' is raw packet data, 'len' is used. */ - uint64_t map; /* 1-bit for each present TLV. */ - uint8_t len; /* Length of data in 'opts'. */ - } present; - struct tun_table *tab; /* Types & lengths for 'opts' and 'opt_map'. */ - -#if UINTPTR_MAX == UINT32_MAX - uint8_t pad[4]; /* Pad to 64-bit boundary. */ -#endif - - union { - uint8_t u8[TUN_METADATA_TOT_OPT_SIZE]; /* Values from tunnel TLVs. */ - struct geneve_opt gnv[TLV_TOT_OPT_SIZE / sizeof(struct geneve_opt)]; - } opts; -}; -BUILD_ASSERT_DECL(offsetof(struct tun_metadata, opts) % 8 == 0); -BUILD_ASSERT_DECL(sizeof(((struct tun_metadata *)0)->present.map) * 8 >= - TUN_METADATA_NUM_OPTS); - -/* The location of an option can be stored either as a single offset/len - * pair (hopefully) or if the address space is fragmented then it is a - * linked list of these blocks. */ -struct tun_metadata_loc_chain { - struct tun_metadata_loc_chain *next; - int offset; /* In bytes, from start of 'opts', multiple of 4. */ - int len; /* In bytes, multiple of 4. */ -}; - -struct tun_metadata_loc { - int len; /* Sum of 'len' over elements in chain. */ - struct tun_metadata_loc_chain c; -}; - -/* Bookkeeping information to keep track of an option that was allocated - * inside struct match. */ -struct tun_metadata_match_entry { - struct tun_metadata_loc loc; /* Allocated position. */ - bool masked; /* Source value had a mask. Otherwise we can't tell if the - * entire field was exact matched or only the portion that - * is the same size as the value. */ -}; - -/* Allocation of options inside struct match. This is important if we don't - * have access to a global allocation table - either because there isn't one - * (ovs-ofctl) or if we need to keep the allocation outside of packet - * processing context (Packet-In). These structures never have dynamically - * allocated memory because the address space is never fragmented. */ -struct tun_metadata_allocation { - struct tun_metadata_match_entry entry[TUN_METADATA_NUM_OPTS]; - int alloc_offset; /* Byte offset into 'opts', multiple of 4. */ - bool valid; /* Set to true after any allocation occurs. */ -}; - void tun_metadata_init(void); enum ofperr tun_metadata_table_mod(struct ofputil_tlv_table_mod *);