Provide an option to disable route setup with dhcp

Framework manages route setup for p2p.

Bug: 5002384
Change-Id: I7489ebed1c268744a3bf8ea13bf5c55d200fe3e7
diff --git a/configure.c b/configure.c
index fb28669..e64dd4e 100644
--- a/configure.c
+++ b/configure.c
@@ -640,6 +640,8 @@
 	struct rt *nrs = NULL, *dnr, *or, *rt, *rtn, *rtl, *lrt = NULL;
 	const struct interface *ifp;
 
+	if (avoid_routes) return;
+
 	for (ifp = ifaces; ifp; ifp = ifp->next) {
 		if (ifp->state->new == NULL)
 			continue;
@@ -758,17 +760,20 @@
 	iface->addr.s_addr = lease->addr.s_addr;
 	iface->net.s_addr = lease->net.s_addr;
 
-	/* We need to delete the subnet route to have our metric or
-	 * prefer the interface. */
-	rt = get_subnet_route(dhcp);
-	if (rt != NULL) {
-		rt->iface = iface;
-		if (!find_route(routes, rt, NULL, NULL))
-			del_route(iface, &rt->dest, &rt->net, &rt->gate, 0);
-		free(rt);
+	if (!avoid_routes) {
+		/* We need to delete the subnet route to have our metric or
+		 * prefer the interface. */
+		rt = get_subnet_route(dhcp);
+		if (rt != NULL) {
+			rt->iface = iface;
+			if (!find_route(routes, rt, NULL, NULL))
+				del_route(iface, &rt->dest, &rt->net, &rt->gate, 0);
+			free(rt);
+		}
+
+		build_routes();
 	}
 
-	build_routes();
 	if (!iface->state->lease.frominfo &&
 	    !(ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC)))
 		if (write_lease(iface, dhcp) == -1)
diff --git a/dhcpcd.c b/dhcpcd.c
index df3e790..15c087b 100644
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -92,6 +92,8 @@
 char **ifav = NULL;
 int ifdc = 0;
 char **ifdv = NULL;
+/* If set, avoid routes after a DHCP success */
+int avoid_routes = 0;
 
 static char **margv;
 static int margc;
@@ -151,7 +153,7 @@
 static void
 usage(void)
 {
-	printf("usage: "PACKAGE" [-dgknpqwxyADEGHJKLOTV] [-c script] [-f file]"
+	printf("usage: "PACKAGE" [-adgknpqwxyADEGHJKLOTV] [-c script] [-f file]"
 	    " [-e var=val]\n"
 	    "              [-h hostname] [-i classID ] [-l leasetime]"
 	    " [-m metric] [-o option]\n"
@@ -1791,6 +1793,9 @@
 		case 'U':
 			i = 2;
 			break;
+		case 'a':
+			avoid_routes = 1;
+			break;
 		case 'V':
 			print_options();
 			exit(EXIT_SUCCESS);
diff --git a/dhcpcd.h b/dhcpcd.h
index ec32474..85cef7c 100644
--- a/dhcpcd.h
+++ b/dhcpcd.h
@@ -119,6 +119,7 @@
 extern int ifdc;
 extern char **ifdv;
 extern struct interface *ifaces;
+extern int avoid_routes;
 
 struct interface *find_interface(const char *);
 int handle_args(struct fd_list *, int, char **);
diff --git a/if-options.c b/if-options.c
index 88b43d7..4dd907b 100644
--- a/if-options.c
+++ b/if-options.c
@@ -333,6 +333,7 @@
 	struct rt *rt;
 
 	switch(opt) {
+	case 'a': /* FALLTHROUGH */
 	case 'f': /* FALLTHROUGH */
 	case 'g': /* FALLTHROUGH */
 	case 'n': /* FALLTHROUGH */
diff --git a/if-options.h b/if-options.h
index 241cb4d..98950ef 100644
--- a/if-options.h
+++ b/if-options.h
@@ -37,7 +37,7 @@
 
 /* Don't set any optional arguments here so we retain POSIX
  * compatibility with getopt */
-#define IF_OPTS "bc:de:f:gh:i:kl:m:no:pqr:s:t:u:v:wxy:z:ABC:DEF:GHI:JKLO:Q:S:TUVW:X:Z:"
+#define IF_OPTS "abc:de:f:gh:i:kl:m:no:pqr:s:t:u:v:wxy:z:ABC:DEF:GHI:JKLO:Q:S:TUVW:X:Z:"
 
 #define DEFAULT_TIMEOUT		30
 #define DEFAULT_REBOOT		10