Skip to content

Commit

Permalink
netdev-vport: Use dpif_port as base for tunnel backing port.
Browse files Browse the repository at this point in the history
In most cases, tunnel ports specify a dpif name to act as the backing
port in the datapath. However, in the case of UDP tunnels the type is
used with the port number appended. This is potentially a problem for
IPsec tunnels because they have different types but should have the
same backing port. The hasn't been a problem in practice though because
no UDP tunnels are currently used with IPsec.

This switches to use the dpif_port in all cases plus a port number if
necessary. It does this by making the names short enough to accomodate
ports, which also makes the naming more consistent.

Signed-off-by: Jesse Gross <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
jessegross committed Jun 13, 2014
1 parent b56ea5d commit a5d4fad
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
37 changes: 21 additions & 16 deletions lib/netdev-vport.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,25 +146,28 @@ const char *
netdev_vport_get_dpif_port(const struct netdev *netdev,
char namebuf[], size_t bufsize)
{
const struct netdev_class *class = netdev_get_class(netdev);
const char *dpif_port = netdev_vport_class_get_dpif_port(class);

if (!dpif_port) {
return netdev_get_name(netdev);
}

if (netdev_vport_needs_dst_port(netdev)) {
const struct netdev_vport *vport = netdev_vport_cast(netdev);
const char *type = netdev_get_type(netdev);

/*
* Note: IFNAMSIZ is 16 bytes long. The maximum length of a VXLAN
* or LISP port name below is 15 or 14 bytes respectively. Still,
* assert here on the size of strlen(type) in case that changes
* in the future.
* Note: IFNAMSIZ is 16 bytes long. Implementations should choose
* a dpif port name that is short enough to fit including any
* port numbers but assert just in case.
*/
BUILD_ASSERT(NETDEV_VPORT_NAME_BUFSIZE >= IFNAMSIZ);
ovs_assert(strlen(type) + 10 < IFNAMSIZ);
snprintf(namebuf, bufsize, "%s_sys_%d", type,
ovs_assert(strlen(dpif_port) + 6 < IFNAMSIZ);
snprintf(namebuf, bufsize, "%s_%d", dpif_port,
ntohs(vport->tnl_cfg.dst_port));
return namebuf;
} else {
const struct netdev_class *class = netdev_get_class(netdev);
const char *dpif_port = netdev_vport_class_get_dpif_port(class);
return dpif_port ? dpif_port : netdev_get_name(netdev);
return dpif_port;
}
}

Expand Down Expand Up @@ -825,13 +828,15 @@ get_stats(const struct netdev *netdev, struct netdev_stats *stats)
void
netdev_vport_tunnel_register(void)
{
/* The name of the dpif_port should be short enough to accomodate adding
* a port number to the end if one is necessary. */
static const struct vport_class vport_classes[] = {
TUNNEL_CLASS("gre", "gre_system"),
TUNNEL_CLASS("ipsec_gre", "gre_system"),
TUNNEL_CLASS("gre64", "gre64_system"),
TUNNEL_CLASS("ipsec_gre64", "gre64_system"),
TUNNEL_CLASS("vxlan", "vxlan_system"),
TUNNEL_CLASS("lisp", "lisp_system")
TUNNEL_CLASS("gre", "gre_sys"),
TUNNEL_CLASS("ipsec_gre", "gre_sys"),
TUNNEL_CLASS("gre64", "gre64_sys"),
TUNNEL_CLASS("ipsec_gre64", "gre64_sys"),
TUNNEL_CLASS("vxlan", "vxlan_sys"),
TUNNEL_CLASS("lisp", "lisp_sys")
};
static struct ovsthread_once once = OVSTHREAD_ONCE_INITIALIZER;

Expand Down
2 changes: 1 addition & 1 deletion lib/netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ netdev_is_reserved_name(const char *name)
ovs_mutex_lock(&netdev_class_mutex);
HMAP_FOR_EACH (rc, hmap_node, &netdev_classes) {
const char *dpif_port = netdev_vport_class_get_dpif_port(rc->class);
if (dpif_port && !strcmp(dpif_port, name)) {
if (dpif_port && !strncmp(name, dpif_port, strlen(dpif_port))) {
ovs_mutex_unlock(&netdev_class_mutex);
return true;
}
Expand Down
16 changes: 8 additions & 8 deletions tests/ovs-vsctl.at
Original file line number Diff line number Diff line change
Expand Up @@ -1203,10 +1203,10 @@ m4_foreach(
[reserved_name],
[[ovs-netdev],
[ovs-dummy],
[gre_system],
[gre64_system],
[lisp_system],
[vxlan_system]],
[gre_sys],
[gre64_sys],
[lisp_sys],
[vxlan_sys]],
[
# Try creating the port
AT_CHECK([ovs-vsctl add-port br0 reserved_name], [0], [], [dnl
Expand Down Expand Up @@ -1238,10 +1238,10 @@ OVS_VSWITCHD_START([add-port br0 p1 -- set Interface p1 type=gre \
# Test creating all reserved tunnel port names
m4_foreach(
[reserved_name],
[[gre_system],
[gre64_system],
[lisp_system],
[vxlan_system]],
[[gre_sys],
[gre64_sys],
[lisp_sys],
[vxlan_sys]],
[
# Try creating the port
AT_CHECK([ovs-vsctl add-port br0 reserved_name], [0], [], [dnl
Expand Down

0 comments on commit a5d4fad

Please sign in to comment.