All of lore.kernel.org
 help / color / mirror / Atom feed
* VLAN patch for 2.4.21
@ 2003-08-06  0:27 Ben Greear
  0 siblings, 0 replies; 6+ messages in thread
From: Ben Greear @ 2003-08-06  0:27 UTC (permalink / raw)
  To: 'netdev@oss.sgi.com'

Here is a patch that adds a few new IOCTL options (not new IOCTLs per se)
for the 802.1Q VLANs.  One ioctl allows one to get the VID for a device by
the interface name.  A second gets the name of the underlying device for
the VLAN device.  Tested on x86 and PPC.

Comments welcome!

Thanks,
Ben



--- linux-2.4.21/net/8021q/vlan_dev.c	2003-06-13 07:51:39.000000000 -0700
+++ linux-2.4.21.amds/net/8021q/vlan_dev.c	2003-07-30 16:20:41.000000000 -0700
@@ -1,4 +1,4 @@
-/*
+/* -*- linux-c -*-
   * INET		802.1Q VLAN
   *		Ethernet-type device handling.
   *
@@ -632,6 +632,59 @@
  	return -EINVAL;
  }

+
+int vlan_dev_get_realdev_name(const char *dev_name, char* result)
+{
+	struct net_device *dev = dev_get_by_name(dev_name);
+        int rv = 0;
+
+	if (dev) {
+		if (dev->priv_flags & IFF_802_1Q_VLAN) {
+                        strncpy(result, VLAN_DEV_INFO(dev)->real_dev->name, 23);
+                        dev_put(dev);
+                        rv = 0;
+		} else {
+			printk(KERN_ERR
+			       "%s: %s is not a vlan device, priv_flags: %hX.\n",
+			       __FUNCTION__, dev->name, dev->priv_flags);
+			dev_put(dev);
+                        rv = -EINVAL;
+		}
+	} else {
+		printk(KERN_ERR  "%s: Could not find device: %s\n",
+			__FUNCTION__, dev_name);
+                rv = -ENODEV;
+	}
+
+	return rv;
+}
+
+int vlan_dev_get_vid(const char *dev_name, unsigned short* result)
+{
+	struct net_device *dev = dev_get_by_name(dev_name);
+        int rv = 0;
+
+	if (dev) {
+		if (dev->priv_flags & IFF_802_1Q_VLAN) {
+                        *result = VLAN_DEV_INFO(dev)->vlan_id;
+                        dev_put(dev);
+                        rv = 0;
+		} else {
+			printk(KERN_ERR
+			       "%s: %s is not a vlan device, priv_flags: %hX.\n",
+			       __FUNCTION__, dev->name, dev->priv_flags);
+			dev_put(dev);
+                        rv = -EINVAL;
+		}
+	} else {
+		printk(KERN_ERR  "%s: Could not find device: %s\n",
+			__FUNCTION__, dev_name);
+                rv = -ENODEV;
+	}
+
+	return rv;
+}
+
  int vlan_dev_set_mac_address(struct net_device *dev, void *addr_struct_p)
  {
  	struct sockaddr *addr = (struct sockaddr *)(addr_struct_p);
--- linux-2.4.21/net/8021q/vlan.c	2003-06-13 07:51:39.000000000 -0700
+++ linux-2.4.21.amds/net/8021q/vlan.c	2003-07-30 16:20:41.000000000 -0700
@@ -1,4 +1,4 @@
-/*
+/* -*- linux-c -*-
   * INET		802.1Q VLAN
   *		Ethernet-type device handling.
   *
@@ -655,12 +655,9 @@
  int vlan_ioctl_handler(unsigned long arg)
  {
  	int err = 0;
+        unsigned short vid = 0;
  	struct vlan_ioctl_args args;

-	/* everything here needs root permissions, except aguably the
-	 * hack ioctls for sending packets.  However, I know _I_ don't
-	 * want users running that on my network! --BLG
-	 */
  	if (!capable(CAP_NET_ADMIN))
  		return -EPERM;

@@ -678,24 +675,32 @@

  	switch (args.cmd) {
  	case SET_VLAN_INGRESS_PRIORITY_CMD:
+                if (!capable(CAP_NET_ADMIN))
+                        return -EPERM;
  		err = vlan_dev_set_ingress_priority(args.device1,
  						    args.u.skb_priority,
  						    args.vlan_qos);
  		break;

  	case SET_VLAN_EGRESS_PRIORITY_CMD:
+                if (!capable(CAP_NET_ADMIN))
+                        return -EPERM;
  		err = vlan_dev_set_egress_priority(args.device1,
  						   args.u.skb_priority,
  						   args.vlan_qos);
  		break;

  	case SET_VLAN_FLAG_CMD:
+                if (!capable(CAP_NET_ADMIN))
+                        return -EPERM;
  		err = vlan_dev_set_vlan_flag(args.device1,
  					     args.u.flag,
  					     args.vlan_qos);
  		break;

  	case SET_VLAN_NAME_TYPE_CMD:
+                if (!capable(CAP_NET_ADMIN))
+                        return -EPERM;
  		if ((args.u.name_type >= 0) &&
  		    (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
  			vlan_name_type = args.u.name_type;
@@ -705,17 +710,9 @@
  		}
  		break;

-		/* TODO:  Figure out how to pass info back...
-		   case GET_VLAN_INGRESS_PRIORITY_IOCTL:
-		   err = vlan_dev_get_ingress_priority(args);
-		   break;
-
-		   case GET_VLAN_EGRESS_PRIORITY_IOCTL:
-		   err = vlan_dev_get_egress_priority(args);
-		   break;
-		*/
-
  	case ADD_VLAN_CMD:
+                if (!capable(CAP_NET_ADMIN))
+                        return -EPERM;
  		/* we have been given the name of the Ethernet Device we want to
  		 * talk to:  args.dev1	 We also have the
  		 * VLAN ID:  args.u.VID
@@ -728,12 +725,53 @@
  		break;

  	case DEL_VLAN_CMD:
+                if (!capable(CAP_NET_ADMIN))
+                        return -EPERM;
  		/* Here, the args.dev1 is the actual VLAN we want
  		 * to get rid of.
  		 */
  		err = unregister_vlan_device(args.device1);
  		break;

+        case GET_VLAN_INGRESS_PRIORITY_CMD:
+                /* TODO:  Implement
+                err = vlan_dev_get_ingress_priority(args);
+                if (copy_to_user((void*)arg, &args,
+                                 sizeof(struct vlan_ioctl_args))) {
+                        err = -EFAULT;
+                }
+                */
+                err = -EINVAL;
+                break;
+
+        case GET_VLAN_EGRESS_PRIORITY_CMD:
+                /* TODO:  Implement
+		err = vlan_dev_get_egress_priority(args.device1, &(args.args);
+                if (copy_to_user((void*)arg, &args,
+                                 sizeof(struct vlan_ioctl_args))) {
+                        err = -EFAULT;
+                }
+                */
+                err = -EINVAL;
+                break;
+
+        case GET_VLAN_REALDEV_NAME_CMD:
+		err = vlan_dev_get_realdev_name(args.device1, args.u.device2);
+                if (copy_to_user((void*)arg, &args,
+                                 sizeof(struct vlan_ioctl_args))) {
+                        err = -EFAULT;
+                }
+                break;
+
+        case GET_VLAN_VID_CMD:
+		err = vlan_dev_get_vid(args.device1, &vid);
+                args.u.VID = vid;
+                if (copy_to_user((void*)arg, &args,
+                                 sizeof(struct vlan_ioctl_args))) {
+                        err = -EFAULT;
+                }
+                break;
+
  	default:
  		/* pass on to underlying device instead?? */
  		printk(VLAN_DBG "%s: Unknown VLAN CMD: %x \n",
--- linux-2.4.21/net/8021q/vlan.h	2002-08-02 17:39:46.000000000 -0700
+++ linux-2.4.21.amds/net/8021q/vlan.h	2003-07-30 16:30:53.000000000 -0700
@@ -72,6 +72,8 @@
  int vlan_dev_set_ingress_priority(char* dev_name, __u32 skb_prio, short vlan_prio);
  int vlan_dev_set_egress_priority(char* dev_name, __u32 skb_prio, short vlan_prio);
  int vlan_dev_set_vlan_flag(char* dev_name, __u32 flag, short flag_val);
+int vlan_dev_get_realdev_name(const char* dev_name, char* result);
+int vlan_dev_get_vid(const char* dev_name, unsigned short* result);
  void vlan_dev_set_multicast_list(struct net_device *vlan_dev);

  #endif /* !(__BEN_VLAN_802_1Q_INC__) */
--- linux-2.4.21/include/linux/if_vlan.h	2002-11-28 15:53:15.000000000 -0800
+++ linux-2.4.21.amds/include/linux/if_vlan.h	2003-07-30 16:29:30.000000000 -0700
@@ -212,7 +212,9 @@
  	GET_VLAN_INGRESS_PRIORITY_CMD,
  	GET_VLAN_EGRESS_PRIORITY_CMD,
  	SET_VLAN_NAME_TYPE_CMD,
-	SET_VLAN_FLAG_CMD
+	SET_VLAN_FLAG_CMD,
+        GET_VLAN_REALDEV_NAME_CMD, /* If this works, you know it's a VLAN device, btw */
+        GET_VLAN_VID_CMD /* Get the VID of this VLAN (specified by name) */
  };

  enum vlan_name_types {




-- 
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc  http://www.candelatech.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: VLAN patch for 2.4.21
  2003-08-07 10:22 Hen, Shmulik
@ 2003-08-07 15:49 ` Ben Greear
  0 siblings, 0 replies; 6+ messages in thread
From: Ben Greear @ 2003-08-07 15:49 UTC (permalink / raw)
  To: Hen, Shmulik; +Cc: netdev

Hen, Shmulik wrote:
>>-----Original Message-----
>>From: Ben Greear [mailto:greearb@candelatech.com]
>>Sent: Thursday, August 07, 2003 10:28 AM
>>To: Hen, Shmulik
>>Cc: netdev@oss.sgi.com
>>Subject: Re: VLAN patch for 2.4.21
>>
>>
>>You can just check the things in the net_device struct directly
>>I imagine.  The calls I added are mainly to provide the info to
>>user-space.
> 
> 
> That was my guess too. I'll figure out a way to do that
> safely from kernel space.
> 
> 
>>What information do you need, and where do you need it?
> 
> 
> In bonding, to better handle self generated packets, I'll need
> to know what vlan ID's are on top of the bond device. So, I'll
> need to listen to net dev registration notifications and sort
> out which ones are for VLAN devices, and then see if they were
> added on top of a bond device. Once I've got that, I'll need to
> get the VID and store it in bonding, so both your additions
> do exactly what I need. I also heard from the bridge developers
> that they wanted similar support, so that's 2 birds...

If it's a VLAN device, it will have priv_flags & 0x1 turned on,
see dev->priv_flags and if.h for possible values that priv_flags
can have:

/* Private (from user) interface flags (netdevice->priv_flags). */
#define IFF_802_1Q_VLAN 0x1             /* 802.1Q VLAN device.          */


You can then get it's vlan-ID by looking for:

VLAN_DEV_INFO(dev)->vlan_id;

VLAN_DEV_INFO is defined in if_vlan.h as:

#define VLAN_DEV_INFO(x) ((struct vlan_dev_info *)(x->priv))

> 
> 
> 	Shmulik.
> 
> 


-- 
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc  http://www.candelatech.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: VLAN patch for 2.4.21
@ 2003-08-07 10:22 Hen, Shmulik
  2003-08-07 15:49 ` Ben Greear
  0 siblings, 1 reply; 6+ messages in thread
From: Hen, Shmulik @ 2003-08-07 10:22 UTC (permalink / raw)
  To: Ben Greear; +Cc: netdev

> -----Original Message-----
> From: Ben Greear [mailto:greearb@candelatech.com]
> Sent: Thursday, August 07, 2003 10:28 AM
> To: Hen, Shmulik
> Cc: netdev@oss.sgi.com
> Subject: Re: VLAN patch for 2.4.21
> 
> 
> You can just check the things in the net_device struct directly
> I imagine.  The calls I added are mainly to provide the info to
> user-space.

That was my guess too. I'll figure out a way to do that
safely from kernel space.

> What information do you need, and where do you need it?

In bonding, to better handle self generated packets, I'll need
to know what vlan ID's are on top of the bond device. So, I'll
need to listen to net dev registration notifications and sort
out which ones are for VLAN devices, and then see if they were
added on top of a bond device. Once I've got that, I'll need to
get the VID and store it in bonding, so both your additions
do exactly what I need. I also heard from the bridge developers
that they wanted similar support, so that's 2 birds...


	Shmulik.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: VLAN patch for 2.4.21
  2003-08-07  7:28 ` Ben Greear
@ 2003-08-07  7:30   ` David S. Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David S. Miller @ 2003-08-07  7:30 UTC (permalink / raw)
  To: Ben Greear; +Cc: shmulik.hen, netdev

On Thu, 07 Aug 2003 00:28:12 -0700
Ben Greear <greearb@candelatech.com> wrote:

> Also, no word yet from the guys who actually take patches, so dunno
> if/when this will get into the tree.

I'll review and add your patch, I have some bigger fires
to put out first :-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: VLAN patch for 2.4.21
  2003-08-07  6:22 Hen, Shmulik
@ 2003-08-07  7:28 ` Ben Greear
  2003-08-07  7:30   ` David S. Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Ben Greear @ 2003-08-07  7:28 UTC (permalink / raw)
  To: Hen, Shmulik; +Cc: netdev

Hen, Shmulik wrote:
>>-----Original Message-----
>>From: Ben Greear [mailto:greearb@candelatech.com]
>>Sent: Wednesday, August 06, 2003 3:27 AM
>>To: 'netdev@oss.sgi.com'
>>Subject: VLAN patch for 2.4.21
>>
>>
>>Here is a patch that adds a few new IOCTL options (not new 
>>IOCTLs per se) for the 802.1Q VLANs.
>>One ioctl allows one to get the VID for a device by
>>the interface name.  A second gets the name of the underlying 
>>device for the VLAN device.  Tested on x86 and PPC.
>>
>>Comments welcome!
>>
>>Thanks,
>>Ben
>>
> 
> 
> Oh, this is great. You just saved me the work I was going to do
> for fixing VLAN stuff over bonding :)
> Any idea how to export those in a way that would enable bonding
> and alike to include them without getting dependant on 8021q module
> being loaded ? (I'm guessing inline function in a .h file, but any
> other solution is welcome (coed sample ?).

You can just check the things in the net_device struct directly
I imagine.  The calls I added are mainly to provide the info to
user-space.

What information do you need, and where do you need it?

Also, no word yet from the guys who actually take patches, so dunno
if/when this will get into the tree.

Ben

-- 
Ben Greear <greearb@candelatech.com>
Candela Technologies Inc  http://www.candelatech.com

^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: VLAN patch for 2.4.21
@ 2003-08-07  6:22 Hen, Shmulik
  2003-08-07  7:28 ` Ben Greear
  0 siblings, 1 reply; 6+ messages in thread
From: Hen, Shmulik @ 2003-08-07  6:22 UTC (permalink / raw)
  To: Ben Greear, netdev

> -----Original Message-----
> From: Ben Greear [mailto:greearb@candelatech.com]
> Sent: Wednesday, August 06, 2003 3:27 AM
> To: 'netdev@oss.sgi.com'
> Subject: VLAN patch for 2.4.21
> 
> 
> Here is a patch that adds a few new IOCTL options (not new 
> IOCTLs per se) for the 802.1Q VLANs.
> One ioctl allows one to get the VID for a device by
> the interface name.  A second gets the name of the underlying 
> device for the VLAN device.  Tested on x86 and PPC.
> 
> Comments welcome!
> 
> Thanks,
> Ben
> 

Oh, this is great. You just saved me the work I was going to do
for fixing VLAN stuff over bonding :)
Any idea how to export those in a way that would enable bonding
and alike to include them without getting dependant on 8021q module
being loaded ? (I'm guessing inline function in a .h file, but any
other solution is welcome (coed sample ?).


-- 
| Shmulik Hen   Advanced Network Services  |
| Israel Design Center, Jerusalem          |
| LAN Access Division, Platform Networking |
| Intel Communications Group, Intel corp.  |

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-08-07 15:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-06  0:27 VLAN patch for 2.4.21 Ben Greear
2003-08-07  6:22 Hen, Shmulik
2003-08-07  7:28 ` Ben Greear
2003-08-07  7:30   ` David S. Miller
2003-08-07 10:22 Hen, Shmulik
2003-08-07 15:49 ` Ben Greear

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.