Source-Changes-HG archive

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

[src/trunk]: src bring in latest gifconfig(8) from kame. "delete" subcommand...



details:   https://anonhg.NetBSD.org/src/rev/81abbbd1f66f
branches:  trunk
changeset: 486103:81abbbd1f66f
user:      itojun <itojun%NetBSD.org@localhost>
date:      Sat May 13 07:55:05 2000 +0000

description:
bring in latest gifconfig(8) from kame.  "delete" subcommand is now available.
add kernel support for gifconfig <if> delete.

diffstat:

 sys/sys/sockio.h               |   5 +-
 usr.sbin/gifconfig/gifconfig.8 |  25 ++++++++-----
 usr.sbin/gifconfig/gifconfig.c |  77 ++++++++++++++++++++++++++++++++---------
 3 files changed, 77 insertions(+), 30 deletions(-)

diffs (281 lines):

diff -r 09bce5983476 -r 81abbbd1f66f sys/sys/sockio.h
--- a/sys/sys/sockio.h  Sat May 13 07:28:09 2000 +0000
+++ b/sys/sys/sockio.h  Sat May 13 07:55:05 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sockio.h,v 1.10 2000/03/13 05:56:47 onoe Exp $ */
+/*     $NetBSD: sockio.h,v 1.11 2000/05/13 07:55:05 itojun Exp $       */
 
 /*-
  * Copyright (c) 1982, 1986, 1990, 1993, 1994
@@ -86,9 +86,10 @@
 #define        SIOCSIFMEDIA    _IOWR('i', 53, struct ifreq)    /* set net media */
 #define        SIOCGIFMEDIA    _IOWR('i', 54, struct ifmediareq) /* get net media */
 
-#define SIOCSIFPHYADDR   _IOW('i', 70, struct ifaliasreq) /* set gif addres */
+#define SIOCSIFPHYADDR  _IOW('i', 70, struct ifaliasreq) /* set gif addres */
 #define        SIOCGIFPSRCADDR _IOWR('i', 71, struct ifreq)    /* get gif psrc addr */
 #define        SIOCGIFPDSTADDR _IOWR('i', 72, struct ifreq)    /* get gif pdst addr */
+#define SIOCDIFPHYADDR  _IOW('i', 73, struct ifreq)    /* delete gif addrs */
 
 #define        SIOCSIFMTU       _IOW('i', 127, struct ifreq)   /* set ifnet mtu */
 #define        SIOCGIFMTU      _IOWR('i', 126, struct ifreq)   /* get ifnet mtu */
diff -r 09bce5983476 -r 81abbbd1f66f usr.sbin/gifconfig/gifconfig.8
--- a/usr.sbin/gifconfig/gifconfig.8    Sat May 13 07:28:09 2000 +0000
+++ b/usr.sbin/gifconfig/gifconfig.8    Sat May 13 07:55:05 2000 +0000
@@ -1,3 +1,6 @@
+.\"    $NetBSD: gifconfig.8,v 1.5 2000/05/13 07:55:06 itojun Exp $
+.\"    $KAME: gifconfig.8,v 1.5 2000/05/13 07:48:10 itojun Exp $
+.\"
 .\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
 .\" All rights reserved.
 .\" 
@@ -25,9 +28,6 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.\"     $NetBSD: gifconfig.8,v 1.4 1999/12/09 15:30:43 itojun Exp $
-.\"     KAME Id: gifconfig.8,v 1.2 1999/10/07 04:25:54 itojun Exp
-.\"
 .Dd May 17, 1998
 .Dt GIFCONFIG 8
 .Os
@@ -42,8 +42,10 @@
 .Op Ar af
 .Op Ar physsrc physdest
 .Nm gifconfig
+.Ar interface
+.Ic delete
+.Nm gifconfig
 .Fl a
-.\"
 .Sh DESCRIPTION
 .Nm
 configures the physical address for the generic IP tunnel 
@@ -63,12 +65,20 @@
 .Ar Af
 can be
 .Li inet
-or 
+or
 .Li inet6 ,
 and will be treated as
 .Li inet
 if ommitted.
 .Pp
+If a special argument
+.Ic delete
+is specified,
+.Nm
+just deletes the existing source and destination addresses on
+.Ar interface .
+If no outer addresses are specified, this usage has no effect.
+.Pp
 .Nm
 takes the following optional argument:
 .Bl -tag -width Ds
@@ -81,7 +91,6 @@
 .Po
 e.g. IPv4-over-IPv4
 .Pc .
-.\"
 .Sh EXAMPLES
 If you would like to configure IPv6 over IPv4
 .Pq aka IPv6 in IPv4
@@ -125,10 +134,8 @@
 to
 .Li inet6 ,
 and IPv4 addresses to some appropriate IPv6 addresses in above example.
-.\"
 .Sh RETURN VALUES
 The command exits with exit status of 1 on errors, 0 on success.
-.\"
 .Sh SEE ALSO
 .Xr gif 4 ,
 .Xr ifconfig 8
@@ -136,5 +143,3 @@
 The
 .Nm
 command first appeared in WIDE Hydrangea IPv6 protocol stack kit.
-.\" .Sh BUGS
-.\" (to be written)
diff -r 09bce5983476 -r 81abbbd1f66f usr.sbin/gifconfig/gifconfig.c
--- a/usr.sbin/gifconfig/gifconfig.c    Sat May 13 07:28:09 2000 +0000
+++ b/usr.sbin/gifconfig/gifconfig.c    Sat May 13 07:55:05 2000 +0000
@@ -1,4 +1,5 @@
-/*     $NetBSD: gifconfig.c,v 1.6 2000/01/22 10:16:23 tron Exp $       */
+/*     $NetBSD: gifconfig.c,v 1.7 2000/05/13 07:55:06 itojun Exp $     */
+/*     $KAME: gifconfig.c,v 1.8 2000/05/13 07:52:46 itojun Exp $       */
 
 /*
  * Copyright (c) 1983, 1993
@@ -93,6 +94,7 @@
 int    metric;
 int    mtu;
 int    setpsrc = 0;
+int    newaddr = 0;
 int    s;
 kvm_t  *kvmd;
 
@@ -103,7 +105,7 @@
 void setifpsrc __P((char *, int));
 void setifpdst __P((char *, int));
 void setifflags __P((char *, int));
-
+void delifaddrs __P((char *, int));
 
 #define        NEXTARG         0xffffff
 
@@ -114,6 +116,7 @@
 } cmds[] = {
        { "up",         IFF_UP,         setifflags } ,
        { "down",       -IFF_UP,        setifflags },
+       { "delete",     0,              delifaddrs },
        { 0,            0,              setifpsrc },
        { 0,            0,              setifpdst },
 };
@@ -220,8 +223,12 @@
        int all;
 
        if (argc < 2) {
-               fprintf(stderr, "usage: gifconfig interface %s",
-                   "[ af ] physsrc physdst\n");
+               fprintf(stderr,
+                   "usage: gifconfig interface [af] [physsrc physdst]\n");
+               fprintf(stderr,
+                   "       gifconfig interface delete\n");
+               fprintf(stderr,
+                   "       gifconfig -a\n");
                exit(1);
        }
        argc--, argv++;
@@ -396,11 +403,14 @@
                }
                argc--, argv++;
        }
-       if (1 /*newaddr*/) {
+       if (newaddr) {
                strncpy(rafp->af_addreq, name, sizeof ifr.ifr_name);
                if (ioctl(s, rafp->af_pifaddr, rafp->af_addreq) < 0)
                        Perror("ioctl (SIOCSIFPHYADDR)");
        }
+       else if (setpsrc) {
+               errx(1, "destination is not specified");
+       }
        return(0);
 }
 #define PSRC   0
@@ -425,6 +435,7 @@
 {
        param = 0;      /*fool gcc*/
        (*afp->af_getaddr)(addr, PDST);
+       newaddr = 1;
 }
 
 void
@@ -449,6 +460,19 @@
                Perror(vname);
 }
 
+/* ARGSUSED */
+void
+delifaddrs(vname, param)
+       char *vname;
+       int param;
+{
+       param = 0;              /* fool gcc */
+       vname = NULL;           /* ditto */
+
+       if (ioctl(s, SIOCDIFPHYADDR, (caddr_t)&ifr) < 0)
+               err(1, "ioctl(SIOCDIFPHYADDR)");
+}
+
 #define        IFFBITS \
 "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6NOTRAILERS\7RUNNING\10NOARP\
 \11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2\20MULTICAST"
@@ -513,7 +537,7 @@
                        }
                } else for (p = afs; p->af_name; p++) {
                        if (p->af_af == info.rti_info[RTAX_IFA]->sa_family &&
-                           p->af_status != ether_status) 
+                           p->af_status != ether_status)
                                (*p->af_status)(0);
                }
        }
@@ -554,7 +578,7 @@
 
        if (0 <= ioctl(s, srccmd, (caddr_t)ifrp)) {
                getnameinfo(&ifrp->ifr_addr, ifrp->ifr_addr.sa_len,
-                           hostname, NI_MAXHOST, 0, 0, flags);
+                           hostname, sizeof(hostname), 0, 0, flags);
 #ifdef INET6
                if (ifrp->ifr_addr.sa_family == AF_INET6)
                        ver = "6";
@@ -563,7 +587,7 @@
        }
        if (0 <= ioctl(s, dstcmd, (caddr_t)ifrp)) {
                getnameinfo(&ifrp->ifr_addr, ifrp->ifr_addr.sa_len,
-                           hostname, NI_MAXHOST, 0, 0, flags);
+                           hostname, sizeof(hostname), 0, 0, flags);
                sprintf(pdstaddr, "%s", hostname);
        }
        printf("\tphysical address %s --> %s\n", psrcaddr, pdstaddr);
@@ -617,12 +641,13 @@
        int force;
 {
        struct sockaddr_in6 *sin, null_sin;
-#if 0
-       char *inet_ntop();
-#endif
-       
+       char hostname[NI_MAXHOST];
+       int niflags = NI_NUMERICHOST;
 
        memset(&null_sin, 0, sizeof(null_sin));
+#ifdef NI_WITHSCOPEID
+       niflags |= NI_WITHSCOPEID;
+#endif
 
        sin = (struct sockaddr_in6 *)info.rti_info[RTAX_IFA];
        if (!sin || sin->sin6_family != AF_INET6) {
@@ -631,8 +656,17 @@
                /* warnx("%s has no AF_INET6 IFA address!", name); */
                sin = &null_sin;
        }
-       printf("\tinet6 %s ", inet_ntop(AF_INET6, &sin->sin6_addr,
-                               ntop_buf, sizeof(ntop_buf)));
+#ifdef __KAME__
+       if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr)) {
+               sin->sin6_scope_id =
+                       ntohs(*(u_int16_t *)&sin->sin6_addr.s6_addr[2]);
+               sin->sin6_addr.s6_addr[2] = 0;
+               sin->sin6_addr.s6_addr[3] = 0;
+       }
+#endif
+       getnameinfo((struct sockaddr *)sin, sin->sin6_len,
+                   hostname, sizeof(hostname), 0, 0, niflags);
+       printf("\tinet6 %s ", hostname);
 
        if (flags & IFF_POINTOPOINT) {
                /* note RTAX_BRD overlap with IFF_BROADCAST */
@@ -642,10 +676,17 @@
                 * address.
                 */
                if (sin->sin6_family == AF_INET6) {
-                       if (!sin)
-                               sin = &null_sin;
-                       printf("--> %s ", inet_ntop(AF_INET6, &sin->sin6_addr,
-                                               ntop_buf, sizeof(ntop_buf)));
+#ifdef __KAME__
+                       if (IN6_IS_ADDR_LINKLOCAL(&sin->sin6_addr)) {
+                               sin->sin6_scope_id =
+                                       ntohs(*(u_int16_t *)&sin->sin6_addr.s6_addr[2]);
+                               sin->sin6_addr.s6_addr[2] = 0;
+                               sin->sin6_addr.s6_addr[3] = 0;
+                       }
+#endif
+                       getnameinfo((struct sockaddr *)sin, sin->sin6_len,
+                                   hostname, sizeof(hostname), 0, 0, flags);
+                       printf("--> %s ", hostname);
                }
        }
 



Home | Main Index | Thread Index | Old Index