Re: shorten ifconfig output for vnetids and parent interfaces
On Mon, May 29, 2017 at 03:34:51PM +1000, David Gwynne wrote: > this rolls vnetid and parent into a single encap line in ifconfig. > > eg: > > - vnetid: 7 > - parent: ix1 > + encap: vnetid: 7 parent: ix1 > > after this i would like to get rid of the vlan compat goo. how about this one? it fixes some whitespace issues and avoids extra colons. the above now looks like: encap: vnetid 7 parent ix1 ok? Index: ifconfig.c === RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v retrieving revision 1.340 diff -u -p -r1.340 ifconfig.c --- ifconfig.c 21 Mar 2017 07:24:36 - 1.340 +++ ifconfig.c 31 May 2017 04:05:40 - @@ -153,6 +153,8 @@ int shownet80211chans; intshownet80211nodes; intshowclasses; +struct ifencap; + void notealias(const char *, int); void setifaddr(const char *, int); void setifrtlabel(const char *, int); @@ -186,10 +188,11 @@ void settunnelinst(const char *, int); void settunnelttl(const char *, int); void setvnetid(const char *, int); void delvnetid(const char *, int); -void getvnetid(void); +void getvnetid(struct ifencap *); void setifparent(const char *, int); void delifparent(const char *, int); -void getifparent(void); +void getifparent(struct ifencap *); +void getencap(void); void setia6flags(const char *, int); void setia6pltime(const char *, int); void setia6vltime(const char *, int); @@ -2999,8 +3002,7 @@ status(int link, struct sockaddr_dl *sdl printf("\tpatch: %s\n", ifname); #endif vlan_status(); - getvnetid(); - getifparent(); + getencap(); #ifndef SMALL carp_status(); pfsync_status(); @@ -3617,6 +3619,22 @@ setmpwcontrolword(const char *value, int } #endif /* SMALL */ +struct ifencap { + unsigned int ife_flags; +#define IFE_VNETID_MASK0xf +#define IFE_VNETID_NOPE0x0 +#define IFE_VNETID_NONE0x1 +#define IFE_VNETID_ANY 0x2 +#define IFE_VNETID_SET 0x3 + int64_t ife_vnetid; + +#define IFE_PARENT_MASK0xf0 +#define IFE_PARENT_NOPE0x00 +#define IFE_PARENT_NONE0x10 +#define IFE_PARENT_SET 0x20 + charife_parent[IFNAMSIZ]; +}; + void setvnetid(const char *id, int param) { @@ -3647,7 +3665,7 @@ delvnetid(const char *ignored, int alsoi } void -getvnetid(void) +getvnetid(struct ifencap *ife) { if (strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)) >= sizeof(ifr.ifr_name)) @@ -3657,17 +3675,17 @@ getvnetid(void) if (errno != EADDRNOTAVAIL) return; - printf("\tvnetid: none\n"); - + ife->ife_flags |= IFE_VNETID_NONE; return; } if (ifr.ifr_vnetid < 0) { - printf("\tvnetid: any\n"); + ife->ife_flags |= IFE_VNETID_ANY; return; } - printf("\tvnetid: %lld\n", ifr.ifr_vnetid); + ife->ife_flags |= IFE_VNETID_SET; + ife->ife_vnetid = ifr.ifr_vnetid; } void @@ -3696,10 +3714,9 @@ delifparent(const char *ignored, int als } void -getifparent(void) +getifparent(struct ifencap *ife) { struct if_parent ifp; - const char *parent = "none"; memset(&ifp, 0, sizeof(ifp)); if (strlcpy(ifp.ifp_name, name, sizeof(ifp.ifp_name)) >= @@ -3709,10 +3726,50 @@ getifparent(void) if (ioctl(s, SIOCGIFPARENT, (caddr_t)&ifp) == -1) { if (errno != EADDRNOTAVAIL) return; - } else - parent = ifp.ifp_parent; - printf("\tparent: %s\n", parent); + ife->ife_flags |= IFE_PARENT_NONE; + } else { + memcpy(ife->ife_parent, ifp.ifp_parent, + sizeof(ife->ife_parent)); + ife->ife_flags |= IFE_PARENT_SET; + } +} + +void +getencap(void) +{ + struct ifencap ife = { .ife_flags = 0 }; + + getvnetid(&ife); + getifparent(&ife); + + if (ife.ife_flags == 0) + return; + + printf("\tencap:"); + + switch (ife.ife_flags & IFE_VNETID_MASK) { + case IFE_VNETID_NONE: + printf(" vnetid none"); + break; + case IFE_VNETID_ANY: + printf(" vnetid any"); + break; + case IFE_VNETID_SET: + printf(" vnetid %lld", ife.ife_vnetid); + break; + } + + switch (ife.ife_flags & IFE_PARENT_MASK) { + case IFE_PARENT_NONE: + printf(" parent none"); + break; + case IFE_PARENT_SET: + printf(" parent %s", ife.ife_parent); + break; + } + + printf("\n"); } static int __tag = 0;
Re: shorten ifconfig output for vnetids and parent interfaces
> > - vnetid: 7 > > - parent: ix1 > > + encap: vnetid: 7 parent: ix1 > >=20 > > The repeated colons for keys after encap: are unusual for ifconfig output, c= > ould you just skip them like the following: > > encap: vnetid 7 parent ix1 true
Re: shorten ifconfig output for vnetids and parent interfaces
> Am 29.05.2017 um 07:34 schrieb David Gwynne : > > this rolls vnetid and parent into a single encap line in ifconfig. > > eg: > > - vnetid: 7 > - parent: ix1 > + encap: vnetid: 7 parent: ix1 > The repeated colons for keys after encap: are unusual for ifconfig output, could you just skip them like the following: encap: vnetid 7 parent ix1 Reyk > after this i would like to get rid of the vlan compat goo. > > ok? > > Index: ifconfig.c > === > RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v > retrieving revision 1.340 > diff -u -p -r1.340 ifconfig.c > --- ifconfig.c21 Mar 2017 07:24:36 -1.340 > +++ ifconfig.c29 May 2017 03:29:09 - > @@ -153,6 +153,8 @@ intshownet80211chans; > intshownet80211nodes; > intshowclasses; > > +struct ifencap; > + > voidnotealias(const char *, int); > voidsetifaddr(const char *, int); > voidsetifrtlabel(const char *, int); > @@ -186,10 +188,11 @@ voidsettunnelinst(const char *, int); > voidsettunnelttl(const char *, int); > voidsetvnetid(const char *, int); > voiddelvnetid(const char *, int); > -voidgetvnetid(void); > +voidgetvnetid(struct ifencap *); > voidsetifparent(const char *, int); > voiddelifparent(const char *, int); > -voidgetifparent(void); > +voidgetifparent(struct ifencap *); > +voidgetencap(void); > voidsetia6flags(const char *, int); > voidsetia6pltime(const char *, int); > voidsetia6vltime(const char *, int); > @@ -2999,8 +3002,7 @@ status(int link, struct sockaddr_dl *sdl >printf("\tpatch: %s\n", ifname); > #endif >vlan_status(); > -getvnetid(); > -getifparent(); > +getencap(); > #ifndef SMALL >carp_status(); >pfsync_status(); > @@ -3617,6 +3619,22 @@ setmpwcontrolword(const char *value, int > } > #endif /* SMALL */ > > +struct ifencap { > +unsigned int ife_flags; > +#define IFE_VNETID_MASK0xf > +#define IFE_VNETID_NOPE0x0 > +#define IFE_VNETID_NONE0x1 > +#define IFE_VNETID_ANY0x2 > +#define IFE_VNETID_SET0x3 > +int64_t ife_vnetid; > + > +#define IFE_PARENT_MASK0xf0 > +#define IFE_PARENT_NOPE0x00 > +#define IFE_PARENT_NONE0x10 > +#define IFE_PARENT_SET0x20 > +charife_parent[IFNAMSIZ]; > +}; > + > void > setvnetid(const char *id, int param) > { > @@ -3647,7 +3665,7 @@ delvnetid(const char *ignored, int alsoi > } > > void > -getvnetid(void) > +getvnetid(struct ifencap *ife) > { >if (strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)) >= >sizeof(ifr.ifr_name)) > @@ -3657,17 +3675,17 @@ getvnetid(void) >if (errno != EADDRNOTAVAIL) >return; > > -printf("\tvnetid: none\n"); > - > +ife->ife_flags |= IFE_VNETID_NONE; >return; >} > >if (ifr.ifr_vnetid < 0) { > -printf("\tvnetid: any\n"); > +ife->ife_flags |= IFE_VNETID_ANY; >return; >} > > -printf("\tvnetid: %lld\n", ifr.ifr_vnetid); > +ife->ife_flags |= IFE_VNETID_SET; > +ife->ife_vnetid = ifr.ifr_vnetid; > } > > void > @@ -3696,10 +3714,9 @@ delifparent(const char *ignored, int als > } > > void > -getifparent(void) > +getifparent(struct ifencap *ife) > { >struct if_parent ifp; > -const char *parent = "none"; > >memset(&ifp, 0, sizeof(ifp)); >if (strlcpy(ifp.ifp_name, name, sizeof(ifp.ifp_name)) >= > @@ -3709,10 +3726,50 @@ getifparent(void) >if (ioctl(s, SIOCGIFPARENT, (caddr_t)&ifp) == -1) { >if (errno != EADDRNOTAVAIL) >return; > -} else > -parent = ifp.ifp_parent; > > -printf("\tparent: %s\n", parent); > +ife->ife_flags |= IFE_PARENT_NONE; > +} else { > +memcpy(ife->ife_parent, ifp.ifp_parent, > +sizeof(ife->ife_parent)); > +ife->ife_flags |= IFE_PARENT_SET; > +} > +} > + > +void > +getencap(void) > +{ > +struct ifencap ife = { .ife_flags = 0 }; > + > +getvnetid(&ife); > +getifparent(&ife); > + > +if (ife.ife_flags == 0) > +return; > + > +printf("\tencap:"); > + > +switch (ife.ife_flags & IFE_VNETID_MASK) { > +case IFE_VNETID_NONE: > +printf(" vnetid: none"); > +break; > +case IFE_VNETID_ANY: > +printf(" vnetid: any"); > +break; > +case IFE_VNETID_SET: > +printf(" vnetid: %lld", ife.ife_vnetid); > +break; > +} > + > +switch (ife.ife_flags & IFE_PARENT_MASK) { > +case IFE_PARENT_NONE: > +printf(" parent: none"); > +break; > +case IFE_PARENT_SET: > +printf(" parent: %s", ife.ife_parent); > +break; > +} > + > +printf("\n"); > } > > static int __tag = 0; >
Re: shorten ifconfig output for vnetids and parent interfaces
David Gwynne(da...@gwynne.id.au) on 2017.05.29 15:34:51 +1000: > this rolls vnetid and parent into a single encap line in ifconfig. > > eg: > > - vnetid: 7 > - parent: ix1 > + encap: vnetid: 7 parent: ix1 > > after this i would like to get rid of the vlan compat goo. > > ok? yes, one whitespace below > > Index: ifconfig.c > === > RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v > retrieving revision 1.340 > diff -u -p -r1.340 ifconfig.c > --- ifconfig.c21 Mar 2017 07:24:36 - 1.340 > +++ ifconfig.c29 May 2017 03:29:09 - > @@ -153,6 +153,8 @@ int shownet80211chans; > int shownet80211nodes; > int showclasses; > > +struct ifencap; > + > void notealias(const char *, int); > void setifaddr(const char *, int); > void setifrtlabel(const char *, int); > @@ -186,10 +188,11 @@ voidsettunnelinst(const char *, int); > void settunnelttl(const char *, int); > void setvnetid(const char *, int); > void delvnetid(const char *, int); > -void getvnetid(void); > +void getvnetid(struct ifencap *); > void setifparent(const char *, int); > void delifparent(const char *, int); > -void getifparent(void); > +void getifparent(struct ifencap *); > +void getencap(void); > void setia6flags(const char *, int); > void setia6pltime(const char *, int); > void setia6vltime(const char *, int); > @@ -2999,8 +3002,7 @@ status(int link, struct sockaddr_dl *sdl > printf("\tpatch: %s\n", ifname); > #endif > vlan_status(); > - getvnetid(); > - getifparent(); > + getencap(); > #ifndef SMALL > carp_status(); > pfsync_status(); > @@ -3617,6 +3619,22 @@ setmpwcontrolword(const char *value, int > } > #endif /* SMALL */ > > +struct ifencap { > +unsigned int ife_flags; spaces up front > +#define IFE_VNETID_MASK 0xf > +#define IFE_VNETID_NOPE 0x0 > +#define IFE_VNETID_NONE 0x1 > +#define IFE_VNETID_ANY 0x2 > +#define IFE_VNETID_SET 0x3 > + int64_t ife_vnetid; > + > +#define IFE_PARENT_MASK 0xf0 > +#define IFE_PARENT_NOPE 0x00 > +#define IFE_PARENT_NONE 0x10 > +#define IFE_PARENT_SET 0x20 > + charife_parent[IFNAMSIZ]; > +}; > + > void > setvnetid(const char *id, int param) > { > @@ -3647,7 +3665,7 @@ delvnetid(const char *ignored, int alsoi > } > > void > -getvnetid(void) > +getvnetid(struct ifencap *ife) > { > if (strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)) >= > sizeof(ifr.ifr_name)) > @@ -3657,17 +3675,17 @@ getvnetid(void) > if (errno != EADDRNOTAVAIL) > return; > > - printf("\tvnetid: none\n"); > - > + ife->ife_flags |= IFE_VNETID_NONE; > return; > } > > if (ifr.ifr_vnetid < 0) { > - printf("\tvnetid: any\n"); > + ife->ife_flags |= IFE_VNETID_ANY; > return; > } > > - printf("\tvnetid: %lld\n", ifr.ifr_vnetid); > + ife->ife_flags |= IFE_VNETID_SET; > + ife->ife_vnetid = ifr.ifr_vnetid; > } > > void > @@ -3696,10 +3714,9 @@ delifparent(const char *ignored, int als > } > > void > -getifparent(void) > +getifparent(struct ifencap *ife) > { > struct if_parent ifp; > - const char *parent = "none"; > > memset(&ifp, 0, sizeof(ifp)); > if (strlcpy(ifp.ifp_name, name, sizeof(ifp.ifp_name)) >= > @@ -3709,10 +3726,50 @@ getifparent(void) > if (ioctl(s, SIOCGIFPARENT, (caddr_t)&ifp) == -1) { > if (errno != EADDRNOTAVAIL) > return; > - } else > - parent = ifp.ifp_parent; > > - printf("\tparent: %s\n", parent); > + ife->ife_flags |= IFE_PARENT_NONE; > + } else { > + memcpy(ife->ife_parent, ifp.ifp_parent, > + sizeof(ife->ife_parent)); > + ife->ife_flags |= IFE_PARENT_SET; > + } > +} > + > +void > +getencap(void) > +{ > + struct ifencap ife = { .ife_flags = 0 }; > + > + getvnetid(&ife); > + getifparent(&ife); > + > + if (ife.ife_flags == 0) > + return; > + > + printf("\tencap:"); > + > + switch (ife.ife_flags & IFE_VNETID_MASK) { > + case IFE_VNETID_NONE: > + printf(" vnetid: none"); > + break; > + case IFE_VNETID_ANY: > + printf(" vnetid: any"); > + break; > + case IFE_VNETID_SET: > + printf(" vnetid: %lld", ife.ife_vnetid); > + break; > + } > + > + switch (ife.ife_flags & IFE_PARENT_MASK) { > + case IFE_PARENT_NONE: > + printf(" parent: none"); > + break; > + case IFE_PARENT_SET: > + printf(" parent: %s", ife.ife_parent); > + break; > + } > + > + printf("\n"); > } > > static int __tag = 0; >
shorten ifconfig output for vnetids and parent interfaces
this rolls vnetid and parent into a single encap line in ifconfig. eg: - vnetid: 7 - parent: ix1 + encap: vnetid: 7 parent: ix1 after this i would like to get rid of the vlan compat goo. ok? Index: ifconfig.c === RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v retrieving revision 1.340 diff -u -p -r1.340 ifconfig.c --- ifconfig.c 21 Mar 2017 07:24:36 - 1.340 +++ ifconfig.c 29 May 2017 03:29:09 - @@ -153,6 +153,8 @@ int shownet80211chans; intshownet80211nodes; intshowclasses; +struct ifencap; + void notealias(const char *, int); void setifaddr(const char *, int); void setifrtlabel(const char *, int); @@ -186,10 +188,11 @@ void settunnelinst(const char *, int); void settunnelttl(const char *, int); void setvnetid(const char *, int); void delvnetid(const char *, int); -void getvnetid(void); +void getvnetid(struct ifencap *); void setifparent(const char *, int); void delifparent(const char *, int); -void getifparent(void); +void getifparent(struct ifencap *); +void getencap(void); void setia6flags(const char *, int); void setia6pltime(const char *, int); void setia6vltime(const char *, int); @@ -2999,8 +3002,7 @@ status(int link, struct sockaddr_dl *sdl printf("\tpatch: %s\n", ifname); #endif vlan_status(); - getvnetid(); - getifparent(); + getencap(); #ifndef SMALL carp_status(); pfsync_status(); @@ -3617,6 +3619,22 @@ setmpwcontrolword(const char *value, int } #endif /* SMALL */ +struct ifencap { +unsigned intife_flags; +#define IFE_VNETID_MASK0xf +#define IFE_VNETID_NOPE0x0 +#define IFE_VNETID_NONE0x1 +#define IFE_VNETID_ANY 0x2 +#define IFE_VNETID_SET 0x3 + int64_t ife_vnetid; + +#define IFE_PARENT_MASK0xf0 +#define IFE_PARENT_NOPE0x00 +#define IFE_PARENT_NONE0x10 +#define IFE_PARENT_SET 0x20 + charife_parent[IFNAMSIZ]; +}; + void setvnetid(const char *id, int param) { @@ -3647,7 +3665,7 @@ delvnetid(const char *ignored, int alsoi } void -getvnetid(void) +getvnetid(struct ifencap *ife) { if (strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)) >= sizeof(ifr.ifr_name)) @@ -3657,17 +3675,17 @@ getvnetid(void) if (errno != EADDRNOTAVAIL) return; - printf("\tvnetid: none\n"); - + ife->ife_flags |= IFE_VNETID_NONE; return; } if (ifr.ifr_vnetid < 0) { - printf("\tvnetid: any\n"); + ife->ife_flags |= IFE_VNETID_ANY; return; } - printf("\tvnetid: %lld\n", ifr.ifr_vnetid); + ife->ife_flags |= IFE_VNETID_SET; + ife->ife_vnetid = ifr.ifr_vnetid; } void @@ -3696,10 +3714,9 @@ delifparent(const char *ignored, int als } void -getifparent(void) +getifparent(struct ifencap *ife) { struct if_parent ifp; - const char *parent = "none"; memset(&ifp, 0, sizeof(ifp)); if (strlcpy(ifp.ifp_name, name, sizeof(ifp.ifp_name)) >= @@ -3709,10 +3726,50 @@ getifparent(void) if (ioctl(s, SIOCGIFPARENT, (caddr_t)&ifp) == -1) { if (errno != EADDRNOTAVAIL) return; - } else - parent = ifp.ifp_parent; - printf("\tparent: %s\n", parent); + ife->ife_flags |= IFE_PARENT_NONE; + } else { + memcpy(ife->ife_parent, ifp.ifp_parent, + sizeof(ife->ife_parent)); + ife->ife_flags |= IFE_PARENT_SET; + } +} + +void +getencap(void) +{ + struct ifencap ife = { .ife_flags = 0 }; + + getvnetid(&ife); + getifparent(&ife); + + if (ife.ife_flags == 0) + return; + + printf("\tencap:"); + + switch (ife.ife_flags & IFE_VNETID_MASK) { + case IFE_VNETID_NONE: + printf(" vnetid: none"); + break; + case IFE_VNETID_ANY: + printf(" vnetid: any"); + break; + case IFE_VNETID_SET: + printf(" vnetid: %lld", ife.ife_vnetid); + break; + } + + switch (ife.ife_flags & IFE_PARENT_MASK) { + case IFE_PARENT_NONE: + printf(" parent: none"); + break; + case IFE_PARENT_SET: + printf(" parent: %s", ife.ife_parent); + break; + } + + printf("\n"); } static int __tag = 0;