Skip to content

Commit

Permalink
vlan: support "loose binding" to the underlying network device
Browse files Browse the repository at this point in the history
Currently the UP/DOWN state of VLANs is synchronized to the state of the
underlying device, meaning all VLANs are set down once the underlying
device is set down. This causes all routes to the VLAN devices to vanish.

Add a flag to specify a "loose binding" mode, in which only the operstate
is transfered, but the VLAN device state is independant.

Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Patrick McHardy authored and David S. Miller committed Nov 27, 2009
1 parent cc83f6d commit 5e75659
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/linux/if_vlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ enum vlan_ioctl_cmds {
enum vlan_flags {
VLAN_FLAG_REORDER_HDR = 0x1,
VLAN_FLAG_GVRP = 0x2,
VLAN_FLAG_LOOSE_BINDING = 0x4,
};

enum vlan_name_types {
Expand Down
9 changes: 7 additions & 2 deletions net/8021q/vlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
struct vlan_group *grp;
int i, flgs;
struct net_device *vlandev;
struct vlan_dev_info *vlan;
LIST_HEAD(list);

if (is_vlan_dev(dev))
Expand Down Expand Up @@ -507,7 +508,9 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
if (!(flgs & IFF_UP))
continue;

dev_change_flags(vlandev, flgs & ~IFF_UP);
vlan = vlan_dev_info(vlandev);
if (!(vlan->flags & VLAN_FLAG_LOOSE_BINDING))
dev_change_flags(vlandev, flgs & ~IFF_UP);
vlan_transfer_operstate(dev, vlandev);
}
break;
Expand All @@ -523,7 +526,9 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
if (flgs & IFF_UP)
continue;

dev_change_flags(vlandev, flgs | IFF_UP);
vlan = vlan_dev_info(vlandev);
if (!(vlan->flags & VLAN_FLAG_LOOSE_BINDING))
dev_change_flags(vlandev, flgs | IFF_UP);
vlan_transfer_operstate(dev, vlandev);
}
break;
Expand Down
6 changes: 4 additions & 2 deletions net/8021q/vlan_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ int vlan_dev_change_flags(const struct net_device *dev, u32 flags, u32 mask)
struct vlan_dev_info *vlan = vlan_dev_info(dev);
u32 old_flags = vlan->flags;

if (mask & ~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP))
if (mask & ~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP |
VLAN_FLAG_LOOSE_BINDING))
return -EINVAL;

vlan->flags = (old_flags & ~mask) | (flags & mask);
Expand All @@ -456,7 +457,8 @@ static int vlan_dev_open(struct net_device *dev)
struct net_device *real_dev = vlan->real_dev;
int err;

if (!(real_dev->flags & IFF_UP))
if (!(real_dev->flags & IFF_UP) &&
!(vlan->flags & VLAN_FLAG_LOOSE_BINDING))
return -ENETDOWN;

if (compare_ether_addr(dev->dev_addr, real_dev->dev_addr)) {
Expand Down
3 changes: 2 additions & 1 deletion net/8021q/vlan_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ static int vlan_validate(struct nlattr *tb[], struct nlattr *data[])
if (data[IFLA_VLAN_FLAGS]) {
flags = nla_data(data[IFLA_VLAN_FLAGS]);
if ((flags->flags & flags->mask) &
~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP))
~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP |
VLAN_FLAG_LOOSE_BINDING))
return -EINVAL;
}

Expand Down

0 comments on commit 5e75659

Please sign in to comment.