diff options
author | wpaul <wpaul@FreeBSD.org> | 2000-06-16 20:14:43 +0000 |
---|---|---|
committer | wpaul <wpaul@FreeBSD.org> | 2000-06-16 20:14:43 +0000 |
commit | 82e4a377a336192df9c5242f53d08e055da24e00 (patch) | |
tree | f225e48869329753bc302bb25eb70daa24458634 /sbin/ifconfig | |
parent | f0880172c7dc6b2cfe0fe129d1d11ea81b53a287 (diff) | |
download | FreeBSD-src-82e4a377a336192df9c5242f53d08e055da24e00.zip FreeBSD-src-82e4a377a336192df9c5242f53d08e055da24e00.tar.gz |
Implement SIOCSIFLLADDR, which allows you to change the link-level
address on an interface. This basically allows you to do what my
little setmac module/utility does via ifconfig. This involves the
following changes:
socket.h: define SIOCSIFLLADDR
if.c: add support for SIOCSIFLLADDR, which resets the values in
the arpcom struct and sockaddr_dl for the specified interface.
Note that if the interface is already up, we need to down/up
it in order to program the underlying hardware's receive filter.
ifconfig.c: add lladdr command
ifconfig.8: document lladdr command
You can now force the MAC address on any ethernet interface to be
whatever you want. (The change is not sticky across reboots of course:
we don't actually reprogram the EEPROM or anything.) Actually, you
can reprogram the MAC address on other kinds of interfaces too; this
shouldn't be ethernet-specific (though at the moment it's limited to
6 bytes of address data).
Nobody ran up to me and said "this is the politically correct way to
do this!" so I don't want to hear any complaints from people who think
I could have done it more elegantly. Consider yourselves lucky I didn't
do it by having ifconfig tread all over /dev/kmem.
Diffstat (limited to 'sbin/ifconfig')
-rw-r--r-- | sbin/ifconfig/ifconfig.8 | 10 | ||||
-rw-r--r-- | sbin/ifconfig/ifconfig.c | 27 |
2 files changed, 36 insertions, 1 deletions
diff --git a/sbin/ifconfig/ifconfig.8 b/sbin/ifconfig/ifconfig.8 index cd0c6c6..e564010 100644 --- a/sbin/ifconfig/ifconfig.8 +++ b/sbin/ifconfig/ifconfig.8 @@ -189,6 +189,16 @@ This action does not automatically disable routes using the interface. .\" IP encapsulation of .\" .Tn CLNP .\" packets is done differently. +.It Cm lladdr Ar addr +Set the link-level address on an interface. This can be used to +e.g. set a new MAC address on an ethernet interface, though the +mechanism used is not ethernet-specific. The address +.Ar addr +is specified as a series of colon-separated hex digits. +If the interface is already +up when this option is used, it will be briefly brought down and +then brought back up again in order to insure that the receive +filter in the underlying ethernet hardware is properly reprogrammed. .It Cm media Ar type If the driver supports the media selection system, set the media type of the interface to diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index a3c75ca..52d403d 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -53,6 +53,7 @@ static const char rcsid[] = #include <sys/module.h> #include <sys/linker.h> +#include <net/ethernet.h> #include <net/if.h> #include <net/if_var.h> #include <net/if_dl.h> @@ -153,7 +154,7 @@ c_func setifprefixlen; c_func setip6flags; #endif c_func setifipdst; -c_func setifflags, setifmetric, setifmtu; +c_func setifflags, setifmetric, setifmtu, setiflladdr; #define NEXTARG 0xffffff @@ -212,6 +213,7 @@ struct cmd { { "compress", IFF_LINK0, setifflags }, { "noicmp", IFF_LINK1, setifflags }, { "mtu", NEXTARG, setifmtu }, + { "lladdr", NEXTARG, setiflladdr }, { 0, 0, setifaddr }, { 0, 0, setifdstaddr }, }; @@ -815,6 +817,29 @@ setifmtu(val, dummy, s, afp) warn("ioctl (set mtu)"); } +void +setiflladdr(val, dummy, s, afp) + const char *val; + int dummy __unused; + int s; + const struct afswtch *afp; +{ + struct ether_addr *ea; + + ea = ether_aton(val); + if (ea == NULL) { + warn("malformed link-level address"); + return; + } + strncpy(ifr.ifr_name, name, sizeof (ifr.ifr_name)); + ifr.ifr_addr.sa_len = ETHER_ADDR_LEN; + ifr.ifr_addr.sa_family = AF_LINK; + bcopy(ea, ifr.ifr_addr.sa_data, ETHER_ADDR_LEN); + if (ioctl(s, SIOCSIFLLADDR, (caddr_t)&ifr) < 0) + warn("ioctl (set lladdr)"); + + return; +} #define IFFBITS \ "\020\1UP\2BROADCAST\3DEBUG\4LOOPBACK\5POINTOPOINT\6SMART\7RUNNING" \ |