/*
- * Copyright (c) 2010, 2011, 2012, 2013 Nicira, Inc.
+ * Copyright (c) 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include "netdev-provider.h"
#include "ofpbuf.h"
#include "packets.h"
+#include "poll-loop.h"
#include "route-table.h"
#include "shash.h"
#include "socket-util.h"
VLOG_DEFINE_THIS_MODULE(netdev_vport);
+#define GENEVE_DST_PORT 6081
#define VXLAN_DST_PORT 4789
#define LISP_DST_PORT 4341
/* Protects all members below. */
struct ovs_mutex mutex;
- unsigned int change_seq;
uint8_t etheraddr[ETH_ADDR_LEN];
struct netdev_stats stats;
/* Tunnels. */
struct netdev_tunnel_config tnl_cfg;
+ char egress_iface[IFNAMSIZ];
+ bool carrier_status;
/* Patch Ports. */
char *peer;
struct netdev_class netdev_class;
};
+/* Last read of the route-table's change number. */
+static uint64_t rt_change_seqno;
+
static int netdev_vport_construct(struct netdev *);
static int get_patch_config(const struct netdev *netdev, struct smap *args);
static int get_tunnel_config(const struct netdev *, struct smap *args);
-static void netdev_vport_poll_notify(struct netdev_vport *netdev)
- OVS_REQUIRES(netdev->mutex);
+static bool tunnel_check_status_change__(struct netdev_vport *);
static bool
is_vport_class(const struct netdev_class *class)
return class->construct == netdev_vport_construct;
}
+bool
+netdev_vport_is_vport_class(const struct netdev_class *class)
+{
+ return is_vport_class(class);
+}
+
static const struct vport_class *
vport_class_cast(const struct netdev_class *class)
{
return class->get_config == get_patch_config;
}
+bool
+netdev_vport_is_layer3(const struct netdev *dev)
+{
+ const char *type = netdev_get_type(dev);
+
+ return (!strcmp("lisp", type));
+}
+
static bool
netdev_vport_needs_dst_port(const struct netdev *dev)
{
const char *type = netdev_get_type(dev);
return (class->get_config == get_tunnel_config &&
- (!strcmp("vxlan", type) || !strcmp("lisp", type)));
+ (!strcmp("geneve", type) || !strcmp("vxlan", type) ||
+ !strcmp("lisp", type)));
}
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;
}
}
sizeof namebuf));
}
+/* Whenever the route-table change number is incremented,
+ * netdev_vport_route_changed() should be called to update
+ * the corresponding tunnel interface status. */
+static void
+netdev_vport_route_changed(void)
+{
+ struct netdev **vports;
+ size_t i, n_vports;
+
+ vports = netdev_get_vports(&n_vports);
+ for (i = 0; i < n_vports; i++) {
+ struct netdev *netdev_ = vports[i];
+ struct netdev_vport *netdev = netdev_vport_cast(netdev_);
+
+ ovs_mutex_lock(&netdev->mutex);
+ /* Finds all tunnel vports. */
+ if (netdev->tnl_cfg.ip_dst) {
+ if (tunnel_check_status_change__(netdev)) {
+ netdev_change_seq_changed(netdev_);
+ }
+ }
+ ovs_mutex_unlock(&netdev->mutex);
+
+ netdev_close(netdev_);
+ }
+
+ free(vports);
+}
+
static struct netdev *
netdev_vport_alloc(void)
{
struct netdev_vport *netdev = netdev_vport_cast(netdev_);
ovs_mutex_init(&netdev->mutex);
- netdev->change_seq = 1;
eth_addr_random(netdev->etheraddr);
route_table_register();
ovs_mutex_lock(&netdev->mutex);
memcpy(netdev->etheraddr, mac, ETH_ADDR_LEN);
- netdev_vport_poll_notify(netdev);
ovs_mutex_unlock(&netdev->mutex);
+ netdev_change_seq_changed(netdev_);
return 0;
}
return 0;
}
-static int
-tunnel_get_status(const struct netdev *netdev_, struct smap *smap)
+/* Checks if the tunnel status has changed and returns a boolean.
+ * Updates the tunnel status if it has changed. */
+static bool
+tunnel_check_status_change__(struct netdev_vport *netdev)
+ OVS_REQUIRES(netdev->mutex)
{
- struct netdev_vport *netdev = netdev_vport_cast(netdev_);
char iface[IFNAMSIZ];
+ bool status = false;
ovs_be32 route;
- ovs_mutex_lock(&netdev->mutex);
+ iface[0] = '\0';
route = netdev->tnl_cfg.ip_dst;
- ovs_mutex_unlock(&netdev->mutex);
-
if (route_table_get_name(route, iface)) {
struct netdev *egress_netdev;
- smap_add(smap, "tunnel_egress_iface", iface);
-
if (!netdev_open(iface, "system", &egress_netdev)) {
- smap_add(smap, "tunnel_egress_iface_carrier",
- netdev_get_carrier(egress_netdev) ? "up" : "down");
+ status = netdev_get_carrier(egress_netdev);
netdev_close(egress_netdev);
}
}
+ if (strcmp(netdev->egress_iface, iface)
+ || netdev->carrier_status != status) {
+ ovs_strlcpy(netdev->egress_iface, iface, IFNAMSIZ);
+ netdev->carrier_status = status;
+
+ return true;
+ }
+
+ return false;
+}
+
+static int
+tunnel_get_status(const struct netdev *netdev_, struct smap *smap)
+{
+ struct netdev_vport *netdev = netdev_vport_cast(netdev_);
+
+ if (netdev->egress_iface[0]) {
+ smap_add(smap, "tunnel_egress_iface", netdev->egress_iface);
+
+ smap_add(smap, "tunnel_egress_iface_carrier",
+ netdev->carrier_status ? "up" : "down");
+ }
+
return 0;
}
return 0;
}
-static unsigned int
-netdev_vport_change_seq(const struct netdev *netdev)
-{
- return netdev_vport_cast(netdev)->change_seq;
-}
-
static void
netdev_vport_run(void)
{
+ uint64_t seq;
+
route_table_run();
+ seq = route_table_get_change_seq();
+ if (rt_change_seqno != seq) {
+ rt_change_seqno = seq;
+ netdev_vport_route_changed();
+ }
}
static void
netdev_vport_wait(void)
{
- route_table_wait();
-}
-\f
-/* Helper functions. */
+ uint64_t seq;
-static void
-netdev_vport_poll_notify(struct netdev_vport *ndv)
-{
- ndv->change_seq++;
- if (!ndv->change_seq) {
- ndv->change_seq++;
+ route_table_wait();
+ seq = route_table_get_change_seq();
+ if (rt_change_seqno != seq) {
+ poll_immediate_wake();
}
}
\f
}
}
- /* Add a default destination port for VXLAN if none specified. */
+ /* Add a default destination port for tunnel ports if none specified. */
+ if (!strcmp(type, "geneve") && !tnl_cfg.dst_port) {
+ tnl_cfg.dst_port = htons(GENEVE_DST_PORT);
+ }
+
if (!strcmp(type, "vxlan") && !tnl_cfg.dst_port) {
tnl_cfg.dst_port = htons(VXLAN_DST_PORT);
}
- /* Add a default destination port for LISP if none specified. */
if (!strcmp(type, "lisp") && !tnl_cfg.dst_port) {
tnl_cfg.dst_port = htons(LISP_DST_PORT);
}
static struct ovs_mutex mutex = OVS_MUTEX_INITIALIZER;
static pid_t pid = 0;
+#ifndef _WIN32
ovs_mutex_lock(&mutex);
if (pid <= 0) {
char *file_name = xasprintf("%s/%s", ovs_rundir(),
free(file_name);
}
ovs_mutex_unlock(&mutex);
+#endif
if (pid < 0) {
VLOG_ERR("%s: IPsec requires the ovs-monitor-ipsec daemon",
ovs_mutex_lock(&dev->mutex);
dev->tnl_cfg = tnl_cfg;
- netdev_vport_poll_notify(dev);
+ tunnel_check_status_change__(dev);
+ netdev_change_seq_changed(dev_);
ovs_mutex_unlock(&dev->mutex);
return 0;
uint16_t dst_port = ntohs(tnl_cfg.dst_port);
const char *type = netdev_get_type(dev);
- if ((!strcmp("vxlan", type) && dst_port != VXLAN_DST_PORT) ||
+ if ((!strcmp("geneve", type) && dst_port != GENEVE_DST_PORT) ||
+ (!strcmp("vxlan", type) && dst_port != VXLAN_DST_PORT) ||
(!strcmp("lisp", type) && dst_port != LISP_DST_PORT)) {
smap_add_format(args, "dst_port", "%d", dst_port);
}
void
netdev_vport_inc_rx(const struct netdev *netdev,
- const struct dpif_flow_stats *stats)
+ const struct dpif_flow_stats *stats)
{
if (is_vport_class(netdev_get_class(netdev))) {
struct netdev_vport *dev = netdev_vport_cast(netdev);
ovs_mutex_lock(&dev->mutex);
free(dev->peer);
dev->peer = xstrdup(peer);
- netdev_vport_poll_notify(dev);
+ netdev_change_seq_changed(dev_);
ovs_mutex_unlock(&dev->mutex);
return 0;
GET_CONFIG, \
SET_CONFIG, \
GET_TUNNEL_CONFIG, \
+ NULL, /* get_numa_id */ \
+ NULL, /* set_multiq */ \
\
NULL, /* send */ \
NULL, /* send_wait */ \
NULL, /* get_carrier_resets */ \
NULL, /* get_miimon */ \
get_stats, \
- NULL, /* set_stats */ \
\
NULL, /* get_features */ \
NULL, /* set_advertisements */ \
\
netdev_vport_update_flags, \
\
- netdev_vport_change_seq, \
- \
NULL, /* rx_alloc */ \
NULL, /* rx_construct */ \
NULL, /* rx_destruct */ \
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("geneve", "genev_sys"),
+ 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;