diff options
| author | Roy Marples <roy@marples.name> | 2007-07-18 11:26:59 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2007-07-18 11:26:59 +0000 |
| commit | 77659ce0359c096d8a2667541879f8a59fad8121 (patch) | |
| tree | 01a6f94b4eb5320b3f9a173398f0657734912fcc /ipv4ll.c | |
| parent | ff711cf766f3efd9dc8f79776e688a3a28f52d9a (diff) | |
| download | dhcpcd-77659ce0359c096d8a2667541879f8a59fad8121.tar.xz | |
We now do ARP checking by default as recommended by RFC 2131.
Add RFC 3927 (aka IPV4LL aka APIPA) support by default.
Diffstat (limited to 'ipv4ll.c')
| -rw-r--r-- | ipv4ll.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/ipv4ll.c b/ipv4ll.c new file mode 100644 index 00000000..bb6a7b1f --- /dev/null +++ b/ipv4ll.c @@ -0,0 +1,63 @@ +/* + * dhcpcd - DHCP client daemon - + * Copyright 2006-2007 Roy Marples <uberlord@gentoo.org> + * + * dhcpcd is an RFC2131 compliant DHCP client daemon. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <errno.h> +#include <stdlib.h> + +#include "config.h" +#include "arp.h" +#include "ipv4ll.h" + +#ifdef ENABLE_IPV4LL + +#ifndef ENABLE_ARP +#error IPV4LL requires ARP +#endif + +#define IPV4LL_LEASETIME 10 + +int ipv4ll_get_address (interface_t *iface, dhcp_t *dhcp) { + struct in_addr addr; + + while (1) { + addr.s_addr = htonl (LINKLOCAL_ADDR | + ((abs (random ()) % 0xFD00) + 0x0100)); + errno = 0; + if (! arp_claim (iface, addr)) + break; + /* Our ARP may have been interrupted */ + if (errno == EINTR) + return (-1); + } + + dhcp->address.s_addr = addr.s_addr; + dhcp->netmask.s_addr = htonl (LINKLOCAL_MASK); + dhcp->broadcast.s_addr = htonl (LINKLOCAL_BRDC); + + /* Finally configure some DHCP like lease times */ + dhcp->leasetime = IPV4LL_LEASETIME; + dhcp->renewaltime = (dhcp->leasetime * 0.5); + dhcp->rebindtime = (dhcp->leasetime * 0.875); + + return (0); +} + +#endif |
