X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fnetdev-vport.c;h=c214bf7132e9327fb64507d5a460bbd4774f10bb;hb=41ca1e0afb4b261a217c9fdaf672ef606e8434f9;hp=07b2381cc4457f3a37974d62da7cb0a013aea6ac;hpb=a6363cfddb91620c9325e2812ae5af96a8d7f127;p=sliver-openvswitch.git diff --git a/lib/netdev-vport.c b/lib/netdev-vport.c index 07b2381cc..c214bf713 100644 --- a/lib/netdev-vport.c +++ b/lib/netdev-vport.c @@ -34,6 +34,7 @@ #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" @@ -52,12 +53,13 @@ struct netdev_vport { /* 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; @@ -68,11 +70,13 @@ struct vport_class { 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_changed(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) @@ -80,6 +84,12 @@ 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) { @@ -167,6 +177,34 @@ netdev_vport_get_dpif_port_strdup(const struct netdev *netdev) 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_); + } + } + netdev_close(netdev_); + ovs_mutex_unlock(&netdev->mutex); + } + + free(vports); +} + static struct netdev * netdev_vport_alloc(void) { @@ -180,7 +218,6 @@ netdev_vport_construct(struct netdev *netdev_) 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(); @@ -213,8 +250,8 @@ netdev_vport_set_etheraddr(struct netdev *netdev_, ovs_mutex_lock(&netdev->mutex); memcpy(netdev->etheraddr, mac, ETH_ADDR_LEN); - netdev_vport_changed(netdev); ovs_mutex_unlock(&netdev->mutex); + netdev_change_seq_changed(netdev_); return 0; } @@ -232,29 +269,50 @@ netdev_vport_get_etheraddr(const struct netdev *netdev_, 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; } @@ -272,32 +330,28 @@ netdev_vport_update_flags(struct netdev *netdev OVS_UNUSED, 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(); -} - -/* Helper functions. */ + uint64_t seq; -static void -netdev_vport_changed(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(); } } @@ -452,6 +506,7 @@ set_tunnel_config(struct netdev *dev_, const struct smap *args) 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(), @@ -460,6 +515,7 @@ set_tunnel_config(struct netdev *dev_, const struct smap *args) free(file_name); } ovs_mutex_unlock(&mutex); +#endif if (pid < 0) { VLOG_ERR("%s: IPsec requires the ovs-monitor-ipsec daemon", @@ -503,7 +559,8 @@ set_tunnel_config(struct netdev *dev_, const struct smap *args) ovs_mutex_lock(&dev->mutex); dev->tnl_cfg = tnl_cfg; - netdev_vport_changed(dev); + tunnel_check_status_change__(dev); + netdev_change_seq_changed(dev_); ovs_mutex_unlock(&dev->mutex); return 0; @@ -677,7 +734,7 @@ set_patch_config(struct netdev *dev_, const struct smap *args) ovs_mutex_lock(&dev->mutex); free(dev->peer); dev->peer = xstrdup(peer); - netdev_vport_changed(dev); + netdev_change_seq_changed(dev_); ovs_mutex_unlock(&dev->mutex); return 0; @@ -750,8 +807,6 @@ get_stats(const struct netdev *netdev, struct netdev_stats *stats) \ netdev_vport_update_flags, \ \ - netdev_vport_change_seq, \ - \ NULL, /* rx_alloc */ \ NULL, /* rx_construct */ \ NULL, /* rx_destruct */ \