summaryrefslogtreecommitdiff
path: root/device.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2020-11-30 12:34:13 +0100
committerFelix Fietkau <nbd@nbd.name>2020-11-30 12:39:25 +0100
commit42c48866f1c1fce068f41536baa8dd2e80fc08d7 (patch)
tree439389ff79d44a5eb48c3fd5d3c60c0a5f36f024 /device.c
parent524310276f2084d419cb0f2de58b0f42641d987f (diff)
downloadnetifd-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.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/device.c b/device.c
index 627f1a2..73cc4bf 100644
--- a/device.c
+++ b/device.c
@@ -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 */