misc/137379: [patch] ppp(8) new command iface name to rename tun
interface
Aragon Gouveia
aragon at phat.za.net
Mon Aug 3 09:10:03 UTC 2009
>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 at 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 <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<UP,POINTOPOINT,RUNNING,MULTICAST> 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:
More information about the freebsd-bugs
mailing list