0

I have a board. This board have two interfaces one eth0 and other usb0. eth0 port is connected with network. and usb0 port is connected to another device With the help of bridge-utils, I am able to set up a software bridge(br0) over the board with eth0 and usb0 as its elements. Now my problem is if usb0 side is down or not running, then is there any way to know that usb0 side is down or not working or not running?

I tried using SIOCGIFCONF ioctl command and SIOCGIFFLAGS(IFF_UP and IFF_RUNNING) to know whether any interface is down or not running. But with SIOCGIFCONF I am getting information about only one interface br0 and not about usb0 or eth0, and br0 is up and working and running.

Any suggestions would be appreciated.

3
  • And can't you just the UP status of the interfaces with ip link show eth0 (same for usb0)?
    – ott--
    May 14, 2013 at 15:49
  • Output of ip link show usb0 when usb0 is not running: # ip link show usb0 2: usb0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast master br0 qlen 1000 link/ether c6:df:ac:7a:e0:5d brd ff:ff:ff:ff:ff:ff So with <NO-CARRIER>, ip link is showing that usb0 side is not running. That's ok. Now my problem is why SIOCGIFCONF ioctl command is not showing all usb0, eth0, br0 interfaces. Why is this ioctl call is only listing only br0 interface. because if it won't list usb0 then i can't diagnose status of usb0. Do i need to use any other ioctl call or some other method.
    – user2311046
    May 15, 2013 at 7:36
  • That ioctl() is obviously no help in that case. I'd suggest a script that extracts the interfaces from a brctl show and then queries every interface.
    – ott--
    May 15, 2013 at 20:40

1 Answer 1

0

I think using sysfs filesystem state of usb0 could be detected.

Today i saw the source code of bride-utilities, where i found that brctl show command gathers information about its interfaces using sysfs(sys/class/net/br0/brif/) filesystem.

So, i traversed through that sysfs filesystem and checked the value in /sys/class/net/br0/brif/usb0/state file. When usb0 interface is running, in that case the output of

/ # cat /sys/class/net/br0/brif/usb0/state
    3

In case the usb0 interface is not running, then :

/ # cat /sys/class/net/br0/brif/usb0/state
    0

So, now i could know the status of usb0 interface which is part of br0 bridge by analyzing the value of /sys/class/net/br0/brif/usb0/state file.

Now i have following ways to know the status of usb0 interface:

1.Continuously poll this .../state file value and then take a decision(I don't like this idea).

2.Open a netlink socket and listen to the RTMGRP_LINK (network interface create/delete/up/down events) multicast groups and then with the kernel notification i could determine the state of usb0.

3.Using udev:http://www.signal11.us/oss/udev/ (libudev - Monitoring Interface) we could monitor the state change event notification and then act.

I am trying using udev. And will try to post complete solution after i implement it.

You must log in to answer this question.