Add the noalias directive to so that when adding an IPv4 addresss

dhcpcd will overwrite a pre-existing address.

NetBSD PR/47699
This commit is contained in:
Roy Marples 2013-03-27 16:36:56 +00:00
parent 0e97750633
commit 7dab081fbe
6 changed files with 22 additions and 6 deletions

View File

@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd February 5, 2013
.Dd March 27, 2013
.Dt DHCPCD.CONF 5 SMM
.Os
.Sh NAME
@ -179,6 +179,9 @@ Metrics are used to prefer an interface over another one, lowest wins.
will supply a default metric of 200 +
.Xr if_nametoindex 3 .
An extra 100 will be added for wireless interfaces.
.It Ic noalias
IPv4 addresses added will overwrite a pre-existing address instead of working
alongside.
.It Ic noarp
Don't send any ARP requests.
This also disables IPv4LL.

View File

@ -201,7 +201,8 @@ if_address(const struct interface *iface, const struct in_addr *address,
#undef ADDADDR
return ioctl(socket_afnet,
action < 0 ? SIOCDIFADDR : SIOCAIFADDR, &ifa);
action < 0 ? SIOCDIFADDR :
action == 2 ? SIOCSIFADDR : SIOCAIFADDR, &ifa);
}
int

View File

@ -61,6 +61,7 @@ unsigned long long options = 0;
#define O_IPV6RA_FORK O_BASE + 6
#define O_IPV6RA_OWN O_BASE + 7
#define O_IPV6RA_OWN_D O_BASE + 8
#define O_NOALIAS O_BASE + 9
const struct option cf_options[] = {
{"background", no_argument, NULL, 'b'},
@ -118,6 +119,7 @@ const struct option cf_options[] = {
{"ipv6ra_own_default", no_argument, NULL, O_IPV6RA_OWN_D},
{"ipv4only", no_argument, NULL, '4'},
{"ipv6only", no_argument, NULL, '6'},
{"noalias", no_argument, NULL, O_NOALIAS},
{NULL, 0, NULL, '\0'}
};
@ -915,6 +917,9 @@ parse_option(struct if_options *ifo, int opt, const char *arg)
case O_IPV6RA_OWN_D:
ifo->options |= DHCPCD_IPV6RA_OWN_DEFAULT;
break;
case O_NOALIAS:
ifo->options |= DHCPCD_NOALIAS;
break;
default:
return 0;
}

View File

@ -88,6 +88,7 @@
#define DHCPCD_FORKED (1ULL << 36)
#define DHCPCD_IPV6 (1ULL << 37)
#define DHCPCD_STARTED (1ULL << 38)
#define DHCPCD_NOALIAS (1ULL << 39)
extern const struct option cf_options[];

12
ipv4.c
View File

@ -592,6 +592,7 @@ ipv4_applyaddr(void *arg)
struct dhcp_lease *lease;
struct if_options *ifo = ifp->options;
struct rt *rt;
int r;
/* As we are now adjusting an interface, we need to ensure
* we have them in the right order for routing and configuration. */
@ -619,10 +620,13 @@ ipv4_applyaddr(void *arg)
syslog(LOG_DEBUG, "%s: adding IP address %s/%d",
ifp->name, inet_ntoa(lease->addr),
inet_ntocidr(lease->net));
if (ipv4_addaddress(ifp,
&lease->addr, &lease->net, &lease->brd) == -1 &&
errno != EEXIST)
{
if (ifo->options & DHCPCD_NOALIAS)
r = ipv4_setaddress(ifp,
&lease->addr, &lease->net, &lease->brd);
else
r = ipv4_addaddress(ifp,
&lease->addr, &lease->net, &lease->brd);
if (r == -1 && errno != EEXIST) {
syslog(LOG_ERR, "%s: ipv4_addaddress: %m", __func__);
return;
}

2
ipv4.h
View File

@ -61,6 +61,8 @@ int if_address(const struct interface *,
const struct in_addr *, int);
#define ipv4_addaddress(iface, addr, net, brd) \
if_address(iface, addr, net, brd, 1)
#define ipv4_setaddress(iface, addr, net, brd) \
if_address(iface, addr, net, brd, 2)
#define ipv4_deleteaddress(iface, addr, net) \
if_address(iface, addr, net, NULL, -1)
#define ipv4_hasaddress(iface, addr, net) \