Module Name: src Committed By: christos Date: Mon Feb 1 16:47:00 UTC 2016
Modified Files: src/external/bsd/dhcpcd/dist: if-bsd.c ipv4.c ipv4.h Log Message: Handle static routes in IPv4. Routing messages for static routes have a gateway address of AF_INET, not AF_LINK. Find the interface for that gateway. XXX: We need to do the same for IPv6... To generate a diff of this commit: cvs rdiff -u -r1.26 -r1.27 src/external/bsd/dhcpcd/dist/if-bsd.c cvs rdiff -u -r1.19 -r1.20 src/external/bsd/dhcpcd/dist/ipv4.c cvs rdiff -u -r1.14 -r1.15 src/external/bsd/dhcpcd/dist/ipv4.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/external/bsd/dhcpcd/dist/if-bsd.c diff -u src/external/bsd/dhcpcd/dist/if-bsd.c:1.26 src/external/bsd/dhcpcd/dist/if-bsd.c:1.27 --- src/external/bsd/dhcpcd/dist/if-bsd.c:1.26 Thu Jan 7 15:09:43 2016 +++ src/external/bsd/dhcpcd/dist/if-bsd.c Mon Feb 1 11:47:00 2016 @@ -1,5 +1,5 @@ #include <sys/cdefs.h> - __RCSID("$NetBSD: if-bsd.c,v 1.26 2016/01/07 20:09:43 roy Exp $"); + __RCSID("$NetBSD: if-bsd.c,v 1.27 2016/02/01 16:47:00 christos Exp $"); /* * dhcpcd - DHCP client daemon @@ -466,6 +466,8 @@ if_copyrt(struct dhcpcd_ctx *ctx, struct char *cp; struct sockaddr *sa, *rti_info[RTAX_MAX]; struct sockaddr_dl *sdl; + struct sockaddr_in *sin; + struct ipv4_addr *ia; cp = (char *)(void *)(rtm + 1); sa = (struct sockaddr *)(void *)cp; @@ -504,9 +506,22 @@ if_copyrt(struct dhcpcd_ctx *ctx, struct sdl = (struct sockaddr_dl *)(void *)rti_info[RTAX_IFP]; rt->iface = if_findsdl(ctx, sdl); } else if (rtm->rtm_addrs & RTA_GATEWAY) { - sdl = (struct sockaddr_dl *)(void *)rti_info[RTAX_GATEWAY]; - if (sdl->sdl_family == AF_LINK) + sa = rti_info[RTAX_GATEWAY]; + switch (sa->sa_family) { + case AF_LINK: + sdl = (void *)sa; rt->iface = if_findsdl(ctx, sdl); + break; + case AF_INET: + sin = (void *)sa; + if ((ia = ipv4_findmaskaddr(ctx, &sin->sin_addr))) + rt->iface = ia->iface; + break; + default: + logger(ctx, LOG_ERR, "%s: Bad family %d", __func__, + sa->sa_family); + return -1; + } } /* If we don't have an interface and it's a host route, it maybe @@ -514,8 +529,6 @@ if_copyrt(struct dhcpcd_ctx *ctx, struct if (rt->iface == NULL && !(~rtm->rtm_flags & (RTF_HOST | RTF_GATEWAY))) { - struct ipv4_addr *ia; - if ((ia = ipv4_findaddr(ctx, &rt->dest))) rt->iface = ia->iface; } Index: src/external/bsd/dhcpcd/dist/ipv4.c diff -u src/external/bsd/dhcpcd/dist/ipv4.c:1.19 src/external/bsd/dhcpcd/dist/ipv4.c:1.20 --- src/external/bsd/dhcpcd/dist/ipv4.c:1.19 Thu Jan 7 15:09:43 2016 +++ src/external/bsd/dhcpcd/dist/ipv4.c Mon Feb 1 11:47:00 2016 @@ -1,5 +1,5 @@ #include <sys/cdefs.h> - __RCSID("$NetBSD: ipv4.c,v 1.19 2016/01/07 20:09:43 roy Exp $"); + __RCSID("$NetBSD: ipv4.c,v 1.20 2016/02/01 16:47:00 christos Exp $"); /* * dhcpcd - DHCP client daemon @@ -132,6 +132,23 @@ ipv4_iffindaddr(struct interface *ifp, return NULL; } +static struct ipv4_addr * +ipv4_iffindmaskaddr(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->addr.s_addr & ap->net.s_addr) == + (addr->s_addr & ap->net.s_addr)) + return ap; + } + } + return NULL; +} + struct ipv4_addr * ipv4_iffindlladdr(struct interface *ifp) { @@ -162,6 +179,20 @@ ipv4_findaddr(struct dhcpcd_ctx *ctx, co return NULL; } +struct ipv4_addr * +ipv4_findmaskaddr(struct dhcpcd_ctx *ctx, const struct in_addr *addr) +{ + struct interface *ifp; + struct ipv4_addr *ap; + + TAILQ_FOREACH(ifp, ctx->ifaces, next) { + ap = ipv4_iffindmaskaddr(ifp, addr); + if (ap) + return ap; + } + return NULL; +} + int ipv4_srcaddr(const struct rt *rt, struct in_addr *addr) { Index: src/external/bsd/dhcpcd/dist/ipv4.h diff -u src/external/bsd/dhcpcd/dist/ipv4.h:1.14 src/external/bsd/dhcpcd/dist/ipv4.h:1.15 --- src/external/bsd/dhcpcd/dist/ipv4.h:1.14 Mon Nov 30 11:33:00 2015 +++ src/external/bsd/dhcpcd/dist/ipv4.h Mon Feb 1 11:47:00 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: ipv4.h,v 1.14 2015/11/30 16:33:00 roy Exp $ */ +/* $NetBSD: ipv4.h,v 1.15 2016/02/01 16:47:00 christos Exp $ */ /* * dhcpcd - DHCP client daemon @@ -123,6 +123,8 @@ struct ipv4_addr *ipv4_iffindaddr(struct const struct in_addr *, const struct in_addr *); 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 *); int ipv4_srcaddr(const struct rt *, struct in_addr *); void ipv4_handleifa(struct dhcpcd_ctx *, int, struct if_head *, const char *, const struct in_addr *, const struct in_addr *, const struct in_addr *,