Mercurial > hg > dhcpcd
comparison src/dhcpcd.c @ 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 | f32e37b1d371 |
| children |
comparison
equal
deleted
inserted
replaced
| 5573:5bf8e1fc0634 | 5574:2a519da0f1a2 |
|---|---|
| 732 * If the interface is roaming (generally on wireless) | 732 * If the interface is roaming (generally on wireless) |
| 733 * then while we are not up, we are not down either. | 733 * then while we are not up, we are not down either. |
| 734 * Preserve the network state until we either disconnect | 734 * Preserve the network state until we either disconnect |
| 735 * or re-connect. | 735 * or re-connect. |
| 736 */ | 736 */ |
| 737 if (!(ifp->options->options & DHCPCD_ANONYMOUS) && | 737 if (!ifp->options->randomise_hwaddr && if_roaming(ifp)) { |
| 738 if_roaming(ifp)) | |
| 739 { | |
| 740 dhcpcd_nocarrier_roaming(ifp); | 738 dhcpcd_nocarrier_roaming(ifp); |
| 741 return; | 739 return; |
| 742 } | 740 } |
| 743 | 741 |
| 744 loginfox("%s: carrier lost", ifp->name); | 742 loginfox("%s: carrier lost", ifp->name); |
| 745 script_runreason(ifp, "NOCARRIER"); | 743 script_runreason(ifp, "NOCARRIER"); |
| 746 dhcpcd_drop(ifp, 0); | 744 dhcpcd_drop(ifp, 0); |
| 747 | 745 |
| 748 if (ifp->options->options & DHCPCD_ANONYMOUS) { | 746 if (ifp->options->randomise_hwaddr) { |
| 749 bool is_up = ifp->flags & IFF_UP; | 747 bool is_up = ifp->flags & IFF_UP; |
| 750 | 748 |
| 751 if (is_up) | 749 if (is_up) |
| 752 if_down(ifp); | 750 if_down(ifp); |
| 753 if (if_randomisemac(ifp) == -1 && errno != ENXIO) | 751 if (if_randomisemac(ifp) == -1 && errno != ENXIO) |
| 969 static void | 967 static void |
| 970 dhcpcd_prestartinterface(void *arg) | 968 dhcpcd_prestartinterface(void *arg) |
| 971 { | 969 { |
| 972 struct interface *ifp = arg; | 970 struct interface *ifp = arg; |
| 973 struct dhcpcd_ctx *ctx = ifp->ctx; | 971 struct dhcpcd_ctx *ctx = ifp->ctx; |
| 974 bool anondown; | 972 bool randmac_down; |
| 975 | 973 |
| 976 if (ifp->carrier <= LINK_DOWN && | 974 if (ifp->carrier <= LINK_DOWN && |
| 977 ifp->options->options & DHCPCD_ANONYMOUS && | 975 ifp->options->randomise_hwaddr && |
| 978 ifp->flags & IFF_UP) | 976 ifp->flags & IFF_UP) |
| 979 { | 977 { |
| 980 if_down(ifp); | 978 if_down(ifp); |
| 981 anondown = true; | 979 randmac_down = true; |
| 982 } else | 980 } else |
| 983 anondown = false; | 981 randmac_down = false; |
| 984 | 982 |
| 985 if ((!(ctx->options & DHCPCD_MASTER) || | 983 if ((!(ctx->options & DHCPCD_MASTER) || |
| 986 ifp->options->options & DHCPCD_IF_UP || anondown) && | 984 ifp->options->options & DHCPCD_IF_UP || randmac_down) && |
| 987 !(ifp->flags & IFF_UP)) | 985 !(ifp->flags & IFF_UP)) |
| 988 { | 986 { |
| 989 if (ifp->options->options & DHCPCD_ANONYMOUS && | 987 if (ifp->options->randomise_hwaddr && |
| 990 if_randomisemac(ifp) == -1) | 988 if_randomisemac(ifp) == -1) |
| 991 logerr(__func__); | 989 logerr(__func__); |
| 992 if (if_up(ifp) == -1) | 990 if (if_up(ifp) == -1) |
| 993 logerr(__func__); | 991 logerr(__func__); |
| 994 } | 992 } |
