Re: Print ifindex in ifconfig(8)

2016-04-12 Thread Martin Pieuchot
On 12/04/16(Tue) 14:43, Christian Weisgerber wrote:
> On 2016-04-12, Martin Pieuchot  wrote:
> 
> > Relying on the "scopeid" field is not a viable long-term solution.  I'm
> > spending too much time these days trying to figure out which interface
> > correspond to which index.
> 
> What's the general use case for this?  I mean apart from network
> stack hacking?

Are you asking for the index or the scopeid?

The index is clearly for debugging.  So that might fall in "network
stack hacking".  It's useless until somebody shows us with a bug
report, in which case I need a simple way to have that information.



Re: Print ifindex in ifconfig(8)

2016-04-12 Thread Sebastian Benoit
Martin Pieuchot(m...@openbsd.org) on 2016.04.12 16:25:36 +0200:
> On 12/04/16(Tue) 14:03, Stuart Henderson wrote:
> > On 2016/04/12 14:18, Claudio Jeker wrote:
> > > On Tue, Apr 12, 2016 at 01:47:53PM +0200, Stefan Sperling wrote:
> > > > On Tue, Apr 12, 2016 at 12:27:10PM +0100, Stuart Henderson wrote:
> > > > > On 2016/04/12 13:00, Martin Pieuchot wrote:
> > > > > > Relying on the "scopeid" field is not a viable long-term solution.  
> > > > > > I'm
> > > > > > spending too much time these days trying to figure out which 
> > > > > > interface
> > > > > > correspond to which index.
> > > > > > 
> > > > > > Here's a difference in output, then the diff itself.  ok?
> > > > > > 
> > > > > > @@ -1,31 +1,29 @@
> > > > > >  lo0: flags=8049 mtu 32768
> > > > > > +   index 4
> > > > > > priority: 0
> > > > > > groups: lo
> > > > > > inet6 ::1 prefixlen 128
> > > > > > inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
> > > > > > inet 127.0.0.1 netmask 0xff00
> > > > > >  em0: 
> > > > > > flags=18b43
> > > > > >  mtu 1500
> > > > > > -   lladdr f0:de:f9:1d:88:53
> > > > > > +   index 1 lladdr f0:de:f9:1d:88:53
> > > > > 
> > > > > This will break scripts, e.g. "awk '/lladdr/ {print $2}'"
> > > > > 
> > > > > I would expect putting it after lladdr would be better for the sort
> > > > > of scripts a user is likely to write, but bsd.rd would need a change
> > > > > if that was done, it uses sed 's/.*lladdr \(.*\)/\1/p;d'
> > > > > 
> > > > > On a new line would be safer.
> > > > 
> > > > How about appending to the flags line, like this?
> > > > 
> > > > lo0: flags=8049 mtu 32768 index 4
> > > > 
> > > 
> > > Or on the line with priority? The risk of breaking scripts that way is
> > > probably smaller.
> > 
> > I'd be happier with priority, the flags line can get quite long these days!
> 
> Like that?

yes, ok
(not an extra line -> ifconfig output is long enough)

> 
> em0: 
> flags=18b43 
> mtu 1500
> lladdr f1:ce:f9:1d:77:49
> index 1 priority 0
> trunk: trunkdev trunk0
> media: Ethernet autoselect (100baseTX full-duplex,rxpause,txpause)
> status: active
> 
> Index: ifconfig.c
> ===
> RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
> retrieving revision 1.319
> diff -u -p -r1.319 ifconfig.c
> --- ifconfig.c6 Apr 2016 11:48:51 -   1.319
> +++ ifconfig.c12 Apr 2016 14:25:03 -
> @@ -2929,8 +2929,14 @@ status(int link, struct sockaddr_dl *sdl
>   strlen(ifrdesc.ifr_data))
>   printf("\tdescription: %s\n", ifrdesc.ifr_data);
>  
> - if (!is_bridge(name) && ioctl(s, SIOCGIFPRIORITY, ) == 0)
> - printf("\tpriority: %d\n", ifrdesc.ifr_metric);
> + if (sdl != NULL)
> + printf("\tindex %u", sdl->sdl_index);
> + if (!is_bridge(name) && ioctl(s, SIOCGIFPRIORITY, ) == 0) {
> + printf("%cpriority %d\n", (sdl != NULL) ? ' ' : '\t',
> + ifrdesc.ifr_metric);
> + } else if (sdl != NULL) {
> + putchar('\n');
> + }
>   (void) memset(, 0, sizeof(ikardesc));
>   (void) strlcpy(ikardesc.ikar_name, name, sizeof(ikardesc.ikar_name));
>   if (ioctl(s, SIOCGETKALIVE, ) == 0 &&
> 

-- 



Re: Print ifindex in ifconfig(8)

2016-04-12 Thread Sebastian Benoit
Christian Weisgerber(na...@mips.inka.de) on 2016.04.12 14:43:50 +:
> On 2016-04-12, Martin Pieuchot  wrote:
> 
> > Relying on the "scopeid" field is not a viable long-term solution.  I'm
> > spending too much time these days trying to figure out which interface
> > correspond to which index.
> 
> What's the general use case for this?  I mean apart from network
> stack hacking?

snmp hacking ;)



Re: Print ifindex in ifconfig(8)

2016-04-12 Thread Christian Weisgerber
On 2016-04-12, Martin Pieuchot  wrote:

> Relying on the "scopeid" field is not a viable long-term solution.  I'm
> spending too much time these days trying to figure out which interface
> correspond to which index.

What's the general use case for this?  I mean apart from network
stack hacking?

(The only time I ever needed something like this was when I had to
manually embed the scope ID into v6 link-local addresses for an
application that didn't handle the %if format.)

-- 
Christian "naddy" Weisgerber  na...@mips.inka.de



Re: Print ifindex in ifconfig(8)

2016-04-12 Thread Martin Pieuchot
On 12/04/16(Tue) 14:03, Stuart Henderson wrote:
> On 2016/04/12 14:18, Claudio Jeker wrote:
> > On Tue, Apr 12, 2016 at 01:47:53PM +0200, Stefan Sperling wrote:
> > > On Tue, Apr 12, 2016 at 12:27:10PM +0100, Stuart Henderson wrote:
> > > > On 2016/04/12 13:00, Martin Pieuchot wrote:
> > > > > Relying on the "scopeid" field is not a viable long-term solution.  
> > > > > I'm
> > > > > spending too much time these days trying to figure out which interface
> > > > > correspond to which index.
> > > > > 
> > > > > Here's a difference in output, then the diff itself.  ok?
> > > > > 
> > > > > @@ -1,31 +1,29 @@
> > > > >  lo0: flags=8049 mtu 32768
> > > > > + index 4
> > > > >   priority: 0
> > > > >   groups: lo
> > > > >   inet6 ::1 prefixlen 128
> > > > >   inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
> > > > >   inet 127.0.0.1 netmask 0xff00
> > > > >  em0: 
> > > > > flags=18b43
> > > > >  mtu 1500
> > > > > - lladdr f0:de:f9:1d:88:53
> > > > > + index 1 lladdr f0:de:f9:1d:88:53
> > > > 
> > > > This will break scripts, e.g. "awk '/lladdr/ {print $2}'"
> > > > 
> > > > I would expect putting it after lladdr would be better for the sort
> > > > of scripts a user is likely to write, but bsd.rd would need a change
> > > > if that was done, it uses sed 's/.*lladdr \(.*\)/\1/p;d'
> > > > 
> > > > On a new line would be safer.
> > > 
> > > How about appending to the flags line, like this?
> > > 
> > > lo0: flags=8049 mtu 32768 index 4
> > > 
> > 
> > Or on the line with priority? The risk of breaking scripts that way is
> > probably smaller.
> 
> I'd be happier with priority, the flags line can get quite long these days!

Like that?

em0: 
flags=18b43 mtu 
1500
lladdr f1:ce:f9:1d:77:49
index 1 priority 0
trunk: trunkdev trunk0
media: Ethernet autoselect (100baseTX full-duplex,rxpause,txpause)
status: active

Index: ifconfig.c
===
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.319
diff -u -p -r1.319 ifconfig.c
--- ifconfig.c  6 Apr 2016 11:48:51 -   1.319
+++ ifconfig.c  12 Apr 2016 14:25:03 -
@@ -2929,8 +2929,14 @@ status(int link, struct sockaddr_dl *sdl
strlen(ifrdesc.ifr_data))
printf("\tdescription: %s\n", ifrdesc.ifr_data);
 
-   if (!is_bridge(name) && ioctl(s, SIOCGIFPRIORITY, ) == 0)
-   printf("\tpriority: %d\n", ifrdesc.ifr_metric);
+   if (sdl != NULL)
+   printf("\tindex %u", sdl->sdl_index);
+   if (!is_bridge(name) && ioctl(s, SIOCGIFPRIORITY, ) == 0) {
+   printf("%cpriority %d\n", (sdl != NULL) ? ' ' : '\t',
+   ifrdesc.ifr_metric);
+   } else if (sdl != NULL) {
+   putchar('\n');
+   }
(void) memset(, 0, sizeof(ikardesc));
(void) strlcpy(ikardesc.ikar_name, name, sizeof(ikardesc.ikar_name));
if (ioctl(s, SIOCGETKALIVE, ) == 0 &&



Re: Print ifindex in ifconfig(8)

2016-04-12 Thread Stuart Henderson
On 2016/04/12 14:18, Claudio Jeker wrote:
> On Tue, Apr 12, 2016 at 01:47:53PM +0200, Stefan Sperling wrote:
> > On Tue, Apr 12, 2016 at 12:27:10PM +0100, Stuart Henderson wrote:
> > > On 2016/04/12 13:00, Martin Pieuchot wrote:
> > > > Relying on the "scopeid" field is not a viable long-term solution.  I'm
> > > > spending too much time these days trying to figure out which interface
> > > > correspond to which index.
> > > > 
> > > > Here's a difference in output, then the diff itself.  ok?
> > > > 
> > > > @@ -1,31 +1,29 @@
> > > >  lo0: flags=8049 mtu 32768
> > > > +   index 4
> > > > priority: 0
> > > > groups: lo
> > > > inet6 ::1 prefixlen 128
> > > > inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
> > > > inet 127.0.0.1 netmask 0xff00
> > > >  em0: 
> > > > flags=18b43
> > > >  mtu 1500
> > > > -   lladdr f0:de:f9:1d:88:53
> > > > +   index 1 lladdr f0:de:f9:1d:88:53
> > > 
> > > This will break scripts, e.g. "awk '/lladdr/ {print $2}'"
> > > 
> > > I would expect putting it after lladdr would be better for the sort
> > > of scripts a user is likely to write, but bsd.rd would need a change
> > > if that was done, it uses sed 's/.*lladdr \(.*\)/\1/p;d'
> > > 
> > > On a new line would be safer.
> > 
> > How about appending to the flags line, like this?
> > 
> > lo0: flags=8049 mtu 32768 index 4
> > 
> 
> Or on the line with priority? The risk of breaking scripts that way is
> probably smaller.

I'd be happier with priority, the flags line can get quite long these days!

|-80-columns-ruler-|
vlan1200: 
flags=58843 mtu 
1500



Re: Print ifindex in ifconfig(8)

2016-04-12 Thread Stuart Henderson
On 2016/04/12 08:32, sven falempin wrote:
> still advocating for a structured output of system commands like ifconfig
> -json,

freebsd is > that way ;-)




Re: Print ifindex in ifconfig(8)

2016-04-12 Thread sven falempin
On Tue, Apr 12, 2016 at 8:18 AM, Claudio Jeker 
wrote:

> On Tue, Apr 12, 2016 at 01:47:53PM +0200, Stefan Sperling wrote:
> > On Tue, Apr 12, 2016 at 12:27:10PM +0100, Stuart Henderson wrote:
> > > On 2016/04/12 13:00, Martin Pieuchot wrote:
> > > > Relying on the "scopeid" field is not a viable long-term solution.
> I'm
> > > > spending too much time these days trying to figure out which
> interface
> > > > correspond to which index.
> > > >
> > > > Here's a difference in output, then the diff itself.  ok?
> > > >
> > > > @@ -1,31 +1,29 @@
> > > >  lo0: flags=8049 mtu 32768
> > > > + index 4
> > > >   priority: 0
> > > >   groups: lo
> > > >   inet6 ::1 prefixlen 128
> > > >   inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
> > > >   inet 127.0.0.1 netmask 0xff00
> > > >  em0:
> flags=18b43
> mtu 1500
> > > > - lladdr f0:de:f9:1d:88:53
> > > > + index 1 lladdr f0:de:f9:1d:88:53
> > >
> > > This will break scripts, e.g. "awk '/lladdr/ {print $2}'"
> > >
> > > I would expect putting it after lladdr would be better for the sort
> > > of scripts a user is likely to write, but bsd.rd would need a change
> > > if that was done, it uses sed 's/.*lladdr \(.*\)/\1/p;d'
> > >
> > > On a new line would be safer.
> >
> > How about appending to the flags line, like this?
> >
> > lo0: flags=8049 mtu 32768 index 4
> >
>
> Or on the line with priority? The risk of breaking scripts that way is
> probably smaller.
>
> --
> :wq Claudio
>
>
my 2 cents:

new line please, or only with an option like -vv
so you can alias it and no one see it, but you.

still advocating for a structured output of system commands like ifconfig
-json,
new scripts  would be able to manage those changes better.

-- 
-
() ascii ribbon campaign - against html e-mail
/\


Re: Print ifindex in ifconfig(8)

2016-04-12 Thread Claudio Jeker
On Tue, Apr 12, 2016 at 01:47:53PM +0200, Stefan Sperling wrote:
> On Tue, Apr 12, 2016 at 12:27:10PM +0100, Stuart Henderson wrote:
> > On 2016/04/12 13:00, Martin Pieuchot wrote:
> > > Relying on the "scopeid" field is not a viable long-term solution.  I'm
> > > spending too much time these days trying to figure out which interface
> > > correspond to which index.
> > > 
> > > Here's a difference in output, then the diff itself.  ok?
> > > 
> > > @@ -1,31 +1,29 @@
> > >  lo0: flags=8049 mtu 32768
> > > + index 4
> > >   priority: 0
> > >   groups: lo
> > >   inet6 ::1 prefixlen 128
> > >   inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
> > >   inet 127.0.0.1 netmask 0xff00
> > >  em0: 
> > > flags=18b43
> > >  mtu 1500
> > > - lladdr f0:de:f9:1d:88:53
> > > + index 1 lladdr f0:de:f9:1d:88:53
> > 
> > This will break scripts, e.g. "awk '/lladdr/ {print $2}'"
> > 
> > I would expect putting it after lladdr would be better for the sort
> > of scripts a user is likely to write, but bsd.rd would need a change
> > if that was done, it uses sed 's/.*lladdr \(.*\)/\1/p;d'
> > 
> > On a new line would be safer.
> 
> How about appending to the flags line, like this?
> 
> lo0: flags=8049 mtu 32768 index 4
> 

Or on the line with priority? The risk of breaking scripts that way is
probably smaller.

-- 
:wq Claudio



Re: Print ifindex in ifconfig(8)

2016-04-12 Thread Stefan Sperling
On Tue, Apr 12, 2016 at 12:27:10PM +0100, Stuart Henderson wrote:
> On 2016/04/12 13:00, Martin Pieuchot wrote:
> > Relying on the "scopeid" field is not a viable long-term solution.  I'm
> > spending too much time these days trying to figure out which interface
> > correspond to which index.
> > 
> > Here's a difference in output, then the diff itself.  ok?
> > 
> > @@ -1,31 +1,29 @@
> >  lo0: flags=8049 mtu 32768
> > +   index 4
> > priority: 0
> > groups: lo
> > inet6 ::1 prefixlen 128
> > inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
> > inet 127.0.0.1 netmask 0xff00
> >  em0: 
> > flags=18b43 
> > mtu 1500
> > -   lladdr f0:de:f9:1d:88:53
> > +   index 1 lladdr f0:de:f9:1d:88:53
> 
> This will break scripts, e.g. "awk '/lladdr/ {print $2}'"
> 
> I would expect putting it after lladdr would be better for the sort
> of scripts a user is likely to write, but bsd.rd would need a change
> if that was done, it uses sed 's/.*lladdr \(.*\)/\1/p;d'
> 
> On a new line would be safer.

How about appending to the flags line, like this?

lo0: flags=8049 mtu 32768 index 4



Re: Print ifindex in ifconfig(8)

2016-04-12 Thread Stuart Henderson
On 2016/04/12 13:00, Martin Pieuchot wrote:
> Relying on the "scopeid" field is not a viable long-term solution.  I'm
> spending too much time these days trying to figure out which interface
> correspond to which index.
> 
> Here's a difference in output, then the diff itself.  ok?
> 
> @@ -1,31 +1,29 @@
>  lo0: flags=8049 mtu 32768
> + index 4
>   priority: 0
>   groups: lo
>   inet6 ::1 prefixlen 128
>   inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
>   inet 127.0.0.1 netmask 0xff00
>  em0: 
> flags=18b43 
> mtu 1500
> - lladdr f0:de:f9:1d:88:53
> + index 1 lladdr f0:de:f9:1d:88:53

This will break scripts, e.g. "awk '/lladdr/ {print $2}'"

I would expect putting it after lladdr would be better for the sort
of scripts a user is likely to write, but bsd.rd would need a change
if that was done, it uses sed 's/.*lladdr \(.*\)/\1/p;d'

On a new line would be safer.

>   priority: 0
>   trunk: trunkdev trunk0
>   media: Ethernet autoselect (100baseTX full-duplex,rxpause,txpause)
>   status: active
>  iwn0: flags=8943 mtu 1500
> - lladdr f0:de:f9:1d:88:53
> + index 2 lladdr f0:de:f9:1d:88:53
>   priority: 4
>   trunk: trunkdev trunk0
>   groups: wlan
>   media: IEEE802.11 autoselect (HT-MCS6 mode 11n)
>   status: active
>  enc0: flags=0<>
> + index 3
>   priority: 0
>   groups: enc
>   status: active
>  trunk0: flags=8843 mtu 1500
> - lladdr f0:de:f9:1d:88:53
> + index 5 lladdr f0:de:f9:1d:88:53
>   priority: 0
>   trunk: trunkproto failover
>   trunkport iwn0 
> @@ -35,13 +33,12 @@
>   status: active
>   inet 192.168.178.68 netmask 0xff00 broadcast 192.168.178.255
>  tap0: flags=8843 mtu 1500
> - lladdr fe:e1:ba:d0:d4:e7
> + index 6 lladdr fe:e1:ba:d0:d4:e7
>   priority: 0
>   groups: tap
>   status: no carrier
>   inet 172.172.0.1 netmask 0x broadcast 172.172.255.255
>   inet6 fe80::fce1:baff:fed0:d4e7%tap0 prefixlen 64 scopeid 0x6
>  pflog0: flags=141 mtu 33144
> + index 7
>   priority: 0
>   groups: pflog
> 
> Index: ifconfig.c
> ===
> RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
> retrieving revision 1.319
> diff -u -p -r1.319 ifconfig.c
> --- ifconfig.c6 Apr 2016 11:48:51 -   1.319
> +++ ifconfig.c12 Apr 2016 10:52:51 -
> @@ -2916,11 +2916,16 @@ status(int link, struct sockaddr_dl *sdl
>   if (showcapsflag)
>   printifhwfeatures(NULL, 1);
>  #endif
> - if (sdl != NULL && sdl->sdl_alen &&
> - (sdl->sdl_type == IFT_ETHER || sdl->sdl_type == IFT_CARP))
> - (void)printf("\tlladdr %s\n", ether_ntoa(
> - (struct ether_addr *)LLADDR(sdl)));
> -
> + if (sdl != NULL) {
> + printf("\tindex %u", sdl->sdl_index);
> + if ((sdl->sdl_alen > 0) &&
> + (sdl->sdl_type == IFT_ETHER || sdl->sdl_type == IFT_CARP)) {
> + printf(" lladdr %s",
> + ether_ntoa((struct ether_addr *)LLADDR(sdl)),
> + sdl->sdl_index);
> + }
> + printf("\n");
> + }
>  #ifndef SMALL
>   (void) memset(, 0, sizeof(ifrdesc));
>   (void) strlcpy(ifrdesc.ifr_name, name, sizeof(ifrdesc.ifr_name));
> 



Print ifindex in ifconfig(8)

2016-04-12 Thread Martin Pieuchot
Relying on the "scopeid" field is not a viable long-term solution.  I'm
spending too much time these days trying to figure out which interface
correspond to which index.

Here's a difference in output, then the diff itself.  ok?

@@ -1,31 +1,29 @@
 lo0: flags=8049 mtu 32768
+   index 4
priority: 0
groups: lo
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x4
inet 127.0.0.1 netmask 0xff00
 em0: 
flags=18b43 mtu 
1500
-   lladdr f0:de:f9:1d:88:53
+   index 1 lladdr f0:de:f9:1d:88:53
priority: 0
trunk: trunkdev trunk0
media: Ethernet autoselect (100baseTX full-duplex,rxpause,txpause)
status: active
 iwn0: flags=8943 mtu 1500
-   lladdr f0:de:f9:1d:88:53
+   index 2 lladdr f0:de:f9:1d:88:53
priority: 4
trunk: trunkdev trunk0
groups: wlan
media: IEEE802.11 autoselect (HT-MCS6 mode 11n)
status: active
 enc0: flags=0<>
+   index 3
priority: 0
groups: enc
status: active
 trunk0: flags=8843 mtu 1500
-   lladdr f0:de:f9:1d:88:53
+   index 5 lladdr f0:de:f9:1d:88:53
priority: 0
trunk: trunkproto failover
trunkport iwn0 
@@ -35,13 +33,12 @@
status: active
inet 192.168.178.68 netmask 0xff00 broadcast 192.168.178.255
 tap0: flags=8843 mtu 1500
-   lladdr fe:e1:ba:d0:d4:e7
+   index 6 lladdr fe:e1:ba:d0:d4:e7
priority: 0
groups: tap
status: no carrier
inet 172.172.0.1 netmask 0x broadcast 172.172.255.255
inet6 fe80::fce1:baff:fed0:d4e7%tap0 prefixlen 64 scopeid 0x6
 pflog0: flags=141 mtu 33144
+   index 7
priority: 0
groups: pflog

Index: ifconfig.c
===
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.319
diff -u -p -r1.319 ifconfig.c
--- ifconfig.c  6 Apr 2016 11:48:51 -   1.319
+++ ifconfig.c  12 Apr 2016 10:52:51 -
@@ -2916,11 +2916,16 @@ status(int link, struct sockaddr_dl *sdl
if (showcapsflag)
printifhwfeatures(NULL, 1);
 #endif
-   if (sdl != NULL && sdl->sdl_alen &&
-   (sdl->sdl_type == IFT_ETHER || sdl->sdl_type == IFT_CARP))
-   (void)printf("\tlladdr %s\n", ether_ntoa(
-   (struct ether_addr *)LLADDR(sdl)));
-
+   if (sdl != NULL) {
+   printf("\tindex %u", sdl->sdl_index);
+   if ((sdl->sdl_alen > 0) &&
+   (sdl->sdl_type == IFT_ETHER || sdl->sdl_type == IFT_CARP)) {
+   printf(" lladdr %s",
+   ether_ntoa((struct ether_addr *)LLADDR(sdl)),
+   sdl->sdl_index);
+   }
+   printf("\n");
+   }
 #ifndef SMALL
(void) memset(, 0, sizeof(ifrdesc));
(void) strlcpy(ifrdesc.ifr_name, name, sizeof(ifrdesc.ifr_name));