Skip to content

Commit 954d1fa

Browse files
herbertxdavem330
authored andcommitted
macvlan: Add netlink attribute for broadcast cutoff
Make the broadcast cutoff configurable through netlink. Note that macvlan is weird because there is no central device for us to configure (the lowerdev could be anything). So all the options are duplicated over what could be thousands of child devices. IFLA_MACVLAN_BC_QUEUE_LEN took the approach of taking the maximum of all child device settings. This is unnecessary as we could simply store the option in the port device and take the last child device that gets updated as the value to use. Signed-off-by: Herbert Xu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d45276e commit 954d1fa

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

drivers/net/macvlan.c

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ struct macvlan_port {
4747
struct sk_buff_head bc_queue;
4848
struct work_struct bc_work;
4949
u32 bc_queue_len_used;
50+
int bc_cutoff;
5051
u32 flags;
5152
int count;
5253
struct hlist_head vlan_source_hash[MACVLAN_HASH_SIZE];
@@ -814,6 +815,12 @@ static void macvlan_compute_filter(unsigned long *mc_filter,
814815
}
815816
}
816817

818+
static void macvlan_recompute_bc_filter(struct macvlan_dev *vlan)
819+
{
820+
macvlan_compute_filter(vlan->port->bc_filter, vlan->lowerdev, NULL,
821+
vlan->port->bc_cutoff);
822+
}
823+
817824
static void macvlan_set_mac_lists(struct net_device *dev)
818825
{
819826
struct macvlan_dev *vlan = netdev_priv(dev);
@@ -838,8 +845,16 @@ static void macvlan_set_mac_lists(struct net_device *dev)
838845
*/
839846
macvlan_compute_filter(vlan->port->mc_filter, vlan->lowerdev, NULL,
840847
0);
841-
macvlan_compute_filter(vlan->port->bc_filter, vlan->lowerdev, NULL,
842-
1);
848+
macvlan_recompute_bc_filter(vlan);
849+
}
850+
851+
static void update_port_bc_cutoff(struct macvlan_dev *vlan, int cutoff)
852+
{
853+
if (vlan->port->bc_cutoff == cutoff)
854+
return;
855+
856+
vlan->port->bc_cutoff = cutoff;
857+
macvlan_recompute_bc_filter(vlan);
843858
}
844859

845860
static int macvlan_change_mtu(struct net_device *dev, int new_mtu)
@@ -1254,6 +1269,7 @@ static int macvlan_port_create(struct net_device *dev)
12541269
INIT_HLIST_HEAD(&port->vlan_source_hash[i]);
12551270

12561271
port->bc_queue_len_used = 0;
1272+
port->bc_cutoff = 1;
12571273
skb_queue_head_init(&port->bc_queue);
12581274
INIT_WORK(&port->bc_work, macvlan_process_broadcast);
12591275

@@ -1527,6 +1543,10 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
15271543
if (data && data[IFLA_MACVLAN_BC_QUEUE_LEN])
15281544
vlan->bc_queue_len_req = nla_get_u32(data[IFLA_MACVLAN_BC_QUEUE_LEN]);
15291545

1546+
if (data && data[IFLA_MACVLAN_BC_CUTOFF])
1547+
update_port_bc_cutoff(
1548+
vlan, nla_get_s32(data[IFLA_MACVLAN_BC_CUTOFF]));
1549+
15301550
err = register_netdevice(dev);
15311551
if (err < 0)
15321552
goto destroy_macvlan_port;
@@ -1623,6 +1643,10 @@ static int macvlan_changelink(struct net_device *dev,
16231643
update_port_bc_queue_len(vlan->port);
16241644
}
16251645

1646+
if (data && data[IFLA_MACVLAN_BC_CUTOFF])
1647+
update_port_bc_cutoff(
1648+
vlan, nla_get_s32(data[IFLA_MACVLAN_BC_CUTOFF]));
1649+
16261650
if (set_mode)
16271651
vlan->mode = mode;
16281652
if (data && data[IFLA_MACVLAN_MACADDR_MODE]) {
@@ -1703,6 +1727,9 @@ static int macvlan_fill_info(struct sk_buff *skb,
17031727
goto nla_put_failure;
17041728
if (nla_put_u32(skb, IFLA_MACVLAN_BC_QUEUE_LEN_USED, port->bc_queue_len_used))
17051729
goto nla_put_failure;
1730+
if (port->bc_cutoff != 1 &&
1731+
nla_put_s32(skb, IFLA_MACVLAN_BC_CUTOFF, port->bc_cutoff))
1732+
goto nla_put_failure;
17061733
return 0;
17071734

17081735
nla_put_failure:

include/uapi/linux/if_link.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ enum {
635635
IFLA_MACVLAN_MACADDR_COUNT,
636636
IFLA_MACVLAN_BC_QUEUE_LEN,
637637
IFLA_MACVLAN_BC_QUEUE_LEN_USED,
638+
IFLA_MACVLAN_BC_CUTOFF,
638639
__IFLA_MACVLAN_MAX,
639640
};
640641

tools/include/uapi/linux/if_link.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ enum {
605605
IFLA_MACVLAN_MACADDR_COUNT,
606606
IFLA_MACVLAN_BC_QUEUE_LEN,
607607
IFLA_MACVLAN_BC_QUEUE_LEN_USED,
608+
IFLA_MACVLAN_BC_CUTOFF,
608609
__IFLA_MACVLAN_MAX,
609610
};
610611

0 commit comments

Comments
 (0)