Mercurial > hg > dhcpcd
changeset 5168:1f5dc6102f9b draft
if: support changing hardware address type on Linux
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Thu, 23 Apr 2020 14:15:41 +0000 |
| parents | bb0276072b5d |
| children | f1a2ce25a64b |
| files | src/dhcpcd.c src/dhcpcd.h src/if-bsd.c src/if-linux.c src/if-sun.c |
| diffstat | 5 files changed, 22 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dhcpcd.c Thu Apr 23 13:40:03 2020 +0000 +++ b/src/dhcpcd.c Thu Apr 23 14:15:41 2020 +0000 @@ -1208,17 +1208,12 @@ } void -dhcpcd_handlehwaddr(struct dhcpcd_ctx *ctx, const char *ifname, - const void *hwaddr, uint8_t hwlen) +dhcpcd_handlehwaddr(struct interface *ifp, + uint16_t hwtype, const void *hwaddr, uint8_t hwlen) { - struct interface *ifp; char buf[sizeof(ifp->hwaddr) * 3]; - ifp = if_find(ctx->ifaces, ifname); - if (ifp == NULL) - return; - - if (!if_valid_hwaddr(hwaddr, hwlen)) + if (hwaddr == NULL || !if_valid_hwaddr(hwaddr, hwlen)) hwlen = 0; if (hwlen > sizeof(ifp->hwaddr)) { @@ -1227,7 +1222,14 @@ return; } - if (ifp->hwlen == hwlen && memcmp(ifp->hwaddr, hwaddr, hwlen) == 0) + if (ifp->hwtype != hwtype) { + loginfox("%s: hardware address type changed from %d to %d", + ifp->name, ifp->hwtype, hwtype); + ifp->hwtype = hwtype; + } + + if (ifp->hwlen == hwlen && + (hwlen == 0 || memcmp(ifp->hwaddr, hwaddr, hwlen) == 0)) return; loginfox("%s: new hardware address: %s", ifp->name,
--- a/src/dhcpcd.h Thu Apr 23 13:40:03 2020 +0000 +++ b/src/dhcpcd.h Thu Apr 23 14:15:41 2020 +0000 @@ -257,8 +257,7 @@ int dhcpcd_handleargs(struct dhcpcd_ctx *, struct fd_list *, int, char **); void dhcpcd_handlecarrier(struct dhcpcd_ctx *, int, unsigned int, const char *); int dhcpcd_handleinterface(void *, int, const char *); -void dhcpcd_handlehwaddr(struct dhcpcd_ctx *, const char *, - const void *, uint8_t); +void dhcpcd_handlehwaddr(struct interface *, uint16_t, const void *, uint8_t); void dhcpcd_dropinterface(struct interface *, const char *); int dhcpcd_selectprofile(struct interface *, const char *);
--- a/src/if-bsd.c Thu Apr 23 13:40:03 2020 +0000 +++ b/src/if-bsd.c Thu Apr 23 14:15:41 2020 +0000 @@ -1330,7 +1330,8 @@ break; #endif memcpy(&sdl, rti_info[RTAX_IFA], rti_info[RTAX_IFA]->sa_len); - dhcpcd_handlehwaddr(ctx, ifp->name, CLLADDR(&sdl),sdl.sdl_alen); + dhcpcd_handlehwaddr(ifp, ifp->hwtype, + CLLADDR(&sdl), sdl.sdl_alen); break; } #ifdef INET
--- a/src/if-linux.c Thu Apr 23 13:40:03 2020 +0000 +++ b/src/if-linux.c Thu Apr 23 14:15:41 2020 +0000 @@ -931,12 +931,13 @@ } /* Re-read hardware address and friends */ - if (!(ifi->ifi_flags & IFF_UP) && hwaddr) { - uint8_t l; + if (!(ifi->ifi_flags & IFF_UP)) { + void *hwa = hwaddr != NULL ? RTA_DATA(hwaddr) : NULL; + uint8_t hwl = l2addr_len(ifi->ifi_type); - l = l2addr_len(ifi->ifi_type); - if (hwaddr->rta_len == RTA_LENGTH(l)) - dhcpcd_handlehwaddr(ctx, ifn, RTA_DATA(hwaddr), l); + if (hwaddr != NULL && hwaddr->rta_len != RTA_LENGTH(hwl)) + hwa = NULL; + dhcpcd_handlehwaddr(ifp, ifi->ifi_type, hwa, hwl); } dhcpcd_handlecarrier(ctx,
--- a/src/if-sun.c Thu Apr 23 13:40:03 2020 +0000 +++ b/src/if-sun.c Thu Apr 23 14:15:41 2020 +0000 @@ -955,7 +955,8 @@ ifam->ifam_type != RTM_NEWADDR) break; memcpy(&sdl, rti_info[RTAX_IFA], sizeof(sdl)); - dhcpcd_handlehwaddr(ctx, ifp->name, CLLADDR(&sdl),sdl.sdl_alen); + dhcpcd_handlehwaddr(ifp, ifp->hwtype, + CLLADDR(&sdl), sdl.sdl_alen); break; } #ifdef INET
