summaryrefslogtreecommitdiff
path: root/sbin/ifconfig
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2008-09-07 02:22:35 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2008-09-07 02:22:35 +0000
commit64d2d76a3095de161b1e6076bfbf96906f56cf66 (patch)
treed059e234bcba5dde22be586fc8a7bebbcb44500b /sbin/ifconfig
parente1dd2b2d75e06369028b12cc55b65962eaeda221 (diff)
Allow some set-style commands to have zero arguments. If there is an
argument after that command, check if it is a keyword, and if it is, that means the original command really has no argument. Get it? Now.. replace -m with media (no options), and -M with chan (no options). Try 'ifconfig -a media chan' on a wireless & ethernet machine after this. ok henning, reyk, thanks for the comments from others
Diffstat (limited to 'sbin/ifconfig')
-rw-r--r--sbin/ifconfig/ifconfig.837
-rw-r--r--sbin/ifconfig/ifconfig.c105
2 files changed, 84 insertions, 58 deletions
diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8
index d01c945ce8e..e5b3cf3e007 100644
--- a/sbin/ifconfig/ifconfig.8
+++ b/sbin/ifconfig/ifconfig.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: ifconfig.8,v 1.164 2008/07/29 18:20:02 damien Exp $
+.\" $OpenBSD: ifconfig.8,v 1.165 2008/09/07 02:22:34 deraadt Exp $
.\" $NetBSD: ifconfig.8,v 1.11 1996/01/04 21:27:29 pk Exp $
.\" $FreeBSD: ifconfig.8,v 1.16 1998/02/01 07:03:29 steve Exp $
.\"
@@ -31,7 +31,7 @@
.\"
.\" @(#)ifconfig.8 8.4 (Berkeley) 6/1/94
.\"
-.Dd $Mdocdate: July 29 2008 $
+.Dd $Mdocdate: September 7 2008 $
.Dt IFCONFIG 8
.Os
.Sh NAME
@@ -39,7 +39,7 @@
.Nd configure network interface parameters
.Sh SYNOPSIS
.Nm ifconfig
-.Op Fl AaCm
+.Op Fl AaC
.Op Ar interface
.Op Ar address_family
.Oo
@@ -91,12 +91,6 @@ This is the default, if no parameters are given to
Print the names of all network pseudo-devices that
can be created dynamically at runtime using
.Cm ifconfig create .
-.It Fl m
-Print media information for a given interface.
-When combined with the
-.Fl Aa
-options,
-additionally prints media information for all interfaces.
.It Ar interface
The
.Ar interface
@@ -287,7 +281,7 @@ Disable special processing at the link level with the specified interface.
.It Cm lladdr Ar etheraddr
Change the link layer address (MAC address) of the interface.
This should be specified as six colon-separated hex values.
-.It Cm media Ar type
+.It Cm media Op Ar type
Set the media type of the interface to
.Ar type .
Some interfaces support the mutually exclusive use of one of several
@@ -309,7 +303,7 @@ list of the available types,
or use the following command
for a listing of choices:
.Pp
-.Dl $ ifconfig -m interface
+.Dl $ ifconfig interface media
.It Cm mediaopt Ar opts
Set the specified media options on the interface.
.Ar opts
@@ -319,7 +313,7 @@ list of available options,
or use the following command
for a listing of choices:
.Pp
-.Dl $ ifconfig -m interface
+.Dl $ ifconfig interface media
.It Fl mediaopt Ar opts
Disable the specified media options on the interface.
.It Cm metric Ar nhops
@@ -557,12 +551,11 @@ will begin advertising as master.
.Sh IEEE 802.11 (WIRELESS DEVICES)
.Nm ifconfig
.Bk -words
-.Op Fl M
.Ar wireless-interface
.Op Oo Fl Oc Cm bssid Ar bssid
.Op Oo Fl Oc Cm chan Ar n
.Op Oo Fl Oc Ns Cm nwflag Ar flag
-.Op Oo Fl Oc Cm nwid Ar id
+.Op Oo Fl Oc Cm nwid Op Ar id
.Op Oo Fl Oc Cm nwkey Ar key
.Op Oo Fl Oc Cm powersave
.Op Cm powersavesleep Ar duration
@@ -578,19 +571,21 @@ will begin advertising as master.
.Pp
The options are as follows:
.Bl -tag -width Ds
-.It Fl M
-Show the results of an access point scan.
-In Host AP mode, this will dump the list of known nodes without scanning.
.It Cm bssid Ar bssid
Set the desired BSSID for IEEE 802.11-based wireless network interfaces.
.It Fl bssid
Unset the desired BSSID for IEEE 802.11-based wireless network interfaces.
The interface will automatically select a BSSID in this mode, which is
the default.
-.It Cm chan Ar n
+.It Cm chan Op Ar n
Set the channel (radio frequency) to be used for IEEE 802.11-based
-wireless network interfaces from the given channel ID
+wireless network interfaces to
.Ar n .
+.Pp
+With no
+.Ar id
+specified, show the results of an access point scan.
+In Host AP mode, this will dump the list of known nodes without scanning.
.It Fl chan
Unset the desired channel to be used for IEEE 802.11-based wireless
network interfaces.
@@ -626,7 +621,7 @@ and
.Xr hostapd 8 .
.It Fl nwflag Ar flag
Remove a specified flag for the wireless network interface.
-.It Cm nwid Ar id
+.It Cm nwid Op Ar id
Configure network ID for IEEE 802.11-based wireless network interfaces.
The
.Ar id
@@ -1070,7 +1065,7 @@ Refer to the interface's driver-specific man page for a complete
list of the available protocols,
or use the following for a listing of choices:
.Pp
-.Dl $ ifconfig -m interface
+.Dl $ ifconfig interface media
.El
.\" TUNNEL
.Sh TUNNEL
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index d50fd369018..03b40456482 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ifconfig.c,v 1.202 2008/07/17 08:14:24 sthen Exp $ */
+/* $OpenBSD: ifconfig.c,v 1.203 2008/09/07 02:22:34 deraadt Exp $ */
/* $NetBSD: ifconfig.c,v 1.40 1997/10/01 02:19:43 enami Exp $ */
/*
@@ -123,13 +123,14 @@ u_long metric, mtu;
int clearaddr, s;
int newaddr = 0;
int af = AF_INET;
-int mflag;
-int net80211flag;
int explicit_prefix = 0;
#ifdef INET6
int Lflag = 1;
#endif /* INET6 */
+int showmediaflag;
+int shownet80211flag;
+
void notealias(const char *, int);
void notrailers(const char *, int);
void setifgroup(const char *, int);
@@ -251,9 +252,11 @@ int actions; /* Actions performed */
#define A_MEDIAOPT (A_MEDIAOPTSET|A_MEDIAOPTCLR)
#define A_MEDIAINST 0x0008 /* instance or inst command */
#define A_MEDIAMODE 0x0010 /* mode command */
+#define A_SILENT 0x8000000 /* doing operation, do not print */
-#define NEXTARG 0xffffff
-#define NEXTARG2 0xfffffe
+#define NEXTARG0 0xffffff
+#define NEXTARG 0xfffffe
+#define NEXTARG2 0xfffffd
const struct cmd {
char *c_name;
@@ -299,7 +302,7 @@ const struct cmd {
{ "wpaprotos", NEXTARG, 0, setifwpaprotos },
{ "wpapsk", NEXTARG, 0, setifwpapsk },
{ "-wpapsk", -1, 0, setifwpapsk },
- { "chan", NEXTARG, 0, setifchan },
+ { "chan", NEXTARG0, 0, setifchan },
{ "-chan", -1, 0, setifchan },
{ "powersave", 1, 0, setifpowersave },
{ "-powersave", 0, 0, setifpowersave },
@@ -381,7 +384,7 @@ const struct cmd {
{ "-link1", -IFF_LINK1, 0, setifflags } ,
{ "link2", IFF_LINK2, 0, setifflags } ,
{ "-link2", -IFF_LINK2, 0, setifflags } ,
- { "media", NEXTARG, A_MEDIA, setmedia },
+ { "media", NEXTARG0, A_MEDIA, setmedia },
{ "mediaopt", NEXTARG, A_MEDIAOPTSET, setmediaopt },
{ "-mediaopt", NEXTARG, A_MEDIAOPTCLR, unsetmediaopt },
{ "mode", NEXTARG, A_MEDIAMODE, setmediamode },
@@ -469,13 +472,14 @@ const struct afswtch {
const struct afswtch *afp; /*the address family being set or asked about*/
+int ifaliases = 0;
+int aflag = 0;
+
int
main(int argc, char *argv[])
{
const struct afswtch *rafp = NULL;
int create = 0;
- int aflag = 0;
- int ifaliases = 0;
int Cflag = 0;
int gflag = 0;
int i;
@@ -503,12 +507,6 @@ main(int argc, char *argv[])
case 'g':
gflag = 1;
break;
- case 'm':
- mflag = 1;
- break;
- case 'M':
- net80211flag = 1;
- break;
case 'C':
Cflag = 1;
nomore = 1;
@@ -540,7 +538,7 @@ main(int argc, char *argv[])
af = ifr.ifr_addr.sa_family = rafp->af_af;
}
if (Cflag) {
- if (argc > 0 || mflag || aflag)
+ if (argc > 0 || aflag)
usage(1);
list_cloners();
exit(0);
@@ -552,17 +550,7 @@ main(int argc, char *argv[])
setgroupattribs(name, argc, argv);
exit(0);
}
- if (aflag) {
- if (argc > 0)
- usage(0);
- printif(NULL, ifaliases);
- exit(0);
- }
(void) strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
- if (argc == 0) {
- printif(ifr.ifr_name, 1);
- exit(0);
- }
#ifdef INET6
/* initialization */
@@ -579,9 +567,11 @@ main(int argc, char *argv[])
if (argc == 0)
exit(0);
}
- create = (argc > 0) && strcmp(argv[0], "destroy") != 0;
- if (getinfo(&ifr, create) < 0)
- exit(1);
+ if (aflag == 0) {
+ create = (argc > 0) && strcmp(argv[0], "destroy") != 0;
+ if (getinfo(&ifr, create) < 0)
+ exit(1);
+ }
while (argc > 0) {
const struct cmd *p;
@@ -595,12 +585,31 @@ main(int argc, char *argv[])
errx(1, "%s: bad value", *argv);
}
if (p->c_func || p->c_func2) {
- if (p->c_parameter == NEXTARG) {
+ if (p->c_parameter == NEXTARG0) {
+ const struct cmd *p0;
+ int noarg = 1;
+
+ if (argv[1]) {
+ for (p0 = cmds; p0->c_name; p0++)
+ if (strcmp(argv[1], p0->c_name) == 0) {
+ noarg = 0;
+ break;
+ }
+ } else
+ noarg = 0;
+
+ if (noarg == 0)
+ (*p->c_func)(NULL, 0);
+ else
+ goto nextarg;
+ } else if (p->c_parameter == NEXTARG) {
+nextarg:
if (argv[1] == NULL)
errx(1, "'%s' requires argument",
p->c_name);
(*p->c_func)(argv[1], 0);
argc--, argv++;
+ actions = actions | A_SILENT | p->c_action;
} else if (p->c_parameter == NEXTARG2) {
if ((argv[1] == NULL) ||
(argv[2] == NULL))
@@ -609,13 +618,20 @@ main(int argc, char *argv[])
(*p->c_func2)(argv[1], argv[2]);
argc -= 2;
argv += 2;
- } else
+ actions = actions | A_SILENT | p->c_action;
+ } else {
(*p->c_func)(*argv, p->c_parameter);
- actions |= p->c_action;
+ actions = actions | A_SILENT | p->c_action;
+ }
}
argc--, argv++;
}
+ if (argc == 0 && actions == 0) {
+ printif(ifr.ifr_name, 1);
+ exit(0);
+ }
+
/* Process any media commands that may have been issued. */
process_media_commands();
@@ -797,6 +813,8 @@ printif(char *ifname, int ifaliases)
int count = 0, noinet = 1;
size_t nlen = 0;
+ if (aflag)
+ ifname = NULL;
if (ifname) {
if ((oname = strdup(ifname)) == NULL)
err(1, "strdup");
@@ -1601,6 +1619,12 @@ setifchan(const char *val, int d)
struct ieee80211chanreq channel;
int chan;
+ if (val == NULL) {
+ if (shownet80211flag)
+ usage(1);
+ shownet80211flag = 1;
+ return;
+ }
if (d != 0)
chan = IEEE80211_CHAN_ANY;
else {
@@ -1934,7 +1958,7 @@ ieee80211_status(void)
}
putchar('\n');
- if (net80211flag)
+ if (shownet80211flag)
ieee80211_listnodes();
}
@@ -2083,7 +2107,7 @@ process_media_commands(void)
ifr.ifr_media = media_current;
if (ioctl(s, SIOCSIFMEDIA, (caddr_t)&ifr) < 0)
- err(1, "SIOCSIFMEDIA");
+ ;
}
/* ARGSUSED */
@@ -2092,6 +2116,13 @@ setmedia(const char *val, int d)
{
int type, subtype, inst;
+ if (val == NULL) {
+ if (showmediaflag)
+ usage(1);
+ showmediaflag = 1;
+ return;
+ }
+
init_current_media();
/* Only one media command may be given. */
@@ -2630,7 +2661,7 @@ status(int link, struct sockaddr_dl *sdl)
ieee80211_status();
- if (mflag) {
+ if (showmediaflag) {
int type, printed_type = 0;
for (type = IFM_NMIN; type <= IFM_NMAX; type += IFM_NMIN) {
@@ -4055,7 +4086,7 @@ trunk_status(void)
putchar('\n');
}
- if (mflag) {
+ if (showmediaflag) {
printf("\tsupported trunk protocols:\n");
for (i = 0; i < (sizeof(tpr) / sizeof(tpr[0])); i++)
printf("\t\ttrunkproto %s\n", tpr[i].tpr_name);
@@ -4288,7 +4319,7 @@ void
usage(int value)
{
fprintf(stderr,
- "usage: ifconfig [-AaCm] [interface] [address_family] "
+ "usage: ifconfig [-AaC] [interface] [address_family] "
"[address [dest_address]]\n"
"\t\t[parameters]\n");
exit(value);