BSD 4_3_Reno release
[unix-history] / usr / src / sys / net / route.c
index 5896b05..676a6e6 100644 (file)
@@ -2,27 +2,28 @@
  * Copyright (c) 1980, 1986 Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1980, 1986 Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * Redistribution is only permitted until one year after the first shipment
+ * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
+ * binary forms are permitted provided that: (1) source distributions retain
+ * this entire copyright notice and comment, and (2) distributions including
+ * binaries display the following acknowledgement:  This product includes
+ * software developed by the University of California, Berkeley and its
+ * contributors'' in the documentation or other materials provided with the
+ * distribution and in all advertising materials mentioning features or use
+ * of this software.  Neither the name of the University nor the names of
+ * its contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  *
- *     @(#)route.c     7.8 (Berkeley) %G%
+ *     @(#)route.c     7.17 (Berkeley) 6/28/90
  */
  */
-#include "../machine/reg.h"
+#include "machine/reg.h"
  
 #include "param.h"
 #include "systm.h"
  
 #include "param.h"
 #include "systm.h"
-#include "dir.h"
 #include "user.h"
 #include "user.h"
-#include "inode.h"
 #include "proc.h"
 #include "mbuf.h"
 #include "socket.h"
 #include "proc.h"
 #include "mbuf.h"
 #include "socket.h"
 #include "../netinet/in.h"
 #include "../netinet/in_var.h"
 
 #include "../netinet/in.h"
 #include "../netinet/in_var.h"
 
-#include "../machine/mtpr.h"
+#include "../netns/ns.h"
+#include "machine/mtpr.h"
 #include "netisr.h"
 #include "netisr.h"
-
-#include "rtsock.c"
+#define        SA(p) ((struct sockaddr *)(p))
 
 int    rttrash;                /* routes not in table but not freed */
 struct sockaddr wildcard;      /* zero valued cookie for wildcard searches */
 
 int    rttrash;                /* routes not in table but not freed */
 struct sockaddr wildcard;      /* zero valued cookie for wildcard searches */
@@ -72,40 +73,44 @@ rtalloc(ro)
 
 struct rtentry *
 rtalloc1(dst, report)
 
 struct rtentry *
 rtalloc1(dst, report)
-       struct sockaddr *dst;
+       register struct sockaddr *dst;
        int  report;
 {
        register struct radix_node_head *rnh;
        int  report;
 {
        register struct radix_node_head *rnh;
+       register struct rtentry *rt;
        register struct radix_node *rn;
        register struct radix_node *rn;
-       register struct rtentry *rt = 0;
-       u_char af = dst->sa_family;
-       int  s = splnet();
+       struct rtentry *newrt = 0;
+       int  s = splnet(), err = 0;
 
 
-       for (rnh = radix_node_head; rnh && (af != rnh->rnh_af); )
+       for (rnh = radix_node_head; rnh && (dst->sa_family != rnh->rnh_af); )
                rnh = rnh->rnh_next;
        if (rnh && rnh->rnh_treetop &&
            (rn = rn_match((caddr_t)dst, rnh->rnh_treetop)) &&
            ((rn->rn_flags & RNF_ROOT) == 0)) {
                rnh = rnh->rnh_next;
        if (rnh && rnh->rnh_treetop &&
            (rn = rn_match((caddr_t)dst, rnh->rnh_treetop)) &&
            ((rn->rn_flags & RNF_ROOT) == 0)) {
-               rt = (struct rtentry *)rn;
-               rt->rt_refcnt++;
+               newrt = rt = (struct rtentry *)rn;
+               if (report && (rt->rt_flags & RTF_CLONING)) {
+                       if (err = rtrequest(RTM_RESOLVE, dst, SA(0),
+                                             SA(0), 0, &newrt))
+                               goto miss;
+               } else
+                       rt->rt_refcnt++;
        } else {
                rtstat.rts_unreach++;
        } else {
                rtstat.rts_unreach++;
-               if (report && route_cb.any_count)
-                       rt_missmsg(RTM_MISS, dst, (struct sockaddr *)0,
-                              (struct sockaddr *)0, (struct sockaddr *)0, 0);
+       miss:   if (report)
+                       rt_missmsg(RTM_MISS, dst, SA(0), SA(0), SA(0), 0, err);
        }
        splx(s);
        }
        splx(s);
-       return (rt);
+       return (newrt);
 }
 
 rtfree(rt)
        register struct rtentry *rt;
 {
 }
 
 rtfree(rt)
        register struct rtentry *rt;
 {
-       u_char *af;
+       register struct ifaddr *ifa;
        if (rt == 0)
                panic("rtfree");
        rt->rt_refcnt--;
        if (rt == 0)
                panic("rtfree");
        rt->rt_refcnt--;
-       if (rt->rt_refcnt <= 0 && (rt->rt_flags&RTF_UP) == 0) {
+       if (rt->rt_refcnt <= 0 && (rt->rt_flags & RTF_UP) == 0) {
                rttrash--;
                if (rt->rt_nodes->rn_flags & (RNF_ACTIVE | RNF_ROOT))
                        panic ("rtfree 2");
                rttrash--;
                if (rt->rt_nodes->rn_flags & (RNF_ACTIVE | RNF_ROOT))
                        panic ("rtfree 2");
@@ -122,61 +127,42 @@ rtfree(rt)
  * N.B.: must be called at splnet
  *
  */
  * N.B.: must be called at splnet
  *
  */
-rtredirect(dst, gateway, netmask, flags, src)
-       struct sockaddr *dst, *gateway, *src;
+rtredirect(dst, gateway, netmask, flags, src, rtp)
+       struct sockaddr *dst, *gateway, *netmask, *src;
        int flags;
        int flags;
+       struct rtentry **rtp;
 {
        register struct rtentry *rt;
 {
        register struct rtentry *rt;
+       int error = 0;
+       short *stat = 0;
 
        /* verify the gateway is directly reachable */
        if (ifa_ifwithnet(gateway) == 0) {
 
        /* verify the gateway is directly reachable */
        if (ifa_ifwithnet(gateway) == 0) {
-               rtstat.rts_badredirect++;
-               return;
+               error = ENETUNREACH;
+               goto done;
        }
        }
-       rt = rtalloc1(dst, 1);
-#define        equal(a1, a2) \
-  (bcmp((caddr_t)(a1), (caddr_t)(a2), ((struct sockaddr *)(a1))->sa_len) == 0)
+       rt = rtalloc1(dst, 0);
        /*
         * If the redirect isn't from our current router for this dst,
         * it's either old or wrong.  If it redirects us to ourselves,
         * we have a routing loop, perhaps as a result of an interface
         * going down recently.
         */
        /*
         * If the redirect isn't from our current router for this dst,
         * it's either old or wrong.  If it redirects us to ourselves,
         * we have a routing loop, perhaps as a result of an interface
         * going down recently.
         */
-       if ((rt && !equal(src, &rt->rt_gateway)) || ifa_ifwithaddr(gateway)) {
-               rtstat.rts_badredirect++;
-               if (rt)
-                       rtfree(rt);
-               return;
-       }
+#define        equal(a1, a2) (bcmp((caddr_t)(a1), (caddr_t)(a2), (a1)->sa_len) == 0)
+       if (!(flags & RTF_DONE) && rt && !equal(src, rt->rt_gateway))
+               error = EINVAL;
+       else if (ifa_ifwithaddr(gateway))
+               error = EHOSTUNREACH;
+       if (error)
+               goto done;
        /*
        /*
-        * Old comment:
         * Create a new entry if we just got back a wildcard entry
         * or the the lookup failed.  This is necessary for hosts
         * which use routing redirects generated by smart gateways
         * to dynamically build the routing tables.
         * Create a new entry if we just got back a wildcard entry
         * or the the lookup failed.  This is necessary for hosts
         * which use routing redirects generated by smart gateways
         * to dynamically build the routing tables.
-        *
-        * New comment:
-        * If we survived the previous tests, it doesn't matter
-        * what sort of entry we got when we looked it up;
-        * we should just go ahead and free the reference to
-        * the route we created.  rtalloc will not give a
-        * pointer to the root node.  And if we got a pointer
-        * to a default gateway, we should free the reference
-        * in any case.
-       if (rt) {
-               rtfree(rt);
-               rt = 0;
-       }
-       if (route_cb.any_count)
-               rt_missmsg(RTM_REDIRECT, dst, gateway, netmask, src,
-                               (flags & RTF_HOST) | RTF_GATEWAY | RTF_DYNAMIC);
         */
         */
-       if (rt == 0) {
-               rtrequest((int)RTM_ADD, dst, gateway, 0,
-                   (flags & RTF_HOST) | RTF_GATEWAY | RTF_DYNAMIC, 0);
-               rtstat.rts_dynamic++;
-               return;
-       }
+       if ((rt == 0) || (rt_mask(rt) && rt_mask(rt)->sa_len < 2))
+               goto create;
        /*
         * Don't listen to the redirect if it's
         * for a route to an interface. 
        /*
         * Don't listen to the redirect if it's
         * for a route to an interface. 
@@ -187,29 +173,44 @@ rtredirect(dst, gateway, netmask, flags, src)
                         * Changing from route to net => route to host.
                         * Create new route, rather than smashing route to net.
                         */
                         * Changing from route to net => route to host.
                         * Create new route, rather than smashing route to net.
                         */
-                       rtrequest((int)RTM_ADD, dst, gateway, 0,
-                           (flags & RTF_HOST) | RTF_GATEWAY | RTF_DYNAMIC, 0);
-                       rtstat.rts_dynamic++;
+               create:
+                       flags |=  RTF_GATEWAY | RTF_DYNAMIC;
+                       error = rtrequest((int)RTM_ADD, dst, gateway,
+                                   SA(0), flags,
+                                   (struct rtentry **)0);
+                       stat = &rtstat.rts_dynamic;
                } else {
                        /*
                         * Smash the current notion of the gateway to
                } else {
                        /*
                         * Smash the current notion of the gateway to
-                        * this destination.
+                        * this destination.  Should check about netmask!!!
                         */
                        if (gateway->sa_len <= rt->rt_gateway->sa_len) {
                                Bcopy(gateway, rt->rt_gateway, gateway->sa_len);
                                rt->rt_flags |= RTF_MODIFIED;
                         */
                        if (gateway->sa_len <= rt->rt_gateway->sa_len) {
                                Bcopy(gateway, rt->rt_gateway, gateway->sa_len);
                                rt->rt_flags |= RTF_MODIFIED;
-                               rtstat.rts_newgateway++;
+                               flags |= RTF_MODIFIED;
+                               stat = &rtstat.rts_newgateway;
                        } else
                        } else
-                               rtstat.rts_badredirect++;
+                               error = ENOSPC;
                }
        } else
                }
        } else
+               error = EHOSTUNREACH;
+done:
+       if (rt) {
+               if (rtp && !error)
+                       *rtp = rt;
+               else
+                       rtfree(rt);
+       }
+       if (error)
                rtstat.rts_badredirect++;
                rtstat.rts_badredirect++;
-       rtfree(rt);
+       else
+               (stat && (*stat)++);
+       rt_missmsg(RTM_REDIRECT, dst, gateway, netmask, src, flags, error);
 }
 
 /*
 }
 
 /*
- * Routing table ioctl interface.
- */
+* Routing table ioctl interface.
+*/
 rtioctl(req, data)
        int req;
        caddr_t data;
 rtioctl(req, data)
        int req;
        caddr_t data;
@@ -228,8 +229,8 @@ rtioctl(req, data)
        else
                return (EINVAL);
 
        else
                return (EINVAL);
 
-       if (!suser())
-               return (u.u_error);
+       if (error = suser(u.u_cred, &u.u_acflag))
+               return (error);
 #if BYTE_ORDER != BIG_ENDIAN
        if (entry->rt_dst.sa_family == 0 && entry->rt_dst.sa_len < 16) {
                entry->rt_dst.sa_family = entry->rt_dst.sa_len;
 #if BYTE_ORDER != BIG_ENDIAN
        if (entry->rt_dst.sa_family == 0 && entry->rt_dst.sa_len < 16) {
                entry->rt_dst.sa_family = entry->rt_dst.sa_len;
@@ -251,12 +252,10 @@ rtioctl(req, data)
                case AF_INET:
                        {
                                extern struct sockaddr_in icmpmask;
                case AF_INET:
                        {
                                extern struct sockaddr_in icmpmask;
-                               u_long in_maskof();
                                struct sockaddr_in *dst_in = 
                                        (struct sockaddr_in *)&entry->rt_dst;
                                struct sockaddr_in *dst_in = 
                                        (struct sockaddr_in *)&entry->rt_dst;
-                               u_long i = ntohl(dst_in->sin_addr.s_addr);
 
 
-                               icmpmask.sin_addr.s_addr = ntohl(in_maskof(i));
+                               in_sockmaskof(dst_in->sin_addr, &icmpmask);
                                netmask = (struct sockaddr *)&icmpmask;
                        }
                        break;
                                netmask = (struct sockaddr *)&icmpmask;
                        }
                        break;
@@ -270,14 +269,48 @@ rtioctl(req, data)
 #endif
                }
        error =  rtrequest(req, &(entry->rt_dst), &(entry->rt_gateway), netmask,
 #endif
                }
        error =  rtrequest(req, &(entry->rt_dst), &(entry->rt_gateway), netmask,
-                                       entry->rt_flags, 0);
+                               entry->rt_flags, (struct rtentry **)0);
        rt_missmsg((req == RTM_ADD ? RTM_OLDADD : RTM_OLDDEL),
                   &(entry->rt_dst), &(entry->rt_gateway),
        rt_missmsg((req == RTM_ADD ? RTM_OLDADD : RTM_OLDDEL),
                   &(entry->rt_dst), &(entry->rt_gateway),
-                  netmask, (struct sockaddr *)error, entry->rt_flags);
+                  netmask, SA(0), entry->rt_flags, error);
        return (error);
 #endif
 }
 
        return (error);
 #endif
 }
 
+struct ifaddr *
+ifa_ifwithroute(flags, dst, gateway)
+int    flags;
+struct sockaddr        *dst, *gateway;
+{
+       struct ifaddr *ifa;
+       if ((flags & RTF_GATEWAY) == 0) {
+               /*
+                * If we are adding a route to an interface,
+                * and the interface is a pt to pt link
+                * we should search for the destination
+                * as our clue to the interface.  Otherwise
+                * we can use the local address.
+                */
+               ifa = 0;
+               if (flags & RTF_HOST) 
+                       ifa = ifa_ifwithdstaddr(dst);
+               if (ifa == 0)
+                       ifa = ifa_ifwithaddr(gateway);
+       } else {
+               /*
+                * If we are adding a route to a remote net
+                * or host, the gateway may still be on the
+                * other end of a pt to pt link.
+                */
+               ifa = ifa_ifwithdstaddr(gateway);
+       }
+       if (ifa == 0)
+               ifa = ifa_ifwithnet(gateway);
+       return (ifa);
+}
+
+#define ROUNDUP(a) (1 + (((a) - 1) | (sizeof(long) - 1)))
+
 rtrequest(req, dst, gateway, netmask, flags, ret_nrt)
        int req, flags;
        struct sockaddr *dst, *gateway, *netmask;
 rtrequest(req, dst, gateway, netmask, flags, ret_nrt)
        int req, flags;
        struct sockaddr *dst, *gateway, *netmask;
@@ -288,95 +321,109 @@ rtrequest(req, dst, gateway, netmask, flags, ret_nrt)
        register struct radix_node *rn;
        register struct radix_node_head *rnh;
        struct ifaddr *ifa, *ifa_ifwithdstaddr();
        register struct radix_node *rn;
        register struct radix_node_head *rnh;
        struct ifaddr *ifa, *ifa_ifwithdstaddr();
+       struct sockaddr *ndst;
        u_char af = dst->sa_family;
        u_char af = dst->sa_family;
+#define senderr(x) { error = x ; goto bad; }
 
        if (rtinits_done == 0)
                rtinitheads();
        for (rnh = radix_node_head; rnh && (af != rnh->rnh_af); )
                rnh = rnh->rnh_next;
 
        if (rtinits_done == 0)
                rtinitheads();
        for (rnh = radix_node_head; rnh && (af != rnh->rnh_af); )
                rnh = rnh->rnh_next;
-       if (rnh == 0) {
-               error = ESRCH;
-               goto bad;
-       }
+       if (rnh == 0)
+               senderr(ESRCH);
+       if (flags & RTF_HOST)
+               netmask = 0;
        switch (req) {
        case RTM_DELETE:
        switch (req) {
        case RTM_DELETE:
-               if ((rn = rn_delete((caddr_t)dst, (caddr_t)netmask, 
-                                       rnh->rnh_treetop)) == 0) {
-                       error = ESRCH;
-                       goto bad;
+               if (ret_nrt && (rt = *ret_nrt)) {
+                       RTFREE(rt);
+                       *ret_nrt = 0;
                }
                }
+               if ((rn = rn_delete((caddr_t)dst, (caddr_t)netmask, 
+                                       rnh->rnh_treetop)) == 0)
+                       senderr(ESRCH);
                if (rn->rn_flags & (RNF_ACTIVE | RNF_ROOT))
                        panic ("rtrequest delete");
                rt = (struct rtentry *)rn;
                rt->rt_flags &= ~RTF_UP;
                if (rn->rn_flags & (RNF_ACTIVE | RNF_ROOT))
                        panic ("rtrequest delete");
                rt = (struct rtentry *)rn;
                rt->rt_flags &= ~RTF_UP;
-               if (rt->rt_refcnt > 0)
-                       rttrash++;
-               else 
-                       free((caddr_t)rt, M_RTABLE);
+               if ((ifa = rt->rt_ifa) && ifa->ifa_rtrequest)
+                       ifa->ifa_rtrequest(RTM_DELETE, rt, SA(0));
+               rttrash++;
+               if (rt->rt_refcnt <= 0)
+                       rtfree(rt);
                break;
 
                break;
 
+       case RTM_RESOLVE:
+               if (ret_nrt == 0 || (rt = *ret_nrt) == 0)
+                       senderr(EINVAL);
+               ifa = rt->rt_ifa;
+               flags = rt->rt_flags & ~RTF_CLONING;
+               gateway = rt->rt_gateway;
+               if ((netmask = rt->rt_genmask) == 0)
+                       flags |= RTF_HOST;
+               goto makeroute;
+
        case RTM_ADD:
        case RTM_ADD:
-               if ((flags & RTF_GATEWAY) == 0) {
-                       /*
-                        * If we are adding a route to an interface,
-                        * and the interface is a pt to pt link
-                        * we should search for the destination
-                        * as our clue to the interface.  Otherwise
-                        * we can use the local address.
-                        */
-                       ifa = 0;
-                       if (flags & RTF_HOST) 
-                               ifa = ifa_ifwithdstaddr(dst);
-                       if (ifa == 0)
-                               ifa = ifa_ifwithaddr(gateway);
-               } else {
-                       /*
-                        * If we are adding a route to a remote net
-                        * or host, the gateway may still be on the
-                        * other end of a pt to pt link.
-                        */
-                       ifa = ifa_ifwithdstaddr(gateway);
-               }
-               if (ifa == 0) {
-                       ifa = ifa_ifwithnet(gateway);
-                       if (ifa == 0 && req == RTM_ADD) {
-                               error = ENETUNREACH;
-                               goto bad;
-                       }
-               }
+               if ((ifa = ifa_ifwithroute(flags, dst, gateway)) == 0)
+                       senderr(ENETUNREACH);
+       makeroute:
                len = sizeof (*rt) + ROUNDUP(gateway->sa_len)
                len = sizeof (*rt) + ROUNDUP(gateway->sa_len)
-                                               + ROUNDUP(dst->sa_len);
+                   + ROUNDUP(dst->sa_len);
                R_Malloc(rt, struct rtentry *, len);
                R_Malloc(rt, struct rtentry *, len);
-               if (rt == 0) {
-                       error = ENOBUFS;
-                       goto bad;
-               }
+               if (rt == 0)
+                       senderr(ENOBUFS);
                Bzero(rt, len);
                Bzero(rt, len);
-               rn = rn_addroute((caddr_t)dst, (caddr_t)netmask,
+               ndst = (struct sockaddr *)(rt + 1);
+               if (netmask) {
+                       rt_maskedcopy(dst, ndst, netmask);
+               } else
+                       Bcopy(dst, ndst, dst->sa_len);
+               rn = rn_addroute((caddr_t)ndst, (caddr_t)netmask,
                                        rnh->rnh_treetop, rt->rt_nodes);
                if (rn == 0) {
                        free((caddr_t)rt, M_RTABLE);
                                        rnh->rnh_treetop, rt->rt_nodes);
                if (rn == 0) {
                        free((caddr_t)rt, M_RTABLE);
-                       error = EEXIST;
-                       goto bad;
+                       senderr(EEXIST);
                }
                }
-               if (ret_nrt)
-                       *ret_nrt = rt; /* == (struct rtentry *)rn */
+               rt->rt_ifa = ifa;
                rt->rt_ifp = ifa->ifa_ifp;
                rt->rt_ifp = ifa->ifa_ifp;
-               rt->rt_use = 0;
-               rt->rt_refcnt = 0;
-               rt->rt_flags = RTF_UP |
-                   (flags & (RTF_HOST|RTF_GATEWAY|RTF_DYNAMIC));
-               rn->rn_key = (caddr_t) (rt + 1); /* == rt_dst */
-               Bcopy(dst, rn->rn_key, dst->sa_len);
+               rt->rt_flags = RTF_UP | flags;
+               rn->rn_key = (caddr_t) ndst; /* == rt_dst */
                rt->rt_gateway = (struct sockaddr *)
                                        (rn->rn_key + ROUNDUP(dst->sa_len));
                Bcopy(gateway, rt->rt_gateway, gateway->sa_len);
                rt->rt_gateway = (struct sockaddr *)
                                        (rn->rn_key + ROUNDUP(dst->sa_len));
                Bcopy(gateway, rt->rt_gateway, gateway->sa_len);
+               if (req == RTM_RESOLVE)
+                       rt->rt_rmx = (*ret_nrt)->rt_rmx; /* copy metrics */
+               if (ifa->ifa_rtrequest)
+                       ifa->ifa_rtrequest(req, rt, SA(ret_nrt ? *ret_nrt : 0));
+               if (ret_nrt) {
+                       *ret_nrt = rt;
+                       rt->rt_refcnt++;
+               }
                break;
        }
 bad:
        splx(s);
        return (error);
 }
                break;
        }
 bad:
        splx(s);
        return (error);
 }
+
+rt_maskedcopy(src, dst, netmask)
+struct sockaddr *src, *dst, *netmask;
+{
+       register u_char *cp1 = (u_char *)src;
+       register u_char *cp2 = (u_char *)dst;
+       register u_char *cp3 = (u_char *)netmask;
+       u_char *cplim = cp2 + *cp3;
+       u_char *cplim2 = cp2 + *cp1;
+
+       *cp2++ = *cp1++; *cp2++ = *cp1++; /* copies sa_len & sa_family */
+       cp3 += 2;
+       if (cplim > cplim2)
+               cplim = cplim2;
+       while (cp2 < cplim)
+               *cp2++ = *cp1++ & *cp3++;
+       if (cp2 < cplim2)
+               bzero((caddr_t)cp2, (unsigned)(cplim2 - cp2));
+}
 /*
  * Set up a routing table entry, normally
  * for an interface.
 /*
  * Set up a routing table entry, normally
  * for an interface.
@@ -385,33 +432,6 @@ rtinit(ifa, cmd, flags)
        register struct ifaddr *ifa;
        int cmd, flags;
 {
        register struct ifaddr *ifa;
        int cmd, flags;
 {
-       struct sockaddr net, *netp;
-       register caddr_t cp, cp2, cp3;
-       caddr_t cplim, freeit = 0;
-       int len;
-
-       if (flags & RTF_HOST || ifa->ifa_netmask == 0) {
-               (void) rtrequest(cmd, ifa->ifa_dstaddr, ifa->ifa_addr,
-                                                               0, flags, 0);
-       } else {
-               if ((len = ifa->ifa_addr->sa_len) >= sizeof (net)) {
-                       R_Malloc(freeit, caddr_t, len);
-                       if (freeit == 0)
-                               return;
-                       netp = (struct sockaddr *)freeit;
-               }
-               netp->sa_len = len;
-               cp2 = 1 + (caddr_t)ifa->ifa_addr;
-               netp->sa_family = *cp2++;
-               cp3 = (caddr_t) ifa->ifa_netmask->sa_data;
-               cp = (caddr_t) netp->sa_data;
-               cplim = cp + len - 2;
-               while (cp < cplim)
-                       *cp++ = *cp2++ & *cp3++;
-               (void) rtrequest(cmd, netp, ifa->ifa_addr, ifa->ifa_netmask,
-                                       flags, 0);
-               if (freeit)
-                       Free(freeit);
-       }
+       return rtrequest(cmd, ifa->ifa_dstaddr, ifa->ifa_addr,
+                   ifa->ifa_netmask, flags | ifa->ifa_flags, &ifa->ifa_rt);
 }
 }
-#include "radix.c"