From owner-freebsd-current@FreeBSD.ORG Thu Jan 9 11:07:26 2014 Return-Path: Delivered-To: current@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1D506CA7 for ; Thu, 9 Jan 2014 11:07:26 +0000 (UTC) Received: from mail.ipfw.ru (mail.ipfw.ru [IPv6:2a01:4f8:120:6141::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id D52B517E8 for ; Thu, 9 Jan 2014 11:07:25 +0000 (UTC) Received: from [2a02:6b8:0:401:222:4dff:fe50:cd2f] (helo=ptichko.yndx.net) by mail.ipfw.ru with esmtpsa (TLSv1:CAMELLIA256-SHA:256) (Exim 4.76 (FreeBSD)) (envelope-from ) id 1W19cr-000DWh-Td; Thu, 09 Jan 2014 11:01:57 +0400 Message-ID: <52CE8235.1090802@FreeBSD.org> Date: Thu, 09 Jan 2014 15:04:21 +0400 From: "Alexander V. Chernikov" User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:24.0) Gecko/20100101 Thunderbird/24.0.1 MIME-Version: 1.0 To: current@FreeBSD.org Subject: Re: interesting routing bug... References: <20140109011823.GI99167@funkthat.com> In-Reply-To: <20140109011823.GI99167@funkthat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: jmg@funkthat.com X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Jan 2014 11:07:26 -0000 On 09.01.2014 05:18, John-Mark Gurney wrote: > Well, I was trying to manually add a route for a host on the local > network (I can explain why, but it doesn't matter) and I got this: Hello! There are several different kernel & userland bugs :) > # netstat -rnfinet > Routing tables > > Internet: > Destination Gateway Flags Netif Expire > default 192.168.0.14 UGS re0 > 127.0.0.1 link#3 UH lo0 > 192.168.0.0/24 link#1 U re0 > 192.168.0.21 link#1 UHS lo0 > # route add -host 192.168.0.254 -interface re0 -link 04:4a:31:d3:95:dc > add net 192.168.0.254: gateway re0 "-link" specifier assumes no parameter, so the next argument is treated as netmask (since dst/gw are already supplied). It is successfully parsed by getaddr() as AF_LINK sockaddr. I've added additional check which requires dst/mask address families to be equal (r260472). Historically, our kernel is a bit relaxed on checking validness for network masks: it does not check family& does not perform usual (addr&mask == addr) check. masked copy is performed instead. This is a bit tricky to fix since most in-kernel consumers are supplying non-masked address. I'm going to fix this soon. > # netstat -rnfinet > Routing tables > > Internet: > Destination Gateway Flags Netif Expire > 0.0.0.0&0x20500 90:2b:34:ab:bb:85 US re0 Basically kernel treats sockaddr_dl as non-contiguos mask. > default 192.168.0.14 UGS re0 > 10.0.0.0/8 link#2 U msk0 > 10.42.42.21 link#2 UHS lo0 > 127.0.0.1 link#3 UH lo0 > 192.168.0.0/24 link#1 U re0 > 192.168.0.21 link#1 UHS lo0 > # route delete 0.0.0.0 > delete net 0.0.0.0 > # route flush Our rtsock protocol does not provide rtable flush, so internally route(8) does route dump for given table and issues RTF_DELETE messages for every route. It seems that non-contiguous masks are handled incorrectly here.. > :: localhost -fib 0 done > ::ffff:0.0.0.0 localhost -fib 0 done > fe80:: localhost -fib 0 done > ff02:: localhost -fib 0 done > # netstat -rnfinet > Routing tables > > Internet: > Destination Gateway Flags Netif Expire > 0.0.0.0&0x20500 90:2b:34:ab:bb:85 US re0 > 127.0.0.1 link#3 UH lo0 > 192.168.0.0/24 link#1 U re0 > 192.168.0.21 link#1 UHS lo0 > > So, as you can see, I have managed to add a bogus route w/o a way > to remove it short of rebooting the box... And because of this route, You should be able to delete this using exactly the same command (s/add/del/). > some hosts like svn0.us-west.freebsd.org will match causing the machine > to try to find the ip on the local network. > > This route I assume should be rejected by the kernel and not added, > or there is a mismatch between the route program and how the kernel > understands it. > > I can provide more information upon request. > > Thanks. >