From: Ben Pfaff Date: Wed, 7 Jan 2009 01:26:12 +0000 (-0800) Subject: netdev: Make carrier status available in device flags. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=17d65262ab3239d0fc24c2299e780053ce1efe91;p=openvswitch netdev: Make carrier status available in device flags. Before, network device carrier status was available only through netdev_get_link_status(). However, Linux makes it available in network device flags, so we might as well use it. --- diff --git a/lib/netdev.c b/lib/netdev.c index efa86e80..f9b27ace 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -49,7 +50,6 @@ #include #include #include -#include #include #include #include @@ -680,31 +680,6 @@ netdev_get_mtu(const struct netdev *netdev) return netdev->mtu; } -/* Checks the link status. Returns 1 or 0 to indicate the link is active - * or not, respectively. Any other return value indicates an error. */ -int -netdev_get_link_status(const struct netdev *netdev) -{ - struct ifreq ifr; - struct ethtool_value edata; - - memset(&ifr, 0, sizeof ifr); - strncpy(ifr.ifr_name, netdev->name, sizeof ifr.ifr_name); - ifr.ifr_data = (caddr_t) &edata; - - memset(&edata, 0, sizeof edata); - edata.cmd = ETHTOOL_GLINK; - if (ioctl(netdev->netdev_fd, SIOCETHTOOL, &ifr) == 0) { - if (edata.data) { - return 1; - } else { - return 0; - } - } - - return -1; -} - /* Returns the features supported by 'netdev' of type 'type', as a bitmap * of bits from enum ofp_phy_features, in host byte order. */ uint32_t @@ -982,6 +957,9 @@ netdev_nodev_get_flags(const char *netdev_name, enum netdev_flags *flagsp) if (flags & IFF_PROMISC) { *flagsp |= NETDEV_PROMISC; } + if (flags & IFF_LOWER_UP) { + *flagsp |= NETDEV_CARRIER; + } return 0; } diff --git a/lib/netdev.h b/lib/netdev.h index 0e06e639..28d84321 100644 --- a/lib/netdev.h +++ b/lib/netdev.h @@ -57,7 +57,8 @@ enum netdev_feature_type { enum netdev_flags { NETDEV_UP = 0x0001, /* Device enabled? */ - NETDEV_PROMISC = 0x0002 /* Promiscuous mode? */ + NETDEV_PROMISC = 0x0002, /* Promiscuous mode? */ + NETDEV_CARRIER = 0x0004 /* Carrier detected? */ }; enum netdev_pseudo_ethertype { @@ -81,7 +82,6 @@ int netdev_set_etheraddr(struct netdev *, const uint8_t mac[6]); const uint8_t *netdev_get_etheraddr(const struct netdev *); const char *netdev_get_name(const struct netdev *); int netdev_get_mtu(const struct netdev *); -int netdev_get_link_status(const struct netdev *); uint32_t netdev_get_features(struct netdev *, int); bool netdev_get_in4(const struct netdev *, struct in_addr *); int netdev_set_in4(struct netdev *, struct in_addr addr, struct in_addr mask); diff --git a/udatapath/datapath.c b/udatapath/datapath.c index 8e884a43..61b5c1fd 100644 --- a/udatapath/datapath.c +++ b/udatapath/datapath.c @@ -738,22 +738,19 @@ update_port_status(struct sw_port *p) VLOG_WARN_RL(&rl, "could not get netdev flags for %s", netdev_get_name(p->netdev)); return 0; + } + + if (flags & NETDEV_UP) { + p->config &= ~OFPPC_PORT_DOWN; } else { - if (flags & NETDEV_UP) { - p->config &= ~OFPPC_PORT_DOWN; - } else { - p->config |= OFPPC_PORT_DOWN; - } + p->config |= OFPPC_PORT_DOWN; } - /* Not all cards support this getting link status, so don't warn on - * error. */ - retval = netdev_get_link_status(p->netdev); - if (retval == 1) { + if (flags & NETDEV_CARRIER) { p->state &= ~OFPPS_LINK_DOWN; - } else if (retval == 0) { + } else { p->state |= OFPPS_LINK_DOWN; - } + } return ((orig_config != p->config) || (orig_state != p->state)); }