Skip to content

Commit 3e403a7

Browse files
vfalicodavem330
authored andcommitted
bonding: make it possible to have unlimited nested upper vlans
Currently we're limited by a constant level of vlan nestings, and fail to find anything beyound that level (currently 2). To fix this - remove the limit of nestings when going through device tree, and when the end device is found - allocate the needed amount of vlan tags and return them, instead of found/not found. CC: Jay Vosburgh <j.vosburgh@gmail.com> CC: Andy Gospodarek <andy@greyhouse.net> Signed-off-by: Veaceslav Falico <vfalico@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 224e923 commit 3e403a7

3 files changed

Lines changed: 58 additions & 39 deletions

File tree

‎drivers/net/bonding/bond_alb.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[],
10421042
struct bonding *bond = bond_get_bond_by_slave(slave);
10431043
struct net_device *upper;
10441044
struct list_head *iter;
1045-
struct bond_vlan_tag tags[BOND_MAX_VLAN_ENCAP];
1045+
struct bond_vlan_tag *tags;
10461046

10471047
/* send untagged */
10481048
alb_send_lp_vid(slave, mac_addr, 0, 0);
@@ -1070,10 +1070,12 @@ static void alb_send_learning_packets(struct slave *slave, u8 mac_addr[],
10701070
* when strict_match is turned off.
10711071
*/
10721072
if (netif_is_macvlan(upper) && !strict_match) {
1073-
memset(tags, 0, sizeof(tags));
1074-
bond_verify_device_path(bond->dev, upper, tags);
1073+
tags = bond_verify_device_path(bond->dev, upper, 0);
1074+
if (IS_ERR_OR_NULL(tags))
1075+
BUG();
10751076
alb_send_lp_vid(slave, upper->dev_addr,
10761077
tags[0].vlan_proto, tags[0].vlan_id);
1078+
kfree(tags);
10771079
}
10781080
}
10791081
rcu_read_unlock();

‎drivers/net/bonding/bond_main.c‎

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,7 +2145,7 @@ static void bond_arp_send(struct net_device *slave_dev, int arp_op,
21452145
struct bond_vlan_tag *tags)
21462146
{
21472147
struct sk_buff *skb;
2148-
int i;
2148+
struct bond_vlan_tag *outer_tag = tags;
21492149

21502150
netdev_dbg(slave_dev, "arp %d on slave %s: dst %pI4 src %pI4\n",
21512151
arp_op, slave_dev->name, &dest_ip, &src_ip);
@@ -2158,30 +2158,42 @@ static void bond_arp_send(struct net_device *slave_dev, int arp_op,
21582158
return;
21592159
}
21602160

2161+
if (!tags || tags->vlan_proto == VLAN_N_VID)
2162+
goto xmit;
2163+
2164+
tags++;
2165+
21612166
/* Go through all the tags backwards and add them to the packet */
2162-
for (i = BOND_MAX_VLAN_ENCAP - 1; i > 0; i--) {
2163-
if (!tags[i].vlan_id)
2167+
while (tags->vlan_proto != VLAN_N_VID) {
2168+
if (!tags->vlan_id) {
2169+
tags++;
21642170
continue;
2171+
}
21652172

21662173
netdev_dbg(slave_dev, "inner tag: proto %X vid %X\n",
2167-
ntohs(tags[i].vlan_proto), tags[i].vlan_id);
2168-
skb = __vlan_put_tag(skb, tags[i].vlan_proto,
2169-
tags[i].vlan_id);
2174+
ntohs(outer_tag->vlan_proto), tags->vlan_id);
2175+
skb = __vlan_put_tag(skb, tags->vlan_proto,
2176+
tags->vlan_id);
21702177
if (!skb) {
21712178
net_err_ratelimited("failed to insert inner VLAN tag\n");
21722179
return;
21732180
}
2181+
2182+
tags++;
21742183
}
21752184
/* Set the outer tag */
2176-
if (tags[0].vlan_id) {
2185+
if (outer_tag->vlan_id) {
21772186
netdev_dbg(slave_dev, "outer tag: proto %X vid %X\n",
2178-
ntohs(tags[0].vlan_proto), tags[0].vlan_id);
2179-
skb = vlan_put_tag(skb, tags[0].vlan_proto, tags[0].vlan_id);
2187+
ntohs(outer_tag->vlan_proto), outer_tag->vlan_id);
2188+
skb = vlan_put_tag(skb, outer_tag->vlan_proto,
2189+
outer_tag->vlan_id);
21802190
if (!skb) {
21812191
net_err_ratelimited("failed to insert outer VLAN tag\n");
21822192
return;
21832193
}
21842194
}
2195+
2196+
xmit:
21852197
arp_xmit(skb);
21862198
}
21872199

@@ -2191,46 +2203,50 @@ static void bond_arp_send(struct net_device *slave_dev, int arp_op,
21912203
* When the path is validated, collect any vlan information in the
21922204
* path.
21932205
*/
2194-
bool bond_verify_device_path(struct net_device *start_dev,
2195-
struct net_device *end_dev,
2196-
struct bond_vlan_tag *tags)
2206+
struct bond_vlan_tag *bond_verify_device_path(struct net_device *start_dev,
2207+
struct net_device *end_dev,
2208+
int level)
21972209
{
2210+
struct bond_vlan_tag *tags;
21982211
struct net_device *upper;
21992212
struct list_head *iter;
2200-
int idx;
22012213

2202-
if (start_dev == end_dev)
2203-
return true;
2214+
if (start_dev == end_dev) {
2215+
tags = kzalloc(sizeof(*tags) * (level + 1), GFP_ATOMIC);
2216+
if (!tags)
2217+
return ERR_PTR(-ENOMEM);
2218+
tags[level].vlan_proto = VLAN_N_VID;
2219+
return tags;
2220+
}
22042221

22052222
netdev_for_each_upper_dev_rcu(start_dev, upper, iter) {
2206-
if (bond_verify_device_path(upper, end_dev, tags)) {
2207-
if (is_vlan_dev(upper)) {
2208-
idx = vlan_get_encap_level(upper);
2209-
if (idx >= BOND_MAX_VLAN_ENCAP)
2210-
return false;
2211-
2212-
tags[idx].vlan_proto =
2213-
vlan_dev_vlan_proto(upper);
2214-
tags[idx].vlan_id = vlan_dev_vlan_id(upper);
2215-
}
2216-
return true;
2223+
tags = bond_verify_device_path(upper, end_dev, level + 1);
2224+
if (IS_ERR_OR_NULL(tags)) {
2225+
if (IS_ERR(tags))
2226+
return tags;
2227+
continue;
22172228
}
2229+
if (is_vlan_dev(upper)) {
2230+
tags[level].vlan_proto = vlan_dev_vlan_proto(upper);
2231+
tags[level].vlan_id = vlan_dev_vlan_id(upper);
2232+
}
2233+
2234+
return tags;
22182235
}
22192236

2220-
return false;
2237+
return NULL;
22212238
}
22222239

22232240
static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
22242241
{
22252242
struct rtable *rt;
2226-
struct bond_vlan_tag tags[BOND_MAX_VLAN_ENCAP];
2243+
struct bond_vlan_tag *tags;
22272244
__be32 *targets = bond->params.arp_targets, addr;
22282245
int i;
2229-
bool ret;
22302246

22312247
for (i = 0; i < BOND_MAX_ARP_TARGETS && targets[i]; i++) {
22322248
netdev_dbg(bond->dev, "basa: target %pI4\n", &targets[i]);
2233-
memset(tags, 0, sizeof(tags));
2249+
tags = NULL;
22342250

22352251
/* Find out through which dev should the packet go */
22362252
rt = ip_route_output(dev_net(bond->dev), targets[i], 0,
@@ -2253,10 +2269,10 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
22532269
goto found;
22542270

22552271
rcu_read_lock();
2256-
ret = bond_verify_device_path(bond->dev, rt->dst.dev, tags);
2272+
tags = bond_verify_device_path(bond->dev, rt->dst.dev, 0);
22572273
rcu_read_unlock();
22582274

2259-
if (ret)
2275+
if (!IS_ERR_OR_NULL(tags))
22602276
goto found;
22612277

22622278
/* Not our device - skip */
@@ -2271,6 +2287,8 @@ static void bond_arp_send_all(struct bonding *bond, struct slave *slave)
22712287
ip_rt_put(rt);
22722288
bond_arp_send(slave->dev, ARPOP_REQUEST, targets[i],
22732289
addr, tags);
2290+
if (!tags)
2291+
kfree(tags);
22742292
}
22752293
}
22762294

‎drivers/net/bonding/bonding.h‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
#define bond_version DRV_DESCRIPTION ": v" DRV_VERSION " (" DRV_RELDATE ")\n"
3838

39-
#define BOND_MAX_VLAN_ENCAP 2
4039
#define BOND_MAX_ARP_TARGETS 16
4140

4241
#define BOND_DEFAULT_MIIMON 100
@@ -525,9 +524,9 @@ int bond_netlink_init(void);
525524
void bond_netlink_fini(void);
526525
struct net_device *bond_option_active_slave_get_rcu(struct bonding *bond);
527526
const char *bond_slave_link_status(s8 link);
528-
bool bond_verify_device_path(struct net_device *start_dev,
529-
struct net_device *end_dev,
530-
struct bond_vlan_tag *tags);
527+
struct bond_vlan_tag *bond_verify_device_path(struct net_device *start_dev,
528+
struct net_device *end_dev,
529+
int level);
531530

532531
#ifdef CONFIG_PROC_FS
533532
void bond_create_proc_entry(struct bonding *bond);

0 commit comments

Comments
 (0)