From tbyte@shadow.otel.net  Sun Jun  3 02:52:49 2001
Return-Path: <tbyte@shadow.otel.net>
Received: from shadow.otel.net (JuDiCaToR.OTEL.net [212.36.9.113])
	by hub.freebsd.org (Postfix) with ESMTP id A19A037B403
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  3 Jun 2001 02:52:48 -0700 (PDT)
	(envelope-from tbyte@shadow.otel.net)
Received: (from tbyte@localhost)
	by shadow.otel.net (8.11.3/8.11.1) id f539qhc10077;
	Sun, 3 Jun 2001 12:52:43 +0300 (EEST)
	(envelope-from tbyte)
Message-Id: <200106030952.f539qhc10077@shadow.otel.net>
Date: Sun, 3 Jun 2001 12:52:43 +0300 (EEST)
From: tbyte@tbyte.org
Reply-To: tbyte@tbyte.org
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Adding default route
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         27852
>Category:       kern
>Synopsis:       Kernel can't add default route from network that none of its int
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    ru
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jun 03 03:00:01 PDT 2001
>Closed-Date:    Mon Jun 4 07:13:09 PDT 2001
>Last-Modified:  Mon Jun 04 07:13:59 PDT 2001
>Originator:     Iasen Kostoff
>Release:        FreeBSD 4.3-STABLE i386
>Organization:
OTEL.net
>Environment:
System: FreeBSD sat.fury.lan 4.3-STABLE FreeBSD 4.3-STABLE #13: Sun Jun 3 11:23:
>Description:
    You have one interface xl0 with ip 100.1.1.10 and netmask 255.255.255.0
    and your gateway is 150.1.1.1. To add this gateway you should add a
    route to this host lets say: route add -net 150.1.1.0/24 -iface xl0;
     and then we should add the default : route add default 150.1.1.1.
    That's the right way but what the kernel say ? - "Network Unreachable" ?!?
    But we have route to that network , aren't we ?
    And here is one way this could be done :
        route add default 100.1.1.10
        route add -net 150.1.1.0/24 -iface xl0
        route change default 150.1.1.1
    Wow everithing works ! :)
    But do you think that's the right way to be done ?
>How-To-Repeat:
        just try do add default gw from network that none of your
        interfaces is.
>Fix:
    I looked in the kernel source and found this in rtrequest :
        if ((ifa = ifa_ifwithroute(flags, dst, gateway)) == 0)
                            senderr(ENETUNREACH);
    ifa_ifwithroute() can't find a route that exest ?
    Then I look at ifa_ifwithroute() and saw this :
        if (ifa == 0) {
                    struct rtentry *rt = rtalloc1(dst, 0, 0UL);
    Why we search a route to a destination but not to a gateway ?
    I change it ofcourse and now everything works fine.
    And this is the changed line just one variable changed :
        if (ifa == 0) {
                    struct rtentry *rt = rtalloc1(gateway, 0, 0UL);

    And here is the patch (hum :)) for this :

--- route.c.old Thu May 17 02:14:03 2001
+++ route.c     Sun Jun  3 11:18:07 2001
@@ -425,7 +425,7 @@
        if (ifa == 0)
                ifa = ifa_ifwithnet(gateway);
        if (ifa == 0) {
-               struct rtentry *rt = rtalloc1(dst, 0, 0UL);
+               struct rtentry *rt = rtalloc1(gateway, 0, 0UL);
                if (rt == 0)
                        return (0);
                rt->rt_refcnt--;

    A long long patch. If you have any sugestions I'd like to hear it
    as soon as posible because there are some other things in the kernel
    routing that I want to discuss.

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: ru 
State-Changed-When: Mon Jun 4 07:13:09 PDT 2001 
State-Changed-Why:  
Committed, thanks!  MFC is planned in two weeks. 


Responsible-Changed-From-To: freebsd-bugs->ru 
Responsible-Changed-By: ru 
Responsible-Changed-When: Mon Jun 4 07:13:09 PDT 2001 
Responsible-Changed-Why:  

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=27852 
>Unformatted:
