Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Nov 2005 17:22:17 +0500
From:      bart <bart@convex.ru>
To:        freebsd-net@freebsd.org
Subject:   ifconfig description
Message-ID:  <1603703438.20051125172217@convex.ru>

next in thread | raw e-mail | index | archive | help
Hello,

I have couple of bsd routers with dozens vlans
and missed ability to make comment on interface like cisco description

so, here are patches for 6.0 but they can be easily adopted for 5.4

now you can write smthng like
#ifconfig vlan45 descr "Some corp. room 666"

and then you'll see
#ifconfig vlan45
vlan45: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
        inet 192.168.1.1 netmask 0xffffffe0
        ether 00:07:e9:69:34:61
        media: Ethernet autoselect (1000baseTX <full-duplex>)        
        status: active
        descr: Some corp. room 666
        vlan: 45 parent interface: em0

bye,
Alex Bartolomey


---- cut ----

*** sys/net/if.c        Thu Sep 29 20:57:06 2005
--- sys1/net/if.c       Fri Nov 25 11:43:25 2005
***************
*** 1201,1206 ****
--- 1201,1207 ----
  {
        struct ifreq *ifr;
        struct ifstat *ifs;
+       struct ifdescreq *ifrd;
        int error = 0;
        int new_flags, temp_flags;
        size_t namelen, onamelen;
***************
*** 1348,1353 ****
--- 1349,1366 ----
                EVENTHANDLER_INVOKE(ifnet_arrival_event, ifp);
                /* Announce the return of the interface. */
                rt_ifannouncemsg(ifp, IFAN_ARRIVAL);
+               break;
+ 
+ /* bartp */
+ 
+       case SIOCSIFDESCR:
+               ifrd = (struct ifdescreq *)data;
+               strlcpy(ifp->if_data.ifi_descr, ifrd->ifrd_descr, MAXIFDESCRSIZE);
+               break;
+ 
+       case SIOCGIFDESCR:
+               ifrd = (struct ifdescreq *)data;
+               strlcpy(ifrd->ifrd_descr, ifp->if_data.ifi_descr, MAXIFDESCRSIZE);
                break;
  
        case SIOCSIFMETRIC:

*** sys/net/if.h        Fri Oct  7 14:00:05 2005
--- sys1/net/if.h       Fri Nov 25 11:30:05 2005
***************
*** 72,77 ****
--- 72,80 ----
        char    *ifcr_buffer;           /* buffer for cloner names */
  };
  
+ #define       MAXIFDESCRSIZE  48
+ 
+ 
  /*
   * Structure describing information about an interface
   * which may be of interest to management entities.
***************
*** 107,112 ****
--- 110,116 ----
        u_int   ifi_timepad;            /* time_t is int, not long on alpha */
  #endif
        struct  timeval ifi_lastchange; /* time of last administrative change */
+       char    ifi_descr[MAXIFDESCRSIZE];
  };
  
  /*-
***************
*** 287,292 ****
--- 291,301 ----
  #define       ifr_reqcap      ifr_ifru.ifru_cap[0]    /* requested capabilities */
  #define       ifr_curcap      ifr_ifru.ifru_cap[1]    /* current capabilities */
  #define       ifr_index       ifr_ifru.ifru_index     /* interface index */
+ };
+ 
+ struct        ifdescreq {
+       char    ifrd_name[IFNAMSIZ];            /* if name, e.g. "en0" */
+       char    ifrd_descr[MAXIFDESCRSIZE];     /* interface description */
  };
  
  #define       _SIZEOF_ADDR_IFREQ(ifr) \

*** sys/sys/sockio.h    Sun Jun  5 03:13:13 2005
--- sys1/sys/sockio.h   Fri Nov 25 11:41:48 2005
***************
*** 80,85 ****
--- 80,90 ----
  #define       SIOCSIFMAC       _IOW('i', 39, struct ifreq)    /* set IF MAC label */
  #define       SIOCSIFNAME      _IOW('i', 40, struct ifreq)    /* set IF name */
  
+ /* bartp */
+ #define       SIOCSIFDESCR     _IOW('i', 41, struct ifdescreq) /* set IF descr */
+ #define       SIOCGIFDESCR    _IOWR('i', 42, struct ifdescreq) /* get IF descr */
+ 
+ 
  #define       SIOCADDMULTI     _IOW('i', 49, struct ifreq)    /* add m'cast addr */
  #define       SIOCDELMULTI     _IOW('i', 50, struct ifreq)    /* del m'cast addr */
  #define       SIOCGIFMTU      _IOWR('i', 51, struct ifreq)    /* get IF mtu */

*** sbin/ifconfig/ifconfig.c    Thu Oct  6 15:01:56 2005
--- sbin1/ifconfig/ifconfig.c   Fri Nov 25 12:09:38 2005
***************
*** 791,796 ****
--- 791,812 ----
        printname = 0;
  }
  
+ static void
+ setifdescr(const char *val, int dummy __unused, int s, 
+     const struct afswtch *afp)
+ {
+       struct ifdescreq ifrd;
+ 
+       strlcpy( ifrd.ifrd_name, ifr.ifr_name,  sizeof(ifr.ifr_name) );
+       strlcpy( ifrd.ifrd_descr, val, sizeof(ifrd.ifrd_descr) );
+ 
+       if (ioctl(s, SIOCSIFDESCR, (caddr_t)&ifrd) < 0) {
+               warn("ioctl (set descr)");
+               return;
+       }
+ }
+ 
+ 
  /*
   * Expand the compacted form of addresses as returned via the
   * configuration read via sysctl().
***************
*** 829,834 ****
--- 845,851 ----
        struct  rt_addrinfo info;
        int allfamilies, s;
        struct ifstat ifs;
+       struct ifdescreq ifrd;
  
        if (afp == NULL) {
                allfamilies = 1;
***************
*** 904,909 ****
--- 921,933 ----
        if (ioctl(s, SIOCGIFSTATUS, &ifs) == 0) 
                printf("%s", ifs.ascii);
  
+ /* bartp */
+ 
+       strncpy(ifrd.ifrd_name, name, sizeof ifrd.ifrd_name);
+       if (ioctl(s, SIOCGIFDESCR, (caddr_t)&ifrd) == 0 && ifrd.ifrd_descr[0]!=0 ) {
+               printf("        descr: %s\n", ifrd.ifrd_descr);
+       }
+ 
        close(s);
        return;
  }
***************
*** 1051,1056 ****
--- 1075,1081 ----
        DEF_CMD("noicmp",       IFF_LINK1,      setifflags),
        DEF_CMD_ARG("mtu",                      setifmtu),
        DEF_CMD_ARG("name",                     setifname),
+       DEF_CMD_ARG("descr",                    setifdescr),
  };
  
  static __constructor void        

-- 
Best regards,
 bart                          mailto:bart@convex.ru




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1603703438.20051125172217>