Source-Changes-HG archive

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

[src/trunk]: src/sbin/ifconfig Split tunnel support into its own file.



details:   https://anonhg.NetBSD.org/src/rev/0b085b2016bc
branches:  trunk
changeset: 579616:0b085b2016bc
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Mar 19 17:32:26 2005 +0000

description:
Split tunnel support into its own file.

diffstat:

 sbin/ifconfig/Makefile   |    3 +-
 sbin/ifconfig/extern.h   |   17 ++++-
 sbin/ifconfig/ifconfig.c |  133 +------------------------------------
 sbin/ifconfig/tunnel.c   |  167 +++++++++++++++++++++++++++++++++++++++++++++++
 sbin/ifconfig/tunnel.h   |   34 +++++++++
 5 files changed, 223 insertions(+), 131 deletions(-)

diffs (truncated from 440 to 300 lines):

diff -r d172d7000c0d -r 0b085b2016bc sbin/ifconfig/Makefile
--- a/sbin/ifconfig/Makefile    Sat Mar 19 17:31:48 2005 +0000
+++ b/sbin/ifconfig/Makefile    Sat Mar 19 17:32:26 2005 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.19 2005/03/19 03:53:55 thorpej Exp $
+#      $NetBSD: Makefile,v 1.20 2005/03/19 17:32:26 thorpej Exp $
 #      @(#)Makefile    8.1 (Berkeley) 6/5/93
 
 .include <bsd.own.mk>
@@ -21,6 +21,7 @@
 
 SRCS= ifconfig.c 
 SRCS+= agr.c
+SRCS+= tunnel.c
 SRCS+= vlan.c
 
 .include <bsd.prog.mk>
diff -r d172d7000c0d -r 0b085b2016bc sbin/ifconfig/extern.h
--- a/sbin/ifconfig/extern.h    Sat Mar 19 17:31:48 2005 +0000
+++ b/sbin/ifconfig/extern.h    Sat Mar 19 17:32:26 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.1 2005/03/19 03:56:06 thorpej Exp $       */
+/*     $NetBSD: extern.h,v 1.2 2005/03/19 17:32:26 thorpej Exp $       */
 
 /*
  * Copyright (c) 1983, 1993
@@ -29,5 +29,20 @@
  * SUCH DAMAGE.
  */
 
+struct afswtch {
+       const char *af_name;
+       short af_af;
+       void (*af_status)(int);
+       void (*af_getaddr)(const char *, int);
+       void (*af_getprefix)(const char *, int);
+       u_long af_difaddr;
+       u_long af_aifaddr;
+       u_long af_gifaddr;
+       void *af_ridreq;
+       void *af_addreq;
+};
+
+extern struct afswtch *afp;
 extern struct ifreq ifr;
 extern int s;
+extern char name[30];
diff -r d172d7000c0d -r 0b085b2016bc sbin/ifconfig/ifconfig.c
--- a/sbin/ifconfig/ifconfig.c  Sat Mar 19 17:31:48 2005 +0000
+++ b/sbin/ifconfig/ifconfig.c  Sat Mar 19 17:32:26 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ifconfig.c,v 1.156 2005/03/19 03:56:06 thorpej Exp $   */
+/*     $NetBSD: ifconfig.c,v 1.157 2005/03/19 17:32:26 thorpej Exp $   */
 
 /*-
  * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
@@ -76,7 +76,7 @@
 #if 0
 static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
 #else
-__RCSID("$NetBSD: ifconfig.c,v 1.156 2005/03/19 03:56:06 thorpej Exp $");
+__RCSID("$NetBSD: ifconfig.c,v 1.157 2005/03/19 17:32:26 thorpej Exp $");
 #endif
 #endif /* not lint */
 
@@ -122,6 +122,7 @@
 
 #include "extern.h"
 #include "agr.h"
+#include "tunnel.h"
 #include "vlan.h"
 
 struct ifreq           ifr, ridreq;
@@ -177,8 +178,6 @@
 void   setsnpaoffset(const char *, int);
 void   setatrange(const char *, int);
 void   setatphase(const char *, int);
-void   settunnel(const char *, const char *);
-void   deletetunnel(const char *, int);
 #ifdef INET6
 void   setia6flags(const char *, int);
 void   setia6pltime(const char *, int);
@@ -363,21 +362,9 @@
 
 void   ieee80211_statistics(void);
 void   ieee80211_status(void);
-void   tunnel_status(void);
 
 /* Known address families */
-struct afswtch {
-       const char *af_name;
-       short af_af;
-       void (*af_status)(int);
-       void (*af_getaddr)(const char *, int);
-       void (*af_getprefix)(const char *, int);
-       u_long af_difaddr;
-       u_long af_aifaddr;
-       u_long af_gifaddr;
-       void *af_ridreq;
-       void *af_addreq;
-} afs[] = {
+struct afswtch afs[] = {
        { "inet", AF_INET, in_status, in_getaddr, in_getprefix,
             SIOCDIFADDR, SIOCAIFADDR, SIOCGIFADDR, &ridreq, &in_addreq },
 #ifdef INET6
@@ -897,82 +884,6 @@
 }
 
 void
-settunnel(const char *src, const char *dst)
-{
-       struct addrinfo hints, *srcres, *dstres;
-       int ecode;
-       struct if_laddrreq req;
-
-       memset(&hints, 0, sizeof(hints));
-       hints.ai_family = afp->af_af;
-       hints.ai_socktype = SOCK_DGRAM; /*dummy*/
-
-       if ((ecode = getaddrinfo(src, NULL, &hints, &srcres)) != 0)
-               errx(EXIT_FAILURE, "error in parsing address string: %s",
-                   gai_strerror(ecode));
-
-       if ((ecode = getaddrinfo(dst, NULL, &hints, &dstres)) != 0)
-               errx(EXIT_FAILURE, "error in parsing address string: %s",
-                   gai_strerror(ecode));
-
-       if (srcres->ai_addr->sa_family != dstres->ai_addr->sa_family)
-               errx(EXIT_FAILURE,
-                   "source and destination address families do not match");
-
-       if (srcres->ai_addrlen > sizeof(req.addr) ||
-           dstres->ai_addrlen > sizeof(req.dstaddr))
-               errx(EXIT_FAILURE, "invalid sockaddr");
-
-       memset(&req, 0, sizeof(req));
-       strncpy(req.iflr_name, name, sizeof(req.iflr_name));
-       memcpy(&req.addr, srcres->ai_addr, srcres->ai_addrlen);
-       memcpy(&req.dstaddr, dstres->ai_addr, dstres->ai_addrlen);
-
-#ifdef INET6
-       if (req.addr.ss_family == AF_INET6) {
-               struct sockaddr_in6 *s6, *d;
-
-               s6 = (struct sockaddr_in6 *)&req.addr;
-               d = (struct sockaddr_in6 *)&req.dstaddr;
-               if (s6->sin6_scope_id != d->sin6_scope_id) {
-                       errx(EXIT_FAILURE, "scope mismatch");
-                       /* NOTREACHED */
-               }
-#ifdef __KAME__
-               /* embed scopeid */
-               if (s6->sin6_scope_id && 
-                   (IN6_IS_ADDR_LINKLOCAL(&s6->sin6_addr) ||
-                    IN6_IS_ADDR_MC_LINKLOCAL(&s6->sin6_addr))) {
-                       *(u_int16_t *)&s6->sin6_addr.s6_addr[2] =
-                           htons(s6->sin6_scope_id);
-               }
-               if (d->sin6_scope_id && 
-                   (IN6_IS_ADDR_LINKLOCAL(&d->sin6_addr) ||
-                    IN6_IS_ADDR_MC_LINKLOCAL(&d->sin6_addr))) {
-                       *(u_int16_t *)&d->sin6_addr.s6_addr[2] =
-                           htons(d->sin6_scope_id);
-               }
-#endif
-       }
-#endif
-
-       if (ioctl(s, SIOCSLIFPHYADDR, &req) == -1)
-               warn("SIOCSLIFPHYADDR");
-
-       freeaddrinfo(srcres);
-       freeaddrinfo(dstres);
-}
-
-/* ARGSUSED */
-void
-deletetunnel(const char *vname, int param)
-{
-
-       if (ioctl(s, SIOCDIFPHYADDR, &ifr) == -1)
-               err(EXIT_FAILURE, "SIOCDIFPHYADDR");
-}
-
-void
 setifnetmask(const char *addr, int d)
 {
        (*afp->af_getaddr)(addr, MASK);
@@ -2025,42 +1936,6 @@
 }
 
 void
-tunnel_status(void)
-{
-       char psrcaddr[NI_MAXHOST];
-       char pdstaddr[NI_MAXHOST];
-       const char *ver = "";
-       const int niflag = NI_NUMERICHOST;
-       struct if_laddrreq req;
-
-       psrcaddr[0] = pdstaddr[0] = '\0';
-
-       memset(&req, 0, sizeof(req));
-       strncpy(req.iflr_name, name, IFNAMSIZ);
-       if (ioctl(s, SIOCGLIFPHYADDR, &req) == -1)
-               return;
-#ifdef INET6
-       if (req.addr.ss_family == AF_INET6)
-               in6_fillscopeid((struct sockaddr_in6 *)&req.addr);
-#endif
-       getnameinfo((struct sockaddr *)&req.addr, req.addr.ss_len,
-           psrcaddr, sizeof(psrcaddr), 0, 0, niflag);
-#ifdef INET6
-       if (req.addr.ss_family == AF_INET6)
-               ver = "6";
-#endif
-
-#ifdef INET6
-       if (req.dstaddr.ss_family == AF_INET6)
-               in6_fillscopeid((struct sockaddr_in6 *)&req.dstaddr);
-#endif
-       getnameinfo((struct sockaddr *)&req.dstaddr, req.dstaddr.ss_len,
-           pdstaddr, sizeof(pdstaddr), 0, 0, niflag);
-
-       printf("\ttunnel inet%s %s --> %s\n", ver, psrcaddr, pdstaddr);
-}
-
-void
 in_alias(struct ifreq *creq)
 {
        struct sockaddr_in *iasin;
diff -r d172d7000c0d -r 0b085b2016bc sbin/ifconfig/tunnel.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/ifconfig/tunnel.c    Sat Mar 19 17:32:26 2005 +0000
@@ -0,0 +1,167 @@
+/*     $NetBSD: tunnel.c,v 1.1 2005/03/19 17:32:26 thorpej Exp $       */
+
+/*
+ * Copyright (c) 1983, 1993
+ *      The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. 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 BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: tunnel.c,v 1.1 2005/03/19 17:32:26 thorpej Exp $");
+#endif /* not lint */
+
+#include <sys/param.h> 
+#include <sys/ioctl.h> 
+#include <sys/socket.h>
+
+#include <net/if.h> 
+
+#ifdef INET6
+#include <netinet/in.h>
+#endif
+
+#include <ctype.h>
+#include <err.h>
+#include <netdb.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "extern.h"
+#include "tunnel.h"
+
+extern void in6_fillscopeid(struct sockaddr_in6 *sin6);        /* XXX */
+
+void
+settunnel(const char *src, const char *dst)
+{
+       struct addrinfo hints, *srcres, *dstres;
+       int ecode;
+       struct if_laddrreq req;
+



Home | Main Index | Thread Index | Old Index