changeset 14125:c1fa4cc16e1b

3931 vrrpadm should work with a vnic as its link 3932 vrrpadm dies when its configuration file doesn't exist Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com> Reviewed by: Garrett D'Amore <garrett@damore.org> Approved by: Dan McDonald <danmcd@nexenta.com>
author Rob Gulewich <robert.gulewich@joyent.com>
date Tue, 21 Aug 2012 22:07:55 +0000
parents 57414b906edf
children 62364715172d
files usr/src/cmd/cmd-inet/usr.lib/vrrpd/vrrpd.c usr/src/lib/libvrrpadm/common/libvrrpadm.c
diffstat 2 files changed, 38 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/cmd-inet/usr.lib/vrrpd/vrrpd.c	Wed Aug 07 21:27:36 2013 +0000
+++ b/usr/src/cmd/cmd-inet/usr.lib/vrrpd/vrrpd.c	Tue Aug 21 22:07:55 2012 +0000
@@ -23,6 +23,10 @@
  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  */
 
+/*
+ * Copyright (c) 2012, Joyent, Inc. All rights reserved.
+ */
+
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/sockio.h>
@@ -2003,9 +2007,19 @@
 	    op == VRRP_CONF_UPDATE ? "update" : "delete");
 
 	if ((fp = fopen(vrrpd_conffile, "r+F")) == NULL) {
-		vrrp_log(VRRP_ERR, "vrrpd_updateconf(): open %s failed: %s",
-		    vrrpd_conffile, strerror(errno));
-		return (VRRP_EDB);
+		if (errno != ENOENT) {
+			vrrp_log(VRRP_ERR, "vrrpd_updateconf(): open %s for "
+			    "update failed: %s", vrrpd_conffile,
+			    strerror(errno));
+			return (VRRP_EDB);
+		}
+
+		if ((fp = fopen(vrrpd_conffile, "w+F")) == NULL) {
+			vrrp_log(VRRP_ERR, "vrrpd_updateconf(): open %s for "
+			    "write failed: %s", vrrpd_conffile,
+			    strerror(errno));
+			return (VRRP_EDB);
+		}
 	}
 
 	(void) snprintf(newfile, MAXPATHLEN, "%s.new", vrrpd_conffile);
@@ -2662,7 +2676,8 @@
 	if ((strlen(conf->vvc_link) == 0) || dladm_name2info(vrrpd_vh->vh_dh,
 	    conf->vvc_link, NULL, &flags, &class, NULL) != DLADM_STATUS_OK ||
 	    !(flags & DLADM_OPT_ACTIVE) || ((class != DATALINK_CLASS_PHYS) &&
-	    (class != DATALINK_CLASS_VLAN) && (class != DATALINK_CLASS_AGGR))) {
+	    (class != DATALINK_CLASS_VLAN) && (class != DATALINK_CLASS_AGGR) &&
+	    (class != DATALINK_CLASS_VNIC))) {
 		vrrp_log(VRRP_DBG1, "vrrpd_enable(%s): invalid link %s",
 		    vn, conf->vvc_link);
 		return (VRRP_EINVALLINK);
--- a/usr/src/lib/libvrrpadm/common/libvrrpadm.c	Wed Aug 07 21:27:36 2013 +0000
+++ b/usr/src/lib/libvrrpadm/common/libvrrpadm.c	Tue Aug 21 22:07:55 2012 +0000
@@ -24,6 +24,10 @@
  * Use is subject to license terms.
  */
 
+/*
+ * Copyright (c) 2012, Joyent, Inc. All rights reserved.
+ */
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/socket.h>
@@ -692,7 +696,8 @@
 
 	if (vrrp_is_vrrp_vnic(lva->lva_vh, vnicid, &linkid, &vid, &vrid,
 	    &af) && lva->lva_vrid == vrid && lva->lva_linkid == linkid &&
-	    lva->lva_vid == vid && lva->lva_af == af) {
+	    (lva->lva_vid == VLAN_ID_NONE || lva->lva_vid == vid) &&
+	    lva->lva_af == af) {
 		if (dladm_datalink_id2info(dh, vnicid, NULL, NULL, NULL,
 		    lva->lva_vnic, sizeof (lva->lva_vnic)) == DLADM_STATUS_OK) {
 			return (DLADM_WALK_TERMINATE);
@@ -714,6 +719,7 @@
 	uint16_t		vid = VLAN_ID_NONE;
 	datalink_class_t	class;
 	dladm_vlan_attr_t	vlan_attr;
+	dladm_vnic_attr_t	vnic_attr;
 	struct lookup_vnic_arg	lva;
 	uint32_t		media;
 
@@ -736,11 +742,20 @@
 		}
 	}
 
+	if (class == DATALINK_CLASS_VNIC) {
+		if (dladm_vnic_info(vh->vh_dh, linkid, &vnic_attr,
+		    DLADM_OPT_ACTIVE) != DLADM_STATUS_OK) {
+			return (VRRP_EINVAL);
+		}
+		linkid = vnic_attr.va_link_id;
+		vid = vnic_attr.va_vid;
+	}
+
 	/*
-	 * For now, Only VRRP over aggr and physical ethernet links is supported
+	 * Only VRRP over vnics, aggrs and physical ethernet links is supported
 	 */
-	if ((class != DATALINK_CLASS_PHYS && class != DATALINK_CLASS_AGGR) ||
-	    media != DL_ETHER) {
+	if ((class != DATALINK_CLASS_PHYS && class != DATALINK_CLASS_AGGR &&
+	    class != DATALINK_CLASS_VNIC) || media != DL_ETHER) {
 		return (VRRP_EINVAL);
 	}