Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/net Remove rt_ifa_localrequest().



details:   https://anonhg.NetBSD.org/src/rev/0c287910750f
branches:  trunk
changeset: 340870:0c287910750f
user:      roy <roy%NetBSD.org@localhost>
date:      Wed Oct 07 09:44:26 2015 +0000

description:
Remove rt_ifa_localrequest().
In it's place, use rtrequest1() inside rt_ifa_addlocal() and
rtdeletemsg() inside rt_ifa_remlocal().

This removes the need for INET/INET6 specific code and allows
greater control over the creation of the local address route.

diffstat:

 sys/net/route.c |  79 ++++++++++++++++++--------------------------------------
 1 files changed, 26 insertions(+), 53 deletions(-)

diffs (114 lines):

diff -r 6d0d1297900a -r 0c287910750f sys/net/route.c
--- a/sys/net/route.c   Wed Oct 07 08:48:04 2015 +0000
+++ b/sys/net/route.c   Wed Oct 07 09:44:26 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: route.c,v 1.151 2015/09/03 02:04:31 ozaki-r Exp $      */
+/*     $NetBSD: route.c,v 1.152 2015/10/07 09:44:26 roy Exp $  */
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.151 2015/09/03 02:04:31 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.152 2015/10/07 09:44:26 roy Exp $");
 
 #include <sys/param.h>
 #ifdef RTFLUSH_DEBUG
@@ -1106,52 +1106,6 @@
        return error;
 }
 
-static const struct in_addr inmask32 = {.s_addr = INADDR_BROADCAST};
-
-/* Subroutine for rt_ifa_addlocal() and rt_ifa_remlocal() */
-static int
-rt_ifa_localrequest(int cmd, struct ifaddr *ifa)
-{
-       struct sockaddr *all1_sa;
-       struct sockaddr_in all1_sin;
-#ifdef INET6
-       struct sockaddr_in6 all1_sin6;
-#endif
-       struct rtentry *nrt = NULL;
-       int flags, e;
-
-       switch(ifa->ifa_addr->sa_family) {
-       case AF_INET:
-               sockaddr_in_init(&all1_sin, &inmask32, 0);
-               all1_sa = (struct sockaddr *)&all1_sin;
-               break;
-#ifdef INET6
-       case AF_INET6:
-               sockaddr_in6_init(&all1_sin6, &in6mask128, 0, 0, 0);
-               all1_sa = (struct sockaddr *)&all1_sin6;
-               break;
-#endif
-       default:
-               return 0;
-       }
-
-       flags = RTF_UP | RTF_HOST | RTF_LOCAL;
-       if (!(ifa->ifa_ifp->if_flags & (IFF_LOOPBACK | IFF_POINTOPOINT)))
-               flags |= RTF_LLINFO;
-       e = rtrequest(cmd, ifa->ifa_addr, ifa->ifa_addr, all1_sa, flags, &nrt);
-
-       /* Make sure rt_ifa be equal to IFA, the second argument of the
-        * function. */
-       if (cmd == RTM_ADD && nrt && ifa != nrt->rt_ifa)
-               rt_replace_ifa(nrt, ifa);
-
-       rt_newaddrmsg(cmd, ifa, e, nrt);
-       if (nrt != NULL)
-               rtfree(nrt);
-
-       return e;
-}
-
 /*
  * Create a local route entry for the address.
  * Announce the addition of the address and the route to the routing socket.
@@ -1166,8 +1120,26 @@
        rt = rtalloc1(ifa->ifa_addr, 0);
        if (rt == NULL || (rt->rt_flags & RTF_HOST) == 0 ||
            (rt->rt_ifp->if_flags & IFF_LOOPBACK) == 0)
-               e = rt_ifa_localrequest(RTM_ADD, ifa);
-       else {
+       {
+               struct rt_addrinfo info;
+               struct rtentry *nrt;
+
+               memset(&info, 0, sizeof(info));
+               info.rti_flags = RTF_HOST | RTF_LOCAL;
+               if (!(ifa->ifa_ifp->if_flags & (IFF_LOOPBACK|IFF_POINTOPOINT)))
+                       info.rti_flags |= RTF_LLINFO;
+               info.rti_info[RTAX_DST] = ifa->ifa_addr;
+               info.rti_info[RTAX_GATEWAY] =
+                   (const struct sockaddr *)ifa->ifa_ifp->if_sadl;
+               info.rti_ifa = ifa;
+               nrt = NULL;
+               e = rtrequest1(RTM_ADD, &info, &nrt);
+               if (nrt && ifa != nrt->rt_ifa)
+                       rt_replace_ifa(nrt, ifa);
+               rt_newaddrmsg(RTM_ADD, ifa, e, nrt);
+               if (nrt != NULL)
+                       rtfree(nrt);
+       } else {
                e = 0;
                rt_newaddrmsg(RTM_NEWADDR, ifa, 0, NULL);
        }
@@ -1204,9 +1176,10 @@
                 * ifaddr of another interface, I believe it is safest to
                 * delete the route.
                 */
-               if (alt_ifa == NULL)
-                       e = rt_ifa_localrequest(RTM_DELETE, ifa);
-               else {
+               if (alt_ifa == NULL) {
+                       e = rtdeletemsg(rt);
+                       rt_newaddrmsg(RTM_DELADDR, ifa, 0, NULL);
+               } else {
                        rt_replace_ifa(rt, alt_ifa);
                        rt_newmsg(RTM_CHANGE, rt);
                }



Home | Main Index | Thread Index | Old Index