ifconfig with quoted arguments

Jeremy Boy jb at jboy.eu
Tue Feb 9 21:58:03 UTC 2016


Hello list,

please CC me in replies to this mail, since I am no subscriber to this list.

For safety reasons, we enclose user input to shell commands in quotes. Until today, the resulting command for ifconfig(8) looked like this:

> ifconfig ue0 inet "192.168.2.176 netmask 255.255.255.0"


As we figured out, this means that ifconfig sometimes doesn't set the netmask as we expect it to do:

> root at csbuild:~ # ifconfig ue0
> ue0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
>         options=80001<RXCSUM,LINKSTATE>
>         ether b8:27:eb:fd:58:69
>         inet 192.168.2.176 netmask 0xffff0000 broadcast 192.168.255.255 
>         media: Ethernet autoselect (100baseTX <full-duplex>)
>         status: active
>         nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
> root at csbuild:~ # ifconfig ue0 inet "192.168.2.176 netmask 255.0.0.0"
> root at csbuild:~ # echo $?
> 0
> root at csbuild:~ # ifconfig ue0
> ue0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
>         options=80001<RXCSUM,LINKSTATE>
>         ether b8:27:eb:fd:58:69
>         inet 192.168.2.176 netmask 0xffffff00 broadcast 192.168.2.255 
>         media: Ethernet autoselect (100baseTX <full-duplex>)
>         status: active
>         nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
> root at csbuild:~ # 


As you can see, ifconfig sets the netmask to 255.255.255.0, ignoring the netmask we provided. If provided with a 10.* address, ifconfig sets the netmask to 255.0.0.0, no matter what actual netmask we entered. Also, it doesn't exit with a status indicating error, which made it a little harder to debug this issue. The following works as expected:

> root at csbuild:~ # ifconfig ue0
> ue0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
>         options=80001<RXCSUM,LINKSTATE>
>         ether b8:27:eb:fd:58:69
>         inet 192.168.2.176 netmask 0xffffff00 broadcast 192.168.2.255 
>         media: Ethernet autoselect (100baseTX <full-duplex>)
>         status: active
>         nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
> root at csbuild:~ # ifconfig ue0 inet "192.168.2.176" netmask "255.0.0.0"
> root at csbuild:~ # ifconfig ue0
> ue0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
>         options=80001<RXCSUM,LINKSTATE>
>         ether b8:27:eb:fd:58:69
>         inet 192.168.2.176 netmask 0xff000000 broadcast 192.255.255.255 
>         media: Ethernet autoselect (100baseTX <full-duplex>)
>         status: active
>         nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
> root at csbuild:~ # 

What exactly does ifconfig do? It seems to me that it reads the IP address from the quoted string but truncates the netmask. Is this a bug in ifconfig or intended behavior?


Best wishes
Jeremy


More information about the freebsd-net mailing list