2010-07-28 15:14:28 -07:00
|
|
|
|
/*
|
2017-05-31 16:06:12 -07:00
|
|
|
|
* Copyright (c) 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Nicira, Inc.
|
2010-07-28 15:14:28 -07:00
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
2018-02-09 10:04:26 -08:00
|
|
|
|
#include "openvswitch/ofp-parse.h"
|
2010-07-28 15:14:28 -07:00
|
|
|
|
#include <errno.h>
|
2010-10-28 17:13:18 -07:00
|
|
|
|
#include "byte-order.h"
|
2018-02-09 10:04:26 -08:00
|
|
|
|
#include "openvswitch/match.h"
|
2016-04-14 15:20:19 -07:00
|
|
|
|
#include "openvswitch/meta-flow.h"
|
2018-02-21 16:32:39 +03:00
|
|
|
|
#include "openvswitch/ofp-actions.h"
|
2018-02-09 10:04:26 -08:00
|
|
|
|
#include "openvswitch/ofp-flow.h"
|
|
|
|
|
#include "openvswitch/ofp-match.h"
|
|
|
|
|
#include "openvswitch/ofp-table.h"
|
2010-07-28 15:14:28 -07:00
|
|
|
|
#include "packets.h"
|
|
|
|
|
#include "socket-util.h"
|
2016-07-12 16:37:34 -05:00
|
|
|
|
#include "util.h"
|
2010-07-28 15:14:28 -07:00
|
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
|
/* Parses 'str' as an 8-bit unsigned integer into '*valuep'.
|
|
|
|
|
*
|
|
|
|
|
* 'name' describes the value parsed in an error message, if any.
|
|
|
|
|
*
|
|
|
|
|
* Returns NULL if successful, otherwise a malloc()'d string describing the
|
|
|
|
|
* error. The caller is responsible for freeing the returned string. */
|
2014-12-15 14:10:38 +01:00
|
|
|
|
char * OVS_WARN_UNUSED_RESULT
|
2013-07-08 10:15:00 -07:00
|
|
|
|
str_to_u8(const char *str, const char *name, uint8_t *valuep)
|
2011-09-27 16:58:55 -07:00
|
|
|
|
{
|
2013-06-20 17:26:18 +03:00
|
|
|
|
int value;
|
2011-09-27 16:58:55 -07:00
|
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
|
if (!str_to_int(str, 0, &value) || value < 0 || value > 255) {
|
|
|
|
|
return xasprintf("invalid %s \"%s\"", name, str);
|
2011-09-27 16:58:55 -07:00
|
|
|
|
}
|
2013-07-08 10:15:00 -07:00
|
|
|
|
*valuep = value;
|
|
|
|
|
return NULL;
|
2011-09-27 16:58:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
|
/* Parses 'str' as a 16-bit unsigned integer into '*valuep'.
|
|
|
|
|
*
|
|
|
|
|
* 'name' describes the value parsed in an error message, if any.
|
|
|
|
|
*
|
|
|
|
|
* Returns NULL if successful, otherwise a malloc()'d string describing the
|
|
|
|
|
* error. The caller is responsible for freeing the returned string. */
|
2014-12-15 14:10:38 +01:00
|
|
|
|
char * OVS_WARN_UNUSED_RESULT
|
2013-07-08 10:15:00 -07:00
|
|
|
|
str_to_u16(const char *str, const char *name, uint16_t *valuep)
|
2011-09-27 16:58:55 -07:00
|
|
|
|
{
|
|
|
|
|
int value;
|
|
|
|
|
|
|
|
|
|
if (!str_to_int(str, 0, &value) || value < 0 || value > 65535) {
|
2013-07-08 10:15:00 -07:00
|
|
|
|
return xasprintf("invalid %s \"%s\"", name, str);
|
2011-09-27 16:58:55 -07:00
|
|
|
|
}
|
2013-07-08 10:15:00 -07:00
|
|
|
|
*valuep = value;
|
|
|
|
|
return NULL;
|
2011-09-27 16:58:55 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
|
/* Parses 'str' as a 32-bit unsigned integer into '*valuep'.
|
|
|
|
|
*
|
|
|
|
|
* Returns NULL if successful, otherwise a malloc()'d string describing the
|
|
|
|
|
* error. The caller is responsible for freeing the returned string. */
|
2014-12-15 14:10:38 +01:00
|
|
|
|
char * OVS_WARN_UNUSED_RESULT
|
2013-07-08 10:15:00 -07:00
|
|
|
|
str_to_u32(const char *str, uint32_t *valuep)
|
2010-07-28 15:14:28 -07:00
|
|
|
|
{
|
|
|
|
|
char *tail;
|
|
|
|
|
uint32_t value;
|
|
|
|
|
|
2011-02-22 14:55:39 -08:00
|
|
|
|
if (!str[0]) {
|
2013-07-08 10:15:00 -07:00
|
|
|
|
return xstrdup("missing required numeric argument");
|
2010-10-08 22:15:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 15:14:28 -07:00
|
|
|
|
errno = 0;
|
|
|
|
|
value = strtoul(str, &tail, 0);
|
|
|
|
|
if (errno == EINVAL || errno == ERANGE || *tail) {
|
2013-07-08 10:15:00 -07:00
|
|
|
|
return xasprintf("invalid numeric format %s", str);
|
2010-07-28 15:14:28 -07:00
|
|
|
|
}
|
2013-07-08 10:15:00 -07:00
|
|
|
|
*valuep = value;
|
|
|
|
|
return NULL;
|
2010-07-28 15:14:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
|
/* Parses 'str' as an 64-bit unsigned integer into '*valuep'.
|
|
|
|
|
*
|
|
|
|
|
* Returns NULL if successful, otherwise a malloc()'d string describing the
|
|
|
|
|
* error. The caller is responsible for freeing the returned string. */
|
2014-12-15 14:10:38 +01:00
|
|
|
|
char * OVS_WARN_UNUSED_RESULT
|
2013-07-08 10:15:00 -07:00
|
|
|
|
str_to_u64(const char *str, uint64_t *valuep)
|
2010-07-28 15:14:28 -07:00
|
|
|
|
{
|
|
|
|
|
char *tail;
|
|
|
|
|
uint64_t value;
|
|
|
|
|
|
2011-02-22 14:55:39 -08:00
|
|
|
|
if (!str[0]) {
|
2013-07-08 10:15:00 -07:00
|
|
|
|
return xstrdup("missing required numeric argument");
|
2011-02-22 14:55:39 -08:00
|
|
|
|
}
|
|
|
|
|
|
2010-07-28 15:14:28 -07:00
|
|
|
|
errno = 0;
|
|
|
|
|
value = strtoull(str, &tail, 0);
|
|
|
|
|
if (errno == EINVAL || errno == ERANGE || *tail) {
|
2013-07-08 10:15:00 -07:00
|
|
|
|
return xasprintf("invalid numeric format %s", str);
|
2010-07-28 15:14:28 -07:00
|
|
|
|
}
|
2013-07-08 10:15:00 -07:00
|
|
|
|
*valuep = value;
|
|
|
|
|
return NULL;
|
2010-07-28 15:14:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
|
/* Parses 'str' as an 64-bit unsigned integer in network byte order into
|
|
|
|
|
* '*valuep'.
|
|
|
|
|
*
|
|
|
|
|
* Returns NULL if successful, otherwise a malloc()'d string describing the
|
|
|
|
|
* error. The caller is responsible for freeing the returned string. */
|
2014-12-15 14:10:38 +01:00
|
|
|
|
char * OVS_WARN_UNUSED_RESULT
|
2013-07-08 10:15:00 -07:00
|
|
|
|
str_to_be64(const char *str, ovs_be64 *valuep)
|
|
|
|
|
{
|
2013-08-21 14:49:09 -07:00
|
|
|
|
uint64_t value = 0;
|
2013-07-08 10:15:00 -07:00
|
|
|
|
char *error;
|
|
|
|
|
|
|
|
|
|
error = str_to_u64(str, &value);
|
|
|
|
|
if (!error) {
|
|
|
|
|
*valuep = htonll(value);
|
|
|
|
|
}
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Parses 'str' as an Ethernet address into 'mac'.
|
|
|
|
|
*
|
|
|
|
|
* Returns NULL if successful, otherwise a malloc()'d string describing the
|
|
|
|
|
* error. The caller is responsible for freeing the returned string. */
|
2014-12-15 14:10:38 +01:00
|
|
|
|
char * OVS_WARN_UNUSED_RESULT
|
2015-08-28 14:55:11 -07:00
|
|
|
|
str_to_mac(const char *str, struct eth_addr *mac)
|
2010-07-28 15:14:28 -07:00
|
|
|
|
{
|
2015-08-28 14:55:11 -07:00
|
|
|
|
if (!ovs_scan(str, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(*mac))) {
|
2013-07-08 10:15:00 -07:00
|
|
|
|
return xasprintf("invalid mac address %s", str);
|
2010-07-28 15:14:28 -07:00
|
|
|
|
}
|
2013-07-08 10:15:00 -07:00
|
|
|
|
return NULL;
|
2010-07-28 15:14:28 -07:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
|
/* Parses 'str' as an IP address into '*ip'.
|
|
|
|
|
*
|
|
|
|
|
* Returns NULL if successful, otherwise a malloc()'d string describing the
|
|
|
|
|
* error. The caller is responsible for freeing the returned string. */
|
2014-12-15 14:10:38 +01:00
|
|
|
|
char * OVS_WARN_UNUSED_RESULT
|
2011-09-12 12:11:50 -07:00
|
|
|
|
str_to_ip(const char *str, ovs_be32 *ip)
|
2011-06-07 09:22:24 -07:00
|
|
|
|
{
|
2010-07-28 15:14:28 -07:00
|
|
|
|
struct in_addr in_addr;
|
|
|
|
|
|
2011-09-12 12:11:50 -07:00
|
|
|
|
if (lookup_ip(str, &in_addr)) {
|
2013-07-08 10:15:00 -07:00
|
|
|
|
return xasprintf("%s: could not convert to IP address", str);
|
2010-07-28 15:14:28 -07:00
|
|
|
|
}
|
|
|
|
|
*ip = in_addr.s_addr;
|
2013-07-08 10:15:00 -07:00
|
|
|
|
return NULL;
|
2010-12-29 19:03:46 -08:00
|
|
|
|
}
|
|
|
|
|
|
Add support for connection tracking helper/ALGs.
This patch adds support for specifying a "helper" or ALG to assist
connection tracking for protocols that consist of multiple streams.
Initially, only support for FTP is included.
Below is an example set of flows to allow FTP control connections from
port 1->2 to establish active data connections in the reverse direction:
table=0,priority=1,action=drop
table=0,arp,action=normal
table=0,in_port=1,tcp,action=ct(alg=ftp,commit),2
table=0,in_port=2,tcp,ct_state=-trk,action=ct(table=1)
table=1,in_port=2,tcp,ct_state=+trk+est,action=1
table=1,in_port=2,tcp,ct_state=+trk+rel,action=ct(commit),1
Signed-off-by: Joe Stringer <joestringer@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2015-09-15 14:29:16 -07:00
|
|
|
|
/* Parses 'str' as a conntrack helper into 'alg'.
|
|
|
|
|
*
|
|
|
|
|
* Returns NULL if successful, otherwise a malloc()'d string describing the
|
|
|
|
|
* error. The caller is responsible for freeing the returned string. */
|
|
|
|
|
char * OVS_WARN_UNUSED_RESULT
|
|
|
|
|
str_to_connhelper(const char *str, uint16_t *alg)
|
|
|
|
|
{
|
|
|
|
|
if (!strcmp(str, "ftp")) {
|
|
|
|
|
*alg = IPPORT_FTP;
|
|
|
|
|
return NULL;
|
2016-12-22 10:58:25 -08:00
|
|
|
|
}
|
|
|
|
|
if (!strcmp(str, "tftp")) {
|
|
|
|
|
*alg = IPPORT_TFTP;
|
|
|
|
|
return NULL;
|
Add support for connection tracking helper/ALGs.
This patch adds support for specifying a "helper" or ALG to assist
connection tracking for protocols that consist of multiple streams.
Initially, only support for FTP is included.
Below is an example set of flows to allow FTP control connections from
port 1->2 to establish active data connections in the reverse direction:
table=0,priority=1,action=drop
table=0,arp,action=normal
table=0,in_port=1,tcp,action=ct(alg=ftp,commit),2
table=0,in_port=2,tcp,ct_state=-trk,action=ct(table=1)
table=1,in_port=2,tcp,ct_state=+trk+est,action=1
table=1,in_port=2,tcp,ct_state=+trk+rel,action=ct(commit),1
Signed-off-by: Joe Stringer <joestringer@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2015-09-15 14:29:16 -07:00
|
|
|
|
}
|
|
|
|
|
return xasprintf("invalid conntrack helper \"%s\"", str);
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 10:04:26 -08:00
|
|
|
|
bool
|
|
|
|
|
ofp_parse_protocol(const char *name, const struct ofp_protocol **p_out)
|
2010-07-28 15:14:28 -07:00
|
|
|
|
{
|
2018-02-09 10:04:26 -08:00
|
|
|
|
static const struct ofp_protocol protocols[] = {
|
2010-07-28 15:14:28 -07:00
|
|
|
|
{ "ip", ETH_TYPE_IP, 0 },
|
2015-08-24 15:39:37 -07:00
|
|
|
|
{ "ipv4", ETH_TYPE_IP, 0 },
|
|
|
|
|
{ "ip4", ETH_TYPE_IP, 0 },
|
2010-07-28 15:14:28 -07:00
|
|
|
|
{ "arp", ETH_TYPE_ARP, 0 },
|
2011-02-02 11:33:20 -08:00
|
|
|
|
{ "icmp", ETH_TYPE_IP, IPPROTO_ICMP },
|
|
|
|
|
{ "tcp", ETH_TYPE_IP, IPPROTO_TCP },
|
|
|
|
|
{ "udp", ETH_TYPE_IP, IPPROTO_UDP },
|
2013-08-22 20:24:45 +12:00
|
|
|
|
{ "sctp", ETH_TYPE_IP, IPPROTO_SCTP },
|
2010-12-29 19:03:46 -08:00
|
|
|
|
{ "ipv6", ETH_TYPE_IPV6, 0 },
|
|
|
|
|
{ "ip6", ETH_TYPE_IPV6, 0 },
|
|
|
|
|
{ "icmp6", ETH_TYPE_IPV6, IPPROTO_ICMPV6 },
|
|
|
|
|
{ "tcp6", ETH_TYPE_IPV6, IPPROTO_TCP },
|
|
|
|
|
{ "udp6", ETH_TYPE_IPV6, IPPROTO_UDP },
|
2013-08-22 20:24:45 +12:00
|
|
|
|
{ "sctp6", ETH_TYPE_IPV6, IPPROTO_SCTP },
|
2012-11-02 11:43:46 -07:00
|
|
|
|
{ "rarp", ETH_TYPE_RARP, 0},
|
2013-01-25 16:22:07 +09:00
|
|
|
|
{ "mpls", ETH_TYPE_MPLS, 0 },
|
|
|
|
|
{ "mplsm", ETH_TYPE_MPLS_MCAST, 0 },
|
|
|
|
|
};
|
2018-02-09 10:04:26 -08:00
|
|
|
|
const struct ofp_protocol *p;
|
2010-07-28 15:14:28 -07:00
|
|
|
|
|
|
|
|
|
for (p = protocols; p < &protocols[ARRAY_SIZE(protocols)]; p++) {
|
|
|
|
|
if (!strcmp(p->name, name)) {
|
|
|
|
|
*p_out = p;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*p_out = NULL;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-08 10:15:00 -07:00
|
|
|
|
/* Parses 's' as the (possibly masked) value of field 'mf', and updates
|
2013-08-20 18:41:45 -07:00
|
|
|
|
* 'match' appropriately. Restricts the set of usable protocols to ones
|
|
|
|
|
* supporting the parsed field.
|
2013-07-08 10:15:00 -07:00
|
|
|
|
*
|
|
|
|
|
* Returns NULL if successful, otherwise a malloc()'d string describing the
|
|
|
|
|
* error. The caller is responsible for freeing the returned string. */
|
2018-02-09 10:04:26 -08:00
|
|
|
|
char * OVS_WARN_UNUSED_RESULT
|
|
|
|
|
ofp_parse_field(const struct mf_field *mf, const char *s,
|
|
|
|
|
const struct ofputil_port_map *port_map, struct match *match,
|
|
|
|
|
enum ofputil_protocol *usable_protocols)
|
2010-11-08 10:37:52 -08:00
|
|
|
|
{
|
2011-09-12 12:11:50 -07:00
|
|
|
|
union mf_value value, mask;
|
|
|
|
|
char *error;
|
2010-12-07 14:02:17 -08:00
|
|
|
|
|
2015-09-09 09:30:35 -07:00
|
|
|
|
if (!*s) {
|
|
|
|
|
/* If there's no string, we're just trying to match on the
|
|
|
|
|
* existence of the field, so use a no-op value. */
|
|
|
|
|
s = "0/0";
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 16:06:12 -07:00
|
|
|
|
error = mf_parse(mf, s, port_map, &value, &mask);
|
2013-07-08 10:15:00 -07:00
|
|
|
|
if (!error) {
|
2015-08-31 14:20:17 -07:00
|
|
|
|
*usable_protocols &= mf_set(mf, &value, &mask, match, &error);
|
2017-06-23 16:47:57 +00:00
|
|
|
|
match_add_ethernet_prereq(match, mf);
|
2010-11-08 10:37:52 -08:00
|
|
|
|
}
|
2013-07-08 10:15:00 -07:00
|
|
|
|
return error;
|
2010-11-23 13:33:48 -08:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 10:04:26 -08:00
|
|
|
|
char *
|
|
|
|
|
ofp_extract_actions(char *s)
|
ofp-actions: Centralize all OpenFlow action code for maintainability.
Until now, knowledge about OpenFlow has been somewhat scattered around the
tree. Some of it is in ofp-actions, some of it is in ofp-util, some in
separate files for individual actions, and most of the wire format
declarations are in include/openflow. This commit centralizes all of that
in ofp-actions.
Encoding and decoding OpenFlow actions was previously broken up by OpenFlow
version. This was OK with only OpenFlow 1.0 and 1.1, but each additional
version added a new wrapper around the existing ones, which started to
become hard to understand. This commit merges all of the processing for
the different versions, to the extent that they are similar, making the
version differences clearer.
Previously, ofp-actions contained OpenFlow encoding and decoding, plus
ofpact formatting, but OpenFlow parsing was separated into ofp-parse, which
seems an odd division. This commit moves the parsing code into ofp-actions
with the rest of the code.
Before this commit, the four main bits of code associated with a particular
ofpact--OpenFlow encoding and decoding, ofpact formatting and parsing--were
all found far away from each other. This often made it hard to see what
was going on for a particular ofpact, since you had to search around to
many different pieces of code. This commit reorganizes so that all of the
code for a given ofpact is in a single place.
As a code refactoring, this commit has little visible behavioral change.
The update to ofproto-dpif.at illustrates one minor bug fix as a side
effect: a flow that was added with the action "dec_ttl" (a standard
OpenFlow action) was previously formatted as "dec_ttl(0)" (using a Nicira
extension to specifically direct packets bounced to the controller because
of too-low TTL), but after this commit it is correctly formatted as
"dec_ttl".
The other visible effect is to drop support for the Nicira extension
dec_ttl action in OpenFlow 1.1 and later in favor of the equivalent
standard action. It seems unlikely that anyone was really using the
Nicira extension in OF1.1 or later.
Signed-off-by: Ben Pfaff <blp@nicira.com>
Acked-by: Jarno Rajahalme <jrajahalme@nicira.com>
2014-08-11 12:50:36 -07:00
|
|
|
|
{
|
|
|
|
|
s = strstr(s, "action");
|
|
|
|
|
if (s) {
|
|
|
|
|
*s = '\0';
|
|
|
|
|
s = strchr(s + 1, '=');
|
|
|
|
|
return s ? s + 1 : NULL;
|
|
|
|
|
} else {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-09 10:04:26 -08:00
|
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
|
parse_value(const char *s, const char *delimiters)
|
|
|
|
|
{
|
|
|
|
|
size_t n = 0;
|
|
|
|
|
|
|
|
|
|
/* Iterate until we reach a delimiter.
|
|
|
|
|
*
|
|
|
|
|
* strchr(s, '\0') returns s+strlen(s), so this test handles the null
|
|
|
|
|
* terminator at the end of 's'. */
|
|
|
|
|
while (!strchr(delimiters, s[n])) {
|
|
|
|
|
if (s[n] == '(') {
|
|
|
|
|
int level = 0;
|
|
|
|
|
do {
|
|
|
|
|
switch (s[n]) {
|
|
|
|
|
case '\0':
|
|
|
|
|
return n;
|
|
|
|
|
case '(':
|
|
|
|
|
level++;
|
|
|
|
|
break;
|
|
|
|
|
case ')':
|
|
|
|
|
level--;
|
|
|
|
|
break;
|
2014-11-12 15:24:12 +09:00
|
|
|
|
}
|
2018-02-09 10:04:26 -08:00
|
|
|
|
n++;
|
|
|
|
|
} while (level > 0);
|
2013-09-01 18:30:17 -07:00
|
|
|
|
} else {
|
2018-02-09 10:04:26 -08:00
|
|
|
|
n++;
|
2013-09-01 18:30:17 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-09 10:04:26 -08:00
|
|
|
|
return n;
|
2013-09-01 18:30:17 -07:00
|
|
|
|
}
|
openflow: Table maintenance commands for Geneve options.
In order to work with Geneve options, we need to maintain a mapping
table between an option (defined by <class, type, length>) and
an NXM field that can be operated on for the purposes of matches,
actions, etc. This mapping must be explicitly specified by the
user.
Conceptually, this table could be communicated using either OpenFlow
or OVSDB. Using OVSDB requires less code and definition of extensions
than OpenFlow but introduces the possibility that mapping table
updates and flow modifications are desynchronized from each other.
This is dangerous because the mapping table signifcantly impacts the
way that flows using Geneve options are installed and processed by
OVS. Therefore, the mapping table is maintained using OpenFlow commands
instead, which opens the possibility of using synchronization between
table changes and flow modifications through barriers, bundles, etc.
There are two primary groups of OpenFlow messages that are introduced
as Nicira extensions: modification commands (add, delete, clear mappings)
and table status request/reply to dump the current table along with switch
information.
Note that mappings should not be changed while they are in active use by
a flow. The result of doing so is undefined.
This only adds the OpenFlow infrastructure but doesn't actually
do anything with the information yet after the messages have been
decoded.
Signed-off-by: Jesse Gross <jesse@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2015-06-02 15:11:00 -07:00
|
|
|
|
|
2018-02-09 10:04:26 -08:00
|
|
|
|
/* Parses a key or a key-value pair from '*stringp'.
|
2016-07-29 16:52:04 -07:00
|
|
|
|
*
|
2018-02-09 10:04:26 -08:00
|
|
|
|
* On success: Stores the key into '*keyp'. Stores the value, if present, into
|
|
|
|
|
* '*valuep', otherwise an empty string. Advances '*stringp' past the end of
|
|
|
|
|
* the key-value pair, preparing it for another call. '*keyp' and '*valuep'
|
|
|
|
|
* are substrings of '*stringp' created by replacing some of its bytes by null
|
|
|
|
|
* terminators. Returns true.
|
|
|
|
|
*
|
|
|
|
|
* If '*stringp' is just white space or commas, sets '*keyp' and '*valuep' to
|
|
|
|
|
* NULL and returns false. */
|
|
|
|
|
bool
|
|
|
|
|
ofputil_parse_key_value(char **stringp, char **keyp, char **valuep)
|
|
|
|
|
{
|
|
|
|
|
/* Skip white space and delimiters. If that brings us to the end of the
|
|
|
|
|
* input string, we are done and there are no more key-value pairs. */
|
|
|
|
|
*stringp += strspn(*stringp, ", \t\r\n");
|
|
|
|
|
if (**stringp == '\0') {
|
|
|
|
|
*keyp = *valuep = NULL;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Extract the key and the delimiter that ends the key-value pair or begins
|
|
|
|
|
* the value. Advance the input position past the key and delimiter. */
|
|
|
|
|
char *key = *stringp;
|
|
|
|
|
size_t key_len = strcspn(key, ":=(, \t\r\n");
|
|
|
|
|
char key_delim = key[key_len];
|
|
|
|
|
key[key_len] = '\0';
|
|
|
|
|
*stringp += key_len + (key_delim != '\0');
|
|
|
|
|
|
|
|
|
|
/* Figure out what delimiter ends the value:
|
|
|
|
|
*
|
|
|
|
|
* - If key_delim is ":" or "=", the value extends until white space
|
|
|
|
|
* or a comma.
|
|
|
|
|
*
|
|
|
|
|
* - If key_delim is "(", the value extends until ")".
|
|
|
|
|
*
|
|
|
|
|
* If there is no value, we are done. */
|
|
|
|
|
const char *value_delims;
|
|
|
|
|
if (key_delim == ':' || key_delim == '=') {
|
|
|
|
|
value_delims = ", \t\r\n";
|
|
|
|
|
} else if (key_delim == '(') {
|
|
|
|
|
value_delims = ")";
|
|
|
|
|
} else {
|
|
|
|
|
*keyp = key;
|
|
|
|
|
*valuep = key + key_len; /* Empty string. */
|
|
|
|
|
return true;
|
2016-07-29 16:52:04 -07:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 10:04:26 -08:00
|
|
|
|
/* Extract the value. Advance the input position past the value and
|
|
|
|
|
* delimiter. */
|
|
|
|
|
char *value = *stringp;
|
|
|
|
|
size_t value_len = parse_value(value, value_delims);
|
|
|
|
|
char value_delim = value[value_len];
|
|
|
|
|
value[value_len] = '\0';
|
|
|
|
|
*stringp += value_len + (value_delim != '\0');
|
2016-07-29 16:52:04 -07:00
|
|
|
|
|
2018-02-09 10:04:26 -08:00
|
|
|
|
*keyp = key;
|
|
|
|
|
*valuep = value;
|
|
|
|
|
return true;
|
openflow: Table maintenance commands for Geneve options.
In order to work with Geneve options, we need to maintain a mapping
table between an option (defined by <class, type, length>) and
an NXM field that can be operated on for the purposes of matches,
actions, etc. This mapping must be explicitly specified by the
user.
Conceptually, this table could be communicated using either OpenFlow
or OVSDB. Using OVSDB requires less code and definition of extensions
than OpenFlow but introduces the possibility that mapping table
updates and flow modifications are desynchronized from each other.
This is dangerous because the mapping table signifcantly impacts the
way that flows using Geneve options are installed and processed by
OVS. Therefore, the mapping table is maintained using OpenFlow commands
instead, which opens the possibility of using synchronization between
table changes and flow modifications through barriers, bundles, etc.
There are two primary groups of OpenFlow messages that are introduced
as Nicira extensions: modification commands (add, delete, clear mappings)
and table status request/reply to dump the current table along with switch
information.
Note that mappings should not be changed while they are in active use by
a flow. The result of doing so is undefined.
This only adds the OpenFlow infrastructure but doesn't actually
do anything with the information yet after the messages have been
decoded.
Signed-off-by: Jesse Gross <jesse@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
2015-06-02 15:11:00 -07:00
|
|
|
|
}
|