From owner-freebsd-net@FreeBSD.ORG Fri Jul 8 00:22:09 2005 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BE60F16A420 for ; Fri, 8 Jul 2005 00:22:09 +0000 (GMT) (envelope-from mjl@luckie.org.nz) Received: from grunt6.ihug.co.nz (grunt6.ihug.co.nz [203.109.254.46]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4AFB643D46 for ; Fri, 8 Jul 2005 00:22:08 +0000 (GMT) (envelope-from mjl@luckie.org.nz) Received: from 203-173-152-49.bliink.ihug.co.nz (lycra.luckie.org.nz) [203.173.152.49] by grunt6.ihug.co.nz with esmtp (Exim 3.35 #1 (Debian)) id 1Dqgd5-0001Ag-00; Fri, 08 Jul 2005 12:22:07 +1200 Received: from mjl by lycra.luckie.org.nz with local (Exim 4.51 (FreeBSD)) id 1Dqgd4-000D1J-M9; Fri, 08 Jul 2005 12:22:06 +1200 Date: Fri, 8 Jul 2005 12:22:06 +1200 From: Matthew Luckie To: gnn@freebsd.org Message-ID: <20050708002203.GB48639@lycra.luckie.org.nz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.1i Cc: freebsd-net@freebsd.org Subject: Re: A bit of a route socket bug... X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 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, 08 Jul 2005 00:22:09 -0000 I'm not very familiar with the route code, but here is what i came up with. [mjl@rayon mjl]$ sudo route change 10.3.2.1 127.0.0.1 route: writing to routing socket: No such process change host 10.3.2.1: gateway 127.0.0.1: not in table the code checks that if changing a host or network route, that the route returned by a lookup matches this type. for network routes, it also ensures that the netmask matches. --- rtsock.c.orig Fri Jul 8 11:56:36 2005 +++ rtsock.c Fri Jul 8 12:12:39 2005 @@ -489,6 +489,30 @@ case RTM_CHANGE: /* + * Check that the route returned is exactly the one + * that was looked up, so that some other route is not + * changed in error. + * Ensure the type of route (host/net) to be changed + * matches, and ensure that the route matches if net + * by checking that the netmask matches. + */ + if (rt->rt_flags & RTF_HOST) { + if((info.rti_flags & RTF_HOST) == 0) { + RT_UNLOCK(rt); + senderr(ESRCH); + } + } else { + if((info.rti_flags & RTF_HOST) || + info.rti_info[RTAX_NETMASK] == NULL || + rt_mask(rt) == NULL || + !sa_equal(info.rti_info[RTAX_NETMASK], + rt_mask(rt))) { + RT_UNLOCK(rt); + senderr(ESRCH); + } + } + + /* * New gateway could require new ifaddr, ifp; * flags may also be different; ifp may be specified * by ll sockaddr when protocol address is ambiguous