]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
dst becomes brd as it's makes more sense as we mainly deal with ethernet.
authorRoy Marples <roy@marples.name>
Mon, 25 Apr 2016 10:58:18 +0000 (10:58 +0000)
committerRoy Marples <roy@marples.name>
Mon, 25 Apr 2016 10:58:18 +0000 (10:58 +0000)
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.

dhcp.c
dhcp.h
if-linux.c
if.c
ipv4.c
ipv4.h

diff --git a/dhcp.c b/dhcp.c
index c07d245b489c4477e5edd539154e15eb05bb6f14..3c966e92bec83fb6ba472378db65e7298cf7a0bc 100644 (file)
--- 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 241a584ff417a42061673e57a04309c1e5bddcd6..f5f9e52f2d0e21b1c784acad6d74e1a6d3dea0af 100644 (file)
--- 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)];
index 3ac8dd20852fbc7fa502f1c3b60226370b54bd05..737d247b8beb633a609d13a5c61edc506a91fb3b 100644 (file)
@@ -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 8715a9e61bfdff99d24d934e779cfc60edadccd5..b51b2d28a4065f797b8fec80cf77504066a191a1 100644 (file)
--- 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 a00f705b2e560edf5f3193c65fbb8aaa91e4572e..ff2413f960d3656e6ee2da98cd02ae4c4185e1ef 100644 (file)
--- 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 f38d0ce1c8c3a93871ec4369fae1615b345fbfe2..91484aaa825b4b28aa50c37990a0c26ddf33b103 100644 (file)
--- 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;
 };