Skip to content

Commit

Permalink
dhcpcd: Add support for arp persist defence (#273)
Browse files Browse the repository at this point in the history
RFC 5227 recommends 3 ways to deal with address conflict detection.
a) Stop everything.
b) Defend and then stop on fail - this is what dhcpcd currently does.
c) Notify and carry on.

The current change implements the option c. A new option arp_persistdefence
has been added and when this is enabled, the a defence is attempted upon a
conflict and when that fails, an error is logged on every other conflict
within the DEFEND_INTERVAL and the current IP address is retained.

Fixes #272
  • Loading branch information
pradeep-brightsign authored Dec 21, 2023
1 parent 1c8ae59 commit e65e82a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/arp.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,24 @@ arp_found(struct arp_state *astate, const struct arp_msg *amsg)
* the other IPv4LL client will receieve two ARP
* messages.
* If another conflict happens within DEFEND_INTERVAL
* then we must drop our address and negotiate a new one. */
* then we must drop our address and negotiate a new one.
* If DHCPCD_ARP_PERSISTDEFENCE is set, that enables
* RFC5227 section 2.4.c behaviour. Upon conflict
* detection, the host records the time that the
* conflicting ARP packet was received, and then
* broadcasts one single ARP Announcement. The host then
* continues to use the address normally. All further
* conflict notifications within the DEFEND_INTERVAL are
* ignored. */
clock_gettime(CLOCK_MONOTONIC, &now);
if (timespecisset(&astate->defend) &&
eloop_timespec_diff(&now, &astate->defend, NULL) < DEFEND_INTERVAL)
{
logwarnx("%s: %d second defence failed for %s",
ifp->name, DEFEND_INTERVAL, inet_ntoa(astate->addr));
if (ifp->options->options & DHCPCD_ARP_PERSISTDEFENCE)
return;
}
else if (arp_request(astate, &astate->addr) == -1)
logerr(__func__);
else {
Expand Down
4 changes: 3 additions & 1 deletion src/dhcpcd.conf.5.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd December 18, 2023
.Dd December 21, 2023
.Dt DHCPCD.CONF 5
.Os
.Sh NAME
Expand Down Expand Up @@ -510,6 +510,8 @@ adding a new IPv4 address.
.It Ic noarp
Don't send any ARP requests.
This also disables IPv4LL.
.It Ic arp_persistdefence
Keep the IP address even if defence fails upon IP Address conflict.
.It Ic noauthrequired
Don't require authentication even though we requested it.
Also allows FORCERENEW and RECONFIGURE messages without authentication.
Expand Down
4 changes: 4 additions & 0 deletions src/if-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ const struct option cf_options[] = {
{"link_rcvbuf", required_argument, NULL, O_LINK_RCVBUF},
{"configure", no_argument, NULL, O_CONFIGURE},
{"noconfigure", no_argument, NULL, O_NOCONFIGURE},
{"arp_persistdefence", no_argument, NULL, O_ARP_PERSISTDEFENCE},
{NULL, 0, NULL, '\0'}
};

Expand Down Expand Up @@ -2337,6 +2338,9 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
case O_NOCONFIGURE:
ifo->options &= ~DHCPCD_CONFIGURE;
break;
case O_ARP_PERSISTDEFENCE:
ifo->options |= DHCPCD_ARP_PERSISTDEFENCE;
break;
default:
return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions src/if-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#define DHCPCD_GATEWAY (1ULL << 3)
#define DHCPCD_STATIC (1ULL << 4)
#define DHCPCD_DEBUG (1ULL << 5)
#define DHCPCD_ARP_PERSISTDEFENCE (1ULL << 6)
#define DHCPCD_LASTLEASE (1ULL << 7)
#define DHCPCD_INFORM (1ULL << 8)
#define DHCPCD_REQUEST (1ULL << 9)
Expand Down Expand Up @@ -183,6 +184,7 @@
#define O_CONFIGURE O_BASE + 50
#define O_NOCONFIGURE O_BASE + 51
#define O_RANDOMISE_HWADDR O_BASE + 52
#define O_ARP_PERSISTDEFENCE O_BASE + 53

extern const struct option cf_options[];

Expand Down

0 comments on commit e65e82a

Please sign in to comment.