[Zrouter-src] ZRouter.org: push to ZRouter contrib/mpd/Makefile contrib/mpd/co...

zrouter-src at zrouter.org zrouter-src at zrouter.org
Thu Sep 13 23:11:17 UTC 2012


details:   http://zrouter.org/hg/zrouter//rev/a245241eda54
changeset: 419:a245241eda54
user:      Aleksandr Rybalko <ray at ddteam.net>
date:      Fri Sep 14 02:13:58 2012 +0300
description:
Update MPD.

diffstat:

 contrib/mpd/Makefile                             |    6 +-
 contrib/mpd/conf/dictionary.mpd                  |    4 +
 contrib/mpd/doc/auth.sgml                        |   13 +-
 contrib/mpd/doc/changes.sgml                     |   44 +-
 contrib/mpd/doc/gencmd.sgml                      |    8 +-
 contrib/mpd/doc/interface.sgml                   |   22 +-
 contrib/mpd/doc/trafacct.sgml                    |   30 +-
 contrib/mpd/port/mpd5.sh                         |    2 +-
 contrib/mpd/src/Makefile                         |   32 +-
 contrib/mpd/src/auth.c                           |   34 +-
 contrib/mpd/src/auth.h                           |    9 +
 contrib/mpd/src/bund.c                           |   24 +-
 contrib/mpd/src/ccp.c                            |   14 +-
 contrib/mpd/src/ccp_deflate.c                    |   16 +-
 contrib/mpd/src/ccp_mppc.c                       |   22 +-
 contrib/mpd/src/ccp_pred1.c                      |   16 +-
 contrib/mpd/src/chat.c                           |    4 +-
 contrib/mpd/src/command.c                        |   26 +-
 contrib/mpd/src/console.c                        |   34 +-
 contrib/mpd/src/console.h                        |    1 +
 contrib/mpd/src/contrib/libpdel/util/pevent.c    |    8 +-
 contrib/mpd/src/contrib/libpdel/util/typed_mem.c |   12 +-
 contrib/mpd/src/defs.h                           |    3 +
 contrib/mpd/src/ecp.c                            |   11 +-
 contrib/mpd/src/event.c                          |    4 +-
 contrib/mpd/src/iface.c                          |  691 +++++++++++++++++-----
 contrib/mpd/src/iface.h                          |   11 +
 contrib/mpd/src/ipcp.c                           |   22 +-
 contrib/mpd/src/ippool.c                         |    2 +-
 contrib/mpd/src/l2tp.c                           |  125 +--
 contrib/mpd/src/l2tp_ctrl.c                      |   52 +-
 contrib/mpd/src/lcp.c                            |   10 +-
 contrib/mpd/src/link.c                           |   37 +-
 contrib/mpd/src/main.c                           |    8 +-
 contrib/mpd/src/mbuf.h                           |    2 +
 contrib/mpd/src/modem.c                          |  245 ++++----
 contrib/mpd/src/msg.c                            |    2 +-
 contrib/mpd/src/nat.h                            |    3 +
 contrib/mpd/src/ng.c                             |   10 +-
 contrib/mpd/src/ngfunc.c                         |  183 ++++-
 contrib/mpd/src/phys.c                           |    4 +-
 contrib/mpd/src/pppoe.c                          |   98 +-
 contrib/mpd/src/pptp.c                           |   37 +-
 contrib/mpd/src/pptp_ctrl.c                      |    2 +-
 contrib/mpd/src/pptp_ctrl.h                      |    4 +-
 contrib/mpd/src/proto.c                          |   28 +-
 contrib/mpd/src/radius.c                         |   89 ++-
 contrib/mpd/src/radius.h                         |    7 +-
 contrib/mpd/src/radsrv.c                         |    2 +-
 contrib/mpd/src/rep.c                            |   10 +-
 contrib/mpd/src/tcp.c                            |   66 +-
 contrib/mpd/src/udp.c                            |   42 +-
 contrib/mpd/src/util.c                           |   35 +-
 contrib/mpd/src/web.c                            |   50 +-
 54 files changed, 1519 insertions(+), 757 deletions(-)

diffs (5537 lines):

diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/Makefile
--- a/contrib/mpd/Makefile	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/Makefile	Fri Sep 14 02:13:58 2012 +0300
@@ -1,11 +1,11 @@
-# $Id: Makefile,v 1.12 2007/09/16 14:03:57 amotin Exp $
+# $Id: Makefile,v 1.13 2011/12/21 14:58:09 amotin Exp $
 
 VERSION!=	cat src/Makefile | grep ^VERSION | awk '{ print $$2 }'
 
 DISTNAME=	mpd-${VERSION}
 TARBALL=	${DISTNAME}.tar.gz
 PORTBALL=	port.tgz
-CVSROOT?=	mpd.cvs.sourceforge.net:/cvsroot/mpd
+CVSROOT?=	:pserver:anonymous at mpd.cvs.sourceforge.net:/cvsroot/mpd
 
 all:		${TARBALL} ${PORTBALL}
 
@@ -38,7 +38,7 @@
 	cp dist/Makefile ${DISTNAME}
 	cp dist/Makefile.conf ${DISTNAME}/conf/Makefile
 	cp dist/Makefile.doc ${DISTNAME}/doc/Makefile
-	cp src/COPYRIGHT* src/Makefile src/[a-z]* ${DISTNAME}/src
+	cp -r src/COPYRIGHT* src/Makefile src/[a-z]* ${DISTNAME}/src
 	sed 's/@VERSION@/${VERSION}/g' < src/Makefile > ${DISTNAME}/src/Makefile
 	cp doc/mpd*.html doc/mpd.ps ${DISTNAME}/doc
 	cp doc/mpd.8 ${DISTNAME}/doc/mpd5.8.in
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/conf/dictionary.mpd
--- a/contrib/mpd/conf/dictionary.mpd	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/conf/dictionary.mpd	Fri Sep 14 02:13:58 2012 +0300
@@ -23,6 +23,10 @@
 ATTRIBUTE	mpd-input-acct	16	string
 ATTRIBUTE	mpd-output-acct	17	string
 ATTRIBUTE	mpd-action	18	string
+ATTRIBUTE	mpd-peer-ident	19	string
+ATTRIBUTE	mpd-iface-name	20	string
+ATTRIBUTE	mpd-iface-descr	21	string
+ATTRIBUTE	mpd-iface-group	22	string
 ATTRIBUTE	mpd-drop-user	154	integer
 
 END-VENDOR	mpd
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/doc/auth.sgml
--- a/contrib/mpd/doc/auth.sgml	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/doc/auth.sgml	Fri Sep 14 02:13:58 2012 +0300
@@ -1,4 +1,4 @@
-<!-- $Id: auth.sgml,v 1.52 2010/08/27 10:06:03 amotin Exp $ -->
+<!-- $Id: auth.sgml,v 1.55 2011/08/30 11:47:02 dmitryluhtionov Exp $ -->
 <!-- mpd netgraph enabled user mode PPP daemon -->
 
 <!-- <!DOCTYPE linuxdoc PUBLIC '-//FreeBSD//DTD linuxdoc//EN'> -->
@@ -339,6 +339,10 @@
 16  mpd-input-acct		-	+	-	-
 17  mpd-output-acct		-	+	-	-
 18  mpd-action			-	+	-	-
+19  mpd-peer-ident		+	-	+	-
+20  mpd-iface-name		-	+	-	-
+21  mpd-iface-descr		-	+	-	-
+22  mpd-iface-group		-	+	-	-
 154 mpd-drop-user		-	-	-	+
 </VERB>
 
@@ -368,6 +372,10 @@
 ATTRIBUTE	mpd-input-acct	16	string
 ATTRIBUTE	mpd-output-acct	17	string
 ATTRIBUTE	mpd-action	18	string
+ATTRIBUTE	mpd-peer-ident	19	string
+ATTRIBUTE	mpd-iface-name	20	string
+ATTRIBUTE	mpd-iface-descr	21	string
+ATTRIBUTE	mpd-iface-group	22	string
 ATTRIBUTE	mpd-drop-user	154	integer
 
 END-VENDOR	mpd
@@ -561,6 +569,9 @@
 MPD_OUTPUT_PACKETS		-	-	+	-
 MPD_ACTION			-	+	-	-
 MPD_DROP_USER			-	-	-	+
+MPD_IFACE_NAME			-	+	-	-
+MPD_IFACE_DESCR			-	+	-	-
+MPD_IFACE_GROUP			-	+	-	-
 </verb>
 
 Attribute USER_PASSWORD provided in Access-Request only for PAP auth.
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/doc/changes.sgml
--- a/contrib/mpd/doc/changes.sgml	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/doc/changes.sgml	Fri Sep 14 02:13:58 2012 +0300
@@ -1,4 +1,4 @@
-<!-- $Id: changes.sgml,v 1.265 2011/04/15 19:01:36 amotin Exp $ -->
+<!-- $Id: changes.sgml,v 1.278 2012/03/19 08:30:45 amotin Exp $ -->
 <!-- mpd netgraph enabled user mode PPP daemon -->
 
 <!-- <!DOCTYPE linuxdoc PUBLIC '-//FreeBSD//DTD linuxdoc//EN'> -->
@@ -6,10 +6,46 @@
   <sect><heading>Change history<label id="changes"></heading>
 
   <p>
+    Changes since version 5.6:
+    <itemize>
+	<item> New features:
+	<itemize>
+	  <item> Added `unset radius server ...` command.
+	  </item>
+	</itemize>
+	</item>
+	<item> Bugfixes:
+	<itemize>
+	  <item> Restore `show sessions` as unprivileged command.
+	  </item>
+	  <item> Fix infinite event loop when STDIN redirected to /dev/null
+		 after it recently got non-blocking mode support.
+	  </item>
+	</itemize>
+	</item>
+    </itemize>
+  </p>
+  <p>
     Changes since version 5.5:
     <itemize>
 	<item> New features:
 	<itemize>
+	  <item> Added `mpd-iface-name` RADIUS attribute.
+	  </item>
+	  <item> Added `mpd-iface-descr` RADIUS attribute.
+	  </item>
+	  <item> Added `mpd-iface-group` RADIUS attribute.
+	  </item>
+	  <item> Added `mpd-peer-ident` RADIUS attribute.
+	  </item>
+	  <item> Added `set iface name ...` command.
+	  </item>
+	  <item> Added `set iface description ...` command.
+	  </item>
+	  <item> Added `set iface group ...` command.
+	  </item>
+	  <item> Added support for NetFlow v9 export.
+	  </item>
 	  <item> Added `set l2tp|pptp|tcp|udp resolve-once ...` command.
 		They allow to resolve peer address every time on reconnect.
 	  </item>
@@ -24,6 +60,10 @@
 	</item>
 	<item> Bugfixes:
 	<itemize>
+	  <item> Fix invoke `set iface up|down-script` without arguments.
+	  </item>
+	  <item> Fix `show eap` command
+	  </item>
 	  <item> Fix build on older FreeBSD versions.
 	  </item>
 	  <item> Fix several memory leaks.
@@ -32,6 +72,8 @@
 	  </item>
 	  <item> Fix byte order in ports in `set nat red-port`.
 	  </item>
+	  <item> Fix some potential crashes because of NULL dereferences.
+	  </item>
 	</itemize>
 	</item>
     </itemize>
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/doc/gencmd.sgml
--- a/contrib/mpd/doc/gencmd.sgml	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/doc/gencmd.sgml	Fri Sep 14 02:13:58 2012 +0300
@@ -1,4 +1,4 @@
-<!-- $Id: gencmd.sgml,v 1.46 2009/07/17 12:37:01 amotin Exp $ -->
+<!-- $Id: gencmd.sgml,v 1.47 2012/03/19 08:30:45 amotin Exp $ -->
 <!-- mpd netgraph enabled user mode PPP daemon -->
 
 <!-- <!DOCTYPE linuxdoc PUBLIC '-//FreeBSD//DTD linuxdoc//EN'> -->
@@ -324,6 +324,12 @@
 Sets web server specific configuration parameters
 </descrip>
 
+<tag><tt>unset ...</tt></tag>
+
+<p>
+This command allows to unsets some of configuration information set using
+<tt>set</tt> command.
+
 <tag><tt>open [ <em>layer</em> ] </tt>
 </tag>
 
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/doc/interface.sgml
--- a/contrib/mpd/doc/interface.sgml	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/doc/interface.sgml	Fri Sep 14 02:13:58 2012 +0300
@@ -1,4 +1,4 @@
-<!-- $Id: interface.sgml,v 1.27 2009/10/30 15:31:04 amotin Exp $ -->
+<!-- $Id: interface.sgml,v 1.29 2011/08/30 11:47:02 dmitryluhtionov Exp $ -->
 <!-- mpd netgraph enabled user mode PPP daemon -->
 
 <!-- <!DOCTYPE linuxdoc PUBLIC '-//FreeBSD//DTD linuxdoc//EN'> -->
@@ -19,6 +19,26 @@
 <descrip>
 
 <tag><tt>
+set iface name [ <em>name</em> ]
+</tt></tag>
+
+This command changes interface name from default ngX to specified one.
+If name argument is not specified, original ngX name is restored.
+Note that inside Netgraph original ngX name is always used.
+
+<tag><tt>
+set iface description [ <em>description</em> ]
+</tt></tag>
+
+This command changes interface description.
+
+<tag><tt>
+set iface group [ <em>group</em> ]
+</tt></tag>
+
+This command add interface to specific group.
+
+<tag><tt>
 set iface addrs [!]<em>local-ip</em> [!]<em>remote-ip</em>
 </tt></tag>
 
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/doc/trafacct.sgml
--- a/contrib/mpd/doc/trafacct.sgml	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/doc/trafacct.sgml	Fri Sep 14 02:13:58 2012 +0300
@@ -1,4 +1,4 @@
-<!-- $Id: trafacct.sgml,v 1.6 2009/02/23 11:17:41 amotin Exp $ -->
+<!-- $Id: trafacct.sgml,v 1.8 2011/08/01 09:04:29 dmitryluhtionov Exp $ -->
 <!-- mpd netgraph enabled user mode PPP daemon -->
 
 <!-- <!DOCTYPE linuxdoc PUBLIC '-//FreeBSD//DTD linuxdoc//EN'> -->
@@ -22,7 +22,7 @@
   so it must be done before first bundle get connected.
 
   <bf>Note:</bf> This feature is available only on FreeBSD 6.0-RELEASE
-  and newer.
+  and newer. NetFlow v9 supprted only on FreeBSD 9.0-RELEASE and newer.
 
 <descrip>
 
@@ -41,6 +41,32 @@
 originate from a specific source.
 
 <tag><tt>
+set netflow version <em>ver</em>
+</tt></tag>
+
+Choose NetFlow version to export. Supported options are 5 or 9.
+
+Default is 5.
+
+<tag><tt>
+set netflow mtu <em>bytes</em>
+</tt></tag>
+
+Set export interface MTU to build packets of specified size (NetFlow
+v9-specific).
+
+Default is 1500.
+
+<tag><tt>
+set netflow template <em>time</em> <em>packets</em>
+</tt></tag>
+
+Modify time and packet timeouts to announce data flow templates (NetFlow
+v9-specific).
+
+Defaults are 600 and 500.
+
+<tag><tt>
 set netflow timeouts <em>inactive</em> <em>active</em>
 </tt></tag>
 
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/port/mpd5.sh
--- a/contrib/mpd/port/mpd5.sh	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/port/mpd5.sh	Fri Sep 14 02:13:58 2012 +0300
@@ -15,7 +15,7 @@
 # mpd_flags (string):	Set to "-b" by default.
 #			Extra flags passed to start command.
 #
-# See mpd(8) for flags.
+# See mpd5(8) for flags.
 #
 
 . %%RC_SUBR%%
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/Makefile
--- a/contrib/mpd/src/Makefile	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/Makefile	Fri Sep 14 02:13:58 2012 +0300
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.102 2010/12/21 12:14:29 amotin Exp $
+# $Id: Makefile,v 1.107 2012/01/11 11:50:16 amotin Exp $
 #
 # Makefile for mpd, multi-link PPP daemon for FreeBSD
 #
@@ -10,7 +10,7 @@
 PROG?=			mpd5
 PREFIX?=		/usr/local
 BINDIR?=		${PREFIX}/sbin
-VERSION=		5.6a1
+VERSION=		5.7a
 NOMAN=
 NO_MAN=
 
@@ -61,6 +61,10 @@
 
 NOLIBPDEL=		yes
 
+# Build without builtin web server
+
+NOWEB=			yes
+
 # Set syslog logging facility. Change LOG_DAEMON to whatever you like.
 
 SYSLOG_FACILITY=	LOG_DAEMON
@@ -138,15 +142,25 @@
 		console.c command.c ecp.c event.c fsm.c iface.c input.c \
 		ip.c ipcp.c ipv6cp.c lcp.c link.c log.c main.c mbuf.c mp.c \
 		msg.c ngfunc.c pap.c phys.c proto.c radius.c radsrv.c timer.c \
-		util.c vars.c eap.c msoft.c web.c ippool.c
+		util.c vars.c eap.c msoft.c ippool.c
+
+.if defined ( NOWEB )
+COPTS+=		-DNOWEB
+.else
+STDSRCS+=	web.c
+.endif
 
 .if defined ( NOLIBPDEL )
 COPTS+=		-DNOLIBPDEL -I./contrib/libpdel
 PDPATH1=	contrib/libpdel/util:contrib/libpdel/structs
-PDPATH2=	contrib/libpdel/http:contrib/libpdel/http/servlet
-PDPATH3=	contrib/libpdel/sys:contrib/libpdel/io
-PDPATH4=	contrib/libpdel/structs/type
+PDPATH2=	contrib/libpdel/structs/type
+.if defined ( NOWEB )
+VPATH+=		$(PDPATH1):$(PDPATH2)
+.else
+PDPATH3=	contrib/libpdel/http:contrib/libpdel/http/servlet
+PDPATH4=	contrib/libpdel/io
 VPATH+=		$(PDPATH1):$(PDPATH2):$(PDPATH3):$(PDPATH4)
+.endif
 PDELSRCS=	typed_mem.c \
 		pevent.c \
 		paction.c \
@@ -158,8 +172,9 @@
 		structs_type_array.c \
 		structs_type_int.c \
 		structs_type_string.c \
-		structs_type_struct.c \
-		http_connection.c \
+		structs_type_struct.c
+.if !defined ( NOWEB )
+PDELSRCS+=	http_connection.c \
 		http_head.c \
 		http_message.c \
 		http_mime.c \
@@ -174,6 +189,7 @@
 		string_fp.c \
 		timeout_fp.c
 .endif
+.endif
 
 # Add sources and flags for the various physical layer types
 
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/auth.c
--- a/contrib/mpd/src/auth.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/auth.c	Fri Sep 14 02:13:58 2012 +0300
@@ -179,6 +179,10 @@
 
 void	authparamsInit(struct authparams *ap) {
     memset(ap,0,sizeof(struct authparams));
+    ap->msdomain = NULL;
+#ifdef SIOCSIFDESCR
+    ap->ifdescr = NULL;
+#endif
     SLIST_INIT(&ap->routes);
 }
 
@@ -212,6 +216,9 @@
     }
 
     Freee(ap->msdomain);
+#ifdef SIOCSIFDESCR
+    Freee(ap->ifdescr);
+#endif
     
     memset(ap,0,sizeof(struct authparams));
 }
@@ -252,6 +259,10 @@
 
     if (src->msdomain)
 	dst->msdomain = Mstrdup(MB_AUTH, src->msdomain);
+#ifdef SIOCSIFDESCR
+    if (src->ifdescr)
+	dst->ifdescr = Mstrdup(MB_AUTH, src->ifdescr);
+#endif
 }
 
 void	authparamsMove(struct authparams *src, struct authparams *dst)
@@ -709,6 +720,14 @@
 
     Printf("Auth Data\r\n");
     Printf("\tPeer authname   : %s\r\n", au->params.authname);
+    Printf("\tInterface name  : %s\r\n", au->params.ifname);
+#ifdef SIOCSIFDESCR
+    Printf("\tInterface descr.: \"%s\"\r\n", 
+	au->params.ifdescr != NULL ? au->params.ifdescr : "<none>");
+#endif
+#ifdef SIOCAIFGROUP
+    Printf("\tInterface group : %s\r\n", au->params.ifgroup);
+#endif
     Printf("\tIP range        : %s\r\n", (au->params.range_valid)?
 	u_rangetoa(&au->params.range,buf,sizeof(buf)):"");
     Printf("\tIP pool         : %s\r\n", au->params.ippool);
@@ -1320,8 +1339,7 @@
     err=errno;
     GIANT_MUTEX_UNLOCK(); /* We must release lock before Log() */
     if (err)
-      Log(LG_ERR, ("[%s] AUTH: Error retrieving passwd: %s",
-        auth->info.lnkname, strerror(errno)));
+      Perror("[%s] AUTH: Error retrieving passwd", auth->info.lnkname);
     else
       Log(LG_AUTH, ("[%s] AUTH: User \"%s\" not found in the systems database",
         auth->info.lnkname, auth->params.authname));
@@ -2274,6 +2292,18 @@
     } else if (strcmp(attr, "MPD_ACTION") == 0) {
 	strlcpy(auth->params.action, val, sizeof(auth->params.action));
 
+    } else if (strcmp(attr, "MPD_IFACE_NAME") == 0) {
+	strlcpy(auth->params.ifname, val, sizeof(auth->params.ifname));
+
+#ifdef SIOCSIFDESCR
+    } else if (strcmp(attr, "MPD_IFACE_DESCR") == 0) {
+	Freee(auth->params.ifdescr);
+	auth->params.ifdescr = Mstrdup(MB_AUTH, val);
+#endif /* SIOCSIFDESCR */
+#ifdef SIOCAIFGROUP
+    } else if (strcmp(attr, "MPD_IFACE_GROUP") == 0) {
+	strlcpy(auth->params.ifgroup, val, sizeof(auth->params.ifgroup));
+#endif
 #if defined(USE_IPFW) || defined(USE_NG_BPF)
     } else if (strncmp(attr, "MPD_", 4) == 0) {
 	struct acl	**acls, *acls1;
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/auth.h
--- a/contrib/mpd/src/auth.h	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/auth.h	Fri Sep 14 02:13:58 2012 +0300
@@ -156,6 +156,15 @@
     char		peermacaddr[32];	/* hr representation of the peer MAC address */
     char		peeriface[IFNAMSIZ];	/* hr representation of the peer interface */
 
+    /* Iface stuff */
+    char		ifname[IFNAMSIZ];	/* Interface name */
+#ifdef SIOCSIFDESCR
+    char		*ifdescr;		/* Interface description */
+#endif
+#ifdef SIOCAIFGROUP
+    char		ifgroup[IFNAMSIZ];	/* Interface group */
+#endif
+
     struct {
       int	policy;			/* MPPE_POLICY_* */
       int	types;			/* MPPE_TYPE_*BIT bitmask */
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/bund.c
--- a/contrib/mpd/src/bund.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/bund.c	Fri Sep 14 02:13:58 2012 +0300
@@ -907,6 +907,7 @@
 
     /* Update interface MTU */
     IfaceSetMTU(b, mtu);
+ 
 }
 
 /*
@@ -1071,7 +1072,7 @@
     if (ac - stay < 1 || ac - stay > 2)
 	return(-1);
 
-    if (strlen(av[0 + stay]) >= (LINK_MAX_NAME - tmpl * 5))
+    if (strlen(av[0 + stay]) >= (LINK_MAX_NAME - tmpl * (IFNUMLEN + 1)))
 	Error("Bundle name \"%s\" is too long", av[0 + stay]);
 
     /* See if bundle name already taken */
@@ -1247,9 +1248,14 @@
 
     Log(LG_BUND, ("[%s] Bundle: Shutdown", b->name));
     for (k = 0; k < NG_PPP_MAX_LINKS; k++) {
-	if ((l = b->links[k]) != NULL)
+	if ((l = b->links[k]) != NULL) {
 	    if (!l->stay)
 		LinkShutdown(l);
+	    else {
+		l->bund = NULL;
+		b->links[k] = NULL;
+	    }
+	}
     }
 
     if (b->hook[0])
@@ -1257,6 +1263,7 @@
     gBundles[b->id] = NULL;
     MsgUnRegister(&b->msgs);
     b->dead = 1;
+    IfaceDestroy(b);
     UNREF(b);
 }
 
@@ -1673,17 +1680,17 @@
     b->iface.ifindex = if_nametoindex(b->iface.ifname);
     Log(LG_BUND|LG_IFACE, ("[%s] Bundle: Interface %s created",
 	b->name, b->iface.ifname));
- 
+
     /* Create new PPP node */
     snprintf(b->hook, sizeof(b->hook), "b%d", b->id);
-
+    memset(&mp, 0, sizeof(mp));
     strcpy(mp.type, NG_PPP_NODE_TYPE);
     strcpy(mp.ourhook, b->hook);
     strcpy(mp.peerhook, NG_PPP_HOOK_BYPASS);
     if (NgSendMsg(gLinksCsock, ".:",
     	    NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
-	Log(LG_ERR, ("[%s] can't create %s node at \"%s\"->\"%s\": %s",
-    	    b->name, mp.type, ".:", mp.ourhook, strerror(errno)));
+	Perror("[%s] can't create %s node at \"%s\"->\"%s\"",
+    	    b->name, mp.type, ".:", mp.ourhook);
 	goto fail;
     }
     newPpp = 1;
@@ -1692,11 +1699,12 @@
     b->nodeID = NgGetNodeID(gLinksCsock, b->hook);
 
     /* Give it a name */
+    memset(&nm, 0, sizeof(nm));
     snprintf(nm.name, sizeof(nm.name), "mpd%d-%s", gPid, b->name);
     if (NgSendMsg(gLinksCsock, b->hook,
     	    NGM_GENERIC_COOKIE, NGM_NAME, &nm, sizeof(nm)) < 0) {
-	Log(LG_ERR, ("[%s] can't name %s node \"%s\": %s",
-    	    b->name, NG_PPP_NODE_TYPE, b->hook, strerror(errno)));
+	Perror("[%s] can't name %s node \"%s\"",
+    	    b->name, NG_PPP_NODE_TYPE, b->hook);
 	goto fail;
     }
 
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/ccp.c
--- a/contrib/mpd/src/ccp.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/ccp.c	Fri Sep 14 02:13:58 2012 +0300
@@ -168,8 +168,7 @@
     /* Create a netgraph socket node */
     snprintf(name, sizeof(name), "mpd%d-cso", gPid);
     if (NgMkSockNode(name, &gCcpCsock, &gCcpDsock) < 0) {
-	Log(LG_ERR, ("CcpsInit(): can't create %s node: %s",
-    	    NG_SOCKET_NODE_TYPE, strerror(errno)));
+	Perror("CcpsInit(): can't create %s node", NG_SOCKET_NODE_TYPE);
 	return(-1);
     }
     (void) fcntl(gCcpCsock, F_SETFD, 1);
@@ -318,8 +317,7 @@
 
     /* Read message */
     if ((len = NgRecvMsg(gCcpCsock, &u.msg, sizeof(u), raddr)) < 0) {
-	Log(LG_ERR, ("CcpNgCtrlEvent: can't read message: %s",
-    	    strerror(errno)));
+	Perror("CcpNgCtrlEvent: can't read message");
 	return;
     }
     
@@ -811,8 +809,8 @@
     strcpy(cn.peerhook, NG_PPP_HOOK_COMPRESS);
     if (NgSendMsg(gCcpCsock, ".:",
 	    NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
-	Log(LG_ERR, ("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-    	    b->name, ".:", cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+	Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+    	    b->name, ".:", cn.ourhook, cn.path, cn.peerhook);
     }
   }
 
@@ -823,8 +821,8 @@
     strcpy(cn.peerhook, NG_PPP_HOOK_DECOMPRESS);
     if (NgSendMsg(gCcpCsock, ".:",
 	    NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
-	Log(LG_ERR, ("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-    	    b->name, ".:", cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+	Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+    	    b->name, ".:", cn.ourhook, cn.path, cn.peerhook);
     }
   }
 
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/ccp_deflate.c
--- a/contrib/mpd/src/ccp_deflate.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/ccp_deflate.c	Fri Sep 14 02:13:58 2012 +0300
@@ -95,8 +95,7 @@
     strcpy(mp.peerhook, deflatehook);
     if (NgSendMsg(gCcpCsock, path,
     	    NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
-	Log(LG_ERR, ("[%s] can't create %s node: %s",
-    	    b->name, mp.type, strerror(errno)));
+	Perror("[%s] can't create %s node", b->name, mp.type);
 	return(-1);
     }
 
@@ -113,8 +112,8 @@
     snprintf(path, sizeof(path), "[%x]:", id);
     if (NgSendMsg(gCcpCsock, path,
     	    NGM_DEFLATE_COOKIE, NGM_DEFLATE_CONFIG, &conf, sizeof(conf)) < 0) {
-	Log(LG_ERR, ("[%s] can't config %s node at %s: %s",
-    	    b->name, NG_DEFLATE_NODE_TYPE, path, strerror(errno)));
+	Perror("[%s] can't config %s node at %s",
+    	    b->name, NG_DEFLATE_NODE_TYPE, path);
 	NgFuncShutdownNode(gCcpCsock, b->name, path);
 	return(-1);
     }
@@ -194,8 +193,7 @@
     snprintf(path, sizeof(path), "[%x]:", b->ccp.comp_node_id);
     if (NgSendMsg(gCcpCsock, path,
     	    NGM_DEFLATE_COOKIE, NGM_DEFLATE_RESETREQ, NULL, 0) < 0) {
-	Log(LG_ERR, ("[%s] reset-req to %s node: %s",
-    	    b->name, NG_DEFLATE_NODE_TYPE, strerror(errno)));
+	Perror("[%s] reset-req to %s node", b->name, NG_DEFLATE_NODE_TYPE);
     }
     return(NULL);
 }
@@ -222,8 +220,7 @@
     snprintf(path, sizeof(path), "[%x]:", b->ccp.decomp_node_id);
     if (NgSendMsg(gCcpCsock, path,
     	    NGM_DEFLATE_COOKIE, NGM_DEFLATE_RESETREQ, NULL, 0) < 0) {
-	Log(LG_ERR, ("[%s] reset-ack to %s node: %s",
-    	    b->name, NG_DEFLATE_NODE_TYPE, strerror(errno)));
+	Perror("[%s] reset-ack to %s node", b->name, NG_DEFLATE_NODE_TYPE);
     }
 }
 
@@ -346,8 +343,7 @@
     }
     if (NgFuncSendQuery(path, NGM_DEFLATE_COOKIE, NGM_DEFLATE_GET_STATS, NULL, 0, 
 	&u.reply, sizeof(u), NULL) < 0) {
-	    Log(LG_ERR, ("[%s] can't get %s stats: %s",
-		b->name, NG_DEFLATE_NODE_TYPE, strerror(errno)));
+	    Perror("[%s] can't get %s stats", b->name, NG_DEFLATE_NODE_TYPE);
 	    return(0);
     }
     memcpy(&stats, u.reply.data, sizeof(stats));
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/ccp_mppc.c
--- a/contrib/mpd/src/ccp_mppc.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/ccp_mppc.c	Fri Sep 14 02:13:58 2012 +0300
@@ -191,8 +191,7 @@
     strcpy(mp.peerhook, mppchook);
     if (NgSendMsg(gCcpCsock, path,
 	    NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
-	Log(LG_ERR, ("[%s] can't create %s node: %s",
-    	    b->name, mp.type, strerror(errno)));
+	Perror("[%s] can't create %s node", b->name, mp.type);
 	return(-1);
     }
 
@@ -209,8 +208,8 @@
     snprintf(path, sizeof(path), "[%x]:", id);
     if (NgSendMsg(gCcpCsock, path,
     	    NGM_MPPC_COOKIE, cmd, &conf, sizeof(conf)) < 0) {
-	Log(LG_ERR, ("[%s] can't config %s node at %s: %s",
-    	    b->name, NG_MPPC_NODE_TYPE, path, strerror(errno)));
+	Perror("[%s] can't config %s node at %s",
+    	    b->name, NG_MPPC_NODE_TYPE, path);
 	NgFuncShutdownNode(gCcpCsock, b->name, path);
 	return(-1);
     }
@@ -494,8 +493,7 @@
     snprintf(path, sizeof(path), "[%x]:", b->ccp.comp_node_id);
     if (NgSendMsg(gCcpCsock, path,
     	    NGM_MPPC_COOKIE, NGM_MPPC_RESETREQ, NULL, 0) < 0) {
-	Log(LG_ERR, ("[%s] reset-req to %s node: %s",
-    	    b->name, NG_MPPC_NODE_TYPE, strerror(errno)));
+	Perror("[%s] reset-req to %s node", b->name, NG_MPPC_NODE_TYPE);
     }
 
     /* No ResetAck required for MPPC */
@@ -754,8 +752,7 @@
 
     /* Create a netgraph socket node */
     if (NgMkSockNode(NULL, &cs, &ds) < 0) {
-	Log(LG_ERR, ("MppcTestCap: can't create socket node: %s",
-    	    strerror(errno)));
+	Perror("MppcTestCap: can't create socket node");
     	return(-1);
     }
 
@@ -765,8 +762,7 @@
     strcpy(mp.peerhook, NG_MPPC_HOOK_COMP);
     if (NgSendMsg(cs, ".",
       NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
-	Log(LG_ERR, ("MppcTestCap: can't create %s node: %s",
-    	    mp.type, strerror(errno)));
+	Perror("MppcTestCap: can't create %s node", mp.type);
 	goto done;
     }
 
@@ -779,8 +775,7 @@
     if (NgSendMsg(cs, "mppc",
       NGM_MPPC_COOKIE, NGM_MPPC_CONFIG_COMP, &conf, sizeof(conf)) < 0) {
         if (errno != EPROTONOSUPPORT) {
-	    Log(LG_ERR, ("MppcTestCap: can't config %s node: %s",
-    		NG_MPPC_NODE_TYPE, strerror(errno)));
+	    Perror("MppcTestCap: can't config %s node", NG_MPPC_NODE_TYPE);
 	}
     } else 
 	MPPCPresent = 1;
@@ -791,8 +786,7 @@
     if (NgSendMsg(cs, "mppc",
       NGM_MPPC_COOKIE, NGM_MPPC_CONFIG_COMP, &conf, sizeof(conf)) < 0) {
         if (errno != EPROTONOSUPPORT) {
-	    Log(LG_ERR, ("MppcTestCap: can't config %s node: %s",
-    		NG_MPPC_NODE_TYPE, strerror(errno)));
+	    Perror("MppcTestCap: can't config %s node", NG_MPPC_NODE_TYPE);
 	}
     } else 
 	MPPEPresent = 1;
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/ccp_pred1.c
--- a/contrib/mpd/src/ccp_pred1.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/ccp_pred1.c	Fri Sep 14 02:13:58 2012 +0300
@@ -146,8 +146,7 @@
     strcpy(mp.peerhook, pred1hook);
     if (NgSendMsg(gCcpCsock, path,
     	    NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
-	Log(LG_ERR, ("[%s] can't create %s node: %s",
-    	    b->name, mp.type, strerror(errno)));
+	Perror("[%s] can't create %s node", b->name, mp.type);
 	return(-1);
     }
 
@@ -164,8 +163,8 @@
     snprintf(path, sizeof(path), "[%x]:", id);
     if (NgSendMsg(gCcpCsock, path,
     	    NGM_PRED1_COOKIE, NGM_PRED1_CONFIG, &conf, sizeof(conf)) < 0) {
-	Log(LG_ERR, ("[%s] can't config %s node at %s: %s",
-    	    b->name, NG_PRED1_NODE_TYPE, path, strerror(errno)));
+	Perror("[%s] can't config %s node at %s",
+    	    b->name, NG_PRED1_NODE_TYPE, path);
 	NgFuncShutdownNode(gCcpCsock, b->name, path);
 	return(-1);
     }
@@ -389,8 +388,7 @@
     snprintf(path, sizeof(path), "[%x]:", b->ccp.comp_node_id);
     if (NgSendMsg(gCcpCsock, path,
     	    NGM_PRED1_COOKIE, NGM_PRED1_RESETREQ, NULL, 0) < 0) {
-	Log(LG_ERR, ("[%s] reset to %s node: %s",
-    	    b->name, NG_PRED1_NODE_TYPE, strerror(errno)));
+	Perror("[%s] reset to %s node", b->name, NG_PRED1_NODE_TYPE);
     }
 #endif
 return(NULL);
@@ -424,8 +422,7 @@
     snprintf(path, sizeof(path), "[%x]:", b->ccp.decomp_node_id);
     if (NgSendMsg(gCcpCsock, path,
     	    NGM_PRED1_COOKIE, NGM_PRED1_RESETREQ, NULL, 0) < 0) {
-	Log(LG_ERR, ("[%s] reset to %s node: %s",
-    	    b->name, NG_PRED1_NODE_TYPE, strerror(errno)));
+	Perror("[%s] reset to %s node", b->name, NG_PRED1_NODE_TYPE);
     }
 #endif
 }
@@ -544,8 +541,7 @@
     }
     if (NgFuncSendQuery(path, NGM_PRED1_COOKIE, NGM_PRED1_GET_STATS, NULL, 0, 
 	&u.reply, sizeof(u), NULL) < 0) {
-	    Log(LG_ERR, ("[%s] can't get %s stats: %s",
-		b->name, NG_PRED1_NODE_TYPE, strerror(errno)));
+	    Perror("[%s] can't get %s stats", b->name, NG_PRED1_NODE_TYPE);
 	    return(0);
     }
     memcpy(&stats, u.reply.data, sizeof(stats));
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/chat.c
--- a/contrib/mpd/src/chat.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/chat.c	Fri Sep 14 02:13:58 2012 +0300
@@ -379,7 +379,7 @@
     {
       if (errno == EAGAIN)
 	break;
-      Log(LG_ERR, ("[%s] CHAT: read: %s", l->name, strerror(errno)));
+      Perror("[%s] CHAT: read", l->name);
       goto die;
     }
     else if (nread == 0)
@@ -1205,7 +1205,7 @@
   if ((nw = write(c->fd, c->out, c->outLen)) < 0) {
     if (errno == EAGAIN)
       return;
-    Log(LG_ERR, ("[%s] CHAT: write: %s", l->name, strerror(errno)));
+    Perror("[%s] CHAT: write", l->name);
     ChatFailure(c);
     return;
   }
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/command.c
--- a/contrib/mpd/src/command.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/command.c	Fri Sep 14 02:13:58 2012 +0300
@@ -181,21 +181,21 @@
 
   static const struct cmdtab ShowSessCmds[] = {
     { "iface {name}",			"Filter by iface name",
-	ShowSessions, NULL, 2, (void *) SHOW_IFACE },
+	ShowSessions, NULL, 0, (void *) SHOW_IFACE },
     { "ip {ip}",			"Filter by IP address",
-	ShowSessions, NULL, 2, (void *) SHOW_IP },
+	ShowSessions, NULL, 0, (void *) SHOW_IP },
     { "user {name}",			"Filter by user name",
-	ShowSessions, NULL, 2, (void *) SHOW_USER },
+	ShowSessions, NULL, 0, (void *) SHOW_USER },
     { "session {ID}",			"Filter by session ID",
-	ShowSessions, NULL, 2, (void *) SHOW_SESSION },
+	ShowSessions, NULL, 0, (void *) SHOW_SESSION },
     { "msession {ID}",			"Filter by msession ID",
-	ShowSessions, NULL, 2, (void *) SHOW_MSESSION },
+	ShowSessions, NULL, 0, (void *) SHOW_MSESSION },
     { "bundle {name}",			"Filter by bundle name",
-	ShowSessions, NULL, 2, (void *) SHOW_BUNDLE },
+	ShowSessions, NULL, 0, (void *) SHOW_BUNDLE },
     { "link {name}",			"Filter by link name",
-	ShowSessions, NULL, 2, (void *) SHOW_LINK },
+	ShowSessions, NULL, 0, (void *) SHOW_LINK },
     { "peer {name}",			"Filter by peer name",
-	ShowSessions, NULL, 2, (void *) SHOW_PEER },
+	ShowSessions, NULL, 0, (void *) SHOW_PEER },
     { NULL },
   };
 
@@ -273,12 +273,18 @@
     { "version",			"Version string",
 	ShowVersion, NULL, 0, NULL },
     { "sessions [ {param} {value} ]",	"Active sessions",
-	CMD_SUBMENU, NULL, 2, (void *) ShowSessCmds},
+	CMD_SUBMENU, NULL, 0, (void *) ShowSessCmds},
     { "summary",			"Daemon status summary",
 	ShowSummary, NULL, 0, NULL },
     { NULL },
   };
 
+  static const struct cmdtab UnSetCommands[] = {
+   { "radius ...",			"RADIUS stuff",
+	CMD_SUBMENU, AdmitLink, 2, (void *) RadiusUnSetCmds },
+	{ NULL },
+  };
+  
   static const struct cmdtab SetCommands[] = {
     { "bundle ...",			"Bundle specific stuff",
 	CMD_SUBMENU, AdmitBund, 2, (void *) BundSetCmds },
@@ -370,6 +376,8 @@
 	SessionCommand, NULL, 0, NULL },
     { "set ...",			"Set parameters",
 	CMD_SUBMENU, NULL, 0, (void *) SetCommands },
+	{ "unset ...",			"Unset parameters",
+	CMD_SUBMENU, NULL, 0, (void *) UnSetCommands },
     { "show ...",			"Show status",
 	CMD_SUBMENU, NULL, 0, (void *) ShowCommands },
     { NULL },
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/console.c
--- a/contrib/mpd/src/console.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/console.c	Fri Sep 14 02:13:58 2012 +0300
@@ -233,10 +233,13 @@
   cs->write = ConsoleSessionWrite;
   cs->writev = ConsoleSessionWriteV;
   cs->prompt = ConsoleSessionShowPrompt;
-//  cs->state = STATE_USERNAME;
-  cs->state = STATE_AUTHENTIC;
+#ifdef WITH_CONSOLE_AUTH
+    cs->state = STATE_USERNAME;
+#else
+    cs->state = STATE_AUTHENTIC;
+    cs->context.priv = 2;
+#endif
   cs->context.cs = cs;
-  cs->context.priv = 2; //-
   RWLOCK_WRLOCK(c->lock);
   SLIST_INSERT_HEAD(&c->sessions, cs, next);
   RWLOCK_UNLOCK(c->lock);
@@ -301,7 +304,12 @@
     cs->write = StdConsoleSessionWrite;
     cs->writev = StdConsoleSessionWriteV;
     cs->prompt = ConsoleSessionShowPrompt;
+#ifdef WITH_CONSOLE_AUTH
+    cs->state = STATE_USERNAME;
+#else
     cs->state = STATE_AUTHENTIC;
+    cs->context.priv = 2;
+#endif
     cs->context.cs = cs;
     strcpy(cs->user.username, "root");
     cs->context.priv = 2;
@@ -351,6 +359,7 @@
     /* Restore original STDxxx flags. */
     if (gOrigFlags>=0)
 	fcntl(cs->fd, F_SETFL, gOrigFlags);
+    cs->close = NULL;
     return;
 }
 
@@ -375,9 +384,9 @@
       if (n < 0) {
 	if (errno == EAGAIN)
 	  goto out;
-	Log(LG_ERR, ("CONSOLE: Error while reading: %s", strerror(errno)));
+	Perror("CONSOLE: Error while reading");
       } else {
-        if (cs->fd == 0)
+        if (cs->fd == 0 && isatty(cs->fd))
 	  goto out;
 	Log(LG_ERR, ("CONSOLE: Connection closed by peer"));
       }
@@ -827,6 +836,21 @@
 }
 
 /*
+ * ConsoleShutdown()
+ */
+
+void
+ConsoleShutdown(Console c)
+{
+    ConsoleSession s, tmp;
+
+    SLIST_FOREACH_SAFE(s, &c->sessions, next, tmp) {
+	if (s->close != NULL)
+		s->close(s);
+    }
+}
+
+/*
  * UserCommand()
  */
 
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/console.h
--- a/contrib/mpd/src/console.h	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/console.h	Fri Sep 14 02:13:58 2012 +0300
@@ -112,6 +112,7 @@
   extern int	ConsoleClose(Console c);
   extern int	ConsoleStat(Context ctx, int ac, char *av[], void *arg);
   extern Context	StdConsoleConnect(Console c);
+  extern void	ConsoleShutdown(Console c);
 
   extern int	UserCommand(Context ctx, int ac, char *av[], void *arg);
   extern int	UserStat(Context ctx, int ac, char *av[], void *arg);
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/contrib/libpdel/util/pevent.c
--- a/contrib/mpd/src/contrib/libpdel/util/pevent.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/contrib/libpdel/util/pevent.c	Fri Sep 14 02:13:58 2012 +0300
@@ -210,13 +210,13 @@
 		if ((errno = pthread_attr_init(&ctx->attr)) != 0)
 			goto fail;
 		ctx->has_attr = 1;
-		pthread_attr_getinheritsched(attr, &value);
+		pthread_attr_getinheritsched((pthread_attr_t *) attr, &value);
 		pthread_attr_setinheritsched(&ctx->attr, value);
-		pthread_attr_getschedparam(attr, &param);
+		pthread_attr_getschedparam((pthread_attr_t *) attr, &param);
 		pthread_attr_setschedparam(&ctx->attr, &param);
-		pthread_attr_getschedpolicy(attr, &value);
+		pthread_attr_getschedpolicy((pthread_attr_t *) attr, &value);
 		pthread_attr_setschedpolicy(&ctx->attr, value);
-		pthread_attr_getscope(attr, &value);
+		pthread_attr_getscope((pthread_attr_t *) attr, &value);
 		pthread_attr_setscope(&ctx->attr, value);
 	}
 
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/contrib/libpdel/util/typed_mem.c
--- a/contrib/mpd/src/contrib/libpdel/util/typed_mem.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/contrib/libpdel/util/typed_mem.c	Fri Sep 14 02:13:58 2012 +0300
@@ -210,8 +210,10 @@
 	pthread_mutexattr_destroy(&mattr);
 
 	/* Fill in guard bytes */
-	for (i = 0; i < ALIGNMENT; i++)
-		typed_mem_guard[i] = typed_mem_guard_data[i % ALIGNMENT];
+	for (i = 0; i < ALIGNMENT; i++) {
+		typed_mem_guard[i] = typed_mem_guard_data[
+		    i % sizeof(typed_mem_guard_data)];
+	}
 
 	/* Done */
 	typed_mem_enabled = 1;
@@ -570,8 +572,12 @@
 	char *s;
 	int r;
 
-	if ((r = vasprintf(ret, fmt, args)) == -1)
+	if ((r = vasprintf(ret, fmt, args)) == -1) {
+		*ret = NULL;
 		return (-1);
+	}
+	if (!typed_mem_enabled)
+		return r;
 	s = *ret;
 #if TYPED_MEM_TRACE
 	*ret = typed_mem_strdup(file, line, type, s);
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/defs.h
--- a/contrib/mpd/src/defs.h	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/defs.h	Fri Sep 14 02:13:58 2012 +0300
@@ -108,6 +108,9 @@
   #define DEFAULT_RADSRV_PORT	3799
   #define DEFAULT_RADSRV_IP	"0.0.0.0"
 
+  /* Characters, leave for interface number. For example: ppp9999 */
+  #define IFNUMLEN		(sizeof("9999") - 1)
+
   /* Forward decl's */
   struct linkst;
   typedef struct linkst *Link;
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/ecp.c
--- a/contrib/mpd/src/ecp.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/ecp.c	Fri Sep 14 02:13:58 2012 +0300
@@ -171,8 +171,7 @@
     /* Create a netgraph socket node */
     snprintf(name, sizeof(name), "mpd%d-eso", gPid);
     if (NgMkSockNode(name, &gEcpCsock, &gEcpDsock) < 0) {
-	Log(LG_ERR, ("EcpsInit(): can't create %s node: %s",
-    	    NG_SOCKET_NODE_TYPE, strerror(errno)));
+	Perror("EcpsInit(): can't create %s node", NG_SOCKET_NODE_TYPE);
 	return(-1);
     }
     (void) fcntl(gEcpCsock, F_SETFD, 1);
@@ -653,8 +652,8 @@
     strcpy(cn.peerhook, NG_PPP_HOOK_DECRYPT);
     if (NgSendMsg(gEcpCsock, ".:",
 	    NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
-	Log(LG_ERR, ("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-        b->name, ".:", cn.ourhook, cn.path, cn.peerhook,  strerror(errno)));
+	Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+          b->name, ".:", cn.ourhook, cn.path, cn.peerhook);
     }
   }
   if (ecp->xmit && ecp->xmit->Encrypt)
@@ -665,8 +664,8 @@
     strcpy(cn.peerhook, NG_PPP_HOOK_ENCRYPT);
     if (NgSendMsg(gEcpCsock, ".:",
 	    NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
-	Log(LG_ERR, ("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-        b->name, ".:", cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+	Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+          b->name, ".:", cn.ourhook, cn.path, cn.peerhook);
     }
   }
 
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/event.c
--- a/contrib/mpd/src/event.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/event.c	Fri Sep 14 02:13:58 2012 +0300
@@ -1,7 +1,7 @@
 /*
  * See ``COPYRIGHT.mpd''
  *
- * $Id: event.c,v 1.20 2011/06/30 09:17:28 dmitryluhtionov Exp $
+ * $Id: event.c,v 1.21 2011/07/11 09:09:22 dmitryluhtionov Exp $
  *
  */
 
@@ -84,7 +84,7 @@
 
     if (pevent_register(gPeventCtx, &refp->pe, flags, &gGiantMutex, EventHandler,
 	    refp, type, val) == -1) {
-        Log(LG_ERR, ("%s: error pevent_register: %s", __FUNCTION__, strerror(errno)));
+        Perror("%s: error pevent_register", __FUNCTION__);
         return(-1);
     }
   
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/iface.c
--- a/contrib/mpd/src/iface.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/iface.c	Fri Sep 14 02:13:58 2012 +0300
@@ -20,6 +20,7 @@
 #include "util.h"
 
 #include <sys/sockio.h>
+#include <sys/sysctl.h>
 #include <net/if.h>
 #include <net/if_types.h>
 #include <net/if_dl.h>
@@ -71,6 +72,12 @@
     SET_ROUTE,
     SET_MTU,
     SET_NAME,
+#ifdef SIOCSIFDESCR
+    SET_DESCR,
+#endif
+#ifdef SIOCAIFGROUP
+    SET_GROUP,
+#endif
     SET_UP_SCRIPT,
     SET_DOWN_SCRIPT,
     SET_ENABLE,
@@ -131,7 +138,15 @@
   static int	IfaceFindACL (struct acl_pool *ap, char * ifname, int number);
   static char *	IFaceParseACL (char * src, char * ifname);
 #endif
-  
+
+  static int	IfaceSetName(Bund b, const char * ifname);
+#ifdef SIOCSIFDESCR
+  static int	IfaceSetDescr(Bund b, const char * ifdescr);
+#endif
+#ifdef SIOCAIFGROUP
+  static int	IfaceAddGroup(Bund b, const char * ifgroup);
+  static int	IfaceDelGroup(Bund b, const char * ifgroup);
+#endif
 /*
  * GLOBAL VARIABLES
  */
@@ -143,8 +158,16 @@
 	IfaceSetCommand, NULL, 2, (void *) SET_ROUTE },
     { "mtu {size}",			"Set max allowed interface MTU",
 	IfaceSetCommand, NULL, 2, (void *) SET_MTU },
-    { "name {name}",			"Set interface name",
+    { "name [{name}]",			"Set interface name",
 	IfaceSetCommand, NULL, 2, (void *) SET_NAME },
+#ifdef SIOCSIFDESCR
+    { "description [{descr}]",		"Set interface description",
+	IfaceSetCommand, NULL, 2, (void *) SET_DESCR },
+#endif
+#ifdef SIOCAIFGROUP
+    { "group [{group}]",		"Set interface group",
+	IfaceSetCommand, NULL, 2, (void *) SET_GROUP },
+#endif
     { "up-script [{progname}]",		"Interface up script",
 	IfaceSetCommand, NULL, 2, (void *) SET_UP_SCRIPT },
     { "down-script [{progname}]",	"Interface down script",
@@ -169,15 +192,23 @@
   static const struct confinfo	gConfList[] = {
     { 0,	IFACE_CONF_ONDEMAND,		"on-demand"	},
     { 0,	IFACE_CONF_PROXY,		"proxy-arp"	},
+#ifdef USE_NG_TCPMSS
     { 0,	IFACE_CONF_TCPMSSFIX,           "tcpmssfix"	},
+#endif
     { 0,	IFACE_CONF_TEE,			"tee"		},
+#ifdef USE_NG_NAT
     { 0,	IFACE_CONF_NAT,			"nat"		},
+#endif
+#ifdef USE_NG_NETFLOW
     { 0,	IFACE_CONF_NETFLOW_IN,		"netflow-in"	},
     { 0,	IFACE_CONF_NETFLOW_OUT,		"netflow-out"	},
 #ifdef NG_NETFLOW_CONF_ONCE
     { 0,	IFACE_CONF_NETFLOW_ONCE,	"netflow-once"	},
 #endif
+#endif
+#ifdef USE_NG_IPACCT
     { 0,	IFACE_CONF_IPACCT,		"ipacct"	},
+#endif
     { 0,	0,				NULL		},
   };
 
@@ -240,6 +271,10 @@
   /* Default configuration */
   iface->mtu = NG_IFACE_MTU_DEFAULT;
   iface->max_mtu = NG_IFACE_MTU_DEFAULT;
+#ifdef SIOCSIFDESCR
+  iface->ifdescr = NULL;
+  iface->conf.ifdescr = NULL;
+#endif
   Disable(&iface->options, IFACE_CONF_ONDEMAND);
   Disable(&iface->options, IFACE_CONF_PROXY);
   Disable(&iface->options, IFACE_CONF_TCPMSSFIX);
@@ -262,6 +297,28 @@
     IfaceState	const iface = &b->iface;
 
     memcpy(iface, &bt->iface, sizeof(*iface));
+
+    /* Copy interface name from template config to current */
+    if (bt->iface.conf.ifname[0] != 0 && b->tmpl == 0) {
+        snprintf(iface->conf.ifname, sizeof(iface->conf.ifname), "%s%d",
+             bt->iface.conf.ifname, b->id);
+        Log(LG_IFACE2, ("[%s] IFACE: Set conf.ifname to ", iface->conf.ifname));
+    }
+}
+
+/*
+ * IfaceDestroy()
+ */
+
+void
+IfaceDestroy(Bund b)
+{
+#ifdef SIOCSIFDESCR
+    IfaceState	const iface = &b->iface;
+
+    if (iface->conf.ifdescr != NULL)
+	Freee(iface->conf.ifdescr);
+#endif
 }
 
 /*
@@ -417,6 +474,37 @@
 	memset(&iface->idleStats, 0, sizeof(iface->idleStats));
     }
 
+    /* Update interface name and description */
+    if (b->params.ifname[0] != 0) {
+       if (IfaceSetName(b, b->params.ifname) != -1)
+	    Log(LG_BUND|LG_IFACE, ("[%s] IFACE: Rename interface %s to %s",
+		b->name, iface->ngname, b->params.ifname));
+    } else if (iface->conf.ifname[0] != 0) {
+       if (IfaceSetName(b, iface->conf.ifname) != -1)
+	    Log(LG_BUND|LG_IFACE, ("[%s] IFACE: Rename interface %s to %s",
+		b->name, iface->ngname, iface->conf.ifname));
+    }
+#ifdef SIOCSIFDESCR
+    if (b->params.ifdescr != NULL) {
+       if (IfaceSetDescr(b, b->params.ifdescr) != -1) {
+	    Log(LG_BUND|LG_IFACE, ("[%s] IFACE: Add description \"%s\"",
+		b->name, b->params.ifdescr));
+	    iface->ifdescr = b->params.ifdescr;
+	}
+    }
+#endif
+#ifdef SIOCAIFGROUP
+    if (iface->conf.ifgroup[0] != 0) {
+       if (IfaceAddGroup(b, iface->conf.ifgroup) != -1)
+	    Log(LG_BUND|LG_IFACE, ("[%s] IFACE: Add group %s to %s",
+		b->name, iface->conf.ifgroup, iface->ngname));
+    }
+    if (b->params.ifgroup[0] != 0) {
+       if (IfaceAddGroup(b, b->params.ifgroup) != -1)
+	    Log(LG_BUND|LG_IFACE, ("[%s] IFACE: Add group %s to %s",
+		b->name, b->params.ifgroup, iface->ngname));
+    }
+#endif
 #ifdef USE_IPFW
   /* Allocate ACLs */
   acls = b->params.acl_pipe;
@@ -477,7 +565,7 @@
   }
   acls = b->params.acl_table;
   while (acls != NULL) {
-    acl = Mdup(MB_IFACE, acls, sizeof(struct acl) + strlen(acls->rule));
+    acl = Mdup(MB_IPFW, acls, sizeof(struct acl) + strlen(acls->rule));
     acl->next = iface->tables;
     iface->tables = acl;
     ExecCmd(LG_IFACE2, b->name, "%s table %d add %s", PATH_IPFW, acls->real_number, acls->rule);
@@ -600,6 +688,48 @@
       PATH_IPFW, cb);
 #endif /* USE_IPFW */
 
+    /* Revert interface name and description */
+
+    if (strcmp(iface->ngname, iface->ifname) != 0) {
+	if (iface->conf.ifname[0] != 0) {
+	    /* Restore to config defined */
+	    if (IfaceSetName(b, iface->conf.ifname) != -1)
+		Log(LG_BUND|LG_IFACE, ("[%s] IFACE: Rename interface %s to %s",
+		    b->name, iface->ifname, iface->conf.ifname));
+	} else {
+	    /* Restore to original interface name */
+	    if (IfaceSetName(b, iface->ngname) != -1)
+		Log(LG_BUND|LG_IFACE, ("[%s] IFACE: Rename interface %s to %s",
+		    b->name, iface->ifname, iface->ngname));
+	}
+    }
+#ifdef SIOCSIFDESCR
+    if (iface->ifdescr != NULL) {
+	if (iface->conf.ifdescr != NULL) {
+	    /* Restore to config defined */
+	    if (IfaceSetDescr(b, iface->conf.ifdescr) != -1) {
+		Log(LG_BUND|LG_IFACE, ("[%s] IFACE: Set description \"%s\"",
+		    b->name, iface->conf.ifdescr));
+		iface->ifdescr = iface->conf.ifdescr;
+	    } else
+		iface->ifdescr = NULL;
+	} else {
+	    /* Restore to original (empty) */
+	    if (IfaceSetDescr(b, "") != -1) {
+		Log(LG_BUND|LG_IFACE, ("[%s] IFACE: Clear description",
+		    b->name));
+	    }
+	    iface->ifdescr = NULL;
+	}
+    }
+#endif
+#ifdef SIOCAIFGROUP
+    if (b->params.ifgroup[0] != 0) {
+       if (IfaceDelGroup(b, b->params.ifgroup) != -1)
+	    Log(LG_BUND|LG_IFACE, ("[%s] IFACE: Remove group %s from %s",
+		b->name, b->params.ifgroup, iface->ngname));
+    }
+#endif
 }
 
 /*
@@ -640,7 +770,7 @@
     int	i;
     struct acl_pool **rp,*rp1;
 
-    rp1 = Malloc(MB_IFACE, sizeof(struct acl_pool));
+    rp1 = Malloc(MB_IPFW, sizeof(struct acl_pool));
     strlcpy(rp1->ifname, ifname, sizeof(rp1->ifname));
     rp1->acl_number = number;
 
@@ -701,8 +831,8 @@
     int num,real_number;
     struct acl_pool *ap;
     
-    buf = Malloc(MB_IFACE, ACL_LEN);
-    buf1 = Malloc(MB_IFACE, ACL_LEN);
+    buf = Malloc(MB_IPFW, ACL_LEN);
+    buf1 = Malloc(MB_IPFW, ACL_LEN);
 
     strlcpy(buf, src, ACL_LEN);
     do {
@@ -1153,8 +1283,7 @@
 	else {
     	    if (NgFuncWritePppFrame(b, NG_PPP_BUNDLE_LINKNUM,
 		    iface->dodCache.proto, iface->dodCache.pkt) < 0) {
-		Log(LG_ERR, ("[%s] can't write cached pkt: %s",
-	    	    b->name, strerror(errno)));
+		Perror("[%s] can't write cached pkt", b->name);
     	    }
 	}
 	iface->dodCache.pkt = NULL;
@@ -1250,8 +1379,23 @@
 IfaceSetCommand(Context ctx, int ac, char *av[], void *arg)
 {
   IfaceState	const iface = &ctx->bund->iface;
-
-  if (ac == 0)
+  int		empty_arg;
+
+  switch ((intptr_t)arg) {
+    case SET_NAME:
+#ifdef SIOCSIFDESCR
+    case SET_DESCR:
+#endif
+    case SET_UP_SCRIPT:
+    case SET_DOWN_SCRIPT:
+      empty_arg = TRUE;
+      break;
+    default:
+      empty_arg = FALSE;
+      break;
+  }
+
+  if ((ac == 0) && (empty_arg == FALSE))
     return(-1);
   switch ((intptr_t)arg) {
     case SET_IDLE:
@@ -1329,6 +1473,10 @@
       {
 	int	max_mtu;
 
+	/* Check */
+	if (ac != 1)
+	  return(-1);
+
 	max_mtu = atoi(av[0]);
 	if (max_mtu < IFACE_MIN_MTU || max_mtu > IFACE_MAX_MTU)
 	  Error("Invalid interface mtu %d", max_mtu);
@@ -1337,37 +1485,71 @@
       break;
 
     case SET_NAME:
-      {
-	char *name = av[0];
-	struct ifreq ifr;
-	int s;
-
-	if (strlen(name) >= IF_NAMESIZE)
-	  Error("Interface name too long, >15 characters");
-
-	/* Get socket */
-	if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
-	  Error("[%s] IFACE: Can't get socket to set name", ctx->bund->name);
+	switch (ac) {
+	  case 0:
+	    /* Restore original interface name */
+	    if (strcmp(iface->ifname, iface->ngname) != 0) {
+		iface->conf.ifname[0] = '\0';
+		return IfaceSetName(ctx->bund, iface->ngname);
+	    }
+	    break;
+	  case 1:
+	    if (strcmp(iface->ifname, av[0]) != 0) {
+		int ifmaxlen = IF_NAMESIZE - ctx->bund->tmpl * IFNUMLEN;
+		if (strlen(av[0]) >= ifmaxlen)
+		    Error("Interface name too long, >%d characters", ifmaxlen-1);
+		if ((strncmp(av[0], "ng", 2) == 0) &&
+		  ((ctx->bund->tmpl && av[0][2] == 0) ||
+		  (av[0][2] >= '0' && av[0][2] <= '9')))
+		    Error("This interface name is reserved");
+		strlcpy(iface->conf.ifname, av[0], sizeof(iface->conf.ifname));
+		return IfaceSetName(ctx->bund, av[0]);
+	    }
+	    break;
+	  default:
+	    return(-1);
 	}
-
-	/* Set name of interface */
-	memset(&ifr, 0, sizeof(ifr));
-	strlcpy(ifr.ifr_name, iface->ifname, sizeof(ifr.ifr_name));
-	ifr.ifr_data = (caddr_t)name;
-	Log(LG_IFACE2, ("[%s] IFACE: setting %s name to %s",
-	  ctx->bund->name, iface->ifname, name));
-	if (ioctl(s, SIOCSIFNAME, (char *)&ifr) != -1) {
-	  close(s);
-	  /* Save name */
-	  strlcpy(iface->ifname, name, sizeof(iface->ifname));
-	} else {
-	  close(s);
-	  Error("[%s] IFACE: ioctl(%s, %s)", ctx->bund->name,
-	    iface->ifname, "SIOCSIFNAME");
+	break;
+#ifdef SIOCSIFDESCR
+    case SET_DESCR:
+	if (ctx->bund->tmpl)
+	    Error("Impossible to apply on template");
+	if (iface->conf.ifdescr != NULL)
+	    Freee(iface->conf.ifdescr);
+	iface->conf.ifdescr = NULL;
+	iface->ifdescr = NULL;
+	switch (ac) {
+	  case 0:
+	    return IfaceSetDescr(ctx->bund, "");
+	    break;
+	  case 1:
+	    iface->conf.ifdescr = Mstrdup(MB_IFACE, av[0]);
+	    if (IfaceSetDescr(ctx->bund, av[0]) == 0) {
+		iface->ifdescr = iface->conf.ifdescr;
+		return(0);
+	    } else
+		return(-1);
+	    break;
+	  default:
+	    return(-1);
 	}
-      }
+	break;
+#endif
+#ifdef SIOCAIFGROUP
+    case SET_GROUP:
+	if (ac != 1)
+	  return(-1);
+
+	if (av[0][0] && isdigit(av[0][strlen(av[0]) - 1]))
+	    Error("Groupnames may not end in a digit");
+	if (strlen(av[0]) >= IFNAMSIZ)
+	    Error("Group name %s too long", av[0]);
+	if (iface->conf.ifgroup[0] != 0)
+	    IfaceDelGroup(ctx->bund, iface->conf.ifgroup);
+	strlcpy(iface->conf.ifgroup, av[0], IFNAMSIZ);
+	return IfaceAddGroup(ctx->bund, av[0]);
       break;
-
+#endif
     case SET_UP_SCRIPT:
       switch (ac) {
 	case 0:
@@ -1427,7 +1609,14 @@
 #endif
 
     Printf("Interface configuration:\r\n");
-    Printf("\tName            : %s\r\n", iface->ifname);
+    Printf("\tName            : %s\r\n", iface->conf.ifname);
+#ifdef SIOCSIFDESCR
+    Printf("\tDescription     : \"%s\"\r\n",
+	(iface->conf.ifdescr != NULL) ? iface->conf.ifdescr : "<none>");
+#endif
+#ifdef SIOCAIFGROUP
+    Printf("\tGroup           : %s\r\n", iface->conf.ifgroup);
+#endif
     Printf("\tMaximum MTU     : %d bytes\r\n", iface->max_mtu);
     Printf("\tIdle timeout    : %d seconds\r\n", iface->idle_timeout);
     Printf("\tSession timeout : %d seconds\r\n", iface->session_timeout);
@@ -1459,6 +1648,11 @@
     Printf("Interface status:\r\n");
     Printf("\tAdmin status    : %s\r\n", iface->open ? "OPEN" : "CLOSED");
     Printf("\tStatus          : %s\r\n", iface->up ? (iface->dod?"DoD":"UP") : "DOWN");
+    Printf("\tName            : %s\r\n", iface->ifname);
+#ifdef SIOCSIFDESCR
+    Printf("\tDescription     : \"%s\"\r\n",
+	(iface->ifdescr != NULL) ? iface->ifdescr : "<none>");
+#endif
     if (iface->up) {
 	Printf("\tSession time    : %ld seconds\r\n", (long int)(time(NULL) - iface->last_up));
 	if (b->params.idle_timeout || iface->idle_timeout)
@@ -1591,8 +1785,8 @@
     struct ifreq ifrq;
     int s, new_flags;
 
-    Log(LG_IFACE2, ("[%s] IFACE: Change interface flags: -%d +%d",
-	b->name, clear, set)); 
+    Log(LG_IFACE2, ("[%s] IFACE: Change interface %s flags: -%d +%d",
+	b->name, b->iface.ifname, clear, set));
 
     if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
 	Perror("[%s] IFACE: Can't get socket to change interface flags", b->name);
@@ -1601,9 +1795,8 @@
 
     memset(&ifrq, '\0', sizeof(ifrq));
     strlcpy(ifrq.ifr_name, b->iface.ifname, sizeof(ifrq.ifr_name));
-    ifrq.ifr_name[sizeof(ifrq.ifr_name) - 1] = '\0';
     if (ioctl(s, SIOCGIFFLAGS, &ifrq) < 0) {
-	Perror("[%s] IFACE: ioctl(%s, %s)", b->name, b->iface.ifname, "SIOCGIFFLAGS");
+	Perror("[%s] IFACE: ioctl(SIOCGIFFLAGS, %s)", b->name, b->iface.ifname);
 	close(s);
 	return;
     }
@@ -1616,7 +1809,7 @@
     ifrq.ifr_flagshigh = new_flags >> 16;
 
     if (ioctl(s, SIOCSIFFLAGS, &ifrq) < 0) {
-	Perror("[%s] IFACE: ioctl(%s, %s)", b->name, b->iface.ifname, "SIOCSIFFLAGS");
+	Perror("[%s] IFACE: ioctl(SIOCSIFFLAGS, %s)", b->name, b->iface.ifname);
 	close(s);
 	return;
     }
@@ -1708,8 +1901,14 @@
 
 	res = ioctl(s, add?SIOCAIFADDR_IN6:SIOCDIFADDR_IN6, &ifra6);
 	if (res == -1) {
-	    Perror("[%s] IFACE: %s IPv6 address %s %s failed", 
-		b->name, add?"Adding":"Removing", add?"to":"from", b->iface.ifname);
+		if (add && errno == EEXIST) {
+			/* this can happen if the kernel has already automatically added
+			   the same link-local address - ignore the error */
+			res = 0;
+		} else {
+			Perror("[%s] IFACE: %s IPv6 address %s %s failed", 
+				b->name, add?"Adding":"Removing", add?"to":"from", b->iface.ifname);
+		}
 	}
 	break;
 
@@ -1951,13 +2150,14 @@
 #endif
 
     /* Connect graph to the iface node. */
+    memset(&cn, 0, sizeof(cn));
     strcpy(cn.ourhook, hook);
     snprintf(cn.path, sizeof(cn.path), "%s:", b->iface.ngname);
     strcpy(cn.peerhook, NG_IFACE_HOOK_INET);
     if (NgSendMsg(gLinksCsock, path,
     	    NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
-	Log(LG_ERR, ("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-    	    b->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+	Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+	    b->name, path, cn.ourhook, cn.path, cn.peerhook);
 	goto fail;
     }
 
@@ -2076,8 +2276,8 @@
     strcpy(cn.peerhook, NG_IFACE_HOOK_INET6);
     if (NgSendMsg(gLinksCsock, path,
     	    NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
-	Log(LG_ERR, ("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-    	    b->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+	Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+	    b->name, path, cn.ourhook, cn.path, cn.peerhook);
 	goto fail;
     }
 
@@ -2126,8 +2326,8 @@
     strcpy(mp.peerhook, NG_NAT_HOOK_IN);
     if (NgSendMsg(gLinksCsock, path,
 	NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
-      Log(LG_ERR, ("[%s] can't create %s node at \"%s\"->\"%s\": %s",
-	b->name, NG_NAT_NODE_TYPE, path, mp.ourhook, strerror(errno)));
+      Perror("[%s] can't create %s node at \"%s\"->\"%s\"",
+	b->name, NG_NAT_NODE_TYPE, path, mp.ourhook);
       return(-1);
     }
     strlcat(path, ".", NG_PATHSIZ);
@@ -2135,8 +2335,7 @@
     snprintf(nm.name, sizeof(nm.name), "mpd%d-%s-nat", gPid, b->name);
     if (NgSendMsg(gLinksCsock, path,
 	NGM_GENERIC_COOKIE, NGM_NAME, &nm, sizeof(nm)) < 0) {
-      Log(LG_ERR, ("[%s] can't name %s node: %s",
-	b->name, NG_NAT_NODE_TYPE, strerror(errno)));
+      Perror("[%s] can't name %s node", b->name, NG_NAT_NODE_TYPE);
       return(-1);
     }
     strcpy(hook, NG_NAT_HOOK_OUT);
@@ -2148,10 +2347,8 @@
 	ip = nat->alias_addr.u.ip4;
     }
     if (NgSendMsg(gLinksCsock, path,
-	    NGM_NAT_COOKIE, NGM_NAT_SET_IPADDR, &ip, sizeof(ip)) < 0) {
-	Log(LG_ERR, ("[%s] can't set NAT ip: %s",
-    	    b->name, strerror(errno)));
-    }
+	    NGM_NAT_COOKIE, NGM_NAT_SET_IPADDR, &ip, sizeof(ip)) < 0)
+	Perror("[%s] can't set NAT ip", b->name);
 
 #ifdef NG_NAT_LOG
     /* Set NAT mode */
@@ -2168,18 +2365,15 @@
     mode.mask = NG_NAT_LOG | NG_NAT_DENY_INCOMING | 
 	NG_NAT_SAME_PORTS | NG_NAT_UNREGISTERED_ONLY;
     if (NgSendMsg(gLinksCsock, path,
-	    NGM_NAT_COOKIE, NGM_NAT_SET_MODE, &mode, sizeof(mode)) < 0) {
-	Log(LG_ERR, ("[%s] can't set NAT mode: %s",
-    	    b->name, strerror(errno)));
-    }
+	    NGM_NAT_COOKIE, NGM_NAT_SET_MODE, &mode, sizeof(mode)) < 0)
+	Perror("[%s] can't set NAT mode", b->name);
 
     /* Set NAT target IP */
     if (!u_addrempty(&nat->target_addr)) {
 	ip = nat->target_addr.u.ip4;
 	if (NgSendMsg(gLinksCsock, path,
 		NGM_NAT_COOKIE, NGM_NAT_SET_IPADDR, &ip, sizeof(ip)) < 0) {
-	    Log(LG_ERR, ("[%s] can't set NAT target IP: %s",
-    		b->name, strerror(errno)));
+	    Perror("[%s] can't set NAT target IP", b->name);
 	}
     }
 #endif
@@ -2200,8 +2394,7 @@
     		NGM_NAT_COOKIE, NGM_NAT_SET_IPADDR,
 		&b->iface.self_addr.addr.u.ip4,
 		sizeof(b->iface.self_addr.addr.u.ip4)) < 0) {
-	    Log(LG_ERR, ("[%s] can't set NAT ip: %s",
-    		b->name, strerror(errno)));
+	    Perror("[%s] can't set NAT ip", b->name);
 	    return (-1);
 	}
     }
@@ -2212,8 +2405,7 @@
 	if (NgSendMsg(gLinksCsock, path,
 		NGM_NAT_COOKIE, NGM_NAT_REDIRECT_PORT, &nat->nrpt[k],
 		sizeof(struct ng_nat_redirect_port)) < 0) {
-	    Log(LG_ERR, ("[%s] can't set NAT redirect-port: %s",
-		b->name, strerror(errno)));
+	    Perror("[%s] can't set NAT redirect-port", b->name);
 	}
       }
     }
@@ -2223,8 +2415,7 @@
 	if (NgSendMsg(gLinksCsock, path,
 		NGM_NAT_COOKIE, NGM_NAT_REDIRECT_ADDR, &nat->nrad[k],
 		sizeof(struct ng_nat_redirect_addr)) < 0) {
-	    Log(LG_ERR, ("[%s] can't set NAT redirect-addr: %s",
-		b->name, strerror(errno)));
+	    Perror("[%s] can't set NAT redirect-addr", b->name);
 	}
       }
     }
@@ -2234,8 +2425,7 @@
 	if (NgSendMsg(gLinksCsock, path,
 		NGM_NAT_COOKIE, NGM_NAT_REDIRECT_PROTO, &nat->nrpr[k],
 		sizeof(struct ng_nat_redirect_proto)) < 0) {
-	    Log(LG_ERR, ("[%s] can't set NAT redirect-proto: %s",
-		b->name, strerror(errno)));
+	    Perror("[%s] can't set NAT redirect-proto", b->name);
 	}
       }
     }
@@ -2266,8 +2456,8 @@
     strcpy(mp.peerhook, NG_TEE_HOOK_RIGHT);
     if (NgSendMsg(gLinksCsock, path,
 	NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
-      Log(LG_ERR, ("[%s] can't create %s node at \"%s\"->\"%s\": %s",
-	b->name, NG_TEE_NODE_TYPE, path, mp.ourhook, strerror(errno)));
+      Perror("[%s] can't create %s node at \"%s\"->\"%s\"",
+	b->name, NG_TEE_NODE_TYPE, path, mp.ourhook);
       return(-1);
     }
     strlcat(path, ".", NG_PATHSIZ);
@@ -2275,8 +2465,7 @@
     snprintf(nm.name, sizeof(nm.name), "%s-tee%s", b->iface.ifname, v6?"6":"");
     if (NgSendMsg(gLinksCsock, path,
 	NGM_GENERIC_COOKIE, NGM_NAME, &nm, sizeof(nm)) < 0) {
-      Log(LG_ERR, ("[%s] can't name %s node: %s",
-	b->name, NG_TEE_NODE_TYPE, strerror(errno)));
+      Perror("[%s] can't name %s node", b->name, NG_TEE_NODE_TYPE);
       return(-1);
     }
     strcpy(hook, NG_TEE_HOOK_LEFT);
@@ -2313,8 +2502,8 @@
     strcpy(mp.peerhook, NG_TEE_HOOK_RIGHT);
     if (NgSendMsg(gLinksCsock, path,
 	NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
-      Log(LG_ERR, ("[%s] can't create %s node at \"%s\"->\"%s\": %s",
-	b->name, NG_TEE_NODE_TYPE, path, mp.ourhook, strerror(errno)));
+      Perror("[%s] can't create %s node at \"%s\"->\"%s\"",
+	b->name, NG_TEE_NODE_TYPE, path, mp.ourhook);
       return(-1);
     }
     strlcat(path, ".", NG_PATHSIZ);
@@ -2322,8 +2511,7 @@
     snprintf(nm.name, sizeof(nm.name), "%s_acct_tee", b->iface.ifname);
     if (NgSendMsg(gLinksCsock, path,
 	NGM_GENERIC_COOKIE, NGM_NAME, &nm, sizeof(nm)) < 0) {
-      Log(LG_ERR, ("[%s] can't name %s node: %s",
-	b->name, NG_TEE_NODE_TYPE, strerror(errno)));
+      Perror("[%s] can't name %s node", b->name, NG_TEE_NODE_TYPE);
       return(-1);
     }
     strcpy(hook, NG_TEE_HOOK_LEFT);
@@ -2333,16 +2521,15 @@
     snprintf(mp.peerhook, sizeof(mp.peerhook), "%s_in", b->iface.ifname);
     if (NgSendMsg(gLinksCsock, path,
 	NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
-      Log(LG_ERR, ("[%s] can't create %s node at \"%s\"->\"%s\": %s",
-	b->name, NG_IPACCT_NODE_TYPE, path, mp.ourhook, strerror(errno)));
+      Perror("[%s] can't create %s node at \"%s\"->\"%s\"",
+	b->name, NG_IPACCT_NODE_TYPE, path, mp.ourhook);
       return(-1);
     }
     snprintf(path1, sizeof(path1), "%s.%s", path, NG_TEE_HOOK_RIGHT2LEFT);
     snprintf(nm.name, sizeof(nm.name), "%s_ip_acct", b->iface.ifname);
     if (NgSendMsg(gLinksCsock, path1,
 	NGM_GENERIC_COOKIE, NGM_NAME, &nm, sizeof(nm)) < 0) {
-      Log(LG_ERR, ("[%s] can't name %s node: %s",
-	b->name, NG_IPACCT_NODE_TYPE, strerror(errno)));
+      Perror("[%s] can't name %s node", b->name, NG_IPACCT_NODE_TYPE);
       return(-1);
     }
     strcpy(cn.ourhook, NG_TEE_HOOK_LEFT2RIGHT);
@@ -2350,8 +2537,8 @@
     snprintf(cn.peerhook, sizeof(cn.peerhook), "%s_out", b->iface.ifname);
     if (NgSendMsg(gLinksCsock, path, NGM_GENERIC_COOKIE, NGM_CONNECT, &cn,
 	sizeof(cn)) < 0) {
-      Log(LG_ERR, ("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s", 
-        b->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+      Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+        b->name, path, cn.ourhook, cn.path, cn.peerhook);
       return (-1);
     }
     
@@ -2359,15 +2546,13 @@
     ipam.data = DLT_RAW;
     if (NgSendMsg(gLinksCsock, path1, NGM_IPACCT_COOKIE, NGM_IPACCT_SETDLT, 
 	&ipam, sizeof(ipam)) < 0) {
-      Log(LG_ERR, ("[%s] can't set DLT \"%s\"->\"%s\": %s", 
-        b->name, path, ipam.m.hname, strerror(errno)));
+      Perror("[%s] can't set DLT \"%s\"->\"%s\"", b->name, path, ipam.m.hname);
       return (-1);
     }
     ipam.data = 10000;
     if (NgSendMsg(gLinksCsock, path1, NGM_IPACCT_COOKIE, NGM_IPACCT_STHRS, 
 	&ipam, sizeof(ipam)) < 0) {
-      Log(LG_ERR, ("[%s] can't set DLT \"%s\"->\"%s\": %s", 
-        b->name, path, ipam.m.hname, strerror(errno)));
+      Perror("[%s] can't set DLT \"%s\"->\"%s\"", b->name, path, ipam.m.hname);
       return (-1);
     }
     
@@ -2375,15 +2560,13 @@
     ipam.data = DLT_RAW;
     if (NgSendMsg(gLinksCsock, path1, NGM_IPACCT_COOKIE, NGM_IPACCT_SETDLT, 
 	&ipam, sizeof(ipam)) < 0) {
-      Log(LG_ERR, ("[%s] can't set DLT \"%s\"->\"%s\": %s", 
-        b->name, path, ipam.m.hname, strerror(errno)));
+      Perror("[%s] can't set DLT \"%s\"->\"%s\"", b->name, path, ipam.m.hname);
       return (-1);
     }
     ipam.data = 10000;
     if (NgSendMsg(gLinksCsock, path1, NGM_IPACCT_COOKIE, NGM_IPACCT_STHRS, 
 	&ipam, sizeof(ipam)) < 0) {
-      Log(LG_ERR, ("[%s] can't set DLT \"%s\"->\"%s\": %s", 
-        b->name, path, ipam.m.hname, strerror(errno)));
+      Perror("[%s] can't set DLT \"%s\"->\"%s\"", b->name, path, ipam.m.hname);
       return (-1);
     }
 
@@ -2437,8 +2620,8 @@
 #endif
     if (NgSendMsg(gLinksCsock, path, NGM_GENERIC_COOKIE, NGM_CONNECT, &cn,
 	sizeof(cn)) < 0) {
-      Log(LG_ERR, ("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s", 
-        b->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+      Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+        b->name, path, cn.ourhook, cn.path, cn.peerhook);
       return (-1);
     }
     strlcat(path, ".", NG_PATHSIZ);
@@ -2478,8 +2661,7 @@
     nf_setdlt.dlt = DLT_RAW;
     if (NgSendMsg(gLinksCsock, path, NGM_NETFLOW_COOKIE, NGM_NETFLOW_SETDLT,
 	&nf_setdlt, sizeof(nf_setdlt)) < 0) {
-      Log(LG_ERR, ("[%s] can't configure data link type on %s: %s", b->name,
-	path, strerror(errno)));
+      Perror("[%s] can't configure data link type on %s", b->name, path);
       goto fail;
     }
 #ifdef NG_NETFLOW_CONF_INGRESS
@@ -2490,8 +2672,7 @@
 	(Enabled(&b->iface.options, IFACE_CONF_NETFLOW_ONCE)?NG_NETFLOW_CONF_ONCE:0);
     if (NgSendMsg(gLinksCsock, path, NGM_NETFLOW_COOKIE, NGM_NETFLOW_SETCONFIG,
 	&nf_setconf, sizeof(nf_setconf)) < 0) {
-      Log(LG_ERR, ("[%s] can't set config on %s: %s", b->name,
-	path, strerror(errno)));
+      Perror("[%s] can't set config on %s", b->name, path);
       goto fail;
     }
 #endif
@@ -2502,8 +2683,7 @@
 	nf_setidx.index = if_nametoindex(b->iface.ifname);
 	if (NgSendMsg(gLinksCsock, path, NGM_NETFLOW_COOKIE, NGM_NETFLOW_SETIFINDEX,
 	    &nf_setidx, sizeof(nf_setidx)) < 0) {
-    	  Log(LG_ERR, ("[%s] can't configure interface index on %s: %s", b->name,
-	    path, strerror(errno)));
+    	  Perror("[%s] can't configure interface index on %s", b->name, path);
     	  goto fail;
 	}
 #ifndef NG_NETFLOW_CONF_INGRESS
@@ -2555,8 +2735,8 @@
 	strcpy(mp.peerhook, "in");
 	if (NgSendMsg(gLinksCsock, path,
     		NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
-    	    Log(LG_ERR, ("can't create %s node at \"%s\"->\"%s\": %s", 
-    		NG_TCPMSS_NODE_TYPE, path, mp.ourhook, strerror(errno)));
+    	    Perror("can't create %s node at \"%s\"->\"%s\"",
+    		NG_TCPMSS_NODE_TYPE, path, mp.ourhook);
 	    goto fail;
 	}
 
@@ -2568,8 +2748,7 @@
 	snprintf(nm.name, sizeof(nm.name), "mpd%d-%s-mss", gPid, b->name);
 	if (NgSendMsg(gLinksCsock, path,
     		NGM_GENERIC_COOKIE, NGM_NAME, &nm, sizeof(nm)) < 0) {
-    	    Log(LG_ERR, ("can't name %s node: %s", NG_TCPMSS_NODE_TYPE,
-    		strerror(errno)));
+    	    Perror("can't name %s node", NG_TCPMSS_NODE_TYPE);
 	    goto fail;
 	}
 
@@ -2580,8 +2759,8 @@
     strcpy(mp.peerhook, "ppp");
     if (NgSendMsg(gLinksCsock, path,
 	    NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
-    	Log(LG_ERR, ("can't create %s node at \"%s\"->\"%s\": %s", 
-    	    NG_BPF_NODE_TYPE, path, mp.ourhook, strerror(errno)));
+	Perror("can't create %s node at \"%s\"->\"%s\"",
+	    NG_BPF_NODE_TYPE, path, mp.ourhook);
 	goto fail;
     }
 
@@ -2593,8 +2772,7 @@
     snprintf(nm.name, sizeof(nm.name), "mpd%d-%s-mss", gPid, b->name);
     if (NgSendMsg(gLinksCsock, path,
 	    NGM_GENERIC_COOKIE, NGM_NAME, &nm, sizeof(nm)) < 0) {
-    	Log(LG_ERR, ("can't name tcpmssfix %s node: %s", NG_BPF_NODE_TYPE,
-    	    strerror(errno)));
+	Perror("can't name tcpmssfix %s node", NG_BPF_NODE_TYPE);
 	goto fail;
     }
 
@@ -2604,8 +2782,8 @@
     strcpy(cn.peerhook, MPD_HOOK_TCPMSS_IN);
     if (NgSendMsg(gLinksCsock, ".:", NGM_GENERIC_COOKIE, NGM_CONNECT, &cn,
     	    sizeof(cn)) < 0) {
-    	Log(LG_ERR, ("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s", 
-    	    b->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+    	Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+    	    b->name, path, cn.ourhook, cn.path, cn.peerhook);
     	goto fail;
     }
 
@@ -2614,8 +2792,8 @@
     strcpy(cn.peerhook, MPD_HOOK_TCPMSS_OUT);
     if (NgSendMsg(gLinksCsock, ".:", NGM_GENERIC_COOKIE, NGM_CONNECT, &cn,
     	    sizeof(cn)) < 0) {
-    	Log(LG_ERR, ("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s", 
-    	    b->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+    	Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+    	    b->name, path, cn.ourhook, cn.path, cn.peerhook);
     	goto fail;
     }
 #endif /* USE_NG_TCPMSS */
@@ -2648,15 +2826,13 @@
   snprintf(tcpmsscfg.outHook, sizeof(tcpmsscfg.outHook), "out");
   if (NgSendMsg(gLinksCsock, path, NGM_TCPMSS_COOKIE, NGM_TCPMSS_CONFIG,
       &tcpmsscfg, sizeof(tcpmsscfg)) < 0) {
-    Log(LG_ERR, ("[%s] can't configure %s node program: %s", b->name,
-      NG_TCPMSS_NODE_TYPE, strerror(errno)));
+    Perror("[%s] can't configure %s node program", b->name, NG_TCPMSS_NODE_TYPE);
   }
   snprintf(tcpmsscfg.inHook, sizeof(tcpmsscfg.inHook), "out");
   snprintf(tcpmsscfg.outHook, sizeof(tcpmsscfg.outHook), "in");
   if (NgSendMsg(gLinksCsock, path, NGM_TCPMSS_COOKIE, NGM_TCPMSS_CONFIG,
       &tcpmsscfg, sizeof(tcpmsscfg)) < 0) {
-    Log(LG_ERR, ("[%s] can't configure %s node program: %s", b->name,
-      NG_TCPMSS_NODE_TYPE, strerror(errno)));
+    Perror("[%s] can't configure %s node program", b->name, NG_TCPMSS_NODE_TYPE);
   }
 #else
     union {
@@ -2678,10 +2854,8 @@
     strcpy(hp->ifNotMatch, "iface");
 
     if (NgSendMsg(gLinksCsock, hook, NGM_BPF_COOKIE,
-	    NGM_BPF_SET_PROGRAM, hp, NG_BPF_HOOKPROG_SIZE(hp->bpf_prog_len)) < 0) {
-	Log(LG_ERR, ("[%s] can't set %s node program: %s",
-    	    b->name, NG_BPF_NODE_TYPE, strerror(errno)));
-    }
+	    NGM_BPF_SET_PROGRAM, hp, NG_BPF_HOOKPROG_SIZE(hp->bpf_prog_len)) < 0)
+	Perror("[%s] can't set %s node program", b->name, NG_BPF_NODE_TYPE);
 
     memset(&u, 0, sizeof(u));
     strcpy(hp->thisHook, MPD_HOOK_TCPMSS_IN);
@@ -2692,10 +2866,8 @@
     strcpy(hp->ifNotMatch, "ppp");
 
     if (NgSendMsg(gLinksCsock, hook, NGM_BPF_COOKIE,
-	    NGM_BPF_SET_PROGRAM, hp, NG_BPF_HOOKPROG_SIZE(hp->bpf_prog_len)) < 0) {
-	Log(LG_ERR, ("[%s] can't set %s node program: %s",
-    	    b->name, NG_BPF_NODE_TYPE, strerror(errno)));
-    }
+	    NGM_BPF_SET_PROGRAM, hp, NG_BPF_HOOKPROG_SIZE(hp->bpf_prog_len)) < 0)
+	Perror("[%s] can't set %s node program", b->name, NG_BPF_NODE_TYPE);
 
     snprintf(hook, sizeof(hook), "o%d", b->id);
     memset(&u, 0, sizeof(u));
@@ -2707,10 +2879,8 @@
     strcpy(hp->ifNotMatch, "ppp");
 
     if (NgSendMsg(gLinksCsock, hook, NGM_BPF_COOKIE,
-	    NGM_BPF_SET_PROGRAM, hp, NG_BPF_HOOKPROG_SIZE(hp->bpf_prog_len)) < 0) {
-	Log(LG_ERR, ("[%s] can't set %s node program: %s",
-    	    b->name, NG_BPF_NODE_TYPE, strerror(errno)));
-    }
+	    NGM_BPF_SET_PROGRAM, hp, NG_BPF_HOOKPROG_SIZE(hp->bpf_prog_len)) < 0)
+	Perror("[%s] can't set %s node program", b->name, NG_BPF_NODE_TYPE);
 
     memset(&u, 0, sizeof(u));
     strcpy(hp->thisHook, MPD_HOOK_TCPMSS_OUT);
@@ -2721,10 +2891,8 @@
     strcpy(hp->ifNotMatch, "iface");
 
     if (NgSendMsg(gLinksCsock, hook, NGM_BPF_COOKIE,
-	    NGM_BPF_SET_PROGRAM, hp, NG_BPF_HOOKPROG_SIZE(hp->bpf_prog_len)) < 0) {
-	Log(LG_ERR, ("[%s] can't set %s node program: %s",
-    	    b->name, NG_BPF_NODE_TYPE, strerror(errno)));
-    }
+	    NGM_BPF_SET_PROGRAM, hp, NG_BPF_HOOKPROG_SIZE(hp->bpf_prog_len)) < 0)
+	Perror("[%s] can't set %s node program", b->name, NG_BPF_NODE_TYPE);
 
 #endif /* USE_NG_TCPMSS */
 }
@@ -2761,8 +2929,8 @@
 	strcpy(mp.peerhook, "ppp");
 	if (NgSendMsg(gLinksCsock, path,
 		NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
-    	    Log(LG_ERR, ("can't create %s node at \"%s\"->\"%s\": %s", 
-    		NG_BPF_NODE_TYPE, path, mp.ourhook, strerror(errno)));
+	    Perror("can't create %s node at \"%s\"->\"%s\"",
+		NG_BPF_NODE_TYPE, path, mp.ourhook);
 	    goto fail;
 	}
 
@@ -2771,17 +2939,14 @@
 	strcpy(hook, "iface");
 
 	b->iface.limitID = NgGetNodeID(gLinksCsock, path);
-	if (b->iface.limitID == 0) {
-    	    Log(LG_ERR, ("can't get limits %s node ID: %s", NG_BPF_NODE_TYPE,
-    		strerror(errno)));
-	}
+	if (b->iface.limitID == 0)
+	    Perror("can't get limits %s node ID", NG_BPF_NODE_TYPE);
 
 	/* Set the new node's name. */
 	snprintf(nm.name, sizeof(nm.name), "mpd%d-%s-lim", gPid, b->name);
 	if (NgSendMsg(gLinksCsock, path,
 		NGM_GENERIC_COOKIE, NGM_NAME, &nm, sizeof(nm)) < 0) {
-    	    Log(LG_ERR, ("can't name limits %s node: %s", NG_BPF_NODE_TYPE,
-    		strerror(errno)));
+	    Perror("can't name limits %s node", NG_BPF_NODE_TYPE);
 	    goto fail;
 	}
 
@@ -2810,7 +2975,7 @@
     struct ngm_connect  cn;
     int			i;
     
-    hpu = Malloc(MB_IFACE, sizeof(*hpu));
+    hpu = Malloc(MB_ACL, sizeof(*hpu));
     hp = &hpu->hprog;
 
     if (b->params.acl_limits[0] || b->params.acl_limits[1]) {
@@ -2880,12 +3045,12 @@
 		    	int		bufbraces;
 
 #define ACL_BUF_SIZE	256*1024
-			buf = Malloc(MB_IFACE, ACL_BUF_SIZE);
+			buf = Malloc(MB_ACL, ACL_BUF_SIZE);
 			buf[0] = 0;
 			bufbraces = 0;
 			while (f) {
 			    char	*b1, *b2, *sbuf;
-			    sbuf = Mstrdup(MB_IFACE, f->rule);
+			    sbuf = Mstrdup(MB_ACL, f->rule);
 			    b2 = sbuf;
 			    b1 = strsep(&b2, " ");
 			    if (b2 != NULL) {
@@ -2966,8 +3131,8 @@
 			strcpy(cn.peerhook, inhookn[0]);
 			if (NgSendMsg(gLinksCsock, path,
 		        	NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
-		    	    Log(LG_ERR, ("[%s] IFACE: can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-			        b->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+			    Perror("[%s] IFACE: can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+			        b->name, path, cn.ourhook, cn.path, cn.peerhook);
 			}
 			strcpy(stathook, inhookn[0]);
 		    }
@@ -2991,9 +3156,9 @@
 		    snprintf(mp.ourhook, sizeof(mp.ourhook), "%d-%d-m", dir, num);
 		    strcpy(mp.peerhook, ((dir == 0)?NG_CAR_HOOK_LOWER:NG_CAR_HOOK_UPPER));
 		    if (NgSendMsg(gLinksCsock, path,
-		    	    NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
-		    	Log(LG_ERR, ("[%s] IFACE: can't create %s node at \"%s\"->\"%s\": %s", 
-		    	    b->name, NG_CAR_NODE_TYPE, path, mp.ourhook, strerror(errno)));
+			    NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
+			Perror("[%s] IFACE: can't create %s node at \"%s\"->\"%s\"", 
+			    b->name, NG_CAR_NODE_TYPE, path, mp.ourhook);
 		    }
 
 		    snprintf(tmppath, sizeof(tmppath), "%s%d-%d-m", path, dir, num);
@@ -3004,8 +3169,8 @@
 		    strcpy(cn.peerhook, ((dir == 0)?NG_CAR_HOOK_UPPER:NG_CAR_HOOK_LOWER));
 		    if (NgSendMsg(gLinksCsock, path,
 		            NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
-		        Log(LG_ERR, ("[%s] IFACE: can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-			    b->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+			Perror("[%s] IFACE: can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+			    b->name, path, cn.ourhook, cn.path, cn.peerhook);
 		    }
 			
 		    bzero(&car, sizeof(car));
@@ -3046,8 +3211,8 @@
 						
 		    if (NgSendMsg(gLinksCsock, tmppath,
 		            NGM_CAR_COOKIE, NGM_CAR_SET_CONF, &car, sizeof(car)) < 0) {
-		        Log(LG_ERR, ("[%s] IFACE: can't set %s configuration: %s",
-			    b->name, NG_CAR_NODE_TYPE, strerror(errno)));
+		        Perror("[%s] IFACE: can't set %s configuration",
+			    b->name, NG_CAR_NODE_TYPE);
 		    }
 			
 		    if (ac > p) {
@@ -3067,8 +3232,8 @@
 		    	    sprintf(hp1->thisHook, "%d-%d-mi", dir, num);
 			    if (NgSendMsg(gLinksCsock, path, NGM_BPF_COOKIE, NGM_BPF_SET_PROGRAM,
 			    	    hp1, NG_BPF_HOOKPROG_SIZE(hp1->bpf_prog_len)) < 0) {
-				Log(LG_ERR, ("[%s] IFACE: can't set %s node program: %s",
-	    			    b->name, NG_BPF_NODE_TYPE, strerror(errno)));
+				Perror("[%s] IFACE: can't set %s node program",
+	    			    b->name, NG_BPF_NODE_TYPE);
 			    }
 			    			    
 			    strcpy(stathook, hp1->thisHook);
@@ -3102,8 +3267,8 @@
 		    strcpy(cn.peerhook, inhookn[1]);
 		    if (NgSendMsg(gLinksCsock, path,
 		            NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
-		        Log(LG_ERR, ("[%s] IFACE: can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-			    b->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+			Perror("[%s] IFACE: can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+			    b->name, path, cn.ourhook, cn.path, cn.peerhook);
 		    }
 		} else {
 		    /* There is no next limit, pass nomatch. */
@@ -3118,13 +3283,13 @@
 			    break;
 		    }
 		    if (ss == NULL) {
-			ss = Malloc(MB_IFACE, sizeof(*ss));
+			ss = Malloc(MB_ACL, sizeof(*ss));
 			strlcpy(ss->name, l->name, sizeof(ss->name));
 			SLIST_INIT(&ss->src);
 			SLIST_INSERT_HEAD(&b->iface.ss[dir], ss, next);
 		    }
 		    if (stathook[0]) {
-			sss = Malloc(MB_IFACE, sizeof(*sss));
+			sss = Malloc(MB_ACL, sizeof(*sss));
 			strlcpy(sss->hook, stathook, sizeof(sss->hook));
 			sss->type = SSSS_IN;
 			SLIST_INSERT_HEAD(&ss->src, sss, next);
@@ -3134,7 +3299,7 @@
 		for (i = 0; i < 2; i++) {
 		    if (inhook[i][0] != 0) {
 			if (l->name[0] && !stathook[0]) {
-			    sss = Malloc(MB_IFACE, sizeof(*sss));
+			    sss = Malloc(MB_ACL, sizeof(*sss));
 			    strlcpy(sss->hook, inhook[i], sizeof(sss->hook));
 			    sss->type = SSSS_MATCH;
 			    SLIST_INSERT_HEAD(&ss->src, sss, next);
@@ -3143,8 +3308,8 @@
 		        strcpy(hp->thisHook, inhook[i]);
 		        if (NgSendMsg(gLinksCsock, path, NGM_BPF_COOKIE, NGM_BPF_SET_PROGRAM,
 		    		hp, NG_BPF_HOOKPROG_SIZE(hp->bpf_prog_len)) < 0) {
-			    Log(LG_ERR, ("[%s] IFACE: can't set %s node program: %s",
-	    		        b->name, NG_BPF_NODE_TYPE, strerror(errno)));
+			    Perror("[%s] IFACE: can't set %s node program",
+	    		        b->name, NG_BPF_NODE_TYPE);
 			}
 		    }
 		    strcpy(inhook[i], inhookn[i]);
@@ -3165,8 +3330,8 @@
 		    strcpy(hp->ifNotMatch, outhook);
 		    if (NgSendMsg(gLinksCsock, path, NGM_BPF_COOKIE, NGM_BPF_SET_PROGRAM, 
 			    hp, NG_BPF_HOOKPROG_SIZE(hp->bpf_prog_len)) < 0) {
-			Log(LG_ERR, ("[%s] IFACE: can't set %s node %s %s program (2): %s",
-	    		    b->name, NG_BPF_NODE_TYPE, path, hp->thisHook, strerror(errno)));
+			Perror("[%s] IFACE: can't set %s node %s %s program (2)",
+			    b->name, NG_BPF_NODE_TYPE, path, hp->thisHook);
 		    }
 		}
 	    }
@@ -3232,7 +3397,7 @@
 		    break;
 	    }
 	    if (!ssr) {
-		ssr = Malloc(MB_IFACE, sizeof(*ssr));
+		ssr = Malloc(MB_ACL, sizeof(*ssr));
 		strlcpy(ssr->name, ss->name, sizeof(ssr->name));
 		SLIST_INSERT_HEAD(&stat->stat[dir], ssr, next);
 	    }
@@ -3280,7 +3445,7 @@
 		    break;
 	    }
 	    if (!ssr1) {
-		ssr1 = Malloc(MB_IFACE, sizeof(*ssr1));
+		ssr1 = Malloc(MB_ACL, sizeof(*ssr1));
 		strlcpy(ssr1->name, ssr2->name, sizeof(ssr1->name));
 		SLIST_INSERT_HEAD(&stat1->stat[dir], ssr1, next);
 	    }
@@ -3304,3 +3469,195 @@
     }
 }
 #endif /* USE_NG_BPF */
+
+/*
+ * IfaceSetName()
+ */
+
+int
+IfaceSetName(Bund b, const char * ifname)
+{
+    IfaceState	const iface = &b->iface;
+    struct ifreq ifr;
+    int s;
+
+    /* Do not rename interface on template */
+    if (b->tmpl)
+	return(0);
+
+    /* Do not wait ioctl error "file already exist" */
+    if (strncmp(iface->ifname, ifname, sizeof(iface->ifname)) == 0)
+	return(0);
+
+    /* Get socket */
+    if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
+	Log(LG_ERR, ("[%s] IFACE: Can't get socket to set name", b->name));
+	return(-1);
+    }
+
+    /* Set name of interface */
+    memset(&ifr, 0, sizeof(ifr));
+    strlcpy(ifr.ifr_name, iface->ifname, sizeof(ifr.ifr_name));
+    ifr.ifr_data = (caddr_t)ifname;
+    Log(LG_IFACE2, ("[%s] IFACE: setting \"%s\" name to \"%s\"",
+	b->name, iface->ifname, ifname));
+
+    if (ioctl(s, SIOCSIFNAME, (caddr_t)&ifr) < 0) {
+	Perror("[%s] IFACE: ioctl(%s, SIOCSIFNAME)", b->name, iface->ifname);
+	close(s);
+	return(-1);
+    }
+
+    close(s);
+    /* Save name */
+    strlcpy(iface->ifname, ifname, sizeof(iface->ifname));
+    return(0);
+}
+
+#ifdef SIOCSIFDESCR
+/*
+ * IfaceSetDescr()
+ */
+
+int
+IfaceSetDescr(Bund b, const char * ifdescr)
+{
+    IfaceState	const iface = &b->iface;
+    struct	ifreq ifr;
+    int		s, ifdescr_maxlen;
+    char	*newdescr;
+    size_t	sz = sizeof(int);
+
+    if (b->tmpl) {
+	Log(LG_ERR, ("Impossible ioctl(SIOCSIFDESCR) on template"));
+	return(-1);
+    }
+
+    if (sysctlbyname("net.ifdescr_maxlen", &ifdescr_maxlen, &sz, NULL, 0) < 0) {
+	Perror("[%s] IFACE: sysctl net.ifdescr_maxlen  failed", b->name);
+	return(-1);
+    }
+
+    if (ifdescr_maxlen < strlen(ifdescr) + 1) {
+	Log(LG_ERR, ("[%s] IFACE: Description too long, >%d characters",
+	    b->name, ifdescr_maxlen-1));
+	return(-1);
+    }
+
+    /* Get socket */
+    if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
+	Log(LG_ERR, ("[%s] IFACE: Can't get socket to set description", b->name));
+	return(-1);
+    }
+
+    /* Set description of interface */
+    memset(&ifr, 0, sizeof(ifr));
+    strlcpy(ifr.ifr_name, iface->ifname, sizeof(ifr.ifr_name));
+    ifr.ifr_buffer.length = strlen(ifdescr) + 1;
+    if (ifr.ifr_buffer.length == 1) {
+	ifr.ifr_buffer.buffer = newdescr = NULL;
+	ifr.ifr_buffer.length = 0;
+	Log(LG_IFACE2, ("[%s] IFACE: clearing \"%s\" description",
+	    b->name, iface->ifname));
+    } else {
+	newdescr = Mstrdup(MB_IFACE, ifdescr);
+	ifr.ifr_buffer.buffer = newdescr;
+	Log(LG_IFACE2, ("[%s] IFACE: setting \"%s\" description to \"%s\"",
+	    b->name, iface->ifname, ifdescr));
+    }
+
+    if (ioctl(s, SIOCSIFDESCR, (caddr_t)&ifr) < 0) {
+	Perror("[%s] IFACE: ioctl(%s, SIOCSIFDESCR)", b->name, iface->ifname);
+	Freee(newdescr);
+	close(s);
+	return(-1);
+    }
+    Freee(newdescr);
+    close(s);
+    return(0);
+}
+#endif /* SIOCSIFDESCR */
+#ifdef SIOCAIFGROUP
+/*
+ * IfaceAddGroup()
+ */
+
+int
+IfaceAddGroup(Bund b, const char * ifgroup)
+{
+    IfaceState	const iface = &b->iface;
+    struct ifgroupreq	ifgr;
+    int	s, i;
+
+    /* Do not add group on template */
+    if (b->tmpl)
+	return(0);
+
+    if (ifgroup[0] && isdigit(ifgroup[strlen(ifgroup) - 1])) {
+	Perror("[%s] IFACE: groupnames may not end in a digit", b->name);
+	return(-1);
+    }
+
+    /* Get socket */
+    if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
+	Perror("[%s] IFACE: Can't get socket to add group", b->name);
+	return(-1);
+    }
+
+    /* Add interface group */
+    memset(&ifgr, 0, sizeof(ifgr));
+    strlcpy(ifgr.ifgr_name, iface->ifname, sizeof(ifgr.ifgr_name));
+    strlcpy(ifgr.ifgr_group, ifgroup, sizeof(ifgr.ifgr_group));
+
+    Log(LG_IFACE2, ("[%s] IFACE: adding interface %s to group %s",
+	b->name, iface->ifname, ifgroup));
+
+    i = ioctl(s, SIOCAIFGROUP, (caddr_t)&ifgr);
+    if (i < 0 && i != EEXIST) {
+	Perror("[%s] IFACE: ioctl(%s, SIOCAIFGROUP)", b->name, iface->ifname);
+        close(s);
+        return(-1);
+    }
+
+    close(s);
+    return(0);
+}
+
+/*
+ * IfaceDelGroup()
+ */
+int
+IfaceDelGroup(Bund b, const char * ifgroup)
+{
+    IfaceState	const iface = &b->iface;
+    struct ifgroupreq	ifgr;
+    int	s;
+
+    /* Get socket */
+    if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
+	Perror("[%s] IFACE: Can't get socket to delete from group", b->name);
+	return(-1);
+    }
+
+    if (ifgroup[0] && isdigit(ifgroup[strlen(ifgroup) - 1])) {
+	Perror("[%s] IFACE: groupnames may not end in a digit", b->name);
+	return(-1);
+    }
+
+    /* Set interface group */
+    memset(&ifgr, 0, sizeof(ifgr));
+    strlcpy(ifgr.ifgr_name, iface->ifname, sizeof(ifgr.ifgr_name));
+    strlcpy(ifgr.ifgr_group, ifgroup, sizeof(ifgr.ifgr_group));
+
+    Log(LG_IFACE2, ("[%s] IFACE: remove interface %s from group %s",
+	b->name, iface->ifname, ifgroup));
+
+    if (ioctl(s, SIOCDIFGROUP, (caddr_t)&ifgr) == -1) {
+	Perror("[%s] IFACE: ioctl(%s, SIOCDIFGROUP)", b->name, iface->ifname);
+	close(s);
+	return(-1);
+    }
+    close(s);
+    return(0);
+}
+#endif
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/iface.h
--- a/contrib/mpd/src/iface.h	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/iface.h	Fri Sep 14 02:13:58 2012 +0300
@@ -79,6 +79,13 @@
     u_char		peer_addr_force;
     u_char		self_ipv6_addr_force;
     u_char		peer_ipv6_addr_force;
+    char		ifname[IFNAMSIZ];	/* Name of my interface */
+#ifdef SIOCSIFDESCR
+    char		*ifdescr;		/* Interface description*/
+#endif
+#ifdef SIOCAIFGROUP
+    char		ifgroup[IFNAMSIZ];	/* Group of my interface */
+#endif
   };
 
   struct ifaceroute {
@@ -92,6 +99,9 @@
     char		ifname[IFNAMSIZ];	/* Name of my interface */
     char		ngname[IFNAMSIZ];	/* Name of my Netgraph node */
     uint		ifindex;		/* System interface index */
+#ifdef SIOCSIFDESCR
+    char		*ifdescr;		/* Interface description*/
+#endif
     struct ifaceconf	conf;
     u_char		traffic[IFACE_IDLE_SPLIT];	/* Mark any traffic */
     u_short		mtu;			/* Interface MTU */
@@ -173,6 +183,7 @@
 
   extern void	IfaceInit(Bund b);
   extern void	IfaceInst(Bund b, Bund bt);
+  extern void	IfaceDestroy(Bund b);
   extern void	IfaceOpen(Bund b);
   extern void	IfaceClose(Bund b);
   extern int	IfaceOpenCmd(Context ctx);
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/ipcp.c
--- a/contrib/mpd/src/ipcp.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/ipcp.c	Fri Sep 14 02:13:58 2012 +0300
@@ -547,8 +547,7 @@
         snprintf(path, sizeof(path), "[%x]:%s", b->nodeID, NG_PPP_HOOK_VJC_IP);
 	if (NgSendMsg(gLinksCsock, path,
     		NGM_VJC_COOKIE, NGM_VJC_SET_CONFIG, &vjc, sizeof(vjc)) < 0) {
-	    Log(LG_ERR, ("[%s] can't config %s node: %s",
-    		b->name, NG_VJC_NODE_TYPE, strerror(errno)));
+	    Perror("[%s] can't config %s node", b->name, NG_VJC_NODE_TYPE);
 	}
     }
 #endif /* USE_NG_VJC */
@@ -913,8 +912,8 @@
   strcpy(mp.peerhook, NG_VJC_HOOK_IP);
   if (NgSendMsg(gLinksCsock, path,
       NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
-    Log(LG_ERR, ("[%s] can't create %s node at \"%s\"->\"%s\": %s",
-      b->name, NG_VJC_NODE_TYPE, path, mp.ourhook, strerror(errno)));
+    Perror("[%s] can't create %s node at \"%s\"->\"%s\"",
+      b->name, NG_VJC_NODE_TYPE, path, mp.ourhook);
     goto fail;
   }
 
@@ -923,8 +922,7 @@
   snprintf(nm.name, sizeof(nm.name), "mpd%d-%s-vjc", gPid, b->name);
   if (NgSendMsg(gLinksCsock, path,
       NGM_GENERIC_COOKIE, NGM_NAME, &nm, sizeof(nm)) < 0) {
-    Log(LG_ERR, ("[%s] can't name %s node: %s",
-      b->name, NG_VJC_NODE_TYPE, strerror(errno)));
+    Perror("[%s] can't name %s node", b->name, NG_VJC_NODE_TYPE);
     goto fail;
   }
 
@@ -935,24 +933,24 @@
   strcpy(cn.peerhook, NG_VJC_HOOK_VJCOMP);
   if (NgSendMsg(gLinksCsock, path,
       NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
-    Log(LG_ERR, ("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-      b->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+    Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+      b->name, path, cn.ourhook, cn.path, cn.peerhook);
     goto fail;
   }
   strcpy(cn.ourhook, NG_PPP_HOOK_VJC_UNCOMP);
   strcpy(cn.peerhook, NG_VJC_HOOK_VJUNCOMP);
   if (NgSendMsg(gLinksCsock, path,
       NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
-    Log(LG_ERR, ("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s", 
-      b->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+    Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+      b->name, path, cn.ourhook, cn.path, cn.peerhook);
     goto fail;
   }
   strcpy(cn.ourhook, NG_PPP_HOOK_VJC_VJIP);
   strcpy(cn.peerhook, NG_VJC_HOOK_VJIP);
   if (NgSendMsg(gLinksCsock, path,
       NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
-    Log(LG_ERR, ("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-      b->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+    Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+      b->name, path, cn.ourhook, cn.path, cn.peerhook);
     goto fail;
   }
 
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/ippool.c
--- a/contrib/mpd/src/ippool.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/ippool.c	Fri Sep 14 02:13:58 2012 +0300
@@ -43,7 +43,7 @@
 void
 IPPoolInit(void)
 {
-    int ret = pthread_mutex_init (&gGiantMutex, NULL);
+    int ret = pthread_mutex_init (&gIPPoolMutex, NULL);
     if (ret != 0) {
 	Log(LG_ERR, ("Could not create IP pool mutex: %d", ret));
 	exit(EX_UNAVAILABLE);
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/l2tp.c
--- a/contrib/mpd/src/l2tp.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/l2tp.c	Fri Sep 14 02:13:58 2012 +0300
@@ -312,9 +312,13 @@
 L2tpInst(Link l, Link lt)
 {
 	L2tpInfo pi;
-	l->info = Mdup(MB_PHYS, lt->info, sizeof(struct l2tpinfo));
-	pi = (L2tpInfo) l->info;
-    
+	L2tpInfo	const pit = (L2tpInfo) lt->info;
+
+	/* Initialize this link */
+	pi = (L2tpInfo) (l->info = Mdup(MB_PHYS, lt->info, sizeof(*pit)));
+	if (pit->conf.fqdn_peer_addr != NULL)
+	    pi->conf.fqdn_peer_addr =
+	        Mstrdup(MB_PHYS, pit->conf.fqdn_peer_addr);
 	if (pi->server)
 	    pi->server->refs++;
 	
@@ -344,7 +348,6 @@
 	} ugetsas;
 	struct sockaddr_storage	*const getsas = (struct sockaddr_storage *)(void *)ugetsas.reply.data;
 	struct ngm_mkpeer mkpeer;
-	struct sockaddr_storage peer_sas;
 	struct sockaddr_storage sas;
 	char hook[NG_HOOKSIZ];
 	char namebuf[64];
@@ -376,8 +379,8 @@
 			    }
 			    if (ppp_l2tp_avp_list_append(avps, 1, 0, AVP_FRAMING_TYPE,
 	        	        &fr, sizeof(fr)) == -1) {
-			    	    Log(LG_ERR, ("[%s] ppp_l2tp_avp_list_append: %s", 
-				        l->name, strerror(errno)));
+				    Perror("[%s] ppp_l2tp_avp_list_append",
+				        l->name);
 			    }
 			} else {
 			    avps = NULL;
@@ -427,15 +430,13 @@
 			if (pi->conf.callingnum[0]) {
 			  if (ppp_l2tp_avp_list_append(avps, 1, 0, AVP_CALLING_NUMBER,
 	        	    pi->conf.callingnum, strlen(pi->conf.callingnum)) == -1) {
-				Log(LG_ERR, ("[%s] ppp_l2tp_avp_list_append: %s", 
-				    l->name, strerror(errno)));
+				Perror("[%s] ppp_l2tp_avp_list_append", l->name);
 			  }
 			}
 			if (pi->conf.callednum[0]) {
 			  if (ppp_l2tp_avp_list_append(avps, 1, 0, AVP_CALLED_NUMBER,
 	        	    pi->conf.callednum, strlen(pi->conf.callednum)) == -1) {
-				Log(LG_ERR, ("[%s] ppp_l2tp_avp_list_append: %s", 
-				    l->name, strerror(errno)));
+				Perror("[%s] ppp_l2tp_avp_list_append", l->name);
 			  }
 			}
 			if ((sess = ppp_l2tp_initiate(tun->ctrl, 
@@ -443,8 +444,7 @@
 				Enabled(&pi->conf.options, L2TP_CONF_LENGTH)?1:0,
 				Enabled(&pi->conf.options, L2TP_CONF_DATASEQ)?1:0,
 				avps)) == NULL) {
-			    Log(LG_ERR, ("[%s] ppp_l2tp_initiate: %s", 
-				l->name, strerror(errno)));
+			    Perror("[%s] ppp_l2tp_initiate", l->name);
 			    ppp_l2tp_avp_list_destroy(&avps);
 			    pi->sess = NULL;
 			    pi->tun = NULL;
@@ -473,8 +473,8 @@
 				}
 				if (ppp_l2tp_avp_list_append(avps, 1, 0, AVP_FRAMING_TYPE,
 	        		    &fr, sizeof(fr)) == -1) {
-				        Log(LG_ERR, ("[%s] ppp_l2tp_avp_list_append: %s", 
-				    	    l->name, strerror(errno)));
+					Perror("[%s] ppp_l2tp_avp_list_append",
+					    l->name);
 				}
 			    } else {
 				avps = NULL;
@@ -490,7 +490,7 @@
 
 	/* There is no tun which we need. Create a new one. */
 	tun = Malloc(MB_PHYS, sizeof(*tun));
-	sockaddrtou_addr(&peer_sas,&tun->peer_addr,&tun->peer_port);
+	memset(tun, 0, sizeof(*tun));
 	u_addrcopy(&pi->conf.peer_addr.addr, &tun->peer_addr);
 	tun->peer_port = pi->conf.peer_port?pi->conf.peer_port:L2TP_PORT;
 	u_addrcopy(&pi->conf.self_addr, &tun->self_addr);
@@ -517,7 +517,7 @@
 	      &cap, sizeof(cap)) == -1) ||
 	    (ppp_l2tp_avp_list_append(avps, 1, 0, AVP_RECEIVE_WINDOW_SIZE,
 	      &win, sizeof(win)) == -1)) {
-		Log(LG_ERR, ("L2TP: ppp_l2tp_avp_list_append: %s", strerror(errno)));
+		Perror("L2TP: ppp_l2tp_avp_list_append");
 		goto fail;
 	}
 
@@ -527,8 +527,7 @@
 	    &node_id, hook, avps, 
 	    pi->conf.secret, strlen(pi->conf.secret),
 	    Enabled(&pi->conf.options, L2TP_CONF_HIDDEN))) == NULL) {
-		Log(LG_ERR, ("[%s] ppp_l2tp_ctrl_create: %s", 
-		    l->name, strerror(errno)));
+		Perror("[%s] ppp_l2tp_ctrl_create", l->name);
 		goto fail;
 	}
 	ppp_l2tp_ctrl_set_cookie(tun->ctrl, tun);
@@ -539,9 +538,8 @@
 
 	/* Get a temporary netgraph socket node */
 	if (NgMkSockNode(NULL, &csock, &dsock) == -1) {
-		Log(LG_ERR, ("[%s] NgMkSockNode: %s", 
-		    l->name, strerror(errno)));
-		goto fail;
+	    Perror("[%s] NgMkSockNode", l->name);
+	    goto fail;
 	}
 
 	/* Attach a new UDP socket to "lower" hook */
@@ -556,8 +554,7 @@
 	}
 	if (NgSendMsg(csock, namebuf, NGM_GENERIC_COOKIE,
 	    NGM_MKPEER, &mkpeer, sizeof(mkpeer)) == -1) {
-		Log(LG_ERR, ("[%s] mkpeer: %s", 
-		    l->name, strerror(errno)));
+		Perror("[%s] mkpeer", l->name);
 		goto fail;
 	}
 
@@ -571,15 +568,13 @@
 	memcpy(sockopt->value, &one, sizeof(int));
 	if (NgSendMsg(csock, namebuf, NGM_KSOCKET_COOKIE,
 	    NGM_KSOCKET_SETOPT, sockopt, sizeof(sockopt_buf)) == -1) {
-		Log(LG_ERR, ("[%s] setsockopt: %s", 
-		    l->name, strerror(errno)));
+		Perror("[%s] setsockopt", l->name);
 		goto fail;
 	}
 	sockopt->name = SO_REUSEPORT;
 	if (NgSendMsg(csock, namebuf, NGM_KSOCKET_COOKIE,
 	    NGM_KSOCKET_SETOPT, sockopt, sizeof(sockopt_buf)) == -1) {
-		Log(LG_ERR, ("[%s] setsockopt: %s", 
-		    l->name, strerror(errno)));
+		Perror("[%s] setsockopt", l->name);
 		goto fail;
 	}
 
@@ -588,8 +583,7 @@
 	    u_addrtosockaddr(&tun->self_addr,tun->self_port,&sas);
 	    if (NgSendMsg(csock, namebuf, NGM_KSOCKET_COOKIE,
 		NGM_KSOCKET_BIND, &sas, sas.ss_len) == -1) {
-		    Log(LG_ERR, ("[%s] bind: %s", 
-			l->name, strerror(errno)));
+		    Perror("[%s] bind", l->name);
 		    goto fail;
 	    }
 	}
@@ -598,27 +592,23 @@
 	if (NgSendMsg(csock, namebuf, NGM_KSOCKET_COOKIE,
 	      NGM_KSOCKET_CONNECT, &sas, sas.ss_len) == -1
 	    && errno != EINPROGRESS) {
-		Log(LG_ERR, ("[%s] connect: %s", 
-		    l->name, strerror(errno)));
+		Perror("[%s] connect", l->name);
 		goto fail;
 	}
 
 	if (NgSendMsg(csock, namebuf, NGM_KSOCKET_COOKIE,
 	    NGM_KSOCKET_GETNAME, NULL, 0) == -1) {
-		Log(LG_ERR, ("[%s] getname send: %s", 
-		    l->name, strerror(errno)));
+		Perror("[%s] getname send", l->name);
 	} else 
 	if (NgRecvMsg(csock, &ugetsas.reply, sizeof(ugetsas), NULL) == -1) {
-		Log(LG_ERR, ("[%s] getname recv: %s", 
-		    l->name, strerror(errno)));
+		Perror("[%s] getname recv", l->name);
 	} else {
 	    sockaddrtou_addr(getsas,&tun->self_addr,&tun->self_port);
 	}
 
 	/* Add peer to our hash table */
 	if (ghash_put(gL2tpTuns, tun) == -1) {
-		Log(LG_ERR, ("[%s] ghash_put: %s", 
-		    l->name, strerror(errno)));
+		Perror("[%s] ghash_put", l->name);
 		goto fail;
 	}
 	pi->tun = tun;
@@ -716,7 +706,7 @@
 
 	    /* Get a temporary netgraph socket node */
 	    if (NgMkSockNode(NULL, &csock, NULL) == -1) {
-		Log(LG_ERR, ("L2TP: NgMkSockNode: %s", strerror(errno)));
+		Perror("L2TP: NgMkSockNode");
 		return;
 	    }
 	
@@ -997,15 +987,13 @@
 		if (pi->conf.callingnum[0]) {
 		   if (ppp_l2tp_avp_list_append(avps, 1, 0, AVP_CALLING_NUMBER,
 	            pi->conf.callingnum, strlen(pi->conf.callingnum)) == -1) {
-			Log(LG_ERR, ("[%s] ppp_l2tp_avp_list_append: %s", 
-			    l->name, strerror(errno)));
+			Perror("[%s] ppp_l2tp_avp_list_append", l->name);
 		   }
 		}
 		if (pi->conf.callednum[0]) {
 		   if (ppp_l2tp_avp_list_append(avps, 1, 0, AVP_CALLED_NUMBER,
 	            pi->conf.callednum, strlen(pi->conf.callednum)) == -1) {
-			Log(LG_ERR, ("[%s] ppp_l2tp_avp_list_append: %s", 
-			    l->name, strerror(errno)));
+			Perror("[%s] ppp_l2tp_avp_list_append", l->name);
 		   }
 		}
 		if ((sess = ppp_l2tp_initiate(tun->ctrl,
@@ -1013,7 +1001,7 @@
 			    Enabled(&pi->conf.options, L2TP_CONF_LENGTH)?1:0,
 			    Enabled(&pi->conf.options, L2TP_CONF_DATASEQ)?1:0,
 			    avps)) == NULL) {
-			Log(LG_ERR, ("ppp_l2tp_initiate: %s", strerror(errno)));
+			Perror("ppp_l2tp_initiate");
 			pi->sess = NULL;
 			pi->tun = NULL;
 			tun->active_sessions--;
@@ -1041,8 +1029,7 @@
 			}
 			if (ppp_l2tp_avp_list_append(avps, 1, 0, AVP_FRAMING_TYPE,
 	        	    &fr, sizeof(fr)) == -1) {
-			        Log(LG_ERR, ("[%s] ppp_l2tp_avp_list_append: %s", 
-			    	    l->name, strerror(errno)));
+			        Perror("[%s] ppp_l2tp_avp_list_append", l->name);
 			}
 		    } else {
 			avps = NULL;
@@ -1128,7 +1115,7 @@
 
 	/* Convert AVP's to friendly form */
 	if ((ptrs = ppp_l2tp_avp_list2ptrs(avps)) == NULL) {
-		Log(LG_ERR, ("L2TP: error decoding AVP list: %s", strerror(errno)));
+		Perror("L2TP: error decoding AVP list");
 		ppp_l2tp_terminate(sess, L2TP_RESULT_ERROR,
 		    L2TP_ERROR_GENERIC, strerror(errno));
 		return;
@@ -1236,7 +1223,7 @@
 	if ((pi->incoming != pi->outcall) && avps != NULL) {
 		/* Convert AVP's to friendly form */
 		if ((ptrs = ppp_l2tp_avp_list2ptrs(avps)) == NULL) {
-			Log(LG_ERR, ("L2TP: error decoding AVP list: %s", strerror(errno)));
+			Perror("L2TP: error decoding AVP list");
 		} else {
 			if (ptrs->framing && ptrs->framing->sync) {
 				pi->sync = 1;
@@ -1320,13 +1307,16 @@
 
 	/* Get a temporary netgraph socket node */
 	if (NgMkSockNode(NULL, &csock, NULL) == -1) {
-		Log(LG_ERR, ("L2TP: NgMkSockNode: %s", strerror(errno)));
+		Perror("L2TP: NgMkSockNode");
 		goto fail;
 	}
 
 	/* Get this link's node and hook */
 	ppp_l2tp_sess_get_hook(pi->sess, &node_id, &hook);
 
+	/* Initialize cn */
+	memset(&cn, 0, sizeof(cn));
+
 	/* Connect our ng_ppp(4) node link hook and ng_l2tp(4) node. */
 	if (!PhysGetUpperHook(l, cn.path, cn.peerhook)) {
 	    Log(LG_PHYS, ("[%s] L2TP: can't get upper hook", l->name));
@@ -1336,8 +1326,8 @@
 	strlcpy(cn.ourhook, hook, sizeof(cn.ourhook));
 	if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, NGM_CONNECT, 
 	    &cn, sizeof(cn)) < 0) {
-		Log(LG_ERR, ("[%s] L2TP: can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-    		    l->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+		Perror("[%s] L2TP: can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+    		    l->name, path, cn.ourhook, cn.path, cn.peerhook);
 		goto fail;
 	}
 	ppp_l2tp_sess_hooked(pi->sess);
@@ -1348,6 +1338,7 @@
 	/* Clean up after failure */
 	ppp_l2tp_terminate(pi->sess, L2TP_RESULT_ERROR,
 	    L2TP_ERROR_GENERIC, strerror(errno));
+	pi->sess = NULL;
 	if (csock != -1)
 		(void)close(csock);
 }
@@ -1395,7 +1386,7 @@
 	sas_len = sizeof(peer_sas);
 	if ((len = recvfrom(s->sock, buf, bufsize, 0,
 	    (struct sockaddr *)&peer_sas, &sas_len)) == -1) {
-		Log(LG_ERR, ("L2TP: recvfrom: %s", strerror(errno)));
+		Perror("L2TP: recvfrom");
 		goto fail;
 	}
 
@@ -1466,7 +1457,7 @@
 	      &cap, sizeof(cap)) == -1) ||
 	    (ppp_l2tp_avp_list_append(avps, 1, 0, AVP_RECEIVE_WINDOW_SIZE,
 	      &win, sizeof(win)) == -1)) {
-		Log(LG_ERR, ("L2TP: ppp_l2tp_avp_list_append: %s", strerror(errno)));
+		Perror("L2TP: ppp_l2tp_avp_list_append");
 		goto fail;
 	}
 
@@ -1476,14 +1467,14 @@
 	    &node_id, hook, avps, 
 	    pi->conf.secret, strlen(pi->conf.secret),
 	    Enabled(&pi->conf.options, L2TP_CONF_HIDDEN))) == NULL) {
-		Log(LG_ERR, ("L2TP: ppp_l2tp_ctrl_create: %s", strerror(errno)));
+		Perror("L2TP: ppp_l2tp_ctrl_create");
 		goto fail;
 	}
 	ppp_l2tp_ctrl_set_cookie(tun->ctrl, tun);
 
 	/* Get a temporary netgraph socket node */
 	if (NgMkSockNode(NULL, &csock, &dsock) == -1) {
-		Log(LG_ERR, ("L2TP: NgMkSockNode: %s", strerror(errno)));
+		Perror("L2TP: NgMkSockNode");
 		goto fail;
 	}
 
@@ -1495,13 +1486,13 @@
 	strlcpy(connect.peerhook, hook, sizeof(connect.peerhook));
 	if (NgSendMsg(csock, ".:", NGM_GENERIC_COOKIE,
 	    NGM_CONNECT, &connect, sizeof(connect)) == -1) {
-		Log(LG_ERR, ("L2TP: %s: %s", "connect", strerror(errno)));
+		Perror("L2TP: connect");
 		goto fail;
 	}
 
 	/* Write the received packet to the node */
 	if (NgSendData(dsock, hook, (u_char *)buf, len) == -1) {
-		Log(LG_ERR, ("L2TP: %s: %s", "NgSendData", strerror(errno)));
+		Perror("L2TP: NgSendData");
 		goto fail;
 	}
 
@@ -1510,7 +1501,7 @@
 	strlcpy(rmhook.ourhook, hook, sizeof(rmhook.ourhook));
 	if (NgSendMsg(csock, ".:", NGM_GENERIC_COOKIE,
 	    NGM_RMHOOK, &rmhook, sizeof(rmhook)) == -1) {
-		Log(LG_ERR, ("L2TP: %s: %s", "rmhook", strerror(errno)));
+		Perror("L2TP: rmhook");
 		goto fail;
 	}
 
@@ -1525,7 +1516,7 @@
 	}
 	if (NgSendMsg(csock, namebuf, NGM_GENERIC_COOKIE,
 	    NGM_MKPEER, &mkpeer, sizeof(mkpeer)) == -1) {
-		Log(LG_ERR, ("L2TP: %s: %s", "mkpeer", strerror(errno)));
+		Perror("L2TP: mkpeer");
 		goto fail;
 	}
 
@@ -1539,13 +1530,13 @@
 	memcpy(sockopt->value, &one, sizeof(int));
 	if (NgSendMsg(csock, namebuf, NGM_KSOCKET_COOKIE,
 	    NGM_KSOCKET_SETOPT, sockopt, sizeof(sockopt_buf)) == -1) {
-		Log(LG_ERR, ("L2TP: setsockopt: %s", strerror(errno)));
+		Perror("L2TP: setsockopt");
 		goto fail;
 	}
 	sockopt->name = SO_REUSEPORT;
 	if (NgSendMsg(csock, namebuf, NGM_KSOCKET_COOKIE,
 	    NGM_KSOCKET_SETOPT, sockopt, sizeof(sockopt_buf)) == -1) {
-		Log(LG_ERR, ("L2TP: setsockopt: %s", strerror(errno)));
+		Perror("L2TP: setsockopt");
 		goto fail;
 	}
 
@@ -1553,7 +1544,7 @@
 	u_addrtosockaddr(&s->self_addr,s->self_port,&sas);
 	if (NgSendMsg(csock, namebuf, NGM_KSOCKET_COOKIE,
 	    NGM_KSOCKET_BIND, &sas, sas.ss_len) == -1) {
-		Log(LG_ERR, ("L2TP: bind: %s", strerror(errno)));
+		Perror("L2TP: bind");
 		goto fail;
 	}
 
@@ -1561,13 +1552,13 @@
 	if (NgSendMsg(csock, namebuf, NGM_KSOCKET_COOKIE,
 	      NGM_KSOCKET_CONNECT, &peer_sas, peer_sas.ss_len) == -1
 	    && errno != EINPROGRESS) {
-		Log(LG_ERR, ("L2TP: connect: %s", strerror(errno)));
+		Perror("L2TP: connect");
 		goto fail;
 	}
 
 	/* Add peer to our hash table */
 	if (ghash_put(gL2tpTuns, tun) == -1) {
-		Log(LG_ERR, ("L2TP: %s: %s", "ghash_put", strerror(errno)));
+		Perror("L2TP: ghash_put");
 		goto fail;
 	}
 
@@ -1635,22 +1626,22 @@
 		s->sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
 	}
 	if (s->sock == -1) {
-		Log(LG_ERR, ("L2TP: socket: %s", strerror(errno)));
+		Perror("L2TP: socket");
 		goto fail;
 	}
 	if (setsockopt(s->sock, SOL_SOCKET,
 	    SO_REUSEADDR, &one, sizeof(one)) == -1) {
-		Log(LG_ERR, ("L2TP: setsockopt: %s", strerror(errno)));
+		Perror("L2TP: setsockopt");
 		goto fail;
 	}
 	if (setsockopt(s->sock, SOL_SOCKET,
 	    SO_REUSEPORT, &one, sizeof(one)) == -1) {
-		Log(LG_ERR, ("L2TP: setsockopt: %s", strerror(errno)));
+		Perror("L2TP: setsockopt");
 		goto fail;
 	}
 	u_addrtosockaddr(&s->self_addr, s->self_port, &sa);
 	if (bind(s->sock, (struct sockaddr *)&sa, sa.ss_len) == -1) {
-		Log(LG_ERR, ("L2TP: bind: %s", strerror(errno)));
+		Perror("L2TP: bind");
 		goto fail;
 	}
 
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/l2tp_ctrl.c
--- a/contrib/mpd/src/l2tp_ctrl.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/l2tp_ctrl.c	Fri Sep 14 02:13:58 2012 +0300
@@ -509,8 +509,7 @@
 
 	/* Get l2tp node ID */
 	if ((ctrl->node_id = NgGetNodeID(ctrl->csock, NG_L2TP_HOOK_CTRL)) == 0) {
-	    Log(LG_ERR, ("L2TP: Cannot get %s node id: %s",
-		NG_L2TP_NODE_TYPE, strerror(errno)));
+	    Perror("L2TP: Cannot get %s node id", NG_L2TP_NODE_TYPE);
 	    goto fail;
 	};
 	snprintf(ctrl->path, sizeof(ctrl->path),
@@ -1142,7 +1141,7 @@
 	if (pevent_register(ctrl->ctx, &ctrl->death_timer, 0,
 	    ctrl->mutex, ppp_l2tp_unused_timeout, ctrl,
 	    PEVENT_TIME, gL2TPto * 1000) == -1) {
-		Log(LOG_ERR, ("L2TP: error starting unused timer: %s", strerror(errno)));
+		Perror("L2TP: error starting unused timer");
 	}
 
 	/* Done */
@@ -1270,7 +1269,7 @@
 
 fail:
 	/* Close up shop */
-	Log(LOG_ERR, ("L2TP: error sending ctrl packet: %s", strerror(errno)));
+	Perror("L2TP: error sending ctrl packet");
 	ppp_l2tp_ctrl_close(ctrl, L2TP_RESULT_ERROR,
 	    L2TP_ERROR_GENERIC, strerror(errno));
 
@@ -1317,7 +1316,7 @@
 		value16 = htons(ctrl->config.tunnel_id);
 		if (ppp_l2tp_avp_list_append(avps, 1, 0,
 		    AVP_ASSIGNED_TUNNEL_ID, &value16, sizeof(value16)) == -1) {
-			Log(LOG_ERR, ("L2TP: %s: %s", "ppp_l2tp_avp_list_append", strerror(errno)));
+			Perror("L2TP: ppp_l2tp_avp_list_append");
 			goto notify_done;
 		}
 
@@ -1330,7 +1329,7 @@
 		memcpy(rbuf + 4, ctrl->errmsg, elen);
 		if (ppp_l2tp_avp_list_append(avps, 1, 0, AVP_RESULT_CODE,
 		    rbuf, 4 + elen) == -1) {
-			Log(LOG_ERR, ("L2TP: %s: %s", "ppp_l2tp_avp_list_append", strerror(errno)));
+			Perror("L2TP: ppp_l2tp_avp_list_append");
 			goto notify_done;
 		}
 
@@ -1357,7 +1356,7 @@
 	/* Start timer to call ppp_l2tp_ctrl_do_close() */
 	if (pevent_register(ctrl->ctx, &ctrl->close_timer, 0, ctrl->mutex,
 	    ppp_l2tp_ctrl_do_close, ctrl, PEVENT_TIME, 0) == -1)
-		Log(LOG_ERR, ("L2TP: error starting close timer: %s", strerror(errno)));
+		Perror("L2TP: error starting close timer");
 }
 
 /*
@@ -1435,7 +1434,7 @@
 	if (pevent_register(ctrl->ctx, &ctrl->death_timer, 0,
 	    ctrl->mutex, ppp_l2tp_ctrl_death_timeout, ctrl,
 	    PEVENT_TIME, L2TP_CTRL_DEATH_TIMEOUT * 1000) == -1)
-		Log(LOG_ERR, ("L2TP: error starting death timer: %s", strerror(errno)));
+		Perror("L2TP: error starting death timer");
 }
 
 /*
@@ -1453,7 +1452,7 @@
 	if (pevent_register(ctrl->ctx, &ctrl->idle_timer, 0,
 	    ctrl->mutex, ppp_l2tp_idle_timeout, ctrl, PEVENT_TIME,
 	    L2TP_IDLE_TIMEOUT * 1000) == -1)
-		Log(LOG_ERR, ("L2TP: error restarting idle timer: %s", strerror(errno)));
+		Perror("L2TP: error restarting idle timer");
 
 	/* Send a 'hello' packet */
 	ppp_l2tp_ctrl_send(ctrl, 0, HELLO, NULL);
@@ -1533,7 +1532,7 @@
 		pevent_unregister(&sess->notify_timer);
 		if (pevent_register(ctrl->ctx, &sess->notify_timer, 0,
 		    ctrl->mutex, ppp_l2tp_sess_notify, sess, PEVENT_TIME, 0) == -1) {
-			Log(LOG_ERR, ("L2TP: error starting notify timer: %s", strerror(errno)));
+			Perror("L2TP: error starting notify timer");
 			goto fail;
 		}
 	}
@@ -1545,15 +1544,14 @@
 	strlcpy(mkpeer.peerhook, NG_TEE_HOOK_LEFT, sizeof(mkpeer.peerhook));
 	if (NgSendMsg(ctrl->csock, NG_L2TP_HOOK_CTRL, NGM_GENERIC_COOKIE,
 	    NGM_MKPEER, &mkpeer, sizeof(mkpeer)) == -1) {
-		Log(LOG_ERR, ("L2TP: %s: %s", "mkpeer", strerror(errno)));
+		Perror("L2TP: mkpeer");
 		goto fail;
 	}
 
 	/* Get ng_tee node ID */
 	snprintf(path, sizeof(path), "%s.%s", NG_L2TP_HOOK_CTRL, sess->hook);
 	if ((sess->node_id = NgGetNodeID(ctrl->csock, path)) == 0) {
-	    Log(LG_ERR, ("L2TP: Cannot get %s node id: %s",
-		NG_TEE_NODE_TYPE, strerror(errno)));
+	    Perror("L2TP: Cannot get %s node id", NG_TEE_NODE_TYPE);
 	    goto fail;
 	};
 
@@ -1570,7 +1568,7 @@
 	if (NgSendMsg(ctrl->csock, NG_L2TP_HOOK_CTRL, NGM_L2TP_COOKIE,
 	    NGM_L2TP_SET_SESS_CONFIG, &sess->config,
 	    sizeof(sess->config)) == -1) {
-		Log(LOG_ERR, ("L2TP: error configuring session hook: %s", strerror(errno)));
+		Perror("L2TP: error configuring session hook");
 		goto fail;
 	}
 
@@ -1620,7 +1618,7 @@
 		value16 = htons(sess->config.session_id);
 		if (ppp_l2tp_avp_list_append(avps, 1, 0,
 		    AVP_ASSIGNED_SESSION_ID, &value16, sizeof(value16)) == -1) {
-			Log(LOG_ERR, ("L2TP: %s: %s", "ppp_l2tp_avp_list_append", strerror(errno)));
+			Perror("L2TP: ppp_l2tp_avp_list_append");
 			goto notify_done;
 		}
 
@@ -1633,7 +1631,7 @@
 		memcpy(rbuf + 4, sess->errmsg, elen);
 		if (ppp_l2tp_avp_list_append(avps, 1, 0, AVP_RESULT_CODE,
 		    rbuf, 4 + elen) == -1) {
-			Log(LOG_ERR, ("L2TP: %s: %s", "ppp_l2tp_avp_list_append", strerror(errno)));
+			Perror("L2TP: ppp_l2tp_avp_list_append");
 			goto notify_done;
 		}
 
@@ -1655,7 +1653,7 @@
 	/* Start timer to call ppp_l2tp_sess_do_close() */
 	if (pevent_register(ctrl->ctx, &sess->close_timer, 0,
 	    ctrl->mutex, ppp_l2tp_sess_do_close, sess, PEVENT_TIME, 0) == -1)
-		Log(LOG_ERR, ("L2TP: error starting close timer: %s", strerror(errno)));
+		Perror("L2TP: error starting close timer");
 }
 
 /*
@@ -1678,7 +1676,7 @@
 	if (pevent_register(ctrl->ctx, &sess->death_timer, 0,
 	    ctrl->mutex, ppp_l2tp_sess_death_timeout, sess, PEVENT_TIME,
 	    L2TP_SESS_DEATH_TIMEOUT * 1000) == -1)
-		Log(LOG_ERR, ("L2TP: error starting death timer: %s", strerror(errno)));
+		Perror("L2TP: error starting death timer");
 
 	/* Notify link side about session if necessary */
 	if (!sess->link_notified) {
@@ -1694,7 +1692,7 @@
 		} else if (pevent_register(ctrl->ctx, &ctrl->death_timer, 0,
 		    ctrl->mutex, ppp_l2tp_unused_timeout, ctrl,
 		    PEVENT_TIME, gL2TPto * 1000) == -1) {
-			Log(LOG_ERR, ("L2TP: error starting unused timer: %s", strerror(errno)));
+			Perror("L2TP: error starting unused timer");
 		}
 	}
 }
@@ -1755,13 +1753,13 @@
 	if (pevent_register(ctrl->ctx, &ctrl->idle_timer, 0,
 	    ctrl->mutex, ppp_l2tp_idle_timeout, ctrl, PEVENT_TIME,
 	    L2TP_IDLE_TIMEOUT * 1000) == -1) {
-		Log(LOG_ERR, ("L2TP: error restarting idle timer: %s", strerror(errno)));
+		Perror("L2TP: error restarting idle timer");
 		goto fail_errno;
 	}
 
 	/* Read packet */
 	if ((len = read(ctrl->dsock, buf, sizeof(buf))) == -1) {
-		Log(LOG_ERR, ("L2TP: error reading ctrl hook: %s", strerror(errno)));
+		Perror("L2TP: error reading ctrl hook");
 		goto fail_errno;
 	}
 
@@ -1790,7 +1788,7 @@
 			    L2TP_ERROR_MANDATORY, NULL);
 			goto done;
 		default:
-			Log(LOG_ERR, ("L2TP: error decoding control message: %s", strerror(errno)));
+			Perror("L2TP: error decoding control message");
 			goto fail_errno;
 		}
 	}
@@ -1847,7 +1845,7 @@
 
 	/* Convert AVP's to friendly form */
 	if ((ptrs = ppp_l2tp_avp_list2ptrs(avps)) == NULL) {
-		Log(LOG_ERR, ("L2TP: error decoding AVP list: %s", strerror(errno)));
+		Perror("L2TP: error decoding AVP list");
 		goto fail_errno;
 	}
 
@@ -1991,7 +1989,7 @@
 
 	/* Read netgraph control message */
 	if (NgRecvMsg(ctrl->csock, msg, sizeof(buf), raddr) < 0) {
-		Log(LOG_ERR, ("L2TP: error reading control message: %s", strerror(errno)));
+		Perror("L2TP: error reading control message");
 		ppp_l2tp_ctrl_close(ctrl, L2TP_RESULT_ERROR,
 		    L2TP_ERROR_GENERIC, strerror(errno));
 		return;
@@ -2322,7 +2320,7 @@
 		if (pevent_register(ctrl->ctx, &ctrl->reply_timer, 0,
 		    ctrl->mutex, ppp_l2tp_ctrl_reply_timeout, ctrl, PEVENT_TIME,
 		    L2TP_REPLY_TIMEOUT * 1000) == -1)
-			Log(LOG_ERR, ("L2TP: error starting reply timer: %s", strerror(errno)));
+			Perror("L2TP: error starting reply timer");
 		break;
 	default:
 		break;
@@ -2341,7 +2339,7 @@
 		if (pevent_register(ctrl->ctx, &sess->reply_timer, 0,
 		    ctrl->mutex, ppp_l2tp_sess_reply_timeout, sess, PEVENT_TIME,
 		    L2TP_REPLY_TIMEOUT * 1000) == -1)
-			Log(LOG_ERR, ("L2TP: error starting reply timer: %s", strerror(errno)));
+			Perror("L2TP: error starting reply timer");
 		break;
 	default:
 		break;
@@ -2450,7 +2448,7 @@
 			} else if (pevent_register(ctrl->ctx, &ctrl->death_timer, 0,
 			    ctrl->mutex, ppp_l2tp_unused_timeout, ctrl,
 			    PEVENT_TIME, gL2TPto * 1000) == -1) {
-				Log(LOG_ERR, ("L2TP: error starting unused timer: %s", strerror(errno)));
+				Perror("L2TP: error starting unused timer");
 			}
 		}
 	}
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/lcp.c
--- a/contrib/mpd/src/lcp.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/lcp.c	Fri Sep 14 02:13:58 2012 +0300
@@ -76,17 +76,17 @@
     { "AUTHPROTO", TY_AUTHPROTO, 2, 255, TRUE },
     { "QUALPROTO", TY_QUALPROTO, 0, 0, FALSE },
     { "MAGICNUM", TY_MAGICNUM, 4, 4, TRUE },
-    { "RESERVED", TY_RESERVED, 0, 0, FALSE },
+    { "RESERVED", TY_RESERVED, 0, 0, FALSE }, /* DEPRECATED */
     { "PROTOCOMP", TY_PROTOCOMP, 0, 0, TRUE },
     { "ACFCOMP", TY_ACFCOMP, 0, 0, TRUE },
     { "FCSALT", TY_FCSALT, 0, 0, FALSE },
     { "SDP", TY_SDP, 0, 0, FALSE },
     { "NUMMODE", TY_NUMMODE, 0, 0, FALSE },
-    { "MULTILINK", TY_MULTILINK, 0, 0, FALSE },
+    { "MULTILINK", TY_MULTILINK, 0, 0, FALSE }, /* DEPRECATED */
     { "CALLBACK", TY_CALLBACK, 1, 255, TRUE },
-    { "CONNECTTIME", TY_CONNECTTIME, 0, 0, FALSE },
-    { "COMPFRAME", TY_COMPFRAME, 0, 0, FALSE },
-    { "NDS", TY_NDS, 0, 0, FALSE },
+    { "CONNECTTIME", TY_CONNECTTIME, 0, 0, FALSE }, /* DEPRECATED */
+    { "COMPFRAME", TY_COMPFRAME, 0, 0, FALSE }, /* DEPRECATED */
+    { "NDS", TY_NDS, 0, 0, FALSE }, /* DEPRECATED */
     { "MP MRRU", TY_MRRU, 2, 2, TRUE },
     { "MP SHORTSEQ", TY_SHORTSEQNUM, 0, 0, TRUE },
     { "ENDPOINTDISC", TY_ENDPOINTDISC, 1, 255, TRUE },
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/link.c
--- a/contrib/mpd/src/link.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/link.c	Fri Sep 14 02:13:58 2012 +0300
@@ -160,8 +160,7 @@
     /* Create a netgraph socket node */
     snprintf(name, sizeof(name), "mpd%d-lso", gPid);
     if (NgMkSockNode(name, &gLinksCsock, &gLinksDsock) < 0) {
-	Log(LG_ERR, ("LinksInit(): can't create %s node: %s",
-    	    NG_SOCKET_NODE_TYPE, strerror(errno)));
+	Perror("LinksInit(): can't create %s node", NG_SOCKET_NODE_TYPE);
 	return(-1);
     }
     (void) fcntl(gLinksCsock, F_SETFD, 1);
@@ -540,7 +539,8 @@
     SLIST_INIT(&l->actions);
     SLIST_FOREACH(at, &lt->actions, next) {
 	a = Mdup(MB_AUTH, at, sizeof(*a));
-	regcomp(&a->regexp, a->regex, REG_EXTENDED);
+	if (a->regex[0])
+	    regcomp(&a->regexp, a->regex, REG_EXTENDED);
 	if (!ap)
 	    SLIST_INSERT_HEAD(&l->actions, a, next);
 	else
@@ -653,14 +653,18 @@
     struct ngm_mkpeer	mp;
     struct ngm_name	nm;
 
+    /* Initialize structures */
+    memset(&mp, 0, sizeof(mp));
+    memset(&nm, 0, sizeof(nm));
+
     /* Create TEE node */
     strcpy(mp.type, NG_TEE_NODE_TYPE);
     snprintf(mp.ourhook, sizeof(mp.ourhook), "l%d", l->id);
     strcpy(mp.peerhook, NG_TEE_HOOK_LEFT2RIGHT);
     if (NgSendMsg(gLinksCsock, ".:",
       NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
-	Log(LG_ERR, ("[%s] can't create %s node at \"%s\"->\"%s\": %s",
-    	    l->name, mp.type, ".:", mp.ourhook, strerror(errno)));
+	Perror("[%s] can't create %s node at \"%s\"->\"%s\"",
+	    l->name, mp.type, ".:", mp.ourhook);
 	goto fail;
     }
     strlcpy(l->hook, mp.ourhook, sizeof(l->hook));
@@ -669,15 +673,14 @@
     snprintf(nm.name, sizeof(nm.name), "mpd%d-%s-lt", gPid, l->name);
     if (NgSendMsg(gLinksCsock, l->hook,
       NGM_GENERIC_COOKIE, NGM_NAME, &nm, sizeof(nm)) < 0) {
-	Log(LG_ERR, ("[%s] can't name %s node \"%s\": %s",
-    	    l->name, NG_TEE_NODE_TYPE, l->hook, strerror(errno)));
+	Perror("[%s] can't name %s node \"%s\"",
+	    l->name, NG_TEE_NODE_TYPE, l->hook);
 	goto fail;
     }
 
     /* Get TEE node ID */
     if ((l->nodeID = NgGetNodeID(gLinksCsock, l->hook)) == 0) {
-	Log(LG_ERR, ("[%s] Cannot get %s node id: %s",
-	    l->name, NG_TEE_NODE_TYPE, strerror(errno)));
+	Perror("[%s] Cannot get %s node id", l->name, NG_TEE_NODE_TYPE);
 	goto fail;
     };
 
@@ -701,14 +704,15 @@
 
     snprintf(path, sizeof(path), "[%lx]:", (u_long)l->nodeID);
 
+    memset(&cn, 0, sizeof(cn));
     snprintf(cn.path, sizeof(cn.path), "[%lx]:", (u_long)l->bund->nodeID);
     strcpy(cn.ourhook, NG_TEE_HOOK_RIGHT);
     snprintf(cn.peerhook, sizeof(cn.peerhook), "%s%d", 
 	NG_PPP_HOOK_LINK_PREFIX, l->bundleIndex);
     if (NgSendMsg(gLinksCsock, path,
       NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
-	Log(LG_ERR, ("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-    	    l->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+	Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+	    l->name, path, cn.ourhook, cn.path, cn.peerhook);
 	return(-1);
     }
     
@@ -726,13 +730,14 @@
     char		path[NG_PATHSIZ];
     struct ngm_connect	cn;
 
+    memset(&cn, 0, sizeof(cn));
     snprintf(cn.path, sizeof(cn.path), "[%lx]:", (u_long)l->nodeID);
     strcpy(cn.ourhook, l->hook);
     strcpy(cn.peerhook, NG_TEE_HOOK_LEFT2RIGHT);
     if (NgSendMsg(gLinksCsock, ".:",
       NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
-	Log(LG_ERR, ("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-    	    l->name, ".:", cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+	Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+	    l->name, ".:", cn.ourhook, cn.path, cn.peerhook);
 	return(-1);
     }
 
@@ -760,8 +765,8 @@
     }
     if (NgSendMsg(gLinksCsock, path,
       NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
-	Log(LG_ERR, ("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-    	    l->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+	Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+	    l->name, path, cn.ourhook, cn.path, cn.peerhook);
 	return(-1);
     }
 
@@ -1438,7 +1443,7 @@
 		        strlcpy(n->regex, av[1], sizeof(n->regex));
 		        if (regcomp(&n->regexp, n->regex, REG_EXTENDED)) {
 		    	    Freee(n);
-			    Error("regexp \"%s\" compilation error", av[0]);
+			    Error("regexp \"%s\" compilation error", av[1]);
 			}
 		    }
 		} else {
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/main.c
--- a/contrib/mpd/src/main.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/main.c	Fri Sep 14 02:13:58 2012 +0300
@@ -233,9 +233,8 @@
 #ifdef CCP_MPPC
     MppcTestCap();
 #endif
-    LinksInit();
-    CcpsInit();
-    EcpsInit();
+    if ((LinksInit() != 0) || (CcpsInit() != 0) || (EcpsInit() != 0))
+	exit(EX_UNAVAILABLE);
     
     /* Init device types. */
     for (k = 0; (pt = gPhysTypes[k]); k++) {
@@ -397,6 +396,7 @@
     LinksShutdown();
 
     /* Remove our PID file and exit */
+    ConsoleShutdown(&gConsole);
     Log(LG_ALWAYS, ("process %d terminated", gPid));
     LogClose();
     (void) unlink(gPidFile);
@@ -660,7 +660,7 @@
     char		buf[100];
     size_t		k;
 
-    fprintf(stderr, "Usage: mpd %s\n", UsageStr);
+    fprintf(stderr, "Usage: mpd5 %s\n", UsageStr);
     fprintf(stderr, "Options:\n");
     for (k = 0; k < OPTLIST_SIZE; k++) {
 	opt = OptList + k;
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/mbuf.h
--- a/contrib/mpd/src/mbuf.h	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/mbuf.h	Fri Sep 14 02:13:58 2012 +0300
@@ -55,6 +55,8 @@
   #define MB_PPTP	"PPTP"
   #define MB_RADIUS	"RADIUS"
   #define MB_RADSRV	"RADSRV"
+  #define MB_ACL	"ACL_BPF"
+  #define MB_IPFW	"ACL_IPFW"
   #define MB_UTIL	"UTIL"
   #define MB_VJCOMP	"VJCOMP"
   #define MB_IPPOOL	"IPPOOL"
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/modem.c
--- a/contrib/mpd/src/modem.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/modem.c	Fri Sep 14 02:13:58 2012 +0300
@@ -216,11 +216,14 @@
     m->opened = TRUE;
     if (m->fd >= 0) {			/* Device is already open.. */
 	if (m->answering) {			/* We just answered a call */
-    	    m->originated = FALSE;
-    	    m->answering = FALSE;
-    	    ModemChatConnectResult(l, TRUE, NULL);
-	} else
-    	    ModemDoClose(l, TRUE);		/* Stop idle script then dial back */
+	    m->originated = FALSE;
+	    m->answering = FALSE;
+	    ModemChatConnectResult(l, TRUE, NULL);
+	} else {
+	    Log(LG_PHYS2, ("[%s] MODEM: Stop idle script then dial back",
+	      l->name));
+	    ModemDoClose(l, TRUE);		/* Stop idle script then dial back */
+	}
     } else
 	ModemStart(l);			/* Open device and try to dial */
 }
@@ -249,17 +252,20 @@
     /* Avoid brief hang from kernel enforcing minimum DTR hold time */
     if (now - m->lastClosed < MODEM_MIN_CLOSE_TIME) {
 	TimerInit(&m->startTimer, "ModemStart",
-    	  (MODEM_MIN_CLOSE_TIME - (now - m->lastClosed)) * SECONDS, ModemStart, l);
+	  (MODEM_MIN_CLOSE_TIME - (now - m->lastClosed)) * SECONDS, ModemStart, l);
 	TimerStart(&m->startTimer);
 	return;
     }
 
     /* Open and configure serial port */
-    if ((m->fd = OpenSerialDevice(l->name, m->device, m->speed)) < 0)
-        goto fail;
-
+    if ((m->fd = OpenSerialDevice(l->name, m->device, m->speed)) < 0) {
+	Log(LG_ERR, ("[%s] MODEM: Fail to open serial port %s on speed %d",
+	  l->name, m->device, m->speed));
+	goto fail;
+    }
     /* If connecting, but no connect script, then skip chat altogether */
     if (m->opened && !*m->connScript) {
+	Log(LG_PHYS2, ("[%s] MODEM: No connect script present", l->name));
 	ModemChatConnectResult(l, TRUE, NULL);
 	return;
     }
@@ -283,8 +289,8 @@
     if (l->lcp.auth.conf.password[0] != 0) {
 	ChatPresetVar(m->chat, CHAT_VAR_PASSWORD, l->lcp.auth.conf.password);
     } else if (AuthGetData(l->lcp.auth.conf.authname,
-        password, sizeof(password), NULL, NULL) >= 0) {
-    	    ChatPresetVar(m->chat, CHAT_VAR_PASSWORD, password);
+	password, sizeof(password), NULL, NULL) >= 0) {
+	    ChatPresetVar(m->chat, CHAT_VAR_PASSWORD, password);
     }
 
     /* Run connect or idle script as appropriate */
@@ -323,10 +329,10 @@
 	return;		/* nothing needs to be done right now */
     if (m->fd >= 0 &&
       (!*m->idleScript || !Enabled(&l->conf.options, LINK_CONF_INCOMING)))
-        ModemDoClose(l, FALSE);
+	ModemDoClose(l, FALSE);
     else if (m->fd < 0 &&
       (*m->idleScript && Enabled(&l->conf.options, LINK_CONF_INCOMING)))
-        ModemStart(l);
+	ModemStart(l);
 }
 
 /*
@@ -374,17 +380,16 @@
 static int
 ModemSetAccm(Link l, u_int32_t xmit, u_int32_t recv)
 {
-    ModemInfo		const m = (ModemInfo) l->info;
-    char       		path[NG_PATHSIZ];
+    ModemInfo	const m = (ModemInfo) l->info;
+    char	path[NG_PATHSIZ];
 
     /* Update async config */
     m->acfg.accm = xmit|recv;
     snprintf(path, sizeof(path), "%s:%s", m->ttynode, NG_TTY_HOOK);
     if (NgSendMsg(m->csock, path, NGM_ASYNC_COOKIE,
       NGM_ASYNC_CMD_SET_CONFIG, &m->acfg, sizeof(m->acfg)) < 0) {
-	Log(LG_PHYS, ("[%s] MODEM: can't update config for %s: %s",
-    	    l->name, path, strerror(errno)));
-        return (-1);
+	Perror("[%s] MODEM: can't update config for %s", l->name, path);
+	return (-1);
     }
     return (0);
 }
@@ -416,9 +421,8 @@
 
     /* Set modem's reported connection speed (if any) as the link bandwidth */
     if ((cspeed = ChatGetVar(m->chat, CHAT_VAR_CONNECT_SPEED)) != NULL) {
-	if ((bw = (int) strtoul(cspeed, NULL, 10)) > 0) {
+	if ((bw = (int) strtoul(cspeed, NULL, 10)) > 0)
 	    l->bandwidth = bw;
-	}
 	Freee(cspeed);
     }
 
@@ -453,7 +457,7 @@
 static void
 ModemChatIdleResult(void *arg, int result, const char *msg)
 {
-    Link		const l = (Link) arg;
+    Link	const l = (Link) arg;
     ModemInfo	const m = (ModemInfo) l->info;
     char	*idleResult;
 
@@ -466,7 +470,7 @@
     /* See what script wants us to do now by checking variable $IdleResult */
     if ((idleResult = ChatGetVar(m->chat, CHAT_VAR_IDLE_RESULT)) == NULL) {
 	Log(LG_ERR, ("[%s] MODEM: idle script succeeded, but %s not defined",
-    	    l->name, CHAT_VAR_IDLE_RESULT));
+	    l->name, CHAT_VAR_IDLE_RESULT));
 	ModemDoClose(l, FALSE);
 	return;
     }
@@ -476,23 +480,23 @@
 	l->name, idleResult));
 
     if (gShutdownInProgress) {
-        Log(LG_PHYS, ("Shutdown sequence in progress, ignoring"));
+	Log(LG_PHYS, ("Shutdown sequence in progress, ignoring"));
 	ModemDoClose(l, FALSE);
     } else if (strcasecmp(idleResult, MODEM_IDLE_RESULT_ANSWER) == 0) {
-        Log(LG_PHYS, ("[%s] MODEM: opening link in %s mode", l->name, "answer"));
-        RecordLinkUpDownReason(NULL, l, 1, STR_INCOMING_CALL, msg ? "%s" : NULL, msg);
-        m->answering = TRUE;
-        l->state = PHYS_STATE_READY;
-        PhysIncoming(l);
+	Log(LG_PHYS, ("[%s] MODEM: opening link in %s mode", l->name, "answer"));
+	RecordLinkUpDownReason(NULL, l, 1, STR_INCOMING_CALL, msg ? "%s" : NULL, msg);
+	m->answering = TRUE;
+	l->state = PHYS_STATE_READY;
+	PhysIncoming(l);
     } else if (strcasecmp(idleResult, MODEM_IDLE_RESULT_RINGBACK) == 0) {
-        Log(LG_PHYS, ("[%s] MODEM: opening link in %s mode", l->name, "ringback"));
-        RecordLinkUpDownReason(NULL, l, 1, STR_RINGBACK, msg ? "%s" : NULL, msg);
-        m->answering = FALSE;
-        PhysIncoming(l);
+	Log(LG_PHYS, ("[%s] MODEM: opening link in %s mode", l->name, "ringback"));
+	RecordLinkUpDownReason(NULL, l, 1, STR_RINGBACK, msg ? "%s" : NULL, msg);
+	m->answering = FALSE;
+	PhysIncoming(l);
     } else {
-        Log(LG_ERR, ("[%s] MODEM: idle script succeeded, but action \"%s\" unknown",
-    	  l->name, idleResult));
-        ModemDoClose(l, FALSE);
+	Log(LG_ERR, ("[%s] MODEM: idle script succeeded, but action \"%s\" unknown",
+	  l->name, idleResult));
+	ModemDoClose(l, FALSE);
     }
     Freee(idleResult);
 }
@@ -524,9 +528,9 @@
 #endif
 
     /* Get a temporary netgraph socket node */
-    if (NgMkSockNode(NULL, &m->csock, NULL) == -1) {
-    	Log(LG_ERR, ("MODEM: NgMkSockNode: %s", strerror(errno)));
-    	return(-1);
+    if (NgMkSockNode(NULL, &m->csock, NULL) < 0) {
+	Perror("[%s] MODEM: NgMkSockNode failed", l->name);
+	return(-1);
     }
 
 #if NGM_TTY_COOKIE < 1226109660
@@ -534,24 +538,24 @@
     if (ioctl(m->fd, TIOCSETD, &ldisc) < 0) {
 
 	/* Installation of the tty node type should be automatic, but isn't yet.
-    	   The 'mkpeer' below will fail, because you can only create a ng_tty
+	   The 'mkpeer' below will fail, because you can only create a ng_tty
            node via TIOCSETD; however, this will force a load of the node type. */
 	if (errno == ENODEV) {
-    	    (void)NgSendAsciiMsg(m->csock, ".:",
+	    (void)NgSendAsciiMsg(m->csock, ".:",
 		"mkpeer { type=\"%s\" ourhook=\"dummy\" peerhook=\"%s\" }",
 		NG_TTY_NODE_TYPE, NG_TTY_HOOK);
 	}
 	if (ioctl(m->fd, TIOCSETD, &ldisc) < 0) {
-    	    Log(LG_ERR, ("[%s] ioctl(TIOCSETD, %d): %s",
-		l->name, ldisc, strerror(errno))); 
-    	    close(m->csock);
-    	    return(-1);
+	    Perror("[%s] ioctl(TIOCSETD, %d)", l->name, ldisc);
+	    close(m->csock);
+	    return(-1);
 	}
     }
 
     /* Get the name of the ng_tty node */
     if (ioctl(m->fd, NGIOCGINFO, &ngtty) < 0) {
-	Log(LG_ERR, ("[%s] MODEM: ioctl(NGIOCGINFO): %s", l->name, strerror(errno))); 
+	Perror("[%s] MODEM: ioctl(NGIOCGINFO)", l->name);
+	close(m->csock);
 	return(-1);
     }
     strlcpy(m->ttynode, ngtty.name, sizeof(m->ttynode));
@@ -561,18 +565,18 @@
     snprintf(ngm.ourhook, sizeof(ngm.ourhook), "%s", NG_TTY_HOOK);
     snprintf(ngm.peerhook, sizeof(ngm.peerhook), "%s", NG_TTY_HOOK);
     if (NgSendMsg(m->csock, ".", NGM_GENERIC_COOKIE,
-    	    NGM_MKPEER, &ngm, sizeof(ngm)) < 0) {
-        Log(LG_ERR, ("[%s] MODEM: can't connect %s node on %s", l->name,
-    	    NG_TTY_NODE_TYPE, "."));
-        close(m->csock);
+	    NGM_MKPEER, &ngm, sizeof(ngm)) < 0) {
+	Perror("[%s] MODEM: can't connect %s node on %s", l->name,
+	    NG_TTY_NODE_TYPE, ".");
+	close(m->csock);
 	return(-1);
     }
     snprintf(path, sizeof(path), ".:%s", NG_TTY_HOOK);
     if (NgSendMsg(m->csock, path,
 	    NGM_GENERIC_COOKIE, NGM_NODEINFO, NULL, 0) != -1) {
-        if (NgRecvMsg(m->csock, reply, sizeof(repbuf), NULL) < 0) {
-            Log(LG_ERR, ("[%s] MODEM: can't locate %s node on %s (%d)", l->name,
-        	NG_TTY_NODE_TYPE, path, errno));
+	if (NgRecvMsg(m->csock, reply, sizeof(repbuf), NULL) < 0) {
+	    Perror("[%s] MODEM: can't locate %s node on %s (%d)", l->name,
+	    NG_TTY_NODE_TYPE, path, errno);
 	    close(m->csock);
 	    return(-1);
 	}
@@ -583,18 +587,17 @@
     tty[1] = m->fd;
     if (NgSendMsg(m->csock, path, NGM_TTY_COOKIE,
           NGM_TTY_SET_TTY, &tty, sizeof(tty)) < 0) {
-        Log(LG_ERR, ("[%s] MODEM: can't hook tty to fd %d", l->name, m->fd));
-        close(m->csock);
+	Perror("[%s] MODEM: can't hook tty to fd %d", l->name, m->fd);
+	close(m->csock);
 	return(-1);
     }
     /* Disconnect temporary hook. */
     snprintf(rm.ourhook, sizeof(rm.ourhook), "%s", NG_TTY_HOOK);
     if (NgSendMsg(m->csock, ".",
-    	    NGM_GENERIC_COOKIE, NGM_RMHOOK, &rm, sizeof(rm)) < 0) {
-        Log(LG_ERR, ("[%s] MODEM: can't remove hook %s: %s", l->name,
-	    NG_TTY_HOOK, strerror(errno)));
-    	close(m->csock);
-    	return(-1);
+	    NGM_GENERIC_COOKIE, NGM_RMHOOK, &rm, sizeof(rm)) < 0) {
+	Perror("[%s] MODEM: can't remove hook %s", l->name, NG_TTY_HOOK);
+	close(m->csock);
+	return(-1);
     }
 #endif
 
@@ -602,7 +605,7 @@
     snprintf(path, sizeof(path), "%s:", m->ttynode);
     if (NgSendMsg(m->csock, path, NGM_TTY_COOKIE,
       NGM_TTY_SET_HOTCHAR, &hotchar, sizeof(hotchar)) < 0) {
-	Log(LG_ERR, ("[%s] MODEM: can't set hotchar", l->name));
+	Perror("[%s] MODEM: can't set hotchar", l->name);
 	close(m->csock);
 	return(-1);
     }
@@ -613,7 +616,7 @@
     strcpy(ngm.peerhook, NG_ASYNC_HOOK_ASYNC);
     if (NgSendMsg(m->csock, path, NGM_GENERIC_COOKIE,
       NGM_MKPEER, &ngm, sizeof(ngm)) < 0) {
-	Log(LG_ERR, ("[%s] MODEM: can't connect %s node", l->name, NG_ASYNC_NODE_TYPE));
+	Perror("[%s] MODEM: can't connect %s node", l->name, NG_ASYNC_NODE_TYPE);
 	close(m->csock);
 	return(-1);
     }
@@ -627,24 +630,24 @@
     m->acfg.smru = MODEM_MTU;
     if (NgSendMsg(m->csock, path, NGM_ASYNC_COOKIE,
       NGM_ASYNC_CMD_SET_CONFIG, &m->acfg, sizeof(m->acfg)) < 0) {
-	Log(LG_ERR, ("[%s] MODEM: can't config %s", l->name, path));
+	Perror("[%s] MODEM: can't config %s", l->name, path);
 	close(m->csock);
 	return(-1);
     }
 
     /* Attach async node to PPP node */
     if (!PhysGetUpperHook(l, cn.path, cn.peerhook)) {
-        Log(LG_PHYS, ("[%s] MODEM: can't get upper hook", l->name));
+	Log(LG_PHYS, ("[%s] MODEM: can't get upper hook", l->name));
 	close(m->csock);
 	return (-1);
     }
     snprintf(cn.ourhook, sizeof(cn.ourhook), NG_ASYNC_HOOK_SYNC);
     if (NgSendMsg(m->csock, path, NGM_GENERIC_COOKIE, NGM_CONNECT, 
         &cn, sizeof(cn)) < 0) {
-    	    Log(LG_ERR, ("[%s] MODEM: can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-	        l->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
-	    close(m->csock);
-	    return (-1);
+	Perror("[%s] MODEM: can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+	    l->name, path, cn.ourhook, cn.path, cn.peerhook);
+	close(m->csock);
+	return (-1);
     }
 
     return(0);
@@ -667,18 +670,15 @@
 
     /* Change baud rate */
     if (tcgetattr(m->fd, &attr) < 0) {
-	Log(LG_ERR, ("[%s] MODEM: can't tcgetattr \"%s\": %s",
-    	    l->name, m->device, strerror(errno)));
+	Perror("[%s] MODEM: can't tcgetattr \"%s\"", l->name, m->device);
 	return(-1);
     }
     if (cfsetspeed(&attr, (speed_t) baud) < 0) {
-	Log(LG_ERR, ("[%s] MODEM: can't set speed %d: %s",
-    	    l->name, baud, strerror(errno)));
+	Perror("[%s] MODEM: can't set speed %d", l->name, baud);
 	return(-1);
     }
     if (tcsetattr(m->fd, TCSANOW, &attr) < 0) {
-	Log(LG_ERR, ("[%s] MODEM: can't tcsetattr \"%s\": %s",
-    	    l->name, m->device, strerror(errno)));
+	Perror("[%s] MODEM: can't tcsetattr \"%s\"", l->name, m->device);
 	return(-1);
     }
     return(0);
@@ -708,8 +708,7 @@
     int		state;
 
     if (ioctl(m->fd, TIOCMGET, &state) < 0) {
-	Log(LG_ERR, ("[%s] MODEM: can't ioctl(%s) %s: %s",
-    	    l->name, "TIOCMGET", m->device, strerror(errno)));
+	Perror("[%s] MODEM: can't ioctl(TIOCMGET) %s", l->name, m->device);
 	l->state = PHYS_STATE_DOWN;
 	ModemDoClose(l, FALSE);
 	PhysDown(l, STR_ERROR, strerror(errno));
@@ -750,12 +749,11 @@
     snprintf(path, sizeof(path), "%s:%s", m->ttynode, NG_TTY_HOOK);
     if (ModemGetNgStats(l, &stats) >= 0
       && (stats.asyncBadCheckSums
-       || stats.asyncRunts || stats.asyncOverflows)) {
-	Log(LG_PHYS, ("[%s] NEW FRAME ERRS: FCS %u RUNT %u OVFL %u",
-        l->name, stats.asyncBadCheckSums,
-        stats.asyncRunts, stats.asyncOverflows));
+      || stats.asyncRunts || stats.asyncOverflows)) {
+	Log(LG_PHYS, ("[%s] NEW FRAME ERRS: FCS %u RUNT %u OVFL %u", l->name,
+          stats.asyncBadCheckSums, stats.asyncRunts, stats.asyncOverflows));
 	(void) NgSendMsg(m->csock, path,
-    	    NGM_ASYNC_COOKIE, NGM_ASYNC_CMD_CLR_STATS, NULL, 0);
+	    NGM_ASYNC_COOKIE, NGM_ASYNC_CMD_CLR_STATS, NULL, 0);
     }
 
     /* Restart timer */
@@ -770,7 +768,7 @@
 static int
 ModemGetNgStats(Link l, struct ng_async_stat *sp)
 {
-    ModemInfo           const m = (ModemInfo) l->info;
+    ModemInfo		const m = (ModemInfo) l->info;
     char		path[NG_PATHSIZ];
     union {
 	u_char		buf[sizeof(struct ng_mesg) + sizeof(*sp)];
@@ -781,7 +779,7 @@
     snprintf(path, sizeof(path), "%s:%s", m->ttynode, NG_TTY_HOOK);
     if (NgFuncSendQuery(path, NGM_ASYNC_COOKIE, NGM_ASYNC_CMD_GET_STATS,
       NULL, 0, &u.resp, sizeof(u), NULL) < 0) {
-	Log(LG_ERR, ("[%s] MODEM: can't get stats: %s", l->name, strerror(errno)));
+	Perror("[%s] MODEM: can't get stats", l->name);
 	return(-1);
     }
 
@@ -801,11 +799,11 @@
 
     switch ((intptr_t)arg) {
 	case SET_DEVICE:
-    	    if (ac == 1)
+	    if (ac == 1)
 		strlcpy(m->device, av[0], sizeof(m->device));
-    	    break;
+	    break;
 	case SET_SPEED:
-    	    {
+	    {
 		int	k, baud;
 
 		if (ac != 1)
@@ -821,46 +819,46 @@
 		    snprintf(buf, sizeof(buf), "%d", m->speed);
 		    ChatPresetVar(m->chat, CHAT_VAR_BAUDRATE, buf);
 		}
-    	    }
-    	    break;
+	    }
+	    break;
 	case SET_CSCRIPT:
-    	    if (ac != 1)
+	    if (ac != 1)
 		return(-1);
-    	    *m->connScript = 0;
-    	    strlcpy(m->connScript, av[0], sizeof(m->connScript));
-    	    break;
+	    *m->connScript = 0;
+	    strlcpy(m->connScript, av[0], sizeof(m->connScript));
+	    break;
 	case SET_ISCRIPT:
-    	    if (ac != 1)
+	    if (ac != 1)
 		return(-1);
-    	    *m->idleScript = 0;
-    	    strlcpy(m->idleScript, av[0], sizeof(m->idleScript));
-    	    if (m->opened || TimerRemain(&m->startTimer) >= 0)
+	    *m->idleScript = 0;
+	    strlcpy(m->idleScript, av[0], sizeof(m->idleScript));
+	    if (m->opened || TimerRemain(&m->startTimer) >= 0)
 		break;		/* nothing needs to be done right now */
-    	    if (m->fd >= 0 && !*m->idleScript)
-	        ModemDoClose(l, FALSE);
-    	    else if (m->fd < 0 && *m->idleScript)
-	        ModemStart(l);
-    	    break;
+	    if (m->fd >= 0 && !*m->idleScript)
+		ModemDoClose(l, FALSE);
+	    else if (m->fd < 0 && *m->idleScript)
+		ModemStart(l);
+	    break;
 	case SET_SCRIPT_VAR:
-    	    if (ac != 2)
+	    if (ac != 2)
 		return(-1);
-    	    ChatPresetVar(m->chat, av[0], av[1]);
-    	    break;
+	    ChatPresetVar(m->chat, av[0], av[1]);
+	    break;
 	case SET_WATCH:
-    	    {
+	    {
 		int	bit, add;
 
 		while (ac--) {
 		    switch (**av) {
 			case '+':
-	    		    (*av)++;
+			    (*av)++;
 			default:
-	    		    add = TRUE;
-	    		    break;
+			    add = TRUE;
+			    break;
 			case '-':
-	    		    add = FALSE;
-	    		    (*av)++;
-	    		    break;
+			    add = FALSE;
+			    (*av)++;
+			    break;
 		    }
 		    if (!strcasecmp(*av, "cd"))
 			bit = TIOCM_CAR;
@@ -876,10 +874,10 @@
 			m->watch &= ~bit;
 		    av++;
 		}
-    	    }
-    	    break;
+	    }
+	    break;
 	default:
-    	    assert(0);
+	    assert(0);
     }
     return(0);
 }
@@ -995,17 +993,16 @@
 	}
 
 	if (ctx->lnk->state == PHYS_STATE_UP && 
-    		ModemGetNgStats(ctx->lnk, &stats) >= 0) {
-    	    Printf("Async stats:\r\n");
-    	    Printf("\t       syncOctets: %8u\r\n", stats.syncOctets);
-    	    Printf("\t       syncFrames: %8u\r\n", stats.syncFrames);
-    	    Printf("\t    syncOverflows: %8u\r\n", stats.syncOverflows);
+		ModemGetNgStats(ctx->lnk, &stats) >= 0) {
+	    Printf("Async stats:\r\n");
+	    Printf("\t       syncOctets: %8u\r\n", stats.syncOctets);
+	    Printf("\t       syncFrames: %8u\r\n", stats.syncFrames);
+	    Printf("\t    syncOverflows: %8u\r\n", stats.syncOverflows);
 	    Printf("\t      asyncOctets: %8u\r\n", stats.asyncOctets);
-    	    Printf("\t      asyncFrames: %8u\r\n", stats.asyncFrames);
-    	    Printf("\t       asyncRunts: %8u\r\n", stats.asyncRunts);
-    	    Printf("\t   asyncOverflows: %8u\r\n", stats.asyncOverflows);
-    	    Printf("\tasyncBadCheckSums: %8u\r\n", stats.asyncBadCheckSums);
-        }
+	    Printf("\t      asyncFrames: %8u\r\n", stats.asyncFrames);
+	    Printf("\t       asyncRunts: %8u\r\n", stats.asyncRunts);
+	    Printf("\t   asyncOverflows: %8u\r\n", stats.asyncOverflows);
+	    Printf("\tasyncBadCheckSums: %8u\r\n", stats.asyncBadCheckSums);
+	}
     }
 }
-
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/msg.c
--- a/contrib/mpd/src/msg.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/msg.c	Fri Sep 14 02:13:58 2012 +0300
@@ -138,7 +138,7 @@
     SETOVERLOAD(QUEUELEN());
 
     if (!msgpipesent) {
-	char	buf[1];
+	char	buf[1] = { 0x2a };
 	if (write(msgpipe[PIPE_WRITE], buf, 1) > 0)
 	    msgpipesent = 1;
     }
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/nat.h
--- a/contrib/mpd/src/nat.h	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/nat.h	Fri Sep 14 02:13:58 2012 +0300
@@ -11,8 +11,11 @@
 #include <netgraph/ng_nat.h>
 
 #ifdef NG_NAT_DESC_LENGTH
+/* max. number of red-port rules */
 #define NM_PORT		16
+/* max. number of red-addr rules */
 #define NM_ADDR		8
+/* max. number of red-proto rules */
 #define NM_PROTO	8
 #endif
 
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/ng.c
--- a/contrib/mpd/src/ng.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/ng.c	Fri Sep 14 02:13:58 2012 +0300
@@ -117,16 +117,15 @@
     
     /* Get a temporary netgraph socket node */
     if (NgMkSockNode(NULL, &csock, NULL) == -1) {
-	Log(LG_ERR, ("[%s] NG: NgMkSockNode: %s", 
-	    l->name, strerror(errno)));
+	Perror("[%s] NG: NgMkSockNode", l->name);
 	goto fail;
     }
 
     strlcpy(cn.path, ng->path, sizeof(cn.path));
     strlcpy(cn.peerhook, ng->hook, sizeof(cn.peerhook));
     if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
-	Log(LG_ERR, ("[%s] NG: can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-    	    l->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+	Perror("[%s] NG: can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+	    l->name, path, cn.ourhook, cn.path, cn.peerhook);
 	goto fail;
     }
     
@@ -156,8 +155,7 @@
 
     /* Get a temporary netgraph socket node */
     if (NgMkSockNode(NULL, &csock, NULL) == -1) {
-	Log(LG_ERR, ("[%s] NG: NgMkSockNode: %s", 
-	    l->name, strerror(errno)));
+	Perror("[%s] NG: NgMkSockNode", l->name);
 	goto fail;
     }
 
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/ngfunc.c
--- a/contrib/mpd/src/ngfunc.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/ngfunc.c	Fri Sep 14 02:13:58 2012 +0300
@@ -44,6 +44,10 @@
 #endif
 #ifdef USE_NG_NETFLOW
 #include <netgraph/netflow/ng_netflow.h>
+#if NGM_NETFLOW_COOKIE >= 1309868867
+#include <netgraph/netflow/netflow.h>
+#include <netgraph/netflow/netflow_v9.h>
+#endif
 #endif
 #ifdef USE_NG_PRED1
 #include <netgraph/ng_pred1.h>
@@ -64,6 +68,11 @@
     SET_PEER,
     SET_SELF,
     SET_TIMEOUTS,
+#if NGM_NETFLOW_COOKIE >= 1309868867
+    SET_TEMPLATE,
+    SET_MTU,
+    SET_VERSION,
+#endif
     SET_NODE,
     SET_HOOK
   };
@@ -88,6 +97,14 @@
         NetflowSetCommand, NULL, 2, (void *) SET_SELF },
     { "timeouts {inactive} {active}", "Set NetFlow timeouts" ,
         NetflowSetCommand, NULL, 2, (void *) SET_TIMEOUTS },
+#if NGM_NETFLOW_COOKIE >= 1309868867
+    { "template {time} {packets}", "Set NetFlow v9 template" ,
+        NetflowSetCommand, NULL, 2, (void *) SET_TEMPLATE },
+    { "mtu {mtu}", "Set NetFlow v9 MTU" ,
+        NetflowSetCommand, NULL, 2, (void *) SET_MTU },
+    { "version {version}", "Set version to export" ,
+        NetflowSetCommand, NULL, 2, (void *) SET_VERSION },
+#endif
     { "node {name}", "Set node name to use" ,
         NetflowSetCommand, NULL, 2, (void *) SET_NODE },
     { "hook {number}", "Set initial hook number" ,
@@ -113,6 +130,12 @@
   struct sockaddr_storage gNetflowSource;
   uint32_t gNetflowInactive = 0;
   uint32_t gNetflowActive = 0;
+#if NGM_NETFLOW_COOKIE >= 1309868867
+  uint16_t gNetflowTime = 0;
+  uint16_t gNetflowPackets = 0;
+  uint16_t gNetflowMTU = 0;
+  u_int gNetflowVer = 5;
+#endif
 #endif
   
   static int	gNgStatSock=0;
@@ -130,8 +153,7 @@
 
     /* Create a netgraph socket node */
     if (NgMkSockNode(NULL, &csock, NULL) < 0) {
-	Log(LG_ERR, ("NETFLOW: Can't create %s node: %s",
-    	    NG_SOCKET_NODE_TYPE, strerror(errno)));
+	Perror("NETFLOW: Can't create %s node", NG_SOCKET_NODE_TYPE);
         return (-1);
     }
 
@@ -151,8 +173,8 @@
     strcpy(mp.peerhook, NG_NETFLOW_HOOK_DATA "0");
     if (NgSendMsg(csock, ".:",
       NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
-	Log(LG_ERR, ("NETFLOW: Can't create %s node at \"%s\"->\"%s\": %s", 
-	    mp.type, ".:", mp.ourhook, strerror(errno)));
+	Perror("NETFLOW: Can't create %s node at \"%s\"->\"%s\"", 
+	    mp.type, ".:", mp.ourhook);
 	goto fail;
     }
     
@@ -163,14 +185,21 @@
     strcpy(nm.name, gNetflowNodeName);
     if (NgSendMsg(csock, TEMPHOOK,
       NGM_GENERIC_COOKIE, NGM_NAME, &nm, sizeof(nm)) < 0) {
-	Log(LG_ERR, ("NETFLOW: Can't name %s node: %s", NG_NETFLOW_NODE_TYPE,
-            strerror(errno)));
+	Perror("NETFLOW: Can't name %s node", NG_NETFLOW_NODE_TYPE);
 	goto fail;
     }
 
     /* Connect ng_ksocket(4) node for export. */
     strcpy(mp.type, NG_KSOCKET_NODE_TYPE);
-    strcpy(mp.ourhook, NG_NETFLOW_HOOK_EXPORT);
+#if NGM_NETFLOW_COOKIE >= 1309868867
+    if (gNetflowVer == 5) {
+#endif
+	strcpy(mp.ourhook, NG_NETFLOW_HOOK_EXPORT);
+#if NGM_NETFLOW_COOKIE >= 1309868867
+    } else {
+	strcpy(mp.ourhook, NG_NETFLOW_HOOK_EXPORT9);
+    }
+#endif
     if (gNetflowExport.ss_family==AF_INET6) {
 	snprintf(mp.peerhook, sizeof(mp.peerhook), "%d/%d/%d", PF_INET6, SOCK_DGRAM, IPPROTO_UDP);
     } else {
@@ -179,8 +208,8 @@
     snprintf(path, sizeof(path), "[%x]:", gNetflowNodeID);
     if (NgSendMsg(csock, path,
       NGM_GENERIC_COOKIE, NGM_MKPEER, &mp, sizeof(mp)) < 0) {
-	Log(LG_ERR, ("NETFLOW: Can't create %s node at \"%s\"->\"%s\": %s", 
-	    mp.type, path, mp.ourhook, strerror(errno)));
+	Perror("NETFLOW: Can't create %s node at \"%s\"->\"%s\"",
+	    mp.type, path, mp.ourhook);
 	goto fail;
     }
 
@@ -193,27 +222,60 @@
 
 	if (NgSendMsg(csock, path, NGM_NETFLOW_COOKIE,
 	  NGM_NETFLOW_SETTIMEOUTS, &nf_settime, sizeof(nf_settime)) < 0) {
-	    Log(LG_ERR, ("NETFLOW: Can't set timeouts on netflow %s node: %s",
-		NG_NETFLOW_NODE_TYPE, strerror(errno)));
+	    Perror("NETFLOW: Can't set timeouts on netflow %s node",
+		NG_NETFLOW_NODE_TYPE);
 	    goto fail2;
 	}
     }
 
+#if NGM_NETFLOW_COOKIE >= 1309868867
+    if (gNetflowTime != 0 && gNetflowPackets != 0) {
+	struct ng_netflow_settemplate nf_settempl;
+
+	nf_settempl.time = gNetflowTime;
+	nf_settempl.packets = gNetflowPackets;
+	if (NgSendMsg(csock, path, NGM_NETFLOW_COOKIE,
+	  NGM_NETFLOW_SETTEMPLATE, &nf_settempl, sizeof(nf_settempl)) < 0) {
+	    Perror("NETFLOW: Can't set NetFlow v9 template on netflow %s node",
+		NG_NETFLOW_NODE_TYPE);
+	    goto fail2;
+	}
+    }
+
+    if (gNetflowMTU != 0) {
+	struct ng_netflow_setmtu nf_setmtu;
+
+	nf_setmtu.mtu = gNetflowMTU;
+	if (NgSendMsg(csock, path, NGM_NETFLOW_COOKIE,
+	  NGM_NETFLOW_SETMTU, &nf_setmtu, sizeof(nf_setmtu)) < 0) {
+	    Perror("NETFLOW: Can't set NetFlow v9 MTU on netflow %s node",
+		NG_NETFLOW_NODE_TYPE);
+	  goto fail2;
+	}
+    }
+#endif
+
     /* Configure export destination and source on ng_ksocket(4). */
-    strlcat(path, NG_NETFLOW_HOOK_EXPORT, sizeof(path));
+#if NGM_NETFLOW_COOKIE >= 1309868867
+    if (gNetflowVer == 5) {
+#endif
+	strlcat(path, NG_NETFLOW_HOOK_EXPORT, sizeof(path));
+#if NGM_NETFLOW_COOKIE >= 1309868867
+    } else {
+	strlcat(path, NG_NETFLOW_HOOK_EXPORT9, sizeof(path));
+    }
+#endif
     if (gNetflowSource.ss_len != 0) {
 	if (NgSendMsg(csock, path, NGM_KSOCKET_COOKIE,
 	  NGM_KSOCKET_BIND, &gNetflowSource, sizeof(gNetflowSource)) < 0) {
-	    Log(LG_ERR, ("NETFLOW: Can't bind export %s node: %s",
-		NG_KSOCKET_NODE_TYPE, strerror(errno)));
+	    Perror("NETFLOW: Can't bind export %s node", NG_KSOCKET_NODE_TYPE);
 	    goto fail2;
 	}
     }
     if (gNetflowExport.ss_len != 0) {
 	if (NgSendMsg(csock, path, NGM_KSOCKET_COOKIE,
 	  NGM_KSOCKET_CONNECT, &gNetflowExport, sizeof(gNetflowExport)) < 0) {
-	    Log(LG_ERR, ("NETFLOW: Can't connect export %s node: %s",
-		NG_KSOCKET_NODE_TYPE, strerror(errno)));
+	    Perror("NETFLOW: Can't connect export %s node", NG_KSOCKET_NODE_TYPE);
 	    goto fail2;
 	}
     }
@@ -222,16 +284,16 @@
     snprintf(nm.name, sizeof(nm.name), "mpd%d-nfso", gPid);
     if (NgSendMsg(csock, path,
       NGM_GENERIC_COOKIE, NGM_NAME, &nm, sizeof(nm)) < 0) {
-	Log(LG_ERR, ("NETFLOW: Can't name %s node: %s", NG_KSOCKET_NODE_TYPE,
-            strerror(errno)));
+	Perror("NETFLOW: Can't name %s node", NG_KSOCKET_NODE_TYPE);
 	goto fail2;
     }
 
     /* Disconnect temporary hook. */
-    strcpy(rm.ourhook, TEMPHOOK);
+    memset(&rm, 0, sizeof(rm));
+    strncpy(rm.ourhook, TEMPHOOK, sizeof(rm.ourhook));
     if (NgSendMsg(csock, ".:",
       NGM_GENERIC_COOKIE, NGM_RMHOOK, &rm, sizeof(rm)) < 0) {
-	Log(LG_ERR, ("can't remove hook %s: %s", TEMPHOOK, strerror(errno)));
+	Perror("can't remove hook %s", TEMPHOOK);
 	goto fail2;
     }
     gNetflowNode = TRUE;
@@ -280,13 +342,12 @@
     /* Get the new node's name */
     if (NgSendMsg(gLinksCsock, TEMPHOOK,
       NGM_GENERIC_COOKIE, NGM_NODEINFO, NULL, 0) < 0) {
-	Log(LG_ERR, ("[%s] %s: %s", b->name, "NGM_NODEINFO", strerror(errno)));
+	Perror("[%s] %s", b->name, "NGM_NODEINFO");
 	rtn = -1;
 	goto done;
     }
     if (NgRecvMsg(gLinksCsock, &u.reply, sizeof(u), NULL) < 0) {
-	Log(LG_ERR, ("[%s] reply from %s: %s",
-    	    b->name, NG_IFACE_NODE_TYPE, strerror(errno)));
+	Perror("[%s] reply from %s", b->name, NG_IFACE_NODE_TYPE);
 	rtn = -1;
 	goto done;
     }
@@ -297,8 +358,7 @@
     strcpy(rm.ourhook, TEMPHOOK);
     if (NgSendMsg(gLinksCsock, ".:",
       NGM_GENERIC_COOKIE, NGM_RMHOOK, &rm, sizeof(rm)) < 0) {
-	Log(LG_ERR, ("[%s] can't remove hook %s: %s",
-    	    b->name, TEMPHOOK, strerror(errno)));
+	Perror("[%s] can't remove hook %s", b->name, TEMPHOOK);
 	rtn = -1;
     }
 
@@ -324,9 +384,8 @@
 
     /* Create a netgraph socket node */
     if (NgMkSockNode(NULL, &csock, NULL) < 0) {
-	Log(LG_ERR, ("NgFuncShutdownGlobal: can't create %s node: %s",
-    	    NG_SOCKET_NODE_TYPE, strerror(errno)));
-        return;
+	Perror("NgFuncShutdownGlobal: can't create %s node", NG_SOCKET_NODE_TYPE);
+	return;
     }
 
     snprintf(path, sizeof(path), "[%x]:", gNetflowNodeID);
@@ -357,8 +416,7 @@
 	    goto retry;
 	}
 	if (errno != ENOENT) {
-    	    Log(LG_ERR, ("[%s] can't shutdown \"%s\": %s",
-	      label, path, strerror(errno)));
+	    Perror("[%s] can't shutdown \"%s\"", label, path);
 	}
     }
     return(rtn);
@@ -375,8 +433,7 @@
     snprintf(path, sizeof(path), "[%x]:", b->nodeID);
     if (NgSendMsg(gLinksCsock, path, NGM_PPP_COOKIE,
     	    NGM_PPP_SET_CONFIG, &b->pppConfig, sizeof(b->pppConfig)) < 0) {
-	Log(LG_ERR, ("[%s] can't config %s: %s",
-    	    b->name, path, strerror(errno)));
+	Perror("[%s] can't config %s", b->name, path);
 	DoExit(EX_ERRDEAD);
     }
 }
@@ -396,9 +453,8 @@
 	/* Create a netgraph socket node */
 	snprintf(name, sizeof(name), "mpd%d-stats", gPid);
 	if (NgMkSockNode(name, &gNgStatSock, NULL) < 0) {
-    	    Log(LG_ERR, ("NgFuncSendQuery: can't create %s node: %s",
-    		NG_SOCKET_NODE_TYPE, strerror(errno)));
-    	    return(-1);
+	    Perror("NgFuncSendQuery: can't create %s node", NG_SOCKET_NODE_TYPE);
+	    return(-1);
 	}
 	(void) fcntl(gNgStatSock, F_SETFD, 1);
     }
@@ -409,8 +465,7 @@
 
     /* Read message */
     if (NgRecvMsg(gNgStatSock, rbuf, replen, raddr) < 0) {
-	Log(LG_ERR, ("NgFuncSendQuery: can't read unexpected message: %s",
-    	    strerror(errno)));
+	Perror("NgFuncSendQuery: can't read unexpected message");
 	return (-1);
     }
 
@@ -432,8 +487,8 @@
     strlcpy(cn.peerhook, hook2, sizeof(cn.peerhook));
     if (NgSendMsg(csock, path,
       NGM_GENERIC_COOKIE, NGM_CONNECT, &cn, sizeof(cn)) < 0) {
-        Log(LG_ERR, ("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-    	    label, path, hook, path2, hook2, strerror(errno)));
+	Perror("[%s] can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+	    label, path, hook, path2, hook2);
 	return(-1);
     }
     return(0);
@@ -450,6 +505,7 @@
     int		retry = 10, delay = 1000;
 
     /* Disconnect hook */
+    memset(&rm, 0, sizeof(rm));
     strlcpy(rm.ourhook, hook, sizeof(rm.ourhook));
 retry:
     if (NgSendMsg(csock, path,
@@ -462,8 +518,7 @@
 	    delay *= 2;
 	    goto retry;
 	}
-	Log(LG_ERR, ("[%s] can't remove hook %s from node \"%s\": %s",
-    	  label, hook, path, strerror(errno)));
+	Perror("[%s] can't remove hook %s from node \"%s\"", label, hook, path);
 	return(-1);
     }
     return(0);
@@ -571,8 +626,8 @@
 
     /* ENOBUFS can be expected on some links, e.g., ng_pptpgre(4) */
     if (rtn < 0 && errno != ENOBUFS) {
-	Log(LG_ERR, ("[%s] error writing len %d frame to %s: %s",
-    	    label, MBLEN(bp), hookname, strerror(errno)));
+	Perror("[%s] error writing len %d frame to %s",
+	    label, MBLEN(bp), hookname);
     }
     mbfree(bp);
     return (rtn);
@@ -593,8 +648,7 @@
     snprintf(path, sizeof(path), "[%x]:", b->nodeID);
     if (NgSendMsg(gLinksCsock, path, 
 	NGM_PPP_COOKIE, NGM_PPP_CLR_LINK_STATS, &linkNum, sizeof(linkNum)) < 0) {
-	    Log(LG_ERR, ("[%s] can't clear stats, link=%d: %s",
-    		b->name, linkNum, strerror(errno)));
+	    Perror("[%s] can't clear stats, link=%d", b->name, linkNum);
 	    return (-1);
     }
     return(0);
@@ -620,8 +674,7 @@
     snprintf(path, sizeof(path), "[%x]:", b->nodeID);
     if (NgFuncSendQuery(path, NGM_PPP_COOKIE, NGM_PPP_GET_LINK_STATS,
       &linkNum, sizeof(linkNum), &u.reply, sizeof(u), NULL) < 0) {
-	Log(LG_ERR, ("[%s] can't get stats, link=%d: %s",
-    	    b->name, linkNum, strerror(errno)));
+	Perror("[%s] can't get stats, link=%d", b->name, linkNum);
 	return -1;
     }
     if (statp != NULL)
@@ -650,8 +703,7 @@
     snprintf(path, sizeof(path), "[%x]:", b->nodeID);
     if (NgFuncSendQuery(path, NGM_PPP_COOKIE, NGM_PPP_GET_LINK_STATS64,
       &linkNum, sizeof(linkNum), &u.reply, sizeof(u), NULL) < 0) {
-	Log(LG_ERR, ("[%s] can't get stats, link=%d: %s",
-    	    b->name, linkNum, strerror(errno)));
+	Perror("[%s] can't get stats, link=%d", b->name, linkNum);
 	return -1;
     }
     if (statp != NULL)
@@ -689,7 +741,7 @@
     va_start(args, fmt);
     vsnprintf(buf, sizeof(buf), fmt, args);
     va_end(args);
-    Log(LG_ERR, ("netgraph: %s: %s", buf, strerror(errno)));
+    Perror("netgraph: %s", buf);
 }
 
 #ifdef USE_NG_NETFLOW
@@ -723,6 +775,34 @@
     	    gNetflowInactive = atoi(av[0]);
     	    gNetflowActive = atoi(av[1]);
     	    break;
+#if NGM_NETFLOW_COOKIE >= 1309868867
+	case SET_TEMPLATE:
+    	    if (ac != 2)
+		return (-1);
+	    /*
+	     * RFC 3954 clause 7.3
+	     * "Both options MUST be configurable by the user on the Exporter."
+	     */
+    	    if (atoi(av[0]) <= 0 || atoi(av[1]) <= 0)
+		Error("Bad netflow v9 template values \"%s %s\"", av[0], av[1]);
+    	    gNetflowTime = atoi(av[0]);		/* Default 600 */
+    	    gNetflowPackets = atoi(av[1]);	/* Default 500 */
+    	    break;
+	case SET_MTU:
+    	    if (ac != 1)
+		return (-1);
+    	    if (atoi(av[0]) < MIN_MTU || atoi(av[0]) > MAX_MTU)
+		Error("Bad netflow v9 MTU \"%s\"", av[0]);
+    	    gNetflowMTU = atoi(av[0]);		/* Default 1500 */
+    	    break;
+	case SET_VERSION:
+    	    if (ac != 1)
+		return (-1);
+    	    if (atoi(av[0]) != 5 && atoi(av[0]) != 9)
+		Error("Bad netflow export version \"%s\"", av[0]);
+    	    gNetflowVer = atoi(av[0]);		/* Default 5 */
+    	    break;
+#endif
 	case SET_NODE:
     	    if (ac != 1)
 		return (-1);
@@ -764,8 +844,7 @@
 	    /* Create a netgraph socket node */
 	    snprintf(name, sizeof(name), "mpd%d-stats", gPid);
 	    if (NgMkSockNode(name, &gNgStatSock, NULL) < 0) {
-    		Log(LG_ERR, ("NgFuncSendQuery: can't create %s node: %s",
-    	    	    NG_SOCKET_NODE_TYPE, strerror(errno)));
+    		Perror("NgFuncSendQuery: can't create %s node", NG_SOCKET_NODE_TYPE);
     		return(-1);
 	    }
 	    (void) fcntl(gNgStatSock, F_SETFD, 1);
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/phys.c
--- a/contrib/mpd/src/phys.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/phys.c	Fri Sep 14 02:13:58 2012 +0300
@@ -296,7 +296,7 @@
 }
 
 /*
- * PhysGetSelfAddr()
+ * PhysGetSelfName()
  */
 
 int
@@ -313,7 +313,7 @@
 }
 
 /*
- * PhysGetPeerAddr()
+ * PhysGetPeerName()
  */
 
 int
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/pppoe.c
--- a/contrib/mpd/src/pppoe.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/pppoe.c	Fri Sep 14 02:13:58 2012 +0300
@@ -263,8 +263,9 @@
 		/* Path to the ng_tee node */
 		snprintf(path, sizeof(path), "[%x]:%s", 
 		    pe->PIf->node_id, session_hook);
-		    
+
 		/* Connect ng_tee(4) node to the ng_ppp(4) node. */
+		memset(&cn, 0, sizeof(cn));
 		if (!PhysGetUpperHook(l, cn.path, cn.peerhook)) {
 		    Log(LG_PHYS, ("[%s] PPPoE: can't get upper hook", l->name));
 		    goto fail3;
@@ -272,15 +273,15 @@
 		snprintf(cn.ourhook, sizeof(cn.ourhook), "right");
 		if (NgSendMsg(pe->PIf->csock, path, NGM_GENERIC_COOKIE, NGM_CONNECT, 
 		    &cn, sizeof(cn)) < 0) {
-			Log(LG_ERR, ("[%s] PPPoE: can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-	    		    l->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+			Perror("[%s] PPPoE: can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+	    		    l->name, path, cn.ourhook, cn.path, cn.peerhook);
 			goto fail3;
 		}
 
 		/* Shutdown ng_tee node */
 		if (NgFuncShutdownNode(pe->PIf->csock, l->name, path) < 0) {
-			Log(LG_ERR, ("[%s] PPPoE: Shutdown ng_tee node %s error: %s",
-			    l->name, path, strerror(errno)));
+			Perror("[%s] PPPoE: Shutdown ng_tee node %s error",
+			    l->name, path);
 		}
 
 		if (l->state==PHYS_STATE_READY) {
@@ -317,8 +318,8 @@
 	
 	if (NgSendMsg(pe->PIf->csock, path, NGM_GENERIC_COOKIE, NGM_CONNECT, 
 	    &cn, sizeof(cn)) < 0) {
-		Log(LG_ERR, ("[%s] PPPoE: can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-    		    l->name, path, cn.ourhook, cn.path, cn.peerhook, strerror(errno)));
+		Perror("[%s] PPPoE: can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+    		    l->name, path, cn.ourhook, cn.path, cn.peerhook);
 		goto fail2;
 	}
 
@@ -331,8 +332,7 @@
 	strncpy(idata->data, pe->session, MAX_SESSION);
 	if (NgSendMsg(pe->PIf->csock, path, NGM_PPPOE_COOKIE, NGM_PPPOE_CONNECT,
 	    idata, sizeof(*idata) + idata->data_len) < 0) {
-		Log(LG_ERR, ("[%s] PPPoE can't request connection to server: "
-		    "%s", l->name, strerror(errno)));
+		Perror("[%s] PPPoE can't request connection to server", l->name);
 		goto fail2;
 	}
 
@@ -450,8 +450,7 @@
 	
 	/* Read control message. */
 	if (NgRecvMsg(PIf->csock, &u.resp, sizeof(u), path) < 0) {
-		Log(LG_ERR, ("PPPoE: error reading message from \"%s\": %s",
-		    path, strerror(errno)));
+		Perror("PPPoE: error reading message from \"%s\"", path);
 		return;
 	}
 	if (u.resp.header.typecookie != NGM_PPPOE_COOKIE) {
@@ -686,8 +685,7 @@
 
 	/* Create a new netgraph node */
 	if (NgMkSockNode(NULL, &PIf->csock, &PIf->dsock) < 0) {
-		Log(LG_ERR, ("[%s] PPPoE: can't create ctrl socket: %s",
-		    iface, strerror(errno)));
+		Perror("[%s] PPPoE: can't create ctrl socket", iface);
 		return(0);
 	}
 	(void)fcntl(PIf->csock, F_SETFD, 1);
@@ -700,8 +698,8 @@
 		/* Ask for a list of available node types. */
 		if (NgSendMsg(PIf->csock, "", NGM_GENERIC_COOKIE, NGM_LISTTYPES,
 		    NULL, 0) < 0) {
-			Log(LG_ERR, ("[%s] PPPoE: Cannot send a netgraph message: %s",
-			    iface, strerror(errno)));
+			Perror("[%s] PPPoE: Cannot send a netgraph message",
+			    iface);
 			close(PIf->csock);
 			close(PIf->dsock);
 			return (0);
@@ -710,8 +708,8 @@
 		/* Get response. */
 		resp = &u.reply;
 		if (NgRecvMsg(PIf->csock, resp, sizeof(u.buf), NULL) <= 0) {
-			Log(LG_ERR, ("[%s] PPPoE: Cannot get netgraph response: %s",
-			    iface, strerror(errno)));
+			Perror("[%s] PPPoE: Cannot get netgraph response",
+			    iface);
 			close(PIf->csock);
 			close(PIf->dsock);
 			return (0);
@@ -727,8 +725,7 @@
 
 		/* If not found try to load ng_ether and repeat the check. */
 		if (gNgEtherLoaded == FALSE && (kldload("ng_ether") < 0)) {
-			Log(LG_ERR, ("PPPoE: Cannot load ng_ether: %s",
-			    strerror(errno)));
+			Perror("PPPoE: Cannot load ng_ether");
 			close(PIf->csock);
 			close(PIf->dsock);
 			assert (0);
@@ -743,8 +740,7 @@
 	 */
 	if (NgSendMsg(PIf->csock, path, NGM_GENERIC_COOKIE, NGM_LISTHOOKS,
 	    NULL, 0) < 0) {
-		Log(LG_ERR, ("[%s] Cannot send a netgraph message: %s:%s",
-                    iface, path, strerror(errno)));
+		Perror("[%s] Cannot send a netgraph message: %s", iface, path);
 		close(PIf->csock);
 		close(PIf->dsock);
 		return (0);
@@ -753,8 +749,7 @@
 	/* Get our list back. */
 	resp = &u.reply;
 	if (NgRecvMsg(PIf->csock, resp, sizeof(u.buf), NULL) <= 0) {
-		Log(LG_ERR, ("[%s] Cannot get netgraph response: %s",
-		    iface, strerror(errno)));
+		Perror("[%s] Cannot get netgraph response", iface);
 		close(PIf->csock);
 		close(PIf->dsock);
 		return (0);
@@ -805,24 +800,23 @@
 		char	path2[NG_PATHSIZ];
 
 		/* Create new PPPoE node. */
+		memset(&mp, 0, sizeof(mp));
 		strcpy(mp.type, NG_PPPOE_NODE_TYPE);
 		strlcpy(mp.ourhook, hook, sizeof(mp.ourhook));
 		strcpy(mp.peerhook, NG_PPPOE_HOOK_ETHERNET);
 		if (NgSendMsg(PIf->csock, path, NGM_GENERIC_COOKIE, NGM_MKPEER, &mp,
 		    sizeof(mp)) < 0) {
-			Log(LG_ERR, ("[%s] can't create %s peer to %s,%s: %s",
-			    iface, NG_PPPOE_NODE_TYPE,
-			    path, hook, strerror(errno)));
-			    close(PIf->csock);
-			    close(PIf->dsock);
-			    return (0);
+			Perror("[%s] can't create %s peer to %s,%s",
+			    iface, NG_PPPOE_NODE_TYPE, path, hook);
+			close(PIf->csock);
+			close(PIf->dsock);
+			return (0);
 		}
 
 		snprintf(path2, sizeof(path2), "%s%s", path, hook);
 		/* Get pppoe node ID */
 		if ((PIf->node_id = NgGetNodeID(PIf->csock, path2)) == 0) {
-			Log(LG_ERR, ("[%s] Cannot get pppoe node id: %s",
-			    iface, strerror(errno)));
+			Perror("[%s] Cannot get pppoe node id", iface);
 			close(PIf->csock);
 			close(PIf->dsock);
 			return (0);
@@ -1037,14 +1031,14 @@
 	    gPid, l->id);
 		
 	/* Create ng_tee(4) node and connect it to ng_pppoe(4). */
+	memset(&mp, 0, sizeof(mp));
 	strcpy(mp.type, NG_TEE_NODE_TYPE);
 	strlcpy(mp.ourhook, session_hook, sizeof(mp.ourhook));
 	snprintf(mp.peerhook, sizeof(mp.peerhook), "left");
 	if (NgSendMsg(pi->PIf->csock, path, NGM_GENERIC_COOKIE, NGM_MKPEER,
 	    &mp, sizeof(mp)) < 0) {
-		Log(LG_ERR, ("[%s] PPPoE: can't create %s peer to %s,%s: %s",
-		    l->name, NG_TEE_NODE_TYPE,
-		    path, "left", strerror(errno)));
+		Perror("[%s] PPPoE: can't create %s peer to %s,%s",
+		    l->name, NG_TEE_NODE_TYPE, path, "left");
 		goto close_socket;
 	}
 
@@ -1052,19 +1046,19 @@
 	snprintf(path1, sizeof(path), "%s%s", path, session_hook);
 
 	/* Connect our socket node link hook to the ng_tee(4) node. */
+	memset(&cn, 0, sizeof(cn));
 	strlcpy(cn.ourhook, l->name, sizeof(cn.ourhook));
 	strlcpy(cn.path, path1, sizeof(cn.path));
 	strcpy(cn.peerhook, "left2right");
 	if (NgSendMsg(pi->PIf->csock, ".:", NGM_GENERIC_COOKIE, NGM_CONNECT,
 	    &cn, sizeof(cn)) < 0) {
-		Log(LG_ERR, ("[%s] PPPoE: can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\": %s",
-		    l->name, ".:", cn.ourhook, cn.path,
-		    cn.peerhook, strerror(errno)));
+		Perror("[%s] PPPoE: can't connect \"%s\"->\"%s\" and \"%s\"->\"%s\"",
+		    l->name, ".:", cn.ourhook, cn.path, cn.peerhook);
 		goto shutdown_tee;
 	}
 
 	/* Put the PPPoE node into OFFER mode. */
-	memset(idata, 0, sizeof(idata));
+	memset(idata, 0, sizeof(*idata));
 	strlcpy(idata->hook, session_hook, sizeof(idata->hook));
 	if (pi->acname[0] != 0) {
 		strlcpy(idata->data, pi->acname, MAX_SESSION);
@@ -1081,13 +1075,12 @@
 
 	if (NgSendMsg(pi->PIf->csock, path, NGM_PPPOE_COOKIE, NGM_PPPOE_OFFER,
 	    idata, sizeof(*idata) + idata->data_len) < 0) {
-		Log(LG_ERR, ("[%s] PPPoE: can't send NGM_PPPOE_OFFER to %s,%s "
-		    ": %s",
-		    l->name, path, idata->hook, strerror(errno)));
+		Perror("[%s] PPPoE: can't send NGM_PPPOE_OFFER to %s,%s ",
+		    l->name, path, idata->hook);
 		goto shutdown_tee;
 	}
 
-	memset(idata, 0, sizeof(idata));
+	memset(idata, 0, sizeof(*idata));
 	strlcpy(idata->hook, session_hook, sizeof(idata->hook));
 	idata->data_len = strlen(pi->session);
 	strncpy(idata->data, pi->session, MAX_SESSION);
@@ -1095,22 +1088,19 @@
 	if (NgSendMsg(pi->PIf->csock, path, NGM_PPPOE_COOKIE,
 	    NGM_PPPOE_SERVICE, idata,
 	    sizeof(*idata) + idata->data_len) < 0) {
-		Log(LG_ERR, ("[%s] PPPoE: can't send NGM_PPPOE_SERVICE to %s,"
-		    "%s : %s",
-		    l->name, path, idata->hook, strerror(errno)));
+		Perror("[%s] PPPoE: can't send NGM_PPPOE_SERVICE to %s,%s",
+		    l->name, path, idata->hook);
 		goto shutdown_tee;
 	}
 
 	/* And send our request data to the waiting node. */
 	if (NgSendData(pi->PIf->dsock, l->name, response, sz) == -1) {
-		Log(LG_ERR, ("[%s] PPPoE: Cannot send original request: %s",
-		    l->name, strerror(errno)));
+		Perror("[%s] PPPoE: Cannot send original request", l->name);
 		goto shutdown_tee;
 	}
 		
 	if (NgFuncDisconnect(pi->PIf->csock, l->name, ".:", l->name) < 0) {
-		Log(LG_ERR, ("[%s] PPPoE: can't remove hook %s: %s", 
-	    	    l->name, l->name, strerror(errno)));
+		Perror("[%s] PPPoE: can't remove hook %s", l->name, l->name);
 		goto shutdown_tee;
     	}
 	l->state = PHYS_STATE_CONNECTING;
@@ -1133,8 +1123,7 @@
 
 shutdown_tee:
 	if (NgFuncShutdownNode(pi->PIf->csock, l->name, path1) < 0) {
-		Log(LG_ERR, ("[%s] Shutdown ng_tee node %s error: %s",
-		    l->name, path1, strerror(errno)));
+	    Perror("[%s] Shutdown ng_tee node %s error", l->name, path1);
 	};
 
 close_socket:
@@ -1259,6 +1248,7 @@
 	snprintf(path, sizeof(path), "[%x]:", PIf->node_id);
 	
 	/* Connect our socket node link hook to the ng_pppoe(4) node. */
+	memset(&cn, 0, sizeof(cn));
 	strcpy(cn.path, path);
 	snprintf(cn.ourhook, sizeof(cn.peerhook), "listen-%s", pi->session);
 	strcpy(cn.peerhook, cn.ourhook);
@@ -1272,15 +1262,15 @@
 	}
 
 	/* Tell the PPPoE node to be a server. */
-	memset(idata, 0, sizeof(idata));
+	memset(idata, 0, sizeof(*idata));
 	snprintf(idata->hook, sizeof(idata->hook), "listen-%s", pi->session);
 	idata->data_len = strlen(pi->session);
 	strncpy(idata->data, pi->session, MAX_SESSION);
 
 	if (NgSendMsg(PIf->csock, path, NGM_PPPOE_COOKIE, NGM_PPPOE_LISTEN,
 	    idata, sizeof(*idata) + idata->data_len) < 0) {
-		Log(LG_ERR, ("PPPoE: Can't send NGM_PPPOE_LISTEN to %s hook "
-		    "%s : %s", path, idata->hook, strerror(errno)));
+		Perror("PPPoE: Can't send NGM_PPPOE_LISTEN to %s hook %s",
+		     path, idata->hook);
 		return (0);
 	}
 
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/pptp.c
--- a/contrib/mpd/src/pptp.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/pptp.c	Fri Sep 14 02:13:58 2012 +0300
@@ -268,9 +268,13 @@
 PptpInst(Link l, Link lt)
 {
     PptpInfo	pptp;
+    PptpInfo	const pptpt = (PptpInfo) lt->info;
 
     /* Initialize this link */
     pptp = (PptpInfo) (l->info = Mdup(MB_PHYS, lt->info, sizeof(*pptp)));
+    if (pptpt->conf.fqdn_peer_addr != NULL)
+        pptp->conf.fqdn_peer_addr =
+            Mstrdup(MB_PHYS, pptpt->conf.fqdn_peer_addr);
     pptp->listener = NULL;
 
     return(0);
@@ -448,7 +452,7 @@
 
 	/* Get a temporary netgraph socket node */
 	if (NgMkSockNode(NULL, &csock, NULL) == -1) {
-		Log(LG_ERR, ("PPTP: NgMkSockNode: %s", strerror(errno)));
+		Perror("PPTP: NgMkSockNode");
 		return;
 	}
 	
@@ -840,7 +844,7 @@
     
     /* Get a temporary netgraph socket node */
     if (NgMkSockNode(NULL, &csock, NULL) == -1) {
-	Log(LG_ERR, ("PPTP: NgMkSockNode: %s", strerror(errno)));
+	Perror("PPTP: NgMkSockNode");
 	return(-1);
     }
 
@@ -859,7 +863,7 @@
 	tun->self_addr = u_self_addr;
 	tun->peer_addr = u_peer_addr;
 	if (ghash_put(gPptpTuns, tun) == -1) {
-	    Log(LG_ERR, ("[%s] PPTP: ghash_put: %s", l->name, strerror(errno)));
+	    Perror("[%s] PPTP: ghash_put", l->name);
 	    Freee(tun);
 	    close(csock);
 	    return(-1);
@@ -875,8 +879,7 @@
 #endif
 	if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
           NGM_MKPEER, &mkp, sizeof(mkp)) < 0) {
-	    Log(LG_ERR, ("[%s] PPTP: can't attach %s node: %s",
-    		l->name, NG_PPTPGRE_NODE_TYPE, strerror(errno)));
+	    Perror("[%s] PPTP: can't attach %s node", l->name, NG_PPTPGRE_NODE_TYPE);
 	    ghash_remove(gPptpTuns, tun);
 	    Freee(tun);
 	    close(csock);
@@ -885,8 +888,7 @@
 
 	/* Get pptpgre node ID */
 	if ((tun->node_id = NgGetNodeID(csock, pptppath)) == 0) {
-	    Log(LG_ERR, ("[%s] Cannot get %s node id: %s",
-		l->name, NG_PPTPGRE_NODE_TYPE, strerror(errno)));
+	    Perror("[%s] Cannot get %s node id", l->name, NG_PPTPGRE_NODE_TYPE);
 	    ghash_remove(gPptpTuns, tun);
 	    Freee(tun);
 	    close(csock);
@@ -906,8 +908,7 @@
 	}
 	if (NgSendMsg(csock, pptppath, NGM_GENERIC_COOKIE,
 	  NGM_MKPEER, &mkp, sizeof(mkp)) < 0) {
-	    Log(LG_ERR, ("[%s] PPTP: can't attach %s node: %s",
-    		l->name, NG_KSOCKET_NODE_TYPE, strerror(errno)));
+	    Perror("[%s] PPTP: can't attach %s node", l->name, NG_KSOCKET_NODE_TYPE);
 	    close(csock);
 	    return(-1);
 	}
@@ -920,15 +921,14 @@
 	((int *)(ksso->value))[0]=48*1024;
 	if (NgSendMsg(csock, ksockpath, NGM_KSOCKET_COOKIE,
 	    NGM_KSOCKET_SETOPT, &u, sizeof(u)) < 0) {
-		Log(LG_ERR, ("[%s] PPTP: can't setsockopt %s node: %s",
-		    l->name, NG_KSOCKET_NODE_TYPE, strerror(errno)));
+		Perror("[%s] PPTP: can't setsockopt %s node",
+		    l->name, NG_KSOCKET_NODE_TYPE);
 	}
 
 	/* Bind ksocket socket to local IP address */
 	if (NgSendMsg(csock, ksockpath, NGM_KSOCKET_COOKIE,
           NGM_KSOCKET_BIND, &self_addr, self_addr.ss_len) < 0) {
-	    Log(LG_ERR, ("[%s] PPTP: can't bind() %s node: %s",
-    		l->name, NG_KSOCKET_NODE_TYPE, strerror(errno)));
+	    Perror("[%s] PPTP: can't bind() %s node", l->name, NG_KSOCKET_NODE_TYPE);
 	    close(csock);
 	    return(-1);
 	}
@@ -937,8 +937,8 @@
 	if (NgSendMsg(csock, ksockpath, NGM_KSOCKET_COOKIE,
     	  NGM_KSOCKET_CONNECT, &peer_addr, peer_addr.ss_len) < 0 &&
     	  errno != EINPROGRESS) {	/* happens in -current (weird) */
-	    Log(LG_ERR, ("[%s] PPTP: can't connect() %s node: %s",
-    	        l->name, NG_KSOCKET_NODE_TYPE, strerror(errno)));
+	    Perror("[%s] PPTP: can't connect() %s node",
+    	        l->name, NG_KSOCKET_NODE_TYPE);
 	    close(csock);
     	    return(-1);
         }
@@ -950,8 +950,8 @@
 	snprintf(cn.peerhook, sizeof(mkp.peerhook), NG_PPTPGRE_HOOK_SESSION_F, pi->cid);
 	if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
           NGM_CONNECT, &cn, sizeof(cn)) < 0) {
-	    Log(LG_ERR, ("[%s] PPTP: can't connect to %s node: %s",
-    		l->name, NG_PPTPGRE_NODE_TYPE, strerror(errno)));
+	    Perror("[%s] PPTP: can't connect to %s node",
+    		l->name, NG_PPTPGRE_NODE_TYPE);
 	    close(csock);
 	    return(-1);
 	}
@@ -970,8 +970,7 @@
 
     if (NgSendMsg(csock, pptppath, NGM_PPTPGRE_COOKIE,
       NGM_PPTPGRE_SET_CONFIG, &gc, sizeof(gc)) < 0) {
-	Log(LG_ERR, ("[%s] PPTP: can't config %s node: %s",
-    	    l->name, NG_PPTPGRE_NODE_TYPE, strerror(errno)));
+	Perror("[%s] PPTP: can't config %s node", l->name, NG_PPTPGRE_NODE_TYPE);
 	close(csock);
 	return(-1);
     }
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/pptp_ctrl.c
--- a/contrib/mpd/src/pptp_ctrl.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/pptp_ctrl.c	Fri Sep 14 02:13:58 2012 +0300
@@ -813,7 +813,7 @@
     /* Get local IP address */
     addrLen = sizeof(selfst);
     if (getsockname(sock, (struct sockaddr *) &selfst, &addrLen) < 0) {
-	Log(LG_ERR, ("PPTP: %s getsockname(): %s", __func__, strerror(errno)));
+	Perror("PPTP: %s getsockname()", __func__);
 	u_addrclear(&self_addr);
 	self_port = 0;
     } else {
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/pptp_ctrl.h
--- a/contrib/mpd/src/pptp_ctrl.h	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/pptp_ctrl.h	Fri Sep 14 02:13:58 2012 +0300
@@ -193,8 +193,8 @@
     u_int16_t		serno;		/* call serial # */
     u_int32_t		minBps;		/* minimum BPS */
     u_int32_t		maxBps;		/* maximum BPS */
+    u_int32_t		bearType;	/* bearer type */
     u_int32_t		frameType;	/* framing type */
-    u_int32_t		bearType;	/* bearer type */
     u_int16_t		recvWin;	/* pkt receive window size */
     u_int16_t		ppd;		/* pkt processing delay */
     u_int16_t		numLen;		/* phone number length */
@@ -205,7 +205,7 @@
 
 #else
   { { "cid", 2 }, { "serno", 2 }, { "minBPS", 4 }, { "maxBPS", 4 },
-    { "frameType", 4 }, { "bearType", 4 }, { "recvWin", 2 }, { "ppd", 2 },
+    { "bearType", 4 }, { "frameType", 4 },{ "recvWin", 2 }, { "ppd", 2 },
     { "numLen", 2 }, { PPTP_RESV_PREF "0", 2 },
     { "phone", PPTP_PHONE_LEN }, { "subaddr", PPTP_SUBADDR_LEN },
     { NULL, 0 } },
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/proto.c
--- a/contrib/mpd/src/proto.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/proto.c	Fri Sep 14 02:13:58 2012 +0300
@@ -58,6 +58,8 @@
 
   static const struct protoname protoNames[] = {
 #ifdef PROTO_NAME_LIST
+
+/* Network layer protocols */
     { 0x0001,	"Padding Protocol" },
     { 0x0021,	"Internet Protocol" },
     { 0x0023,	"OSI Network Layer" },
@@ -89,16 +91,18 @@
     { 0x0057,	"IPv6 over PPP" },
     { 0x0059,	"PPP Multiplexing (RFC 3153)" },
     { 0x005b,	"Vendor-Specific Network Protocol" },
+    { 0x005d,	"TRILL Network Protocol (TNP)" },
     { 0x0061,	"RTP IPHC Full Header" },
     { 0x0063,	"RTP IPHC Compressed TCP" },
     { 0x0065,	"RTP IPHC Compressed Non TCP" },
     { 0x0067,	"RTP IPHC Compressed UDP 8" },
-    { 0x0067,	"RTP IPHC Compressed RTP 8" },
+    { 0x0069,	"RTP IPHC Compressed RTP 8" },
     { 0x006f,	"Stampede Bridging" },
     { 0x0071,	"BAP Bandwidth Allocation Protocol" },
     { 0x0073,	"MP+ Protocol" },
-    { 0x007d,	"reserved (Control Escape)" },
+    { 0x007d,	"reserved (Control Escape) (RFC 1661)" },
     { 0x007f,	"reserved (compression inefficient) (RFC 1662)" },
+    { 0x00c1,	"NTCITS IPI" },
     { 0x00cf,	"reserved (PPP NLPID)" },
     { 0x00fb,	"compression on single link in multilink group" },
     { 0x00fd,	"1st choice compression (RFC 1962)" },
@@ -108,14 +112,29 @@
     { 0x0203,	"IBM Source Routing BPDU" },
     { 0x0205,	"DEC LANBridge100 Spanning Tree" },
     { 0x0207,	"Cisco Discovery Protocol" },
+    { 0x0209,	"Netcs Twin Routing" },
+    { 0x0211,	"Optical Supervisory Channel Protocol (OSCP)" },
+    { 0x0213,	"Optical Supervisory Channel Protocol (OSCP)" },
     { 0x0231,	"Luxcom" },
     { 0x0233,	"Sigma Network Systems" },
     { 0x0235,	"Apple Client Server Protocol" },
+    { 0x0281,	"MPLS Unicast" },
+    { 0x0283,	"MPLS Multicast" },
+    { 0x0285,	"IEEE p1284.4 standard - data packets" },
+    { 0x0287,	"ETSI TETRA Network Protocol Type 1" },
+    { 0x0289,	"Multichannel Flow Treatment Protocol" },
+
+    { 0x2063,	"RTP IPHC Compressed TCP No Delta" },
+    { 0x2065,	"RTP IPHC Context State" },
+    { 0x2067,	"RTP IPHC Compressed UDP 16" },
+    { 0x2069,	"RTP IPHC Compressed RTP 16" },
 
     { 0x4001,	"Cray Communications Control Protocol" },
     { 0x4003,	"CDPD Mobile Network Registration Protocol" },
     { 0x4021,	"Stacker LZS" },
 
+/* Network layer control protocols */
+
     { 0x8021,	"Internet Protocol Control Protocol" },
     { 0x8023,	"OSI Network Layer Control Protocol" },
     { 0x8025,	"Xerox NS IDP Control Protocol" },
@@ -148,6 +167,7 @@
     { 0x8071,	"BACP Bandwidth Allocation Control Protocol" },
     { 0x8073,	"MP+ Control Protocol" },
     { 0x807d,	"Not Used - reserved" },
+    { 0x80c1,	"NTCITS IPI Control Protocol" },
     { 0x80cf,	"Not Used - reserved" },
     { 0x80fb,	"compression on single link in multilink group control" },
     { 0x80fd,	"Compression Control Protocol" },
@@ -155,6 +175,8 @@
 
     { 0x8207,	"Cisco Discovery Protocol Control" },
     { 0x8209,	"Netcs Twin Routing" },
+    { 0x820b,	"STP - Control Protocol" },
+    { 0x820d,	"EDPCP - Extreme Discovery Protocol Ctrl Prtcl" },
     { 0x8235,	"Apple Client Server Protocol Control" },
     { 0x8281,	"MPLS Control Protocol (RFC 3032)" },
     { 0x8283,	"Tag Switching - Multicast" },
@@ -162,6 +184,8 @@
     { 0x8287,	"ETSI TETRA NSP1 Control Protocol" },
     { 0x8289,	"Multichannel Flow Treatment Protocol" },
 
+/* Link layer control protocols */
+
     { 0xc021,	"Link Control Protocol" },
     { 0xc023,	"Password Authentication Protocol" },
     { 0xc025,	"Link Quality Report" },
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/radius.c
--- a/contrib/mpd/src/radius.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/radius.c	Fri Sep 14 02:13:58 2012 +0300
@@ -1,7 +1,7 @@
 /*
  * See ``COPYRIGHT.mpd''
  *
- * $Id: radius.c,v 1.155 2011/07/01 06:51:48 dmitryluhtionov Exp $
+ * $Id: radius.c,v 1.159 2012/03/19 08:30:45 amotin Exp $
  *
  */
 
@@ -49,6 +49,7 @@
 /* Set menu options */
 
   enum {
+	UNSET_SERVER,
     SET_SERVER,
     SET_ME,
     SET_MEV6,
@@ -63,7 +64,12 @@
 /*
  * GLOBAL VARIABLES
  */
-
+  const struct cmdtab RadiusUnSetCmds[] = {
+	  { "server {name} [{auth port}] [{acct port}]", "Unset (remove) radius server" ,
+		  RadiusSetCommand, NULL, 2, (void *) UNSET_SERVER },
+	  { NULL },
+  };
+  
   const struct cmdtab RadiusSetCmds[] = {
     { "server {name} {secret} [{auth port}] [{acct port}]", "Set radius server parameters" ,
 	RadiusSetCommand, NULL, 2, (void *) SET_SERVER },
@@ -344,6 +350,7 @@
   RadConf	const conf = &ctx->lnk->lcp.auth.conf.radius;
   RadServe_Conf	server;
   RadServe_Conf	t_server;
+  RadServe_Conf	next, prev;
   int		val, count;
   struct u_addr t;
   int 		auth_port = 1812;
@@ -354,6 +361,37 @@
 
     switch ((intptr_t)arg) {
 
+      case UNSET_SERVER:
+	
+	if (ac > 3 || ac < 1) {
+		return(-1);
+	}
+	for ( prev = NULL, t_server = conf->server ;
+	    t_server != NULL && (next = t_server->next, 1) ;
+	    prev = t_server, t_server = next) {
+		
+		if (strcmp(t_server->hostname, av[0]) != 0)
+			continue;
+		if (ac > 1 && t_server->auth_port != atoi(av[1]))
+			continue;
+		if (ac > 2 && t_server->acct_port != atoi(av[2]))
+			continue;
+		
+		if (t_server == conf->server) {
+			conf->server = t_server->next;
+		} else {
+			prev->next = t_server->next;
+			t_server->next = NULL;
+		}
+		
+		Freee(t_server->hostname);
+		Freee(t_server->sharedsecret);
+		Freee(t_server);
+		t_server = prev;
+	}
+	
+	break;
+
       case SET_SERVER:
 	if (ac > 4 || ac < 2) {
 	  return(-1);
@@ -681,6 +719,15 @@
     	return (RAD_NACK);
     }
 
+    Log(LG_RADIUS2, ("[%s] RADIUS: Put RAD_MPD_PEER_IDENT: %s",
+	auth->info.lnkname, auth->info.peer_ident));
+    if (rad_put_vendor_string(auth->radius.handle, RAD_VENDOR_MPD,
+      RAD_MPD_PEER_IDENT, auth->info.peer_ident) != 0) {
+	Log(LG_RADIUS, ("[%s] RADIUS: Put RAD_MPD_PEER_IDENT failed %s",
+	    auth->info.lnkname, rad_strerror(auth->radius.handle)));
+	return (RAD_NACK);
+    }
+
 #ifdef PHYSTYPE_PPTP
     if (auth->info.phys_type == &gPptpPhysType) {
 	porttype = 1;
@@ -1038,6 +1085,14 @@
 	return (RAD_NACK);
     }
 
+    Log(LG_RADIUS2, ("[%s] RADIUS: Put RAD_MPD_PEER_IDENT: %s",
+	auth->info.lnkname, auth->info.peer_ident));
+    if (rad_put_vendor_string(auth->radius.handle, RAD_VENDOR_MPD, RAD_MPD_PEER_IDENT, auth->info.peer_ident) != 0) {
+	Log(LG_RADIUS, ("[%s] RADIUS: Put RAD_MPD_PEER_IDENT failed %s",
+	    auth->info.lnkname, rad_strerror(auth->radius.handle)));
+	return (RAD_NACK);
+    }
+
     Log(LG_RADIUS2, ("[%s] RADIUS: Put RAD_ACCT_LINK_COUNT: %d", 
 	auth->info.lnkname, auth->info.n_links));
     if (rad_put_int(auth->radius.handle, RAD_ACCT_LINK_COUNT, auth->info.n_links) != 0) {
@@ -1761,7 +1816,37 @@
 		    sizeof(auth->params.action));
 		free(tmpval);
 		break;
+	    } else if (res == RAD_MPD_IFACE_NAME) {
+		tmpval = rad_cvt_string(data, len);
+	        Log(LG_RADIUS2, ("[%s] RADIUS: Get RAD_MPD_IFACE_NAME: %s",
+	    	    auth->info.lnkname, tmpval));
+		strlcpy(auth->params.ifname, tmpval,
+		    sizeof(auth->params.ifname));
+		free(tmpval);
+		break;
 	    } else
+#ifdef SIOCSIFDESCR
+	    if (res == RAD_MPD_IFACE_DESCR) {
+		tmpval = rad_cvt_string(data, len);
+	        Log(LG_RADIUS2, ("[%s] RADIUS: Get RAD_MPD_IFACE_DESCR: %s",
+	    	    auth->info.lnkname, tmpval));
+		Freee(auth->params.ifdescr);
+		auth->params.ifdescr = Mdup(MB_AUTH, tmpval, len + 1);
+		free(tmpval);
+		break;
+	    } else
+#endif /* SIOCSIFDESCR */
+#ifdef SIOCAIFGROUP
+	    if (res == RAD_MPD_IFACE_GROUP) {
+		tmpval = rad_cvt_string(data, len);
+	        Log(LG_RADIUS2, ("[%s] RADIUS: Get RAD_MPD_IFACE_GROUP: %s",
+	    	    auth->info.lnkname, tmpval));
+		strlcpy(auth->params.ifgroup, tmpval,
+		    sizeof(auth->params.ifgroup));
+		free(tmpval);
+		break;
+	    } else
+#endif /* SIOCAIFGROUP */
 #ifdef USE_IPFW
 	    if (res == RAD_MPD_RULE) {
 	      acl1 = acl = rad_cvt_string(data, len);
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/radius.h
--- a/contrib/mpd/src/radius.h	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/radius.h	Fri Sep 14 02:13:58 2012 +0300
@@ -1,7 +1,7 @@
 /*
  * See ``COPYRIGHT.mpd''
  *
- * $Id: radius.h,v 1.41 2008/10/23 22:14:37 amotin Exp $
+ * $Id: radius.h,v 1.45 2012/03/19 08:30:45 amotin Exp $
  *
  */
 
@@ -113,6 +113,10 @@
   #define RAD_MPD_INPUT_ACCT	16
   #define RAD_MPD_OUTPUT_ACCT	17
   #define RAD_MPD_ACTION	18
+  #define RAD_MPD_PEER_IDENT	19
+  #define RAD_MPD_IFACE_NAME	20
+  #define RAD_MPD_IFACE_DESCR	21
+  #define RAD_MPD_IFACE_GROUP	22
   #define RAD_MPD_DROP_USER	154
 
   /* Configuration options */
@@ -121,6 +125,7 @@
   };
 
   extern const	struct cmdtab RadiusSetCmds[];
+  extern const	struct cmdtab RadiusUnSetCmds[];
 
   /* Configuration for a radius server */
   struct radiusserver_conf {
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/radsrv.c
--- a/contrib/mpd/src/radsrv.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/radsrv.c	Fri Sep 14 02:13:58 2012 +0300
@@ -628,7 +628,7 @@
     }
 
     if ((w->fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
-	Log(LG_ERR, ("%s: Cannot create socket: %s", __FUNCTION__, strerror(errno)));
+	Perror("%s: Cannot create socket", __FUNCTION__);
 	return (-1);
     }
     memset(&sin, 0, sizeof sin);
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/rep.c
--- a/contrib/mpd/src/rep.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/rep.c	Fri Sep 14 02:13:58 2012 +0300
@@ -40,8 +40,7 @@
     if (r->csock <= 0) {
 	/* Create a new netgraph node to control TCP ksocket node. */
 	if (NgMkSockNode(NULL, &r->csock, NULL) < 0) {
-    	    Log(LG_ERR, ("[%s] Rep: can't create control socket: %s",
-    		r->name, strerror(errno)));
+    	    Perror("[%s] Rep: can't create control socket", r->name);
     	    PhysClose(l);
 	    return;
 	}
@@ -53,8 +52,8 @@
     snprintf(mkp.peerhook, sizeof(mkp.peerhook), NG_TEE_HOOK_LEFT2RIGHT);
     if (NgSendMsg(r->csock, ".:", NGM_GENERIC_COOKIE,
         NGM_MKPEER, &mkp, sizeof(mkp)) < 0) {
-    	Log(LG_ERR, ("[%s] Rep: can't attach %s %s node: %s",
-    	    l->name, NG_TEE_NODE_TYPE, mkp.ourhook, strerror(errno)));
+    	Perror("[%s] Rep: can't attach %s %s node",
+    	    l->name, NG_TEE_NODE_TYPE, mkp.ourhook);
 	close(r->csock);
     	PhysClose(l);
 	return;
@@ -62,8 +61,7 @@
 
     /* Get tee node ID */
     if ((r->node_id = NgGetNodeID(r->csock, ".:tee")) == 0) {
-	Log(LG_ERR, ("[%s] Rep: Cannot get %s node id: %s",
-	    l->name, NG_TEE_NODE_TYPE, strerror(errno)));
+	Perror("[%s] Rep: Cannot get %s node id", l->name, NG_TEE_NODE_TYPE);
 	close(r->csock);
     	PhysClose(l);
 	return;
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/tcp.c
--- a/contrib/mpd/src/tcp.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/tcp.c	Fri Sep 14 02:13:58 2012 +0300
@@ -184,8 +184,13 @@
 TcpInst(Link l, Link lt)
 {
 	TcpInfo pi;
-	l->info = Mdup(MB_PHYS, lt->info, sizeof(struct tcpinfo));
-	pi = (TcpInfo) l->info;
+	TcpInfo const pit = (TcpInfo) lt->info;
+
+	/* Initialize this link */
+	pi = (TcpInfo) (l->info = Mdup(MB_PHYS, lt->info, sizeof(*pi)));
+	if (pit->conf.fqdn_peer_addr != NULL)
+	    pi->conf.fqdn_peer_addr =
+		Mstrdup(MB_PHYS, pit->conf.fqdn_peer_addr);
     
 	if (pi->If)
 	    pi->If->refs++;
@@ -213,8 +218,7 @@
 
 	/* Create a new netgraph node to control TCP ksocket node. */
 	if (NgMkSockNode(NULL, &pi->csock, NULL) < 0) {
-		Log(LG_ERR, ("[%s] TCP can't create control socket: %s",
-		    l->name, strerror(errno)));
+		Perror("[%s] TCP can't create control socket", l->name);
 		goto fail;
 	}
 	(void)fcntl(pi->csock, F_SETFD, 1);
@@ -229,8 +233,8 @@
 	strcpy(mkp.peerhook, NG_ASYNC_HOOK_SYNC);
 	if (NgSendMsg(pi->csock, path, NGM_GENERIC_COOKIE,
 	    NGM_MKPEER, &mkp, sizeof(mkp)) < 0) {
-		Log(LG_ERR, ("[%s] can't attach %s %s node: %s",
-		    l->name, NG_ASYNC_NODE_TYPE, mkp.ourhook, strerror(errno)));
+		Perror("[%s] can't attach %s %s node",
+		    l->name, NG_ASYNC_NODE_TYPE, mkp.ourhook);
 		goto fail;
 	}
 	
@@ -241,14 +245,12 @@
 	snprintf(nm.name, sizeof(nm.name), "mpd%d-%s-as", gPid, l->name);
 	if (NgSendMsg(pi->csock, path,
 	    NGM_GENERIC_COOKIE, NGM_NAME, &nm, sizeof(nm)) < 0) {
-		Log(LG_ERR, ("[%s] can't name %s node: %s",
-		    l->name, NG_ASYNC_NODE_TYPE, strerror(errno)));
+		Perror("[%s] can't name %s node", l->name, NG_ASYNC_NODE_TYPE);
 	}
 
 	/* Get async node ID */
 	if ((pi->async_node_id = NgGetNodeID(pi->csock, path)) == 0) {
-	    Log(LG_ERR, ("[%s] Cannot get %s node id: %s",
-		l->name, NG_ASYNC_NODE_TYPE, strerror(errno)));
+	    Perror("[%s] Cannot get %s node id", l->name, NG_ASYNC_NODE_TYPE);
 	    goto fail;
 	};
 
@@ -274,8 +276,7 @@
 		snprintf(cn.peerhook, sizeof(cn.peerhook), "data");
 		if (NgSendMsg(pi->csock, path, NGM_GENERIC_COOKIE, NGM_CONNECT,
 		    &cn, sizeof(cn)) < 0) {
-			Log(LG_ERR, ("[%s] can't connect new born ksocket: %s",
-			    l->name, strerror(errno)));
+			Perror("[%s] can't connect new born ksocket", l->name);
 			goto fail;
 	  	}
 
@@ -306,8 +307,7 @@
 	}
 	if (NgSendMsg(pi->csock, path, NGM_GENERIC_COOKIE, NGM_MKPEER, &mkp,
 	    sizeof(mkp)) < 0) {
-		Log(LG_ERR, ("[%s] can't attach %s node: %s", l->name,
-		    NG_KSOCKET_NODE_TYPE, strerror(errno)));
+		Perror("[%s] can't attach %s node", l->name, NG_KSOCKET_NODE_TYPE);
 		goto fail;
 	}
 
@@ -318,8 +318,7 @@
 	snprintf(nm.name, sizeof(nm.name), "mpd%d-%s-kso", gPid, l->name);
 	if (NgSendMsg(pi->csock, path,
 	    NGM_GENERIC_COOKIE, NGM_NAME, &nm, sizeof(nm)) < 0) {
-		Log(LG_ERR, ("[%s] can't name %s node: %s",
-		    l->name, NG_KSOCKET_NODE_TYPE, strerror(errno)));
+		Perror("[%s] can't name %s node", l->name, NG_KSOCKET_NODE_TYPE);
 	}
 
 	/* Start connecting to peer. */
@@ -327,8 +326,8 @@
 	rval = NgSendMsg(pi->csock, path, NGM_KSOCKET_COOKIE,
 	    NGM_KSOCKET_CONNECT, &addr, addr.ss_len);
 	if (rval < 0 && errno != EINPROGRESS) {
-		Log(LG_ERR, ("[%s] can't connect() %s node: %s", l->name,
-		    NG_KSOCKET_NODE_TYPE, strerror(errno))); 
+		Perror("[%s] can't connect() %s node", l->name,
+		    NG_KSOCKET_NODE_TYPE);
 		goto fail;
 	}
 
@@ -374,8 +373,7 @@
 
 	/* Check whether the connection was successful or not. */
 	if (NgRecvMsg(pi->csock, &cn.resp, sizeof(cn), path) < 0) {
-		Log(LG_ERR, ("[%s] error reading message from \"%s\": %s",
-		    l->name, path, strerror(errno)));
+		Perror("[%s] error reading message from \"%s\"", l->name, path);
 		goto failed;
 	}
 
@@ -427,8 +425,7 @@
 
 	/* Accept cloned ng_ksocket(4). */
 	if (NgRecvMsg(If->csock, &ac.resp, sizeof(ac), NULL) < 0) {
-		Log(LG_ERR, ("TCP: error reading message from \"%s\": %s",
-		    path, strerror(errno)));
+		Perror("TCP: error reading message from \"%s\"", path);
 		goto failed;
 	}
 	sockaddrtou_addr(&ac.sin, &addr, &port);
@@ -489,8 +486,8 @@
 		snprintf(path, sizeof(path), "[%x]:", ac.id);
 		if (NgSendMsg(If->csock, path,
 		    NGM_GENERIC_COOKIE, NGM_NAME, &nm, sizeof(nm)) < 0) {
-			Log(LG_ERR, ("[%s] can't name %s node: %s",
-			    l->name, NG_KSOCKET_NODE_TYPE, strerror(errno)));
+			Perror("[%s] can't name %s node",
+			    l->name, NG_KSOCKET_NODE_TYPE);
 		}
 
 		pi->incoming=1;
@@ -508,8 +505,7 @@
 	/* Tell that we are willing to receive accept message. */
 	if (NgSendMsg(If->csock, LISTENHOOK, NGM_KSOCKET_COOKIE,
 	    NGM_KSOCKET_ACCEPT, NULL, 0) < 0) {
-		Log(LG_ERR, ("TCP: can't accept on %s node: %s",
-		    NG_KSOCKET_NODE_TYPE, strerror(errno)));
+		Perror("TCP: can't accept on %s node", NG_KSOCKET_NODE_TYPE);
 	}
 	EventRegister(&If->ctrlEvent, EVENT_READ, If->csock,
 	    0, TcpAcceptEvent, If);
@@ -756,8 +752,7 @@
 	
 	/* Create a new netgraph node */
 	if (NgMkSockNode(NULL, &pi->If->csock, NULL) < 0) {
-	    Log(LG_ERR, ("TCP: can't create ctrl socket: %s",
-	        strerror(errno)));
+	    Perror("TCP: can't create ctrl socket");
 	    return(0);
 	}
 	(void)fcntl(pi->If->csock, F_SETFD, 1);
@@ -772,8 +767,7 @@
 	}
 	if (NgSendMsg(pi->If->csock, ".:", NGM_GENERIC_COOKIE, NGM_MKPEER,
 	    &mkp, sizeof(mkp)) < 0) {
-		Log(LG_ERR, ("TCP: can't attach %s node: %s",
-		    NG_KSOCKET_NODE_TYPE, strerror(errno)));
+		Perror("TCP: can't attach %s node", NG_KSOCKET_NODE_TYPE);
 		goto fail2;
 	}
 
@@ -783,8 +777,7 @@
 	((int *)(ksso->value))[0]=1;
 	if (NgSendMsg(pi->If->csock, LISTENHOOK, NGM_KSOCKET_COOKIE,
 	    NGM_KSOCKET_SETOPT, &u, sizeof(u)) < 0) {
-		Log(LG_ERR, ("TCP: can't setsockopt() %s node: %s",
-		    NG_KSOCKET_NODE_TYPE, strerror(errno)));
+		Perror("TCP: can't setsockopt() %s node", NG_KSOCKET_NODE_TYPE);
 		goto fail2;
 	}
 
@@ -792,24 +785,21 @@
 	u_addrtosockaddr(&pi->If->self_addr, pi->If->self_port, &addr);
 	if (NgSendMsg(pi->If->csock, LISTENHOOK, NGM_KSOCKET_COOKIE,
 	    NGM_KSOCKET_BIND, &addr, addr.ss_len) < 0) {
-		Log(LG_ERR, ("TCP: can't bind() %s node: %s",
-		    NG_KSOCKET_NODE_TYPE, strerror(errno)));
+		Perror("TCP: can't bind() %s node", NG_KSOCKET_NODE_TYPE);
 		goto fail2;
 	}
 
 	/* Listen. */
 	if (NgSendMsg(pi->If->csock, LISTENHOOK, NGM_KSOCKET_COOKIE,
 	    NGM_KSOCKET_LISTEN, &backlog, sizeof(backlog)) < 0) {
-		Log(LG_ERR, ("TCP: can't listen() on %s node: %s",
-		    NG_KSOCKET_NODE_TYPE, strerror(errno)));
+		Perror("TCP: can't listen() on %s node", NG_KSOCKET_NODE_TYPE);
 		goto fail2;
 	}
 
 	/* Tell that we are willing to receive accept message. */
 	if (NgSendMsg(pi->If->csock, LISTENHOOK, NGM_KSOCKET_COOKIE,
 	    NGM_KSOCKET_ACCEPT, NULL, 0) < 0) {
-		Log(LG_ERR, ("TCP: can't accept() on %s node: %s",
-		    NG_KSOCKET_NODE_TYPE, strerror(errno)));
+		Perror("TCP: can't accept() on %s node", NG_KSOCKET_NODE_TYPE);
 		goto fail2;
 	}
 
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/udp.c
--- a/contrib/mpd/src/udp.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/udp.c	Fri Sep 14 02:13:58 2012 +0300
@@ -185,8 +185,13 @@
 UdpInst(Link l, Link lt)
 {
     UdpInfo	pi;
-    l->info = Mdup(MB_PHYS, lt->info, sizeof(struct udpinfo));
-    pi = (UdpInfo) l->info;
+    UdpInfo const pit = (UdpInfo) lt->info;
+
+    /* Initialize this link */
+    pi = (UdpInfo) (l->info = Mdup(MB_PHYS, lt->info, sizeof(*pi)));
+    if (pit->conf.fqdn_peer_addr != NULL)
+        pi->conf.fqdn_peer_addr =
+            Mstrdup(MB_PHYS, pit->conf.fqdn_peer_addr);
     
     if (pi->If)
 	pi->If->refs++;
@@ -216,8 +221,7 @@
 
 	/* Create a new netgraph node to control TCP ksocket node. */
 	if (NgMkSockNode(NULL, &csock, NULL) < 0) {
-		Log(LG_ERR, ("[%s] TCP can't create control socket: %s",
-		    l->name, strerror(errno)));
+		Perror("[%s] TCP can't create control socket", l->name);
 		goto fail;
 	}
 	(void)fcntl(csock, F_SETFD, 1);
@@ -228,6 +232,7 @@
         }
 
 	/* Attach ksocket node to PPP node */
+	memset(&mkp, 0, sizeof(mkp));
 	strcpy(mkp.type, NG_KSOCKET_NODE_TYPE);
 	strlcpy(mkp.ourhook, hook, sizeof(mkp.ourhook));
 	if ((pi->conf.self_addr.family==AF_INET6) || 
@@ -238,8 +243,8 @@
 	}
 	if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE,
 	    NGM_MKPEER, &mkp, sizeof(mkp)) < 0) {
-	        Log(LG_ERR, ("[%s] can't attach %s node: %s",
-	    	    l->name, NG_KSOCKET_NODE_TYPE, strerror(errno)));
+	        Perror("[%s] can't attach %s node",
+	    	    l->name, NG_KSOCKET_NODE_TYPE);
 		goto fail;
 	}
 
@@ -247,16 +252,15 @@
 	strlcat(path, hook, sizeof(path));
 
 	/* Give it a name */
+	memset(&nm, 0, sizeof(nm));
 	snprintf(nm.name, sizeof(nm.name), "mpd%d-%s-kso", gPid, l->name);
 	if (NgSendMsg(csock, path,
 	    NGM_GENERIC_COOKIE, NGM_NAME, &nm, sizeof(nm)) < 0) {
-		Log(LG_ERR, ("[%s] can't name %s node: %s",
-		    l->name, NG_KSOCKET_NODE_TYPE, strerror(errno)));
+		Perror("[%s] can't name %s node", l->name, NG_KSOCKET_NODE_TYPE);
 	}
 
 	if ((pi->node_id = NgGetNodeID(csock, path)) == 0) {
-	    Log(LG_ERR, ("[%s] Cannot get %s node id: %s",
-		l->name, NG_KSOCKET_NODE_TYPE, strerror(errno)));
+	    Perror("[%s] Cannot get %s node id", l->name, NG_KSOCKET_NODE_TYPE);
 	    goto fail;
 	};
 
@@ -267,8 +271,8 @@
 	((int *)(ksso->value))[0]=1;
 	if (NgSendMsg(csock, path, NGM_KSOCKET_COOKIE,
     	    NGM_KSOCKET_SETOPT, &u, sizeof(u)) < 0) {
-    	    Log(LG_ERR, ("[%s] can't setsockopt() %s node: %s",
-    		l->name, NG_KSOCKET_NODE_TYPE, strerror(errno)));
+    	    Perror("[%s] can't setsockopt() %s node",
+    		l->name, NG_KSOCKET_NODE_TYPE);
 	    goto fail;
 	}
 
@@ -283,8 +287,7 @@
 	u_addrtosockaddr(&pi->conf.self_addr, pi->conf.self_port, &addr);
 	if (NgSendMsg(csock, path, NGM_KSOCKET_COOKIE,
 	  NGM_KSOCKET_BIND, &addr, addr.ss_len) < 0) {
-	    Log(LG_ERR, ("[%s] can't bind() %s node: %s",
-    		l->name, NG_KSOCKET_NODE_TYPE, strerror(errno)));
+	    Perror("[%s] can't bind() %s node", l->name, NG_KSOCKET_NODE_TYPE);
 	    goto fail;
 	}
     }
@@ -303,8 +306,7 @@
     /* Connect socket if peer address and port is specified */
     if (NgSendMsg(csock, path, NGM_KSOCKET_COOKIE,
       NGM_KSOCKET_CONNECT, &addr, addr.ss_len) < 0) {
-	Log(LG_ERR, ("[%s] can't connect() %s node: %s",
-	    l->name, NG_KSOCKET_NODE_TYPE, strerror(errno)));
+	Perror("[%s] can't connect() %s node", l->name, NG_KSOCKET_NODE_TYPE);
 	goto fail;
     }
   
@@ -378,7 +380,7 @@
 
 	/* Get a temporary netgraph socket node */
 	if (NgMkSockNode(NULL, &csock, NULL) == -1) {
-		Log(LG_ERR, ("UDP: NgMkSockNode: %s", strerror(errno)));
+		Perror("UDP: NgMkSockNode");
 		return;
 	}
 	
@@ -657,16 +659,14 @@
 	/* Setsockopt socket. */
 	opt = 1;
 	if (setsockopt(pi->If->csock, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt))) {
-		Log(LG_ERR, ("UDP: can't setsockopt socket: %s",
-		    strerror(errno)));
+		Perror("UDP: can't setsockopt socket");
 		goto fail2;
 	};
 
 	/* Bind socket. */
 	u_addrtosockaddr(&pi->If->self_addr, pi->If->self_port, &addr);
 	if (bind(pi->If->csock, (struct sockaddr *)(&addr), addr.ss_len)) {
-		Log(LG_ERR, ("UDP: can't bind socket: %s",
-		    strerror(errno)));
+		Perror("UDP: can't bind socket");
 		goto fail2;
 	}
 
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/util.c
--- a/contrib/mpd/src/util.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/util.c	Fri Sep 14 02:13:58 2012 +0300
@@ -688,8 +688,7 @@
 
   if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
   {
-    Log(LG_ERR, ("[%s] can't set \"%s\" to non-blocking: %s",
-      label, path, strerror(errno)));
+    Perror("[%s] can't set \"%s\" to non-blocking", label, path);
     goto failed;
   }
 
@@ -697,8 +696,7 @@
 
   if (tcgetattr(fd, &attr) < 0)
   {
-    Log(LG_ERR, ("[%s] can't tcgetattr \"%s\": %s",
-      label, path, strerror(errno)));
+    Perror("[%s] can't tcgetattr \"%s\"", label, path);
     goto failed;
   }
 
@@ -715,8 +713,7 @@
 
   if (tcsetattr(fd, TCSANOW, &attr) < 0)
   {
-    Log(LG_ERR, ("[%s] can't tcsetattr \"%s\": %s",
-      label, path, strerror(errno)));
+    Perror("[%s] can't tcsetattr \"%s\"", label, path);
 failed:
     ExclusiveCloseDevice(label, fd, path);
     return(-1);
@@ -758,8 +755,7 @@
       && time(NULL) < startTime + MAX_OPEN_DELAY; )
     if (errno != EINTR)
     {
-      Log(LG_ERR, ("[%s] can't open %s: %s",
-	label, pathname, strerror(errno)));
+      Perror("[%s] can't open %s", label, pathname);
       if (locked)
 	UuUnlock(ttyname);
       return(-1);
@@ -799,8 +795,7 @@
       time(NULL) < startTime + MAX_OPEN_DELAY && (rtn = close(fd)) < 0; )
     if (errno != EINTR)
     {
-      Log(LG_ERR, ("[%s] can't close %s: %s",
-	label, pathname, strerror(errno)));
+      Perror("[%s] can't close %s", label, pathname);
       break;
     }
 
@@ -819,8 +814,7 @@
   {
     ttyname = pathname + 5;
     if (UuUnlock(ttyname) < 0)
-      Log(LG_ERR, ("[%s] can't unlock %s: %s",
-	label, ttyname, strerror(errno)));
+      Perror("[%s] can't unlock %s", label, ttyname);
   }
 }
 
@@ -1192,12 +1186,19 @@
   size_t	i, j;
   char		*buf;
   
-  buf = Malloc(MB_UTIL, len * 2 + 1);
-  for (i = j = 0; i < len; i++) {
-    buf[j++] = hexconvtab[bin[i] >> 4];
-    buf[j++] = hexconvtab[bin[i] & 15];
+  if (len > 0) {
+    buf = Malloc(MB_UTIL, len * 2 + 1);
+    for (i = j = 0; i < len; i++) {
+      buf[j++] = hexconvtab[bin[i] >> 4];
+      buf[j++] = hexconvtab[bin[i] & 15];
+    }
+    buf[j] = 0;
+  } else {
+    buf = Malloc(MB_UTIL, 3);
+    buf[0] = '0';
+    buf[1] = '0';
+    buf[2] = 0;
   }
-  buf[j] = 0;
   return buf;
 }
 
diff -r 370cf0e347e3 -r a245241eda54 contrib/mpd/src/web.c
--- a/contrib/mpd/src/web.c	Fri Sep 14 01:49:53 2012 +0300
+++ b/contrib/mpd/src/web.c	Fri Sep 14 02:13:58 2012 +0300
@@ -241,8 +241,8 @@
   fprintf(f, "<H2>Current status summary</H2>\n");
   fprintf(f, "<table>\n");
   fprintf(f, "<TR><TH>Bund</TH><TH colspan=2>Iface</TH><TH>IPCP</TH><TH>IPV6CP</TH><TH>CCP</TH><TH>ECP</TH>"
-	     "<TH>Link</TH><TH>LCP</TH><TH>User</TH><TH colspan=2>Device</TH><TH>Peer</TH><TH colspan=3></TH>%s</TR>",
-	     priv?"<TH></TH>":"");
+	     "<TH>Link</TH><TH>LCP</TH><TH>User</TH><TH colspan=2>Device</TH><TH>Peer</TH><TH>IP</TH><TH colspan=3></TH>%s</TR>",
+	     priv?"<TH>State</TH>":"");
 #define FSM_COLOR(s) (((s)==ST_OPENED)?"g":(((s)==ST_INITIAL)?"r":"y"))
 #define PHYS_COLOR(s) (((s)==PHYS_STATE_UP)?"g":(((s)==PHYS_STATE_DOWN)?"r":"y"))
     for (b = 0; b<gNumLinks; b++) {
@@ -262,6 +262,7 @@
 	    if (L->state != PHYS_STATE_DOWN) {
 		PhysGetPeerAddr(L, buf, sizeof(buf));
 		fprintf(f, "<TD>%s</TD>\n", buf);
+		fprintf(f, "<TD></TD>\n");
 		PhysGetCallingNum(L, buf, sizeof(buf));
 		PhysGetCalledNum(L, buf2, sizeof(buf2));
 		if (PhysGetOriginate(L) == LINK_ORIGINATE_REMOTE) {
@@ -273,12 +274,24 @@
 		}
 	    } else {
 	    	fprintf(f, "<TD></TD>\n");
+	    	fprintf(f, "<TD></TD>\n");
 	    	fprintf(f, "<TD colspan=3></TD>\n");
 	    }
 	    if (priv) {
 		if (!L->tmpl) {
-		    fprintf(f, "<TD><A href=\"/cmd?link%%20%s&open\">[Open]</a> <A href=\"/cmd?link%%20%s&close\">[Close]</a></TD>\n", 
-	    		L->name, L->name);
+		    switch (L->state) {
+			case PHYS_STATE_DOWN:
+			    fprintf(f, "<TD><A href=\"/cmd?link%%20%s&open\">[Open]</A></TD>\n",
+				L->name);
+			    break;
+			case PHYS_STATE_UP:
+			    fprintf(f, "<TD><A href=\"/cmd?link%%20%s&close\">[Close]</A></TD>\n",
+				L->name);
+			    break;
+			default:
+			    fprintf(f, "<TD><A href=\"/cmd?link%%20%s&open\">[Open]</a> <A href=\"/cmd?link%%20%s&close\">[Close]</a></TD>\n", 
+				L->name, L->name);
+		    }
 		} else {
 		    fprintf(f, "<TD></TD>\n");
 		}
@@ -306,7 +319,7 @@
 	fprintf(f, "<TD rowspan=\"%d\" class=\"%s\"><A href=\"/cmd?bund%%20%s&show%%20ecp\">%s</a></TD>\n", 
 	    rows, B->tmpl?"d":FSM_COLOR(B->ecp.fsm.state), B->name,FsmStateName(B->ecp.fsm.state));
 	if (B->n_links == 0) {
-	    fprintf(f, "<TD colspan=\"10\"> </a></TD>\n</TR>\n");
+	    fprintf(f, "<TD colspan=\"11\"> </a></TD>\n</TR>\n");
 	}
 	for (l = 0; l < NG_PPP_MAX_LINKS; l++) {
 	    if ((L=B->links[l]) != NULL) {
@@ -327,6 +340,10 @@
 		if (L->state != PHYS_STATE_DOWN) {
 		    PhysGetPeerAddr(L, buf, sizeof(buf));
 		    fprintf(f, "<TD>%s</TD>\n", buf);
+		    if (L->bund != NULL)
+			fprintf(f, "<TD>%s</TD>\n", inet_ntoa(L->bund->ipcp.peer_addr));
+		    else
+			fprintf(f, "<TD></TD>\n");
 		    PhysGetCallingNum(L, buf, sizeof(buf));
 		    PhysGetCalledNum(L, buf2, sizeof(buf2));
 		    if (PhysGetOriginate(L) == LINK_ORIGINATE_REMOTE) {
@@ -338,11 +355,23 @@
 		    }
 		} else {
 			fprintf(f, "<TD></TD>\n");
+			fprintf(f, "<TD></TD>\n");
 			fprintf(f, "<TD colspan=3></TD>\n");
 		}
 		if (priv) {
-		    fprintf(f, "<TD><A href=\"/cmd?link%%20%s&open\">[Open]</a><A href=\"/cmd?link%%20%s&close\">[Close]</a></TD>\n", 
-		    	L->name, L->name);
+		    switch (L->state) {
+			case PHYS_STATE_DOWN:
+			    fprintf(f, "<TD><A href=\"/cmd?link%%20%s&open\">[Open]</A></TD>\n",
+				L->name);
+			    break;
+			case PHYS_STATE_UP:
+			    fprintf(f, "<TD><A href=\"/cmd?link%%20%s&close\">[Close]</A></TD>\n",
+				L->name);
+			    break;
+			default:
+			    fprintf(f, "<TD><A href=\"/cmd?link%%20%s&open\">[Open]</a> <A href=\"/cmd?link%%20%s&close\">[Close]</a></TD>\n", 
+				L->name, L->name);
+		    }
 		}
 		fprintf(f, "</TR>\n");
 	    }
@@ -375,6 +404,10 @@
 		if (L->state != PHYS_STATE_DOWN) {
 		    PhysGetPeerAddr(L, buf, sizeof(buf));
 		    fprintf(f, "<TD>%s</TD>\n", buf);
+		    if (L->bund != NULL)
+			fprintf(f, "<TD>%s</TD>\n", inet_ntoa(L->bund->ipcp.peer_addr));
+		    else
+			fprintf(f, "<TD></TD>\n");
 		    PhysGetCallingNum(L, buf, sizeof(buf));
 		    PhysGetCalledNum(L, buf2, sizeof(buf2));
 		    if (PhysGetOriginate(L) == LINK_ORIGINATE_REMOTE) {
@@ -386,6 +419,7 @@
 		    }
 		} else {
 			fprintf(f, "<TD></TD>\n");
+			fprintf(f, "<TD></TD>\n");
 			fprintf(f, "<TD colspan=3></TD>\n");
 		}
 		fprintf(f, "<TD></TD>\n");
@@ -395,7 +429,7 @@
 	    }
 	}
 	if (!shown) {
-	    fprintf(f, "<TD colspan = \"10\"></TD>\n");
+	    fprintf(f, "<TD colspan = \"11\"></TD>\n");
 	    fprintf(f, "</TR>\n");
 	}
     }


More information about the Zrouter-src mailing list