6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
authorgfaden
Mon, 25 Feb 2008 17:23:19 -0800
changeset 6076 39e1b255225b
parent 6075 a4bde31081d4
child 6077 370a5406262b
6583565 need a mechanism to configure a per zone default route in shared IP stack for TX
usr/src/cmd/zoneadmd/vplat.c
usr/src/cmd/zonecfg/zonecfg.c
usr/src/cmd/zonecfg/zonecfg.h
usr/src/cmd/zonecfg/zonecfg_grammar.y
usr/src/cmd/zonecfg/zonecfg_lex.l
usr/src/head/libzonecfg.h
usr/src/lib/libzonecfg/common/libzonecfg.c
usr/src/lib/libzonecfg/dtd/zonecfg.dtd.1
--- a/usr/src/cmd/zoneadmd/vplat.c	Mon Feb 25 14:55:36 2008 -0800
+++ b/usr/src/cmd/zoneadmd/vplat.c	Mon Feb 25 17:23:19 2008 -0800
@@ -2476,6 +2476,30 @@
 		    lifr.lifr_name, addrstr4, buffer);
 	}
 
+	/*
+	 * If a default router was specified for this interface
+	 * set the route now. Ignore if already set.
+	 */
+	if (strlen(nwiftabptr->zone_nwif_defrouter) > 0) {
+		int status;
+		char *argv[7];
+
+		argv[0] = "route";
+		argv[1] = "add";
+		argv[2] = "-ifp";
+		argv[3] = nwiftabptr->zone_nwif_physical;
+		argv[4] = "default";
+		argv[5] = nwiftabptr->zone_nwif_defrouter;
+		argv[6] = NULL;
+
+		status = forkexec(zlogp, "/usr/sbin/route", argv);
+		if (status != 0 && status != EEXIST)
+			zerror(zlogp, B_FALSE, "Unable to set route for "
+			    "interface %s to %s\n",
+			    nwiftabptr->zone_nwif_physical,
+			    nwiftabptr->zone_nwif_defrouter);
+	}
+
 	(void) close(s);
 	return (Z_OK);
 bad:
--- a/usr/src/cmd/zonecfg/zonecfg.c	Mon Feb 25 14:55:36 2008 -0800
+++ b/usr/src/cmd/zonecfg/zonecfg.c	Mon Feb 25 17:23:19 2008 -0800
@@ -20,7 +20,7 @@
  */
 
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -220,6 +220,7 @@
 	ALIAS_MAXSWAP,
 	"scheduling-class",
 	"ip-type",
+	"defrouter",
 	NULL
 };
 
@@ -936,10 +937,13 @@
 			    pt_to_str(PT_PHYSICAL), gettext("<interface>"));
 			(void) fprintf(fp, gettext("See ifconfig(1M) for "
 			    "details of the <interface> string.\n"));
-			(void) fprintf(fp, gettext("%s %s is valid if the %s "
-			    "property is set to %s, otherwise it must not be "
-			    "set.\n"),
+			(void) fprintf(fp, "\t%s %s=%s\n", cmd_to_str(CMD_SET),
+			    pt_to_str(PT_DEFROUTER), gettext("<IP-address>"));
+			(void) fprintf(fp, gettext("%s %s and %s %s are valid "
+			    "if the %s property is set to %s, otherwise they "
+			    "must not be set.\n"),
 			    cmd_to_str(CMD_SET), pt_to_str(PT_ADDRESS),
+			    cmd_to_str(CMD_SET), pt_to_str(PT_DEFROUTER),
 			    pt_to_str(PT_IPTYPE), "shared");
 			break;
 		case RT_DEVICE:
@@ -1155,8 +1159,9 @@
 		    pt_to_str(PT_OPTIONS));
 		(void) fprintf(fp, "\t%s\t%s\n", rt_to_str(RT_IPD),
 		    pt_to_str(PT_DIR));
-		(void) fprintf(fp, "\t%s\t\t%s, %s\n", rt_to_str(RT_NET),
-		    pt_to_str(PT_ADDRESS), pt_to_str(PT_PHYSICAL));
+		(void) fprintf(fp, "\t%s\t\t%s, %s, %s\n", rt_to_str(RT_NET),
+		    pt_to_str(PT_ADDRESS), pt_to_str(PT_PHYSICAL),
+		    pt_to_str(PT_DEFROUTER));
 		(void) fprintf(fp, "\t%s\t\t%s\n", rt_to_str(RT_DEVICE),
 		    pt_to_str(PT_MATCH));
 		(void) fprintf(fp, "\t%s\t\t%s, %s\n", rt_to_str(RT_RCTL),
@@ -1779,6 +1784,7 @@
 		    rt_to_str(RT_NET));
 		export_prop(of, PT_ADDRESS, nwiftab.zone_nwif_address);
 		export_prop(of, PT_PHYSICAL, nwiftab.zone_nwif_physical);
+		export_prop(of, PT_DEFROUTER, nwiftab.zone_nwif_defrouter);
 		(void) fprintf(of, "%s\n", cmd_to_str(CMD_END));
 	}
 	(void) zonecfg_endnwifent(handle);
@@ -2550,6 +2556,11 @@
 			    pp->pv_simple,
 			    sizeof (nwiftab->zone_nwif_physical));
 			break;
+		case PT_DEFROUTER:
+			(void) strlcpy(nwiftab->zone_nwif_defrouter,
+			    pp->pv_simple,
+			    sizeof (nwiftab->zone_nwif_defrouter));
+			break;
 		default:
 			zone_perror(pt_to_str(cmd->cmd_prop_name[i]),
 			    Z_NO_PROPERTY_TYPE, TRUE);
@@ -3297,6 +3308,18 @@
 			zone_perror(pt_to_str(prop_type), err, TRUE);
 		zonecfg_free_rctl_value_list(rctlvaltab);
 		return;
+	case RT_NET:
+		if (prop_type != PT_DEFROUTER) {
+			zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
+			    TRUE);
+			long_usage(CMD_REMOVE, TRUE);
+			usage(FALSE, HELP_PROPS);
+			return;
+		} else {
+			bzero(&in_progress_nwiftab.zone_nwif_defrouter,
+			    sizeof (in_progress_nwiftab.zone_nwif_defrouter));
+			return;
+		}
 	default:
 		zone_perror(rt_to_str(res_type), Z_NO_RESOURCE_TYPE, TRUE);
 		long_usage(CMD_REMOVE, TRUE);
@@ -4159,6 +4182,15 @@
 			    prop_id,
 			    sizeof (in_progress_nwiftab.zone_nwif_physical));
 			break;
+		case PT_DEFROUTER:
+			if (validate_net_address_syntax(prop_id) != Z_OK) {
+				saw_error = TRUE;
+				return;
+			}
+			(void) strlcpy(in_progress_nwiftab.zone_nwif_defrouter,
+			    prop_id,
+			    sizeof (in_progress_nwiftab.zone_nwif_defrouter));
+			break;
 		default:
 			zone_perror(pt_to_str(prop_type), Z_NO_PROPERTY_TYPE,
 			    TRUE);
@@ -4688,6 +4720,7 @@
 	(void) fprintf(fp, "%s:\n", rt_to_str(RT_NET));
 	output_prop(fp, PT_ADDRESS, nwiftab->zone_nwif_address, B_TRUE);
 	output_prop(fp, PT_PHYSICAL, nwiftab->zone_nwif_physical, B_TRUE);
+	output_prop(fp, PT_DEFROUTER, nwiftab->zone_nwif_defrouter, B_TRUE);
 }
 
 static void
@@ -5457,8 +5490,10 @@
 	while (zonecfg_getnwifent(handle, &nwiftab) == Z_OK) {
 		/*
 		 * physical is required in all cases.
-		 * A shared IP requires an address, while
-		 * an exclusive IP must not have an address.
+		 * A shared IP requires an address,
+		 * and may include a default router, while
+		 * an exclusive IP must have neither an address
+		 * nor a default router.
 		 */
 		check_reqd_prop(nwiftab.zone_nwif_physical, RT_NET,
 		    PT_PHYSICAL, &ret_val);
@@ -5477,6 +5512,14 @@
 				if (ret_val == Z_OK)
 					ret_val = Z_INVAL;
 			}
+			if (strlen(nwiftab.zone_nwif_defrouter) > 0) {
+				zerr(gettext("%s: %s cannot be specified "
+				    "for an exclusive IP type"),
+				    rt_to_str(RT_NET), pt_to_str(PT_DEFROUTER));
+				saw_error = TRUE;
+				if (ret_val == Z_OK)
+					ret_val = Z_INVAL;
+			}
 			break;
 		}
 	}
--- a/usr/src/cmd/zonecfg/zonecfg.h	Mon Feb 25 14:55:36 2008 -0800
+++ b/usr/src/cmd/zonecfg/zonecfg.h	Mon Feb 25 17:23:19 2008 -0800
@@ -20,7 +20,7 @@
  */
 
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -135,9 +135,10 @@
 #define	PT_MAXSWAP	32
 #define	PT_SCHED	33
 #define	PT_IPTYPE	34
+#define	PT_DEFROUTER	35
 
 #define	PT_MIN		PT_UNKNOWN
-#define	PT_MAX		PT_IPTYPE
+#define	PT_MAX		PT_DEFROUTER
 
 #define	MAX_EQ_PROP_PAIRS	3
 
--- a/usr/src/cmd/zonecfg/zonecfg_grammar.y	Mon Feb 25 14:55:36 2008 -0800
+++ b/usr/src/cmd/zonecfg/zonecfg_grammar.y	Mon Feb 25 17:23:19 2008 -0800
@@ -21,7 +21,7 @@
  */
 
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -63,7 +63,7 @@
 %token NAME MATCH PRIV LIMIT ACTION VALUE EQUAL OPEN_SQ_BRACKET CLOSE_SQ_BRACKET
 %token OPEN_PAREN CLOSE_PAREN COMMA DATASET LIMITPRIV BOOTARGS BRAND PSET PCAP
 %token MCAP NCPUS IMPORTANCE SHARES MAXLWPS MAXSHMMEM MAXSHMIDS MAXMSGIDS
-%token MAXSEMIDS LOCKED SWAP SCHED CLEAR
+%token MAXSEMIDS LOCKED SWAP SCHED CLEAR DEFROUTER
 
 %type <strval> TOKEN EQUAL OPEN_SQ_BRACKET CLOSE_SQ_BRACKET
     property_value OPEN_PAREN CLOSE_PAREN COMMA simple_prop_val
@@ -71,7 +71,7 @@
 %type <ival> resource_type NET FS IPD DEVICE RCTL ATTR DATASET PSET PCAP MCAP
 %type <ival> property_name SPECIAL RAW DIR OPTIONS TYPE ADDRESS PHYSICAL NAME
     MATCH ZONENAME ZONEPATH AUTOBOOT POOL LIMITPRIV BOOTARGS VALUE PRIV LIMIT
-    ACTION BRAND SCHED IPTYPE
+    ACTION BRAND SCHED IPTYPE DEFROUTER
 %type <cmd> command
 %type <cmd> add_command ADD
 %type <cmd> cancel_command CANCEL
@@ -865,6 +865,7 @@
 	| BOOTARGS	{ $$ = PT_BOOTARGS; }
 	| ADDRESS	{ $$ = PT_ADDRESS; }
 	| PHYSICAL	{ $$ = PT_PHYSICAL; }
+	| DEFROUTER	{ $$ = PT_DEFROUTER; }
 	| NAME		{ $$ = PT_NAME; }
 	| VALUE		{ $$ = PT_VALUE; }
 	| MATCH		{ $$ = PT_MATCH; }
--- a/usr/src/cmd/zonecfg/zonecfg_lex.l	Mon Feb 25 14:55:36 2008 -0800
+++ b/usr/src/cmd/zonecfg/zonecfg_lex.l	Mon Feb 25 17:23:19 2008 -0800
@@ -21,7 +21,7 @@
  */
 
 /*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
@@ -213,6 +213,9 @@
 <TSTATE>physical	{ return PHYSICAL; }
 <CSTATE>physical	{ return PHYSICAL; }
 
+<TSTATE>defrouter	{ return DEFROUTER; }
+<CSTATE>defrouter	{ return DEFROUTER; }
+
 <TSTATE>dir	{ return DIR; }
 <CSTATE>dir	{ return DIR; }
 
--- a/usr/src/head/libzonecfg.h	Mon Feb 25 14:55:36 2008 -0800
+++ b/usr/src/head/libzonecfg.h	Mon Feb 25 17:23:19 2008 -0800
@@ -185,6 +185,7 @@
 struct zone_nwiftab {
 	char	zone_nwif_address[INET6_ADDRSTRLEN];
 	char	zone_nwif_physical[LIFNAMSIZ];
+	char	zone_nwif_defrouter[INET6_ADDRSTRLEN];
 };
 
 struct zone_devtab {
--- a/usr/src/lib/libzonecfg/common/libzonecfg.c	Mon Feb 25 14:55:36 2008 -0800
+++ b/usr/src/lib/libzonecfg/common/libzonecfg.c	Mon Feb 25 17:23:19 2008 -0800
@@ -96,6 +96,7 @@
 #define	DTD_ATTR_ADDRESS	(const xmlChar *) "address"
 #define	DTD_ATTR_AUTOBOOT	(const xmlChar *) "autoboot"
 #define	DTD_ATTR_IPTYPE		(const xmlChar *) "ip-type"
+#define	DTD_ATTR_DEFROUTER	(const xmlChar *) "defrouter"
 #define	DTD_ATTR_DIR		(const xmlChar *) "directory"
 #define	DTD_ATTR_LIMIT		(const xmlChar *) "limit"
 #define	DTD_ATTR_LIMITPRIV	(const xmlChar *) "limitpriv"
@@ -2209,6 +2210,11 @@
 	    sizeof (tabptr->zone_nwif_address))) != Z_OK)
 		return (err);
 
+	if ((err = fetchprop(cur, DTD_ATTR_DEFROUTER,
+	    tabptr->zone_nwif_defrouter,
+	    sizeof (tabptr->zone_nwif_defrouter))) != Z_OK)
+		return (err);
+
 	return (Z_OK);
 }
 
@@ -2225,6 +2231,9 @@
 	if ((err = newprop(newnode, DTD_ATTR_PHYSICAL,
 	    tabptr->zone_nwif_physical)) != Z_OK)
 		return (err);
+	if ((err = newprop(newnode, DTD_ATTR_DEFROUTER,
+	    tabptr->zone_nwif_defrouter)) != Z_OK)
+		return (err);
 	return (Z_OK);
 }
 
@@ -4386,6 +4395,13 @@
 		return (err);
 	}
 
+	if ((err = fetchprop(cur, DTD_ATTR_DEFROUTER,
+	    tabptr->zone_nwif_defrouter,
+	    sizeof (tabptr->zone_nwif_defrouter))) != Z_OK) {
+		handle->zone_dh_cur = handle->zone_dh_top;
+		return (err);
+	}
+
 	handle->zone_dh_cur = cur->next;
 	return (Z_OK);
 }
--- a/usr/src/lib/libzonecfg/dtd/zonecfg.dtd.1	Mon Feb 25 14:55:36 2008 -0800
+++ b/usr/src/lib/libzonecfg/dtd/zonecfg.dtd.1	Mon Feb 25 17:23:19 2008 -0800
@@ -20,7 +20,7 @@
 
  CDDL HEADER END
 
- Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  Use is subject to license terms.
 
  ident	"%Z%%M%	%I%	%E% SMI"
@@ -45,6 +45,7 @@
 <!ELEMENT network	EMPTY>
 
 <!ATTLIST network	address		CDATA ""
+			defrouter	CDATA ""
 			physical	CDATA #REQUIRED>
 
 <!ELEMENT device	EMPTY>