changeset 1884:3d4a3711a436 draft

Add the noalias directive to so that when adding an IPv4 addresss dhcpcd will overwrite a pre-existing address. NetBSD PR/47699
author Roy Marples <roy@marples.name>
date Wed, 27 Mar 2013 16:36:56 +0000
parents 7614fc9da4f9
children 158c55bbce72
files dhcpcd.conf.5.in if-bsd.c if-options.c if-options.h ipv4.c ipv4.h
diffstat 6 files changed, 22 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/dhcpcd.conf.5.in	Wed Mar 27 15:43:48 2013 +0000
+++ b/dhcpcd.conf.5.in	Wed Mar 27 16:36:56 2013 +0000
@@ -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 @@
 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.
--- a/if-bsd.c	Wed Mar 27 15:43:48 2013 +0000
+++ b/if-bsd.c	Wed Mar 27 16:36:56 2013 +0000
@@ -201,7 +201,8 @@
 #undef ADDADDR
 
 	return ioctl(socket_afnet,
-	    action < 0 ? SIOCDIFADDR : SIOCAIFADDR, &ifa);
+	    action < 0 ? SIOCDIFADDR :
+	    action == 2 ? SIOCSIFADDR :  SIOCAIFADDR, &ifa);
 }
 
 int
--- a/if-options.c	Wed Mar 27 15:43:48 2013 +0000
+++ b/if-options.c	Wed Mar 27 16:36:56 2013 +0000
@@ -61,6 +61,7 @@
 #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 @@
 	{"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 @@
 	case O_IPV6RA_OWN_D:
 		ifo->options |= DHCPCD_IPV6RA_OWN_DEFAULT;
 		break;
+	case O_NOALIAS:
+		ifo->options |= DHCPCD_NOALIAS;
+		break;
 	default:
 		return 0;
 	}
--- a/if-options.h	Wed Mar 27 15:43:48 2013 +0000
+++ b/if-options.h	Wed Mar 27 16:36:56 2013 +0000
@@ -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[];
 
--- a/ipv4.c	Wed Mar 27 15:43:48 2013 +0000
+++ b/ipv4.c	Wed Mar 27 16:36:56 2013 +0000
@@ -592,6 +592,7 @@
 	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 @@
 		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;
 		}
--- a/ipv4.h	Wed Mar 27 15:43:48 2013 +0000
+++ b/ipv4.h	Wed Mar 27 16:36:56 2013 +0000
@@ -61,6 +61,8 @@
     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)				      \