Source-Changes-HG archive

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

[src/trunk]: src/sbin/ifconfig support "eui64" option (grab interface ID from...



details:   https://anonhg.NetBSD.org/src/rev/2d288d55e6b6
branches:  trunk
changeset: 532752:2d288d55e6b6
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Jun 14 09:01:59 2002 +0000

description:
support "eui64" option (grab interface ID from link-local addr).
from: ww%styx.org@localhost

diffstat:

 sbin/ifconfig/ifconfig.8 |    7 ++-
 sbin/ifconfig/ifconfig.c |  125 +++++++++++++++++++++++++++++++---------------
 2 files changed, 90 insertions(+), 42 deletions(-)

diffs (truncated from 396 to 300 lines):

diff -r 8b0d9bbde9f8 -r 2d288d55e6b6 sbin/ifconfig/ifconfig.8
--- a/sbin/ifconfig/ifconfig.8  Fri Jun 14 06:04:33 2002 +0000
+++ b/sbin/ifconfig/ifconfig.8  Fri Jun 14 09:01:59 2002 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: ifconfig.8,v 1.55 2002/06/09 17:47:33 itojun Exp $
+.\"    $NetBSD: ifconfig.8,v 1.56 2002/06/14 09:01:59 itojun Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -390,6 +390,11 @@
 .It Fl tentative
 (inet6 only)
 Clear the IPv6 tentative address bit.
+.It eui64
+(inet6 only)
+Fill interface index
+.Pq lowermost 64bit of an IPv6 address
+automatically.
 .It Cm link[0-2]
 Enable special processing of the link level of the interface.
 These three options are interface specific in actual effect, however,
diff -r 8b0d9bbde9f8 -r 2d288d55e6b6 sbin/ifconfig/ifconfig.c
--- a/sbin/ifconfig/ifconfig.c  Fri Jun 14 06:04:33 2002 +0000
+++ b/sbin/ifconfig/ifconfig.c  Fri Jun 14 09:01:59 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ifconfig.c,v 1.126 2002/06/14 01:07:01 itojun Exp $    */
+/*     $NetBSD: ifconfig.c,v 1.127 2002/06/14 09:02:00 itojun Exp $    */
 
 /*-
  * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
@@ -80,7 +80,7 @@
 #if 0
 static char sccsid[] = "@(#)ifconfig.c 8.2 (Berkeley) 2/16/94";
 #else
-__RCSID("$NetBSD: ifconfig.c,v 1.126 2002/06/14 01:07:01 itojun Exp $");
+__RCSID("$NetBSD: ifconfig.c,v 1.127 2002/06/14 09:02:00 itojun Exp $");
 #endif
 #endif /* not lint */
 
@@ -182,6 +182,7 @@
 void   setia6pltime __P((const char *, int));
 void   setia6vltime __P((const char *, int));
 void   setia6lifetime __P((const char *, const char *));
+void   setia6eui64 __P((const char *, int));
 #endif
 void   checkatrange __P ((struct sockaddr_at *));
 void   setmedia __P((const char *, int));
@@ -262,6 +263,7 @@
        { "-deprecated", -IN6_IFF_DEPRECATED,   0,      setia6flags },
        { "pltime",     NEXTARG,        0,              setia6pltime },
        { "vltime",     NEXTARG,        0,              setia6vltime },
+       { "eui64",      0,              0,              setia6eui64 },
 #endif /*INET6*/
 #ifndef INET_ONLY
        { "range",      NEXTARG,        0,              setatrange },
@@ -583,7 +585,8 @@
                                break;
                if (p->c_name == 0 && setaddr) {
                        if ((flags & IFF_POINTOPOINT) == 0) {
-                               errx(1, "can't set destination address %s",
+                               errx(EXIT_FAILURE,
+                                   "can't set destination address %s",
                                     "on non-point-to-point link");
                        }
                        p++;    /* got src, do dst */
@@ -591,13 +594,15 @@
                if (p->c_func != NULL || p->c_func2 != NULL) {
                        if (p->c_parameter == NEXTARG) {
                                if (argc < 2)
-                                       errx(1, "'%s' requires argument",
+                                       errx(EXIT_FAILURE,
+                                           "'%s' requires argument",
                                            p->c_name);
                                (*p->c_func)(argv[1], 0);
                                argc--, argv++;
                        } else if (p->c_parameter == NEXTARG2) {
                                if (argc < 3)
-                                       errx(1, "'%s' requires 2 arguments",
+                                       errx(EXIT_FAILURE,
+                                           "'%s' requires 2 arguments",
                                            p->c_name);
                                (*p->c_func2)(argv[1], argv[2]);
                                argc -= 2, argv += 2;
@@ -916,20 +921,20 @@
        hints.ai_socktype = SOCK_DGRAM; /*dummy*/
 
        if ((ecode = getaddrinfo(src, NULL, &hints, &srcres)) != 0)
-               errx(1, "error in parsing address string: %s",
+               errx(EXIT_FAILURE, "error in parsing address string: %s",
                    gai_strerror(ecode));
 
        if ((ecode = getaddrinfo(dst, NULL, &hints, &dstres)) != 0)
-               errx(1, "error in parsing address string: %s",
+               errx(EXIT_FAILURE, "error in parsing address string: %s",
                    gai_strerror(ecode));
 
        if (srcres->ai_addr->sa_family != dstres->ai_addr->sa_family)
-               errx(1,
+               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(1, "invalid sockaddr");
+               errx(EXIT_FAILURE, "invalid sockaddr");
 
        memset(&req, 0, sizeof(req));
        strncpy(req.iflr_name, name, sizeof(req.iflr_name));
@@ -943,7 +948,7 @@
                s6 = (struct sockaddr_in6 *)&req.addr;
                d = (struct sockaddr_in6 *)&req.dstaddr;
                if (s6->sin6_scope_id != d->sin6_scope_id) {
-                       errx(1, "scope mismatch");
+                       errx(EXIT_FAILURE, "scope mismatch");
                        /* NOTREACHED */
                }
 #ifdef __KAME__
@@ -1207,9 +1212,9 @@
        t = time(NULL);
        newval = (time_t)strtoul(val, &ep, 0);
        if (val == ep)
-               errx(1, "invalid %s", cmd);
+               errx(EXIT_FAILURE, "invalid %s", cmd);
        if (afp->af_af != AF_INET6)
-               errx(1, "%s not allowed for the AF", cmd);
+               errx(EXIT_FAILURE, "%s not allowed for the AF", cmd);
        if (strcmp(cmd, "vltime") == 0) {
                in6_addreq.ifra_lifetime.ia6t_expire = t + newval;
                in6_addreq.ifra_lifetime.ia6t_vltime = newval;
@@ -1218,6 +1223,40 @@
                in6_addreq.ifra_lifetime.ia6t_pltime = newval;
        }
 }
+
+void
+setia6eui64(cmd, val)
+       const char *cmd;
+       int val;
+{
+       struct ifaddrs *ifap, *ifa;
+       const struct sockaddr_in6 *sin6 = NULL;
+       const struct in6_addr *lladdr = NULL;
+       struct in6_addr *in6;
+
+       if (afp->af_af != AF_INET6)
+               errx(EXIT_FAILURE, "%s not allowed for the AF", cmd);
+       in6 = (struct in6_addr *)&in6_addreq.ifra_addr.sin6_addr;
+       if (memcmp(&in6addr_any.s6_addr[8], &in6->s6_addr[8], 8) != 0)
+               errx(EXIT_FAILURE, "interface index is already filled");
+       if (getifaddrs(&ifap) != 0)
+               err(EXIT_FAILURE, "getifaddrs");
+       for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+               if (ifa->ifa_addr->sa_family == AF_INET6) {
+                       sin6 = (const struct sockaddr_in6 *)ifa->ifa_addr;
+                       if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
+                               lladdr = &sin6->sin6_addr;
+                               break;
+                       }
+               }
+       }
+       if (!lladdr)
+               errx(EXIT_FAILURE, "could not determine link local address"); 
+
+       memcpy(&in6->s6_addr[8], &lladdr->s6_addr[8], 8);
+
+       freeifaddrs(ifap);
+}
 #endif
 
 void
@@ -1230,7 +1269,7 @@
        (void) strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name));
        ifr.ifr_metric = strtoul(val, &ep, 10);
        if (!ep || *ep)
-               errx(1, "%s: invalid metric", val);
+               errx(EXIT_FAILURE, "%s: invalid metric", val);
        if (ioctl(s, SIOCSIFMETRIC, (caddr_t)&ifr) == -1)
                warn("SIOCSIFMETRIC");
 }
@@ -1245,7 +1284,7 @@
        (void)strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
        ifr.ifr_mtu = strtoul(val, &ep, 10);
        if (!ep || *ep)
-               errx(1, "%s: invalid mtu", val);
+               errx(EXIT_FAILURE, "%s: invalid mtu", val);
        if (ioctl(s, SIOCSIFMTU, (caddr_t)&ifr) == -1)
                warn("SIOCSIFMTU");
 }
@@ -1563,7 +1602,7 @@
 
        /* Sanity. */
        if (IFM_TYPE(media_current) == 0)
-               errx(1, "%s: no link type?", name);
+               errx(EXIT_FAILURE, "%s: no link type?", name);
 }
 
 void
@@ -1600,11 +1639,12 @@
 
        /* Only one media command may be given. */
        if (actions & A_MEDIA)
-               errx(1, "only one `media' command may be issued");
+               errx(EXIT_FAILURE, "only one `media' command may be issued");
 
        /* Must not come after mediaopt commands */
        if (actions & A_MEDIAOPT)
-               errx(1, "may not issue `media' after `mediaopt' commands");
+               errx(EXIT_FAILURE,
+                   "may not issue `media' after `mediaopt' commands");
 
        /*
         * No need to check if `instance' has been issued; setmediainst()
@@ -1633,11 +1673,11 @@
 
        /* Can only issue `mediaopt' once. */
        if (actions & A_MEDIAOPTSET)
-               errx(1, "only one `mediaopt' command may be issued");
+               errx(EXIT_FAILURE, "only one `mediaopt' command may be issued");
 
        /* Can't issue `mediaopt' if `instance' has already been issued. */
        if (actions & A_MEDIAINST)
-               errx(1, "may not issue `mediaopt' after `instance'");
+               errx(EXIT_FAILURE, "may not issue `mediaopt' after `instance'");
 
        mediaopt_set = get_media_options(IFM_TYPE(media_current), val);
 
@@ -1654,11 +1694,13 @@
 
        /* Can only issue `-mediaopt' once. */
        if (actions & A_MEDIAOPTCLR)
-               errx(1, "only one `-mediaopt' command may be issued");
+               errx(EXIT_FAILURE,
+                   "only one `-mediaopt' command may be issued");
 
        /* May not issue `media' and `-mediaopt'. */
        if (actions & A_MEDIA)
-               errx(1, "may not issue both `media' and `-mediaopt'");
+               errx(EXIT_FAILURE,
+                   "may not issue both `media' and `-mediaopt'");
 
        /*
         * No need to check for A_MEDIAINST, since the test for A_MEDIA
@@ -1681,11 +1723,11 @@
 
        /* Can only issue `instance' once. */
        if (actions & A_MEDIAINST)
-               errx(1, "only one `instance' command may be issued");
+               errx(EXIT_FAILURE, "only one `instance' command may be issued");
 
        /* Must have already specified `media' */
        if ((actions & A_MEDIA) == 0)
-               errx(1, "must specify `media' before `instance'");
+               errx(EXIT_FAILURE, "must specify `media' before `instance'");
 
        type = IFM_TYPE(media_current);
        subtype = IFM_SUBTYPE(media_current);
@@ -1693,7 +1735,7 @@
 
        inst = atoi(val);
        if (inst < 0 || inst > IFM_INST_MAX)
-               errx(1, "invalid media instance: %s", val);
+               errx(EXIT_FAILURE, "invalid media instance: %s", val);
 
        media_current = IFM_MAKEWORD(type, subtype, options, inst);
 
@@ -1747,7 +1789,7 @@
 
        rval = lookup_media_word(ifm_subtype_descriptions, type, val);
        if (rval == -1)
-               errx(1, "unknown %s media subtype: %s",
+               errx(EXIT_FAILURE, "unknown %s media subtype: %s",
                    get_media_type_string(type), val);
 
        return (rval);
@@ -1773,7 +1815,7 @@
        for (; (str = strtok(str, ",")) != NULL; str = NULL) {
                option = lookup_media_word(ifm_option_descriptions, type, str);
                if (option == -1)
-                       errx(1, "unknown %s media option: %s",
+                       errx(EXIT_FAILURE, "unknown %s media option: %s",
                            get_media_type_string(type), str);
                rval |= IFM_OPTIONS(option);
        }
@@ -2548,7 +2590,7 @@
                else if ((np = getnetbyname(str)) != NULL)
                        gasin->sin_addr = inet_makeaddr(np->n_net, INADDR_ANY);
                else
-                       errx(1, "%s: bad value", str);
+                       errx(EXIT_FAILURE, "%s: bad value", str);
        }
 }
 
@@ -2562,7 +2604,7 @@
        int len = strtol(plen, (char **)NULL, 10);
 
        if ((len < 0) || (len > 32))
-               errx(1, "%s: bad value", plen);
+               errx(EXIT_FAILURE, "%s: bad value", plen);
        igsin->sin_len = sizeof(*igsin);
        if (which != MASK)



Home | Main Index | Thread Index | Old Index