Skip to contentSkip to conversation

getting a list of naked interface names from iproute2

DISCUSSION Matthew Thode 3 participants 4 messages Feb 17, 2015 – Feb 18, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

iproute2 seems to like to add @ and : info to it's output. This makes parsing it hard for things like neutron (openstack). I have a patch to slightly update it (still missing some things, I'll link it at the end if interested). Is there a better way of getting interface names from iproute2 without having to strip out at characters like '@' and ':'?

changeset in neutron: https://review.openstack.org/#/c/154128/
link to current code:
https://github.com/openstack/neutron/blob/master/neutron/agent/linux/ip_lib.py#L110-L131

I'd appreciate your help, I'd rather not have to go through each link type to pull it's delimiter, but if needed I guess it's needed.

Signature · 1 line
Matthew Thode
#1 lore raw
Quoted 6 lines · On Mon, 16 Feb 2015 18:07:12 -0600 Matthew Thode <[email protected]> wrote:

iproute2 seems to like to add @ and : info to it's output. This makes parsing it hard for things like neutron (openstack). I have a patch to slightly update it (still missing some things, I'll link it at the end if interested). Is there a better way of getting interface names from iproute2 without having to strip out at characters like '@' and ':'?

Quoted 7 lines

changeset in neutron: https://review.openstack.org/#/c/154128/
link to current code:
https://github.com/openstack/neutron/blob/master/neutron/agent/linux/ip_lib.py#L110-L131

I'd appreciate your help, I'd rather not have to go through each link type to pull it's delimiter, but if needed I guess it's needed.

Stop screenscraping, and use a real API.
All of the above would work better:
1. Libc if_nameindex
2. Legacy ioctl(SIOCGIFCONF)
3. Netlink NLMMSG_REQ (RTM_GETLINK)
4. Sysfs /sys/class/net

#2 lore raw
Quoted 17 lines · Stephen Hemminger
Quoted 6 lines · On Mon, 16 Feb 2015 18:07:12 -0600 Matthew Thode <[email protected]> wrote:

iproute2 seems to like to add @ and : info to it's output. This makes parsing it hard for things like neutron (openstack). I have a patch to slightly update it (still missing some things, I'll link it at the end if interested). Is there a better way of getting interface names from iproute2 without having to strip out at characters like '@' and ':'?

Quoted 7 lines

changeset in neutron: https://review.openstack.org/#/c/154128/
link to current code:
https://github.com/openstack/neutron/blob/master/neutron/agent/linux/ip_lib.py#L110-L131

I'd appreciate your help, I'd rather not have to go through each link type to pull it's delimiter, but if needed I guess it's needed.

Quoted 7 lines

Stop screenscraping, and use a real API.
All of the above would work better:
1. Libc if_nameindex
2. Legacy ioctl(SIOCGIFCONF)
3. Netlink NLMMSG_REQ (RTM_GETLINK)
4. Sysfs /sys/class/net

Do you happen to know a way to request it for a specific namespace? going over the links in /sys/class/net only gets you the current namespace (was the easiest method to do in python2.7).

Signature · 1 line
Matthew Thode
#3 lore raw
Quoted 3 lines · Matthew Thode

Do you happen to know a way to request it for a specific namespace? going over the links in /sys/class/net only gets you the current namespace (was the easiest method to do in python2.7).

The interface is not friendly. You need to open an fd which points to the netns proc file or the pid of a task inside the namespace, take a look at how ip netns exec is implemented.