Skip to content

Commit 494f829

Browse files
committed
iface: refresh hw address when interface appears via netlink
getmac() is only called once during config parsing. If the interface does not exist at that point, ifi_hwaddr stays all-zeroes and IGMP queries are later sent with a source MAC of 00:00:00:00:00:00. Fix by calling config_iface_update() from iface_add(), so the hardware address is fetched at the moment the interface actually appears in the system. Fixes: #4 Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
1 parent f8106e4 commit 494f829

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/config.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,17 @@ static int getmac(const char *ifname, uint8_t *mac, size_t size)
100100
return rc;
101101
}
102102

103+
/*
104+
* Fetch (or re-fetch) the hardware address for an interface. Called when
105+
* an interface appears via netlink to handle the case where the interface
106+
* did not exist when the config was first parsed.
107+
*/
108+
void config_iface_update(struct ifi *ifi)
109+
{
110+
if (getmac(ifi->ifi_name, ifi->ifi_hwaddr, sizeof(ifi->ifi_hwaddr)))
111+
warn("failed finding hw address for iface %s", ifi->ifi_name);
112+
}
113+
103114
/*
104115
* Called by parser to add an interface to start or watch for in the future
105116
*/

src/defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ extern struct ifi *config_find_ifname(char *);
159159
extern struct ifi *config_find_ifaddr(in_addr_t);
160160
extern struct ifi *config_find_iface(int, int);
161161
extern struct ifi *config_init_tunnel(in_addr_t, in_addr_t, uint32_t);
162+
extern void config_iface_update(struct ifi *);
162163
extern void config_iface_addr_add(int, struct sockaddr *, unsigned int);
163164
extern void config_iface_init(void);
164165

src/iface.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ void iface_add(int ifindex, int flags)
193193

194194
dbg("Marking %s as now available in system", ifi->ifi_name);
195195
ifi->ifi_index = ifindex;
196+
config_iface_update(ifi);
196197

197198
iface_check(ifindex, flags);
198199
}

0 commit comments

Comments
 (0)