summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/if-bsd.c2
-rw-r--r--src/if-sun.c2
-rw-r--r--src/ipv4.c31
-rw-r--r--src/ipv4.h2
4 files changed, 37 insertions, 0 deletions
diff --git a/src/if-bsd.c b/src/if-bsd.c
index aa488397..e5ffe500 100644
--- a/src/if-bsd.c
+++ b/src/if-bsd.c
@@ -627,6 +627,8 @@ if_findsa(struct dhcpcd_ctx *ctx, const struct sockaddr *sa)
sin = (const void *)sa;
if ((ia = ipv4_findmaskaddr(ctx, &sin->sin_addr)))
return ia->iface;
+ if ((ia = ipv4_findmaskbrd(ctx, &sin->sin_addr)))
+ return ia->iface;
break;
}
#endif
diff --git a/src/if-sun.c b/src/if-sun.c
index 27a18087..d25bbc81 100644
--- a/src/if-sun.c
+++ b/src/if-sun.c
@@ -533,6 +533,8 @@ if_findsa(struct dhcpcd_ctx *ctx, const struct sockaddr *sa)
sin = (const void *)sa;
if ((ia = ipv4_findmaskaddr(ctx, &sin->sin_addr)))
return ia->iface;
+ if ((ia = ipv4_findmaskbrd(ctx, &sin->sin_addr)))
+ return ia->iface;
break;
}
#endif
diff --git a/src/ipv4.c b/src/ipv4.c
index 866486c2..7bf7db38 100644
--- a/src/ipv4.c
+++ b/src/ipv4.c
@@ -170,6 +170,23 @@ ipv4_iffindmaskaddr(struct interface *ifp, const struct in_addr *addr)
return NULL;
}
+static struct ipv4_addr *
+ipv4_iffindmaskbrd(struct interface *ifp, const struct in_addr *addr)
+{
+ struct ipv4_state *state;
+ struct ipv4_addr *ap;
+
+ state = IPV4_STATE(ifp);
+ if (state) {
+ TAILQ_FOREACH (ap, &state->addrs, next) {
+ if ((ap->brd.s_addr & ap->mask.s_addr) ==
+ (addr->s_addr & ap->mask.s_addr))
+ return ap;
+ }
+ }
+ return NULL;
+}
+
struct ipv4_addr *
ipv4_findaddr(struct dhcpcd_ctx *ctx, const struct in_addr *addr)
{
@@ -198,6 +215,20 @@ ipv4_findmaskaddr(struct dhcpcd_ctx *ctx, const struct in_addr *addr)
return NULL;
}
+struct ipv4_addr *
+ipv4_findmaskbrd(struct dhcpcd_ctx *ctx, const struct in_addr *addr)
+{
+ struct interface *ifp;
+ struct ipv4_addr *ap;
+
+ TAILQ_FOREACH(ifp, ctx->ifaces, next) {
+ ap = ipv4_iffindmaskbrd(ifp, addr);
+ if (ap)
+ return ap;
+ }
+ return NULL;
+}
+
int
ipv4_hasaddr(const struct interface *ifp)
{
diff --git a/src/ipv4.h b/src/ipv4.h
index 6cf5654d..6c0ac8e8 100644
--- a/src/ipv4.h
+++ b/src/ipv4.h
@@ -143,6 +143,8 @@ struct ipv4_addr *ipv4_iffindlladdr(struct interface *);
struct ipv4_addr *ipv4_findaddr(struct dhcpcd_ctx *, const struct in_addr *);
struct ipv4_addr *ipv4_findmaskaddr(struct dhcpcd_ctx *,
const struct in_addr *);
+struct ipv4_addr *ipv4_findmaskbrd(struct dhcpcd_ctx *,
+ const struct in_addr *);
void ipv4_markaddrsstale(struct interface *);
void ipv4_deletestaleaddrs(struct interface *);
void ipv4_handleifa(struct dhcpcd_ctx *, int, struct if_head *, const char *,