Lines Matching +full:addr +full:- +full:mode
1 // SPDX-License-Identifier: GPL-2.0-or-later
6 * ---
7 * (C) Copyright 2001-2006
9 * Re-worked by Ben Greear <greearb@candelatech.com>
10 * ---
62 unsigned char addr[6+2] __aligned(sizeof(u16));
70 #define MACVLAN_SKB_CB(__skb) ((struct macvlan_skb_cb *)&((__skb)->cb[0]))
77 return port->flags & MACVLAN_F_PASSTHRU; in macvlan_passthru()
82 port->flags |= MACVLAN_F_PASSTHRU; in macvlan_set_passthru()
87 return port->flags & MACVLAN_F_ADDRCHANGE; in macvlan_addr_change()
92 port->flags |= MACVLAN_F_ADDRCHANGE; in macvlan_set_addr_change()
97 port->flags &= ~MACVLAN_F_ADDRCHANGE; in macvlan_clear_addr_change()
101 static u32 macvlan_eth_hash(const unsigned char *addr) in macvlan_eth_hash() argument
103 u64 value = get_unaligned((u64 *)addr); in macvlan_eth_hash()
116 return rcu_dereference(dev->rx_handler_data); in macvlan_port_get_rcu()
121 return rtnl_dereference(dev->rx_handler_data); in macvlan_port_get_rtnl()
125 const unsigned char *addr) in macvlan_hash_lookup() argument
128 u32 idx = macvlan_eth_hash(addr); in macvlan_hash_lookup()
130 hlist_for_each_entry_rcu(vlan, &port->vlan_hash[idx], hlist, in macvlan_hash_lookup()
132 if (ether_addr_equal_64bits(vlan->dev->dev_addr, addr)) in macvlan_hash_lookup()
140 const unsigned char *addr) in macvlan_hash_lookup_source() argument
143 u32 idx = macvlan_eth_hash(addr); in macvlan_hash_lookup_source()
144 struct hlist_head *h = &vlan->port->vlan_source_hash[idx]; in macvlan_hash_lookup_source()
147 if (ether_addr_equal_64bits(entry->addr, addr) && in macvlan_hash_lookup_source()
148 entry->vlan == vlan) in macvlan_hash_lookup_source()
155 const unsigned char *addr) in macvlan_hash_add_source() argument
157 struct macvlan_port *port = vlan->port; in macvlan_hash_add_source()
161 entry = macvlan_hash_lookup_source(vlan, addr); in macvlan_hash_add_source()
167 return -ENOMEM; in macvlan_hash_add_source()
169 ether_addr_copy(entry->addr, addr); in macvlan_hash_add_source()
170 entry->vlan = vlan; in macvlan_hash_add_source()
171 h = &port->vlan_source_hash[macvlan_eth_hash(addr)]; in macvlan_hash_add_source()
172 hlist_add_head_rcu(&entry->hlist, h); in macvlan_hash_add_source()
173 vlan->macaddr_count++; in macvlan_hash_add_source()
180 struct macvlan_port *port = vlan->port; in macvlan_hash_add()
181 const unsigned char *addr = vlan->dev->dev_addr; in macvlan_hash_add() local
182 u32 idx = macvlan_eth_hash(addr); in macvlan_hash_add()
184 hlist_add_head_rcu(&vlan->hlist, &port->vlan_hash[idx]); in macvlan_hash_add()
189 hlist_del_rcu(&entry->hlist); in macvlan_hash_del_source()
195 hlist_del_rcu(&vlan->hlist); in macvlan_hash_del()
201 const unsigned char *addr) in macvlan_hash_change_addr() argument
207 eth_hw_addr_set(vlan->dev, addr); in macvlan_hash_change_addr()
212 const unsigned char *addr) in macvlan_addr_busy() argument
219 ether_addr_equal_64bits(port->dev->dev_addr, addr)) in macvlan_addr_busy()
222 if (macvlan_hash_lookup(port, addr)) in macvlan_addr_busy()
233 struct net_device *dev = vlan->dev; in macvlan_broadcast_one()
238 skb->dev = dev; in macvlan_broadcast_one()
239 if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast)) in macvlan_broadcast_one()
240 skb->pkt_type = PACKET_BROADCAST; in macvlan_broadcast_one()
242 skb->pkt_type = PACKET_MULTICAST; in macvlan_broadcast_one()
254 const unsigned char *addr) in mc_hash() argument
256 u32 val = __get_unaligned_cpu32(addr + 2); in mc_hash()
265 enum macvlan_mode mode) in macvlan_broadcast() argument
274 if (skb->protocol == htons(ETH_P_PAUSE)) in macvlan_broadcast()
277 hash_for_each_rcu(port->vlan_hash, i, vlan, hlist) { in macvlan_broadcast()
278 if (vlan->dev == src || !(vlan->mode & mode)) in macvlan_broadcast()
281 hash = mc_hash(vlan, eth->h_dest); in macvlan_broadcast()
282 if (!test_bit(hash, vlan->mc_filter)) in macvlan_broadcast()
289 mode == MACVLAN_MODE_BRIDGE) ?: in macvlan_broadcast()
291 macvlan_count_rx(vlan, skb->len + ETH_HLEN, in macvlan_broadcast()
307 else if (src->mode == MACVLAN_MODE_VEPA) in macvlan_multicast_rx()
309 macvlan_broadcast(skb, port, src->dev, in macvlan_multicast_rx()
317 macvlan_broadcast(skb, port, src->dev, in macvlan_multicast_rx()
330 spin_lock_bh(&port->bc_queue.lock); in macvlan_process_broadcast()
331 skb_queue_splice_tail_init(&port->bc_queue, &list); in macvlan_process_broadcast()
332 spin_unlock_bh(&port->bc_queue.lock); in macvlan_process_broadcast()
335 const struct macvlan_dev *src = MACVLAN_SKB_CB(skb)->src; in macvlan_process_broadcast()
342 dev_put(src->dev); in macvlan_process_broadcast()
354 int err = -ENOMEM; in macvlan_broadcast_enqueue()
360 MACVLAN_SKB_CB(nskb)->src = src; in macvlan_broadcast_enqueue()
362 spin_lock(&port->bc_queue.lock); in macvlan_broadcast_enqueue()
363 if (skb_queue_len(&port->bc_queue) < port->bc_queue_len_used) { in macvlan_broadcast_enqueue()
365 dev_hold(src->dev); in macvlan_broadcast_enqueue()
366 __skb_queue_tail(&port->bc_queue, nskb); in macvlan_broadcast_enqueue()
369 spin_unlock(&port->bc_queue.lock); in macvlan_broadcast_enqueue()
371 queue_work(system_unbound_wq, &port->bc_work); in macvlan_broadcast_enqueue()
381 dev_core_stats_rx_dropped_inc(skb->dev); in macvlan_broadcast_enqueue()
391 hash_for_each_safe(port->vlan_source_hash, i, next, entry, hlist) in macvlan_flush_sources()
392 if (entry->vlan == vlan) in macvlan_flush_sources()
395 vlan->macaddr_count = 0; in macvlan_flush_sources()
406 dev = vlan->dev; in macvlan_forward_source_one()
407 if (unlikely(!(dev->flags & IFF_UP))) in macvlan_forward_source_one()
414 len = nskb->len + ETH_HLEN; in macvlan_forward_source_one()
415 nskb->dev = dev; in macvlan_forward_source_one()
417 if (ether_addr_equal_64bits(eth_hdr(skb)->h_dest, dev->dev_addr)) in macvlan_forward_source_one()
418 nskb->pkt_type = PACKET_HOST; in macvlan_forward_source_one()
426 const unsigned char *addr) in macvlan_forward_source() argument
429 u32 idx = macvlan_eth_hash(addr); in macvlan_forward_source()
430 struct hlist_head *h = &port->vlan_source_hash[idx]; in macvlan_forward_source()
434 if (ether_addr_equal_64bits(entry->addr, addr)) { in macvlan_forward_source()
435 if (entry->vlan->flags & MACVLAN_FLAG_NODST) in macvlan_forward_source()
437 macvlan_forward_source_one(skb, entry->vlan); in macvlan_forward_source()
458 if (unlikely(skb->pkt_type == PACKET_LOOPBACK)) in macvlan_handle_frame()
461 port = macvlan_port_get_rcu(skb->dev); in macvlan_handle_frame()
462 if (is_multicast_ether_addr(eth->h_dest)) { in macvlan_handle_frame()
465 skb = ip_check_defrag(dev_net(skb->dev), skb, IP_DEFRAG_MACVLAN); in macvlan_handle_frame()
470 if (macvlan_forward_source(skb, port, eth->h_source)) { in macvlan_handle_frame()
474 src = macvlan_hash_lookup(port, eth->h_source); in macvlan_handle_frame()
475 if (src && src->mode != MACVLAN_MODE_VEPA && in macvlan_handle_frame()
476 src->mode != MACVLAN_MODE_BRIDGE) { in macvlan_handle_frame()
485 hash = mc_hash(NULL, eth->h_dest); in macvlan_handle_frame()
486 if (test_bit(hash, port->bc_filter)) in macvlan_handle_frame()
488 else if (test_bit(hash, port->mc_filter)) in macvlan_handle_frame()
494 if (macvlan_forward_source(skb, port, eth->h_source)) { in macvlan_handle_frame()
499 vlan = list_first_or_null_rcu(&port->vlans, in macvlan_handle_frame()
502 vlan = macvlan_hash_lookup(port, eth->h_dest); in macvlan_handle_frame()
503 if (!vlan || vlan->mode == MACVLAN_MODE_SOURCE) in macvlan_handle_frame()
506 dev = vlan->dev; in macvlan_handle_frame()
507 if (unlikely(!(dev->flags & IFF_UP))) { in macvlan_handle_frame()
511 len = skb->len + ETH_HLEN; in macvlan_handle_frame()
520 skb->dev = dev; in macvlan_handle_frame()
521 skb->pkt_type = PACKET_HOST; in macvlan_handle_frame()
533 const struct macvlan_port *port = vlan->port; in macvlan_queue_xmit()
536 if (vlan->mode == MACVLAN_MODE_BRIDGE) { in macvlan_queue_xmit()
540 if (is_multicast_ether_addr(eth->h_dest)) { in macvlan_queue_xmit()
546 dest = macvlan_hash_lookup(port, eth->h_dest); in macvlan_queue_xmit()
547 if (dest && dest->mode == MACVLAN_MODE_BRIDGE) { in macvlan_queue_xmit()
549 dev_forward_skb(vlan->lowerdev, skb); in macvlan_queue_xmit()
555 skb->dev = vlan->lowerdev; in macvlan_queue_xmit()
563 return netpoll_send_skb(vlan->netpoll, skb); in macvlan_netpoll_send_skb()
574 unsigned int len = skb->len; in macvlan_start_xmit()
585 pcpu_stats = this_cpu_ptr(vlan->pcpu_stats); in macvlan_start_xmit()
586 u64_stats_update_begin(&pcpu_stats->syncp); in macvlan_start_xmit()
587 u64_stats_inc(&pcpu_stats->tx_packets); in macvlan_start_xmit()
588 u64_stats_add(&pcpu_stats->tx_bytes, len); in macvlan_start_xmit()
589 u64_stats_update_end(&pcpu_stats->syncp); in macvlan_start_xmit()
591 this_cpu_inc(vlan->pcpu_stats->tx_dropped); in macvlan_start_xmit()
601 struct net_device *lowerdev = vlan->lowerdev; in macvlan_hard_header()
604 saddr ? : dev->dev_addr, len); in macvlan_hard_header()
618 struct net_device *lowerdev = vlan->lowerdev; in macvlan_open()
621 if (macvlan_passthru(vlan->port)) { in macvlan_open()
622 if (!(vlan->flags & MACVLAN_FLAG_NOPROMISC)) { in macvlan_open()
630 err = -EADDRINUSE; in macvlan_open()
631 if (macvlan_addr_busy(vlan->port, dev->dev_addr)) in macvlan_open()
637 if (lowerdev->features & NETIF_F_HW_L2FW_DOFFLOAD) in macvlan_open()
638 vlan->accel_priv = in macvlan_open()
639 lowerdev->netdev_ops->ndo_dfwd_add_station(lowerdev, dev); in macvlan_open()
644 if (IS_ERR_OR_NULL(vlan->accel_priv)) { in macvlan_open()
645 vlan->accel_priv = NULL; in macvlan_open()
646 err = dev_uc_add(lowerdev, dev->dev_addr); in macvlan_open()
651 if (dev->flags & IFF_ALLMULTI) { in macvlan_open()
657 if (dev->flags & IFF_PROMISC) { in macvlan_open()
668 if (dev->flags & IFF_ALLMULTI) in macvlan_open()
669 dev_set_allmulti(lowerdev, -1); in macvlan_open()
671 if (vlan->accel_priv) { in macvlan_open()
672 lowerdev->netdev_ops->ndo_dfwd_del_station(lowerdev, in macvlan_open()
673 vlan->accel_priv); in macvlan_open()
674 vlan->accel_priv = NULL; in macvlan_open()
676 dev_uc_del(lowerdev, dev->dev_addr); in macvlan_open()
685 struct net_device *lowerdev = vlan->lowerdev; in macvlan_stop()
687 if (vlan->accel_priv) { in macvlan_stop()
688 lowerdev->netdev_ops->ndo_dfwd_del_station(lowerdev, in macvlan_stop()
689 vlan->accel_priv); in macvlan_stop()
690 vlan->accel_priv = NULL; in macvlan_stop()
696 if (macvlan_passthru(vlan->port)) { in macvlan_stop()
697 if (!(vlan->flags & MACVLAN_FLAG_NOPROMISC)) in macvlan_stop()
698 dev_set_promiscuity(lowerdev, -1); in macvlan_stop()
702 if (dev->flags & IFF_ALLMULTI) in macvlan_stop()
703 dev_set_allmulti(lowerdev, -1); in macvlan_stop()
705 if (dev->flags & IFF_PROMISC) in macvlan_stop()
706 dev_set_promiscuity(lowerdev, -1); in macvlan_stop()
708 dev_uc_del(lowerdev, dev->dev_addr); in macvlan_stop()
711 macvlan_hash_del(vlan, !dev->dismantle); in macvlan_stop()
716 const unsigned char *addr) in macvlan_sync_address() argument
719 struct net_device *lowerdev = vlan->lowerdev; in macvlan_sync_address()
720 struct macvlan_port *port = vlan->port; in macvlan_sync_address()
723 if (!(dev->flags & IFF_UP)) { in macvlan_sync_address()
725 eth_hw_addr_set(dev, addr); in macvlan_sync_address()
728 if (macvlan_addr_busy(vlan->port, addr)) in macvlan_sync_address()
729 return -EADDRINUSE; in macvlan_sync_address()
732 err = dev_uc_add(lowerdev, addr); in macvlan_sync_address()
736 dev_uc_del(lowerdev, dev->dev_addr); in macvlan_sync_address()
739 macvlan_hash_change_addr(vlan, addr); in macvlan_sync_address()
743 * device change. Save the lower-dev address so we can in macvlan_sync_address()
746 ether_addr_copy(vlan->port->perm_addr, in macvlan_sync_address()
747 lowerdev->dev_addr); in macvlan_sync_address()
756 struct sockaddr *addr = p; in macvlan_set_mac_address() local
758 if (!is_valid_ether_addr(addr->sa_data)) in macvlan_set_mac_address()
759 return -EADDRNOTAVAIL; in macvlan_set_mac_address()
761 /* If the addresses are the same, this is a no-op */ in macvlan_set_mac_address()
762 if (ether_addr_equal(dev->dev_addr, addr->sa_data)) in macvlan_set_mac_address()
765 if (vlan->mode == MACVLAN_MODE_PASSTHRU) { in macvlan_set_mac_address()
766 macvlan_set_addr_change(vlan->port); in macvlan_set_mac_address()
767 return dev_set_mac_address(vlan->lowerdev, addr, NULL); in macvlan_set_mac_address()
770 if (macvlan_addr_busy(vlan->port, addr->sa_data)) in macvlan_set_mac_address()
771 return -EADDRINUSE; in macvlan_set_mac_address()
773 return macvlan_sync_address(dev, addr->sa_data); in macvlan_set_mac_address()
779 struct net_device *lowerdev = vlan->lowerdev; in macvlan_change_rx_flags()
781 if (dev->flags & IFF_UP) { in macvlan_change_rx_flags()
783 dev_set_allmulti(lowerdev, dev->flags & IFF_ALLMULTI ? 1 : -1); in macvlan_change_rx_flags()
784 if (!macvlan_passthru(vlan->port) && change & IFF_PROMISC) in macvlan_change_rx_flags()
786 dev->flags & IFF_PROMISC ? 1 : -1); in macvlan_change_rx_flags()
795 if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) { in macvlan_compute_filter()
803 if (!vlan && ha->synced <= cutoff) in macvlan_compute_filter()
806 __set_bit(mc_hash(vlan, ha->addr), filter); in macvlan_compute_filter()
809 __set_bit(mc_hash(vlan, dev->broadcast), filter); in macvlan_compute_filter()
817 if (vlan->port->bc_cutoff < 0) { in macvlan_recompute_bc_filter()
818 bitmap_zero(vlan->port->bc_filter, MACVLAN_MC_FILTER_SZ); in macvlan_recompute_bc_filter()
822 macvlan_compute_filter(vlan->port->bc_filter, vlan->lowerdev, NULL, in macvlan_recompute_bc_filter()
823 vlan->port->bc_cutoff); in macvlan_recompute_bc_filter()
830 macvlan_compute_filter(vlan->mc_filter, dev, vlan, 0); in macvlan_set_mac_lists()
832 dev_uc_sync(vlan->lowerdev, dev); in macvlan_set_mac_lists()
833 dev_mc_sync(vlan->lowerdev, dev); in macvlan_set_mac_lists()
836 * list of vlan->lowerdev too. in macvlan_set_mac_lists()
848 macvlan_compute_filter(vlan->port->mc_filter, vlan->lowerdev, NULL, in macvlan_set_mac_lists()
855 if (vlan->port->bc_cutoff == cutoff) in update_port_bc_cutoff()
858 vlan->port->bc_cutoff = cutoff; in update_port_bc_cutoff()
866 if (vlan->lowerdev->mtu < new_mtu) in macvlan_change_mtu()
867 return -EINVAL; in macvlan_change_mtu()
868 WRITE_ONCE(dev->mtu, new_mtu); in macvlan_change_mtu()
887 return -EOPNOTSUPP; in macvlan_hwtstamp_set()
917 lockdep_set_class(&dev->addr_list_lock, in macvlan_set_lockdep_class()
924 struct net_device *lowerdev = vlan->lowerdev; in macvlan_init()
925 struct macvlan_port *port = vlan->port; in macvlan_init()
927 dev->state = (dev->state & ~MACVLAN_STATE_MASK) | in macvlan_init()
928 (lowerdev->state & MACVLAN_STATE_MASK); in macvlan_init()
929 dev->features = lowerdev->features & MACVLAN_FEATURES; in macvlan_init()
930 dev->features |= ALWAYS_ON_FEATURES; in macvlan_init()
931 dev->hw_features |= NETIF_F_LRO; in macvlan_init()
932 dev->vlan_features = lowerdev->vlan_features & MACVLAN_FEATURES; in macvlan_init()
933 dev->vlan_features |= ALWAYS_ON_OFFLOADS; in macvlan_init()
934 dev->hw_enc_features |= dev->features; in macvlan_init()
935 dev->lltx = true; in macvlan_init()
937 dev->hard_header_len = lowerdev->hard_header_len; in macvlan_init()
940 vlan->pcpu_stats = netdev_alloc_pcpu_stats(struct vlan_pcpu_stats); in macvlan_init()
941 if (!vlan->pcpu_stats) in macvlan_init()
942 return -ENOMEM; in macvlan_init()
944 port->count += 1; in macvlan_init()
947 netdev_hold(lowerdev, &vlan->dev_tracker, GFP_KERNEL); in macvlan_init()
955 struct macvlan_port *port = vlan->port; in macvlan_uninit()
957 free_percpu(vlan->pcpu_stats); in macvlan_uninit()
960 port->count -= 1; in macvlan_uninit()
961 if (!port->count) in macvlan_uninit()
962 macvlan_port_destroy(port->dev); in macvlan_uninit()
970 if (vlan->pcpu_stats) { in macvlan_dev_get_stats64()
978 p = per_cpu_ptr(vlan->pcpu_stats, i); in macvlan_dev_get_stats64()
980 start = u64_stats_fetch_begin(&p->syncp); in macvlan_dev_get_stats64()
981 rx_packets = u64_stats_read(&p->rx_packets); in macvlan_dev_get_stats64()
982 rx_bytes = u64_stats_read(&p->rx_bytes); in macvlan_dev_get_stats64()
983 rx_multicast = u64_stats_read(&p->rx_multicast); in macvlan_dev_get_stats64()
984 tx_packets = u64_stats_read(&p->tx_packets); in macvlan_dev_get_stats64()
985 tx_bytes = u64_stats_read(&p->tx_bytes); in macvlan_dev_get_stats64()
986 } while (u64_stats_fetch_retry(&p->syncp, start)); in macvlan_dev_get_stats64()
988 stats->rx_packets += rx_packets; in macvlan_dev_get_stats64()
989 stats->rx_bytes += rx_bytes; in macvlan_dev_get_stats64()
990 stats->multicast += rx_multicast; in macvlan_dev_get_stats64()
991 stats->tx_packets += tx_packets; in macvlan_dev_get_stats64()
992 stats->tx_bytes += tx_bytes; in macvlan_dev_get_stats64()
996 rx_errors += READ_ONCE(p->rx_errors); in macvlan_dev_get_stats64()
997 tx_dropped += READ_ONCE(p->tx_dropped); in macvlan_dev_get_stats64()
999 stats->rx_errors = rx_errors; in macvlan_dev_get_stats64()
1000 stats->rx_dropped = rx_errors; in macvlan_dev_get_stats64()
1001 stats->tx_dropped = tx_dropped; in macvlan_dev_get_stats64()
1009 struct net_device *lowerdev = vlan->lowerdev; in macvlan_vlan_rx_add_vid()
1018 struct net_device *lowerdev = vlan->lowerdev; in macvlan_vlan_rx_kill_vid()
1026 const unsigned char *addr, u16 vid, in macvlan_fdb_add() argument
1031 int err = -EINVAL; in macvlan_fdb_add()
1036 if (!macvlan_passthru(vlan->port) && is_unicast_ether_addr(addr)) in macvlan_fdb_add()
1037 return -EOPNOTSUPP; in macvlan_fdb_add()
1040 return -EOPNOTSUPP; in macvlan_fdb_add()
1042 if (is_unicast_ether_addr(addr)) in macvlan_fdb_add()
1043 err = dev_uc_add_excl(dev, addr); in macvlan_fdb_add()
1044 else if (is_multicast_ether_addr(addr)) in macvlan_fdb_add()
1045 err = dev_mc_add_excl(dev, addr); in macvlan_fdb_add()
1052 const unsigned char *addr, u16 vid, in macvlan_fdb_del() argument
1056 int err = -EINVAL; in macvlan_fdb_del()
1061 if (!macvlan_passthru(vlan->port) && is_unicast_ether_addr(addr)) in macvlan_fdb_del()
1062 return -EOPNOTSUPP; in macvlan_fdb_del()
1064 if (is_unicast_ether_addr(addr)) in macvlan_fdb_del()
1065 err = dev_uc_del(dev, addr); in macvlan_fdb_del()
1066 else if (is_multicast_ether_addr(addr)) in macvlan_fdb_del()
1067 err = dev_mc_del(dev, addr); in macvlan_fdb_del()
1075 strscpy(drvinfo->driver, "macvlan", sizeof(drvinfo->driver)); in macvlan_ethtool_get_drvinfo()
1076 strscpy(drvinfo->version, "0.1", sizeof(drvinfo->version)); in macvlan_ethtool_get_drvinfo()
1084 return __ethtool_get_link_ksettings(vlan->lowerdev, cmd); in macvlan_ethtool_get_link_ksettings()
1099 netdev_features_t lowerdev_features = vlan->lowerdev->features; in macvlan_fix_features()
1103 features &= (vlan->set_features | ~MACVLAN_FEATURES); in macvlan_fix_features()
1123 struct net_device *real_dev = vlan->lowerdev; in macvlan_dev_netpoll_setup()
1128 err = -ENOMEM; in macvlan_dev_netpoll_setup()
1138 vlan->netpoll = netpoll; in macvlan_dev_netpoll_setup()
1147 struct netpoll *netpoll = vlan->netpoll; in macvlan_dev_netpoll_cleanup()
1152 vlan->netpoll = NULL; in macvlan_dev_netpoll_cleanup()
1162 return READ_ONCE(vlan->lowerdev->ifindex); in macvlan_dev_get_iflink()
1206 netdev_put(vlan->lowerdev, &vlan->dev_tracker); in macvlan_dev_free()
1213 /* ether_setup() has set dev->min_mtu to ETH_MIN_MTU. */ in macvlan_common_setup()
1214 dev->max_mtu = ETH_MAX_MTU; in macvlan_common_setup()
1215 dev->priv_flags &= ~IFF_TX_SKB_SHARING; in macvlan_common_setup()
1217 dev->priv_flags |= IFF_UNICAST_FLT; in macvlan_common_setup()
1218 dev->change_proto_down = true; in macvlan_common_setup()
1219 dev->netdev_ops = &macvlan_netdev_ops; in macvlan_common_setup()
1220 dev->needs_free_netdev = true; in macvlan_common_setup()
1221 dev->priv_destructor = macvlan_dev_free; in macvlan_common_setup()
1222 dev->header_ops = &macvlan_hard_header_ops; in macvlan_common_setup()
1223 dev->ethtool_ops = &macvlan_ethtool_ops; in macvlan_common_setup()
1230 dev->priv_flags |= IFF_NO_QUEUE; in macvlan_setup()
1239 if (dev->type != ARPHRD_ETHER || dev->flags & IFF_LOOPBACK) in macvlan_port_create()
1240 return -EINVAL; in macvlan_port_create()
1243 return -EBUSY; in macvlan_port_create()
1247 return -ENOMEM; in macvlan_port_create()
1249 port->dev = dev; in macvlan_port_create()
1250 ether_addr_copy(port->perm_addr, dev->dev_addr); in macvlan_port_create()
1251 INIT_LIST_HEAD(&port->vlans); in macvlan_port_create()
1253 INIT_HLIST_HEAD(&port->vlan_hash[i]); in macvlan_port_create()
1255 INIT_HLIST_HEAD(&port->vlan_source_hash[i]); in macvlan_port_create()
1257 port->bc_queue_len_used = 0; in macvlan_port_create()
1258 port->bc_cutoff = 1; in macvlan_port_create()
1259 skb_queue_head_init(&port->bc_queue); in macvlan_port_create()
1260 INIT_WORK(&port->bc_work, macvlan_process_broadcast); in macvlan_port_create()
1266 dev->priv_flags |= IFF_MACVLAN_PORT; in macvlan_port_create()
1275 dev->priv_flags &= ~IFF_MACVLAN_PORT; in macvlan_port_destroy()
1281 cancel_work_sync(&port->bc_work); in macvlan_port_destroy()
1283 while ((skb = __skb_dequeue(&port->bc_queue))) { in macvlan_port_destroy()
1284 const struct macvlan_dev *src = MACVLAN_SKB_CB(skb)->src; in macvlan_port_destroy()
1287 dev_put(src->dev); in macvlan_port_destroy()
1296 !ether_addr_equal(port->dev->dev_addr, port->perm_addr)) { in macvlan_port_destroy()
1299 sa.sa_family = port->dev->type; in macvlan_port_destroy()
1300 memcpy(&sa.sa_data, port->perm_addr, port->dev->addr_len); in macvlan_port_destroy()
1301 dev_set_mac_address(port->dev, &sa, NULL); in macvlan_port_destroy()
1315 return -EINVAL; in macvlan_validate()
1317 return -EADDRNOTAVAIL; in macvlan_validate()
1326 return -EINVAL; in macvlan_validate()
1337 return -EINVAL; in macvlan_validate()
1349 return -EINVAL; in macvlan_validate()
1355 return -EINVAL; in macvlan_validate()
1358 return -EADDRNOTAVAIL; in macvlan_validate()
1368 return -EINVAL; in macvlan_validate()
1371 return -EADDRNOTAVAIL; in macvlan_validate()
1376 return -EINVAL; in macvlan_validate()
1383 * (only for macvlan devices in source mode)
1387 static int macvlan_changelink_sources(struct macvlan_dev *vlan, u32 mode, in macvlan_changelink_sources() argument
1390 char *addr = NULL; in macvlan_changelink_sources() local
1396 addr = nla_data(data[IFLA_MACVLAN_MACADDR]); in macvlan_changelink_sources()
1398 if (mode == MACVLAN_MACADDR_ADD) { in macvlan_changelink_sources()
1399 if (!addr) in macvlan_changelink_sources()
1400 return -EINVAL; in macvlan_changelink_sources()
1402 return macvlan_hash_add_source(vlan, addr); in macvlan_changelink_sources()
1404 } else if (mode == MACVLAN_MACADDR_DEL) { in macvlan_changelink_sources()
1405 if (!addr) in macvlan_changelink_sources()
1406 return -EINVAL; in macvlan_changelink_sources()
1408 entry = macvlan_hash_lookup_source(vlan, addr); in macvlan_changelink_sources()
1411 vlan->macaddr_count--; in macvlan_changelink_sources()
1413 } else if (mode == MACVLAN_MACADDR_FLUSH) { in macvlan_changelink_sources()
1414 macvlan_flush_sources(vlan->port, vlan); in macvlan_changelink_sources()
1415 } else if (mode == MACVLAN_MACADDR_SET) { in macvlan_changelink_sources()
1416 macvlan_flush_sources(vlan->port, vlan); in macvlan_changelink_sources()
1418 if (addr) { in macvlan_changelink_sources()
1419 ret = macvlan_hash_add_source(vlan, addr); in macvlan_changelink_sources()
1431 addr = nla_data(nla); in macvlan_changelink_sources()
1432 ret = macvlan_hash_add_source(vlan, addr); in macvlan_changelink_sources()
1437 return -EINVAL; in macvlan_changelink_sources()
1455 return -EINVAL; in macvlan_common_newlink()
1459 return -ENODEV; in macvlan_common_newlink()
1461 /* When creating macvlans or macvtaps on top of other macvlans - use in macvlan_common_newlink()
1468 dev->mtu = lowerdev->mtu; in macvlan_common_newlink()
1469 else if (dev->mtu > lowerdev->mtu) in macvlan_common_newlink()
1470 return -EINVAL; in macvlan_common_newlink()
1472 /* MTU range: 68 - lowerdev->max_mtu */ in macvlan_common_newlink()
1473 dev->min_mtu = ETH_MIN_MTU; in macvlan_common_newlink()
1474 dev->max_mtu = lowerdev->max_mtu; in macvlan_common_newlink()
1487 /* Only 1 macvlan device can be created in passthru mode */ in macvlan_common_newlink()
1492 err = -EINVAL; in macvlan_common_newlink()
1496 vlan->lowerdev = lowerdev; in macvlan_common_newlink()
1497 vlan->dev = dev; in macvlan_common_newlink()
1498 vlan->port = port; in macvlan_common_newlink()
1499 vlan->set_features = MACVLAN_FEATURES; in macvlan_common_newlink()
1501 vlan->mode = MACVLAN_MODE_VEPA; in macvlan_common_newlink()
1503 vlan->mode = nla_get_u32(data[IFLA_MACVLAN_MODE]); in macvlan_common_newlink()
1506 vlan->flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]); in macvlan_common_newlink()
1508 if (vlan->mode == MACVLAN_MODE_PASSTHRU) { in macvlan_common_newlink()
1509 if (port->count) { in macvlan_common_newlink()
1510 err = -EINVAL; in macvlan_common_newlink()
1518 if (vlan->mode != MACVLAN_MODE_SOURCE) { in macvlan_common_newlink()
1519 err = -EINVAL; in macvlan_common_newlink()
1528 vlan->bc_queue_len_req = MACVLAN_DEFAULT_BC_QUEUE_LEN; in macvlan_common_newlink()
1530 vlan->bc_queue_len_req = nla_get_u32(data[IFLA_MACVLAN_BC_QUEUE_LEN]); in macvlan_common_newlink()
1540 dev->priv_flags |= IFF_MACVLAN; in macvlan_common_newlink()
1545 list_add_tail_rcu(&vlan->list, &port->vlans); in macvlan_common_newlink()
1546 update_port_bc_queue_len(vlan->port); in macvlan_common_newlink()
1562 macvlan_port_destroy(port->dev); in macvlan_common_newlink()
1579 if (vlan->mode == MACVLAN_MODE_SOURCE) in macvlan_dellink()
1580 macvlan_flush_sources(vlan->port, vlan); in macvlan_dellink()
1581 list_del_rcu(&vlan->list); in macvlan_dellink()
1582 update_port_bc_queue_len(vlan->port); in macvlan_dellink()
1584 netdev_upper_dev_unlink(vlan->lowerdev, dev); in macvlan_dellink()
1593 enum macvlan_mode mode; in macvlan_changelink() local
1598 /* Validate mode, but don't set yet: setting flags may fail. */ in macvlan_changelink()
1601 mode = nla_get_u32(data[IFLA_MACVLAN_MODE]); in macvlan_changelink()
1602 /* Passthrough mode can't be set or cleared dynamically */ in macvlan_changelink()
1603 if ((mode == MACVLAN_MODE_PASSTHRU) != in macvlan_changelink()
1604 (vlan->mode == MACVLAN_MODE_PASSTHRU)) in macvlan_changelink()
1605 return -EINVAL; in macvlan_changelink()
1606 if (vlan->mode == MACVLAN_MODE_SOURCE && in macvlan_changelink()
1607 vlan->mode != mode) in macvlan_changelink()
1608 macvlan_flush_sources(vlan->port, vlan); in macvlan_changelink()
1613 bool promisc = (flags ^ vlan->flags) & MACVLAN_FLAG_NOPROMISC; in macvlan_changelink()
1614 if (macvlan_passthru(vlan->port) && promisc) { in macvlan_changelink()
1618 err = dev_set_promiscuity(vlan->lowerdev, -1); in macvlan_changelink()
1620 err = dev_set_promiscuity(vlan->lowerdev, 1); in macvlan_changelink()
1624 vlan->flags = flags; in macvlan_changelink()
1628 vlan->bc_queue_len_req = nla_get_u32(data[IFLA_MACVLAN_BC_QUEUE_LEN]); in macvlan_changelink()
1629 update_port_bc_queue_len(vlan->port); in macvlan_changelink()
1637 vlan->mode = mode; in macvlan_changelink()
1639 if (vlan->mode != MACVLAN_MODE_SOURCE) in macvlan_changelink()
1640 return -EINVAL; in macvlan_changelink()
1651 if (vlan->macaddr_count == 0) in macvlan_get_size_mac()
1654 + vlan->macaddr_count * nla_total_size(sizeof(u8) * ETH_ALEN); in macvlan_get_size_mac()
1675 struct hlist_head *h = &vlan->port->vlan_source_hash[i]; in macvlan_fill_info_macaddr()
1679 if (entry->vlan != vlan) in macvlan_fill_info_macaddr()
1681 if (nla_put(skb, IFLA_MACVLAN_MACADDR, ETH_ALEN, entry->addr)) in macvlan_fill_info_macaddr()
1691 struct macvlan_port *port = vlan->port; in macvlan_fill_info()
1695 if (nla_put_u32(skb, IFLA_MACVLAN_MODE, vlan->mode)) in macvlan_fill_info()
1697 if (nla_put_u16(skb, IFLA_MACVLAN_FLAGS, vlan->flags)) in macvlan_fill_info()
1699 if (nla_put_u32(skb, IFLA_MACVLAN_MACADDR_COUNT, vlan->macaddr_count)) in macvlan_fill_info()
1701 if (vlan->macaddr_count > 0) { in macvlan_fill_info()
1712 if (nla_put_u32(skb, IFLA_MACVLAN_BC_QUEUE_LEN, vlan->bc_queue_len_req)) in macvlan_fill_info()
1714 if (nla_put_u32(skb, IFLA_MACVLAN_BC_QUEUE_LEN_USED, port->bc_queue_len_used)) in macvlan_fill_info()
1716 if (port->bc_cutoff != 1 && in macvlan_fill_info()
1717 nla_put_s32(skb, IFLA_MACVLAN_BC_CUTOFF, port->bc_cutoff)) in macvlan_fill_info()
1722 return -EMSGSIZE; in macvlan_fill_info()
1740 ops->validate = macvlan_validate; in macvlan_link_register()
1741 ops->maxtype = IFLA_MACVLAN_MAX; in macvlan_link_register()
1742 ops->policy = macvlan_policy; in macvlan_link_register()
1743 ops->changelink = macvlan_changelink; in macvlan_link_register()
1744 ops->get_size = macvlan_get_size; in macvlan_link_register()
1745 ops->fill_info = macvlan_fill_info; in macvlan_link_register()
1770 list_for_each_entry(vlan, &port->vlans, list) { in update_port_bc_queue_len()
1771 if (vlan->bc_queue_len_req > max_bc_queue_len_req) in update_port_bc_queue_len()
1772 max_bc_queue_len_req = vlan->bc_queue_len_req; in update_port_bc_queue_len()
1774 port->bc_queue_len_used = max_bc_queue_len_req; in update_port_bc_queue_len()
1794 list_for_each_entry(vlan, &port->vlans, list) in macvlan_device_event()
1795 netif_stacked_transfer_operstate(vlan->lowerdev, in macvlan_device_event()
1796 vlan->dev); in macvlan_device_event()
1799 list_for_each_entry(vlan, &port->vlans, list) { in macvlan_device_event()
1800 netif_inherit_tso_max(vlan->dev, dev); in macvlan_device_event()
1801 netdev_update_features(vlan->dev); in macvlan_device_event()
1805 list_for_each_entry(vlan, &port->vlans, list) { in macvlan_device_event()
1806 if (vlan->dev->mtu <= dev->mtu) in macvlan_device_event()
1808 dev_set_mtu(vlan->dev, dev->mtu); in macvlan_device_event()
1815 vlan = list_first_entry_or_null(&port->vlans, in macvlan_device_event()
1819 if (vlan && macvlan_sync_address(vlan->dev, dev->dev_addr)) in macvlan_device_event()
1825 if (dev->reg_state != NETREG_UNREGISTERING) in macvlan_device_event()
1828 list_for_each_entry_safe(vlan, next, &port->vlans, list) in macvlan_device_event()
1829 vlan->dev->rtnl_link_ops->dellink(vlan->dev, &list_kill); in macvlan_device_event()
1840 list_for_each_entry(vlan, &port->vlans, list) in macvlan_device_event()
1841 call_netdevice_notifiers(event, vlan->dev); in macvlan_device_event()