# # Patch for OpenBSD's ifconfig that should # allow changing of link-layer address for a given # interface (eg. MAC address on Ethernet). # Adapted by Michal Ludvig # See http://www.logix.cz/michal/devel/openbsd-lladdr/ for more info. # Index: ifconfig.8 =================================================================== RCS file: /cvs/src/sbin/ifconfig/ifconfig.8,v retrieving revision 1.59 diff -u -p -r1.59 ifconfig.8 --- ifconfig.8 14 Nov 2002 02:57:27 -0000 1.59 +++ ifconfig.8 15 Nov 2002 09:23:51 -0000 @@ -238,6 +238,16 @@ for some Ethernet cards. Refer to the man page for the specific driver for more information. .It Fl link[0-2] Disable special processing at the link level with the specified interface. +.It Cm lladdr Ar hwaddr +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 hwaddr +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 Set the media type of the interface to .Ar type . Index: ifconfig.c =================================================================== RCS file: /cvs/src/sbin/ifconfig/ifconfig.c,v retrieving revision 1.69 diff -u -p -r1.69 ifconfig.c --- ifconfig.c 8 Jul 2002 00:48:54 -0000 1.69 +++ ifconfig.c 15 Nov 2002 09:23:52 -0000 @@ -171,6 +171,7 @@ void setifbroadaddr(char *); void setifipdst(char *); void setifmetric(char *); void setifmtu(char *, int); +void setiflladdr(char *, int); void setifnwid(const char *, int); void setifnwkey(const char *, int); void setifpowersave(const char *, int); @@ -251,6 +252,7 @@ const struct cmd { { "netmask", NEXTARG, 0, setifnetmask }, { "metric", NEXTARG, 0, setifmetric }, { "mtu", NEXTARG, 0, setifmtu }, + { "lladdr", NEXTARG, 0, setiflladdr }, { "nwid", NEXTARG, 0, setifnwid }, { "nwkey", NEXTARG, 0, setifnwkey }, { "-nwkey", -1, 0, setifnwkey }, @@ -1034,6 +1036,28 @@ setifmtu(val, d) warn("SIOCSIFMTU"); } +void +setiflladdr(val, d) + char *val; + int d; +{ + 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("SIOCSIFLLADDR"); + + return; +} + const char * get_string(val, sep, buf, lenp) const char *val, *sep; @@ -2594,7 +2618,7 @@ usage() "[ netmask mask ] ]\n" "\t[ media media_type ] [ mediaopt media_option ]\n" "\t[ metric n ]\n" - "\t[ mtu n ]\n" + "\t[ mtu n ] [ lladdr hwaddr ]\n" "\t[ nwid network_id ] [ nwkey network_key | -nwkey ]\n" "\t[ powersave | -powersave ] [ powersavesleep duration ]\n" "\t[ [af] tunnel srcaddress dstaddress ] [ deletetunnel ]\n"