From owner-freebsd-net@freebsd.org Fri Feb 12 01:02:34 2016 Return-Path: Delivered-To: freebsd-net@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B8D92AA5A03 for ; Fri, 12 Feb 2016 01:02:34 +0000 (UTC) (envelope-from julian@freebsd.org) Received: from vps1.elischer.org (vps1.elischer.org [204.109.63.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "vps1.elischer.org", Issuer "CA Cert Signing Authority" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 8BCA418F4 for ; Fri, 12 Feb 2016 01:02:34 +0000 (UTC) (envelope-from julian@freebsd.org) Received: from Julian-MBP3.local (ppp121-45-229-231.lns20.per1.internode.on.net [121.45.229.231]) (authenticated bits=0) by vps1.elischer.org (8.15.2/8.15.2) with ESMTPSA id u1C0rFcM055862 (version=TLSv1.2 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO); Thu, 11 Feb 2016 16:53:18 -0800 (PST) (envelope-from julian@freebsd.org) Subject: Re: ifconfig with quoted arguments To: Jeremy Boy , freebsd-net@freebsd.org References: <76A08658-ACD2-426B-865A-45A6A79BBFB4@jboy.eu> From: Julian Elischer Message-ID: <56BD2CF5.7020200@freebsd.org> Date: Fri, 12 Feb 2016 08:53:09 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 In-Reply-To: <76A08658-ACD2-426B-865A-45A6A79BBFB4@jboy.eu> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Feb 2016 01:02:34 -0000 On 10/02/2016 5:51 AM, Jeremy Boy wrote: > 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@csbuild:~ # ifconfig ue0 >> ue0: flags=8843 metric 0 mtu 1500 >> options=80001 >> ether b8:27:eb:fd:58:69 >> inet 192.168.2.176 netmask 0xffff0000 broadcast 192.168.255.255 >> media: Ethernet autoselect (100baseTX ) >> status: active >> nd6 options=29 >> root@csbuild:~ # ifconfig ue0 inet "192.168.2.176 netmask 255.0.0.0" >> root@csbuild:~ # echo $? >> 0 >> root@csbuild:~ # ifconfig ue0 >> ue0: flags=8843 metric 0 mtu 1500 >> options=80001 >> ether b8:27:eb:fd:58:69 >> inet 192.168.2.176 netmask 0xffffff00 broadcast 192.168.2.255 >> media: Ethernet autoselect (100baseTX ) >> status: active >> nd6 options=29 >> root@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@csbuild:~ # ifconfig ue0 >> ue0: flags=8843 metric 0 mtu 1500 >> options=80001 >> ether b8:27:eb:fd:58:69 >> inet 192.168.2.176 netmask 0xffffff00 broadcast 192.168.2.255 >> media: Ethernet autoselect (100baseTX ) >> status: active >> nd6 options=29 >> root@csbuild:~ # ifconfig ue0 inet "192.168.2.176" netmask "255.0.0.0" >> root@csbuild:~ # ifconfig ue0 >> ue0: flags=8843 metric 0 mtu 1500 >> options=80001 >> ether b8:27:eb:fd:58:69 >> inet 192.168.2.176 netmask 0xff000000 broadcast 192.255.255.255 >> media: Ethernet autoselect (100baseTX ) >> status: active >> nd6 options=29 >> root@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? it's not so much as ifconfig, as the shell you have ifconfig with 3 arguments, the last of which is "192.168.2.176 netmask 255.255.255.0" which ifconfig inspects to see if it has an IP address in it (followed by a space which terminates the test successfully). this is expected behaviour. Though admittedly a less than clear example of it. > > Best wishes > Jeremy > _______________________________________________ > freebsd-net@freebsd.org mailing list > https://lists.freebsd.org/mailman/listinfo/freebsd-net > To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org" >