Skip to content

Commit a900878

Browse files
committed
Actually work on NetBSD
1 parent acaf53d commit a900878

5 files changed

Lines changed: 53 additions & 12 deletions

File tree

src/dhcp.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,10 +1303,12 @@ dhcp_handlebootp(struct interface *ifp, struct bootp *bootp, size_t len,
13031303
wanted = dhcp_lease_findaddr(ctx, &paddr);
13041304
if (wanted != NULL && !dhcp_lease_avail(lease, wanted, &now)) {
13051305
logwarnx(
1306-
"%s: plugin assigned address unavailable: 0x%x %s",
1306+
"%s: plugin assigned address in-use: 0x%x %s",
13071307
ifp->if_name, bootp->xid, inet_ntoa(paddr));
1308+
#if 0
13081309
paddr.s_addr = INADDR_ANY;
13091310
wanted = NULL;
1311+
#endif
13101312
}
13111313
break;
13121314
}

src/dhcpsd.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,6 @@ main(int argc, char **argv)
470470
logerr("%s: PF_INET", __func__);
471471
goto exit;
472472
}
473-
if (ctx.ctx_options & DHCPSD_RUN)
474-
goto run;
475473

476474
#ifdef IFLR_ACTIVE
477475
ctx.ctx_pf_link_fd = xsocket(PF_LINK, SOCK_DGRAM | SOCK_CLOEXEC, 0);
@@ -481,6 +479,9 @@ main(int argc, char **argv)
481479
}
482480
#endif
483481

482+
if (ctx.ctx_options & DHCPSD_RUN)
483+
goto run;
484+
484485
if (link_open(&ctx) == -1) {
485486
logerr("%s: link_open", __func__);
486487
goto exit;

src/if.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,17 @@ if_sockaddr_active(struct ctx *ctx, const char *if_name,
164164
{
165165
#ifdef IFLR_ACTIVE
166166
const struct sockaddr_dl *sdl = (const void *)sa;
167-
struct if_laddrreq iflr = { .flags = IFLR_PREFIX };
167+
struct if_laddrreq iflr = {
168+
.flags = IFLR_PREFIX,
169+
.prefixlen = (unsigned int)sdl->sdl_alen * NBBY,
170+
};
168171

169172
strlcpy(iflr.iflr_name, if_name, sizeof(iflr.iflr_name));
170173
memcpy(&iflr.addr, sa, MIN(sa->sa_len, sizeof(iflr.addr)));
171-
iflr.flags = IFLR_PREFIX;
172-
iflr.prefixlen = (unsigned int)sdl->sdl_alen * NBBY;
173-
if (ioctl(ctx->ctx_pf_link_fd, SIOCGLIFADDR, &iflr) == -1 ||
174-
!(iflr.flags & IFLR_ACTIVE))
174+
175+
if (ioctl(ctx->ctx_pf_link_fd, SIOCGLIFADDR, &iflr) == -1)
176+
return 0;
177+
if (!(iflr.flags & IFLR_ACTIVE))
175178
return 0;
176179
#else
177180
UNUSED(ctx);
@@ -330,7 +333,8 @@ if_findifpfromcmsg(struct ctx *ctx, struct msghdr *msg, void *to)
330333

331334
if (unpriv_learnif(ifp) == -1) {
332335
logerr("%s: unpriv_learnif", __func__);
333-
if_free(ifp);
336+
/* Avoid neededless checks */
337+
free(ifp);
334338
return NULL;
335339
}
336340

@@ -345,7 +349,7 @@ if_findifpfromcmsg(struct ctx *ctx, struct msghdr *msg, void *to)
345349
}
346350
}
347351
if (ifp->if_flags & IF_ACTIVE) {
348-
loginfox("%s: activated interface (%d)", ifp->if_name,
352+
logdebugx("%s: activated interface (%d)", ifp->if_name,
349353
ifp->if_index);
350354
if (dhcpsd_configure_pools(ifp) == -1) {
351355
logerr("%s: dhcpsd_configure_pools",

src/netlink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ netlink_link(struct link_ctx *lctx, struct nlmsghdr *nlm)
149149
return 0;
150150

151151
if (nlm->nlmsg_type == RTM_DELLINK)
152-
loginfox("%s: interface departed", ifp->if_name);
152+
loginfox("%s: interface has departed", ifp->if_name);
153153
else if (!(ifi->ifi_flags & IFF_UP))
154154
loginfox("%s: interface is down", ifp->if_name);
155155
else

src/route.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <net/if.h>
3131
#include <net/route.h>
3232

33+
#include <errno.h>
3334
#include <stddef.h>
3435
#include <stdlib.h>
3536
#include <unistd.h>
@@ -77,6 +78,34 @@ route_dispatch_ifinfo(struct link_ctx *lctx, struct rt_msghdr *rtm)
7778
if_free(ifp);
7879
}
7980

81+
#ifdef RTM_IFANNOUNCE
82+
static void
83+
route_dispatch_ifannounce(struct link_ctx *lctx, const struct rt_msghdr *rtm)
84+
{
85+
struct ctx *ctx = lctx->link_ctx;
86+
const struct if_announcemsghdr *ifan = (const struct if_announcemsghdr *)rtm;
87+
struct interface *ifp;
88+
89+
if (rtm->rtm_msglen < sizeof(*ifan))
90+
return;
91+
92+
if (ifan->ifan_what != IFAN_DEPARTURE)
93+
return;
94+
95+
/* Interface has departed, remove it from consideration. */
96+
TAILQ_FOREACH(ifp, ctx->ctx_ifaces, if_next) {
97+
if (ifp->if_index == ifan->ifan_index)
98+
break;
99+
}
100+
if (ifp == NULL)
101+
return;
102+
103+
logwarnx("%s: interface has departed", ifp->if_name);
104+
TAILQ_REMOVE(ctx->ctx_ifaces, ifp, if_next);
105+
if_free(ifp);
106+
}
107+
#endif
108+
80109
static void
81110
route_dispatch(void *arg, unsigned short e)
82111
{
@@ -105,6 +134,11 @@ route_dispatch(void *arg, unsigned short e)
105134
case RTM_IFINFO:
106135
route_dispatch_ifinfo(lctx, &rtm.hdr);
107136
break;
137+
#ifdef RTM_IFANNOUNCE
138+
case RTM_IFANNOUNCE:
139+
route_dispatch_ifannounce(lctx, &rtm.hdr);
140+
break;
141+
#endif
108142
default:
109143
/* Ignore other messages */
110144
break;
@@ -185,4 +219,4 @@ link_free(struct ctx *ctx)
185219
close(lctx->link_fd);
186220
free(lctx);
187221
ctx->ctx_link = NULL;
188-
}
222+
}

0 commit comments

Comments
 (0)