2017-05-31 16:06:12 -07:00
|
|
|
/* Copyright (c) 2013, 2014, 2015, 2017 Nicira, Inc.
|
2012-09-19 18:37:07 -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>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "byte-order.h"
|
2013-12-13 03:33:46 +00:00
|
|
|
#include "connectivity.h"
|
2014-11-11 11:53:47 -08:00
|
|
|
#include "csum.h"
|
|
|
|
#include "dpif.h"
|
2016-03-03 10:20:46 -08:00
|
|
|
#include "openvswitch/dynamic-string.h"
|
2014-11-10 12:45:57 -08:00
|
|
|
#include "fat-rwlock.h"
|
2012-09-19 18:37:07 -07:00
|
|
|
#include "hash.h"
|
2016-07-12 16:37:34 -05:00
|
|
|
#include "openvswitch/hmap.h"
|
2013-06-18 14:40:30 -07:00
|
|
|
#include "netdev.h"
|
2012-09-19 18:37:07 -07:00
|
|
|
#include "odp-util.h"
|
2016-03-25 14:10:24 -07:00
|
|
|
#include "openvswitch/ofpbuf.h"
|
2012-09-19 18:37:07 -07:00
|
|
|
#include "packets.h"
|
2014-11-11 11:53:47 -08:00
|
|
|
#include "route-table.h"
|
2013-12-13 03:33:46 +00:00
|
|
|
#include "seq.h"
|
2012-09-19 18:37:07 -07:00
|
|
|
#include "smap.h"
|
|
|
|
#include "socket-util.h"
|
2014-11-11 11:53:47 -08:00
|
|
|
#include "tnl-ports.h"
|
2012-09-19 18:37:07 -07:00
|
|
|
#include "tunnel.h"
|
2014-12-15 14:10:38 +01:00
|
|
|
#include "openvswitch/vlog.h"
|
2014-11-11 11:53:47 -08:00
|
|
|
#include "unaligned.h"
|
2017-12-28 12:34:50 -08:00
|
|
|
#include "unixctl.h"
|
2014-11-11 11:53:47 -08:00
|
|
|
#include "ofproto-dpif.h"
|
2017-06-02 16:16:21 +00:00
|
|
|
#include "netdev-vport.h"
|
2012-09-19 18:37:07 -07:00
|
|
|
|
|
|
|
VLOG_DEFINE_THIS_MODULE(tunnel);
|
|
|
|
|
|
|
|
struct tnl_match {
|
|
|
|
ovs_be64 in_key;
|
2015-10-22 15:28:57 -02:00
|
|
|
struct in6_addr ipv6_src;
|
|
|
|
struct in6_addr ipv6_dst;
|
2013-06-19 16:58:44 -07:00
|
|
|
odp_port_t odp_port;
|
2012-09-19 18:37:07 -07:00
|
|
|
bool in_key_flow;
|
2013-05-09 15:24:16 +03:00
|
|
|
bool ip_src_flow;
|
|
|
|
bool ip_dst_flow;
|
2017-06-23 16:47:59 +00:00
|
|
|
enum netdev_pt_mode pt_mode;
|
2012-09-19 18:37:07 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct tnl_port {
|
2013-06-18 15:24:33 -07:00
|
|
|
struct hmap_node ofport_node;
|
2012-09-19 18:37:07 -07:00
|
|
|
struct hmap_node match_node;
|
|
|
|
|
2013-06-18 14:40:30 -07:00
|
|
|
const struct ofport_dpif *ofport;
|
2014-12-05 14:02:53 -08:00
|
|
|
uint64_t change_seq;
|
2013-06-18 14:40:30 -07:00
|
|
|
struct netdev *netdev;
|
|
|
|
|
2012-09-19 18:37:07 -07:00
|
|
|
struct tnl_match match;
|
|
|
|
};
|
|
|
|
|
2014-11-10 12:45:57 -08:00
|
|
|
static struct fat_rwlock rwlock;
|
2013-07-23 12:03:37 -07:00
|
|
|
|
2014-02-11 15:13:56 -08:00
|
|
|
/* Tunnel matches.
|
|
|
|
*
|
|
|
|
* This module maps packets received over tunnel protocols to vports. The
|
|
|
|
* tunnel protocol and, for some protocols, tunnel-specific information (e.g.,
|
|
|
|
* for VXLAN, the UDP destination port number) are always use as part of the
|
|
|
|
* mapping. Which other fields are used for the mapping depends on the vports
|
|
|
|
* themselves (the parenthesized notations refer to "struct tnl_match" fields):
|
|
|
|
*
|
|
|
|
* - in_key: A vport may match a specific tunnel ID (in_key_flow == false)
|
|
|
|
* or arrange for the tunnel ID to be matched as tunnel.tun_id in the
|
|
|
|
* OpenFlow flow (in_key_flow == true).
|
|
|
|
*
|
|
|
|
* - ip_dst: A vport may match a specific destination IP address
|
|
|
|
* (ip_dst_flow == false) or arrange for the destination IP to be matched
|
|
|
|
* as tunnel.ip_dst in the OpenFlow flow (ip_dst_flow == true).
|
|
|
|
*
|
|
|
|
* - ip_src: A vport may match a specific IP source address (ip_src_flow ==
|
|
|
|
* false, ip_src != 0), wildcard all source addresses (ip_src_flow ==
|
|
|
|
* false, ip_src == 0), or arrange for the IP source address to be
|
|
|
|
* handled in the OpenFlow flow table (ip_src_flow == true).
|
|
|
|
*
|
|
|
|
* Thus, there are 2 * 2 * 3 == 12 possible ways a vport can match against a
|
|
|
|
* tunnel packet. We number the possibilities for each field in increasing
|
|
|
|
* order as listed in each bullet above. We order the 12 overall combinations
|
|
|
|
* in lexicographic order considering in_key first, then ip_dst, then
|
|
|
|
* ip_src. */
|
|
|
|
#define N_MATCH_TYPES (2 * 2 * 3)
|
|
|
|
|
|
|
|
/* The three possibilities (see above) for vport ip_src matches. */
|
|
|
|
enum ip_src_type {
|
|
|
|
IP_SRC_CFG, /* ip_src must equal configured address. */
|
|
|
|
IP_SRC_ANY, /* Any ip_src is acceptable. */
|
|
|
|
IP_SRC_FLOW /* ip_src is handled in flow table. */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Each hmap contains "struct tnl_port"s.
|
|
|
|
* The index is a combination of how each of the fields listed under "Tunnel
|
|
|
|
* matches" above matches, see the final paragraph for ordering. */
|
|
|
|
static struct hmap *tnl_match_maps[N_MATCH_TYPES] OVS_GUARDED_BY(rwlock);
|
|
|
|
static struct hmap **tnl_match_map(const struct tnl_match *);
|
2013-07-23 12:03:37 -07:00
|
|
|
|
|
|
|
static struct hmap ofport_map__ = HMAP_INITIALIZER(&ofport_map__);
|
|
|
|
static struct hmap *ofport_map OVS_GUARDED_BY(rwlock) = &ofport_map__;
|
2012-09-19 18:37:07 -07:00
|
|
|
|
|
|
|
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);
|
|
|
|
static struct vlog_rate_limit dbg_rl = VLOG_RATE_LIMIT_INIT(60, 60);
|
|
|
|
|
2013-09-25 09:35:33 -07:00
|
|
|
static struct tnl_port *tnl_find(const struct flow *) OVS_REQ_RDLOCK(rwlock);
|
2014-02-11 15:13:56 -08:00
|
|
|
static struct tnl_port *tnl_find_exact(struct tnl_match *, struct hmap *)
|
2013-08-08 15:14:20 -07:00
|
|
|
OVS_REQ_RDLOCK(rwlock);
|
2013-07-23 12:03:37 -07:00
|
|
|
static struct tnl_port *tnl_find_ofport(const struct ofport_dpif *)
|
2013-08-08 15:14:20 -07:00
|
|
|
OVS_REQ_RDLOCK(rwlock);
|
2013-06-18 15:24:33 -07:00
|
|
|
|
2012-09-19 18:37:07 -07:00
|
|
|
static uint32_t tnl_hash(struct tnl_match *);
|
|
|
|
static void tnl_match_fmt(const struct tnl_match *, struct ds *);
|
2017-12-28 12:34:50 -08:00
|
|
|
static char *tnl_port_to_string(const struct tnl_port *)
|
|
|
|
OVS_REQ_RDLOCK(rwlock);
|
|
|
|
static void tnl_port_format(const struct tnl_port *, struct ds *)
|
|
|
|
OVS_REQ_RDLOCK(rwlock);
|
2013-07-23 12:03:37 -07:00
|
|
|
static void tnl_port_mod_log(const struct tnl_port *, const char *action)
|
2013-08-08 15:14:20 -07:00
|
|
|
OVS_REQ_RDLOCK(rwlock);
|
2013-07-23 12:03:37 -07:00
|
|
|
static const char *tnl_port_get_name(const struct tnl_port *)
|
2013-08-08 15:14:20 -07:00
|
|
|
OVS_REQ_RDLOCK(rwlock);
|
2017-11-01 15:20:47 +00:00
|
|
|
static void tnl_port_del__(const struct ofport_dpif *, odp_port_t)
|
|
|
|
OVS_REQ_WRLOCK(rwlock);
|
2012-09-19 18:37:07 -07:00
|
|
|
|
2017-12-28 12:34:50 -08:00
|
|
|
static unixctl_cb_func tnl_unixctl_list;
|
|
|
|
|
2014-11-10 12:45:57 -08:00
|
|
|
void
|
|
|
|
ofproto_tunnel_init(void)
|
|
|
|
{
|
|
|
|
static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;
|
|
|
|
|
|
|
|
if (ovsthread_once_start(&once)) {
|
|
|
|
fat_rwlock_init(&rwlock);
|
2017-12-28 12:34:50 -08:00
|
|
|
unixctl_command_register("ofproto/list-tunnels", "", 0, 0,
|
|
|
|
tnl_unixctl_list, NULL);
|
2014-11-10 12:45:57 -08:00
|
|
|
ovsthread_once_done(&once);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-18 15:24:33 -07:00
|
|
|
static bool
|
2013-06-18 14:40:30 -07:00
|
|
|
tnl_port_add__(const struct ofport_dpif *ofport, const struct netdev *netdev,
|
2014-11-11 11:53:47 -08:00
|
|
|
odp_port_t odp_port, bool warn, bool native_tnl, const char name[])
|
2013-08-08 15:14:20 -07:00
|
|
|
OVS_REQ_WRLOCK(rwlock)
|
2012-09-19 18:37:07 -07:00
|
|
|
{
|
|
|
|
const struct netdev_tunnel_config *cfg;
|
|
|
|
struct tnl_port *existing_port;
|
|
|
|
struct tnl_port *tnl_port;
|
2014-02-11 15:13:56 -08:00
|
|
|
struct hmap **map;
|
2012-09-19 18:37:07 -07:00
|
|
|
|
2013-06-18 14:40:30 -07:00
|
|
|
cfg = netdev_get_tunnel_config(netdev);
|
2012-09-19 18:37:07 -07:00
|
|
|
ovs_assert(cfg);
|
|
|
|
|
|
|
|
tnl_port = xzalloc(sizeof *tnl_port);
|
|
|
|
tnl_port->ofport = ofport;
|
2013-06-18 14:40:30 -07:00
|
|
|
tnl_port->netdev = netdev_ref(netdev);
|
2014-12-05 14:02:53 -08:00
|
|
|
tnl_port->change_seq = netdev_get_change_seq(tnl_port->netdev);
|
2012-09-19 18:37:07 -07:00
|
|
|
|
|
|
|
tnl_port->match.in_key = cfg->in_key;
|
2015-11-25 11:31:08 -02:00
|
|
|
tnl_port->match.ipv6_src = cfg->ipv6_src;
|
|
|
|
tnl_port->match.ipv6_dst = cfg->ipv6_dst;
|
2013-05-09 15:24:16 +03:00
|
|
|
tnl_port->match.ip_src_flow = cfg->ip_src_flow;
|
|
|
|
tnl_port->match.ip_dst_flow = cfg->ip_dst_flow;
|
2012-09-19 18:37:07 -07:00
|
|
|
tnl_port->match.in_key_flow = cfg->in_key_flow;
|
|
|
|
tnl_port->match.odp_port = odp_port;
|
2017-06-23 16:47:59 +00:00
|
|
|
tnl_port->match.pt_mode = netdev_get_pt_mode(netdev);
|
2012-09-19 18:37:07 -07:00
|
|
|
|
2014-02-11 15:13:56 -08:00
|
|
|
map = tnl_match_map(&tnl_port->match);
|
|
|
|
existing_port = tnl_find_exact(&tnl_port->match, *map);
|
2012-09-19 18:37:07 -07:00
|
|
|
if (existing_port) {
|
|
|
|
if (warn) {
|
|
|
|
struct ds ds = DS_EMPTY_INITIALIZER;
|
|
|
|
tnl_match_fmt(&tnl_port->match, &ds);
|
|
|
|
VLOG_WARN("%s: attempting to add tunnel port with same config as "
|
|
|
|
"port '%s' (%s)", tnl_port_get_name(tnl_port),
|
|
|
|
tnl_port_get_name(existing_port), ds_cstr(&ds));
|
|
|
|
ds_destroy(&ds);
|
|
|
|
}
|
2014-05-05 10:14:18 +12:00
|
|
|
netdev_close(tnl_port->netdev);
|
|
|
|
free(tnl_port);
|
2013-06-18 15:24:33 -07:00
|
|
|
return false;
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
|
|
|
|
2013-07-23 12:03:37 -07:00
|
|
|
hmap_insert(ofport_map, &tnl_port->ofport_node, hash_pointer(ofport, 0));
|
2014-02-11 15:13:56 -08:00
|
|
|
|
|
|
|
if (!*map) {
|
|
|
|
*map = xmalloc(sizeof **map);
|
|
|
|
hmap_init(*map);
|
|
|
|
}
|
|
|
|
hmap_insert(*map, &tnl_port->match_node, tnl_hash(&tnl_port->match));
|
2012-09-19 18:37:07 -07:00
|
|
|
tnl_port_mod_log(tnl_port, "adding");
|
2014-11-11 11:53:47 -08:00
|
|
|
|
|
|
|
if (native_tnl) {
|
2016-05-17 17:35:33 -07:00
|
|
|
const char *type;
|
|
|
|
|
|
|
|
type = netdev_get_type(netdev);
|
|
|
|
tnl_port_map_insert(odp_port, cfg->dst_port, name, type);
|
|
|
|
|
2014-11-11 11:53:47 -08:00
|
|
|
}
|
2013-06-18 15:24:33 -07:00
|
|
|
return true;
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Adds 'ofport' to the module with datapath port number 'odp_port'. 'ofport's
|
|
|
|
* must be added before they can be used by the module. 'ofport' must be a
|
2015-06-05 08:13:28 -07:00
|
|
|
* tunnel.
|
|
|
|
*
|
|
|
|
* Returns 0 if successful, otherwise a positive errno value. */
|
|
|
|
int
|
2013-06-18 14:40:30 -07:00
|
|
|
tnl_port_add(const struct ofport_dpif *ofport, const struct netdev *netdev,
|
2017-06-02 16:16:21 +00:00
|
|
|
odp_port_t odp_port, bool native_tnl, const char name[])
|
|
|
|
OVS_EXCLUDED(rwlock)
|
2012-09-19 18:37:07 -07:00
|
|
|
{
|
2015-06-05 08:13:28 -07:00
|
|
|
bool ok;
|
|
|
|
|
2014-11-10 12:45:57 -08:00
|
|
|
fat_rwlock_wrlock(&rwlock);
|
2015-06-05 08:13:28 -07:00
|
|
|
ok = tnl_port_add__(ofport, netdev, odp_port, true, native_tnl, name);
|
2014-11-10 12:45:57 -08:00
|
|
|
fat_rwlock_unlock(&rwlock);
|
2015-06-05 08:13:28 -07:00
|
|
|
|
|
|
|
return ok ? 0 : EEXIST;
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
|
|
|
|
2013-06-18 15:24:33 -07:00
|
|
|
/* Checks if the tunnel represented by 'ofport' reconfiguration due to changes
|
2017-11-01 15:20:47 +00:00
|
|
|
* in its netdev_tunnel_config. If it does, returns true. Otherwise, returns
|
|
|
|
* false. 'new_odp_port' should be the port number coming from 'ofport' that
|
|
|
|
* is passed to tnl_port_add__(). 'old_odp_port' should be the port number
|
|
|
|
* that is passed to tnl_port_del__(). */
|
2012-09-19 18:37:07 -07:00
|
|
|
bool
|
2013-06-18 14:40:30 -07:00
|
|
|
tnl_port_reconfigure(const struct ofport_dpif *ofport,
|
2017-11-01 15:20:47 +00:00
|
|
|
const struct netdev *netdev, odp_port_t new_odp_port,
|
|
|
|
odp_port_t old_odp_port, bool native_tnl,
|
|
|
|
const char name[])
|
2013-07-23 12:03:37 -07:00
|
|
|
OVS_EXCLUDED(rwlock)
|
2012-09-19 18:37:07 -07:00
|
|
|
{
|
2013-07-23 12:03:37 -07:00
|
|
|
struct tnl_port *tnl_port;
|
|
|
|
bool changed = false;
|
2012-09-19 18:37:07 -07:00
|
|
|
|
2014-11-10 12:45:57 -08:00
|
|
|
fat_rwlock_wrlock(&rwlock);
|
2013-07-23 12:03:37 -07:00
|
|
|
tnl_port = tnl_find_ofport(ofport);
|
2013-06-18 15:24:33 -07:00
|
|
|
if (!tnl_port) {
|
2017-11-01 15:20:47 +00:00
|
|
|
changed = tnl_port_add__(ofport, netdev, new_odp_port, false,
|
|
|
|
native_tnl, name);
|
2013-06-18 15:24:33 -07:00
|
|
|
} else if (tnl_port->netdev != netdev
|
2017-11-01 15:20:47 +00:00
|
|
|
|| tnl_port->match.odp_port != new_odp_port
|
2014-12-05 14:02:53 -08:00
|
|
|
|| tnl_port->change_seq != netdev_get_change_seq(tnl_port->netdev)) {
|
2012-09-19 18:37:07 -07:00
|
|
|
VLOG_DBG("reconfiguring %s", tnl_port_get_name(tnl_port));
|
2017-11-01 15:20:47 +00:00
|
|
|
tnl_port_del__(ofport, old_odp_port);
|
|
|
|
tnl_port_add__(ofport, netdev, new_odp_port, true, native_tnl, name);
|
2013-07-23 12:03:37 -07:00
|
|
|
changed = true;
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
2014-11-10 12:45:57 -08:00
|
|
|
fat_rwlock_unlock(&rwlock);
|
2013-07-23 12:03:37 -07:00
|
|
|
return changed;
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
|
|
|
|
2013-07-23 12:03:37 -07:00
|
|
|
static void
|
2017-11-01 15:20:47 +00:00
|
|
|
tnl_port_del__(const struct ofport_dpif *ofport, odp_port_t odp_port)
|
|
|
|
OVS_REQ_WRLOCK(rwlock)
|
2012-09-19 18:37:07 -07:00
|
|
|
{
|
2013-07-23 12:03:37 -07:00
|
|
|
struct tnl_port *tnl_port;
|
|
|
|
|
|
|
|
if (!ofport) {
|
|
|
|
return;
|
|
|
|
}
|
2013-06-18 15:24:33 -07:00
|
|
|
|
2013-07-23 12:03:37 -07:00
|
|
|
tnl_port = tnl_find_ofport(ofport);
|
2013-06-18 15:24:33 -07:00
|
|
|
if (tnl_port) {
|
2014-02-11 15:13:56 -08:00
|
|
|
struct hmap **map;
|
|
|
|
|
2017-11-01 15:20:47 +00:00
|
|
|
tnl_port_map_delete(odp_port, netdev_get_type(tnl_port->netdev));
|
2012-09-19 18:37:07 -07:00
|
|
|
tnl_port_mod_log(tnl_port, "removing");
|
2014-02-11 15:13:56 -08:00
|
|
|
map = tnl_match_map(&tnl_port->match);
|
|
|
|
hmap_remove(*map, &tnl_port->match_node);
|
|
|
|
if (hmap_is_empty(*map)) {
|
|
|
|
hmap_destroy(*map);
|
|
|
|
free(*map);
|
|
|
|
*map = NULL;
|
|
|
|
}
|
2013-07-23 12:03:37 -07:00
|
|
|
hmap_remove(ofport_map, &tnl_port->ofport_node);
|
2013-06-18 14:40:30 -07:00
|
|
|
netdev_close(tnl_port->netdev);
|
2012-09-19 18:37:07 -07:00
|
|
|
free(tnl_port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-23 12:03:37 -07:00
|
|
|
/* Removes 'ofport' from the module. */
|
|
|
|
void
|
2017-11-01 15:20:47 +00:00
|
|
|
tnl_port_del(const struct ofport_dpif *ofport, odp_port_t odp_port)
|
|
|
|
OVS_EXCLUDED(rwlock)
|
2013-07-23 12:03:37 -07:00
|
|
|
{
|
2014-11-10 12:45:57 -08:00
|
|
|
fat_rwlock_wrlock(&rwlock);
|
2017-11-01 15:20:47 +00:00
|
|
|
tnl_port_del__(ofport, odp_port);
|
2014-11-10 12:45:57 -08:00
|
|
|
fat_rwlock_unlock(&rwlock);
|
2013-07-23 12:03:37 -07:00
|
|
|
}
|
|
|
|
|
2013-05-08 13:21:11 -07:00
|
|
|
/* Looks in the table of tunnels for a tunnel matching the metadata in 'flow'.
|
|
|
|
* Returns the 'ofport' corresponding to the new in_port, or a null pointer if
|
|
|
|
* none is found.
|
2012-09-19 18:37:07 -07:00
|
|
|
*
|
|
|
|
* Callers should verify that 'flow' needs to be received by calling
|
2013-05-08 13:21:11 -07:00
|
|
|
* tnl_port_should_receive() before this function. */
|
2013-06-18 14:40:30 -07:00
|
|
|
const struct ofport_dpif *
|
2013-07-23 12:03:37 -07:00
|
|
|
tnl_port_receive(const struct flow *flow) OVS_EXCLUDED(rwlock)
|
2012-09-19 18:37:07 -07:00
|
|
|
{
|
2013-07-23 12:03:37 -07:00
|
|
|
const struct ofport_dpif *ofport;
|
2012-09-19 18:37:07 -07:00
|
|
|
struct tnl_port *tnl_port;
|
|
|
|
|
2014-11-10 12:45:57 -08:00
|
|
|
fat_rwlock_rdlock(&rwlock);
|
2013-09-25 09:35:33 -07:00
|
|
|
tnl_port = tnl_find(flow);
|
2013-07-23 12:03:37 -07:00
|
|
|
ofport = tnl_port ? tnl_port->ofport : NULL;
|
2012-09-19 18:37:07 -07:00
|
|
|
if (!tnl_port) {
|
2017-12-28 12:34:48 -08:00
|
|
|
if (!VLOG_DROP_WARN(&rl)) {
|
|
|
|
char *flow_str = flow_to_string(flow, NULL);
|
|
|
|
VLOG_WARN("receive tunnel port not found (%s)", flow_str);
|
|
|
|
free(flow_str);
|
|
|
|
}
|
2013-07-23 12:03:37 -07:00
|
|
|
goto out;
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!VLOG_DROP_DBG(&dbg_rl)) {
|
2017-12-28 12:34:49 -08:00
|
|
|
char *flow_str = flow_to_string(flow, NULL);
|
2017-12-28 12:34:50 -08:00
|
|
|
char *tnl_str = tnl_port_to_string(tnl_port);
|
2017-12-28 12:34:49 -08:00
|
|
|
VLOG_DBG("tunnel port %s receive from flow %s", tnl_str, flow_str);
|
2012-09-19 18:37:07 -07:00
|
|
|
free(tnl_str);
|
2017-12-28 12:34:49 -08:00
|
|
|
free(flow_str);
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
2013-07-23 12:03:37 -07:00
|
|
|
|
|
|
|
out:
|
2014-11-10 12:45:57 -08:00
|
|
|
fat_rwlock_unlock(&rwlock);
|
2013-07-23 12:03:37 -07:00
|
|
|
return ofport;
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
|
|
|
|
2013-08-06 12:57:14 -07:00
|
|
|
/* Should be called at the beginning of action translation to initialize
|
|
|
|
* wildcards and perform any actions based on receiving on tunnel port.
|
|
|
|
*
|
|
|
|
* Returns false if the packet must be dropped. */
|
|
|
|
bool
|
2015-07-29 14:12:26 -07:00
|
|
|
tnl_process_ecn(struct flow *flow)
|
2013-08-06 12:57:14 -07:00
|
|
|
{
|
2015-07-29 14:12:26 -07:00
|
|
|
if (!tnl_port_should_receive(flow)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-17 17:35:28 -07:00
|
|
|
if (is_ip_any(flow) && IP_ECN_is_ce(flow->tunnel.ip_tos)) {
|
2015-07-29 14:12:26 -07:00
|
|
|
if ((flow->nw_tos & IP_ECN_MASK) == IP_ECN_NOT_ECT) {
|
|
|
|
VLOG_WARN_RL(&rl, "dropping tunnel packet marked ECN CE"
|
|
|
|
" but is not ECN capable");
|
2013-08-06 12:57:14 -07:00
|
|
|
return false;
|
|
|
|
}
|
2013-08-06 12:57:15 -07:00
|
|
|
|
2015-07-29 14:12:26 -07:00
|
|
|
/* Set the ECN CE value in the tunneled packet. */
|
|
|
|
flow->nw_tos |= IP_ECN_CE;
|
2013-08-06 12:57:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-29 14:12:26 -07:00
|
|
|
void
|
|
|
|
tnl_wc_init(struct flow *flow, struct flow_wildcards *wc)
|
|
|
|
{
|
|
|
|
if (tnl_port_should_receive(flow)) {
|
|
|
|
wc->masks.tunnel.tun_id = OVS_BE64_MAX;
|
2015-11-25 11:31:11 -02:00
|
|
|
if (flow->tunnel.ip_dst) {
|
|
|
|
wc->masks.tunnel.ip_src = OVS_BE32_MAX;
|
|
|
|
wc->masks.tunnel.ip_dst = OVS_BE32_MAX;
|
|
|
|
} else {
|
|
|
|
wc->masks.tunnel.ipv6_src = in6addr_exact;
|
|
|
|
wc->masks.tunnel.ipv6_dst = in6addr_exact;
|
|
|
|
}
|
2015-07-29 14:12:26 -07:00
|
|
|
wc->masks.tunnel.flags = (FLOW_TNL_F_DONT_FRAGMENT |
|
|
|
|
FLOW_TNL_F_CSUM |
|
|
|
|
FLOW_TNL_F_KEY);
|
|
|
|
wc->masks.tunnel.ip_tos = UINT8_MAX;
|
2016-01-14 13:29:08 +02:00
|
|
|
wc->masks.tunnel.ip_ttl = 0;
|
2015-07-29 14:12:26 -07:00
|
|
|
/* The tp_src and tp_dst members in flow_tnl are set to be always
|
|
|
|
* wildcarded, not to unwildcard them here. */
|
|
|
|
wc->masks.tunnel.tp_src = 0;
|
|
|
|
wc->masks.tunnel.tp_dst = 0;
|
|
|
|
|
|
|
|
if (is_ip_any(flow)
|
2016-05-17 17:35:28 -07:00
|
|
|
&& IP_ECN_is_ce(flow->tunnel.ip_tos)) {
|
2015-07-29 14:12:26 -07:00
|
|
|
wc->masks.nw_tos |= IP_ECN_MASK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-19 18:37:07 -07:00
|
|
|
/* Given that 'flow' should be output to the ofport corresponding to
|
|
|
|
* 'tnl_port', updates 'flow''s tunnel headers and returns the actual datapath
|
2013-06-19 16:58:44 -07:00
|
|
|
* port that the output should happen on. May return ODPP_NONE if the output
|
2012-09-19 18:37:07 -07:00
|
|
|
* shouldn't occur. */
|
2013-06-19 16:58:44 -07:00
|
|
|
odp_port_t
|
2013-06-18 15:24:33 -07:00
|
|
|
tnl_port_send(const struct ofport_dpif *ofport, struct flow *flow,
|
2013-07-23 12:03:37 -07:00
|
|
|
struct flow_wildcards *wc) OVS_EXCLUDED(rwlock)
|
2012-09-19 18:37:07 -07:00
|
|
|
{
|
|
|
|
const struct netdev_tunnel_config *cfg;
|
2013-07-23 12:03:37 -07:00
|
|
|
struct tnl_port *tnl_port;
|
2012-09-19 18:37:07 -07:00
|
|
|
char *pre_flow_str = NULL;
|
2013-07-23 12:03:37 -07:00
|
|
|
odp_port_t out_port;
|
2012-09-19 18:37:07 -07:00
|
|
|
|
2014-11-10 12:45:57 -08:00
|
|
|
fat_rwlock_rdlock(&rwlock);
|
2013-07-23 12:03:37 -07:00
|
|
|
tnl_port = tnl_find_ofport(ofport);
|
|
|
|
out_port = tnl_port ? tnl_port->match.odp_port : ODPP_NONE;
|
2013-06-18 15:24:33 -07:00
|
|
|
if (!tnl_port) {
|
2013-07-23 12:03:37 -07:00
|
|
|
goto out;
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
|
|
|
|
2013-06-18 14:40:30 -07:00
|
|
|
cfg = netdev_get_tunnel_config(tnl_port->netdev);
|
2012-09-19 18:37:07 -07:00
|
|
|
ovs_assert(cfg);
|
|
|
|
|
|
|
|
if (!VLOG_DROP_DBG(&dbg_rl)) {
|
2017-05-31 16:06:12 -07:00
|
|
|
pre_flow_str = flow_to_string(flow, NULL);
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
|
|
|
|
2013-05-09 15:24:16 +03:00
|
|
|
if (!cfg->ip_src_flow) {
|
2015-10-22 15:28:57 -02:00
|
|
|
flow->tunnel.ip_src = in6_addr_get_mapped_ipv4(&tnl_port->match.ipv6_src);
|
2015-11-25 11:31:11 -02:00
|
|
|
if (!flow->tunnel.ip_src) {
|
|
|
|
flow->tunnel.ipv6_src = tnl_port->match.ipv6_src;
|
2016-04-01 10:06:05 -03:00
|
|
|
} else {
|
|
|
|
flow->tunnel.ipv6_src = in6addr_any;
|
2015-11-25 11:31:11 -02:00
|
|
|
}
|
2013-05-09 15:24:16 +03:00
|
|
|
}
|
|
|
|
if (!cfg->ip_dst_flow) {
|
2015-10-22 15:28:57 -02:00
|
|
|
flow->tunnel.ip_dst = in6_addr_get_mapped_ipv4(&tnl_port->match.ipv6_dst);
|
2015-11-25 11:31:11 -02:00
|
|
|
if (!flow->tunnel.ip_dst) {
|
|
|
|
flow->tunnel.ipv6_dst = tnl_port->match.ipv6_dst;
|
2016-04-01 10:06:05 -03:00
|
|
|
} else {
|
|
|
|
flow->tunnel.ipv6_dst = in6addr_any;
|
2015-11-25 11:31:11 -02:00
|
|
|
}
|
2013-05-09 15:24:16 +03:00
|
|
|
}
|
2023-12-01 22:04:12 +01:00
|
|
|
flow->tunnel.tp_src = 0; /* Do not carry from a previous tunnel. */
|
2016-12-05 18:22:11 -08:00
|
|
|
flow->tunnel.tp_dst = cfg->dst_port;
|
2012-09-19 18:37:07 -07:00
|
|
|
if (!cfg->out_key_flow) {
|
|
|
|
flow->tunnel.tun_id = cfg->out_key;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg->ttl_inherit && is_ip_any(flow)) {
|
2013-06-13 16:46:33 -07:00
|
|
|
wc->masks.nw_ttl = 0xff;
|
2012-09-19 18:37:07 -07:00
|
|
|
flow->tunnel.ip_ttl = flow->nw_ttl;
|
|
|
|
} else {
|
|
|
|
flow->tunnel.ip_ttl = cfg->ttl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg->tos_inherit && is_ip_any(flow)) {
|
2014-10-22 14:57:39 -07:00
|
|
|
wc->masks.nw_tos |= IP_DSCP_MASK;
|
2012-09-19 18:37:07 -07:00
|
|
|
flow->tunnel.ip_tos = flow->nw_tos & IP_DSCP_MASK;
|
|
|
|
} else {
|
|
|
|
flow->tunnel.ip_tos = cfg->tos;
|
|
|
|
}
|
|
|
|
|
2013-06-25 16:40:50 -07:00
|
|
|
/* ECN fields are always inherited. */
|
|
|
|
if (is_ip_any(flow)) {
|
|
|
|
wc->masks.nw_tos |= IP_ECN_MASK;
|
|
|
|
|
2016-05-17 17:35:28 -07:00
|
|
|
if (IP_ECN_is_ce(flow->nw_tos)) {
|
2014-04-09 11:13:57 -07:00
|
|
|
flow->tunnel.ip_tos |= IP_ECN_ECT_0;
|
|
|
|
} else {
|
|
|
|
flow->tunnel.ip_tos |= flow->nw_tos & IP_ECN_MASK;
|
|
|
|
}
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
|
|
|
|
2018-01-10 13:13:11 -08:00
|
|
|
flow->tunnel.flags &= ~(FLOW_TNL_F_MASK & ~FLOW_TNL_PUB_F_MASK);
|
2015-07-08 16:02:30 -07:00
|
|
|
flow->tunnel.flags |= (cfg->dont_fragment ? FLOW_TNL_F_DONT_FRAGMENT : 0)
|
2012-09-19 18:37:07 -07:00
|
|
|
| (cfg->out_key_present ? FLOW_TNL_F_KEY : 0);
|
|
|
|
|
2024-07-05 16:45:01 -04:00
|
|
|
if (cfg->csum == NETDEV_TNL_CSUM_ENABLED ||
|
|
|
|
(cfg->csum == NETDEV_TNL_CSUM_DEFAULT && !flow->tunnel.ip_dst)) {
|
|
|
|
flow->tunnel.flags |= FLOW_TNL_F_CSUM;
|
|
|
|
}
|
|
|
|
|
2017-01-17 10:16:09 -08:00
|
|
|
if (cfg->set_egress_pkt_mark) {
|
|
|
|
flow->pkt_mark = cfg->egress_pkt_mark;
|
|
|
|
wc->masks.pkt_mark = UINT32_MAX;
|
|
|
|
}
|
|
|
|
|
2018-05-17 17:46:41 -07:00
|
|
|
if (!cfg->erspan_ver_flow) {
|
2018-05-15 16:10:48 -04:00
|
|
|
flow->tunnel.erspan_ver = cfg->erspan_ver;
|
|
|
|
}
|
2018-05-17 17:46:41 -07:00
|
|
|
|
|
|
|
if (!cfg->erspan_idx_flow) {
|
2018-05-15 16:10:48 -04:00
|
|
|
flow->tunnel.erspan_idx = cfg->erspan_idx;
|
|
|
|
}
|
2018-05-17 17:46:41 -07:00
|
|
|
|
|
|
|
if (!cfg->erspan_dir_flow) {
|
2018-05-15 16:10:48 -04:00
|
|
|
flow->tunnel.erspan_dir = cfg->erspan_dir;
|
|
|
|
}
|
2018-05-17 17:46:41 -07:00
|
|
|
|
|
|
|
if (!cfg->erspan_hwid_flow) {
|
2018-05-15 16:10:48 -04:00
|
|
|
flow->tunnel.erspan_hwid = cfg->erspan_hwid;
|
|
|
|
}
|
|
|
|
|
2012-09-19 18:37:07 -07:00
|
|
|
if (pre_flow_str) {
|
2017-05-31 16:06:12 -07:00
|
|
|
char *post_flow_str = flow_to_string(flow, NULL);
|
2017-12-28 12:34:50 -08:00
|
|
|
char *tnl_str = tnl_port_to_string(tnl_port);
|
2012-09-19 18:37:07 -07:00
|
|
|
VLOG_DBG("flow sent\n"
|
|
|
|
"%s"
|
|
|
|
" pre: %s\n"
|
|
|
|
"post: %s",
|
|
|
|
tnl_str, pre_flow_str, post_flow_str);
|
|
|
|
free(tnl_str);
|
|
|
|
free(pre_flow_str);
|
|
|
|
free(post_flow_str);
|
|
|
|
}
|
|
|
|
|
2013-07-23 12:03:37 -07:00
|
|
|
out:
|
2014-11-10 12:45:57 -08:00
|
|
|
fat_rwlock_unlock(&rwlock);
|
2013-07-23 12:03:37 -07:00
|
|
|
return out_port;
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
tnl_hash(struct tnl_match *match)
|
|
|
|
{
|
|
|
|
BUILD_ASSERT_DECL(sizeof *match % sizeof(uint32_t) == 0);
|
|
|
|
return hash_words((uint32_t *) match, sizeof *match / sizeof(uint32_t), 0);
|
|
|
|
}
|
|
|
|
|
2013-06-18 15:24:33 -07:00
|
|
|
static struct tnl_port *
|
2013-07-23 12:03:37 -07:00
|
|
|
tnl_find_ofport(const struct ofport_dpif *ofport) OVS_REQ_RDLOCK(rwlock)
|
2013-06-18 15:24:33 -07:00
|
|
|
{
|
|
|
|
struct tnl_port *tnl_port;
|
|
|
|
|
|
|
|
HMAP_FOR_EACH_IN_BUCKET (tnl_port, ofport_node, hash_pointer(ofport, 0),
|
2013-07-23 12:03:37 -07:00
|
|
|
ofport_map) {
|
2013-06-18 15:24:33 -07:00
|
|
|
if (tnl_port->ofport == ofport) {
|
|
|
|
return tnl_port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-09-19 18:37:07 -07:00
|
|
|
static struct tnl_port *
|
2014-02-11 15:13:56 -08:00
|
|
|
tnl_find_exact(struct tnl_match *match, struct hmap *map)
|
|
|
|
OVS_REQ_RDLOCK(rwlock)
|
2012-09-19 18:37:07 -07:00
|
|
|
{
|
2014-02-11 15:13:56 -08:00
|
|
|
if (map) {
|
|
|
|
struct tnl_port *tnl_port;
|
2012-09-19 18:37:07 -07:00
|
|
|
|
2014-02-11 15:13:56 -08:00
|
|
|
HMAP_FOR_EACH_WITH_HASH (tnl_port, match_node, tnl_hash(match), map) {
|
|
|
|
if (!memcmp(match, &tnl_port->match, sizeof *match)) {
|
|
|
|
return tnl_port;
|
|
|
|
}
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-09-25 09:35:33 -07:00
|
|
|
/* Returns the tnl_port that is the best match for the tunnel data in 'flow',
|
|
|
|
* or NULL if no tnl_port matches 'flow'. */
|
2012-09-19 18:37:07 -07:00
|
|
|
static struct tnl_port *
|
2013-09-25 09:35:33 -07:00
|
|
|
tnl_find(const struct flow *flow) OVS_REQ_RDLOCK(rwlock)
|
2012-09-19 18:37:07 -07:00
|
|
|
{
|
2014-02-11 15:13:56 -08:00
|
|
|
enum ip_src_type ip_src;
|
|
|
|
int in_key_flow;
|
|
|
|
int ip_dst_flow;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
for (in_key_flow = 0; in_key_flow < 2; in_key_flow++) {
|
|
|
|
for (ip_dst_flow = 0; ip_dst_flow < 2; ip_dst_flow++) {
|
|
|
|
for (ip_src = 0; ip_src < 3; ip_src++) {
|
|
|
|
struct hmap *map = tnl_match_maps[i];
|
|
|
|
|
|
|
|
if (map) {
|
|
|
|
struct tnl_port *tnl_port;
|
|
|
|
struct tnl_match match;
|
|
|
|
|
|
|
|
memset(&match, 0, sizeof match);
|
|
|
|
|
|
|
|
/* The apparent mix-up of 'ip_dst' and 'ip_src' below is
|
|
|
|
* correct, because "struct tnl_match" is expressed in
|
|
|
|
* terms of packets being sent out, but we are using it
|
|
|
|
* here as a description of how to treat received
|
|
|
|
* packets. */
|
|
|
|
match.in_key = in_key_flow ? 0 : flow->tunnel.tun_id;
|
2015-11-25 11:31:11 -02:00
|
|
|
if (ip_src == IP_SRC_CFG) {
|
|
|
|
match.ipv6_src = flow_tnl_dst(&flow->tunnel);
|
2015-10-22 15:28:57 -02:00
|
|
|
}
|
2015-11-25 11:31:11 -02:00
|
|
|
if (!ip_dst_flow) {
|
|
|
|
match.ipv6_dst = flow_tnl_src(&flow->tunnel);
|
2015-10-22 15:28:57 -02:00
|
|
|
}
|
2014-02-11 15:13:56 -08:00
|
|
|
match.odp_port = flow->in_port.odp_port;
|
|
|
|
match.in_key_flow = in_key_flow;
|
|
|
|
match.ip_dst_flow = ip_dst_flow;
|
|
|
|
match.ip_src_flow = ip_src == IP_SRC_FLOW;
|
|
|
|
|
2017-06-23 16:47:59 +00:00
|
|
|
/* Look for a legacy L2 or L3 tunnel port first. */
|
|
|
|
if (pt_ns(flow->packet_type) == OFPHTN_ETHERTYPE) {
|
|
|
|
match.pt_mode = NETDEV_PT_LEGACY_L3;
|
|
|
|
} else {
|
|
|
|
match.pt_mode = NETDEV_PT_LEGACY_L2;
|
|
|
|
}
|
|
|
|
tnl_port = tnl_find_exact(&match, map);
|
|
|
|
if (tnl_port) {
|
|
|
|
return tnl_port;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Then check for a packet type aware port. */
|
|
|
|
match.pt_mode = NETDEV_PT_AWARE;
|
2014-02-11 15:13:56 -08:00
|
|
|
tnl_port = tnl_find_exact(&match, map);
|
|
|
|
if (tnl_port) {
|
|
|
|
return tnl_port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
2013-09-25 09:35:33 -07:00
|
|
|
}
|
2013-05-09 15:24:16 +03:00
|
|
|
}
|
|
|
|
|
2012-09-19 18:37:07 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-11 15:13:56 -08:00
|
|
|
/* Returns a pointer to the 'tnl_match_maps' element corresponding to 'm''s
|
|
|
|
* matching criteria. */
|
|
|
|
static struct hmap **
|
|
|
|
tnl_match_map(const struct tnl_match *m)
|
|
|
|
{
|
|
|
|
enum ip_src_type ip_src;
|
|
|
|
|
|
|
|
ip_src = (m->ip_src_flow ? IP_SRC_FLOW
|
2015-10-22 15:28:57 -02:00
|
|
|
: ipv6_addr_is_set(&m->ipv6_src) ? IP_SRC_CFG
|
2014-02-11 15:13:56 -08:00
|
|
|
: IP_SRC_ANY);
|
|
|
|
|
|
|
|
return &tnl_match_maps[6 * m->in_key_flow + 3 * m->ip_dst_flow + ip_src];
|
|
|
|
}
|
|
|
|
|
2012-09-19 18:37:07 -07:00
|
|
|
static void
|
|
|
|
tnl_match_fmt(const struct tnl_match *match, struct ds *ds)
|
2013-07-23 12:03:37 -07:00
|
|
|
OVS_REQ_RDLOCK(rwlock)
|
2012-09-19 18:37:07 -07:00
|
|
|
{
|
2013-05-09 15:24:16 +03:00
|
|
|
if (!match->ip_dst_flow) {
|
2015-10-25 13:19:22 -07:00
|
|
|
ipv6_format_mapped(&match->ipv6_src, ds);
|
2015-10-22 15:28:57 -02:00
|
|
|
ds_put_cstr(ds, "->");
|
2015-10-25 13:19:22 -07:00
|
|
|
ipv6_format_mapped(&match->ipv6_dst, ds);
|
2013-05-09 15:24:16 +03:00
|
|
|
} else if (!match->ip_src_flow) {
|
2015-10-25 13:19:22 -07:00
|
|
|
ipv6_format_mapped(&match->ipv6_src, ds);
|
2015-10-22 15:28:57 -02:00
|
|
|
ds_put_cstr(ds, "->flow");
|
2013-05-09 15:24:16 +03:00
|
|
|
} else {
|
|
|
|
ds_put_cstr(ds, "flow->flow");
|
|
|
|
}
|
2012-09-19 18:37:07 -07:00
|
|
|
|
2013-02-07 18:39:24 -08:00
|
|
|
if (match->in_key_flow) {
|
|
|
|
ds_put_cstr(ds, ", key=flow");
|
|
|
|
} else {
|
|
|
|
ds_put_format(ds, ", key=%#"PRIx64, ntohll(match->in_key));
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
|
|
|
|
2017-06-23 16:47:59 +00:00
|
|
|
const char *pt_mode
|
|
|
|
= (match->pt_mode == NETDEV_PT_LEGACY_L2 ? "legacy_l2"
|
|
|
|
: match->pt_mode == NETDEV_PT_LEGACY_L3 ? "legacy_l3"
|
|
|
|
: "ptap");
|
|
|
|
ds_put_format(ds, ", %s, dp port=%"PRIu32, pt_mode, match->odp_port);
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
tnl_port_mod_log(const struct tnl_port *tnl_port, const char *action)
|
2013-07-23 12:03:37 -07:00
|
|
|
OVS_REQ_RDLOCK(rwlock)
|
2012-09-19 18:37:07 -07:00
|
|
|
{
|
|
|
|
if (VLOG_IS_DBG_ENABLED()) {
|
|
|
|
struct ds ds = DS_EMPTY_INITIALIZER;
|
|
|
|
|
|
|
|
tnl_match_fmt(&tnl_port->match, &ds);
|
2013-02-06 16:45:38 -08:00
|
|
|
VLOG_INFO("%s tunnel port %s (%s)", action,
|
|
|
|
tnl_port_get_name(tnl_port), ds_cstr(&ds));
|
2012-09-19 18:37:07 -07:00
|
|
|
ds_destroy(&ds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-28 12:34:50 -08:00
|
|
|
static void OVS_REQ_RDLOCK(rwlock)
|
|
|
|
tnl_port_format(const struct tnl_port *tnl_port, struct ds *ds)
|
2012-09-19 18:37:07 -07:00
|
|
|
{
|
|
|
|
const struct netdev_tunnel_config *cfg =
|
2013-06-18 14:40:30 -07:00
|
|
|
netdev_get_tunnel_config(tnl_port->netdev);
|
2012-09-19 18:37:07 -07:00
|
|
|
|
2017-12-28 12:34:50 -08:00
|
|
|
ds_put_format(ds, "port %"PRIu32": %s (%s: ", tnl_port->match.odp_port,
|
2012-09-19 18:37:07 -07:00
|
|
|
tnl_port_get_name(tnl_port),
|
2013-06-18 14:40:30 -07:00
|
|
|
netdev_get_type(tnl_port->netdev));
|
2017-12-28 12:34:50 -08:00
|
|
|
tnl_match_fmt(&tnl_port->match, ds);
|
2012-09-19 18:37:07 -07:00
|
|
|
|
|
|
|
if (cfg->out_key != cfg->in_key ||
|
|
|
|
cfg->out_key_present != cfg->in_key_present ||
|
|
|
|
cfg->out_key_flow != cfg->in_key_flow) {
|
2017-12-28 12:34:50 -08:00
|
|
|
ds_put_cstr(ds, ", out_key=");
|
2012-09-19 18:37:07 -07:00
|
|
|
if (!cfg->out_key_present) {
|
2017-12-28 12:34:50 -08:00
|
|
|
ds_put_cstr(ds, "none");
|
2012-09-19 18:37:07 -07:00
|
|
|
} else if (cfg->out_key_flow) {
|
2017-12-28 12:34:50 -08:00
|
|
|
ds_put_cstr(ds, "flow");
|
2012-09-19 18:37:07 -07:00
|
|
|
} else {
|
2017-12-28 12:34:50 -08:00
|
|
|
ds_put_format(ds, "%#"PRIx64, ntohll(cfg->out_key));
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg->ttl_inherit) {
|
2017-12-28 12:34:50 -08:00
|
|
|
ds_put_cstr(ds, ", ttl=inherit");
|
2012-09-19 18:37:07 -07:00
|
|
|
} else {
|
2017-12-28 12:34:50 -08:00
|
|
|
ds_put_format(ds, ", ttl=%"PRIu8, cfg->ttl);
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (cfg->tos_inherit) {
|
2017-12-28 12:34:50 -08:00
|
|
|
ds_put_cstr(ds, ", tos=inherit");
|
2012-09-19 18:37:07 -07:00
|
|
|
} else if (cfg->tos) {
|
2017-12-28 12:34:50 -08:00
|
|
|
ds_put_format(ds, ", tos=%#"PRIx8, cfg->tos);
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!cfg->dont_fragment) {
|
2017-12-28 12:34:50 -08:00
|
|
|
ds_put_cstr(ds, ", df=false");
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
|
|
|
|
2024-07-05 16:45:01 -04:00
|
|
|
if (cfg->csum == NETDEV_TNL_CSUM_ENABLED) {
|
2017-12-28 12:34:50 -08:00
|
|
|
ds_put_cstr(ds, ", csum=true");
|
2024-07-05 16:45:01 -04:00
|
|
|
} else if (cfg->csum == NETDEV_TNL_CSUM_DISABLED) {
|
|
|
|
ds_put_cstr(ds, ", csum=false");
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
|
|
|
|
2017-12-28 12:34:50 -08:00
|
|
|
ds_put_cstr(ds, ")\n");
|
|
|
|
}
|
2012-09-19 18:37:07 -07:00
|
|
|
|
2017-12-28 12:34:50 -08:00
|
|
|
static char * OVS_REQ_RDLOCK(rwlock)
|
|
|
|
tnl_port_to_string(const struct tnl_port *tnl_port)
|
|
|
|
{
|
|
|
|
struct ds ds = DS_EMPTY_INITIALIZER;
|
|
|
|
tnl_port_format(tnl_port, &ds);
|
2012-09-19 18:37:07 -07:00
|
|
|
return ds_steal_cstr(&ds);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
2013-07-23 12:03:37 -07:00
|
|
|
tnl_port_get_name(const struct tnl_port *tnl_port) OVS_REQ_RDLOCK(rwlock)
|
2012-09-19 18:37:07 -07:00
|
|
|
{
|
2013-06-18 14:40:30 -07:00
|
|
|
return netdev_get_name(tnl_port->netdev);
|
2012-09-19 18:37:07 -07:00
|
|
|
}
|
2014-11-11 11:53:47 -08:00
|
|
|
|
tunnel: make tun_key_to_attr aware of tunnel type.
When there is a flow rule which forwards a packet from geneve
port to another tunnel port, ex: gre, the tun_metadata carried
from the geneve port might affect the outgoing port. For example,
the datapath action from geneve port output to gre port (1) shows:
set(tunnel(tun_id=0x7b,dst=2.2.2.2,ttl=64,
geneve({class=0xffff,type=0,len=4,0x123}),flags(df|key))),1
Where the geneve(...) should not exist.
When using kernel's tunnel port, this triggers an error saying:
"Multiple metadata blocks provided", when there is a rule forwarding
the geneve packet to vxlan/erspan tunnel port. A userspace test case
using geneve and gre also demonstrates the issue.
The patch makes the tun_key_to_attr aware of the tunnel type. So only
the relevant output tunnel's options are set.
Reported-by: Xiaoyan Jin <xiaoyanj@vmware.com>
Signed-off-by: William Tu <u9012063@gmail.com>
Cc: Greg Rose <gvrose8192@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
2018-05-14 11:46:47 -07:00
|
|
|
const char *
|
|
|
|
tnl_port_get_type(const struct ofport_dpif *ofport) OVS_REQ_RDLOCK(rwlock)
|
|
|
|
{
|
|
|
|
struct tnl_port *tnl_port;
|
|
|
|
|
|
|
|
tnl_port = tnl_find_ofport(ofport);
|
|
|
|
return !tnl_port ? NULL :
|
|
|
|
netdev_get_type(tnl_port->netdev);
|
|
|
|
}
|
|
|
|
|
2014-11-11 11:53:47 -08:00
|
|
|
int
|
|
|
|
tnl_port_build_header(const struct ofport_dpif *ofport,
|
2016-05-23 20:27:14 -07:00
|
|
|
struct ovs_action_push_tnl *data,
|
|
|
|
const struct netdev_tnl_build_header_params *params)
|
2014-11-11 11:53:47 -08:00
|
|
|
{
|
|
|
|
struct tnl_port *tnl_port;
|
|
|
|
int res;
|
|
|
|
|
|
|
|
fat_rwlock_rdlock(&rwlock);
|
|
|
|
tnl_port = tnl_find_ofport(ofport);
|
|
|
|
ovs_assert(tnl_port);
|
2016-05-23 20:27:14 -07:00
|
|
|
res = netdev_build_header(tnl_port->netdev, data, params);
|
2014-11-11 11:53:47 -08:00
|
|
|
fat_rwlock_unlock(&rwlock);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2017-12-28 12:34:50 -08:00
|
|
|
|
|
|
|
static void
|
|
|
|
tnl_unixctl_list(struct unixctl_conn *conn,
|
|
|
|
int argc OVS_UNUSED, const char *argv[] OVS_UNUSED,
|
|
|
|
void *aux OVS_UNUSED)
|
|
|
|
{
|
|
|
|
struct ds reply = DS_EMPTY_INITIALIZER;
|
|
|
|
|
|
|
|
fat_rwlock_rdlock(&rwlock);
|
|
|
|
for (int i = 0; i < N_MATCH_TYPES; i++) {
|
|
|
|
struct hmap *map = tnl_match_maps[i];
|
|
|
|
if (map) {
|
|
|
|
struct tnl_port *tnl_port;
|
|
|
|
HMAP_FOR_EACH (tnl_port, match_node, map) {
|
|
|
|
tnl_port_format(tnl_port, &reply);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fat_rwlock_unlock(&rwlock);
|
|
|
|
|
|
|
|
unixctl_command_reply(conn, ds_cstr(&reply));
|
|
|
|
ds_destroy(&reply);
|
|
|
|
}
|