From nobody@FreeBSD.org  Mon Oct 11 21:08:16 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 9E864106570B
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 11 Oct 2010 21:08:15 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 820568FC1C
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 11 Oct 2010 21:08:15 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o9BL8FsF057142
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 11 Oct 2010 21:08:15 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o9BL8FvF057140;
	Mon, 11 Oct 2010 21:08:15 GMT
	(envelope-from nobody)
Message-Id: <201010112108.o9BL8FvF057140@www.freebsd.org>
Date: Mon, 11 Oct 2010 21:08:15 GMT
From: Aragon Gouveia <aragon@phat.za.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] ppp(8) new commands: iface name and iface descr
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         151400
>Category:       bin
>Synopsis:       [patch] ppp(8) new commands: iface name and iface descr
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    brian
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Oct 11 21:10:04 UTC 2010
>Closed-Date:    Sun Jul 24 01:37:35 UTC 2011
>Last-Modified:  Sun Jul 24 01:40:05 UTC 2011
>Originator:     Aragon Gouveia
>Release:        8.1-STABLE
>Organization:
>Environment:
FreeBSD soek.geek.sh 8.1-STABLE FreeBSD 8.1-STABLE #0: Sun Oct 10 11:43:28 SAST 2010     toor@igor.geek.sh:/usr/obj/nanobsd.soek/i386/usr/src/sys/SOEK  i386

>Description:
FreeBSD has supported network interface renaming for some time now.  More recently it's been possible to attach textual descriptions to network interfaces too.  Both of these are very useful, but unavailable to PPP interfaces.  I've written a patch for ppp(8) which allows it to rename the tun(4) interfaces that it clones and assign textual descriptions to them too.

The patch adds two new commands:

iface name <name>
iface descr <descr>

The patch also makes a small change to how ppp(8) destroys interfaces at exit. Instead of just dealiasing interfaces and leaving them behind, they are now destroyed in the same manner "ifconfig destroy" works. I believe this is the only correct way of enabling interface renaming without causing ppp to break when it is restarted.

Written for and tested on 8.1-STABLE.  Please note this PR supersedes bin/137379 so please could that old PR be closed.

Please consider committing this patch. :)

>How-To-Repeat:

>Fix:


Patch attached with submission follows:

--- usr.sbin/ppp/bundle.c.orig	2009-08-03 10:13:06.000000000 +0200
+++ usr.sbin/ppp/bundle.c	2010-08-15 04:10:54.000000000 +0200
@@ -758,7 +758,7 @@ bundle_Create(const char *prefix, int ty
     return NULL;
   }
 
-  log_SetTun(bundle.unit);
+  log_SetTun(bundle.unit, NULL);
 
   ifname = strrchr(bundle.dev.Name, '/');
   if (ifname == NULL)
@@ -849,7 +849,7 @@ bundle_Create(const char *prefix, int ty
   bundle.links = datalink_Create("deflink", &bundle, type);
   if (bundle.links == NULL) {
     log_Printf(LogALERT, "Cannot create data link: %s\n", strerror(errno));
-    iface_Destroy(bundle.iface);
+    iface_Free(bundle.iface);
     bundle.iface = NULL;
     close(bundle.dev.fd);
     return NULL;
--- usr.sbin/ppp/command.c.orig	2009-08-03 10:13:06.000000000 +0200
+++ usr.sbin/ppp/command.c	2010-08-15 05:28:36.000000000 +0200
@@ -184,6 +184,7 @@ static int DeleteCommand(struct cmdargs 
 static int NegotiateCommand(struct cmdargs const *);
 static int ClearCommand(struct cmdargs const *);
 static int RunListCommand(struct cmdargs const *);
+static int IfaceNameCommand(struct cmdargs const *arg);
 static int IfaceAddCommand(struct cmdargs const *);
 static int IfaceDeleteCommand(struct cmdargs const *);
 static int IfaceClearCommand(struct cmdargs const *);
@@ -823,6 +824,10 @@ static struct cmdtab const IfaceCommands
    "Delete iface address", "iface delete addr", (void *)1},
   {NULL, "delete!", IfaceDeleteCommand, LOCAL_AUTH,
    "Delete iface address", "iface delete addr", (void *)1},
+  {"name", NULL, IfaceNameCommand, LOCAL_AUTH,
+    "Set iface name", "iface name name", NULL},
+  {"descr", NULL, iface_Descr, LOCAL_AUTH,
+    "Set iface description", "iface descr description", NULL},
   {"show", NULL, iface_Show, LOCAL_AUTH,
    "Show iface address(es)", "iface show", NULL},
   {"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
@@ -3176,6 +3181,22 @@ RunListCommand(struct cmdargs const *arg
 }
 
 static int
+IfaceNameCommand(struct cmdargs const *arg)
+{
+  int n = arg->argn;
+
+  if (arg->argc != n + 1) {
+    return -1;
+  }
+
+  if (!iface_Name(arg->bundle->iface, arg->argv[n]))
+    return 1;
+
+  log_SetTun(arg->bundle->unit, arg->bundle->iface->name);
+  return 0;
+}
+
+static int
 IfaceAddCommand(struct cmdargs const *arg)
 {
   struct ncpaddr peer, addr;
--- usr.sbin/ppp/iface.c.orig	2009-08-03 10:13:06.000000000 +0200
+++ usr.sbin/ppp/iface.c	2010-08-15 05:25:27.000000000 +0200
@@ -369,6 +369,100 @@ iface_addr_Add(const char *name, struct 
   return res != -1;
 }
 
+int
+iface_Name(struct iface *iface, const char *name)
+{
+  struct ifreq ifr;
+  int s;
+  char *newname;
+
+  if ((newname = strdup(name)) == NULL) {
+    log_Printf(LogWARN, "iface name: strdup failed: %s\n", strerror(errno));
+    return 0;
+  }
+
+  if ((s = ID0socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
+    log_Printf(LogERROR, "iface name: socket(): %s\n", strerror(errno));
+    free(newname);
+    return 0;
+  }
+
+  strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name));
+  ifr.ifr_data = (caddr_t)newname;
+  if (ID0ioctl(s, SIOCSIFNAME, (caddr_t)&ifr) < 0) {
+    log_Printf(LogWARN, "iface name: ioctl(SIOCSIFNAME, %s -> %s): %s\n",
+               name, newname, strerror(errno));
+    free(newname);
+    return 0;
+  }
+
+  free(iface->name);
+  iface->name = newname;
+  return 1;
+}
+
+int
+iface_Descr (struct cmdargs const *arg)
+{
+  struct ifreq ifr;
+  struct iface *iface;
+  size_t sz, len;
+  int s, n, ifdescr_maxlen;
+  char *descr;
+
+  sz = sizeof(int);
+  if (sysctlbyname("net.ifdescr_maxlen", &ifdescr_maxlen, &sz, NULL, 0) < 0) {
+    log_Printf(LogERROR, "iface descr: sysctl failed: %s\n", strerror(errno));
+    return 1;
+  }
+
+  if (ifdescr_maxlen < 1) {
+    log_Printf(LogERROR, "iface descr: sysctl net.ifdescr_maxlen < 1\n");
+    return 1;
+  }
+
+  sz = sizeof(char)*ifdescr_maxlen;
+  if ((descr = malloc(sz)) == NULL) {
+    log_Printf(LogERROR, "iface descr: malloc failed: %s\n", strerror(errno));
+    return 1;
+  }
+
+  *descr = '\0';
+  n = arg->argn;
+  len = strlcat(descr, arg->argv[n++], sz);
+  while (n < arg->argc) {
+    if ((len = strlcat(descr, " ", sz)) >= sz
+    || (len = strlcat(descr, arg->argv[n], sz)) >= sz)
+      break;
+    ++n;
+  }
+  if (len >= sz) {
+    log_Printf(LogERROR, "iface descr: description exceeds maximum (%d)\n", (ifdescr_maxlen-1));
+    free(descr);
+    return 1;
+  }
+
+  if ((s = ID0socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
+    log_Printf(LogERROR, "iface descr: socket(): %s\n", strerror(errno));
+    free(descr);
+    return 1;
+  }
+
+  iface = arg->bundle->iface;
+  strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name));
+  ifr.ifr_buffer.length = strlen(descr) + 1;
+  ifr.ifr_buffer.buffer = descr;
+  if (ID0ioctl(s, SIOCSIFDESCR, (caddr_t)&ifr) < 0) {
+    log_Printf(LogWARN, "iface descr: ioctl(SIOCSIFDESCR, %s): %s\n",
+               descr, strerror(errno));
+    free(descr);
+    return 1;
+  }
+
+  if (iface->descr) free(iface->descr);
+  iface->descr = descr;
+  return 0;
+}
 
 void
 iface_Clear(struct iface *iface, struct ncp *ncp, int family, int how)
@@ -608,18 +702,40 @@ iface_ClearFlags(const char *ifname, int
 }
 
 void
+iface_Free(struct iface *iface)
+{
+    free(iface->name);
+    free(iface->descr);
+    free(iface->addr);
+    free(iface);
+}
+
+void
 iface_Destroy(struct iface *iface)
 {
+  struct ifreq ifr;
+  int s;
   /*
-   * iface_Clear(iface, IFACE_CLEAR_ALL) must be called manually
-   * if that's what the user wants.  It's better to leave the interface
-   * allocated so that existing connections can continue to work.
+   * Old behaviour used to leave interface created, but this
+   * conflicts with interface renaming.  When ppp is started
+   * it tries to open an unopened interface by /dev/tunX
+   * control device and then assumes the interface name
+   * corresponds to the control device name.  If an interface
+   * is renamed the tun(4) control device name won't correspond
+   * to the interface name anymore, so it must be destroyed
+   * when ppp is done with it.
    */
 
   if (iface != NULL) {
-    free(iface->name);
-    free(iface->addr);
-    free(iface);
+    if ((s = ID0socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
+      log_Printf(LogERROR, "iface_Destroy: socket(): %s\n", strerror(errno));
+    } else {
+      strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name));
+      if (ID0ioctl(s, SIOCIFDESTROY, (caddr_t)&ifr) < 0)
+        log_Printf(LogWARN, "iface_Destroy: ioctl(SIOCIFDESTROY, %s): %s\n",
+               iface->name, strerror(errno));
+    }
+    iface_Free(iface);
   }
 }
 
@@ -661,7 +777,7 @@ iface_Show(struct cmdargs const *arg)
 
   current = iface_Create(iface->name);
   flags = iface->flags = current->flags;
-  iface_Destroy(current);
+  iface_Free(current);
 
   prompt_Printf(arg->prompt, "%s (idx %d) <", iface->name, iface->index);
   for (f = 0; f < sizeof if_flags / sizeof if_flags[0]; f++)
--- usr.sbin/ppp/iface.h.orig	2009-08-03 10:13:06.000000000 +0200
+++ usr.sbin/ppp/iface.h	2010-08-15 04:22:20.000000000 +0200
@@ -36,6 +36,7 @@ struct iface_addr {
 
 struct iface {
   char *name;			/* Interface name (malloc'd) */
+  char *descr;			/* Interface description (malloc'd) */
   int index;			/* Interface index */
   int flags;			/* Interface flags (IFF_*) */
   unsigned long mtu;		/* struct tuninfo MTU */
@@ -55,11 +56,14 @@ struct iface {
 
 extern struct iface *iface_Create(const char *name);
 extern void iface_Clear(struct iface *, struct ncp *, int, int);
+extern int iface_Name(struct iface *, const char *);
+extern int iface_Descr(struct cmdargs const *);
 extern int iface_Add(struct iface *, struct ncp *, const struct ncprange *,
                      const struct ncpaddr *, int);
 extern int iface_Delete(struct iface *, struct ncp *, const struct ncpaddr *);
 extern int iface_Show(struct cmdargs const *);
 extern int iface_SetFlags(const char *, int);
 extern int iface_ClearFlags(const char *, int);
+extern void iface_Free(struct iface *);
 extern void iface_Destroy(struct iface *);
 extern void iface_ParseHdr(struct ifa_msghdr *, struct sockaddr *[RTAX_MAX]);
--- usr.sbin/ppp/log.c.orig	2010-08-15 03:56:43.000000000 +0200
+++ usr.sbin/ppp/log.c	2010-08-15 04:23:55.000000000 +0200
@@ -75,6 +75,7 @@ static const char *const LogNames[] = {
 static u_long LogMask = MSK(LogPHASE);
 static u_long LogMaskLocal = MSK(LogERROR) | MSK(LogALERT) | MSK(LogWARN);
 static int LogTunno = -1;
+static char *LogIfaceName = NULL;
 static struct prompt *promptlist;	/* Where to log local stuff */
 struct prompt *log_PromptContext;
 int log_PromptListChanged;
@@ -296,9 +297,10 @@ log_Open(const char *Name)
 }
 
 void
-log_SetTun(int tunno)
+log_SetTun(int tunno, char *ifaceName)
 {
   LogTunno = tunno;
+  LogIfaceName = ifaceName;
 }
 
 void
@@ -306,6 +308,7 @@ log_Close()
 {
   closelog();
   LogTunno = -1;
+  LogIfaceName = NULL;
 }
 
 void
@@ -320,8 +323,13 @@ log_Printf(int lev, const char *fmt,...)
     va_start(ap, fmt);
     if (promptlist && (log_IsKept(lev) & LOG_KEPT_LOCAL)) {
       if ((log_IsKept(LogTUN) & LOG_KEPT_LOCAL) && LogTunno != -1)
-        snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME,
+        if (LogIfaceName)
+          snprintf(nfmt, sizeof nfmt, "%s%d(%s): %s: %s", TUN_NAME,
+	         LogTunno, LogIfaceName, log_Name(lev), fmt);
+        else
+          snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME,
 	         LogTunno, log_Name(lev), fmt);
+          
       else
         snprintf(nfmt, sizeof nfmt, "%s: %s", log_Name(lev), fmt);
 
@@ -338,8 +346,13 @@ log_Printf(int lev, const char *fmt,...)
     if ((log_IsKept(lev) & LOG_KEPT_SYSLOG) &&
         (lev != LogWARN || !log_PromptContext)) {
       if ((log_IsKept(LogTUN) & LOG_KEPT_SYSLOG) && LogTunno != -1)
-        snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME,
+        if (LogIfaceName)
+          snprintf(nfmt, sizeof nfmt, "%s%d(%s): %s: %s", TUN_NAME,
+	         LogTunno, LogIfaceName, log_Name(lev), fmt);
+        else
+          snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME,
 	         LogTunno, log_Name(lev), fmt);
+          
       else
         snprintf(nfmt, sizeof nfmt, "%s: %s", log_Name(lev), fmt);
       vsyslog(syslogLevel(lev), nfmt, ap);
--- usr.sbin/ppp/log.h.orig	2010-08-15 03:57:48.000000000 +0200
+++ usr.sbin/ppp/log.h	2010-08-15 03:58:44.000000000 +0200
@@ -76,7 +76,7 @@ extern void log_DiscardAllLocal(u_long *
 extern int log_IsKept(int);
 extern int log_IsKeptLocal(int, u_long);
 extern void log_Open(const char *);
-extern void log_SetTun(int);
+extern void log_SetTun(int, char *);
 extern void log_Close(void);
 #ifdef __GNUC__
 extern void log_Printf(int, const char *,...)
--- usr.sbin/ppp/main.c.orig	2009-08-27 09:07:38.000000000 +0200
+++ usr.sbin/ppp/main.c	2010-08-14 22:37:41.000000000 +0200
@@ -386,11 +386,6 @@ main(int argc, char **argv)
 
   /* NOTE:  We may now have changed argv[1] via a ``set proctitle'' */
 
-  if (prompt) {
-    prompt->bundle = bundle;	/* couldn't do it earlier */
-    if (!sw.quiet)
-      prompt_Printf(prompt, "Using interface: %s\n", bundle->iface->name);
-  }
   SignalBundle = bundle;
   bundle->NatEnabled = sw.nat;
   if (sw.nat)
@@ -430,6 +425,12 @@ main(int argc, char **argv)
     AbortProgram(EX_START);
   }
 
+  if (prompt) {
+    prompt->bundle = bundle;	/* couldn't do it earlier */
+    if (!sw.quiet)
+      prompt_Printf(prompt, "Using interface: %s\n", bundle->iface->name);
+  } 
+
   if (sw.mode != PHYS_INTERACTIVE) {
     if (sw.mode != PHYS_DIRECT) {
       if (!sw.fg) {
--- usr.sbin/ppp/ppp.8.m4.orig	2009-08-29 06:15:37.000000000 +0200
+++ usr.sbin/ppp/ppp.8.m4	2010-08-15 03:24:25.000000000 +0200
@@ -3924,6 +3924,13 @@ If the
 .Dq !\&
 is used, no error is given if the address is not currently assigned to
 the interface (and no deletion takes place).
+.It iface name Ar name
+Renames tun interface to
+.Ar name .
+.It iface descr Ar description
+Sets tun interface description to
+.Ar description .
+Useful if you have many interfaces on your system.
 .It iface show
 Shows the current state and current addresses for the interface.
 It is much the same as running


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->brian 
Responsible-Changed-By: brian 
Responsible-Changed-When: Mon Feb 7 09:49:45 UTC 2011 
Responsible-Changed-Why:  
Take 

http://www.freebsd.org/cgi/query-pr.cgi?pr=151400 
State-Changed-From-To: open->patched 
State-Changed-By: brian 
State-Changed-When: Mon Feb 7 11:18:25 UTC 2011 
State-Changed-Why:  
Fix applied (r218397).  I'll MFC after 3 weeks if there are no problems 
reported. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=151400 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/151400: commit references a PR
Date: Mon,  7 Feb 2011 11:18:24 +0000 (UTC)

 Author: brian
 Date: Mon Feb  7 11:18:18 2011
 New Revision: 218397
 URL: http://svn.freebsd.org/changeset/base/218397
 
 Log:
   Add "iface name" and "iface description" commands.
   
   PR:		151400
   Submitted by:	Aragon Gouveia - aragon at phat dot za dot net with minor fixes
   MFC after:	3 weeks
 
 Modified:
   head/usr.sbin/ppp/bundle.c
   head/usr.sbin/ppp/command.c
   head/usr.sbin/ppp/iface.c
   head/usr.sbin/ppp/iface.h
   head/usr.sbin/ppp/log.c
   head/usr.sbin/ppp/log.h
   head/usr.sbin/ppp/main.c
   head/usr.sbin/ppp/ppp.8.m4
 
 Modified: head/usr.sbin/ppp/bundle.c
 ==============================================================================
 --- head/usr.sbin/ppp/bundle.c	Mon Feb  7 11:13:28 2011	(r218396)
 +++ head/usr.sbin/ppp/bundle.c	Mon Feb  7 11:18:18 2011	(r218397)
 @@ -758,7 +758,7 @@ bundle_Create(const char *prefix, int ty
      return NULL;
    }
  
 -  log_SetTun(bundle.unit);
 +  log_SetTun(bundle.unit, NULL);
  
    ifname = strrchr(bundle.dev.Name, '/');
    if (ifname == NULL)
 @@ -849,7 +849,7 @@ bundle_Create(const char *prefix, int ty
    bundle.links = datalink_Create("deflink", &bundle, type);
    if (bundle.links == NULL) {
      log_Printf(LogALERT, "Cannot create data link: %s\n", strerror(errno));
 -    iface_Destroy(bundle.iface);
 +    iface_Free(bundle.iface);
      bundle.iface = NULL;
      close(bundle.dev.fd);
      return NULL;
 
 Modified: head/usr.sbin/ppp/command.c
 ==============================================================================
 --- head/usr.sbin/ppp/command.c	Mon Feb  7 11:13:28 2011	(r218396)
 +++ head/usr.sbin/ppp/command.c	Mon Feb  7 11:18:18 2011	(r218397)
 @@ -184,6 +184,7 @@ static int DeleteCommand(struct cmdargs 
  static int NegotiateCommand(struct cmdargs const *);
  static int ClearCommand(struct cmdargs const *);
  static int RunListCommand(struct cmdargs const *);
 +static int IfaceNameCommand(struct cmdargs const *arg);
  static int IfaceAddCommand(struct cmdargs const *);
  static int IfaceDeleteCommand(struct cmdargs const *);
  static int IfaceClearCommand(struct cmdargs const *);
 @@ -823,6 +824,10 @@ static struct cmdtab const IfaceCommands
     "Delete iface address", "iface delete addr", (void *)1},
    {NULL, "delete!", IfaceDeleteCommand, LOCAL_AUTH,
     "Delete iface address", "iface delete addr", (void *)1},
 +  {"name", NULL, IfaceNameCommand, LOCAL_AUTH,
 +    "Set iface name", "iface name name", NULL},
 +  {"description", NULL, iface_Descr, LOCAL_AUTH,
 +    "Set iface description", "iface description text", NULL},
    {"show", NULL, iface_Show, LOCAL_AUTH,
     "Show iface address(es)", "iface show", NULL},
    {"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
 @@ -3176,6 +3181,21 @@ RunListCommand(struct cmdargs const *arg
  }
  
  static int
 +IfaceNameCommand(struct cmdargs const *arg)
 +{
 +  int n = arg->argn;
 +
 +  if (arg->argc != n + 1)
 +    return -1;
 +
 +  if (!iface_Name(arg->bundle->iface, arg->argv[n]))
 +    return 1;
 +
 +  log_SetTun(arg->bundle->unit, arg->bundle->iface->name);
 +  return 0;
 +}
 +
 +static int
  IfaceAddCommand(struct cmdargs const *arg)
  {
    struct ncpaddr peer, addr;
 
 Modified: head/usr.sbin/ppp/iface.c
 ==============================================================================
 --- head/usr.sbin/ppp/iface.c	Mon Feb  7 11:13:28 2011	(r218396)
 +++ head/usr.sbin/ppp/iface.c	Mon Feb  7 11:18:18 2011	(r218397)
 @@ -151,6 +151,7 @@ iface_Create(const char *name)
          return NULL;
        }
        iface->name = strdup(name);
 +      iface->descr = NULL;
        iface->index = ifm->ifm_index;
        iface->flags = ifm->ifm_flags;
        iface->mtu = 0;
 @@ -369,6 +370,103 @@ iface_addr_Add(const char *name, struct 
    return res != -1;
  }
  
 +int
 +iface_Name(struct iface *iface, const char *name)
 +{
 +  struct ifreq ifr;
 +  int s;
 +  char *newname;
 +
 +  if ((newname = strdup(name)) == NULL) {
 +    log_Printf(LogWARN, "iface name: strdup failed: %s\n", strerror(errno));
 +    return 0;
 +  }
 +
 +  if ((s = ID0socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
 +    log_Printf(LogERROR, "iface name: socket(): %s\n", strerror(errno));
 +    free(newname);
 +    return 0;
 +  }
 +
 +  strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name));
 +  ifr.ifr_data = newname;
 +  if (ID0ioctl(s, SIOCSIFNAME, (caddr_t)&ifr) < 0) {
 +    log_Printf(LogWARN, "iface name: ioctl(SIOCSIFNAME, %s -> %s): %s\n",
 +               name, newname, strerror(errno));
 +    free(newname);
 +    return 0;
 +  }
 +
 +  free(iface->name);
 +  iface->name = newname;
 +
 +  return 1;
 +}
 +
 +int
 +iface_Descr(struct cmdargs const *arg)
 +{
 +  struct ifreq ifr;
 +  struct iface *iface;
 +  size_t sz, len;
 +  int s, n, ifdescr_maxlen;
 +  char *descr;
 +
 +  sz = sizeof(int);
 +  if (sysctlbyname("net.ifdescr_maxlen", &ifdescr_maxlen, &sz, NULL, 0) < 0) {
 +    log_Printf(LogERROR, "iface descr: sysctl failed: %s\n", strerror(errno));
 +    return 1;
 +  }
 +
 +  if (ifdescr_maxlen < 1) {
 +    log_Printf(LogERROR, "iface descr: sysctl net.ifdescr_maxlen < 1\n");
 +    return 1;
 +  }
 +
 +  sz = sizeof(char) * ifdescr_maxlen;
 +  if ((descr = malloc(sz)) == NULL) {
 +    log_Printf(LogERROR, "iface descr: malloc failed: %s\n", strerror(errno));
 +    return 1;
 +  }
 +
 +  *descr = '\0';
 +  n = arg->argn;
 +  while (n < arg->argc) {
 +    if (n > arg->argn && (len = strlcat(descr, " ", sz)) >= sz)
 +      break;
 +    if ((len = strlcat(descr, arg->argv[n], sz)) >= sz)
 +      break;
 +    ++n;
 +  }
 +  if (len >= sz) {
 +    log_Printf(LogERROR, "iface descr: description exceeds maximum (%d)\n",
 +               ifdescr_maxlen-1);
 +    free(descr);
 +    return 1;
 +  }
 +
 +  if ((s = ID0socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
 +    log_Printf(LogERROR, "iface descr: socket(): %s\n", strerror(errno));
 +    free(descr);
 +    return 1;
 +  }
 +
 +  iface = arg->bundle->iface;
 +  strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name));
 +  ifr.ifr_buffer.length = strlen(descr) + 1;
 +  ifr.ifr_buffer.buffer = descr;
 +  if (ID0ioctl(s, SIOCSIFDESCR, (caddr_t)&ifr) < 0) {
 +    log_Printf(LogWARN, "iface descr: ioctl(SIOCSIFDESCR, %s): %s\n",
 +               descr, strerror(errno));
 +    free(descr);
 +    return 1;
 +  }
 +
 +  free(iface->descr);
 +  iface->descr = descr;
 +
 +  return 0;
 +}
  
  void
  iface_Clear(struct iface *iface, struct ncp *ncp, int family, int how)
 @@ -608,18 +706,30 @@ iface_ClearFlags(const char *ifname, int
  }
  
  void
 -iface_Destroy(struct iface *iface)
 +iface_Free(struct iface *iface)
  {
 -  /*
 -   * iface_Clear(iface, IFACE_CLEAR_ALL) must be called manually
 -   * if that's what the user wants.  It's better to leave the interface
 -   * allocated so that existing connections can continue to work.
 -   */
 -
 -  if (iface != NULL) {
      free(iface->name);
 +    free(iface->descr);
      free(iface->addr);
      free(iface);
 +}
 +
 +void
 +iface_Destroy(struct iface *iface)
 +{
 +  struct ifreq ifr;
 +  int s;
 +
 +  if (iface != NULL) {
 +    if ((s = ID0socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
 +      log_Printf(LogERROR, "iface_Destroy: socket(): %s\n", strerror(errno));
 +    } else {
 +      strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name));
 +      if (ID0ioctl(s, SIOCIFDESTROY, (caddr_t)&ifr) < 0)
 +        log_Printf(LogWARN, "iface_Destroy: ioctl(SIOCIFDESTROY, %s): %s\n",
 +               iface->name, strerror(errno));
 +    }
 +    iface_Free(iface);
    }
  }
  
 @@ -661,7 +771,7 @@ iface_Show(struct cmdargs const *arg)
  
    current = iface_Create(iface->name);
    flags = iface->flags = current->flags;
 -  iface_Destroy(current);
 +  iface_Free(current);
  
    prompt_Printf(arg->prompt, "%s (idx %d) <", iface->name, iface->index);
    for (f = 0; f < sizeof if_flags / sizeof if_flags[0]; f++)
 
 Modified: head/usr.sbin/ppp/iface.h
 ==============================================================================
 --- head/usr.sbin/ppp/iface.h	Mon Feb  7 11:13:28 2011	(r218396)
 +++ head/usr.sbin/ppp/iface.h	Mon Feb  7 11:18:18 2011	(r218397)
 @@ -36,6 +36,7 @@ struct iface_addr {
  
  struct iface {
    char *name;			/* Interface name (malloc'd) */
 +  char *descr;			/* Interface description (malloc'd) */
    int index;			/* Interface index */
    int flags;			/* Interface flags (IFF_*) */
    unsigned long mtu;		/* struct tuninfo MTU */
 @@ -55,11 +56,14 @@ struct iface {
  
  extern struct iface *iface_Create(const char *name);
  extern void iface_Clear(struct iface *, struct ncp *, int, int);
 +extern int iface_Name(struct iface *, const char *);
 +extern int iface_Descr(struct cmdargs const *);
  extern int iface_Add(struct iface *, struct ncp *, const struct ncprange *,
                       const struct ncpaddr *, int);
  extern int iface_Delete(struct iface *, struct ncp *, const struct ncpaddr *);
  extern int iface_Show(struct cmdargs const *);
  extern int iface_SetFlags(const char *, int);
  extern int iface_ClearFlags(const char *, int);
 +extern void iface_Free(struct iface *);
  extern void iface_Destroy(struct iface *);
  extern void iface_ParseHdr(struct ifa_msghdr *, struct sockaddr *[RTAX_MAX]);
 
 Modified: head/usr.sbin/ppp/log.c
 ==============================================================================
 --- head/usr.sbin/ppp/log.c	Mon Feb  7 11:13:28 2011	(r218396)
 +++ head/usr.sbin/ppp/log.c	Mon Feb  7 11:18:18 2011	(r218397)
 @@ -75,6 +75,7 @@ static const char *const LogNames[] = {
  static u_long LogMask = MSK(LogPHASE);
  static u_long LogMaskLocal = MSK(LogERROR) | MSK(LogALERT) | MSK(LogWARN);
  static int LogTunno = -1;
 +static const char *LogIfaceName;
  static struct prompt *promptlist;	/* Where to log local stuff */
  struct prompt *log_PromptContext;
  int log_PromptListChanged;
 @@ -296,9 +297,10 @@ log_Open(const char *Name)
  }
  
  void
 -log_SetTun(int tunno)
 +log_SetTun(int tunno, const char *ifaceName)
  {
    LogTunno = tunno;
 +  LogIfaceName = ifaceName;
  }
  
  void
 @@ -306,6 +308,7 @@ log_Close()
  {
    closelog();
    LogTunno = -1;
 +  LogIfaceName = NULL;
  }
  
  void
 @@ -319,10 +322,14 @@ log_Printf(int lev, const char *fmt,...)
  
      va_start(ap, fmt);
      if (promptlist && (log_IsKept(lev) & LOG_KEPT_LOCAL)) {
 -      if ((log_IsKept(LogTUN) & LOG_KEPT_LOCAL) && LogTunno != -1)
 -        snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME,
 +      if ((log_IsKept(LogTUN) & LOG_KEPT_LOCAL) && LogTunno != -1) {
 +        if (LogIfaceName)
 +          snprintf(nfmt, sizeof nfmt, "%s%d(%s): %s: %s", TUN_NAME,
 +	         LogTunno, LogIfaceName, log_Name(lev), fmt);
 +        else
 +          snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME,
  	         LogTunno, log_Name(lev), fmt);
 -      else
 +      } else
          snprintf(nfmt, sizeof nfmt, "%s: %s", log_Name(lev), fmt);
  
        if (log_PromptContext && lev == LogWARN)
 @@ -337,10 +344,14 @@ log_Printf(int lev, const char *fmt,...)
      va_start(ap, fmt);
      if ((log_IsKept(lev) & LOG_KEPT_SYSLOG) &&
          (lev != LogWARN || !log_PromptContext)) {
 -      if ((log_IsKept(LogTUN) & LOG_KEPT_SYSLOG) && LogTunno != -1)
 -        snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME,
 +      if ((log_IsKept(LogTUN) & LOG_KEPT_SYSLOG) && LogTunno != -1) {
 +        if (LogIfaceName)
 +          snprintf(nfmt, sizeof nfmt, "%s%d(%s): %s: %s", TUN_NAME,
 +	         LogTunno, LogIfaceName, log_Name(lev), fmt);
 +        else
 +          snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME,
  	         LogTunno, log_Name(lev), fmt);
 -      else
 +      } else
          snprintf(nfmt, sizeof nfmt, "%s: %s", log_Name(lev), fmt);
        vsyslog(syslogLevel(lev), nfmt, ap);
      }
 
 Modified: head/usr.sbin/ppp/log.h
 ==============================================================================
 --- head/usr.sbin/ppp/log.h	Mon Feb  7 11:13:28 2011	(r218396)
 +++ head/usr.sbin/ppp/log.h	Mon Feb  7 11:18:18 2011	(r218397)
 @@ -76,7 +76,7 @@ extern void log_DiscardAllLocal(u_long *
  extern int log_IsKept(int);
  extern int log_IsKeptLocal(int, u_long);
  extern void log_Open(const char *);
 -extern void log_SetTun(int);
 +extern void log_SetTun(int, const char *);
  extern void log_Close(void);
  #ifdef __GNUC__
  extern void log_Printf(int, const char *,...)
 
 Modified: head/usr.sbin/ppp/main.c
 ==============================================================================
 --- head/usr.sbin/ppp/main.c	Mon Feb  7 11:13:28 2011	(r218396)
 +++ head/usr.sbin/ppp/main.c	Mon Feb  7 11:18:18 2011	(r218397)
 @@ -386,11 +386,6 @@ main(int argc, char **argv)
  
    /* NOTE:  We may now have changed argv[1] via a ``set proctitle'' */
  
 -  if (prompt) {
 -    prompt->bundle = bundle;	/* couldn't do it earlier */
 -    if (!sw.quiet)
 -      prompt_Printf(prompt, "Using interface: %s\n", bundle->iface->name);
 -  }
    SignalBundle = bundle;
    bundle->NatEnabled = sw.nat;
    if (sw.nat)
 @@ -430,6 +425,12 @@ main(int argc, char **argv)
      AbortProgram(EX_START);
    }
  
 +  if (prompt) {
 +    prompt->bundle = bundle;	/* couldn't do it earlier */
 +    if (!sw.quiet)
 +      prompt_Printf(prompt, "Using interface: %s\n", bundle->iface->name);
 +  } 
 +
    if (sw.mode != PHYS_INTERACTIVE) {
      if (sw.mode != PHYS_DIRECT) {
        if (!sw.fg) {
 
 Modified: head/usr.sbin/ppp/ppp.8.m4
 ==============================================================================
 --- head/usr.sbin/ppp/ppp.8.m4	Mon Feb  7 11:13:28 2011	(r218396)
 +++ head/usr.sbin/ppp/ppp.8.m4	Mon Feb  7 11:18:18 2011	(r218397)
 @@ -3924,6 +3924,13 @@ If the
  .Dq !\&
  is used, no error is given if the address is not currently assigned to
  the interface (and no deletion takes place).
 +.It iface name Ar name
 +Renames the interface to
 +.Ar name .
 +.It iface description Ar description
 +Sets the interface description to
 +.Ar description .
 +Useful if you have many interfaces on your system.
  .It iface show
  Shows the current state and current addresses for the interface.
  It is much the same as running
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: brian 
State-Changed-When: Sun Jul 24 01:36:58 UTC 2011 
State-Changed-Why:  
Merged to stable/8 - r224285 

http://www.freebsd.org/cgi/query-pr.cgi?pr=151400 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/151400: commit references a PR
Date: Sun, 24 Jul 2011 01:36:23 +0000 (UTC)

 Author: brian
 Date: Sun Jul 24 01:36:01 2011
 New Revision: 224285
 URL: http://svn.freebsd.org/changeset/base/224285
 
 Log:
   MFC r218397: Add "iface name" and "iface description" commands.
   
   PR:		151400
   Submitted by:	Aragon Gouveia - aragon at phat dot za dot net
 
 Modified:
   stable/8/usr.sbin/ppp/bundle.c
   stable/8/usr.sbin/ppp/command.c
   stable/8/usr.sbin/ppp/iface.c
   stable/8/usr.sbin/ppp/iface.h
   stable/8/usr.sbin/ppp/log.c
   stable/8/usr.sbin/ppp/log.h
   stable/8/usr.sbin/ppp/main.c
   stable/8/usr.sbin/ppp/ppp.8.m4
 Directory Properties:
   stable/8/usr.sbin/ppp/   (props changed)
 
 Modified: stable/8/usr.sbin/ppp/bundle.c
 ==============================================================================
 --- stable/8/usr.sbin/ppp/bundle.c	Sat Jul 23 22:55:32 2011	(r224284)
 +++ stable/8/usr.sbin/ppp/bundle.c	Sun Jul 24 01:36:01 2011	(r224285)
 @@ -758,7 +758,7 @@ bundle_Create(const char *prefix, int ty
      return NULL;
    }
  
 -  log_SetTun(bundle.unit);
 +  log_SetTun(bundle.unit, NULL);
  
    ifname = strrchr(bundle.dev.Name, '/');
    if (ifname == NULL)
 @@ -849,7 +849,7 @@ bundle_Create(const char *prefix, int ty
    bundle.links = datalink_Create("deflink", &bundle, type);
    if (bundle.links == NULL) {
      log_Printf(LogALERT, "Cannot create data link: %s\n", strerror(errno));
 -    iface_Destroy(bundle.iface);
 +    iface_Free(bundle.iface);
      bundle.iface = NULL;
      close(bundle.dev.fd);
      return NULL;
 
 Modified: stable/8/usr.sbin/ppp/command.c
 ==============================================================================
 --- stable/8/usr.sbin/ppp/command.c	Sat Jul 23 22:55:32 2011	(r224284)
 +++ stable/8/usr.sbin/ppp/command.c	Sun Jul 24 01:36:01 2011	(r224285)
 @@ -184,6 +184,7 @@ static int DeleteCommand(struct cmdargs 
  static int NegotiateCommand(struct cmdargs const *);
  static int ClearCommand(struct cmdargs const *);
  static int RunListCommand(struct cmdargs const *);
 +static int IfaceNameCommand(struct cmdargs const *arg);
  static int IfaceAddCommand(struct cmdargs const *);
  static int IfaceDeleteCommand(struct cmdargs const *);
  static int IfaceClearCommand(struct cmdargs const *);
 @@ -823,6 +824,10 @@ static struct cmdtab const IfaceCommands
     "Delete iface address", "iface delete addr", (void *)1},
    {NULL, "delete!", IfaceDeleteCommand, LOCAL_AUTH,
     "Delete iface address", "iface delete addr", (void *)1},
 +  {"name", NULL, IfaceNameCommand, LOCAL_AUTH,
 +    "Set iface name", "iface name name", NULL},
 +  {"description", NULL, iface_Descr, LOCAL_AUTH,
 +    "Set iface description", "iface description text", NULL},
    {"show", NULL, iface_Show, LOCAL_AUTH,
     "Show iface address(es)", "iface show", NULL},
    {"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH,
 @@ -3176,6 +3181,21 @@ RunListCommand(struct cmdargs const *arg
  }
  
  static int
 +IfaceNameCommand(struct cmdargs const *arg)
 +{
 +  int n = arg->argn;
 +
 +  if (arg->argc != n + 1)
 +    return -1;
 +
 +  if (!iface_Name(arg->bundle->iface, arg->argv[n]))
 +    return 1;
 +
 +  log_SetTun(arg->bundle->unit, arg->bundle->iface->name);
 +  return 0;
 +}
 +
 +static int
  IfaceAddCommand(struct cmdargs const *arg)
  {
    struct ncpaddr peer, addr;
 
 Modified: stable/8/usr.sbin/ppp/iface.c
 ==============================================================================
 --- stable/8/usr.sbin/ppp/iface.c	Sat Jul 23 22:55:32 2011	(r224284)
 +++ stable/8/usr.sbin/ppp/iface.c	Sun Jul 24 01:36:01 2011	(r224285)
 @@ -151,6 +151,7 @@ iface_Create(const char *name)
          return NULL;
        }
        iface->name = strdup(name);
 +      iface->descr = NULL;
        iface->index = ifm->ifm_index;
        iface->flags = ifm->ifm_flags;
        iface->mtu = 0;
 @@ -369,6 +370,103 @@ iface_addr_Add(const char *name, struct 
    return res != -1;
  }
  
 +int
 +iface_Name(struct iface *iface, const char *name)
 +{
 +  struct ifreq ifr;
 +  int s;
 +  char *newname;
 +
 +  if ((newname = strdup(name)) == NULL) {
 +    log_Printf(LogWARN, "iface name: strdup failed: %s\n", strerror(errno));
 +    return 0;
 +  }
 +
 +  if ((s = ID0socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
 +    log_Printf(LogERROR, "iface name: socket(): %s\n", strerror(errno));
 +    free(newname);
 +    return 0;
 +  }
 +
 +  strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name));
 +  ifr.ifr_data = newname;
 +  if (ID0ioctl(s, SIOCSIFNAME, (caddr_t)&ifr) < 0) {
 +    log_Printf(LogWARN, "iface name: ioctl(SIOCSIFNAME, %s -> %s): %s\n",
 +               name, newname, strerror(errno));
 +    free(newname);
 +    return 0;
 +  }
 +
 +  free(iface->name);
 +  iface->name = newname;
 +
 +  return 1;
 +}
 +
 +int
 +iface_Descr(struct cmdargs const *arg)
 +{
 +  struct ifreq ifr;
 +  struct iface *iface;
 +  size_t sz, len;
 +  int s, n, ifdescr_maxlen;
 +  char *descr;
 +
 +  sz = sizeof(int);
 +  if (sysctlbyname("net.ifdescr_maxlen", &ifdescr_maxlen, &sz, NULL, 0) < 0) {
 +    log_Printf(LogERROR, "iface descr: sysctl failed: %s\n", strerror(errno));
 +    return 1;
 +  }
 +
 +  if (ifdescr_maxlen < 1) {
 +    log_Printf(LogERROR, "iface descr: sysctl net.ifdescr_maxlen < 1\n");
 +    return 1;
 +  }
 +
 +  sz = sizeof(char) * ifdescr_maxlen;
 +  if ((descr = malloc(sz)) == NULL) {
 +    log_Printf(LogERROR, "iface descr: malloc failed: %s\n", strerror(errno));
 +    return 1;
 +  }
 +
 +  *descr = '\0';
 +  n = arg->argn;
 +  while (n < arg->argc) {
 +    if (n > arg->argn && (len = strlcat(descr, " ", sz)) >= sz)
 +      break;
 +    if ((len = strlcat(descr, arg->argv[n], sz)) >= sz)
 +      break;
 +    ++n;
 +  }
 +  if (len >= sz) {
 +    log_Printf(LogERROR, "iface descr: description exceeds maximum (%d)\n",
 +               ifdescr_maxlen-1);
 +    free(descr);
 +    return 1;
 +  }
 +
 +  if ((s = ID0socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
 +    log_Printf(LogERROR, "iface descr: socket(): %s\n", strerror(errno));
 +    free(descr);
 +    return 1;
 +  }
 +
 +  iface = arg->bundle->iface;
 +  strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name));
 +  ifr.ifr_buffer.length = strlen(descr) + 1;
 +  ifr.ifr_buffer.buffer = descr;
 +  if (ID0ioctl(s, SIOCSIFDESCR, (caddr_t)&ifr) < 0) {
 +    log_Printf(LogWARN, "iface descr: ioctl(SIOCSIFDESCR, %s): %s\n",
 +               descr, strerror(errno));
 +    free(descr);
 +    return 1;
 +  }
 +
 +  free(iface->descr);
 +  iface->descr = descr;
 +
 +  return 0;
 +}
  
  void
  iface_Clear(struct iface *iface, struct ncp *ncp, int family, int how)
 @@ -608,18 +706,30 @@ iface_ClearFlags(const char *ifname, int
  }
  
  void
 -iface_Destroy(struct iface *iface)
 +iface_Free(struct iface *iface)
  {
 -  /*
 -   * iface_Clear(iface, IFACE_CLEAR_ALL) must be called manually
 -   * if that's what the user wants.  It's better to leave the interface
 -   * allocated so that existing connections can continue to work.
 -   */
 -
 -  if (iface != NULL) {
      free(iface->name);
 +    free(iface->descr);
      free(iface->addr);
      free(iface);
 +}
 +
 +void
 +iface_Destroy(struct iface *iface)
 +{
 +  struct ifreq ifr;
 +  int s;
 +
 +  if (iface != NULL) {
 +    if ((s = ID0socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
 +      log_Printf(LogERROR, "iface_Destroy: socket(): %s\n", strerror(errno));
 +    } else {
 +      strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name));
 +      if (ID0ioctl(s, SIOCIFDESTROY, (caddr_t)&ifr) < 0)
 +        log_Printf(LogWARN, "iface_Destroy: ioctl(SIOCIFDESTROY, %s): %s\n",
 +               iface->name, strerror(errno));
 +    }
 +    iface_Free(iface);
    }
  }
  
 @@ -661,7 +771,7 @@ iface_Show(struct cmdargs const *arg)
  
    current = iface_Create(iface->name);
    flags = iface->flags = current->flags;
 -  iface_Destroy(current);
 +  iface_Free(current);
  
    prompt_Printf(arg->prompt, "%s (idx %d) <", iface->name, iface->index);
    for (f = 0; f < sizeof if_flags / sizeof if_flags[0]; f++)
 
 Modified: stable/8/usr.sbin/ppp/iface.h
 ==============================================================================
 --- stable/8/usr.sbin/ppp/iface.h	Sat Jul 23 22:55:32 2011	(r224284)
 +++ stable/8/usr.sbin/ppp/iface.h	Sun Jul 24 01:36:01 2011	(r224285)
 @@ -36,6 +36,7 @@ struct iface_addr {
  
  struct iface {
    char *name;			/* Interface name (malloc'd) */
 +  char *descr;			/* Interface description (malloc'd) */
    int index;			/* Interface index */
    int flags;			/* Interface flags (IFF_*) */
    unsigned long mtu;		/* struct tuninfo MTU */
 @@ -55,11 +56,14 @@ struct iface {
  
  extern struct iface *iface_Create(const char *name);
  extern void iface_Clear(struct iface *, struct ncp *, int, int);
 +extern int iface_Name(struct iface *, const char *);
 +extern int iface_Descr(struct cmdargs const *);
  extern int iface_Add(struct iface *, struct ncp *, const struct ncprange *,
                       const struct ncpaddr *, int);
  extern int iface_Delete(struct iface *, struct ncp *, const struct ncpaddr *);
  extern int iface_Show(struct cmdargs const *);
  extern int iface_SetFlags(const char *, int);
  extern int iface_ClearFlags(const char *, int);
 +extern void iface_Free(struct iface *);
  extern void iface_Destroy(struct iface *);
  extern void iface_ParseHdr(struct ifa_msghdr *, struct sockaddr *[RTAX_MAX]);
 
 Modified: stable/8/usr.sbin/ppp/log.c
 ==============================================================================
 --- stable/8/usr.sbin/ppp/log.c	Sat Jul 23 22:55:32 2011	(r224284)
 +++ stable/8/usr.sbin/ppp/log.c	Sun Jul 24 01:36:01 2011	(r224285)
 @@ -75,6 +75,7 @@ static const char *const LogNames[] = {
  static u_long LogMask = MSK(LogPHASE);
  static u_long LogMaskLocal = MSK(LogERROR) | MSK(LogALERT) | MSK(LogWARN);
  static int LogTunno = -1;
 +static const char *LogIfaceName;
  static struct prompt *promptlist;	/* Where to log local stuff */
  struct prompt *log_PromptContext;
  int log_PromptListChanged;
 @@ -296,9 +297,10 @@ log_Open(const char *Name)
  }
  
  void
 -log_SetTun(int tunno)
 +log_SetTun(int tunno, const char *ifaceName)
  {
    LogTunno = tunno;
 +  LogIfaceName = ifaceName;
  }
  
  void
 @@ -306,6 +308,7 @@ log_Close()
  {
    closelog();
    LogTunno = -1;
 +  LogIfaceName = NULL;
  }
  
  void
 @@ -319,10 +322,14 @@ log_Printf(int lev, const char *fmt,...)
  
      va_start(ap, fmt);
      if (promptlist && (log_IsKept(lev) & LOG_KEPT_LOCAL)) {
 -      if ((log_IsKept(LogTUN) & LOG_KEPT_LOCAL) && LogTunno != -1)
 -        snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME,
 +      if ((log_IsKept(LogTUN) & LOG_KEPT_LOCAL) && LogTunno != -1) {
 +        if (LogIfaceName)
 +          snprintf(nfmt, sizeof nfmt, "%s%d(%s): %s: %s", TUN_NAME,
 +	         LogTunno, LogIfaceName, log_Name(lev), fmt);
 +        else
 +          snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME,
  	         LogTunno, log_Name(lev), fmt);
 -      else
 +      } else
          snprintf(nfmt, sizeof nfmt, "%s: %s", log_Name(lev), fmt);
  
        if (log_PromptContext && lev == LogWARN)
 @@ -337,10 +344,14 @@ log_Printf(int lev, const char *fmt,...)
      va_start(ap, fmt);
      if ((log_IsKept(lev) & LOG_KEPT_SYSLOG) &&
          (lev != LogWARN || !log_PromptContext)) {
 -      if ((log_IsKept(LogTUN) & LOG_KEPT_SYSLOG) && LogTunno != -1)
 -        snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME,
 +      if ((log_IsKept(LogTUN) & LOG_KEPT_SYSLOG) && LogTunno != -1) {
 +        if (LogIfaceName)
 +          snprintf(nfmt, sizeof nfmt, "%s%d(%s): %s: %s", TUN_NAME,
 +	         LogTunno, LogIfaceName, log_Name(lev), fmt);
 +        else
 +          snprintf(nfmt, sizeof nfmt, "%s%d: %s: %s", TUN_NAME,
  	         LogTunno, log_Name(lev), fmt);
 -      else
 +      } else
          snprintf(nfmt, sizeof nfmt, "%s: %s", log_Name(lev), fmt);
        vsyslog(syslogLevel(lev), nfmt, ap);
      }
 
 Modified: stable/8/usr.sbin/ppp/log.h
 ==============================================================================
 --- stable/8/usr.sbin/ppp/log.h	Sat Jul 23 22:55:32 2011	(r224284)
 +++ stable/8/usr.sbin/ppp/log.h	Sun Jul 24 01:36:01 2011	(r224285)
 @@ -76,7 +76,7 @@ extern void log_DiscardAllLocal(u_long *
  extern int log_IsKept(int);
  extern int log_IsKeptLocal(int, u_long);
  extern void log_Open(const char *);
 -extern void log_SetTun(int);
 +extern void log_SetTun(int, const char *);
  extern void log_Close(void);
  #ifdef __GNUC__
  extern void log_Printf(int, const char *,...)
 
 Modified: stable/8/usr.sbin/ppp/main.c
 ==============================================================================
 --- stable/8/usr.sbin/ppp/main.c	Sat Jul 23 22:55:32 2011	(r224284)
 +++ stable/8/usr.sbin/ppp/main.c	Sun Jul 24 01:36:01 2011	(r224285)
 @@ -386,11 +386,6 @@ main(int argc, char **argv)
  
    /* NOTE:  We may now have changed argv[1] via a ``set proctitle'' */
  
 -  if (prompt) {
 -    prompt->bundle = bundle;	/* couldn't do it earlier */
 -    if (!sw.quiet)
 -      prompt_Printf(prompt, "Using interface: %s\n", bundle->iface->name);
 -  }
    SignalBundle = bundle;
    bundle->NatEnabled = sw.nat;
    if (sw.nat)
 @@ -430,6 +425,12 @@ main(int argc, char **argv)
      AbortProgram(EX_START);
    }
  
 +  if (prompt) {
 +    prompt->bundle = bundle;	/* couldn't do it earlier */
 +    if (!sw.quiet)
 +      prompt_Printf(prompt, "Using interface: %s\n", bundle->iface->name);
 +  } 
 +
    if (sw.mode != PHYS_INTERACTIVE) {
      if (sw.mode != PHYS_DIRECT) {
        if (!sw.fg) {
 
 Modified: stable/8/usr.sbin/ppp/ppp.8.m4
 ==============================================================================
 --- stable/8/usr.sbin/ppp/ppp.8.m4	Sat Jul 23 22:55:32 2011	(r224284)
 +++ stable/8/usr.sbin/ppp/ppp.8.m4	Sun Jul 24 01:36:01 2011	(r224285)
 @@ -3924,6 +3924,13 @@ If the
  .Dq !\&
  is used, no error is given if the address is not currently assigned to
  the interface (and no deletion takes place).
 +.It iface name Ar name
 +Renames the interface to
 +.Ar name .
 +.It iface description Ar description
 +Sets the interface description to
 +.Ar description .
 +Useful if you have many interfaces on your system.
  .It iface show
  Shows the current state and current addresses for the interface.
  It is much the same as running
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
