Add ifconfig support for network interface renaming. In the process,
reorganize the printing of the interface name when using wildcard cloning so it is not printed if it we either immediately rename or destroy the interface. Reviewed by: ru
This commit is contained in:
parent
36c19a572a
commit
97bebf0a28
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=125412
@ -322,6 +322,9 @@ this directive is used to select between 802.11a
|
||||
and 802.11g
|
||||
.Pq Dq 11g
|
||||
operating modes.
|
||||
.It Cm name Ar name
|
||||
Set the interface name to
|
||||
.Ar name .
|
||||
.It Cm rxcsum , txcsum
|
||||
If the driver supports user-configurable checksum offloading,
|
||||
enable receive (or transmit) checksum offloading on the interface.
|
||||
@ -353,7 +356,10 @@ Create the specified network pseudo-device.
|
||||
If the interface is given without a unit number, try to create a new
|
||||
device with an arbitrary unit number.
|
||||
If creation of an arbitrary device is successful, the new device name is
|
||||
printed to standard output.
|
||||
printed to standard output unless the interface is renamed or destroyed
|
||||
in the same
|
||||
.Nm
|
||||
invocation.
|
||||
.It Cm destroy
|
||||
Destroy the specified network pseudo-device.
|
||||
.It Cm plumb
|
||||
|
@ -129,6 +129,7 @@ struct afswtch;
|
||||
|
||||
int supmedia = 0;
|
||||
int listcloners = 0;
|
||||
int printname = 0; /* Print the name of the created interface. */
|
||||
|
||||
#ifdef INET6
|
||||
char addr_buf[MAXHOSTNAMELEN *2 + 1]; /*for getnameinfo()*/
|
||||
@ -172,6 +173,7 @@ c_func setip6eui64;
|
||||
c_func setifipdst;
|
||||
c_func setifflags, setifmetric, setifmtu, setifcap;
|
||||
c_func clone_destroy;
|
||||
c_func setifname;
|
||||
|
||||
|
||||
void clone_create(void);
|
||||
@ -286,6 +288,7 @@ struct cmd {
|
||||
{ "compress", IFF_LINK0, setifflags },
|
||||
{ "noicmp", IFF_LINK1, setifflags },
|
||||
{ "mtu", NEXTARG, setifmtu },
|
||||
{ "name", NEXTARG, setifname },
|
||||
{ 0, 0, setifaddr },
|
||||
{ 0, 0, setifdstaddr },
|
||||
};
|
||||
@ -525,7 +528,7 @@ main(int argc, char *argv[])
|
||||
clone_create();
|
||||
argc--, argv++;
|
||||
if (argc == 0)
|
||||
exit(0);
|
||||
goto end;
|
||||
}
|
||||
ifindex = if_nametoindex(name);
|
||||
if (ifindex == 0)
|
||||
@ -631,6 +634,9 @@ main(int argc, char *argv[])
|
||||
|
||||
if (namesonly && need_nl > 0)
|
||||
putchar('\n');
|
||||
end:
|
||||
if (printname)
|
||||
printf("%s\n", name);
|
||||
|
||||
exit (0);
|
||||
}
|
||||
@ -1039,6 +1045,30 @@ setifmtu(const char *val, int dummy __unused, int s,
|
||||
warn("ioctl (set mtu)");
|
||||
}
|
||||
|
||||
void
|
||||
setifname(const char *val, int dummy __unused, int s,
|
||||
const struct afswtch *afp)
|
||||
{
|
||||
char *newname;
|
||||
|
||||
newname = strdup(val);
|
||||
|
||||
ifr.ifr_data = newname;
|
||||
if (ioctl(s, SIOCSIFNAME, (caddr_t)&ifr) < 0) {
|
||||
warn("ioctl (set name)");
|
||||
free(newname);
|
||||
return;
|
||||
}
|
||||
strlcpy(name, newname, sizeof(name));
|
||||
free(newname);
|
||||
|
||||
/*
|
||||
* Even if we just created the interface, we don't need to print
|
||||
* its name because we just nailed it down separately.
|
||||
*/
|
||||
printname = 0;
|
||||
}
|
||||
|
||||
#define IFFBITS \
|
||||
"\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6SMART\7RUNNING" \
|
||||
"\10NOARP\11PROMISC\12ALLMULTI\13OACTIVE\14SIMPLEX\15LINK0\16LINK1\17LINK2" \
|
||||
@ -1885,8 +1915,13 @@ clone_create(void)
|
||||
if (ioctl(s, SIOCIFCREATE, &ifr) < 0)
|
||||
err(1, "SIOCIFCREATE");
|
||||
|
||||
/*
|
||||
* If we get a different name back then we put in, we probably
|
||||
* want to print it out, but we might change our mind later so
|
||||
* we just signal our intrest and leave the printout for later.
|
||||
*/
|
||||
if (strcmp(name, ifr.ifr_name) != 0) {
|
||||
printf("%s\n", ifr.ifr_name);
|
||||
printname = 1;
|
||||
strlcpy(name, ifr.ifr_name, sizeof(name));
|
||||
}
|
||||
|
||||
@ -1900,4 +1935,9 @@ clone_destroy(const char *val, int d, int s, const struct afswtch *rafp)
|
||||
(void) strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||
if (ioctl(s, SIOCIFDESTROY, &ifr) < 0)
|
||||
err(1, "SIOCIFDESTROY");
|
||||
/*
|
||||
* If we create and destroy an interface in the same command,
|
||||
* there isn't any reason to print it's name.
|
||||
*/
|
||||
printname = 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user