Skip to contentSkip to conversation

VLAN patch for 2.4.21

PATCH Ben Greear 1 participant 1 message Aug 6, 2003

Subsystems (2)
lore
Share & tools
lore

Ben Greear

author
#0 lore raw

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

net/8021q/vlan_dev.c +54 -1
@@ -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);
net/8021q/vlan.c +53 -15

122 lines not on this page · raw message

net/8021q/vlan.h +2 -0
@@ -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__) */
include/linux/if_vlan.h +3 -1
@@ -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 {
Signature · 2 lines
Ben Greear <[email protected]>
Candela Technologies Inc  http://www.candelatech.com