diff options
author | Felix Fietkau <nbd@nbd.name> | 2020-11-30 12:34:13 +0100 |
---|---|---|
committer | Felix Fietkau <nbd@nbd.name> | 2020-11-30 12:39:25 +0100 |
commit | 42c48866f1c1fce068f41536baa8dd2e80fc08d7 (patch) | |
tree | 439389ff79d44a5eb48c3fd5d3c60c0a5f36f024 /device.c | |
parent | 524310276f2084d419cb0f2de58b0f42641d987f (diff) | |
download | netifd-42c48866f1c1fce068f41536baa8dd2e80fc08d7.tar.gz |
config: parse default mac address from board.json
Example:
{
"network-device": {
"eth0": {
"macaddr": "bc:a5:11:16:76:d7"
}
}
}
Signed-off-by: Felix Fietkau <nbd@nbd.name>
Diffstat (limited to 'device.c')
-rw-r--r-- | device.c | 23 |
1 files changed, 17 insertions, 6 deletions
@@ -18,11 +18,6 @@ #include <sys/types.h> #include <sys/socket.h> -#include <net/ethernet.h> - -#ifdef linux -#include <netinet/ether.h> -#endif #include <libubox/list.h> @@ -232,7 +227,7 @@ device_merge_settings(struct device *dev, struct device_settings *n) n->txqueuelen = s->flags & DEV_OPT_TXQUEUELEN ? s->txqueuelen : os->txqueuelen; memcpy(n->macaddr, - (s->flags & DEV_OPT_MACADDR ? s->macaddr : os->macaddr), + (s->flags & (DEV_OPT_MACADDR|DEV_OPT_DEFAULT_MACADDR) ? s->macaddr : os->macaddr), sizeof(n->macaddr)); n->ipv6 = s->flags & DEV_OPT_IPV6 ? s->ipv6 : os->ipv6; n->promisc = s->flags & DEV_OPT_PROMISC ? s->promisc : os->promisc; @@ -430,6 +425,21 @@ void device_broadcast_event(struct device *dev, enum device_event ev) safe_list_for_each(&dev->users, device_broadcast_cb, &dev_ev); } +static void +device_fill_default_settings(struct device *dev) +{ + struct device_settings *s = &dev->settings; + struct ether_addr *ea; + + if (!(s->flags & DEV_OPT_MACADDR)) { + ea = config_get_default_macaddr(dev->ifname); + if (ea) { + memcpy(s->macaddr, ea, 6); + s->flags |= DEV_OPT_DEFAULT_MACADDR; + } + } +} + int device_claim(struct device_user *dep) { struct device *dev = dep->dev; @@ -447,6 +457,7 @@ int device_claim(struct device_user *dep) return 0; device_broadcast_event(dev, DEV_EVENT_SETUP); + device_fill_default_settings(dev); if (dev->external) { /* Get ifindex for external claimed devices so a valid */ /* ifindex is in place avoiding possible race conditions */ |