Skip to content

Commit 79e62be

Browse files
committed
Linux: set broadcast flag by default for ipvlan interfaces.
1 parent 0e93962 commit 79e62be

File tree

2 files changed

+18
-29
lines changed

2 files changed

+18
-29
lines changed

src/common.h

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
#define ROUNDUP4(a) (1 + (((a) - 1) | 3))
6464
#define ROUNDUP8(a) (1 + (((a) - 1) | 7))
6565

66+
#ifndef FIELD_SIZEOF
67+
#define FIELD_SIZEOF(t, f) sizeof(((t *)0)->f)
68+
#endif
69+
6670
/* Some systems don't define timespec macros */
6771
#ifndef timespecclear
6872
#define timespecclear(tsp) (tsp)->tv_sec = (time_t)((tsp)->tv_nsec = 0L)

src/if-linux.c

+14-29
Original file line numberDiff line numberDiff line change
@@ -310,44 +310,29 @@ if_init(struct interface *ifp)
310310
return if_writepathuint(ifp->ctx, path, 1) == -1 ? -1 : 0;
311311
}
312312

313-
/* Returns number of bytes written to driver, 0 on error.
314-
* @driverlen note that sizeof(ethtool_drvinfo.driver) = 32 */
313+
/* Returns number of bytes written to driver, else 0 (error or indeterminate). */
315314
static size_t
316-
if_get_driver(const char *ifname, char *driver, const size_t driverlen)
315+
if_get_driver(struct interface *ifp, char *driver, const size_t driverlen)
317316
{
318-
struct ifreq ifr = { .ifr_flags = 0 };
319-
struct ethtool_drvinfo drvinfo;
320-
int fd;
321-
size_t n = 0;
317+
struct ethtool_drvinfo drvinfo = { .cmd = ETHTOOL_GDRVINFO };
318+
struct ifreq ifr = { .ifr_data = (void *)&drvinfo };
322319

323-
fd = socket(AF_INET, SOCK_STREAM, 0);
324-
if (fd == -1) {
325-
logerr("%s: socket ifname=%s", __func__, ifname);
326-
goto eexit;
327-
}
328-
memset(&ifr, 0, sizeof(ifr));
329-
strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
330-
drvinfo.cmd = ETHTOOL_GDRVINFO;
331-
ifr.ifr_data = (void *)&drvinfo;
332-
if (ioctl(fd, SIOCETHTOOL, &ifr) == -1) {
333-
logerr("%s: SIOCETHTOOL ifname=%s", __func__, ifname);
334-
goto eexit;
320+
strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
321+
if (ioctl(ifp->ctx->pf_inet_fd, SIOCETHTOOL, &ifr) != 0) {
322+
logerr("%s: SIOCETHTOOL ifname=%s", __func__, ifp->name);
323+
return 0; /* 0 means error or indeterminate driver name */
335324
}
336-
n = strlcpy(driver, drvinfo.driver, driverlen);
337-
eexit:
338-
if (fd != -1)
339-
close(fd);
340-
return n;
325+
return strlcpy(driver, drvinfo.driver, driverlen);
341326
}
342327

343328
static bool
344-
if_cmp_driver(const char *ifname, const char *driver)
329+
if_cmp_driver(struct interface *ifp, const char *driver)
345330
{
346-
char ifdriver[32]; /* see ethtool_drvinfo.driver declaration */
347-
size_t n = if_get_driver(ifname, ifdriver, sizeof(ifdriver));
331+
char ifdriver[FIELD_SIZEOF(struct ethtool_drvinfo, driver)];
332+
size_t n = if_get_driver(ifp, ifdriver, sizeof(ifdriver));
348333

349334
if (n == 0) {
350-
logerr("%s: if_get_driver ifname=%s", __func__, ifname);
335+
logerr("%s: if_get_driver ifname=%s", __func__, ifp->name);
351336
return false;
352337
}
353338
if (strncmp(ifdriver, driver, n) == 0)
@@ -358,7 +343,7 @@ if_cmp_driver(const char *ifname, const char *driver)
358343
static bool
359344
if_ipvlan(struct interface *ifp)
360345
{
361-
if (if_cmp_driver(ifp->name, "ipvlan"))
346+
if (if_cmp_driver(ifp, "ipvlan"))
362347
return true;
363348
return false;
364349
}

0 commit comments

Comments
 (0)