Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 25 Jan 2005 13:08:43 +0500
From:      Boris Kovalenko <boris@ntmk.ru>
To:        Brooks Davis <brooks@one-eyed-alien.net>, freebsd-net@freebsd.org
Subject:   Re: [PATCH] 802.1p priority (fixed)
Message-ID:  <41F5FE8B.40809@ntmk.ru>
In-Reply-To: <20050125062914.GA12771@odin.ac.hmc.edu>
References:  <41F33E9F.9090301@tagnet.ru> <20050123193711.GB29225@odin.ac.hmc.edu> <41F46C3C.20205@ntmk.ru> <20050124170735.GA26830@odin.ac.hmc.edu> <41F5C802.8010307@ntmk.ru> <20050125062914.GA12771@odin.ac.hmc.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.
--------------020001000007000200010100
Content-Type: text/plain; charset=KOI8-R; format=flowed
Content-Transfer-Encoding: 7bit

Hello!

	Is this patch looks ok for You now? Or should I do something more?

-- 
With respect,
	Boris

--------------020001000007000200010100
Content-Type: text/plain;
 name="patch-8021p.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="patch-8021p.diff"

--- sbin/ifconfig/ifconfig.h.orig	Wed Jan 19 10:44:20 2005
+++ sbin/ifconfig/ifconfig.h	Fri Jan 21 09:11:22 2005
@@ -49,6 +49,8 @@
 
 extern void setvlantag(const char *, int, int, const struct afswtch *rafp);
 extern void setvlandev(const char *, int, int, const struct afswtch *rafp);
+extern void setvlanpri(const char *, int, int, const struct afswtch *rafp);
+extern void setvlancfi(const char *, int, int, const struct afswtch *rafp);
 extern void unsetvlandev(const char *, int, int, const struct afswtch *rafp);
 extern void vlan_status(int s, struct rt_addrinfo *);
 
--- sbin/ifconfig/ifconfig.c.orig	Wed Jan 19 10:56:44 2005
+++ sbin/ifconfig/ifconfig.c	Fri Jan 21 09:11:54 2005
@@ -247,6 +247,8 @@
 #endif
 #ifdef USE_VLANS
 	{ "vlan",	NEXTARG,	setvlantag },
+	{ "vlanpri",	NEXTARG,	setvlanpri },
+	{ "vlancfi",	NEXTARG,	setvlancfi },
 	{ "vlandev",	NEXTARG,	setvlandev },
 	{ "-vlandev",	NEXTARG,	unsetvlandev },
 #endif
--- sbin/ifconfig/ifvlan.c.orig	Thu Apr 18 23:14:09 2002
+++ sbin/ifconfig/ifvlan.c	Tue Jan 25 13:05:11 2005
@@ -59,6 +59,8 @@
   "$FreeBSD: src/sbin/ifconfig/ifvlan.c,v 1.5 2002/04/18 17:14:09 imp Exp $";
 #endif
 static int			__tag = 0;
+static int			__pri = 0;
+static int			__cfi = 0;
 static int			__have_tag = 0;
 
 void
@@ -72,9 +74,10 @@
 	if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1)
 		return;
 
-	printf("\tvlan: %d parent interface: %s\n",
-	    vreq.vlr_tag, vreq.vlr_parent[0] == '\0' ?
-	    "<none>" : vreq.vlr_parent);
+	printf("\tvlan: %d 802.1p: %d CFI: %d parent interface: %s \n",
+	    EVL_VLANOFTAG(vreq.vlr_tag), EVL_PRIOFTAG(vreq.vlr_tag),
+	    EVL_CFIOFTAG(vreq.vlr_tag),
+	    vreq.vlr_parent[0] == '\0' ? "<none>" : vreq.vlr_parent );
 
 	return;
 }
@@ -84,17 +87,79 @@
 {
 	u_int16_t		tag;
 	struct vlanreq		vreq;
+	char			*endptr;
 
-	__tag = tag = atoi(val);
+	__tag = tag = (u_int16_t)strtoul(val, &endptr, 0);
+	if(*endptr != '\0')
+		errx(1, "VLID ID must be a number");
 	__have_tag = 1;
 
+	if(tag < 1 || tag > 4094)
+		errx(1, "VLAN ID should be in range 1..4094");
+
+	bzero((char *)&vreq, sizeof(struct vlanreq));
+	ifr.ifr_data = (caddr_t)&vreq;
+
+	if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1)
+		err(1, "SIOCGETVLAN");
+
+	vreq.vlr_tag = EVL_MAKETAG(tag, __pri, __cfi);
+
+	if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1)
+		err(1, "SIOCSETVLAN");
+
+	return;
+}
+
+void
+setvlanpri(const char *val, int d, int s, const struct afswtch	*afp)
+{
+	u_int16_t		pri;
+	struct vlanreq		vreq;
+	char			*endptr;
+
+	__pri = pri = (u_int16_t)strtoul(val, &endptr, 0);
+	if(*endptr != '\0')
+		errx(1, "VLAN 802.1p must be a number");
+
+	if(pri > 7)
+	    errx(1, "VLAN 802.1p shoud be in range 0..7");
+
+	bzero((char *)&vreq, sizeof(struct vlanreq));
+	ifr.ifr_data = (caddr_t)&vreq;
+
+	if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1)
+		err(1, "SIOCGETVLAN");
+
+	vreq.vlr_tag = EVL_MAKETAG(EVL_VLANOFTAG(vreq.vlr_tag), pri, __cfi);
+
+	if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1)
+		err(1, "SIOCSETVLAN");
+
+	return;
+}
+
+void
+setvlancfi(const char *val, int d, int s, const struct afswtch	*afp)
+{
+	u_int16_t		cfi;
+	struct vlanreq		vreq;
+	char			*endptr;
+
+	__cfi = cfi = (u_int16_t)strtoul(val, &endptr, 0);
+	if(*endptr != '\0')
+		errx(1, "VLAN CFI must be a number");
+
+	if(cfi > 1)
+	    errx(1, "VLAN CFI shoud be 0 or 1");
+
 	bzero((char *)&vreq, sizeof(struct vlanreq));
 	ifr.ifr_data = (caddr_t)&vreq;
 
 	if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1)
 		err(1, "SIOCGETVLAN");
 
-	vreq.vlr_tag = tag;
+	vreq.vlr_tag = EVL_MAKETAG(EVL_VLANOFTAG(vreq.vlr_tag), __pri, cfi);
 
 	if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1)
 		err(1, "SIOCSETVLAN");
@@ -117,7 +182,7 @@
 		err(1, "SIOCGETVLAN");
 
 	strncpy(vreq.vlr_parent, val, sizeof(vreq.vlr_parent));
-	vreq.vlr_tag = __tag;
+	vreq.vlr_tag = EVL_MAKETAG(__tag, __pri, __cfi);
 
 	if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1)
 		err(1, "SIOCSETVLAN");
--- sbin/ifconfig/ifconfig.8.orig	Thu Sep 30 20:25:39 2004
+++ sbin/ifconfig/ifconfig.8	Fri Jan 21 09:39:24 2005
@@ -386,15 +386,35 @@
 pseudo interface, set the VLAN tag value
 to
 .Ar vlan_tag .
-This value is a 16-bit number which is used to create an 802.1Q
+This value is a 12-bit number which is used to create an 802.1Q
 VLAN header for packets sent from the
 .Xr vlan 4
 interface.
 Note that
-.Cm vlan
+.Cm vlan, vlanpri, vlancfi
 and
 .Cm vlandev
-must both be set at the same time.
+must be set at the same time.
+.It Cm vlanpri Ar vlan_pri
+If the interface is a
+.Xr vlan 4
+pseudo interface, set the 802.1p priority value
+to
+.Ar vlan_pri .
+This value is a 3-bit number which is used to tag outgoing
+VLAN packtes with apropriate priority. If
+.Cm vlanpri
+is omitted it default to 0.
+.It Cm vlancfi Ar vlan_cfi
+If the interface is a
+.Xr vlan 4
+pseudo interface, set the CFI value
+to
+.Ar vlan_cfi .
+This value is a 1-bit number which is used to tag outgoing
+VLAN packtes with apropriate CFI value. If
+.Cm vlancfi
+is omitted it default to 0.
 .It Cm vlandev Ar iface
 If the interface is a
 .Xr vlan 4
--- sys/net/if_vlan_var.h.orig	Mon Jan 19 00:29:04 2004
+++ sys/net/if_vlan_var.h	Tue Jan 25 11:54:33 2005
@@ -43,6 +43,8 @@
 #define EVL_VLID_MASK	0x0FFF
 #define	EVL_VLANOFTAG(tag) ((tag) & EVL_VLID_MASK)
 #define	EVL_PRIOFTAG(tag) (((tag) >> 13) & 7)
+#define	EVL_CFIOFTAG(tag) (((tag) >> 12) & 1)
+#define	EVL_MAKETAG(vlid,pri,cfi) ((((((pri) & 7) << 1) | ((cfi) & 1)) << 12) | ((vlid) & EVL_VLID_MASK))
 
 /* sysctl(3) tags, for compatibility purposes */
 #define	VLANCTL_PROTO	1
--- sys/net/if_vlan.c.orig	Wed Jan 19 10:40:32 2005
+++ sys/net/if_vlan.c	Fri Jan 21 09:05:45 2005
@@ -930,15 +930,6 @@
 			error = ENOENT;
 			break;
 		}
-		/*
-		 * Don't let the caller set up a VLAN tag with
-		 * anything except VLID bits.
-		 */
-
-		if (vlr.vlr_tag & ~EVL_VLID_MASK) {
-			error = EINVAL;
-			break;
-		}
 
 		VLAN_LOCK();
 		error = vlan_config(ifv, p);

--------------020001000007000200010100--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?41F5FE8B.40809>