Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 103341
b: refs/heads/master
c: 9bb8582
h: refs/heads/master
i:
  103339: 0879e69
v: v3
  • Loading branch information
Patrick McHardy authored and David S. Miller committed Jul 8, 2008
1 parent d88f51a commit 63ecbba
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 96 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: df6b6a0cf62afeacdeb4c1a35b8fba21fda54399
refs/heads/master: 9bb8582efb555521c7eec595ebd34e835ddc34b8
84 changes: 48 additions & 36 deletions trunk/include/linux/if_vlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,15 @@ struct vlan_group {
};

static inline struct net_device *vlan_group_get_device(struct vlan_group *vg,
unsigned int vlan_id)
u16 vlan_id)
{
struct net_device **array;
array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
return array ? array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] : NULL;
}

static inline void vlan_group_set_device(struct vlan_group *vg,
unsigned int vlan_id,
u16 vlan_id,
struct net_device *dev)
{
struct net_device **array;
Expand All @@ -122,7 +122,7 @@ extern struct net_device *vlan_dev_real_dev(const struct net_device *dev);
extern u16 vlan_dev_vlan_id(const struct net_device *dev);

extern int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp,
unsigned short vlan_tag, int polling);
u16 vlan_tci, int polling);
#else
static inline struct net_device *vlan_dev_real_dev(const struct net_device *dev)
{
Expand All @@ -137,39 +137,51 @@ static inline u16 vlan_dev_vlan_id(const struct net_device *dev)
}

static inline int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp,
unsigned short vlan_tag, int polling)
u16 vlan_tci, int polling)
{
BUG();
return NET_XMIT_SUCCESS;
}
#endif

/**
* vlan_hwaccel_rx - netif_rx wrapper for VLAN RX acceleration
* @skb: buffer
* @grp: vlan group
* @vlan_tci: VLAN TCI as received from the card
*/
static inline int vlan_hwaccel_rx(struct sk_buff *skb,
struct vlan_group *grp,
unsigned short vlan_tag)
u16 vlan_tci)
{
return __vlan_hwaccel_rx(skb, grp, vlan_tag, 0);
return __vlan_hwaccel_rx(skb, grp, vlan_tci, 0);
}

/**
* vlan_hwaccel_receive_skb - netif_receive_skb wrapper for VLAN RX acceleration
* @skb: buffer
* @grp: vlan group
* @vlan_tci: VLAN TCI as received from the card
*/
static inline int vlan_hwaccel_receive_skb(struct sk_buff *skb,
struct vlan_group *grp,
unsigned short vlan_tag)
u16 vlan_tci)
{
return __vlan_hwaccel_rx(skb, grp, vlan_tag, 1);
return __vlan_hwaccel_rx(skb, grp, vlan_tci, 1);
}

/**
* __vlan_put_tag - regular VLAN tag inserting
* @skb: skbuff to tag
* @tag: VLAN tag to insert
* @vlan_tci: VLAN TCI to insert
*
* Inserts the VLAN tag into @skb as part of the payload
* Returns a VLAN tagged skb. If a new skb is created, @skb is freed.
*
*
* Following the skb_unshare() example, in case of error, the calling function
* doesn't have to worry about freeing the original skb.
*/
static inline struct sk_buff *__vlan_put_tag(struct sk_buff *skb, unsigned short tag)
static inline struct sk_buff *__vlan_put_tag(struct sk_buff *skb, u16 vlan_tci)
{
struct vlan_ethhdr *veth;

Expand Down Expand Up @@ -197,8 +209,8 @@ static inline struct sk_buff *__vlan_put_tag(struct sk_buff *skb, unsigned short
/* first, the ethernet type */
veth->h_vlan_proto = htons(ETH_P_8021Q);

/* now, the tag */
veth->h_vlan_TCI = htons(tag);
/* now, the TCI */
veth->h_vlan_TCI = htons(vlan_tci);

skb->protocol = htons(ETH_P_8021Q);

Expand All @@ -208,17 +220,18 @@ static inline struct sk_buff *__vlan_put_tag(struct sk_buff *skb, unsigned short
/**
* __vlan_hwaccel_put_tag - hardware accelerated VLAN inserting
* @skb: skbuff to tag
* @tag: VLAN tag to insert
* @vlan_tci: VLAN TCI to insert
*
* Puts the VLAN tag in @skb->cb[] and lets the device do the rest
* Puts the VLAN TCI in @skb->cb[] and lets the device do the rest
*/
static inline struct sk_buff *__vlan_hwaccel_put_tag(struct sk_buff *skb, unsigned short tag)
static inline struct sk_buff *__vlan_hwaccel_put_tag(struct sk_buff *skb,
u16 vlan_tci)
{
struct vlan_skb_tx_cookie *cookie;

cookie = VLAN_TX_SKB_CB(skb);
cookie->magic = VLAN_TX_COOKIE_MAGIC;
cookie->vlan_tag = tag;
cookie->vlan_tag = vlan_tci;

return skb;
}
Expand All @@ -228,58 +241,57 @@ static inline struct sk_buff *__vlan_hwaccel_put_tag(struct sk_buff *skb, unsign
/**
* vlan_put_tag - inserts VLAN tag according to device features
* @skb: skbuff to tag
* @tag: VLAN tag to insert
* @vlan_tci: VLAN TCI to insert
*
* Assumes skb->dev is the target that will xmit this frame.
* Returns a VLAN tagged skb.
*/
static inline struct sk_buff *vlan_put_tag(struct sk_buff *skb, unsigned short tag)
static inline struct sk_buff *vlan_put_tag(struct sk_buff *skb, u16 vlan_tci)
{
if (skb->dev->features & NETIF_F_HW_VLAN_TX) {
return __vlan_hwaccel_put_tag(skb, tag);
return __vlan_hwaccel_put_tag(skb, vlan_tci);
} else {
return __vlan_put_tag(skb, tag);
return __vlan_put_tag(skb, vlan_tci);
}
}

/**
* __vlan_get_tag - get the VLAN ID that is part of the payload
* @skb: skbuff to query
* @tag: buffer to store vlaue
*
* @vlan_tci: buffer to store vlaue
*
* Returns error if the skb is not of VLAN type
*/
static inline int __vlan_get_tag(const struct sk_buff *skb, unsigned short *tag)
static inline int __vlan_get_tag(const struct sk_buff *skb, u16 *vlan_tci)
{
struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb->data;

if (veth->h_vlan_proto != htons(ETH_P_8021Q)) {
return -EINVAL;
}

*tag = ntohs(veth->h_vlan_TCI);

*vlan_tci = ntohs(veth->h_vlan_TCI);
return 0;
}

/**
* __vlan_hwaccel_get_tag - get the VLAN ID that is in @skb->cb[]
* @skb: skbuff to query
* @tag: buffer to store vlaue
*
* @vlan_tci: buffer to store vlaue
*
* Returns error if @skb->cb[] is not set correctly
*/
static inline int __vlan_hwaccel_get_tag(const struct sk_buff *skb,
unsigned short *tag)
u16 *vlan_tci)
{
struct vlan_skb_tx_cookie *cookie;

cookie = VLAN_TX_SKB_CB(skb);
if (cookie->magic == VLAN_TX_COOKIE_MAGIC) {
*tag = cookie->vlan_tag;
*vlan_tci = cookie->vlan_tag;
return 0;
} else {
*tag = 0;
*vlan_tci = 0;
return -EINVAL;
}
}
Expand All @@ -289,16 +301,16 @@ static inline int __vlan_hwaccel_get_tag(const struct sk_buff *skb,
/**
* vlan_get_tag - get the VLAN ID from the skb
* @skb: skbuff to query
* @tag: buffer to store vlaue
*
* @vlan_tci: buffer to store vlaue
*
* Returns error if the skb is not VLAN tagged
*/
static inline int vlan_get_tag(const struct sk_buff *skb, unsigned short *tag)
static inline int vlan_get_tag(const struct sk_buff *skb, u16 *vlan_tci)
{
if (skb->dev->features & NETIF_F_HW_VLAN_TX) {
return __vlan_hwaccel_get_tag(skb, tag);
return __vlan_hwaccel_get_tag(skb, vlan_tci);
} else {
return __vlan_get_tag(skb, tag);
return __vlan_get_tag(skb, vlan_tci);
}
}

Expand Down
34 changes: 16 additions & 18 deletions trunk/net/8021q/vlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,12 @@ static struct vlan_group *__vlan_find_group(struct net_device *real_dev)
*
* Must be invoked with RCU read lock (no preempt)
*/
struct net_device *__find_vlan_dev(struct net_device *real_dev,
unsigned short VID)
struct net_device *__find_vlan_dev(struct net_device *real_dev, u16 vlan_id)
{
struct vlan_group *grp = __vlan_find_group(real_dev);

if (grp)
return vlan_group_get_device(grp, VID);
return vlan_group_get_device(grp, vlan_id);

return NULL;
}
Expand Down Expand Up @@ -117,14 +116,14 @@ static struct vlan_group *vlan_group_alloc(struct net_device *real_dev)
return grp;
}

static int vlan_group_prealloc_vid(struct vlan_group *vg, int vid)
static int vlan_group_prealloc_vid(struct vlan_group *vg, u16 vlan_id)
{
struct net_device **array;
unsigned int size;

ASSERT_RTNL();

array = vg->vlan_devices_arrays[vid / VLAN_GROUP_ARRAY_PART_LEN];
array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
if (array != NULL)
return 0;

Expand All @@ -133,7 +132,7 @@ static int vlan_group_prealloc_vid(struct vlan_group *vg, int vid)
if (array == NULL)
return -ENOBUFS;

vg->vlan_devices_arrays[vid / VLAN_GROUP_ARRAY_PART_LEN] = array;
vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN] = array;
return 0;
}

Expand All @@ -147,7 +146,7 @@ void unregister_vlan_dev(struct net_device *dev)
struct vlan_dev_info *vlan = vlan_dev_info(dev);
struct net_device *real_dev = vlan->real_dev;
struct vlan_group *grp;
unsigned short vlan_id = vlan->vlan_id;
u16 vlan_id = vlan->vlan_id;

ASSERT_RTNL();

Expand Down Expand Up @@ -205,7 +204,7 @@ static void vlan_transfer_operstate(const struct net_device *dev,
}
}

int vlan_check_real_dev(struct net_device *real_dev, unsigned short vlan_id)
int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id)
{
char *name = real_dev->name;

Expand Down Expand Up @@ -242,7 +241,7 @@ int register_vlan_dev(struct net_device *dev)
{
struct vlan_dev_info *vlan = vlan_dev_info(dev);
struct net_device *real_dev = vlan->real_dev;
unsigned short vlan_id = vlan->vlan_id;
u16 vlan_id = vlan->vlan_id;
struct vlan_group *grp, *ngrp = NULL;
int err;

Expand Down Expand Up @@ -295,46 +294,45 @@ int register_vlan_dev(struct net_device *dev)
/* Attach a VLAN device to a mac address (ie Ethernet Card).
* Returns 0 if the device was created or a negative error code otherwise.
*/
static int register_vlan_device(struct net_device *real_dev,
unsigned short VLAN_ID)
static int register_vlan_device(struct net_device *real_dev, u16 vlan_id)
{
struct net_device *new_dev;
struct net *net = dev_net(real_dev);
struct vlan_net *vn = net_generic(net, vlan_net_id);
char name[IFNAMSIZ];
int err;

if (VLAN_ID >= VLAN_VID_MASK)
if (vlan_id >= VLAN_VID_MASK)
return -ERANGE;

err = vlan_check_real_dev(real_dev, VLAN_ID);
err = vlan_check_real_dev(real_dev, vlan_id);
if (err < 0)
return err;

/* Gotta set up the fields for the device. */
switch (vn->name_type) {
case VLAN_NAME_TYPE_RAW_PLUS_VID:
/* name will look like: eth1.0005 */
snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, VLAN_ID);
snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, vlan_id);
break;
case VLAN_NAME_TYPE_PLUS_VID_NO_PAD:
/* Put our vlan.VID in the name.
* Name will look like: vlan5
*/
snprintf(name, IFNAMSIZ, "vlan%i", VLAN_ID);
snprintf(name, IFNAMSIZ, "vlan%i", vlan_id);
break;
case VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD:
/* Put our vlan.VID in the name.
* Name will look like: eth0.5
*/
snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, VLAN_ID);
snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, vlan_id);
break;
case VLAN_NAME_TYPE_PLUS_VID:
/* Put our vlan.VID in the name.
* Name will look like: vlan0005
*/
default:
snprintf(name, IFNAMSIZ, "vlan%.4i", VLAN_ID);
snprintf(name, IFNAMSIZ, "vlan%.4i", vlan_id);
}

new_dev = alloc_netdev(sizeof(struct vlan_dev_info), name,
Expand All @@ -349,7 +347,7 @@ static int register_vlan_device(struct net_device *real_dev,
*/
new_dev->mtu = real_dev->mtu;

vlan_dev_info(new_dev)->vlan_id = VLAN_ID; /* 1 through VLAN_VID_MASK */
vlan_dev_info(new_dev)->vlan_id = vlan_id;
vlan_dev_info(new_dev)->real_dev = real_dev;
vlan_dev_info(new_dev)->dent = NULL;
vlan_dev_info(new_dev)->flags = VLAN_FLAG_REORDER_HDR;
Expand Down
Loading

0 comments on commit 63ecbba

Please sign in to comment.