]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
BSD: Find the correct interface for tunneled routes
authorRoy Marples <roy@marples.name>
Tue, 9 Feb 2021 10:11:54 +0000 (10:11 +0000)
committerRoy Marples <roy@marples.name>
Tue, 9 Feb 2021 10:11:54 +0000 (10:11 +0000)
Should disard a harmless diagnostic.

src/if-bsd.c
src/if-sun.c
src/ipv4.c
src/ipv4.h

index aa4883979b53c2ada88dbc2093b80795577c8d14..e5ffe500655fb795fc9fd1a3c1e1242d609d92c8 100644 (file)
@@ -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
index 27a1808750c252dd63da32096d373ce53a717be9..d25bbc817a29a2edd6e726f612302f69de9262d9 100644 (file)
@@ -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
index 866486c2f328c5a5beea4cfcc1c6c004e25c3f85..7bf7db38278ae5854e56c9c246dfef97ef4221c4 100644 (file)
@@ -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)
 {
index 6cf5654d9c989ea2086c6591d19a78d54a5930aa..6c0ac8e889bc9b86eaa8862b89e80daf6d47eddd 100644 (file)
@@ -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 *,