Commit 30b0594a authored by David S. Miller's avatar David S. Miller

Merge branch 'net-bridge-convert-bool-options-to-bits'

Nikolay Aleksandrov says:

====================
net: bridge: convert bool options to bits

A lot of boolean bridge options have been added around the net_bridge
structure resulting in holes and more importantly different cache lines
that need to be fetched in the fast path. This set moves all of those
to bits in a bitfield which resides in a hot cache line thus reducing
the size of net_bridge, the number of holes and the number of cache
lines needed for the fast path.
The set is also sent in preparation for new boolean options to avoid
spreading them in the structure and making new holes.
One nice side-effect is that we avoid potential race conditions by using
the bitops since some of the options were bits being directly set in
parallel risking hard to debug issues (has_ipv6_addr).

Before:
 size: 1184, holes: 8, sum holes: 30
After:
 size: 1160, holes: 3, sum holes: 7

Patch 01 is a trivial style fix
Patch 02 adds the new options bitfield and converts the vlan boolean
         options to bits
Patches 03-08 convert the rest of the boolean options to bits
Patch 09 re-arranges a few fields in net_bridge to further reduce size

v2: patch 09: remove the comment about offload_fwd_mark in net_bridge and
    leave it where it is now, thanks to Ido for spotting it
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 37ac5db6 35750b0b
...@@ -175,6 +175,22 @@ static struct notifier_block br_switchdev_notifier = { ...@@ -175,6 +175,22 @@ static struct notifier_block br_switchdev_notifier = {
.notifier_call = br_switchdev_event, .notifier_call = br_switchdev_event,
}; };
void br_opt_toggle(struct net_bridge *br, enum net_bridge_opts opt, bool on)
{
bool cur = !!br_opt_get(br, opt);
br_debug(br, "toggle option: %d state: %d -> %d\n",
opt, cur, on);
if (cur == on)
return;
if (on)
set_bit(opt, &br->options);
else
clear_bit(opt, &br->options);
}
static void __net_exit br_net_exit(struct net *net) static void __net_exit br_net_exit(struct net *net)
{ {
struct net_device *dev; struct net_device *dev;
......
...@@ -39,7 +39,7 @@ void br_recalculate_neigh_suppress_enabled(struct net_bridge *br) ...@@ -39,7 +39,7 @@ void br_recalculate_neigh_suppress_enabled(struct net_bridge *br)
} }
} }
br->neigh_suppress_enabled = neigh_suppress; br_opt_toggle(br, BROPT_NEIGH_SUPPRESS_ENABLED, neigh_suppress);
} }
#if IS_ENABLED(CONFIG_INET) #if IS_ENABLED(CONFIG_INET)
...@@ -155,7 +155,7 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, ...@@ -155,7 +155,7 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,
ipv4_is_multicast(tip)) ipv4_is_multicast(tip))
return; return;
if (br->neigh_suppress_enabled) { if (br_opt_get(br, BROPT_NEIGH_SUPPRESS_ENABLED)) {
if (p && (p->flags & BR_NEIGH_SUPPRESS)) if (p && (p->flags & BR_NEIGH_SUPPRESS))
return; return;
if (ipv4_is_zeronet(sip) || sip == tip) { if (ipv4_is_zeronet(sip) || sip == tip) {
...@@ -175,7 +175,8 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, ...@@ -175,7 +175,8 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,
return; return;
} }
if (br->neigh_suppress_enabled && br_is_local_ip(vlandev, tip)) { if (br_opt_get(br, BROPT_NEIGH_SUPPRESS_ENABLED) &&
br_is_local_ip(vlandev, tip)) {
/* its our local ip, so don't proxy reply /* its our local ip, so don't proxy reply
* and don't forward to neigh suppress ports * and don't forward to neigh suppress ports
*/ */
...@@ -213,7 +214,8 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br, ...@@ -213,7 +214,8 @@ void br_do_proxy_suppress_arp(struct sk_buff *skb, struct net_bridge *br,
/* If we have replied or as long as we know the /* If we have replied or as long as we know the
* mac, indicate to arp replied * mac, indicate to arp replied
*/ */
if (replied || br->neigh_suppress_enabled) if (replied ||
br_opt_get(br, BROPT_NEIGH_SUPPRESS_ENABLED))
BR_INPUT_SKB_CB(skb)->proxyarp_replied = true; BR_INPUT_SKB_CB(skb)->proxyarp_replied = true;
} }
...@@ -460,7 +462,8 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br, ...@@ -460,7 +462,8 @@ void br_do_suppress_nd(struct sk_buff *skb, struct net_bridge *br,
* mac, indicate to NEIGH_SUPPRESS ports that we * mac, indicate to NEIGH_SUPPRESS ports that we
* have replied * have replied
*/ */
if (replied || br->neigh_suppress_enabled) if (replied ||
br_opt_get(br, BROPT_NEIGH_SUPPRESS_ENABLED))
BR_INPUT_SKB_CB(skb)->proxyarp_replied = true; BR_INPUT_SKB_CB(skb)->proxyarp_replied = true;
} }
neigh_release(n); neigh_release(n);
......
...@@ -67,11 +67,11 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev) ...@@ -67,11 +67,11 @@ netdev_tx_t br_dev_xmit(struct sk_buff *skb, struct net_device *dev)
if (IS_ENABLED(CONFIG_INET) && if (IS_ENABLED(CONFIG_INET) &&
(eth->h_proto == htons(ETH_P_ARP) || (eth->h_proto == htons(ETH_P_ARP) ||
eth->h_proto == htons(ETH_P_RARP)) && eth->h_proto == htons(ETH_P_RARP)) &&
br->neigh_suppress_enabled) { br_opt_get(br, BROPT_NEIGH_SUPPRESS_ENABLED)) {
br_do_proxy_suppress_arp(skb, br, vid, NULL); br_do_proxy_suppress_arp(skb, br, vid, NULL);
} else if (IS_ENABLED(CONFIG_IPV6) && } else if (IS_ENABLED(CONFIG_IPV6) &&
skb->protocol == htons(ETH_P_IPV6) && skb->protocol == htons(ETH_P_IPV6) &&
br->neigh_suppress_enabled && br_opt_get(br, BROPT_NEIGH_SUPPRESS_ENABLED) &&
pskb_may_pull(skb, sizeof(struct ipv6hdr) + pskb_may_pull(skb, sizeof(struct ipv6hdr) +
sizeof(struct nd_msg)) && sizeof(struct nd_msg)) &&
ipv6_hdr(skb)->nexthdr == IPPROTO_ICMPV6) { ipv6_hdr(skb)->nexthdr == IPPROTO_ICMPV6) {
...@@ -228,7 +228,7 @@ static int br_change_mtu(struct net_device *dev, int new_mtu) ...@@ -228,7 +228,7 @@ static int br_change_mtu(struct net_device *dev, int new_mtu)
dev->mtu = new_mtu; dev->mtu = new_mtu;
/* this flag will be cleared if the MTU was automatically adjusted */ /* this flag will be cleared if the MTU was automatically adjusted */
br->mtu_set_by_user = true; br_opt_toggle(br, BROPT_MTU_SET_BY_USER, true);
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
/* remember the MTU in the rtable for PMTU */ /* remember the MTU in the rtable for PMTU */
dst_metric_set(&br->fake_rtable.dst, RTAX_MTU, new_mtu); dst_metric_set(&br->fake_rtable.dst, RTAX_MTU, new_mtu);
......
...@@ -508,14 +508,14 @@ void br_mtu_auto_adjust(struct net_bridge *br) ...@@ -508,14 +508,14 @@ void br_mtu_auto_adjust(struct net_bridge *br)
ASSERT_RTNL(); ASSERT_RTNL();
/* if the bridge MTU was manually configured don't mess with it */ /* if the bridge MTU was manually configured don't mess with it */
if (br->mtu_set_by_user) if (br_opt_get(br, BROPT_MTU_SET_BY_USER))
return; return;
/* change to the minimum MTU and clear the flag which was set by /* change to the minimum MTU and clear the flag which was set by
* the bridge ndo_change_mtu callback * the bridge ndo_change_mtu callback
*/ */
dev_set_mtu(br->dev, br_mtu_min(br)); dev_set_mtu(br->dev, br_mtu_min(br));
br->mtu_set_by_user = false; br_opt_toggle(br, BROPT_MTU_SET_BY_USER, false);
} }
static void br_set_gso_limits(struct net_bridge *br) static void br_set_gso_limits(struct net_bridge *br)
......
...@@ -122,7 +122,7 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb ...@@ -122,7 +122,7 @@ int br_handle_frame_finish(struct net *net, struct sock *sk, struct sk_buff *skb
br_do_proxy_suppress_arp(skb, br, vid, p); br_do_proxy_suppress_arp(skb, br, vid, p);
} else if (IS_ENABLED(CONFIG_IPV6) && } else if (IS_ENABLED(CONFIG_IPV6) &&
skb->protocol == htons(ETH_P_IPV6) && skb->protocol == htons(ETH_P_IPV6) &&
br->neigh_suppress_enabled && br_opt_get(br, BROPT_NEIGH_SUPPRESS_ENABLED) &&
pskb_may_pull(skb, sizeof(struct ipv6hdr) + pskb_may_pull(skb, sizeof(struct ipv6hdr) +
sizeof(struct nd_msg)) && sizeof(struct nd_msg)) &&
ipv6_hdr(skb)->nexthdr == IPPROTO_ICMPV6) { ipv6_hdr(skb)->nexthdr == IPPROTO_ICMPV6) {
......
...@@ -84,7 +84,7 @@ static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb, ...@@ -84,7 +84,7 @@ static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
int i, err = 0; int i, err = 0;
int idx = 0, s_idx = cb->args[1]; int idx = 0, s_idx = cb->args[1];
if (br->multicast_disabled) if (!br_opt_get(br, BROPT_MULTICAST_ENABLED))
return 0; return 0;
mdb = rcu_dereference(br->mdb); mdb = rcu_dereference(br->mdb);
...@@ -598,7 +598,7 @@ static int __br_mdb_add(struct net *net, struct net_bridge *br, ...@@ -598,7 +598,7 @@ static int __br_mdb_add(struct net *net, struct net_bridge *br,
struct net_bridge_port *p; struct net_bridge_port *p;
int ret; int ret;
if (!netif_running(br->dev) || br->multicast_disabled) if (!netif_running(br->dev) || !br_opt_get(br, BROPT_MULTICAST_ENABLED))
return -EINVAL; return -EINVAL;
dev = __dev_get_by_index(net, entry->ifindex); dev = __dev_get_by_index(net, entry->ifindex);
...@@ -673,7 +673,7 @@ static int __br_mdb_del(struct net_bridge *br, struct br_mdb_entry *entry) ...@@ -673,7 +673,7 @@ static int __br_mdb_del(struct net_bridge *br, struct br_mdb_entry *entry)
struct br_ip ip; struct br_ip ip;
int err = -EINVAL; int err = -EINVAL;
if (!netif_running(br->dev) || br->multicast_disabled) if (!netif_running(br->dev) || !br_opt_get(br, BROPT_MULTICAST_ENABLED))
return -EINVAL; return -EINVAL;
__mdb_entry_to_br_ip(entry, &ip); __mdb_entry_to_br_ip(entry, &ip);
......
...@@ -158,7 +158,7 @@ struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br, ...@@ -158,7 +158,7 @@ struct net_bridge_mdb_entry *br_mdb_get(struct net_bridge *br,
struct net_bridge_mdb_htable *mdb = rcu_dereference(br->mdb); struct net_bridge_mdb_htable *mdb = rcu_dereference(br->mdb);
struct br_ip ip; struct br_ip ip;
if (br->multicast_disabled) if (!br_opt_get(br, BROPT_MULTICAST_ENABLED))
return NULL; return NULL;
if (BR_INPUT_SKB_CB(skb)->igmp) if (BR_INPUT_SKB_CB(skb)->igmp)
...@@ -411,7 +411,7 @@ static struct sk_buff *br_ip4_multicast_alloc_query(struct net_bridge *br, ...@@ -411,7 +411,7 @@ static struct sk_buff *br_ip4_multicast_alloc_query(struct net_bridge *br,
iph->frag_off = htons(IP_DF); iph->frag_off = htons(IP_DF);
iph->ttl = 1; iph->ttl = 1;
iph->protocol = IPPROTO_IGMP; iph->protocol = IPPROTO_IGMP;
iph->saddr = br->multicast_query_use_ifaddr ? iph->saddr = br_opt_get(br, BROPT_MULTICAST_QUERY_USE_IFADDR) ?
inet_select_addr(br->dev, 0, RT_SCOPE_LINK) : 0; inet_select_addr(br->dev, 0, RT_SCOPE_LINK) : 0;
iph->daddr = htonl(INADDR_ALLHOSTS_GROUP); iph->daddr = htonl(INADDR_ALLHOSTS_GROUP);
((u8 *)&iph[1])[0] = IPOPT_RA; ((u8 *)&iph[1])[0] = IPOPT_RA;
...@@ -503,11 +503,11 @@ static struct sk_buff *br_ip6_multicast_alloc_query(struct net_bridge *br, ...@@ -503,11 +503,11 @@ static struct sk_buff *br_ip6_multicast_alloc_query(struct net_bridge *br,
if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0, if (ipv6_dev_get_saddr(dev_net(br->dev), br->dev, &ip6h->daddr, 0,
&ip6h->saddr)) { &ip6h->saddr)) {
kfree_skb(skb); kfree_skb(skb);
br->has_ipv6_addr = 0; br_opt_toggle(br, BROPT_HAS_IPV6_ADDR, false);
return NULL; return NULL;
} }
br->has_ipv6_addr = 1; br_opt_toggle(br, BROPT_HAS_IPV6_ADDR, true);
ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest); ipv6_eth_mc_map(&ip6h->daddr, eth->h_dest);
hopopt = (u8 *)(ip6h + 1); hopopt = (u8 *)(ip6h + 1);
...@@ -628,7 +628,7 @@ static struct net_bridge_mdb_entry *br_multicast_get_group( ...@@ -628,7 +628,7 @@ static struct net_bridge_mdb_entry *br_multicast_get_group(
port ? port->dev->name : br->dev->name); port ? port->dev->name : br->dev->name);
err = -E2BIG; err = -E2BIG;
disable: disable:
br->multicast_disabled = 1; br_opt_toggle(br, BROPT_MULTICAST_ENABLED, false);
goto err; goto err;
} }
} }
...@@ -894,7 +894,7 @@ static void br_multicast_querier_expired(struct net_bridge *br, ...@@ -894,7 +894,7 @@ static void br_multicast_querier_expired(struct net_bridge *br,
struct bridge_mcast_own_query *query) struct bridge_mcast_own_query *query)
{ {
spin_lock(&br->multicast_lock); spin_lock(&br->multicast_lock);
if (!netif_running(br->dev) || br->multicast_disabled) if (!netif_running(br->dev) || !br_opt_get(br, BROPT_MULTICAST_ENABLED))
goto out; goto out;
br_multicast_start_querier(br, query); br_multicast_start_querier(br, query);
...@@ -965,8 +965,9 @@ static void br_multicast_send_query(struct net_bridge *br, ...@@ -965,8 +965,9 @@ static void br_multicast_send_query(struct net_bridge *br,
struct br_ip br_group; struct br_ip br_group;
unsigned long time; unsigned long time;
if (!netif_running(br->dev) || br->multicast_disabled || if (!netif_running(br->dev) ||
!br->multicast_querier) !br_opt_get(br, BROPT_MULTICAST_ENABLED) ||
!br_opt_get(br, BROPT_MULTICAST_QUERIER))
return; return;
memset(&br_group.u, 0, sizeof(br_group.u)); memset(&br_group.u, 0, sizeof(br_group.u));
...@@ -1036,7 +1037,7 @@ static void br_mc_disabled_update(struct net_device *dev, bool value) ...@@ -1036,7 +1037,7 @@ static void br_mc_disabled_update(struct net_device *dev, bool value)
.orig_dev = dev, .orig_dev = dev,
.id = SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED, .id = SWITCHDEV_ATTR_ID_BRIDGE_MC_DISABLED,
.flags = SWITCHDEV_F_DEFER, .flags = SWITCHDEV_F_DEFER,
.u.mc_disabled = value, .u.mc_disabled = !value,
}; };
switchdev_port_attr_set(dev, &attr); switchdev_port_attr_set(dev, &attr);
...@@ -1054,7 +1055,8 @@ int br_multicast_add_port(struct net_bridge_port *port) ...@@ -1054,7 +1055,8 @@ int br_multicast_add_port(struct net_bridge_port *port)
timer_setup(&port->ip6_own_query.timer, timer_setup(&port->ip6_own_query.timer,
br_ip6_multicast_port_query_expired, 0); br_ip6_multicast_port_query_expired, 0);
#endif #endif
br_mc_disabled_update(port->dev, port->br->multicast_disabled); br_mc_disabled_update(port->dev,
br_opt_get(port->br, BROPT_MULTICAST_ENABLED));
port->mcast_stats = netdev_alloc_pcpu_stats(struct bridge_mcast_stats); port->mcast_stats = netdev_alloc_pcpu_stats(struct bridge_mcast_stats);
if (!port->mcast_stats) if (!port->mcast_stats)
...@@ -1091,7 +1093,7 @@ static void __br_multicast_enable_port(struct net_bridge_port *port) ...@@ -1091,7 +1093,7 @@ static void __br_multicast_enable_port(struct net_bridge_port *port)
{ {
struct net_bridge *br = port->br; struct net_bridge *br = port->br;
if (br->multicast_disabled || !netif_running(br->dev)) if (!br_opt_get(br, BROPT_MULTICAST_ENABLED) || !netif_running(br->dev))
return; return;
br_multicast_enable(&port->ip4_own_query); br_multicast_enable(&port->ip4_own_query);
...@@ -1634,7 +1636,7 @@ br_multicast_leave_group(struct net_bridge *br, ...@@ -1634,7 +1636,7 @@ br_multicast_leave_group(struct net_bridge *br,
if (timer_pending(&other_query->timer)) if (timer_pending(&other_query->timer))
goto out; goto out;
if (br->multicast_querier) { if (br_opt_get(br, BROPT_MULTICAST_QUERIER)) {
__br_multicast_send_query(br, port, &mp->addr); __br_multicast_send_query(br, port, &mp->addr);
time = jiffies + br->multicast_last_member_count * time = jiffies + br->multicast_last_member_count *
...@@ -1746,7 +1748,7 @@ static void br_multicast_err_count(const struct net_bridge *br, ...@@ -1746,7 +1748,7 @@ static void br_multicast_err_count(const struct net_bridge *br,
struct bridge_mcast_stats __percpu *stats; struct bridge_mcast_stats __percpu *stats;
struct bridge_mcast_stats *pstats; struct bridge_mcast_stats *pstats;
if (!br->multicast_stats_enabled) if (!br_opt_get(br, BROPT_MULTICAST_STATS_ENABLED))
return; return;
if (p) if (p)
...@@ -1904,7 +1906,7 @@ int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port, ...@@ -1904,7 +1906,7 @@ int br_multicast_rcv(struct net_bridge *br, struct net_bridge_port *port,
BR_INPUT_SKB_CB(skb)->igmp = 0; BR_INPUT_SKB_CB(skb)->igmp = 0;
BR_INPUT_SKB_CB(skb)->mrouters_only = 0; BR_INPUT_SKB_CB(skb)->mrouters_only = 0;
if (br->multicast_disabled) if (!br_opt_get(br, BROPT_MULTICAST_ENABLED))
return 0; return 0;
switch (skb->protocol) { switch (skb->protocol) {
...@@ -1956,8 +1958,6 @@ void br_multicast_init(struct net_bridge *br) ...@@ -1956,8 +1958,6 @@ void br_multicast_init(struct net_bridge *br)
br->hash_max = 512; br->hash_max = 512;
br->multicast_router = MDB_RTR_TYPE_TEMP_QUERY; br->multicast_router = MDB_RTR_TYPE_TEMP_QUERY;
br->multicast_querier = 0;
br->multicast_query_use_ifaddr = 0;
br->multicast_last_member_count = 2; br->multicast_last_member_count = 2;
br->multicast_startup_query_count = 2; br->multicast_startup_query_count = 2;
...@@ -1976,7 +1976,7 @@ void br_multicast_init(struct net_bridge *br) ...@@ -1976,7 +1976,7 @@ void br_multicast_init(struct net_bridge *br)
br->ip6_other_query.delay_time = 0; br->ip6_other_query.delay_time = 0;
br->ip6_querier.port = NULL; br->ip6_querier.port = NULL;
#endif #endif
br->has_ipv6_addr = 1; br_opt_toggle(br, BROPT_HAS_IPV6_ADDR, true);
spin_lock_init(&br->multicast_lock); spin_lock_init(&br->multicast_lock);
timer_setup(&br->multicast_router_timer, timer_setup(&br->multicast_router_timer,
...@@ -1998,7 +1998,7 @@ static void __br_multicast_open(struct net_bridge *br, ...@@ -1998,7 +1998,7 @@ static void __br_multicast_open(struct net_bridge *br,
{ {
query->startup_sent = 0; query->startup_sent = 0;
if (br->multicast_disabled) if (!br_opt_get(br, BROPT_MULTICAST_ENABLED))
return; return;
mod_timer(&query->timer, jiffies); mod_timer(&query->timer, jiffies);
...@@ -2173,12 +2173,12 @@ int br_multicast_toggle(struct net_bridge *br, unsigned long val) ...@@ -2173,12 +2173,12 @@ int br_multicast_toggle(struct net_bridge *br, unsigned long val)
int err = 0; int err = 0;
spin_lock_bh(&br->multicast_lock); spin_lock_bh(&br->multicast_lock);
if (br->multicast_disabled == !val) if (!!br_opt_get(br, BROPT_MULTICAST_ENABLED) == !!val)
goto unlock; goto unlock;
br_mc_disabled_update(br->dev, !val); br_mc_disabled_update(br->dev, val);
br->multicast_disabled = !val; br_opt_toggle(br, BROPT_MULTICAST_ENABLED, !!val);
if (br->multicast_disabled) if (!br_opt_get(br, BROPT_MULTICAST_ENABLED))
goto unlock; goto unlock;
if (!netif_running(br->dev)) if (!netif_running(br->dev))
...@@ -2189,7 +2189,7 @@ int br_multicast_toggle(struct net_bridge *br, unsigned long val) ...@@ -2189,7 +2189,7 @@ int br_multicast_toggle(struct net_bridge *br, unsigned long val)
if (mdb->old) { if (mdb->old) {
err = -EEXIST; err = -EEXIST;
rollback: rollback:
br->multicast_disabled = !!val; br_opt_toggle(br, BROPT_MULTICAST_ENABLED, false);
goto unlock; goto unlock;
} }
...@@ -2213,7 +2213,7 @@ bool br_multicast_enabled(const struct net_device *dev) ...@@ -2213,7 +2213,7 @@ bool br_multicast_enabled(const struct net_device *dev)
{ {
struct net_bridge *br = netdev_priv(dev); struct net_bridge *br = netdev_priv(dev);
return !br->multicast_disabled; return !!br_opt_get(br, BROPT_MULTICAST_ENABLED);
} }
EXPORT_SYMBOL_GPL(br_multicast_enabled); EXPORT_SYMBOL_GPL(br_multicast_enabled);
...@@ -2236,10 +2236,10 @@ int br_multicast_set_querier(struct net_bridge *br, unsigned long val) ...@@ -2236,10 +2236,10 @@ int br_multicast_set_querier(struct net_bridge *br, unsigned long val)
val = !!val; val = !!val;
spin_lock_bh(&br->multicast_lock); spin_lock_bh(&br->multicast_lock);
if (br->multicast_querier == val) if (br_opt_get(br, BROPT_MULTICAST_QUERIER) == val)
goto unlock; goto unlock;
br->multicast_querier = val; br_opt_toggle(br, BROPT_MULTICAST_QUERIER, !!val);
if (!val) if (!val)
goto unlock; goto unlock;
...@@ -2560,7 +2560,7 @@ void br_multicast_count(struct net_bridge *br, const struct net_bridge_port *p, ...@@ -2560,7 +2560,7 @@ void br_multicast_count(struct net_bridge *br, const struct net_bridge_port *p,
struct bridge_mcast_stats __percpu *stats; struct bridge_mcast_stats __percpu *stats;
/* if multicast_disabled is true then igmp type can't be set */ /* if multicast_disabled is true then igmp type can't be set */
if (!type || !br->multicast_stats_enabled) if (!type || !br_opt_get(br, BROPT_MULTICAST_STATS_ENABLED))
return; return;
if (p) if (p)
......
...@@ -487,14 +487,15 @@ static unsigned int br_nf_pre_routing(void *priv, ...@@ -487,14 +487,15 @@ static unsigned int br_nf_pre_routing(void *priv,
br = p->br; br = p->br;
if (IS_IPV6(skb) || IS_VLAN_IPV6(skb) || IS_PPPOE_IPV6(skb)) { if (IS_IPV6(skb) || IS_VLAN_IPV6(skb) || IS_PPPOE_IPV6(skb)) {
if (!brnf_call_ip6tables && !br->nf_call_ip6tables) if (!brnf_call_ip6tables &&
!br_opt_get(br, BROPT_NF_CALL_IP6TABLES))
return NF_ACCEPT; return NF_ACCEPT;
nf_bridge_pull_encap_header_rcsum(skb); nf_bridge_pull_encap_header_rcsum(skb);
return br_nf_pre_routing_ipv6(priv, skb, state); return br_nf_pre_routing_ipv6(priv, skb, state);
} }
if (!brnf_call_iptables && !br->nf_call_iptables) if (!brnf_call_iptables && !br_opt_get(br, BROPT_NF_CALL_IPTABLES))
return NF_ACCEPT; return NF_ACCEPT;
if (!IS_IP(skb) && !IS_VLAN_IP(skb) && !IS_PPPOE_IP(skb)) if (!IS_IP(skb) && !IS_VLAN_IP(skb) && !IS_PPPOE_IP(skb))
...@@ -636,7 +637,7 @@ static unsigned int br_nf_forward_arp(void *priv, ...@@ -636,7 +637,7 @@ static unsigned int br_nf_forward_arp(void *priv,
return NF_ACCEPT; return NF_ACCEPT;
br = p->br; br = p->br;
if (!brnf_call_arptables && !br->nf_call_arptables) if (!brnf_call_arptables && !br_opt_get(br, BROPT_NF_CALL_ARPTABLES))
return NF_ACCEPT; return NF_ACCEPT;
if (!IS_ARP(skb)) { if (!IS_ARP(skb)) {
......
...@@ -1139,7 +1139,7 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[], ...@@ -1139,7 +1139,7 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[],
spin_lock_bh(&br->lock); spin_lock_bh(&br->lock);
memcpy(br->group_addr, new_addr, sizeof(br->group_addr)); memcpy(br->group_addr, new_addr, sizeof(br->group_addr));
spin_unlock_bh(&br->lock); spin_unlock_bh(&br->lock);
br->group_addr_set = true; br_opt_toggle(br, BROPT_GROUP_ADDR_SET, true);
br_recalculate_fwd_mask(br); br_recalculate_fwd_mask(br);
} }
...@@ -1167,7 +1167,7 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[], ...@@ -1167,7 +1167,7 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[],
u8 val; u8 val;
val = nla_get_u8(data[IFLA_BR_MCAST_QUERY_USE_IFADDR]); val = nla_get_u8(data[IFLA_BR_MCAST_QUERY_USE_IFADDR]);
br->multicast_query_use_ifaddr = !!val; br_opt_toggle(br, BROPT_MULTICAST_QUERY_USE_IFADDR, !!val);
} }
if (data[IFLA_BR_MCAST_QUERIER]) { if (data[IFLA_BR_MCAST_QUERIER]) {
...@@ -1244,7 +1244,7 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[], ...@@ -1244,7 +1244,7 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[],
__u8 mcast_stats; __u8 mcast_stats;
mcast_stats = nla_get_u8(data[IFLA_BR_MCAST_STATS_ENABLED]); mcast_stats = nla_get_u8(data[IFLA_BR_MCAST_STATS_ENABLED]);
br->multicast_stats_enabled = !!mcast_stats; br_opt_toggle(br, BROPT_MULTICAST_STATS_ENABLED, !!mcast_stats);
} }
if (data[IFLA_BR_MCAST_IGMP_VERSION]) { if (data[IFLA_BR_MCAST_IGMP_VERSION]) {
...@@ -1271,19 +1271,19 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[], ...@@ -1271,19 +1271,19 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[],
if (data[IFLA_BR_NF_CALL_IPTABLES]) { if (data[IFLA_BR_NF_CALL_IPTABLES]) {
u8 val = nla_get_u8(data[IFLA_BR_NF_CALL_IPTABLES]); u8 val = nla_get_u8(data[IFLA_BR_NF_CALL_IPTABLES]);
br->nf_call_iptables = val ? true : false; br_opt_toggle(br, BROPT_NF_CALL_IPTABLES, !!val);
} }
if (data[IFLA_BR_NF_CALL_IP6TABLES]) { if (data[IFLA_BR_NF_CALL_IP6TABLES]) {
u8 val = nla_get_u8(data[IFLA_BR_NF_CALL_IP6TABLES]); u8 val = nla_get_u8(data[IFLA_BR_NF_CALL_IP6TABLES]);
br->nf_call_ip6tables = val ? true : false; br_opt_toggle(br, BROPT_NF_CALL_IP6TABLES, !!val);
} }
if (data[IFLA_BR_NF_CALL_ARPTABLES]) { if (data[IFLA_BR_NF_CALL_ARPTABLES]) {
u8 val = nla_get_u8(data[IFLA_BR_NF_CALL_ARPTABLES]); u8 val = nla_get_u8(data[IFLA_BR_NF_CALL_ARPTABLES]);
br->nf_call_arptables = val ? true : false; br_opt_toggle(br, BROPT_NF_CALL_ARPTABLES, !!val);
} }
#endif #endif
...@@ -1416,17 +1416,20 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev) ...@@ -1416,17 +1416,20 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
#ifdef CONFIG_BRIDGE_VLAN_FILTERING #ifdef CONFIG_BRIDGE_VLAN_FILTERING
if (nla_put_be16(skb, IFLA_BR_VLAN_PROTOCOL, br->vlan_proto) || if (nla_put_be16(skb, IFLA_BR_VLAN_PROTOCOL, br->vlan_proto) ||
nla_put_u16(skb, IFLA_BR_VLAN_DEFAULT_PVID, br->default_pvid) || nla_put_u16(skb, IFLA_BR_VLAN_DEFAULT_PVID, br->default_pvid) ||
nla_put_u8(skb, IFLA_BR_VLAN_STATS_ENABLED, br->vlan_stats_enabled)) nla_put_u8(skb, IFLA_BR_VLAN_STATS_ENABLED,
br_opt_get(br, BROPT_VLAN_STATS_ENABLED)))
return -EMSGSIZE; return -EMSGSIZE;
#endif #endif
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER, br->multicast_router) || if (nla_put_u8(skb, IFLA_BR_MCAST_ROUTER, br->multicast_router) ||
nla_put_u8(skb, IFLA_BR_MCAST_SNOOPING, !br->multicast_disabled) || nla_put_u8(skb, IFLA_BR_MCAST_SNOOPING,
br_opt_get(br, BROPT_MULTICAST_ENABLED)) ||
nla_put_u8(skb, IFLA_BR_MCAST_QUERY_USE_IFADDR, nla_put_u8(skb, IFLA_BR_MCAST_QUERY_USE_IFADDR,
br->multicast_query_use_ifaddr) || br_opt_get(br, BROPT_MULTICAST_QUERY_USE_IFADDR)) ||
nla_put_u8(skb, IFLA_BR_MCAST_QUERIER, br->multicast_querier) || nla_put_u8(skb, IFLA_BR_MCAST_QUERIER,
br_opt_get(br, BROPT_MULTICAST_QUERIER)) ||
nla_put_u8(skb, IFLA_BR_MCAST_STATS_ENABLED, nla_put_u8(skb, IFLA_BR_MCAST_STATS_ENABLED,
br->multicast_stats_enabled) || br_opt_get(br, BROPT_MULTICAST_STATS_ENABLED)) ||
nla_put_u32(skb, IFLA_BR_MCAST_HASH_ELASTICITY, nla_put_u32(skb, IFLA_BR_MCAST_HASH_ELASTICITY,
br->hash_elasticity) || br->hash_elasticity) ||
nla_put_u32(skb, IFLA_BR_MCAST_HASH_MAX, br->hash_max) || nla_put_u32(skb, IFLA_BR_MCAST_HASH_MAX, br->hash_max) ||
...@@ -1469,11 +1472,11 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev) ...@@ -1469,11 +1472,11 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
#endif #endif
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
if (nla_put_u8(skb, IFLA_BR_NF_CALL_IPTABLES, if (nla_put_u8(skb, IFLA_BR_NF_CALL_IPTABLES,
br->nf_call_iptables ? 1 : 0) || br_opt_get(br, BROPT_NF_CALL_IPTABLES) ? 1 : 0) ||
nla_put_u8(skb, IFLA_BR_NF_CALL_IP6TABLES, nla_put_u8(skb, IFLA_BR_NF_CALL_IP6TABLES,
br->nf_call_ip6tables ? 1 : 0) || br_opt_get(br, BROPT_NF_CALL_IP6TABLES) ? 1 : 0) ||
nla_put_u8(skb, IFLA_BR_NF_CALL_ARPTABLES, nla_put_u8(skb, IFLA_BR_NF_CALL_ARPTABLES,
br->nf_call_arptables ? 1 : 0)) br_opt_get(br, BROPT_NF_CALL_ARPTABLES) ? 1 : 0))
return -EMSGSIZE; return -EMSGSIZE;
#endif #endif
......
...@@ -54,14 +54,12 @@ typedef struct bridge_id bridge_id; ...@@ -54,14 +54,12 @@ typedef struct bridge_id bridge_id;
typedef struct mac_addr mac_addr; typedef struct mac_addr mac_addr;
typedef __u16 port_id; typedef __u16 port_id;
struct bridge_id struct bridge_id {
{
unsigned char prio[2]; unsigned char prio[2];
unsigned char addr[ETH_ALEN]; unsigned char addr[ETH_ALEN];
}; };
struct mac_addr struct mac_addr {
{
unsigned char addr[ETH_ALEN]; unsigned char addr[ETH_ALEN];
}; };
...@@ -207,8 +205,7 @@ struct net_bridge_port_group { ...@@ -207,8 +205,7 @@ struct net_bridge_port_group {
unsigned char eth_addr[ETH_ALEN]; unsigned char eth_addr[ETH_ALEN];
}; };
struct net_bridge_mdb_entry struct net_bridge_mdb_entry {
{
struct hlist_node hlist[2]; struct hlist_node hlist[2];
struct net_bridge *br; struct net_bridge *br;
struct net_bridge_port_group __rcu *ports; struct net_bridge_port_group __rcu *ports;
...@@ -218,8 +215,7 @@ struct net_bridge_mdb_entry ...@@ -218,8 +215,7 @@ struct net_bridge_mdb_entry
bool host_joined; bool host_joined;
}; };
struct net_bridge_mdb_htable struct net_bridge_mdb_htable {
{
struct hlist_head *mhash; struct hlist_head *mhash;
struct rcu_head rcu; struct rcu_head rcu;
struct net_bridge_mdb_htable *old; struct net_bridge_mdb_htable *old;
...@@ -310,16 +306,31 @@ static inline struct net_bridge_port *br_port_get_rtnl_rcu(const struct net_devi ...@@ -310,16 +306,31 @@ static inline struct net_bridge_port *br_port_get_rtnl_rcu(const struct net_devi
rcu_dereference_rtnl(dev->rx_handler_data) : NULL; rcu_dereference_rtnl(dev->rx_handler_data) : NULL;
} }
enum net_bridge_opts {
BROPT_VLAN_ENABLED,
BROPT_VLAN_STATS_ENABLED,
BROPT_NF_CALL_IPTABLES,
BROPT_NF_CALL_IP6TABLES,
BROPT_NF_CALL_ARPTABLES,
BROPT_GROUP_ADDR_SET,
BROPT_MULTICAST_ENABLED,
BROPT_MULTICAST_QUERIER,
BROPT_MULTICAST_QUERY_USE_IFADDR,
BROPT_MULTICAST_STATS_ENABLED,
BROPT_HAS_IPV6_ADDR,
BROPT_NEIGH_SUPPRESS_ENABLED,
BROPT_MTU_SET_BY_USER,
};
struct net_bridge { struct net_bridge {
spinlock_t lock; spinlock_t lock;
spinlock_t hash_lock; spinlock_t hash_lock;
struct list_head port_list; struct list_head port_list;
struct net_device *dev; struct net_device *dev;
struct pcpu_sw_netstats __percpu *stats; struct pcpu_sw_netstats __percpu *stats;
unsigned long options;
/* These fields are accessed on each packet */ /* These fields are accessed on each packet */
#ifdef CONFIG_BRIDGE_VLAN_FILTERING #ifdef CONFIG_BRIDGE_VLAN_FILTERING
u8 vlan_enabled;
u8 vlan_stats_enabled;
__be16 vlan_proto; __be16 vlan_proto;
u16 default_pvid; u16 default_pvid;
struct net_bridge_vlan_group __rcu *vlgrp; struct net_bridge_vlan_group __rcu *vlgrp;
...@@ -331,9 +342,6 @@ struct net_bridge { ...@@ -331,9 +342,6 @@ struct net_bridge {
struct rtable fake_rtable; struct rtable fake_rtable;
struct rt6_info fake_rt6_info; struct rt6_info fake_rt6_info;
}; };
bool nf_call_iptables;
bool nf_call_ip6tables;
bool nf_call_arptables;
#endif #endif
u16 group_fwd_mask; u16 group_fwd_mask;
u16 group_fwd_mask_required; u16 group_fwd_mask_required;
...@@ -341,7 +349,6 @@ struct net_bridge { ...@@ -341,7 +349,6 @@ struct net_bridge {
/* STP */ /* STP */
bridge_id designated_root; bridge_id designated_root;
bridge_id bridge_id; bridge_id bridge_id;
u32 root_path_cost;
unsigned char topology_change; unsigned char topology_change;
unsigned char topology_change_detected; unsigned char topology_change_detected;
u16 root_port; u16 root_port;
...@@ -353,9 +360,9 @@ struct net_bridge { ...@@ -353,9 +360,9 @@ struct net_bridge {
unsigned long bridge_hello_time; unsigned long bridge_hello_time;
unsigned long bridge_forward_delay; unsigned long bridge_forward_delay;
unsigned long bridge_ageing_time; unsigned long bridge_ageing_time;
u32 root_path_cost;
u8 group_addr[ETH_ALEN]; u8 group_addr[ETH_ALEN];
bool group_addr_set;
enum { enum {
BR_NO_STP, /* no spanning tree */ BR_NO_STP, /* no spanning tree */
...@@ -364,13 +371,6 @@ struct net_bridge { ...@@ -364,13 +371,6 @@ struct net_bridge {
} stp_enabled; } stp_enabled;
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING #ifdef CONFIG_BRIDGE_IGMP_SNOOPING
unsigned char multicast_router;
u8 multicast_disabled:1;
u8 multicast_querier:1;
u8 multicast_query_use_ifaddr:1;
u8 has_ipv6_addr:1;
u8 multicast_stats_enabled:1;
u32 hash_elasticity; u32 hash_elasticity;
u32 hash_max; u32 hash_max;
...@@ -379,7 +379,11 @@ struct net_bridge { ...@@ -379,7 +379,11 @@ struct net_bridge {
u32 multicast_startup_query_count; u32 multicast_startup_query_count;
u8 multicast_igmp_version; u8 multicast_igmp_version;
u8 multicast_router;
#if IS_ENABLED(CONFIG_IPV6)
u8 multicast_mld_version;
#endif
spinlock_t multicast_lock;
unsigned long multicast_last_member_interval; unsigned long multicast_last_member_interval;
unsigned long multicast_membership_interval; unsigned long multicast_membership_interval;
unsigned long multicast_querier_interval; unsigned long multicast_querier_interval;
...@@ -387,7 +391,6 @@ struct net_bridge { ...@@ -387,7 +391,6 @@ struct net_bridge {
unsigned long multicast_query_response_interval; unsigned long multicast_query_response_interval;
unsigned long multicast_startup_query_interval; unsigned long multicast_startup_query_interval;
spinlock_t multicast_lock;
struct net_bridge_mdb_htable __rcu *mdb; struct net_bridge_mdb_htable __rcu *mdb;
struct hlist_head router_list; struct hlist_head router_list;
...@@ -400,7 +403,6 @@ struct net_bridge { ...@@ -400,7 +403,6 @@ struct net_bridge {
struct bridge_mcast_other_query ip6_other_query; struct bridge_mcast_other_query ip6_other_query;
struct bridge_mcast_own_query ip6_own_query; struct bridge_mcast_own_query ip6_own_query;
struct bridge_mcast_querier ip6_querier; struct bridge_mcast_querier ip6_querier;
u8 multicast_mld_version;
#endif /* IS_ENABLED(CONFIG_IPV6) */ #endif /* IS_ENABLED(CONFIG_IPV6) */
#endif #endif
...@@ -414,8 +416,6 @@ struct net_bridge { ...@@ -414,8 +416,6 @@ struct net_bridge {
#ifdef CONFIG_NET_SWITCHDEV #ifdef CONFIG_NET_SWITCHDEV
int offload_fwd_mark; int offload_fwd_mark;
#endif #endif
bool neigh_suppress_enabled;
bool mtu_set_by_user;
struct hlist_head fdb_list; struct hlist_head fdb_list;
}; };
...@@ -493,6 +493,14 @@ static inline bool br_vlan_should_use(const struct net_bridge_vlan *v) ...@@ -493,6 +493,14 @@ static inline bool br_vlan_should_use(const struct net_bridge_vlan *v)
return true; return true;
} }
static inline int br_opt_get(const struct net_bridge *br,
enum net_bridge_opts opt)
{
return test_bit(opt, &br->options);
}
void br_opt_toggle(struct net_bridge *br, enum net_bridge_opts opt, bool on);
/* br_device.c */ /* br_device.c */
void br_dev_setup(struct net_device *dev); void br_dev_setup(struct net_device *dev);
void br_dev_delete(struct net_device *dev, struct list_head *list); void br_dev_delete(struct net_device *dev, struct list_head *list);
...@@ -699,8 +707,8 @@ __br_multicast_querier_exists(struct net_bridge *br, ...@@ -699,8 +707,8 @@ __br_multicast_querier_exists(struct net_bridge *br,
{ {
bool own_querier_enabled; bool own_querier_enabled;
if (br->multicast_querier) { if (br_opt_get(br, BROPT_MULTICAST_QUERIER)) {
if (is_ipv6 && !br->has_ipv6_addr) if (is_ipv6 && !br_opt_get(br, BROPT_HAS_IPV6_ADDR))
own_querier_enabled = false; own_querier_enabled = false;
else else
own_querier_enabled = true; own_querier_enabled = true;
......
...@@ -303,7 +303,7 @@ static ssize_t group_addr_store(struct device *d, ...@@ -303,7 +303,7 @@ static ssize_t group_addr_store(struct device *d,
ether_addr_copy(br->group_addr, new_addr); ether_addr_copy(br->group_addr, new_addr);
spin_unlock_bh(&br->lock); spin_unlock_bh(&br->lock);
br->group_addr_set = true; br_opt_toggle(br, BROPT_GROUP_ADDR_SET, true);
br_recalculate_fwd_mask(br); br_recalculate_fwd_mask(br);
netdev_state_change(br->dev); netdev_state_change(br->dev);
...@@ -349,7 +349,7 @@ static ssize_t multicast_snooping_show(struct device *d, ...@@ -349,7 +349,7 @@ static ssize_t multicast_snooping_show(struct device *d,
char *buf) char *buf)
{ {
struct net_bridge *br = to_bridge(d); struct net_bridge *br = to_bridge(d);
return sprintf(buf, "%d\n", !br->multicast_disabled); return sprintf(buf, "%d\n", br_opt_get(br, BROPT_MULTICAST_ENABLED));
} }
static ssize_t multicast_snooping_store(struct device *d, static ssize_t multicast_snooping_store(struct device *d,
...@@ -365,12 +365,13 @@ static ssize_t multicast_query_use_ifaddr_show(struct device *d, ...@@ -365,12 +365,13 @@ static ssize_t multicast_query_use_ifaddr_show(struct device *d,
char *buf) char *buf)
{ {
struct net_bridge *br = to_bridge(d); struct net_bridge *br = to_bridge(d);
return sprintf(buf, "%d\n", br->multicast_query_use_ifaddr); return sprintf(buf, "%d\n",
br_opt_get(br, BROPT_MULTICAST_QUERY_USE_IFADDR));
} }
static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val) static int set_query_use_ifaddr(struct net_bridge *br, unsigned long val)
{ {
br->multicast_query_use_ifaddr = !!val; br_opt_toggle(br, BROPT_MULTICAST_QUERY_USE_IFADDR, !!val);
return 0; return 0;
} }
...@@ -388,7 +389,7 @@ static ssize_t multicast_querier_show(struct device *d, ...@@ -388,7 +389,7 @@ static ssize_t multicast_querier_show(struct device *d,
char *buf) char *buf)
{ {
struct net_bridge *br = to_bridge(d); struct net_bridge *br = to_bridge(d);
return sprintf(buf, "%d\n", br->multicast_querier); return sprintf(buf, "%d\n", br_opt_get(br, BROPT_MULTICAST_QUERIER));
} }
static ssize_t multicast_querier_store(struct device *d, static ssize_t multicast_querier_store(struct device *d,
...@@ -636,12 +637,13 @@ static ssize_t multicast_stats_enabled_show(struct device *d, ...@@ -636,12 +637,13 @@ static ssize_t multicast_stats_enabled_show(struct device *d,
{ {
struct net_bridge *br = to_bridge(d); struct net_bridge *br = to_bridge(d);
return sprintf(buf, "%u\n", br->multicast_stats_enabled); return sprintf(buf, "%d\n",
br_opt_get(br, BROPT_MULTICAST_STATS_ENABLED));
} }
static int set_stats_enabled(struct net_bridge *br, unsigned long val) static int set_stats_enabled(struct net_bridge *br, unsigned long val)
{ {
br->multicast_stats_enabled = !!val; br_opt_toggle(br, BROPT_MULTICAST_STATS_ENABLED, !!val);
return 0; return 0;
} }
...@@ -678,12 +680,12 @@ static ssize_t nf_call_iptables_show( ...@@ -678,12 +680,12 @@ static ssize_t nf_call_iptables_show(
struct device *d, struct device_attribute *attr, char *buf) struct device *d, struct device_attribute *attr, char *buf)
{ {
struct net_bridge *br = to_bridge(d); struct net_bridge *br = to_bridge(d);
return sprintf(buf, "%u\n", br->nf_call_iptables); return sprintf(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_IPTABLES));
} }
static int set_nf_call_iptables(struct net_bridge *br, unsigned long val) static int set_nf_call_iptables(struct net_bridge *br, unsigned long val)
{ {
br->nf_call_iptables = val ? true : false; br_opt_toggle(br, BROPT_NF_CALL_IPTABLES, !!val);
return 0; return 0;
} }
...@@ -699,12 +701,12 @@ static ssize_t nf_call_ip6tables_show( ...@@ -699,12 +701,12 @@ static ssize_t nf_call_ip6tables_show(
struct device *d, struct device_attribute *attr, char *buf) struct device *d, struct device_attribute *attr, char *buf)
{ {
struct net_bridge *br = to_bridge(d); struct net_bridge *br = to_bridge(d);
return sprintf(buf, "%u\n", br->nf_call_ip6tables); return sprintf(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_IP6TABLES));
} }
static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val) static int set_nf_call_ip6tables(struct net_bridge *br, unsigned long val)
{ {
br->nf_call_ip6tables = val ? true : false; br_opt_toggle(br, BROPT_NF_CALL_IP6TABLES, !!val);
return 0; return 0;
} }
...@@ -720,12 +722,12 @@ static ssize_t nf_call_arptables_show( ...@@ -720,12 +722,12 @@ static ssize_t nf_call_arptables_show(
struct device *d, struct device_attribute *attr, char *buf) struct device *d, struct device_attribute *attr, char *buf)
{ {
struct net_bridge *br = to_bridge(d); struct net_bridge *br = to_bridge(d);
return sprintf(buf, "%u\n", br->nf_call_arptables); return sprintf(buf, "%u\n", br_opt_get(br, BROPT_NF_CALL_ARPTABLES));
} }
static int set_nf_call_arptables(struct net_bridge *br, unsigned long val) static int set_nf_call_arptables(struct net_bridge *br, unsigned long val)
{ {
br->nf_call_arptables = val ? true : false; br_opt_toggle(br, BROPT_NF_CALL_ARPTABLES, !!val);
return 0; return 0;
} }
...@@ -743,7 +745,7 @@ static ssize_t vlan_filtering_show(struct device *d, ...@@ -743,7 +745,7 @@ static ssize_t vlan_filtering_show(struct device *d,
char *buf) char *buf)
{ {
struct net_bridge *br = to_bridge(d); struct net_bridge *br = to_bridge(d);
return sprintf(buf, "%d\n", br->vlan_enabled); return sprintf(buf, "%d\n", br_opt_get(br, BROPT_VLAN_ENABLED));
} }
static ssize_t vlan_filtering_store(struct device *d, static ssize_t vlan_filtering_store(struct device *d,
...@@ -791,7 +793,7 @@ static ssize_t vlan_stats_enabled_show(struct device *d, ...@@ -791,7 +793,7 @@ static ssize_t vlan_stats_enabled_show(struct device *d,
char *buf) char *buf)
{ {
struct net_bridge *br = to_bridge(d); struct net_bridge *br = to_bridge(d);
return sprintf(buf, "%u\n", br->vlan_stats_enabled); return sprintf(buf, "%u\n", br_opt_get(br, BROPT_VLAN_STATS_ENABLED));
} }
static ssize_t vlan_stats_enabled_store(struct device *d, static ssize_t vlan_stats_enabled_store(struct device *d,
......
...@@ -386,7 +386,7 @@ struct sk_buff *br_handle_vlan(struct net_bridge *br, ...@@ -386,7 +386,7 @@ struct sk_buff *br_handle_vlan(struct net_bridge *br,
return NULL; return NULL;
} }
} }
if (br->vlan_stats_enabled) { if (br_opt_get(br, BROPT_VLAN_STATS_ENABLED)) {
stats = this_cpu_ptr(v->stats); stats = this_cpu_ptr(v->stats);
u64_stats_update_begin(&stats->syncp); u64_stats_update_begin(&stats->syncp);
stats->tx_bytes += skb->len; stats->tx_bytes += skb->len;
...@@ -475,14 +475,14 @@ static bool __allowed_ingress(const struct net_bridge *br, ...@@ -475,14 +475,14 @@ static bool __allowed_ingress(const struct net_bridge *br,
skb->vlan_tci |= pvid; skb->vlan_tci |= pvid;
/* if stats are disabled we can avoid the lookup */ /* if stats are disabled we can avoid the lookup */
if (!br->vlan_stats_enabled) if (!br_opt_get(br, BROPT_VLAN_STATS_ENABLED))
return true; return true;
} }
v = br_vlan_find(vg, *vid); v = br_vlan_find(vg, *vid);
if (!v || !br_vlan_should_use(v)) if (!v || !br_vlan_should_use(v))
goto drop; goto drop;
if (br->vlan_stats_enabled) { if (br_opt_get(br, BROPT_VLAN_STATS_ENABLED)) {
stats = this_cpu_ptr(v->stats); stats = this_cpu_ptr(v->stats);
u64_stats_update_begin(&stats->syncp); u64_stats_update_begin(&stats->syncp);
stats->rx_bytes += skb->len; stats->rx_bytes += skb->len;
...@@ -504,7 +504,7 @@ bool br_allowed_ingress(const struct net_bridge *br, ...@@ -504,7 +504,7 @@ bool br_allowed_ingress(const struct net_bridge *br,
/* If VLAN filtering is disabled on the bridge, all packets are /* If VLAN filtering is disabled on the bridge, all packets are
* permitted. * permitted.
*/ */
if (!br->vlan_enabled) { if (!br_opt_get(br, BROPT_VLAN_ENABLED)) {
BR_INPUT_SKB_CB(skb)->vlan_filtered = false; BR_INPUT_SKB_CB(skb)->vlan_filtered = false;
return true; return true;
} }
...@@ -538,7 +538,7 @@ bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid) ...@@ -538,7 +538,7 @@ bool br_should_learn(struct net_bridge_port *p, struct sk_buff *skb, u16 *vid)
struct net_bridge *br = p->br; struct net_bridge *br = p->br;
/* If filtering was disabled at input, let it pass. */ /* If filtering was disabled at input, let it pass. */
if (!br->vlan_enabled) if (!br_opt_get(br, BROPT_VLAN_ENABLED))
return true; return true;
vg = nbp_vlan_group_rcu(p); vg = nbp_vlan_group_rcu(p);
...@@ -695,11 +695,12 @@ struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid) ...@@ -695,11 +695,12 @@ struct net_bridge_vlan *br_vlan_find(struct net_bridge_vlan_group *vg, u16 vid)
/* Must be protected by RTNL. */ /* Must be protected by RTNL. */
static void recalculate_group_addr(struct net_bridge *br) static void recalculate_group_addr(struct net_bridge *br)
{ {
if (br->group_addr_set) if (br_opt_get(br, BROPT_GROUP_ADDR_SET))
return; return;
spin_lock_bh(&br->lock); spin_lock_bh(&br->lock);
if (!br->vlan_enabled || br->vlan_proto == htons(ETH_P_8021Q)) { if (!br_opt_get(br, BROPT_VLAN_ENABLED) ||
br->vlan_proto == htons(ETH_P_8021Q)) {
/* Bridge Group Address */ /* Bridge Group Address */
br->group_addr[5] = 0x00; br->group_addr[5] = 0x00;
} else { /* vlan_enabled && ETH_P_8021AD */ } else { /* vlan_enabled && ETH_P_8021AD */
...@@ -712,7 +713,8 @@ static void recalculate_group_addr(struct net_bridge *br) ...@@ -712,7 +713,8 @@ static void recalculate_group_addr(struct net_bridge *br)
/* Must be protected by RTNL. */ /* Must be protected by RTNL. */
void br_recalculate_fwd_mask(struct net_bridge *br) void br_recalculate_fwd_mask(struct net_bridge *br)
{ {
if (!br->vlan_enabled || br->vlan_proto == htons(ETH_P_8021Q)) if (!br_opt_get(br, BROPT_VLAN_ENABLED) ||
br->vlan_proto == htons(ETH_P_8021Q))
br->group_fwd_mask_required = BR_GROUPFWD_DEFAULT; br->group_fwd_mask_required = BR_GROUPFWD_DEFAULT;
else /* vlan_enabled && ETH_P_8021AD */ else /* vlan_enabled && ETH_P_8021AD */
br->group_fwd_mask_required = BR_GROUPFWD_8021AD & br->group_fwd_mask_required = BR_GROUPFWD_8021AD &
...@@ -729,14 +731,14 @@ int __br_vlan_filter_toggle(struct net_bridge *br, unsigned long val) ...@@ -729,14 +731,14 @@ int __br_vlan_filter_toggle(struct net_bridge *br, unsigned long val)
}; };
int err; int err;
if (br->vlan_enabled == val) if (br_opt_get(br, BROPT_VLAN_ENABLED) == !!val)
return 0; return 0;
err = switchdev_port_attr_set(br->dev, &attr); err = switchdev_port_attr_set(br->dev, &attr);
if (err && err != -EOPNOTSUPP) if (err && err != -EOPNOTSUPP)
return err; return err;
br->vlan_enabled = val; br_opt_toggle(br, BROPT_VLAN_ENABLED, !!val);
br_manage_promisc(br); br_manage_promisc(br);
recalculate_group_addr(br); recalculate_group_addr(br);
br_recalculate_fwd_mask(br); br_recalculate_fwd_mask(br);
...@@ -753,7 +755,7 @@ bool br_vlan_enabled(const struct net_device *dev) ...@@ -753,7 +755,7 @@ bool br_vlan_enabled(const struct net_device *dev)
{ {
struct net_bridge *br = netdev_priv(dev); struct net_bridge *br = netdev_priv(dev);
return !!br->vlan_enabled; return br_opt_get(br, BROPT_VLAN_ENABLED);
} }
EXPORT_SYMBOL_GPL(br_vlan_enabled); EXPORT_SYMBOL_GPL(br_vlan_enabled);
...@@ -819,7 +821,7 @@ int br_vlan_set_stats(struct net_bridge *br, unsigned long val) ...@@ -819,7 +821,7 @@ int br_vlan_set_stats(struct net_bridge *br, unsigned long val)
switch (val) { switch (val) {
case 0: case 0:
case 1: case 1:
br->vlan_stats_enabled = val; br_opt_toggle(br, BROPT_VLAN_STATS_ENABLED, !!val);
break; break;
default: default:
return -EINVAL; return -EINVAL;
...@@ -964,7 +966,7 @@ int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val) ...@@ -964,7 +966,7 @@ int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val)
goto out; goto out;
/* Only allow default pvid change when filtering is disabled */ /* Only allow default pvid change when filtering is disabled */
if (br->vlan_enabled) { if (br_opt_get(br, BROPT_VLAN_ENABLED)) {
pr_info_once("Please disable vlan filtering to change default_pvid\n"); pr_info_once("Please disable vlan filtering to change default_pvid\n");
err = -EPERM; err = -EPERM;
goto out; goto out;
...@@ -1018,7 +1020,7 @@ int nbp_vlan_init(struct net_bridge_port *p) ...@@ -1018,7 +1020,7 @@ int nbp_vlan_init(struct net_bridge_port *p)
.orig_dev = p->br->dev, .orig_dev = p->br->dev,
.id = SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING, .id = SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING,
.flags = SWITCHDEV_F_SKIP_EOPNOTSUPP, .flags = SWITCHDEV_F_SKIP_EOPNOTSUPP,
.u.vlan_filtering = p->br->vlan_enabled, .u.vlan_filtering = br_opt_get(p->br, BROPT_VLAN_ENABLED),
}; };
struct net_bridge_vlan_group *vg; struct net_bridge_vlan_group *vg;
int ret = -ENOMEM; int ret = -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment