int init_bridge_ops(void);
-int bridge_notify(int br_index, int if_index, bool newlink, bool up);
+int bridge_notify(int br_index, int if_index, bool newlink, unsigned flags);
void bridge_bpdu_rcv(int ifindex, const unsigned char *data, int len);
}
/* br_index == if_index means: interface is bridge master */
-int bridge_notify(int br_index, int if_index, bool newlink, bool up)
+int bridge_notify(int br_index, int if_index, bool newlink, unsigned flags)
{
port_t *ifc;
bridge_t *br = NULL, *other_br;
+ bool up = !!(flags & IFF_UP);
+ bool running = up && (flags & IFF_RUNNING);
- LOG("br_index %d, if_index %d, newlink %d, up %d",
- br_index, if_index, newlink, up);
+ LOG("br_index %d, if_index %d, newlink %d, up %d, running %d",
+ br_index, if_index, newlink, up, running);
if((br_index >= 0) && (br_index != if_index))
{
ERROR("Couldn't create data for bridge interface %d", br_index);
return -1;
}
- int br_up = ethtool_get_link(br->sysdeps.name);
- if(br_up >= 0)
- set_br_up(br, !!br_up);
+ int br_flags = get_flags(br->sysdeps.name);
+ if(br_flags >= 0)
+ set_br_up(br, !!(flags & IFF_UP));
}
if(br)
delete_if(ifc);
return 0;
}
- set_if_up(ifc, up); /* And speed and duplex */
+ set_if_up(ifc, running); /* And speed and duplex */
}
else
{ /* Interface is not a bridge slave */
int len = n->nlmsg_len;
char b1[IFNAMSIZ];
int af_family = ifi->ifi_family;
- bool newlink, up;
+ bool newlink;
int br_index;
if(n->nlmsg_type == NLMSG_DONE)
fflush(fp);
newlink = (n->nlmsg_type == RTM_NEWLINK);
- up = false;
- if(newlink && tb[IFLA_OPERSTATE])
- {
- int state = *(uint8_t*)RTA_DATA(tb[IFLA_OPERSTATE]);
- up = (state == IF_OPER_UP) || (state == IF_OPER_UNKNOWN);
- }
if(tb[IFLA_MASTER])
br_index = *(int*)RTA_DATA(tb[IFLA_MASTER]);
else
br_index = -1;
- bridge_notify(br_index, ifi->ifi_index, newlink, up);
+ bridge_notify(br_index, ifi->ifi_index, newlink, ifi->ifi_flags);
return 0;
}
return 0;
}
-int ethtool_get_link(char *ifname)
+int get_flags(char *ifname)
{
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
- struct ethtool_value eval;
-
- eval.cmd = ETHTOOL_GLINK;
- ifr.ifr_data = (caddr_t)&eval;
- if(0 > ioctl(netsock, SIOCETHTOOL, &ifr))
+ if(0 > ioctl(netsock, SIOCGIFFLAGS, &ifr))
{
- ERROR("Cannot get link status for %s: %m\n", ifname);
+ ERROR("%s: get interface flags failed: %m", ifname);
return -1;
}
- if(eval.data)
- return 1;
- return 0;
+ return ifr.ifr_flags;
}
int ethtool_get_speed_duplex(char *ifname, int *speed, int *duplex)
int netsock_init(void);
int get_hwaddr(char *ifname, unsigned char *hwaddr);
+int get_flags(char *ifname);
int ethtool_get_speed_duplex(char *ifname, int *speed, int *duplex);
-int ethtool_get_link(char *ifname);
bool is_bridge(char *if_name);