Re: ifconfig: print netmask in CIDR notation

2016-12-13 Thread Martin Pieuchot
On 13/12/16(Tue) 11:32, Reyk Floeter wrote:
> [...] 
> Simple reasons: this is a different discussion or diff.  If we would
> want to remove non-contiguous netmasks completely, it should be done
> in the stack.  Until then, it is better that ifconfig can cope with
> them.

The stack no longer support them.  But nobody did the work to fully
clean it.

I agree with Peter, if it's not extra work for you to remove that from
ifconfig(8) that's one step towards cleaning this.



Re: ifconfig: print netmask in CIDR notation

2016-12-13 Thread Reyk Floeter
On Tue, Dec 13, 2016 at 10:13:32AM +, Stuart Henderson wrote:
> On 2016/12/13 10:51, Reyk Floeter wrote:
> > printing the netmask in hex seems to be a historical artifact in ifconfig;
> > I always wondered about it and I never got used to it.
> > 
> > The following diff changes ifconfig output to print contiguous
> > netmasks in CIDR notation.  Non-contiguous netmasks will still be
> > printed in full, tunnels will print explicit "prefixlen" because it is
> > not unambiguous where the mask belongs to in this case.
> > 
> > lo1: flags=8049 rdomain 1 mtu 32768
> > index 7 priority 0 llprio 3
> > groups: lo
> > inet6 ::1/128
> > inet6 fe80::1%lo1/64 scopeid 0x7
> > inet 10.2.1.100 netmask 0x00ff
> > inet 10.3.100.1/24
> > 
> > A similar change has been done in NetBSD and FreeBSD is doing the
> > FreeBSD thing by providing an -f command-line button to select one of
> > three output modes ...
> > 
> > Thoughts?
> 
> From when this came up before:
> 
> http://marc.info/?t=14273741506=1=2
> 
> The installer needs to be modified, I'm not sure if anything else might
> turn up.
> 

Thanks, I forgot about this thread.
At least I solved the printing of non-contiguous netmasks :)

I think scripts and things like Ansible can be fixed.

Reyk



Re: ifconfig: print netmask in CIDR notation

2016-12-13 Thread Stuart Henderson
On 2016/12/13 10:51, Reyk Floeter wrote:
> printing the netmask in hex seems to be a historical artifact in ifconfig;
> I always wondered about it and I never got used to it.
> 
> The following diff changes ifconfig output to print contiguous
> netmasks in CIDR notation.  Non-contiguous netmasks will still be
> printed in full, tunnels will print explicit "prefixlen" because it is
> not unambiguous where the mask belongs to in this case.
> 
> lo1: flags=8049 rdomain 1 mtu 32768
> index 7 priority 0 llprio 3
> groups: lo
> inet6 ::1/128
> inet6 fe80::1%lo1/64 scopeid 0x7
> inet 10.2.1.100 netmask 0x00ff
> inet 10.3.100.1/24
> 
> A similar change has been done in NetBSD and FreeBSD is doing the
> FreeBSD thing by providing an -f command-line button to select one of
> three output modes ...
> 
> Thoughts?

>From when this came up before:

http://marc.info/?t=14273741506=1=2

The installer needs to be modified, I'm not sure if anything else might
turn up.



Re: ifconfig: print netmask in CIDR notation

2016-12-13 Thread Reyk Floeter
On Tue, Dec 13, 2016 at 10:58:28AM +0100, Mark Kettenis wrote:
> > Date: Tue, 13 Dec 2016 10:51:40 +0100
> > From: Reyk Floeter 
> > 
> > Hi,
> > 
> > printing the netmask in hex seems to be a historical artifact in ifconfig;
> > I always wondered about it and I never got used to it.
> > 
> > The following diff changes ifconfig output to print contiguous
> > netmasks in CIDR notation.  Non-contiguous netmasks will still be
> > printed in full, tunnels will print explicit "prefixlen" because it is
> > not unambiguous where the mask belongs to in this case.
> > 
> > lo1: flags=8049 rdomain 1 mtu 32768
> > index 7 priority 0 llprio 3
> > groups: lo
> > inet6 ::1/128
> > inet6 fe80::1%lo1/64 scopeid 0x7
> > inet 10.2.1.100 netmask 0x00ff
> > inet 10.3.100.1/24
> > 
> > A similar change has been done in NetBSD and FreeBSD is doing the
> > FreeBSD thing by providing an -f command-line button to select one of
> > three output modes ...
> > 
> > Thoughts?
> 
> I'd say it is a bad idea to mix the two forms in ifconfig output.

What mix?  It is always using CIDR unless it is the really rare case
of a non-contiguous netmask that might be used by 0 to 4 people.

Furthermore,

- On the input side, we already support CIDR, netmask and prefixlen.

- "route" displays CIDR, pf and almost all other configurations use it.

- Almost every other tool uses CIDR or at least dotted-quad netmasks,
the hex format is something that is used almost nowhere else.

Reyk



Re: ifconfig: print netmask in CIDR notation

2016-12-13 Thread Mark Kettenis
> Date: Tue, 13 Dec 2016 10:51:40 +0100
> From: Reyk Floeter 
> 
> Hi,
> 
> printing the netmask in hex seems to be a historical artifact in ifconfig;
> I always wondered about it and I never got used to it.
> 
> The following diff changes ifconfig output to print contiguous
> netmasks in CIDR notation.  Non-contiguous netmasks will still be
> printed in full, tunnels will print explicit "prefixlen" because it is
> not unambiguous where the mask belongs to in this case.
> 
> lo1: flags=8049 rdomain 1 mtu 32768
> index 7 priority 0 llprio 3
> groups: lo
> inet6 ::1/128
> inet6 fe80::1%lo1/64 scopeid 0x7
> inet 10.2.1.100 netmask 0x00ff
> inet 10.3.100.1/24
> 
> A similar change has been done in NetBSD and FreeBSD is doing the
> FreeBSD thing by providing an -f command-line button to select one of
> three output modes ...
> 
> Thoughts?

I'd say it is a bad idea to mix the two forms in ifconfig output.



ifconfig: print netmask in CIDR notation

2016-12-13 Thread Reyk Floeter
Hi,

printing the netmask in hex seems to be a historical artifact in ifconfig;
I always wondered about it and I never got used to it.

The following diff changes ifconfig output to print contiguous
netmasks in CIDR notation.  Non-contiguous netmasks will still be
printed in full, tunnels will print explicit "prefixlen" because it is
not unambiguous where the mask belongs to in this case.

lo1: flags=8049 rdomain 1 mtu 32768
index 7 priority 0 llprio 3
groups: lo
inet6 ::1/128
inet6 fe80::1%lo1/64 scopeid 0x7
inet 10.2.1.100 netmask 0x00ff
inet 10.3.100.1/24

A similar change has been done in NetBSD and FreeBSD is doing the
FreeBSD thing by providing an -f command-line button to select one of
three output modes ...

Thoughts?

Reyk

Index: sbin/ifconfig/ifconfig.c
===
RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v
retrieving revision 1.334
diff -u -p -u -p -r1.334 ifconfig.c
--- sbin/ifconfig/ifconfig.c13 Dec 2016 01:36:21 -  1.334
+++ sbin/ifconfig/ifconfig.c13 Dec 2016 09:36:52 -
@@ -3138,6 +3138,7 @@ void
 in_status(int force)
 {
struct sockaddr_in *sin, sin2;
+   int prefixlen;
 
getsock(AF_INET);
if (s < 0) {
@@ -3177,7 +3178,14 @@ in_status(int force)
sin = (struct sockaddr_in *)_dstaddr;
printf(" --> %s", inet_ntoa(sin->sin_addr));
}
-   printf(" netmask 0x%x", ntohl(netmask.sin_addr.s_addr));
+   prefixlen = prefix(_addr.s_addr,
+   sizeof(netmask.sin_addr.s_addr));
+   if (prefixlen == -1)
+   printf(" netmask 0x%x", ntohl(netmask.sin_addr.s_addr));
+   else if (flags & IFF_POINTOPOINT)
+   printf("prefixlen %d", prefixlen);
+   else
+   printf("/%d", prefixlen);
if (flags & IFF_BROADCAST) {
memcpy(_addr, , sizeof(sin2));
if (ioctl(s, SIOCGIFBRDADDR, (caddr_t)) < 0) {
@@ -3224,6 +3232,7 @@ in6_alias(struct in6_ifreq *creq)
u_int32_t scopeid;
char hbuf[NI_MAXHOST];
const int niflag = NI_NUMERICHOST;
+   int prefixlen;
 
/* Get the non-alias address for this interface. */
getsock(AF_INET6);
@@ -3269,8 +3278,17 @@ in6_alias(struct in6_ifreq *creq)
warn("SIOCGIFNETMASK_IN6");
} else {
sin6 = (struct sockaddr_in6 *)_addr;
-   printf(" prefixlen %d", prefix(>sin6_addr,
-   sizeof(struct in6_addr)));
+   prefixlen = prefix(>sin6_addr,
+   sizeof(struct in6_addr));
+   if (prefixlen == -1) {
+   if (getnameinfo((struct sockaddr *)sin6, sin6->sin6_len,
+   hbuf, sizeof(hbuf), NULL, 0, niflag) != 0)
+   strlcpy(hbuf, "", sizeof hbuf);
+   printf(" netmask %s", hbuf);
+   } else if (flags & IFF_POINTOPOINT) {
+   printf(" prefixlen %d", prefixlen);
+   } else
+   printf("/%d", prefixlen);
}
 
(void) memset(, 0, sizeof(ifr6));
@@ -5559,11 +5577,11 @@ prefix(void *val, int size)
break;
for (; bit != 0; bit--)
if (nam[byte] & (1 << bit))
-   return (0);
+   return (-1);
byte++;
for (; byte < size; byte++)
if (nam[byte])
-   return (0);
+   return (-1);
return (plen);
 }