# Error on NetBSD-CURRENT due to new ifconfig behavior

**URL:** <https://forum.ansible.com/t/error-on-netbsd-current-due-to-new-ifconfig-behavior/24644>\
**Category:** Ansible Developer\
**Created:** [June 4, 2017, 8:32pm UTC](https://forum.ansible.com/t/error-on-netbsd-current-due-to-new-ifconfig-behavior/24644 "2017-06-04T20:32:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bruce\_V\_Chiarelli](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@Bruce\_V\_Chiarelli](https://forum.ansible.com/u/Bruce_V_Chiarelli)\
**Post date:** [June 4, 2017, 8:32pm UTC](https://forum.ansible.com/t/error-on-netbsd-current-due-to-new-ifconfig-behavior/24644/1 "2017-06-04T20:32:15Z")

</div>

Upcoming versions of NetBSD will print the network prefix in CIDR  
notation instead of as a hex subnet mask. This currently causes Ansible  
to choke on ifconfig output there. See:  
[http://cvsweb.netbsd.org/bsdweb.cgi/src/sbin/ifconfig/af\_inet.c.diff?r1=1.22&r2=1.23&only\_with\_tag=MAIN&f=h](http://cvsweb.netbsd.org/bsdweb.cgi/src/sbin/ifconfig/af_inet.c.diff?r1=1.22&r2=1.23&only_with_tag=MAIN&f=h)

This fixes it for me. I had never even looked at Ansible code before  
today, let alone debugged it, so I'm sure there are better ways.

diff --git a/lib/ansible/module\_utils/facts/network/generic\_bsd.py b/lib/ansible/module\_utils/facts/network/generic\_bsd.py  
index 212c842f43..30e7f5f726 100644  
--- a/lib/ansible/module\_utils/facts/network/generic\_bsd.py  
+++ b/lib/ansible/module\_utils/facts/network/generic\_bsd.py  
@@ -198,13 +198,18 @@ class GenericBsdIfconfigNetwork(Network):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# inet alias 127.1.1.1 netmask 0xff000000  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if words[1] == 'alias':  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;del words[1]  
- address = {'address': words[1]}  
+ if re.search('/', words[1]):  
+ address = {'address': words[1].split('/')[0]}  
+ address['netmask'] = socket.inet\_ntoa(  
+ struct.pack('!I', ( 1 \<\< 32 ) - (1 \<\< ( 32 - int(words[1].split('/')[1])))))  
+ else:  
+ address = {'address': words[1]}  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# deal with hex netmask  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if re.match('([0-9a-f]){8}', words[3]) and len(words[3]) == 8:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;words[3] = '0x' + words[3]  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if words[3].startswith('0x'):  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;address['netmask'] = socket.inet\_ntoa(struct.pack('!L', int(words[3], base=16)))  
- else:  
+ elif not address['netmask']:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# otherwise assume this is a dotted quad  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;address['netmask'] = words[3]  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# calculate the network

---

<div class="post-metadata">

**Author:** ![alikins](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@alikins](https://forum.ansible.com/u/alikins)\
**Post date:** [June 6, 2017, 2:47pm UTC](https://forum.ansible.com/t/error-on-netbsd-current-due-to-new-ifconfig-behavior/24644/2 "2017-06-06T14:47:47Z")

</div>

Could you get an example output from NetBSD ‘ifconfig -a’ before and after the change?

If so, I’ll add test cases and update the code.

Any idea if that change will also be coming to FreeBSD/OpenBSD ?

---

<div class="post-metadata">

**Author:** ![Bruce\_V\_Chiarelli](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@Bruce\_V\_Chiarelli](https://forum.ansible.com/u/Bruce_V_Chiarelli)\
**Post date:** [June 6, 2017, 3:29pm UTC](https://forum.ansible.com/t/error-on-netbsd-current-due-to-new-ifconfig-behavior/24644/3 "2017-06-06T15:29:46Z")

</div>

Adrian Likins \<alikins@redhat.com\> writes:

> Could you get an example output from NetBSD 'ifconfig -a' before and after  
> the change?
> 
> If so, I'll add test cases and update the code.

On NetBSD 7.1:  
laika# ifconfig -a  
lo0: flags=8049\<UP,LOOPBACK,RUNNING,MULTICAST\> mtu 33624  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inet 127.0.0.1 netmask 0xff000000  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inet6 ::1 prefixlen 128  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1  
re0: flags=8843\<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST\> mtu 1500  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;capabilities=3f80\<TSO4,IP4CSUM\_Rx,IP4CSUM\_Tx,TCP4CSUM\_Rx,TCP4CSUM\_Tx\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;capabilities=3f80\<UDP4CSUM\_Rx,UDP4CSUM\_Tx\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;enabled=0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ec\_capabilities=3\<VLAN\_MTU,VLAN\_HWTAGGING\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ec\_enabled=0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;address: 52:54:00:63:55:af  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;media: Ethernet autoselect (100baseTX full-duplex)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status: active  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inet 192.168.122.205 netmask 0xffffff00 broadcast 192.168.122.255  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inet6 fe80::5054:ff:fe63:55af%re0 prefixlen 64 scopeid 0x2

And in the same machine, NetBSD from CVS built two days ago:

laika# ifconfig -a  
lo0: flags=0x8049\<UP,LOOPBACK,RUNNING,MULTICAST\> mtu 33624  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inet 127.0.0.1/8 flags 0x0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inet6 ::1/128 flags 0x20\<NODAD\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inet6 fe80::1%lo0/64 flags 0x0 scopeid 0x1  
re0: flags=0x8843\<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST\> mtu 1500  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;capabilities=3f80\<TSO4,IP4CSUM\_Rx,IP4CSUM\_Tx,TCP4CSUM\_Rx,TCP4CSUM\_Tx\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;capabilities=3f80\<UDP4CSUM\_Rx,UDP4CSUM\_Tx\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;enabled=0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ec\_capabilities=3\<VLAN\_MTU,VLAN\_HWTAGGING\>  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ec\_enabled=0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;address: 52:54:00:63:55:af  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;media: Ethernet autoselect (100baseTX full-duplex)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;status: active  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inet 192.168.122.205/24 broadcast 192.168.122.255 flags 0x0  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;inet6 fe80::5054:ff:fe63:55af%re0/64 flags 0x0 scopeid 0x2

> Any idea if that change will also be coming to FreeBSD/OpenBSD ?

I remember it being discussed on the FreeBSD-current list ages ago, but  
I don't think anything came of it. I'll look into this more later today.

---

<div class="post-metadata">

**Author:** ![Bruce\_V\_Chiarelli](https://avatars.discourse-cdn.com/v4/letter/b/db5fbb/32.png) [@Bruce\_V\_Chiarelli](https://forum.ansible.com/u/Bruce_V_Chiarelli)\
**Post date:** [June 6, 2017, 6:40pm UTC](https://forum.ansible.com/t/error-on-netbsd-current-due-to-new-ifconfig-behavior/24644/4 "2017-06-06T18:40:34Z")

</div>

> > Any idea if that change will also be coming to FreeBSD/OpenBSD ?
> 
> I remember it being discussed on the FreeBSD-current list ages ago, but  
> I don't think anything came of it. I'll look into this more later today.

On FreeBSD, the default is still a hex netmask. A more recent change (  
[https://reviews.freebsd.org/rS301059](https://reviews.freebsd.org/rS301059) ) gave the "-f" flag to ifconfig,  
which allows the format to be adjusted (-f inet:dotted -f inet6:cidr for  
example). This was introduced with FreeBSD 11, the current stable  
release. This change also made it into the latest TrueOS (formerly  
PC-BSD), which frequently rebases against FreeBSD-current.

OpenBSD, DragonFlyBSD, and MidnightBSD only display hex netmasks, and  
I'm not aware of any plans to change those.

---

<div class="post-metadata">

**Author:** ![alikins](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@alikins](https://forum.ansible.com/u/alikins)\
**Post date:** [June 7, 2017, 2:56pm UTC](https://forum.ansible.com/t/error-on-netbsd-current-due-to-new-ifconfig-behavior/24644/5 "2017-06-07T14:56:51Z")

</div>

Thanks for the sample output. Working on test cases now.

---

<div class="post-metadata">

**Author:** ![alikins](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@alikins](https://forum.ansible.com/u/alikins)\
**Post date:** [June 7, 2017, 5:33pm UTC](https://forum.ansible.com/t/error-on-netbsd-current-due-to-new-ifconfig-behavior/24644/6 "2017-06-07T17:33:00Z")

</div>

pr with proposed fixes and some basic unit tests at  
[https://github.com/ansible/ansible/pull/25442](https://github.com/ansible/ansible/pull/25442)
