Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/if-bsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ os_init(void)

int
if_init(__unused struct interface *iface)
{
/* No extra init needed. */
return 0;
}

int
if_init_os(__unused struct interface *iface)
{
/* BSD promotes secondary address by default */
return 0;
Expand Down
27 changes: 27 additions & 0 deletions src/if-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,33 @@ if_writepathuint(struct dhcpcd_ctx *ctx, const char *path, unsigned int val)

int
if_init(struct interface *ifp)
{
struct dhcpcd_ctx *ctx = ifp->ctx;
struct ifreq ifr = { .ifr_flags = 0 };
int err = 0;

if (ifp->index != 0)
return 0;

/* This is a huge bug in getifaddrs(3) as there
* is no reason why this can't be returned in
* ifa_addr. */
strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
if (ioctl(ctx->pf_inet_fd, SIOCGIFHWADDR, &ifr) == -1) {
logerr("%s: SIOCGIFHWADDR", ifp->name);
err = -1;
} else
ifp->hwtype = ifr.ifr_hwaddr.sa_family;
if (ioctl(ctx->pf_inet_fd, SIOCGIFINDEX, &ifr) == -1) {
logerr("%s: SIOCGIFINDEX", ifp->name);
err = -1;
} else
ifp->index = (unsigned int)ifr.ifr_ifindex;
return err;
}

int
if_init_os(struct interface *ifp)
{
char path[sizeof(PROC_PROMOTE) + IF_NAMESIZE];
int n;
Expand Down
6 changes: 6 additions & 0 deletions src/if-sun.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ os_init(void)

int
if_init(struct interface *ifp)
{
return 0;
}

int
if_init_os(struct interface *ifp)
{
#ifdef INET
if (if_plumb(RTM_NEWADDR, ifp->ctx, AF_INET, ifp->name) == -1 &&
Expand Down
34 changes: 13 additions & 21 deletions src/if.c
Original file line number Diff line number Diff line change
Expand Up @@ -400,15 +400,17 @@ if_valid_hwaddr(const uint8_t *hwaddr, size_t hwlen)
return false;
}

#if defined(AF_PACKET) && !defined(AF_LINK)
#ifndef AF_LINK
static unsigned int
if_check_arphrd(struct interface *ifp, unsigned int active, bool if_noconf)
{
switch (ifp->hwtype) {
#ifdef ARPHRD_NONE
case ARPHRD_NONE: /* FALLTHROUGH */
#endif
case ARPHRD_ETHER: /* FALLTHROUGH */
case ARPHRD_IEEE1394: /* FALLTHROUGH */
case ARPHRD_INFINIBAND: /* FALLTHROUGH */
case ARPHRD_NONE: /* FALLTHROUGH */
break;
case ARPHRD_LOOPBACK:
case ARPHRD_PPP:
Expand Down Expand Up @@ -659,32 +661,22 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs, int argc,
ifp->hwlen = sll->sll_halen;
if (ifp->hwlen != 0)
memcpy(ifp->hwaddr, sll->sll_addr, ifp->hwlen);
active = if_check_arphrd(ifp, active, if_noconf);
#endif
}
#ifdef __linux__
else {
struct ifreq ifr = { .ifr_flags = 0 };

/* This is a huge bug in getifaddrs(3) as there
* is no reason why this can't be returned in
* ifa_addr. */
strlcpy(ifr.ifr_name, ifa->ifa_name,
sizeof(ifr.ifr_name));
if (ioctl(ctx->pf_inet_fd, SIOCGIFHWADDR, &ifr) == -1)
logerr("%s: SIOCGIFHWADDR", ifa->ifa_name);
ifp->hwtype = ifr.ifr_hwaddr.sa_family;
if (ioctl(ctx->pf_inet_fd, SIOCGIFINDEX, &ifr) == -1)
logerr("%s: SIOCGIFINDEX", ifa->ifa_name);
ifp->index = (unsigned int)ifr.ifr_ifindex;
if_check_arphrd(ifp, active, if_noconf);

if (if_init(ifp) == -1) {
logerr("%s: if_init", ifp->name);
if_free(ifp);
continue;
}
#ifndef AF_LINK
active = if_check_arphrd(ifp, active, if_noconf);
#endif

if (!(ctx->options & (DHCPCD_DUMPLEASE | DHCPCD_TEST))) {
/* Handle any platform init for the interface */
if (active != IF_INACTIVE && if_init(ifp) == -1) {
logerr("%s: if_init", ifp->name);
if (active != IF_INACTIVE && if_init_os(ifp) == -1) {
logerr("%s: if_init_os", ifp->name);
if_free(ifp);
continue;
}
Expand Down
5 changes: 3 additions & 2 deletions src/if.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,9 @@ int if_nametospec(const char *, struct if_spec *);

/* The below functions are provided by if-KERNEL.c */
int os_init(void);
int if_conf(struct interface *);
int if_init(struct interface *);
int if_init(struct interface *); /* init interface from kernel */
int if_init_os(struct interface *); /* init kernel from interface */
int if_conf(struct interface *); /* finish configuration from kernel */
int if_getssid(struct interface *);
int if_ignoregroup(int, const char *);
bool if_ignore(struct dhcpcd_ctx *, const char *);
Expand Down