Source-Changes-HG archive

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

[src/trunk]: src/sbin/ifconfig Add descr, description/-descr, -description comm...



details:   https://anonhg.NetBSD.org/src/rev/2277ba01d6b1
branches:  trunk
changeset: 457576:2277ba01d6b1
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Thu Jul 04 02:45:45 2019 +0000

description:
Add descr,description/-descr,-description commands to ifconfig(8) to handle a description.

>From t-kusaba@IIJ

diffstat:

 sbin/ifconfig/ifconfig.8 |   8 ++++-
 sbin/ifconfig/ifconfig.c |  72 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 76 insertions(+), 4 deletions(-)

diffs (164 lines):

diff -r 3533f2825516 -r 2277ba01d6b1 sbin/ifconfig/ifconfig.8
--- a/sbin/ifconfig/ifconfig.8  Thu Jul 04 02:44:25 2019 +0000
+++ b/sbin/ifconfig/ifconfig.8  Thu Jul 04 02:45:45 2019 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: ifconfig.8,v 1.116 2018/11/15 04:37:20 ozaki-r Exp $
+.\"    $NetBSD: ifconfig.8,v 1.117 2019/07/04 02:45:45 ozaki-r Exp $
 .\"
 .\" Copyright (c) 1983, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)ifconfig.8 8.4 (Berkeley) 6/1/94
 .\"
-.Dd November 15, 2018
+.Dd June 18, 2019
 .Dt IFCONFIG 8
 .Os
 .Sh NAME
@@ -186,6 +186,10 @@
 .Ar iface .
 If not specified, the kernel will attempt to select an interface with
 a subnet matching that of the carp interface.
+.It Cm description Ar description , Cm descr Ar description
+Set a description of the interface. (0-63 characters)
+.It Cm -description , Cm -descr
+Clear the description of the interface.
 .It Cm debug
 Enable driver dependent debugging code; usually, this turns on
 extra console error logging.
diff -r 3533f2825516 -r 2277ba01d6b1 sbin/ifconfig/ifconfig.c
--- a/sbin/ifconfig/ifconfig.c  Thu Jul 04 02:44:25 2019 +0000
+++ b/sbin/ifconfig/ifconfig.c  Thu Jul 04 02:45:45 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ifconfig.c,v 1.238 2018/12/21 08:58:08 msaitoh Exp $   */
+/*     $NetBSD: ifconfig.c,v 1.239 2019/07/04 02:45:45 ozaki-r Exp $   */
 
 /*-
  * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
@@ -63,7 +63,7 @@
 #ifndef lint
 __COPYRIGHT("@(#) Copyright (c) 1983, 1993\
  The Regents of the University of California.  All rights reserved.");
-__RCSID("$NetBSD: ifconfig.c,v 1.238 2018/12/21 08:58:08 msaitoh Exp $");
+__RCSID("$NetBSD: ifconfig.c,v 1.239 2019/07/04 02:45:45 ozaki-r Exp $");
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -133,6 +133,8 @@
 static int setifprefixlen(prop_dictionary_t, prop_dictionary_t);
 static int setlinkstr(prop_dictionary_t, prop_dictionary_t);
 static int unsetlinkstr(prop_dictionary_t, prop_dictionary_t);
+static int setifdescr(prop_dictionary_t, prop_dictionary_t);
+static int unsetifdescr(prop_dictionary_t, prop_dictionary_t);
 static void status(const struct sockaddr *, prop_dictionary_t,
     prop_dictionary_t);
 __dead static void usage(void);
@@ -193,6 +195,9 @@
     "broadcast address",
     setifbroadaddr, "broadcast", NULL, NULL, NULL, &command_root.pb_parser);
 
+struct pstr parse_descr = PSTR_INITIALIZER1(&parse_descr, "descr",
+    setifdescr, "descr", false, &command_root.pb_parser);
+
 static const struct kwinst misckw[] = {
          {.k_word = "alias", .k_key = "alias", .k_deact = "alias",
           .k_type = KW_T_BOOL, .k_neg = true,
@@ -213,6 +218,12 @@
        , {.k_word = "linkstr", .k_nextparser = &parse_linkstr.ps_parser }
        , {.k_word = "-linkstr", .k_exec = unsetlinkstr,
           .k_nextparser = &command_root.pb_parser }
+       , {.k_word = "descr", .k_nextparser = &parse_descr.ps_parser}
+       , {.k_word = "description", .k_nextparser = &parse_descr.ps_parser}
+       , {.k_word = "-descr", .k_exec = unsetifdescr,
+          .k_nextparser = &command_root.pb_parser}
+       , {.k_word = "-description", .k_exec = unsetifdescr,
+          .k_nextparser = &command_root.pb_parser}
 };
 
 /* key: clonecmd */
@@ -1270,6 +1281,7 @@
        struct ifcapreq ifcr;
        unsigned short flags;
        const struct afswtch *afp;
+       char ifdescr[IFDESCRSIZE];
 
        if ((af = getaf(env)) == -1) {
                afp = NULL;
@@ -1321,6 +1333,12 @@
        SIMPLEQ_FOREACH(status_f, &status_funcs, f_next)
                (*status_f->f_func)(env, oenv);
 
+       estrlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+       ifr.ifr_buf = &ifdescr;
+       ifr.ifr_buflen = sizeof(ifdescr);
+       if (prog_ioctl(s, SIOCGIFDESCR, &ifr) == 0)
+               printf("\tdescription: \"%s\"\n", (char *)ifr.ifr_buf);
+
        print_link_addresses(env, true);
 
        estrlcpy(ifdrv.ifd_name, ifname, sizeof(ifdrv.ifd_name));
@@ -1461,6 +1479,55 @@
        return 0;
 }
 
+static int
+setifdescr(prop_dictionary_t env, prop_dictionary_t oenv)
+{
+       struct ifreq ifr;
+       size_t len;
+       prop_data_t data;
+       char *descr;
+
+       data = (prop_data_t)prop_dictionary_get(env, "descr");
+       if (data == NULL) {
+               errno = ENOENT;
+               return -1;
+       }
+       len = prop_data_size(data) + 1;
+
+       if (len > IFDESCRSIZE)
+               err(EXIT_FAILURE, "description too long");
+
+       descr = malloc(len);
+       if (descr == NULL)
+               err(EXIT_FAILURE, "malloc description space");
+       if (getargstr(env, "descr", descr, len) == -1)
+               errx(EXIT_FAILURE, "getargstr descr failed");
+
+
+       ifr.ifr_buf = descr;
+       ifr.ifr_buflen = len;
+       if (direct_ioctl(env, SIOCSIFDESCR, &ifr) != 0)
+               err(EXIT_FAILURE, "SIOCSIFDESCR");
+
+       free(descr);
+
+       return 0;
+}
+
+static int
+unsetifdescr(prop_dictionary_t env, prop_dictionary_t oenv)
+{
+       struct ifreq ifr;
+       ifr.ifr_buf = NULL;
+       ifr.ifr_buflen = 0;
+
+       if (direct_ioctl(env, SIOCSIFDESCR, &ifr) != 0)
+               err(EXIT_FAILURE, "SIOCSIFDESCR");
+
+       return 0;
+}
+
+
 static void
 usage(void)
 {
@@ -1486,6 +1553,7 @@
                "\t[ preference n ]\n"
                "\t[ link0 | -link0 ] [ link1 | -link1 ] [ link2 | -link2 ]\n"
                "\t[ linkstr str | -linkstr ]\n"
+               "\t[ description str | descr str | -description | -descr ]\n"
                "       %s -a [-b] [-d] [-h] %s[-u] [-v] [-z] [ af ]\n"
                "       %s -l [-b] [-d] [-s] [-u]\n"
                "       %s -C\n"



Home | Main Index | Thread Index | Old Index