From nobody@FreeBSD.org  Tue Nov  5 17:12:07 2013
Return-Path: <nobody@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 ESMTP id 8B24B8CF
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  5 Nov 2013 17:12:07 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id 77D0E26B1
	for <freebsd-gnats-submit@FreeBSD.org>; Tue,  5 Nov 2013 17:12:07 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id rA5HC7HO095714
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 5 Nov 2013 17:12:07 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id rA5HC7la095709;
	Tue, 5 Nov 2013 17:12:07 GMT
	(envelope-from nobody)
Message-Id: <201311051712.rA5HC7la095709@oldred.freebsd.org>
Date: Tue, 5 Nov 2013 17:12:07 GMT
From: Hiroshi Yamashita <piro77@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: route add -net 172.20 add wrong host address
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         183687
>Category:       bin
>Synopsis:       [patch] route(8): route add -net 172.20 add wrong host address
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-net
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Nov 05 17:20:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Mon Nov 11 00:58:04 UTC 2013
>Originator:     Hiroshi Yamashita
>Release:        9.2
>Organization:
>Environment:
FreeBSD fsrv1 9.2-RELEASE FreeBSD 9.2-RELEASE #0 r255898: Thu Sep 26 22:50:31 UTC 2013     root@bake.isc.freebsd.org:/usr/obj/usr/src/sys/GENERIC  amd64
>Description:
route add -net 172.20 add wrong host address

fsrv1# route add -net 172.20 192.168.1.80
add net 172.20: gateway 192.168.1.80

fsrv1#netstat -rn
Internet:
Destination        Gateway            Flags    Refs      Use  Netif Expire
172.0.0.20         192.168.1.80       UGS         0        0    em0

another host 8.4-RELEASE 

root@pt2# route add -net 172.20 192.168.1.80
add net 172.20: gateway 192.168.1.80
root@pt2# netstat -rn
Routing tables

Internet:
Destination        Gateway            Flags    Refs      Use  Netif Expire
172.20.0.0/16      192.168.1.80       UGS         0        0    re0
root@pt2# uname -a
FreeBSD pt2 8.4-RELEASE-p2 FreeBSD 8.4-RELEASE-p2 #9: Sun Jul 28 02:00:51 JST 2013     piro@pt2:/
>How-To-Repeat:
always in 9.2-RELEASE
>Fix:
diff --git a/route.c b/route.c
index 3549e1a..21ff963 100644
--- a/route.c
+++ b/route.c
@@ -1244,7 +1244,7 @@ getaddr(int which, char *str, struct hostent **hpp, int nrflags)
                 */
                switch (which) {
                case RTA_DST:
-                       forcenet++;
+                       nrflags |= F_FORCENET;
 #if 0
                        bzero(su, sizeof(*su)); /* for readability */
 #endif
@@ -1333,7 +1333,7 @@ getaddr(int which, char *str, struct hostent **hpp, int nrflags)
                }
                *q = '/';
        }
-       if ((which != RTA_DST || forcenet == 0) &&
+       if ((which != RTA_DST || !(nrflags & F_FORCENET)) &&
            inet_aton(str, &su->sin.sin_addr)) {
                val = su->sin.sin_addr.s_addr;
                if (which != RTA_DST || forcehost ||
~


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Mon Nov 11 00:57:28 UTC 2013 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=183687 
>Unformatted:
