mirror of
https://github.com/torvalds/linux.git
synced 2024-12-12 06:02:38 +00:00
macvlan: convert port passthru to flags.
Convert the port passthru boolean into flags with accesor functions. Signed-off-by: Vladislav Yasevich <vyasevic@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
e696cda7bd
commit
43c2d578a0
@ -39,13 +39,15 @@
|
|||||||
#define MACVLAN_HASH_SIZE (1<<MACVLAN_HASH_BITS)
|
#define MACVLAN_HASH_SIZE (1<<MACVLAN_HASH_BITS)
|
||||||
#define MACVLAN_BC_QUEUE_LEN 1000
|
#define MACVLAN_BC_QUEUE_LEN 1000
|
||||||
|
|
||||||
|
#define MACVLAN_F_PASSTHRU 1
|
||||||
|
|
||||||
struct macvlan_port {
|
struct macvlan_port {
|
||||||
struct net_device *dev;
|
struct net_device *dev;
|
||||||
struct hlist_head vlan_hash[MACVLAN_HASH_SIZE];
|
struct hlist_head vlan_hash[MACVLAN_HASH_SIZE];
|
||||||
struct list_head vlans;
|
struct list_head vlans;
|
||||||
struct sk_buff_head bc_queue;
|
struct sk_buff_head bc_queue;
|
||||||
struct work_struct bc_work;
|
struct work_struct bc_work;
|
||||||
bool passthru;
|
u32 flags;
|
||||||
int count;
|
int count;
|
||||||
struct hlist_head vlan_source_hash[MACVLAN_HASH_SIZE];
|
struct hlist_head vlan_source_hash[MACVLAN_HASH_SIZE];
|
||||||
DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
|
DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ);
|
||||||
@ -66,6 +68,16 @@ struct macvlan_skb_cb {
|
|||||||
|
|
||||||
static void macvlan_port_destroy(struct net_device *dev);
|
static void macvlan_port_destroy(struct net_device *dev);
|
||||||
|
|
||||||
|
static inline bool macvlan_passthru(const struct macvlan_port *port)
|
||||||
|
{
|
||||||
|
return port->flags & MACVLAN_F_PASSTHRU;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void macvlan_set_passthru(struct macvlan_port *port)
|
||||||
|
{
|
||||||
|
port->flags |= MACVLAN_F_PASSTHRU;
|
||||||
|
}
|
||||||
|
|
||||||
/* Hash Ethernet address */
|
/* Hash Ethernet address */
|
||||||
static u32 macvlan_eth_hash(const unsigned char *addr)
|
static u32 macvlan_eth_hash(const unsigned char *addr)
|
||||||
{
|
{
|
||||||
@ -185,7 +197,7 @@ static bool macvlan_addr_busy(const struct macvlan_port *port,
|
|||||||
* currently in use by the underlying device or
|
* currently in use by the underlying device or
|
||||||
* another macvlan.
|
* another macvlan.
|
||||||
*/
|
*/
|
||||||
if (!port->passthru &&
|
if (!macvlan_passthru(port) &&
|
||||||
ether_addr_equal_64bits(port->dev->dev_addr, addr))
|
ether_addr_equal_64bits(port->dev->dev_addr, addr))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -446,7 +458,7 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb)
|
|||||||
}
|
}
|
||||||
|
|
||||||
macvlan_forward_source(skb, port, eth->h_source);
|
macvlan_forward_source(skb, port, eth->h_source);
|
||||||
if (port->passthru)
|
if (macvlan_passthru(port))
|
||||||
vlan = list_first_or_null_rcu(&port->vlans,
|
vlan = list_first_or_null_rcu(&port->vlans,
|
||||||
struct macvlan_dev, list);
|
struct macvlan_dev, list);
|
||||||
else
|
else
|
||||||
@ -575,7 +587,7 @@ static int macvlan_open(struct net_device *dev)
|
|||||||
struct net_device *lowerdev = vlan->lowerdev;
|
struct net_device *lowerdev = vlan->lowerdev;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (vlan->port->passthru) {
|
if (macvlan_passthru(vlan->port)) {
|
||||||
if (!(vlan->flags & MACVLAN_FLAG_NOPROMISC)) {
|
if (!(vlan->flags & MACVLAN_FLAG_NOPROMISC)) {
|
||||||
err = dev_set_promiscuity(lowerdev, 1);
|
err = dev_set_promiscuity(lowerdev, 1);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
@ -650,7 +662,7 @@ static int macvlan_stop(struct net_device *dev)
|
|||||||
dev_uc_unsync(lowerdev, dev);
|
dev_uc_unsync(lowerdev, dev);
|
||||||
dev_mc_unsync(lowerdev, dev);
|
dev_mc_unsync(lowerdev, dev);
|
||||||
|
|
||||||
if (vlan->port->passthru) {
|
if (macvlan_passthru(vlan->port)) {
|
||||||
if (!(vlan->flags & MACVLAN_FLAG_NOPROMISC))
|
if (!(vlan->flags & MACVLAN_FLAG_NOPROMISC))
|
||||||
dev_set_promiscuity(lowerdev, -1);
|
dev_set_promiscuity(lowerdev, -1);
|
||||||
goto hash_del;
|
goto hash_del;
|
||||||
@ -683,7 +695,7 @@ static int macvlan_sync_address(struct net_device *dev, unsigned char *addr)
|
|||||||
if (macvlan_addr_busy(vlan->port, addr))
|
if (macvlan_addr_busy(vlan->port, addr))
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
|
||||||
if (!vlan->port->passthru) {
|
if (!macvlan_passthru(vlan->port)) {
|
||||||
err = dev_uc_add(lowerdev, addr);
|
err = dev_uc_add(lowerdev, addr);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
@ -933,7 +945,7 @@ static int macvlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
|
|||||||
/* Support unicast filter only on passthru devices.
|
/* Support unicast filter only on passthru devices.
|
||||||
* Multicast filter should be allowed on all devices.
|
* Multicast filter should be allowed on all devices.
|
||||||
*/
|
*/
|
||||||
if (!vlan->port->passthru && is_unicast_ether_addr(addr))
|
if (!macvlan_passthru(vlan->port) && is_unicast_ether_addr(addr))
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
if (flags & NLM_F_REPLACE)
|
if (flags & NLM_F_REPLACE)
|
||||||
@ -957,7 +969,7 @@ static int macvlan_fdb_del(struct ndmsg *ndm, struct nlattr *tb[],
|
|||||||
/* Support unicast filter only on passthru devices.
|
/* Support unicast filter only on passthru devices.
|
||||||
* Multicast filter should be allowed on all devices.
|
* Multicast filter should be allowed on all devices.
|
||||||
*/
|
*/
|
||||||
if (!vlan->port->passthru && is_unicast_ether_addr(addr))
|
if (!macvlan_passthru(vlan->port) && is_unicast_ether_addr(addr))
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
if (is_unicast_ether_addr(addr))
|
if (is_unicast_ether_addr(addr))
|
||||||
@ -1125,7 +1137,6 @@ static int macvlan_port_create(struct net_device *dev)
|
|||||||
if (port == NULL)
|
if (port == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
port->passthru = false;
|
|
||||||
port->dev = dev;
|
port->dev = dev;
|
||||||
INIT_LIST_HEAD(&port->vlans);
|
INIT_LIST_HEAD(&port->vlans);
|
||||||
for (i = 0; i < MACVLAN_HASH_SIZE; i++)
|
for (i = 0; i < MACVLAN_HASH_SIZE; i++)
|
||||||
@ -1331,7 +1342,7 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
|
|||||||
port = macvlan_port_get_rtnl(lowerdev);
|
port = macvlan_port_get_rtnl(lowerdev);
|
||||||
|
|
||||||
/* Only 1 macvlan device can be created in passthru mode */
|
/* Only 1 macvlan device can be created in passthru mode */
|
||||||
if (port->passthru) {
|
if (macvlan_passthru(port)) {
|
||||||
/* The macvlan port must be not created this time,
|
/* The macvlan port must be not created this time,
|
||||||
* still goto destroy_macvlan_port for readability.
|
* still goto destroy_macvlan_port for readability.
|
||||||
*/
|
*/
|
||||||
@ -1357,7 +1368,7 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev,
|
|||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
goto destroy_macvlan_port;
|
goto destroy_macvlan_port;
|
||||||
}
|
}
|
||||||
port->passthru = true;
|
macvlan_set_passthru(port);
|
||||||
eth_hw_addr_inherit(dev, lowerdev);
|
eth_hw_addr_inherit(dev, lowerdev);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1439,7 +1450,7 @@ static int macvlan_changelink(struct net_device *dev,
|
|||||||
if (data && data[IFLA_MACVLAN_FLAGS]) {
|
if (data && data[IFLA_MACVLAN_FLAGS]) {
|
||||||
__u16 flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]);
|
__u16 flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]);
|
||||||
bool promisc = (flags ^ vlan->flags) & MACVLAN_FLAG_NOPROMISC;
|
bool promisc = (flags ^ vlan->flags) & MACVLAN_FLAG_NOPROMISC;
|
||||||
if (vlan->port->passthru && promisc) {
|
if (macvlan_passthru(vlan->port) && promisc) {
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (flags & MACVLAN_FLAG_NOPROMISC)
|
if (flags & MACVLAN_FLAG_NOPROMISC)
|
||||||
@ -1602,7 +1613,7 @@ static int macvlan_device_event(struct notifier_block *unused,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NETDEV_CHANGEADDR:
|
case NETDEV_CHANGEADDR:
|
||||||
if (!port->passthru)
|
if (!macvlan_passthru(port))
|
||||||
return NOTIFY_DONE;
|
return NOTIFY_DONE;
|
||||||
|
|
||||||
vlan = list_first_entry_or_null(&port->vlans,
|
vlan = list_first_entry_or_null(&port->vlans,
|
||||||
|
Loading…
Reference in New Issue
Block a user