From owner-freebsd-bugs@FreeBSD.ORG Mon Aug 3 09:10:03 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 269AE106566C for ; Mon, 3 Aug 2009 09:10:03 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id A56F88FC13 for ; Mon, 3 Aug 2009 09:10:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n739A2j9055876 for ; Mon, 3 Aug 2009 09:10:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n739A2vd055868; Mon, 3 Aug 2009 09:10:02 GMT (envelope-from gnats) Resent-Date: Mon, 3 Aug 2009 09:10:02 GMT Resent-Message-Id: <200908030910.n739A2vd055868@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Aragon Gouveia Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 09D23106566B for ; Mon, 3 Aug 2009 09:08:26 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id DFF7C8FC0C for ; Mon, 3 Aug 2009 09:08:25 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n7398PqQ074132 for ; Mon, 3 Aug 2009 09:08:25 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id n7398P50074131; Mon, 3 Aug 2009 09:08:25 GMT (envelope-from nobody) Message-Id: <200908030908.n7398P50074131@www.freebsd.org> Date: Mon, 3 Aug 2009 09:08:25 GMT From: Aragon Gouveia To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: misc/137379: [patch] ppp(8) new command iface name to rename tun interface X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Aug 2009 09:10:03 -0000 >Number: 137379 >Category: misc >Synopsis: [patch] ppp(8) new command iface name to rename tun interface >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Mon Aug 03 09:10:02 UTC 2009 >Closed-Date: >Last-Modified: >Originator: Aragon Gouveia >Release: 7.1-STABLE >Organization: >Environment: FreeBSD igor.geek.sh 7.1-STABLE FreeBSD 7.1-STABLE #3: Wed Mar 11 14:24:50 SAST 2009 root@igor.geek.sh:/usr/src/sys/amd64/compile/IGOR amd64 >Description: FreeBSD has supported network interface renaming for some time now, and it is useful. I've written a patch for ppp(8) which allows it to rename the tun(4) interfaces that it clones. The patch adds a new command: iface name The patch also makes a small change to how ppp(8) destroys interfaces at exit. Instead of just dealiasing interfaces and leaving them behind, they are now destroyed in the same manner "ifconfig destroy" works. I believe this is the only correct way of enabling interface renaming without causing ppp to break when it is restarted. Please consider committing this patch. :) >How-To-Repeat: A sample ppp.conf might look like this: default: set log Phase Chat LCP LQM IPCP CCP tun command isdsl: set device PPPoE:adsl set authname XXX set authkey YYY set ifaddr 10.0.0.1/0 10.0.0.2/0 255.255.255.0 0.0.0.0 add default HISADDR enable dns iface name internet Which would result in: internet: flags=8051 metric 0 mtu 1492 inet 1.1.1.1 --> 2.2.2.2 netmask 0xffffff00 Opened by PID 1277 >Fix: Patch attached with submission follows: --- usr.sbin/ppp/bundle.c.orig 2009-08-03 08:55:49.000000000 +0200 +++ usr.sbin/ppp/bundle.c 2009-08-03 07:54:33.000000000 +0200 @@ -849,7 +849,9 @@ bundle.links = datalink_Create("deflink", &bundle, type); if (bundle.links == NULL) { log_Printf(LogALERT, "Cannot create data link: %s\n", strerror(errno)); - iface_Destroy(bundle.iface); + free(bundle.iface->name); + free(bundle.iface->addr); + free(bundle.iface); bundle.iface = NULL; close(bundle.dev.fd); return NULL; --- usr.sbin/ppp/command.c.orig 2009-08-03 05:47:48.000000000 +0200 +++ usr.sbin/ppp/command.c 2009-08-03 09:19:16.000000000 +0200 @@ -184,6 +184,7 @@ static int NegotiateCommand(struct cmdargs const *); static int ClearCommand(struct cmdargs const *); static int RunListCommand(struct cmdargs const *); +static int IfaceNameCommand(struct cmdargs const *); static int IfaceAddCommand(struct cmdargs const *); static int IfaceDeleteCommand(struct cmdargs const *); static int IfaceClearCommand(struct cmdargs const *); @@ -821,6 +822,8 @@ "Delete iface address", "iface delete addr", (void *)1}, {NULL, "delete!", IfaceDeleteCommand, LOCAL_AUTH, "Delete iface address", "iface delete addr", (void *)1}, + {"name", NULL, IfaceNameCommand, LOCAL_AUTH, + "Set iface name", "iface name [name]", NULL}, {"show", NULL, iface_Show, LOCAL_AUTH, "Show iface address(es)", "iface show", NULL}, {"help", "?", HelpCommand, LOCAL_AUTH | LOCAL_NO_AUTH, @@ -3174,6 +3177,18 @@ } static int +IfaceNameCommand(struct cmdargs const *arg) +{ + int n = arg->argn; + + if (arg->argc != n + 1) { + return -1; + } + + return !iface_Name(arg->bundle->iface, arg->argv[n]); +} + +static int IfaceAddCommand(struct cmdargs const *arg) { struct ncpaddr peer, addr; --- usr.sbin/ppp/iface.h.orig 2009-08-03 10:23:37.000000000 +0200 +++ usr.sbin/ppp/iface.h 2009-08-03 06:29:03.000000000 +0200 @@ -55,6 +55,7 @@ extern struct iface *iface_Create(const char *name); extern void iface_Clear(struct iface *, struct ncp *, int, int); +extern int iface_Name(struct iface *, const char *newname); extern int iface_Add(struct iface *, struct ncp *, const struct ncprange *, const struct ncpaddr *, int); extern int iface_Delete(struct iface *, struct ncp *, const struct ncpaddr *); --- usr.sbin/ppp/iface.c.orig 2009-08-03 05:20:46.000000000 +0200 +++ usr.sbin/ppp/iface.c 2009-08-03 09:20:00.000000000 +0200 @@ -369,6 +369,41 @@ return res != -1; } +int +iface_Name (struct iface *iface, const char *newname) +{ + struct ifreq ifr; + int s; + char *name; + + if (strlen(newname) > IF_NAMESIZE) { + log_Printf(LogWARN, "Invalid iface name: %s\n", newname); + return 0; + } + + if ((name = strdup(newname)) == NULL) { + log_Printf(LogWARN, "iface name: strdup failed: %s\n", strerror(errno)); + return 0; + } + + if ((s = ID0socket(PF_INET, SOCK_DGRAM, 0)) == -1) { + log_Printf(LogERROR, "iface name: socket(): %s\n", strerror(errno)); + return 0; + } + + strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name)); + ifr.ifr_data = (caddr_t)newname; + if (ID0ioctl(s, SIOCSIFNAME, (caddr_t)&ifr) < 0) { + log_Printf(LogWARN, "iface name: ioctl(SIOCSIFNAME, %s -> %s): %s\n", + name, newname, strerror(errno)); + return 0; + } + + free(iface->name); + iface->name = name; + return 1; +} + void iface_Clear(struct iface *iface, struct ncp *ncp, int family, int how) @@ -609,6 +644,8 @@ void iface_Destroy(struct iface *iface) { + struct ifreq ifr; + int s; /* * iface_Clear(iface, IFACE_CLEAR_ALL) must be called manually * if that's what the user wants. It's better to leave the interface @@ -616,6 +653,14 @@ */ if (iface != NULL) { + if ((s = ID0socket(PF_INET, SOCK_DGRAM, 0)) == -1) { + log_Printf(LogERROR, "iface_Destroy: socket(): %s\n", strerror(errno)); + } else { + strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name)); + if (ID0ioctl(s, SIOCIFDESTROY, (caddr_t)&ifr) < 0) + log_Printf(LogWARN, "iface_Destroy: ioctl(SIOCIFDESTROY, %s): %s\n", + iface->name, strerror(errno)); + } free(iface->name); free(iface->addr); free(iface); @@ -660,7 +705,9 @@ current = iface_Create(iface->name); flags = iface->flags = current->flags; - iface_Destroy(current); + free(current->name); + free(current->addr); + free(current); prompt_Printf(arg->prompt, "%s (idx %d) <", iface->name, iface->index); for (f = 0; f < sizeof if_flags / sizeof if_flags[0]; f++) --- usr.sbin/ppp/main.c.orig 2009-08-03 08:57:07.000000000 +0200 +++ usr.sbin/ppp/main.c 2009-08-03 07:21:27.000000000 +0200 @@ -385,11 +385,6 @@ /* NOTE: We may now have changed argv[1] via a ``set proctitle'' */ - if (prompt) { - prompt->bundle = bundle; /* couldn't do it earlier */ - if (!sw.quiet) - prompt_Printf(prompt, "Using interface: %s\n", bundle->iface->name); - } SignalBundle = bundle; bundle->NatEnabled = sw.nat; if (sw.nat) @@ -429,6 +424,12 @@ AbortProgram(EX_START); } + if (prompt) { + prompt->bundle = bundle; /* couldn't do it earlier */ + if (!sw.quiet) + prompt_Printf(prompt, "Using interface: %s\n", bundle->iface->name); + } + if (sw.mode != PHYS_INTERACTIVE) { if (sw.mode != PHYS_DIRECT) { if (!sw.fg) { --- usr.sbin/ppp/ppp.8.m4.orig 2009-08-03 09:56:32.000000000 +0200 +++ usr.sbin/ppp/ppp.8.m4 2009-08-03 09:55:03.000000000 +0200 @@ -3920,6 +3920,9 @@ .Dq !\& is used, no error is given if the address is not currently assigned to the interface (and no deletion takes place). +.It iface name Ar name +Renames interface to +.Ar name . .It iface show Shows the current state and current addresses for the interface. It is much the same as running >Release-Note: >Audit-Trail: >Unformatted: