Mercurial > hg > dhcpcd
changeset 5574:2a519da0f1a2 draft
DHCP: Split hardware address randomisation out of anonymous option
A 3rd party might want to control the randomisation.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Mon, 28 Dec 2020 00:02:26 +0000 |
| parents | 5bf8e1fc0634 |
| children | 465cc5abc6d6 |
| files | src/dhcpcd.c src/dhcpcd.conf.5.in src/if-options.c src/if-options.h |
| diffstat | 4 files changed, 20 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dhcpcd.c Sun Dec 27 23:52:44 2020 +0000 +++ b/src/dhcpcd.c Mon Dec 28 00:02:26 2020 +0000 @@ -734,9 +734,7 @@ * Preserve the network state until we either disconnect * or re-connect. */ - if (!(ifp->options->options & DHCPCD_ANONYMOUS) && - if_roaming(ifp)) - { + if (!ifp->options->randomise_hwaddr && if_roaming(ifp)) { dhcpcd_nocarrier_roaming(ifp); return; } @@ -745,7 +743,7 @@ script_runreason(ifp, "NOCARRIER"); dhcpcd_drop(ifp, 0); - if (ifp->options->options & DHCPCD_ANONYMOUS) { + if (ifp->options->randomise_hwaddr) { bool is_up = ifp->flags & IFF_UP; if (is_up) @@ -971,22 +969,22 @@ { struct interface *ifp = arg; struct dhcpcd_ctx *ctx = ifp->ctx; - bool anondown; + bool randmac_down; if (ifp->carrier <= LINK_DOWN && - ifp->options->options & DHCPCD_ANONYMOUS && + ifp->options->randomise_hwaddr && ifp->flags & IFF_UP) { if_down(ifp); - anondown = true; + randmac_down = true; } else - anondown = false; + randmac_down = false; if ((!(ctx->options & DHCPCD_MASTER) || - ifp->options->options & DHCPCD_IF_UP || anondown) && + ifp->options->options & DHCPCD_IF_UP || randmac_down) && !(ifp->flags & IFF_UP)) { - if (ifp->options->options & DHCPCD_ANONYMOUS && + if (ifp->options->randomise_hwaddr && if_randomisemac(ifp) == -1) logerr(__func__); if (if_up(ifp) == -1)
--- a/src/dhcpcd.conf.5.in Sun Dec 27 23:52:44 2020 +0000 +++ b/src/dhcpcd.conf.5.in Mon Dec 28 00:02:26 2020 +0000 @@ -24,7 +24,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd November 25, 2020 +.Dd December 27, 2020 .Dt DHCPCD.CONF 5 .Os .Sh NAME @@ -61,9 +61,7 @@ .Xr fnmatch 3 . .It Ic anonymous Enables Anonymity Profiles for DHCP, RFC 7844. -This implementation forces a hardware address randomisaton when -the interface link is down and that ClientID's are only LL. -Any DUID is ignored. +Any DUID is ignored and ClientID is set to LL only. All non essential options are then masked at this point, but they could be unmasked by explicitly requesting the option .Sy after @@ -79,6 +77,10 @@ .Nm dhcpcd will not try and reboot an old lease, it will go straight into DISCOVER/SOLICIT. +.It Ic randomise_hwaddr +Forces a hardware address randomisation when the interface is brought up +or when the carrier is lost. +This is generally used in tandem with the anonymous option. .It Ic arping Ar address Op address .Nm dhcpcd will arping each address in order before attempting DHCP.
--- a/src/if-options.c Sun Dec 27 23:52:44 2020 +0000 +++ b/src/if-options.c Mon Dec 28 00:02:26 2020 +0000 @@ -120,6 +120,7 @@ {"ipv4only", no_argument, NULL, '4'}, {"ipv6only", no_argument, NULL, '6'}, {"anonymous", no_argument, NULL, O_ANONYMOUS}, + {"randomise_hwaddr",no_argument, NULL, O_RANDOMISE_HWADDR}, {"arping", required_argument, NULL, O_ARPING}, {"destination", required_argument, NULL, O_DESTINATION}, {"fallback", required_argument, NULL, O_FALLBACK}, @@ -1304,6 +1305,9 @@ #endif break; + case O_RANDOMISE_HWADDR: + ifo->randomise_hwaddr = true; + break; #ifdef INET case O_ARPING: while (arg != NULL) {
--- a/src/if-options.h Sun Dec 27 23:52:44 2020 +0000 +++ b/src/if-options.h Mon Dec 28 00:02:26 2020 +0000 @@ -182,6 +182,7 @@ #define O_MSUSERCLASS O_BASE + 49 #define O_CONFIGURE O_BASE + 50 #define O_NOCONFIGURE O_BASE + 51 +#define O_RANDOMISE_HWADDR O_BASE + 52 extern const struct option cf_options[]; @@ -234,6 +235,7 @@ uint32_t timeout; uint32_t reboot; unsigned long long options; + bool randomise_hwaddr; struct in_addr req_addr; struct in_addr req_mask;
