#include <fcntl.h>
#include <arpa/inet.h>
#include <inttypes.h>
+#include <linux/if.h>
#include <linux/if_tun.h>
#include <linux/types.h>
#include <linux/ethtool.h>
#include <sys/socket.h>
#include <netpacket/packet.h>
#include <net/ethernet.h>
-#include <net/if.h>
#include <net/if_arp.h>
#include <net/if_packet.h>
#include <net/route.h>
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
if (flags & IFF_PROMISC) {
*flagsp |= NETDEV_PROMISC;
}
+ if (flags & IFF_LOWER_UP) {
+ *flagsp |= NETDEV_CARRIER;
+ }
return 0;
}
\f
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 {
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);
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));
}