Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com May 16 '13 at 12:57

This question came from our site for professional and enthusiast programmers.

    
And can't you just the UP status of the interfaces with ip link show eth0 (same for usb0)? –  ott-- May 14 '13 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 '13 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 '13 at 20:40

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.