From: Roy Marples Date: Mon, 25 Apr 2016 10:58:18 +0000 (+0000) Subject: dst becomes brd as it's makes more sense as we mainly deal with ethernet. X-Git-Tag: v6.11.0~79 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fbf8f9ae3b6ddabe1b1707fd79cf2e7b6879c43e;p=thirdparty%2Fdhcpcd.git dst becomes brd as it's makes more sense as we mainly deal with ethernet. Ensure that handleifa is always passed brd. If brd does not match existing broadcast address on an existing inet address, delete it and add our new one. --- diff --git a/dhcp.c b/dhcp.c index c07d245b..3c966e92 100644 --- a/dhcp.c +++ b/dhcp.c @@ -2995,7 +2995,7 @@ dhcp_handlepacket(void *arg) continue; } if (ifp->flags & IFF_POINTOPOINT && - state->dst.s_addr != from.s_addr) + state->brd.s_addr != from.s_addr) { logger(ifp->ctx, LOG_WARNING, "%s: server %s is not destination", @@ -3453,7 +3453,7 @@ void dhcp_handleifa(int cmd, struct interface *ifp, const struct in_addr *addr, const struct in_addr *net, - const struct in_addr *dst, + const struct in_addr *brd, int flags) { struct dhcp_state *state; @@ -3504,11 +3504,11 @@ dhcp_handleifa(int cmd, struct interface *ifp, state->new = dhcp_message_new(addr, net); if (state->new == NULL) return; - state->dst.s_addr = dst ? dst->s_addr : INADDR_ANY; - if (dst) { + state->brd = *brd; + if (ifp->flags & IFF_POINTOPOINT) { for (i = 1; i < 255; i++) if (i != DHO_ROUTER && has_option_mask(ifo->dstmask,i)) - dhcp_message_add_addr(state->new, i, *dst); + dhcp_message_add_addr(state->new, i, *brd); } state->reason = "STATIC"; ipv4_buildroutes(ifp->ctx); @@ -3516,7 +3516,7 @@ dhcp_handleifa(int cmd, struct interface *ifp, if (ifo->options & DHCPCD_INFORM) { state->state = DHS_INFORM; state->xid = dhcp_xid(ifp); - state->lease.server.s_addr = dst ? dst->s_addr : INADDR_ANY; + state->lease.server = *brd; state->addr = *addr; state->net = *net; dhcp_inform(ifp); diff --git a/dhcp.h b/dhcp.h index 241a584f..f5f9e52f 100644 --- a/dhcp.h +++ b/dhcp.h @@ -215,7 +215,7 @@ struct dhcp_state { int raw_fd; struct in_addr addr; struct in_addr net; - struct in_addr dst; + struct in_addr brd; uint8_t added; char leasefile[sizeof(LEASEFILE) + IF_NAMESIZE + (IF_SSIDLEN * 4)]; diff --git a/if-linux.c b/if-linux.c index 3ac8dd20..737d247b 100644 --- a/if-linux.c +++ b/if-linux.c @@ -630,7 +630,7 @@ link_addr(struct dhcpcd_ctx *ctx, struct interface *ifp, struct nlmsghdr *nlm) struct ifaddrmsg *ifa; struct priv *priv; #ifdef INET - struct in_addr addr, net, dest; + struct in_addr addr, net, brd; #endif #ifdef INET6 struct in6_addr addr6; @@ -661,26 +661,29 @@ link_addr(struct dhcpcd_ctx *ctx, struct interface *ifp, struct nlmsghdr *nlm) switch (ifa->ifa_family) { #ifdef INET case AF_INET: - addr.s_addr = dest.s_addr = INADDR_ANY; - dest.s_addr = INADDR_ANY; + addr.s_addr = dest.s_addr = brd.s_addr = INADDR_ANY; inet_cidrtoaddr(ifa->ifa_prefixlen, &net); while (RTA_OK(rta, len)) { switch (rta->rta_type) { case IFA_ADDRESS: if (ifp->flags & IFF_POINTOPOINT) { - memcpy(&dest.s_addr, RTA_DATA(rta), - sizeof(addr.s_addr)); + memcpy(&brd.s_addr, RTA_DATA(rta), + sizeof(brd.s_addr)); } break; + case IFA_BROADCAST: + memcpy(&brd.s_addr, RTA_DATA(rta), + sizeof(brd.s_addr)); + break; case IFA_LOCAL: memcpy(&addr.s_addr, RTA_DATA(rta), - sizeof(addr.s_addr)); + sizeof(addr.s_addr)); break; } rta = RTA_NEXT(rta, len); } ipv4_handleifa(ctx, nlm->nlmsg_type, NULL, ifp->name, - &addr, &net, &dest, ifa->ifa_flags); + &addr, &net, &brd, ifa->ifa_flags); break; #endif #ifdef INET6 diff --git a/if.c b/if.c index 8715a9e6..b51b2d28 100644 --- a/if.c +++ b/if.c @@ -192,7 +192,7 @@ static void if_learnaddrs(struct dhcpcd_ctx *ctx, struct if_head *ifs, struct ifaddrs *ifa; struct interface *ifp; #ifdef INET - const struct sockaddr_in *addr, *net, *dst; + const struct sockaddr_in *addr, *net, *brd; #endif #ifdef INET6 struct sockaddr_in6 *sin6, *net6; @@ -211,15 +211,14 @@ static void if_learnaddrs(struct dhcpcd_ctx *ctx, struct if_head *ifs, addr = (void *)ifa->ifa_addr; net = (void *)ifa->ifa_netmask; if (ifa->ifa_flags & IFF_POINTOPOINT) - dst = (const struct sockaddr_in *) + brd = (const struct sockaddr_in *) (void *)ifa->ifa_dstaddr; else - dst = NULL; + brd = (void *)ifa->ifa_broadaddr; ifa_flags = if_addrflags(&addr->sin_addr, ifp); ipv4_handleifa(ctx, RTM_NEWADDR, ifs, ifa->ifa_name, - &addr->sin_addr, - &net->sin_addr, - dst ? &dst->sin_addr : NULL, ifa_flags); + &addr->sin_addr, &net->sin_addr, &brd->sin_addr, + ifa_flags); break; #endif #ifdef INET6 diff --git a/ipv4.c b/ipv4.c index a00f705b..ff2413f9 100644 --- a/ipv4.c +++ b/ipv4.c @@ -676,7 +676,7 @@ add_destination_route(struct rt_head *rt, const struct interface *ifp) } r->dest.s_addr = INADDR_ANY; r->net.s_addr = INADDR_ANY; - r->gate.s_addr = state->dst.s_addr; + r->gate.s_addr = state->brd.s_addr; r->mtu = dhcp_get_mtu(ifp); r->src = state->addr; TAILQ_INSERT_HEAD(rt, r, next); @@ -1026,6 +1026,7 @@ ipv4_addaddr(struct interface *ifp, const struct in_addr *addr, ia->iface = ifp; ia->addr = *addr; ia->net = *mask; + ia->brd = *bcast; #ifdef IN_IFF_TENTATIVE ia->addr_flags = IN_IFF_TENTATIVE; #endif @@ -1158,9 +1159,10 @@ ipv4_applyaddr(void *arg) } } - /* If the netmask is different, delete the addresss */ + /* If the netmask or broadcast is different, delete the addresss */ ap = ipv4_iffindaddr(ifp, &lease->addr, NULL); - if (ap && ap->net.s_addr != lease->net.s_addr) + if (ap && (ap->net.s_addr != lease->net.s_addr || + ap->brd.s_addr != lease->brd.s_addr)) ipv4_deladdr(ifp, &ap->addr, &ap->net, 0); if (ipv4_iffindaddr(ifp, &lease->addr, &lease->net)) @@ -1216,7 +1218,7 @@ void ipv4_handleifa(struct dhcpcd_ctx *ctx, int cmd, struct if_head *ifs, const char *ifname, const struct in_addr *addr, const struct in_addr *net, - const struct in_addr *dst, int flags) + const struct in_addr *brd, int flags) { struct interface *ifp; struct ipv4_state *state; @@ -1249,10 +1251,7 @@ ipv4_handleifa(struct dhcpcd_ctx *ctx, ap->iface = ifp; ap->addr = *addr; ap->net = *net; - if (dst) - ap->dst.s_addr = dst->s_addr; - else - ap->dst.s_addr = INADDR_ANY; + ap->brd = *brd; TAILQ_INSERT_TAIL(&state->addrs, ap, next); } ap->addr_flags = flags; @@ -1264,7 +1263,7 @@ ipv4_handleifa(struct dhcpcd_ctx *ctx, } arp_handleifa(cmd, ifp, addr, flags); - dhcp_handleifa(cmd, ifp, addr, net, dst, flags); + dhcp_handleifa(cmd, ifp, addr, net, brd, flags); } void diff --git a/ipv4.h b/ipv4.h index f38d0ce1..91484aaa 100644 --- a/ipv4.h +++ b/ipv4.h @@ -72,7 +72,7 @@ struct ipv4_addr { TAILQ_ENTRY(ipv4_addr) next; struct in_addr addr; struct in_addr net; - struct in_addr dst; + struct in_addr brd; struct interface *iface; int addr_flags; };