Bug 5786

Summary: ifconfig oddly won't respect CIDR notation
Product: Busybox Reporter: Јован Јаневски <jovan>
Component: NetworkingAssignee: unassigned
Status: RESOLVED FIXED    
Severity: critical CC: busybox-cvs, jovan
Priority: P5    
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:

Description Јован Јаневски 2012-12-13 18:27:29 UTC
Hello,

I am using TinyCoreLinux, kernel 3.0.21-tinycore with BusyBox v1.20.1 installed on it.

If i try to assign interface IP and subnet within the 192.168.0.0/16 subnet using for example:
----
ifconfig eth4 up 192.168.1.1/24
----
My specified CIDR notation is respected and i get 192.168.1.1/24:
----
ifconfig eth4
eth4      Link encap:Ethernet  HWaddr 00:00:E8:XX:XX:XX 
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: XXXX::XXX:XXXX:XX:XX/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:266 errors:0 dropped:0 overruns:0 frame:0
          TX packets:41 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:22874 (22.3 KiB)  TX bytes:4338 (4.2 KiB)
          Interrupt:18 Base address:0xba00
----

But if i try to assign interface IP and subnet within 172.16.0.0/12, 10.0.0.0/8 or other subnets using for example:
----
ifconfig eth4 up 172.16.2.1/24
====and====
ifconfig eth4 up 10.0.0.1/24
----
Then my specified CIRD notation is not respected and i get 172.16.2.1/12 and 10.0.0.1/8 instead:
----
ifconfig eth4
eth4      Link encap:Ethernet  HWaddr 00:00:E8:XX:XX:XX
          inet addr:172.16.2.1  Bcast:172.16.255.255  Mask:255.255.0.0
          inet6 addr: XXXX::XXX:XXXX:XX:XX/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:296 errors:0 dropped:0 overruns:0 frame:0
          TX packets:41 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:24674 (24.0 KiB)  TX bytes:4338 (4.2 KiB)
          Interrupt:18 Base address:0xba00 
====and====
eth4      Link encap:Ethernet  HWaddr 00:00:E8:XX:XX:XX 
          inet addr:10.0.0.1  Bcast:10.255.255.255  Mask:255.0.0.0
          inet6 addr: XXXX::XXX:XXXX:XX:XX/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:296 errors:0 dropped:0 overruns:0 frame:0
          TX packets:41 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:24674 (24.0 KiB)  TX bytes:4338 (4.2 KiB)
          Interrupt:18 Base address:0xba00
----

The same problem happens if i try to assign 1.1.1.1/24 instead i get 1.1.1.1/8.

I've tested the commands on Debian 6.0.5 both 32 and 64 bit with the standard ifconfig tool (non-busybox) it works without any problems.

The only way to get the proper IP and subnet assignment per interface while using busybox is - instead of using:
----
ifconfig eth4 up 172.16.2.1/24
----
i could use:
----
ifconfig eth4 172.16.2.1 netmask 255.255.255.0 broadcast 172.16.2.255
----
And then i get the propper IP and subnet assignment.

Any help regarding this problem is appreciated.

Best Regards,
Jovan
Comment 1 Denys Vlasenko 2013-01-20 17:15:14 UTC
Indeed, bbox's ifconfig doesn't accept that format.

It does not bail out by accident, because parser strips out /MASK
before parsing IP.
(Why? The parser is reused for "add IPV6/MASK" and "del IPV6/MASK" cases).

For now I made so that it won't accept this format:

commit 31dc8603eedc0140c798c9af3404a35ea190af2c
Author: Denys Vlasenko <vda.linux@googlemail.com>
Date:   Sun Jan 20 18:10:12 2013 +0100

    ifconfig: do not accept "ifconfig eth0 up 1.2.3.4/17" (ip with mask)


> i could use:
> ----
> ifconfig eth4 172.16.2.1 netmask 255.255.255.0 broadcast 172.16.2.255

Please do. That's how ifconfig worked from the time immemorial, before new netmask notation was born.
If you want more modern tool, consider switching to ip.
Comment 2 Јован Јаневски 2013-01-20 17:44:34 UTC
Thank You.

Best Regards,
Jovan