diff options
author | Vlad Yasevich <vyasevich@gmail.com> | 2017-06-21 07:59:18 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-06-22 11:17:42 -0400 |
commit | 43c2d578a0ce0d6067a02b46461811aced551425 (patch) | |
tree | 8596fa46fc93f008bda5b52f11d292277671bc69 /drivers/net/macvlan.c | |
parent | e696cda7bd091411705a4e868ce480eaa3082dbf (diff) |
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>
Diffstat (limited to 'drivers/net/macvlan.c')
-rw-r--r-- | drivers/net/macvlan.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index 0c9c6da3427a..4d013ca79dae 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c | |||
@@ -39,13 +39,15 @@ | |||
39 | #define MACVLAN_HASH_SIZE (1<<MACVLAN_HASH_BITS) | 39 | #define MACVLAN_HASH_SIZE (1<<MACVLAN_HASH_BITS) |
40 | #define MACVLAN_BC_QUEUE_LEN 1000 | 40 | #define MACVLAN_BC_QUEUE_LEN 1000 |
41 | 41 | ||
42 | #define MACVLAN_F_PASSTHRU 1 | ||
43 | |||
42 | struct macvlan_port { | 44 | struct macvlan_port { |
43 | struct net_device *dev; | 45 | struct net_device *dev; |
44 | struct hlist_head vlan_hash[MACVLAN_HASH_SIZE]; | 46 | struct hlist_head vlan_hash[MACVLAN_HASH_SIZE]; |
45 | struct list_head vlans; | 47 | struct list_head vlans; |
46 | struct sk_buff_head bc_queue; | 48 | struct sk_buff_head bc_queue; |
47 | struct work_struct bc_work; | 49 | struct work_struct bc_work; |
48 | bool passthru; | 50 | u32 flags; |
49 | int count; | 51 | int count; |
50 | struct hlist_head vlan_source_hash[MACVLAN_HASH_SIZE]; | 52 | struct hlist_head vlan_source_hash[MACVLAN_HASH_SIZE]; |
51 | DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ); | 53 | DECLARE_BITMAP(mc_filter, MACVLAN_MC_FILTER_SZ); |
@@ -66,6 +68,16 @@ struct macvlan_skb_cb { | |||
66 | 68 | ||
67 | static void macvlan_port_destroy(struct net_device *dev); | 69 | static void macvlan_port_destroy(struct net_device *dev); |
68 | 70 | ||
71 | static inline bool macvlan_passthru(const struct macvlan_port *port) | ||
72 | { | ||
73 | return port->flags & MACVLAN_F_PASSTHRU; | ||
74 | } | ||
75 | |||
76 | static inline void macvlan_set_passthru(struct macvlan_port *port) | ||
77 | { | ||
78 | port->flags |= MACVLAN_F_PASSTHRU; | ||
79 | } | ||
80 | |||
69 | /* Hash Ethernet address */ | 81 | /* Hash Ethernet address */ |
70 | static u32 macvlan_eth_hash(const unsigned char *addr) | 82 | static u32 macvlan_eth_hash(const unsigned char *addr) |
71 | { | 83 | { |
@@ -185,7 +197,7 @@ static bool macvlan_addr_busy(const struct macvlan_port *port, | |||
185 | * currently in use by the underlying device or | 197 | * currently in use by the underlying device or |
186 | * another macvlan. | 198 | * another macvlan. |
187 | */ | 199 | */ |
188 | if (!port->passthru && | 200 | if (!macvlan_passthru(port) && |
189 | ether_addr_equal_64bits(port->dev->dev_addr, addr)) | 201 | ether_addr_equal_64bits(port->dev->dev_addr, addr)) |
190 | return true; | 202 | return true; |
191 | 203 | ||
@@ -446,7 +458,7 @@ static rx_handler_result_t macvlan_handle_frame(struct sk_buff **pskb) | |||
446 | } | 458 | } |
447 | 459 | ||
448 | macvlan_forward_source(skb, port, eth->h_source); | 460 | macvlan_forward_source(skb, port, eth->h_source); |
449 | if (port->passthru) | 461 | if (macvlan_passthru(port)) |
450 | vlan = list_first_or_null_rcu(&port->vlans, | 462 | vlan = list_first_or_null_rcu(&port->vlans, |
451 | struct macvlan_dev, list); | 463 | struct macvlan_dev, list); |
452 | else | 464 | else |
@@ -575,7 +587,7 @@ static int macvlan_open(struct net_device *dev) | |||
575 | struct net_device *lowerdev = vlan->lowerdev; | 587 | struct net_device *lowerdev = vlan->lowerdev; |
576 | int err; | 588 | int err; |
577 | 589 | ||
578 | if (vlan->port->passthru) { | 590 | if (macvlan_passthru(vlan->port)) { |
579 | if (!(vlan->flags & MACVLAN_FLAG_NOPROMISC)) { | 591 | if (!(vlan->flags & MACVLAN_FLAG_NOPROMISC)) { |
580 | err = dev_set_promiscuity(lowerdev, 1); | 592 | err = dev_set_promiscuity(lowerdev, 1); |
581 | if (err < 0) | 593 | if (err < 0) |
@@ -650,7 +662,7 @@ static int macvlan_stop(struct net_device *dev) | |||
650 | dev_uc_unsync(lowerdev, dev); | 662 | dev_uc_unsync(lowerdev, dev); |
651 | dev_mc_unsync(lowerdev, dev); | 663 | dev_mc_unsync(lowerdev, dev); |
652 | 664 | ||
653 | if (vlan->port->passthru) { | 665 | if (macvlan_passthru(vlan->port)) { |
654 | if (!(vlan->flags & MACVLAN_FLAG_NOPROMISC)) | 666 | if (!(vlan->flags & MACVLAN_FLAG_NOPROMISC)) |
655 | dev_set_promiscuity(lowerdev, -1); | 667 | dev_set_promiscuity(lowerdev, -1); |
656 | goto hash_del; | 668 | goto hash_del; |
@@ -683,7 +695,7 @@ static int macvlan_sync_address(struct net_device *dev, unsigned char *addr) | |||
683 | if (macvlan_addr_busy(vlan->port, addr)) | 695 | if (macvlan_addr_busy(vlan->port, addr)) |
684 | return -EBUSY; | 696 | return -EBUSY; |
685 | 697 | ||
686 | if (!vlan->port->passthru) { | 698 | if (!macvlan_passthru(vlan->port)) { |
687 | err = dev_uc_add(lowerdev, addr); | 699 | err = dev_uc_add(lowerdev, addr); |
688 | if (err) | 700 | if (err) |
689 | return err; | 701 | return err; |
@@ -933,7 +945,7 @@ static int macvlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[], | |||
933 | /* Support unicast filter only on passthru devices. | 945 | /* Support unicast filter only on passthru devices. |
934 | * Multicast filter should be allowed on all devices. | 946 | * Multicast filter should be allowed on all devices. |
935 | */ | 947 | */ |
936 | if (!vlan->port->passthru && is_unicast_ether_addr(addr)) | 948 | if (!macvlan_passthru(vlan->port) && is_unicast_ether_addr(addr)) |
937 | return -EOPNOTSUPP; | 949 | return -EOPNOTSUPP; |
938 | 950 | ||
939 | if (flags & NLM_F_REPLACE) | 951 | if (flags & NLM_F_REPLACE) |
@@ -957,7 +969,7 @@ static int macvlan_fdb_del(struct ndmsg *ndm, struct nlattr *tb[], | |||
957 | /* Support unicast filter only on passthru devices. | 969 | /* Support unicast filter only on passthru devices. |
958 | * Multicast filter should be allowed on all devices. | 970 | * Multicast filter should be allowed on all devices. |
959 | */ | 971 | */ |
960 | if (!vlan->port->passthru && is_unicast_ether_addr(addr)) | 972 | if (!macvlan_passthru(vlan->port) && is_unicast_ether_addr(addr)) |
961 | return -EOPNOTSUPP; | 973 | return -EOPNOTSUPP; |
962 | 974 | ||
963 | if (is_unicast_ether_addr(addr)) | 975 | if (is_unicast_ether_addr(addr)) |
@@ -1125,7 +1137,6 @@ static int macvlan_port_create(struct net_device *dev) | |||
1125 | if (port == NULL) | 1137 | if (port == NULL) |
1126 | return -ENOMEM; | 1138 | return -ENOMEM; |
1127 | 1139 | ||
1128 | port->passthru = false; | ||
1129 | port->dev = dev; | 1140 | port->dev = dev; |
1130 | INIT_LIST_HEAD(&port->vlans); | 1141 | INIT_LIST_HEAD(&port->vlans); |
1131 | for (i = 0; i < MACVLAN_HASH_SIZE; i++) | 1142 | for (i = 0; i < MACVLAN_HASH_SIZE; i++) |
@@ -1331,7 +1342,7 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev, | |||
1331 | port = macvlan_port_get_rtnl(lowerdev); | 1342 | port = macvlan_port_get_rtnl(lowerdev); |
1332 | 1343 | ||
1333 | /* Only 1 macvlan device can be created in passthru mode */ | 1344 | /* Only 1 macvlan device can be created in passthru mode */ |
1334 | if (port->passthru) { | 1345 | if (macvlan_passthru(port)) { |
1335 | /* The macvlan port must be not created this time, | 1346 | /* The macvlan port must be not created this time, |
1336 | * still goto destroy_macvlan_port for readability. | 1347 | * still goto destroy_macvlan_port for readability. |
1337 | */ | 1348 | */ |
@@ -1357,7 +1368,7 @@ int macvlan_common_newlink(struct net *src_net, struct net_device *dev, | |||
1357 | err = -EINVAL; | 1368 | err = -EINVAL; |
1358 | goto destroy_macvlan_port; | 1369 | goto destroy_macvlan_port; |
1359 | } | 1370 | } |
1360 | port->passthru = true; | 1371 | macvlan_set_passthru(port); |
1361 | eth_hw_addr_inherit(dev, lowerdev); | 1372 | eth_hw_addr_inherit(dev, lowerdev); |
1362 | } | 1373 | } |
1363 | 1374 | ||
@@ -1439,7 +1450,7 @@ static int macvlan_changelink(struct net_device *dev, | |||
1439 | if (data && data[IFLA_MACVLAN_FLAGS]) { | 1450 | if (data && data[IFLA_MACVLAN_FLAGS]) { |
1440 | __u16 flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]); | 1451 | __u16 flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]); |
1441 | bool promisc = (flags ^ vlan->flags) & MACVLAN_FLAG_NOPROMISC; | 1452 | bool promisc = (flags ^ vlan->flags) & MACVLAN_FLAG_NOPROMISC; |
1442 | if (vlan->port->passthru && promisc) { | 1453 | if (macvlan_passthru(vlan->port) && promisc) { |
1443 | int err; | 1454 | int err; |
1444 | 1455 | ||
1445 | if (flags & MACVLAN_FLAG_NOPROMISC) | 1456 | if (flags & MACVLAN_FLAG_NOPROMISC) |
@@ -1602,7 +1613,7 @@ static int macvlan_device_event(struct notifier_block *unused, | |||
1602 | } | 1613 | } |
1603 | break; | 1614 | break; |
1604 | case NETDEV_CHANGEADDR: | 1615 | case NETDEV_CHANGEADDR: |
1605 | if (!port->passthru) | 1616 | if (!macvlan_passthru(port)) |
1606 | return NOTIFY_DONE; | 1617 | return NOTIFY_DONE; |
1607 | 1618 | ||
1608 | vlan = list_first_entry_or_null(&port->vlans, | 1619 | vlan = list_first_entry_or_null(&port->vlans, |