View | Details | Raw Unified | Return to bug 274092 | Differences between
and this patch

Collapse All | Expand All

(-)b/sys/dev/usb/net/if_smsc.c (-3 / +66 lines)
Lines 179-184 static const struct usb_device_id smsc_devs[] = { Link Here
179
#define ETHER_IS_VALID(addr) \
179
#define ETHER_IS_VALID(addr) \
180
	(!ETHER_IS_MULTICAST(addr) && !ETHER_IS_ZERO(addr))
180
	(!ETHER_IS_MULTICAST(addr) && !ETHER_IS_ZERO(addr))
181
181
182
#define BOOTARGS_SMSC95XX	"smsc95xx.macaddr"
183
182
static device_probe_t smsc_probe;
184
static device_probe_t smsc_probe;
183
static device_attach_t smsc_attach;
185
static device_attach_t smsc_attach;
184
static device_detach_t smsc_detach;
186
static device_detach_t smsc_detach;
Lines 1538-1543 smsc_ioctl(if_t ifp, u_long cmd, caddr_t data) Link Here
1538
	return (rc);
1540
	return (rc);
1539
}
1541
}
1540
1542
1543
static bool
1544
smsc_get_smsc95xx_macaddr(device_t dev, char* bootargs, size_t bootargs_len, struct usb_ether *ue)
1545
{
1546
	int values[6];
1547
	int i;
1548
	char* p;
1549
1550
	p = strnstr(bootargs, BOOTARGS_SMSC95XX, bootargs_len);
1551
1552
	if (6 != sscanf(p, BOOTARGS_SMSC95XX "=%x:%x:%x:%x:%x:%x%*c",
1553
			&values[0], &values[1], &values[2],
1554
			&values[3], &values[4], &values[5])) {
1555
		device_printf(dev, "invalid mac from bootargs '%s'.\n", p);
1556
		return false;
1557
	}
1558
1559
	for (i = 0; i < ETHER_ADDR_LEN; ++i)
1560
		ue->ue_eaddr[i] = values[i];
1561
1562
	smsc_dbg_printf(ue->ue_sc, "bootargs mac=%x:%x:%x:%x:%x:%x.\n",
1563
		ue->ue_eaddr[0], ue->ue_eaddr[1], ue->ue_eaddr[2],
1564
		ue->ue_eaddr[3], ue->ue_eaddr[4], ue->ue_eaddr[5]);
1565
	return true;
1566
}
1567
1568
/**
1569
 * Raspberry Pi is known to pass smsc95xx.macaddr=XX:XX:XX:XX:XX:XX via bootargs.
1570
 */
1571
static int
1572
smsc_bootargs_get_mac_addr(device_t dev, struct usb_ether *ue) {
1573
	struct smsc_softc *sc = device_get_softc(dev);
1574
	char bootargs[2048];         /* early stack supposedly big enough */
1575
	phandle_t node;
1576
1577
	/* only use bootargs for the first device to prevent duplicate mac addresses */
1578
	if (device_get_unit(dev) != 0)
1579
		return 1;
1580
	node = OF_finddevice("/chosen");
1581
	if (node == -1)
1582
		return 1;
1583
	if (OF_getproplen(node, "bootargs") > sizeof(bootargs)) {
1584
		smsc_err_printf(sc, "bootargs too large (%lu) for buffer", OF_getproplen(node, "bootargs"));
1585
		return 1;
1586
	}
1587
	if (OF_getprop(node, "bootargs", bootargs, sizeof(bootargs)) == -1)
1588
		return 1;
1589
	smsc_dbg_printf(sc, "bootargs: %s.\n", bootargs);
1590
	if (!smsc_get_smsc95xx_macaddr(dev, bootargs, sizeof(bootargs), ue))
1591
		return 1;
1592
	device_printf(dev, "Ethernet address found in bootargs %x:%x:%x:%x:%x:%x.\n",
1593
			ue->ue_eaddr[0], ue->ue_eaddr[1], ue->ue_eaddr[2],
1594
			ue->ue_eaddr[3], ue->ue_eaddr[4], ue->ue_eaddr[5]);
1595
	return 0;
1596
}
1597
1541
/**
1598
/**
1542
 *	smsc_attach_post - Called after the driver attached to the USB interface
1599
 *	smsc_attach_post - Called after the driver attached to the USB interface
1543
 *	@ue: the USB ethernet device
1600
 *	@ue: the USB ethernet device
Lines 1552-1559 static void Link Here
1552
smsc_attach_post(struct usb_ether *ue)
1609
smsc_attach_post(struct usb_ether *ue)
1553
{
1610
{
1554
	struct smsc_softc *sc = uether_getsc(ue);
1611
	struct smsc_softc *sc = uether_getsc(ue);
1612
	struct ether_addr eaddr;
1555
	uint32_t mac_h, mac_l;
1613
	uint32_t mac_h, mac_l;
1556
	int err;
1614
	int err;
1615
	int i;
1557
1616
1558
	smsc_dbg_printf(sc, "smsc_attach_post\n");
1617
	smsc_dbg_printf(sc, "smsc_attach_post\n");
1559
1618
Lines 1587-1595 smsc_attach_post(struct usb_ether *ue) Link Here
1587
			err = usb_fdt_get_mac_addr(sc->sc_ue.ue_dev, &sc->sc_ue);
1646
			err = usb_fdt_get_mac_addr(sc->sc_ue.ue_dev, &sc->sc_ue);
1588
#endif
1647
#endif
1589
		if ((err != 0) || (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr))) {
1648
		if ((err != 0) || (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr))) {
1590
			read_random(sc->sc_ue.ue_eaddr, ETHER_ADDR_LEN);
1649
			err = smsc_bootargs_get_mac_addr(sc->sc_ue.ue_dev, &sc->sc_ue);
1591
			sc->sc_ue.ue_eaddr[0] &= ~0x01;     /* unicast */
1650
		}
1592
			sc->sc_ue.ue_eaddr[0] |=  0x02;     /* locally administered */
1651
		if ((err != 0) || (!ETHER_IS_VALID(sc->sc_ue.ue_eaddr))) {
1652
			smsc_dbg_printf(sc, "No MAC address found. Using ether_gen_addr().\n");
1653
			ether_gen_addr_bydev(ue->ue_dev, &eaddr);
1654
			for (i = 0; i < ETHER_ADDR_LEN; i++)
1655
				sc->sc_ue.ue_eaddr[i] = eaddr.octet[i];
1593
		}
1656
		}
1594
	}
1657
	}
1595
1658
(-)b/sys/net/ethernet.h (+1 lines)
Lines 448-453 struct mbuf *ether_vlanencap_proto(struct mbuf *, uint16_t, uint16_t); Link Here
448
bool	ether_8021q_frame(struct mbuf **mp, struct ifnet *ife,
448
bool	ether_8021q_frame(struct mbuf **mp, struct ifnet *ife,
449
		struct ifnet *p, const struct ether_8021q_tag *);
449
		struct ifnet *p, const struct ether_8021q_tag *);
450
void	ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr);
450
void	ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr);
451
void	ether_gen_addr_bydev(device_t dev, struct ether_addr *hwaddr);
451
452
452
static __inline struct mbuf *ether_vlanencap(struct mbuf *m, uint16_t tag)
453
static __inline struct mbuf *ether_vlanencap(struct mbuf *m, uint16_t tag)
453
{
454
{
(-)b/sys/net/if_ethersubr.c (-3 / +14 lines)
Lines 38-43 Link Here
38
#include "opt_rss.h"
38
#include "opt_rss.h"
39
39
40
#include <sys/param.h>
40
#include <sys/param.h>
41
#include <sys/bus.h>
41
#include <sys/systm.h>
42
#include <sys/systm.h>
42
#include <sys/devctl.h>
43
#include <sys/devctl.h>
43
#include <sys/eventhandler.h>
44
#include <sys/eventhandler.h>
Lines 1488-1495 ether_8021q_frame(struct mbuf **mp, struct ifnet *ife, struct ifnet *p, Link Here
1488
 * Pseudo-interfaces which require a MAC address should use this function to
1489
 * Pseudo-interfaces which require a MAC address should use this function to
1489
 * allocate non-locally-administered addresses.
1490
 * allocate non-locally-administered addresses.
1490
 */
1491
 */
1491
void
1492
static void
1492
ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr)
1493
ether_gen_addr_byname(const char *nameunit, struct ether_addr *hwaddr)
1493
{
1494
{
1494
	SHA1_CTX ctx;
1495
	SHA1_CTX ctx;
1495
	char *buf;
1496
	char *buf;
Lines 1508-1514 ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr) Link Here
1508
	/* If each (vnet) jail would also have a unique hostuuid this would not
1509
	/* If each (vnet) jail would also have a unique hostuuid this would not
1509
	 * be necessary. */
1510
	 * be necessary. */
1510
	getjailname(curthread->td_ucred, jailname, sizeof(jailname));
1511
	getjailname(curthread->td_ucred, jailname, sizeof(jailname));
1511
	sz = asprintf(&buf, M_TEMP, "%s-%s-%s", uuid, if_name(ifp),
1512
	sz = asprintf(&buf, M_TEMP, "%s-%s-%s", uuid, nameunit,
1512
	    jailname);
1513
	    jailname);
1513
	if (sz < 0) {
1514
	if (sz < 0) {
1514
		/* Fall back to a random mac address. */
1515
		/* Fall back to a random mac address. */
Lines 1537-1541 ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr) Link Here
1537
	hwaddr->octet[0] |= 0x02;
1538
	hwaddr->octet[0] |= 0x02;
1538
}
1539
}
1539
1540
1541
void
1542
ether_gen_addr(struct ifnet *ifp, struct ether_addr *hwaddr) {
1543
	ether_gen_addr_byname(if_name(ifp), hwaddr);
1544
}
1545
1546
void
1547
ether_gen_addr_bydev(device_t dev, struct ether_addr *hwaddr) {
1548
	ether_gen_addr_byname(device_get_nameunit(dev), hwaddr);
1549
}
1550
1540
DECLARE_MODULE(ether, ether_mod, SI_SUB_INIT_IF, SI_ORDER_ANY);
1551
DECLARE_MODULE(ether, ether_mod, SI_SUB_INIT_IF, SI_ORDER_ANY);
1541
MODULE_VERSION(ether, 1);
1552
MODULE_VERSION(ether, 1);

Return to bug 274092