From f25cb0ef9f6341648513e793a3162b32fc250d2b Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Thu, 11 Nov 2010 10:03:02 +0100 Subject: Implements link state detection. Also changes some symbol names (IFF_ADMIN_DOWN -> IFF_SHUTDOWN, IFF_LINK_UP -> IFF_ADMIN_UP). --- sysdep/bsd/krt-sock.c | 4 +++- sysdep/linux/netlink/netlink.c | 14 ++++++++++++-- sysdep/unix/krt-iface.c | 4 ++-- 3 files changed, 17 insertions(+), 5 deletions(-) (limited to 'sysdep') diff --git a/sysdep/bsd/krt-sock.c b/sysdep/bsd/krt-sock.c index 9ae658d..53b30ca 100644 --- a/sysdep/bsd/krt-sock.c +++ b/sysdep/bsd/krt-sock.c @@ -456,7 +456,9 @@ krt_read_ifinfo(struct ks_msg *msg) f.flags = 0; if (fl & IFF_UP) - f.flags |= IF_LINK_UP; + f.flags |= IF_ADMIN_UP; + if (ifm->ifm_data.ifi_link_state != LINK_STATE_DOWN) + f.flags |= IF_LINK_UP; /* up or unknown */ if (fl & IFF_LOOPBACK) /* Loopback */ f.flags |= IF_MULTIACCESS | IF_LOOPBACK | IF_IGNORE; else if (fl & IFF_POINTOPOINT) /* PtP */ diff --git a/sysdep/linux/netlink/netlink.c b/sysdep/linux/netlink/netlink.c index 2dd0359..79f7210 100644 --- a/sysdep/linux/netlink/netlink.c +++ b/sysdep/linux/netlink/netlink.c @@ -8,7 +8,6 @@ #include #include -#include #include #include #include @@ -27,6 +26,7 @@ #include "conf/conf.h" #include +#include #include #include @@ -34,6 +34,10 @@ #define MSG_TRUNC 0x20 #endif +#ifndef IFF_LOWER_UP +#define IFF_LOWER_UP 0x10000 +#endif + /* * Synchronous Netlink interface */ @@ -281,6 +285,8 @@ nl_parse_link(struct nlmsghdr *h, int scan) u32 mtu; unsigned int fl; + debug("nl_parse_link %d\n", new); + if (!(i = nl_checkin(h, sizeof(*i))) || !nl_parse_attrs(IFLA_RTA(i), a, sizeof(a))) return; if (!a[IFLA_IFNAME] || RTA_PAYLOAD(a[IFLA_IFNAME]) < 2 || @@ -293,6 +299,8 @@ nl_parse_link(struct nlmsghdr *h, int scan) name = RTA_DATA(a[IFLA_IFNAME]); memcpy(&mtu, RTA_DATA(a[IFLA_MTU]), sizeof(u32)); + debug("nl_parse_link name %s index %d flags %x\n", name, i->ifi_index, i->ifi_flags); + ifi = if_find_by_index(i->ifi_index); if (!new) { @@ -300,7 +308,7 @@ nl_parse_link(struct nlmsghdr *h, int scan) if (ifi && !scan) { memcpy(&f, ifi, sizeof(struct iface)); - f.flags |= IF_ADMIN_DOWN; + f.flags |= IF_SHUTDOWN; if_update(&f); } } @@ -319,6 +327,8 @@ nl_parse_link(struct nlmsghdr *h, int scan) f.flags = 0; fl = i->ifi_flags; if (fl & IFF_UP) + f.flags |= IF_ADMIN_UP; + if (fl & IFF_LOWER_UP) f.flags |= IF_LINK_UP; if (fl & IFF_LOOPBACK) /* Loopback */ f.flags |= IF_MULTIACCESS | IF_LOOPBACK | IF_IGNORE; diff --git a/sysdep/unix/krt-iface.c b/sysdep/unix/krt-iface.c index 5fda0d1..c305d27 100644 --- a/sysdep/unix/krt-iface.c +++ b/sysdep/unix/krt-iface.c @@ -78,12 +78,12 @@ scan_ifs(struct ifreq *r, int cnt) faulty: log(L_ERR "%s(%s): %m", err, i.name); bad: - i.flags = (i.flags & ~IF_LINK_UP) | IF_ADMIN_DOWN; + i.flags = (i.flags & ~IF_ADMIN_UP) | IF_SHUTDOWN; continue; } fl = r->ifr_flags; if (fl & IFF_UP) - i.flags |= IF_LINK_UP; + i.flags |= IF_ADMIN_UP; if (ioctl(if_scan_sock, SIOCGIFNETMASK, r) < 0) { err = "SIOCGIFNETMASK"; goto faulty; } -- cgit v1.2.3