From 5d95b8a1326cf513153ef369316c1f85618776af Mon Sep 17 00:00:00 2001 From: julian Date: Fri, 9 Aug 1996 22:52:02 +0000 Subject: Reviewed by: julian Submitted by: archie@whistle.com This patch allows true interface routing to be controlled from the command line.. you can now do: route add default -interface ppp0 even if you have no clue what the address at the other end is.. this is part of a set of changes that allow true "unnumbered links" such as netcom run between their sites.. In practice you should assign the address from one of your ethernet interfaces to the local side of the P2P link so that IP doesn't say that the packet comes from 255.255.255.255, but there is no need whatsoever to assign an address of any kind to the remote end of the link.. useful for frame relay links etc also. --- sbin/route/Makefile | 2 +- sbin/route/route.8 | 2 ++ sbin/route/route.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 2 deletions(-) (limited to 'sbin') diff --git a/sbin/route/Makefile b/sbin/route/Makefile index 5a67eda..af97fc0 100644 --- a/sbin/route/Makefile +++ b/sbin/route/Makefile @@ -3,7 +3,7 @@ PROG= route MAN8= route.8 SRCS= route.c keywords.h # ccitt_addr.h -CFLAGS+=-I. +CFLAGS+=-I. -Wall CLEANFILES+=keywords.h BINOWN= root BINMODE=4555 diff --git a/sbin/route/route.8 b/sbin/route/route.8 index 42b2678..be13a70 100644 --- a/sbin/route/route.8 +++ b/sbin/route/route.8 @@ -177,6 +177,8 @@ no intermediary system to act as a gateway, the modifier should be specified; the gateway given is the address of this host on the common network, indicating the interface to be used for transmission. +If the interface point to point, the name of the interface +itself may be given instead. .Pp The optional modifiers .Fl xns , diff --git a/sbin/route/route.c b/sbin/route/route.c index b2d1eb8..a823569 100644 --- a/sbin/route/route.c +++ b/sbin/route/route.c @@ -43,7 +43,7 @@ static const char copyright[] = static char sccsid[] = "@(#)route.c 8.3 (Berkeley) 3/19/94"; */ static const char rcsid[] = - "$Id: route.c,v 1.10 1996/07/23 01:18:47 julian Exp $"; + "$Id: route.c,v 1.11 1996/07/23 22:00:14 julian Exp $"; #endif /* not lint */ #include @@ -827,6 +827,48 @@ getaddr(which, s, hpp) break; case RTA_GATEWAY: su = &so_gate; + if (iflag) { + #define MAX_IFACES 400 + int sock; + struct ifreq iflist[MAX_IFACES]; + struct ifconf ifconf; + struct ifreq *ifr, *ifr_end; + struct sockaddr_dl *dl, *sdl = NULL; + + /* Get socket */ + if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) < 0) + err(1, "socket"); + + /* Get interface list */ + ifconf.ifc_req = iflist; + ifconf.ifc_len = sizeof(iflist); + if (ioctl(sock, SIOCGIFCONF, &ifconf) < 0) + err(1, "ioctl(SIOCGIFCONF)"); + close(sock); + + /* Look for this interface in the list */ + for (ifr = ifconf.ifc_req, + ifr_end = (struct ifreq *) + (ifconf.ifc_buf + ifconf.ifc_len); + ifr < ifr_end; + ifr = (struct ifreq *) ((char *) &ifr->ifr_addr + + ifr->ifr_addr.sa_len)) { + dl = (struct sockaddr_dl *)&ifr->ifr_addr; + if (ifr->ifr_addr.sa_family == AF_LINK + && (ifr->ifr_flags & IFF_POINTOPOINT) + && !strncmp(s, dl->sdl_data, dl->sdl_nlen) + && s[dl->sdl_nlen] == 0) { + sdl = dl; + break; + } + } + + /* If we found it, then use it */ + if (sdl) { + su->sdl = *sdl; + return(1); + } + } su->sa.sa_family = af; break; case RTA_NETMASK: -- cgit v1.1