tech-net archive

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

route command cannot set up route through point-to-point interface



Hello, tech-net.

Netbsd's route command seems to reject route through point-to-point
interface.

I checked out difference of the source code between netbsd and
freebsd, and maked following patch.

Can anybody give me comments, or merge the patch?

-
Takashi Sogabe (sogabe%iij.ad.jp@localhost)
Internet Initiative Japan., Inc.
SEIL Business Unit  Tel: +81-3-5205-6455

Index: route.c
===================================================================
RCS file: /cvsroot/src/sbin/route/route.c,v
retrieving revision 1.119
diff -u -r1.119 route.c
--- route.c     28 Dec 2008 20:12:31 -0000      1.119
+++ route.c     30 Jul 2009 07:29:57 -0000
@@ -64,6 +64,7 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <ctype.h>
+#include <ifaddrs.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
@@ -1119,6 +1120,35 @@
                break;
        case RTA_GATEWAY:
                su = &soup->so_gate;
+               if (iflag) {
+                       struct ifaddrs *ifap, *ifa;
+                       struct sockaddr_dl *sdl = NULL;
+
+                       if (getifaddrs(&ifap))
+                               err(1, "getifaddrs");
+                       for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+                               if (ifa->ifa_addr->sa_family != AF_LINK)
+                                       continue;
+
+                               if (strcmp(s, ifa->ifa_name))
+                                       continue;
+
+                               sdl = (struct sockaddr_dl *)ifa->ifa_addr;
+                       }
+                       /* If we found it, then use it */
+                       if (sdl) {
+                               /*
+                                * Copy is safe since we have a
+                                * sockaddr_storage member in sockunion{}.
+                                * Note that we need to copy before calling
+                                * freeifaddrs().
+                                */
+                               memcpy(&su->sdl, sdl, sdl->sdl_len);
+                       }
+                       freeifaddrs(ifap);
+                       if (sdl)
+                               return(1);
+               }
                break;
        case RTA_NETMASK:
                su = &soup->so_mask;

================



Home | Main Index | Thread Index | Old Index