Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Attn: Aragorn - Network Interface Question

130 views
Skip to first unread message

Wildman

unread,
Dec 16, 2016, 11:07:25 PM12/16/16
to
With your knowledge of the underbelly of Linux, I was hoping
you will be able to answer a question for me.

For a project I am working on, I want to replicate this in
Python: ip -s link show eth0

I have most of it worked out by using the info found here:
/sys/class/net/eth0/ and this file: /proc/net/dev.

There is one thing I cannot figure out and that has to do
with the interface flags. When I use the 'ip' command
above, I get this for the flags:
BROADCAST, MULTICAST, UP, LOWER_UP

If I do 'cat /sys/class/net/eth0/flags' I get 0x1003 which
translates to UP(bit0), BROADCAST(bit1), MULTICAST(bit12).
LOWER_UP is not included.

In the kernel source the flags are declared here:
include/uapi/linux/if.h

Below are the declares form the source and as you can see
IFF_LOWER_UP is in the 'extended' flags using bit 16. The
flags file I believe is 16 bits (0 to 15). At least the
extended bits are not stored there on my system. So my
question is, where are the extended flag bits stored?
Any ideas? Maybe in one of the other files found in
/sys/class/net/eth0/ that is using a cryptic name?

79 IFF_UP = 1<<0, /* sysfs */
80 IFF_BROADCAST = 1<<1, /* volatile */
81 IFF_DEBUG = 1<<2, /* sysfs */
82 IFF_LOOPBACK = 1<<3, /* volatile */
83 IFF_POINTOPOINT = 1<<4, /* volatile */
84 IFF_NOTRAILERS = 1<<5, /* sysfs */
85 IFF_RUNNING = 1<<6, /* volatile */
86 IFF_NOARP = 1<<7, /* sysfs */
87 IFF_PROMISC = 1<<8, /* sysfs */
88 IFF_ALLMULTI = 1<<9, /* sysfs */
89 IFF_MASTER = 1<<10, /* volatile */
90 IFF_SLAVE = 1<<11, /* volatile */
91 IFF_MULTICAST = 1<<12, /* sysfs */
92 IFF_PORTSEL = 1<<13, /* sysfs */
93 IFF_AUTOMEDIA = 1<<14, /* sysfs */
94 IFF_DYNAMIC = 1<<15, /* sysfs */
.
.
97 IFF_LOWER_UP = 1<<16, /* volatile */
98 IFF_DORMANT = 1<<17, /* volatile */
99 IFF_ECHO = 1<<18, /* volatile */

--
<Wildman> GNU/Linux user #557453
The cow died so I don't need your bull!

Aragorn

unread,
Dec 17, 2016, 8:27:09 AM12/17/16
to
On Saturday 17 December 2016 05:07, Wildman conveyed the following to
alt.os.linux...

> With your knowledge of the underbelly of Linux, I was hoping
> you will be able to answer a question for me.

Well, I am flattered that you think so highly of my expertise, but I'm
afraid this particular area is way out of my league. :-/

> For a project I am working on, I want to replicate this in
> Python: ip -s link show eth0
>
> I have most of it worked out by using the info found here:
> /sys/class/net/eth0/ and this file: /proc/net/dev.
>
> There is one thing I cannot figure out and that has to do
> with the interface flags. When I use the 'ip' command
> above, I get this for the flags:
> BROADCAST, MULTICAST, UP, LOWER_UP
>
> If I do 'cat /sys/class/net/eth0/flags' I get 0x1003 which
> translates to UP(bit0), BROADCAST(bit1), MULTICAST(bit12).
> LOWER_UP is not included.
>
> In the kernel source the flags are declared here:
> include/uapi/linux/if.h
>
> Below are the declares form the source and as you can see
> IFF_LOWER_UP is in the 'extended' flags using bit 16. The
> flags file I believe is 16 bits (0 to 15).

Well, I don't know whether the flags file ─ which, as everything under
/sys, is only a pseudofile, but I'm guessing you know that already ─
only covers 16 bits, but the hexadecimal number 0x1003 translates to a
13 bit value.
Like I said, this is out of my league, but my guess from the above would
be that the bits commented as "volatile" are not exported via sysfs.
Maybe they are stored in a socket file instead?

Maybe one of the real gurus can jump in? :-/

--
= Aragorn =

Wildman

unread,
Dec 17, 2016, 12:07:57 PM12/17/16
to
On Sat, 17 Dec 2016 14:27:07 +0100, Aragorn wrote:

> On Saturday 17 December 2016 05:07, Wildman conveyed the following to
> alt.os.linux...
>
>> With your knowledge of the underbelly of Linux, I was hoping
>> you will be able to answer a question for me.
>
> Well, I am flattered that you think so highly of my expertise, but I'm
> afraid this particular area is way out of my league. :-/

Oh well, it was worth a shot.

>> For a project I am working on, I want to replicate this in
>> Python: ip -s link show eth0
>>
>> I have most of it worked out by using the info found here:
>> /sys/class/net/eth0/ and this file: /proc/net/dev.
>>
>> There is one thing I cannot figure out and that has to do
>> with the interface flags. When I use the 'ip' command
>> above, I get this for the flags:
>> BROADCAST, MULTICAST, UP, LOWER_UP
>>
>> If I do 'cat /sys/class/net/eth0/flags' I get 0x1003 which
>> translates to UP(bit0), BROADCAST(bit1), MULTICAST(bit12).
>> LOWER_UP is not included.
>>
>> In the kernel source the flags are declared here:
>> include/uapi/linux/if.h
>>
>> Below are the declares form the source and as you can see
>> IFF_LOWER_UP is in the 'extended' flags using bit 16. The
>> flags file I believe is 16 bits (0 to 15).
>
> Well, I don't know whether the flags file ─ which, as everything under
> /sys, is only a pseudofile, but I'm guessing you know that already ─
> only covers 16 bits, but the hexadecimal number 0x1003 translates to a
> 13 bit value.

I should have said 'up to 16 bits'. And yes I knew it was
a pseudofile.
A socket file? Hmmm, something to look into.

> Maybe one of the real gurus can jump in? :-/

Thanks for the reply. Maybe Bit or Jonathan will chime in.

Bit Twister

unread,
Dec 17, 2016, 12:22:49 PM12/17/16
to
On Sat, 17 Dec 2016 11:07:50 -0600, Wildman wrote:
>
> Thanks for the reply. Maybe Bit or Jonathan will chime in.

I doubt if Bit will. He has given up bit twiddling whenever possible.

He has added root's PATH to his PATH, so he can run root apps to get
the same information. If an app needs root privs for data access he
clicks the xroot desktop shortcut to jump to desktop number 5, pop up
an xterm -fg black -bg SkyBlue3 with root automagically logged in. :)

marrgol

unread,
Dec 17, 2016, 1:37:39 PM12/17/16
to
On 2016-12-17 at 05:07, Wildman wrote:
> If I do 'cat /sys/class/net/eth0/flags' I get 0x1003 which
> translates to UP(bit0), BROADCAST(bit1), MULTICAST(bit12).
> LOWER_UP is not included.
> […]
> So my question is, where are the extended flag bits stored?
> Any ideas? Maybe in one of the other files found in
> /sys/class/net/eth0/ that is using a cryptic name?
> […]
> 97 IFF_LOWER_UP = 1<<16, /* volatile */
> 98 IFF_DORMANT = 1<<17, /* volatile */

These two are stored as single flags in /sys/class/net/eth0/carrier
and /sys/class/net/eth0/dormant respectively.


--
mrg

Wildman

unread,
Dec 17, 2016, 1:51:15 PM12/17/16
to
That is exactly what I wanted to know. I suspected it was
'carrier' but I could not confirm it. Thank you.

Do you happen to know anything about IFF_ECHO?

Theo

unread,
Dec 17, 2016, 4:52:24 PM12/17/16
to
Wildman <best...@yahoo.com> wrote:
> That is exactly what I wanted to know. I suspected it was
> 'carrier' but I could not confirm it. Thank you.
>
> Do you happen to know anything about IFF_ECHO?

I can't help feeling that using sysfs is a recipe for breakage when they
decide to change the layout for some reason.

Seems to me that it would be safer to use the ioctls:
http://stackoverflow.com/questions/4951257/using-c-code-to-get-same-info-as-ifconfig

Theo

marrgol

unread,
Dec 17, 2016, 7:45:36 PM12/17/16
to
On 2016-12-17 at 19:51, Wildman wrote:
> Do you happen to know anything about IFF_ECHO?

AFAICR typical network device drivers do not use this flag,
CAN network device drivers do.

I think you can probably find all this in the Documentation/networking
directory of the kernel sources…


--
mrg
0 new messages