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 * ---
60 unsigned char addr[6+2] __aligned(sizeof(u16));
68 #define MACVLAN_SKB_CB(__skb) ((struct macvlan_skb_cb *)&((__skb)->cb[0]))
75 return port->flags & MACVLAN_F_PASSTHRU; in macvlan_passthru()
80 port->flags |= MACVLAN_F_PASSTHRU; in macvlan_set_passthru()
85 return port->flags & MACVLAN_F_ADDRCHANGE; in macvlan_addr_change()
90 port->flags |= MACVLAN_F_ADDRCHANGE; in macvlan_set_addr_change()
95 port->flags &= ~MACVLAN_F_ADDRCHANGE; in macvlan_clear_addr_change()
99 static u32 macvlan_eth_hash(const unsigned char *addr) in macvlan_eth_hash() argument
101 u64 value = get_unaligned((u64 *)addr); in macvlan_eth_hash()
114 return rcu_dereference(dev->rx_handler_data); in macvlan_port_get_rcu()
119 return rtnl_dereference(dev->rx_handler_data); in macvlan_port_get_rtnl()
123 const unsigned char *addr) in macvlan_hash_lookup() argument
126 u32 idx = macvlan_eth_hash(addr); in macvlan_hash_lookup()
128 hlist_for_each_entry_rcu(vlan, &port->vlan_hash[idx], hlist, in macvlan_hash_lookup()
130 if (ether_addr_equal_64bits(vlan->dev->dev_addr, addr)) in macvlan_hash_lookup()
138 const unsigned char *addr) in macvlan_hash_lookup_source() argument
141 u32 idx = macvlan_eth_hash(addr); in macvlan_hash_lookup_source()
142 struct hlist_head *h = &vlan->port->vlan_source_hash[idx]; in macvlan_hash_lookup_source()
145 if (ether_addr_equal_64bits(entry->addr, addr) && in macvlan_hash_lookup_source()
146 entry->vlan == vlan) in macvlan_hash_lookup_source()
153 const unsigned char *addr) in macvlan_hash_add_source() argument
155 struct macvlan_port *port = vlan->port; in macvlan_hash_add_source()
159 entry = macvlan_hash_lookup_source(vlan, addr); in macvlan_hash_add_source()
165 return -ENOMEM; in macvlan_hash_add_source()
167 ether_addr_copy(entry->addr, addr); in macvlan_hash_add_source()
168 entry->vlan = vlan; in macvlan_hash_add_source()
169 h = &port->vlan_source_hash[macvlan_eth_hash(addr)]; in macvlan_hash_add_source()
170 hlist_add_head_rcu(&entry->hlist, h); in macvlan_hash_add_source()
171 vlan->macaddr_count++; in macvlan_hash_add_source()
178 struct macvlan_port *port = vlan->port; in macvlan_hash_add()
179 const unsigned char *addr = vlan->dev->dev_addr; in macvlan_hash_add() local
180 u32 idx = macvlan_eth_hash(addr); in macvlan_hash_add()
182 hlist_add_head_rcu(&vlan->hlist, &port->vlan_hash[idx]); in macvlan_hash_add()
187 hlist_del_rcu(&entry->hlist); in macvlan_hash_del_source()
193 hlist_del_rcu(&vlan->hlist); in macvlan_hash_del()
199 const unsigned char *addr) in macvlan_hash_change_addr() argument
205 eth_hw_addr_set(vlan->dev, addr); in macvlan_hash_change_addr()
210 const unsigned char *addr) in macvlan_addr_busy() argument
217 ether_addr_equal_64bits(port->dev->dev_addr, addr)) in macvlan_addr_busy()
220 if (macvlan_hash_lookup(port, addr)) in macvlan_addr_busy()
231 struct net_device *dev = vlan->dev; in macvlan_broadcast_one()
236 skb->dev = dev; in macvlan_broadcast_one()
237 if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast)) in macvlan_broadcast_one()
238 skb->pkt_type = PACKET_BROADCAST; in macvlan_broadcast_one()
240 skb->pkt_type = PACKET_MULTICAST; in macvlan_broadcast_one()
252 const unsigned char *addr) in mc_hash() argument
254 u32 val = __get_unaligned_cpu32(addr + 2); in mc_hash()
263 enum macvlan_mode mode) in macvlan_broadcast() argument
272 if (skb->protocol == htons(ETH_P_PAUSE)) in macvlan_broadcast()
275 hash_for_each_rcu(port->vlan_hash, i, vlan, hlist) { in macvlan_broadcast()
276 if (vlan->dev == src || !(vlan->mode & mode)) in macvlan_broadcast()
279 hash = mc_hash(vlan, eth->h_dest); in macvlan_broadcast()
280 if (!test_bit(hash, vlan->mc_filter)) in macvlan_broadcast()
287 mode == MACVLAN_MODE_BRIDGE) ?: in macvlan_broadcast()
289 macvlan_count_rx(vlan, skb->len + ETH_HLEN, in macvlan_broadcast()
303 spin_lock_bh(&port->bc_queue.lock); in macvlan_process_broadcast()
304 skb_queue_splice_tail_init(&port->bc_queue, &list); in macvlan_process_broadcast()
305 spin_unlock_bh(&port->bc_queue.lock); in macvlan_process_broadcast()
308 const struct macvlan_dev *src = MACVLAN_SKB_CB(skb)->src; in macvlan_process_broadcast()
319 else if (src->mode == MACVLAN_MODE_VEPA) in macvlan_process_broadcast()
321 macvlan_broadcast(skb, port, src->dev, in macvlan_process_broadcast()
329 macvlan_broadcast(skb, port, src->dev, in macvlan_process_broadcast()
335 dev_put(src->dev); in macvlan_process_broadcast()
347 int err = -ENOMEM; in macvlan_broadcast_enqueue()
353 MACVLAN_SKB_CB(nskb)->src = src; in macvlan_broadcast_enqueue()
355 spin_lock(&port->bc_queue.lock); in macvlan_broadcast_enqueue()
356 if (skb_queue_len(&port->bc_queue) < port->bc_queue_len_used) { in macvlan_broadcast_enqueue()
358 dev_hold(src->dev); in macvlan_broadcast_enqueue()
359 __skb_queue_tail(&port->bc_queue, nskb); in macvlan_broadcast_enqueue()
362 spin_unlock(&port->bc_queue.lock); in macvlan_broadcast_enqueue()
364 queue_work(system_unbound_wq, &port->bc_work); in macvlan_broadcast_enqueue()
374 dev_core_stats_rx_dropped_inc(skb->dev); in macvlan_broadcast_enqueue()
384 hash_for_each_safe(port->vlan_source_hash, i, next, entry, hlist) in macvlan_flush_sources()
385 if (entry->vlan == vlan) in macvlan_flush_sources()
388 vlan->macaddr_count = 0; in macvlan_flush_sources()
399 dev = vlan->dev; in macvlan_forward_source_one()
400 if (unlikely(!(dev->flags & IFF_UP))) in macvlan_forward_source_one()
407 len = nskb->len + ETH_HLEN; in macvlan_forward_source_one()
408 nskb->dev = dev; in macvlan_forward_source_one()
410 if (ether_addr_equal_64bits(eth_hdr(skb)->h_dest, dev->dev_addr)) in macvlan_forward_source_one()
411 nskb->pkt_type = PACKET_HOST; in macvlan_forward_source_one()
419 const unsigned char *addr) in macvlan_forward_source() argument
422 u32 idx = macvlan_eth_hash(addr); in macvlan_forward_source()
423 struct hlist_head *h = &port->vlan_source_hash[idx]; in macvlan_forward_source()
427 if (ether_addr_equal_64bits(entry->addr, addr)) { in macvlan_forward_source()
428 if (entry->vlan->flags & MACVLAN_FLAG_NODST) in macvlan_forward_source()
430 macvlan_forward_source_one(skb, entry->vlan); in macvlan_forward_source()
451 if (unlikely(skb->pkt_type == PACKET_LOOPBACK)) in macvlan_handle_frame()
454 port = macvlan_port_get_rcu(skb->dev); in macvlan_handle_frame()
455 if (is_multicast_ether_addr(eth->h_dest)) { in macvlan_handle_frame()
458 skb = ip_check_defrag(dev_net(skb->dev), skb, IP_DEFRAG_MACVLAN); in macvlan_handle_frame()
463 if (macvlan_forward_source(skb, port, eth->h_source)) { in macvlan_handle_frame()
467 src = macvlan_hash_lookup(port, eth->h_source); in macvlan_handle_frame()
468 if (src && src->mode != MACVLAN_MODE_VEPA && in macvlan_handle_frame()
469 src->mode != MACVLAN_MODE_BRIDGE) { in macvlan_handle_frame()
478 hash = mc_hash(NULL, eth->h_dest); in macvlan_handle_frame()
479 if (test_bit(hash, port->mc_filter)) in macvlan_handle_frame()
485 if (macvlan_forward_source(skb, port, eth->h_source)) { in macvlan_handle_frame()
490 vlan = list_first_or_null_rcu(&port->vlans, in macvlan_handle_frame()
493 vlan = macvlan_hash_lookup(port, eth->h_dest); in macvlan_handle_frame()
494 if (!vlan || vlan->mode == MACVLAN_MODE_SOURCE) in macvlan_handle_frame()
497 dev = vlan->dev; in macvlan_handle_frame()
498 if (unlikely(!(dev->flags & IFF_UP))) { in macvlan_handle_frame()
502 len = skb->len + ETH_HLEN; in macvlan_handle_frame()
511 skb->dev = dev; in macvlan_handle_frame()
512 skb->pkt_type = PACKET_HOST; in macvlan_handle_frame()
524 const struct macvlan_port *port = vlan->port; in macvlan_queue_xmit()
527 if (vlan->mode == MACVLAN_MODE_BRIDGE) { in macvlan_queue_xmit()
531 if (is_multicast_ether_addr(eth->h_dest)) { in macvlan_queue_xmit()
537 dest = macvlan_hash_lookup(port, eth->h_dest); in macvlan_queue_xmit()
538 if (dest && dest->mode == MACVLAN_MODE_BRIDGE) { in macvlan_queue_xmit()
540 dev_forward_skb(vlan->lowerdev, skb); in macvlan_queue_xmit()
546 skb->dev = vlan->lowerdev; in macvlan_queue_xmit()
554 return netpoll_send_skb(vlan->netpoll, skb); in macvlan_netpoll_send_skb()
565 unsigned int len = skb->len; in macvlan_start_xmit()
576 pcpu_stats = this_cpu_ptr(vlan->pcpu_stats); in macvlan_start_xmit()
577 u64_stats_update_begin(&pcpu_stats->syncp); in macvlan_start_xmit()
578 u64_stats_inc(&pcpu_stats->tx_packets); in macvlan_start_xmit()
579 u64_stats_add(&pcpu_stats->tx_bytes, len); in macvlan_start_xmit()
580 u64_stats_update_end(&pcpu_stats->syncp); in macvlan_start_xmit()
582 this_cpu_inc(vlan->pcpu_stats->tx_dropped); in macvlan_start_xmit()
592 struct net_device *lowerdev = vlan->lowerdev; in macvlan_hard_header()
595 saddr ? : dev->dev_addr, len); in macvlan_hard_header()
608 struct net_device *lowerdev = vlan->lowerdev; in macvlan_open()
611 if (macvlan_passthru(vlan->port)) { in macvlan_open()
612 if (!(vlan->flags & MACVLAN_FLAG_NOPROMISC)) { in macvlan_open()
620 err = -EADDRINUSE; in macvlan_open()
621 if (macvlan_addr_busy(vlan->port, dev->dev_addr)) in macvlan_open()
627 if (lowerdev->features & NETIF_F_HW_L2FW_DOFFLOAD) in macvlan_open()
628 vlan->accel_priv = in macvlan_open()
629 lowerdev->netdev_ops->ndo_dfwd_add_station(lowerdev, dev); in macvlan_open()
634 if (IS_ERR_OR_NULL(vlan->accel_priv)) { in macvlan_open()
635 vlan->accel_priv = NULL; in macvlan_open()
636 err = dev_uc_add(lowerdev, dev->dev_addr); in macvlan_open()
641 if (dev->flags & IFF_ALLMULTI) { in macvlan_open()
647 if (dev->flags & IFF_PROMISC) { in macvlan_open()
658 if (dev->flags & IFF_ALLMULTI) in macvlan_open()
659 dev_set_allmulti(lowerdev, -1); in macvlan_open()
661 if (vlan->accel_priv) { in macvlan_open()
662 lowerdev->netdev_ops->ndo_dfwd_del_station(lowerdev, in macvlan_open()
663 vlan->accel_priv); in macvlan_open()
664 vlan->accel_priv = NULL; in macvlan_open()
666 dev_uc_del(lowerdev, dev->dev_addr); in macvlan_open()
675 struct net_device *lowerdev = vlan->lowerdev; in macvlan_stop()
677 if (vlan->accel_priv) { in macvlan_stop()
678 lowerdev->netdev_ops->ndo_dfwd_del_station(lowerdev, in macvlan_stop()
679 vlan->accel_priv); in macvlan_stop()
680 vlan->accel_priv = NULL; in macvlan_stop()
686 if (macvlan_passthru(vlan->port)) { in macvlan_stop()
687 if (!(vlan->flags & MACVLAN_FLAG_NOPROMISC)) in macvlan_stop()
688 dev_set_promiscuity(lowerdev, -1); in macvlan_stop()
692 if (dev->flags & IFF_ALLMULTI) in macvlan_stop()
693 dev_set_allmulti(lowerdev, -1); in macvlan_stop()
695 if (dev->flags & IFF_PROMISC) in macvlan_stop()
696 dev_set_promiscuity(lowerdev, -1); in macvlan_stop()
698 dev_uc_del(lowerdev, dev->dev_addr); in macvlan_stop()
701 macvlan_hash_del(vlan, !dev->dismantle); in macvlan_stop()
706 const unsigned char *addr) in macvlan_sync_address() argument
709 struct net_device *lowerdev = vlan->lowerdev; in macvlan_sync_address()
710 struct macvlan_port *port = vlan->port; in macvlan_sync_address()
713 if (!(dev->flags & IFF_UP)) { in macvlan_sync_address()
715 eth_hw_addr_set(dev, addr); in macvlan_sync_address()
718 if (macvlan_addr_busy(vlan->port, addr)) in macvlan_sync_address()
719 return -EADDRINUSE; in macvlan_sync_address()
722 err = dev_uc_add(lowerdev, addr); in macvlan_sync_address()
726 dev_uc_del(lowerdev, dev->dev_addr); in macvlan_sync_address()
729 macvlan_hash_change_addr(vlan, addr); in macvlan_sync_address()
733 * device change. Save the lower-dev address so we can in macvlan_sync_address()
736 ether_addr_copy(vlan->port->perm_addr, in macvlan_sync_address()
737 lowerdev->dev_addr); in macvlan_sync_address()
746 struct sockaddr *addr = p; in macvlan_set_mac_address() local
748 if (!is_valid_ether_addr(addr->sa_data)) in macvlan_set_mac_address()
749 return -EADDRNOTAVAIL; in macvlan_set_mac_address()
751 /* If the addresses are the same, this is a no-op */ in macvlan_set_mac_address()
752 if (ether_addr_equal(dev->dev_addr, addr->sa_data)) in macvlan_set_mac_address()
755 if (vlan->mode == MACVLAN_MODE_PASSTHRU) { in macvlan_set_mac_address()
756 macvlan_set_addr_change(vlan->port); in macvlan_set_mac_address()
757 return dev_set_mac_address(vlan->lowerdev, addr, NULL); in macvlan_set_mac_address()
760 if (macvlan_addr_busy(vlan->port, addr->sa_data)) in macvlan_set_mac_address()
761 return -EADDRINUSE; in macvlan_set_mac_address()
763 return macvlan_sync_address(dev, addr->sa_data); in macvlan_set_mac_address()
769 struct net_device *lowerdev = vlan->lowerdev; in macvlan_change_rx_flags()
771 if (dev->flags & IFF_UP) { in macvlan_change_rx_flags()
773 dev_set_allmulti(lowerdev, dev->flags & IFF_ALLMULTI ? 1 : -1); in macvlan_change_rx_flags()
776 dev->flags & IFF_PROMISC ? 1 : -1); in macvlan_change_rx_flags()
785 if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) { in macvlan_compute_filter()
793 __set_bit(mc_hash(vlan, ha->addr), filter); in macvlan_compute_filter()
796 __set_bit(mc_hash(vlan, dev->broadcast), filter); in macvlan_compute_filter()
806 macvlan_compute_filter(vlan->mc_filter, dev, vlan); in macvlan_set_mac_lists()
808 dev_uc_sync(vlan->lowerdev, dev); in macvlan_set_mac_lists()
809 dev_mc_sync(vlan->lowerdev, dev); in macvlan_set_mac_lists()
812 * list of vlan->lowerdev too. in macvlan_set_mac_lists()
824 macvlan_compute_filter(vlan->port->mc_filter, vlan->lowerdev, NULL); in macvlan_set_mac_lists()
831 if (vlan->lowerdev->mtu < new_mtu) in macvlan_change_mtu()
832 return -EINVAL; in macvlan_change_mtu()
833 dev->mtu = new_mtu; in macvlan_change_mtu()
840 const struct net_device_ops *ops = real_dev->netdev_ops; in macvlan_eth_ioctl()
842 int err = -EOPNOTSUPP; in macvlan_eth_ioctl()
844 strscpy(ifrr.ifr_name, real_dev->name, IFNAMSIZ); in macvlan_eth_ioctl()
845 ifrr.ifr_ifru = ifr->ifr_ifru; in macvlan_eth_ioctl()
853 if (netif_device_present(real_dev) && ops->ndo_eth_ioctl) in macvlan_eth_ioctl()
854 err = ops->ndo_eth_ioctl(real_dev, &ifrr, cmd); in macvlan_eth_ioctl()
859 ifr->ifr_ifru = ifrr.ifr_ifru; in macvlan_eth_ioctl()
889 lockdep_set_class(&dev->addr_list_lock, in macvlan_set_lockdep_class()
896 struct net_device *lowerdev = vlan->lowerdev; in macvlan_init()
897 struct macvlan_port *port = vlan->port; in macvlan_init()
899 dev->state = (dev->state & ~MACVLAN_STATE_MASK) | in macvlan_init()
900 (lowerdev->state & MACVLAN_STATE_MASK); in macvlan_init()
901 dev->features = lowerdev->features & MACVLAN_FEATURES; in macvlan_init()
902 dev->features |= ALWAYS_ON_FEATURES; in macvlan_init()
903 dev->hw_features |= NETIF_F_LRO; in macvlan_init()
904 dev->vlan_features = lowerdev->vlan_features & MACVLAN_FEATURES; in macvlan_init()
905 dev->vlan_features |= ALWAYS_ON_OFFLOADS; in macvlan_init()
906 dev->hw_enc_features |= dev->features; in macvlan_init()
908 dev->hard_header_len = lowerdev->hard_header_len; in macvlan_init()
911 vlan->pcpu_stats = netdev_alloc_pcpu_stats(struct vlan_pcpu_stats); in macvlan_init()
912 if (!vlan->pcpu_stats) in macvlan_init()
913 return -ENOMEM; in macvlan_init()
915 port->count += 1; in macvlan_init()
918 netdev_hold(lowerdev, &vlan->dev_tracker, GFP_KERNEL); in macvlan_init()
926 struct macvlan_port *port = vlan->port; in macvlan_uninit()
928 free_percpu(vlan->pcpu_stats); in macvlan_uninit()
931 port->count -= 1; in macvlan_uninit()
932 if (!port->count) in macvlan_uninit()
933 macvlan_port_destroy(port->dev); in macvlan_uninit()
941 if (vlan->pcpu_stats) { in macvlan_dev_get_stats64()
949 p = per_cpu_ptr(vlan->pcpu_stats, i); in macvlan_dev_get_stats64()
951 start = u64_stats_fetch_begin_irq(&p->syncp); in macvlan_dev_get_stats64()
952 rx_packets = u64_stats_read(&p->rx_packets); in macvlan_dev_get_stats64()
953 rx_bytes = u64_stats_read(&p->rx_bytes); in macvlan_dev_get_stats64()
954 rx_multicast = u64_stats_read(&p->rx_multicast); in macvlan_dev_get_stats64()
955 tx_packets = u64_stats_read(&p->tx_packets); in macvlan_dev_get_stats64()
956 tx_bytes = u64_stats_read(&p->tx_bytes); in macvlan_dev_get_stats64()
957 } while (u64_stats_fetch_retry_irq(&p->syncp, start)); in macvlan_dev_get_stats64()
959 stats->rx_packets += rx_packets; in macvlan_dev_get_stats64()
960 stats->rx_bytes += rx_bytes; in macvlan_dev_get_stats64()
961 stats->multicast += rx_multicast; in macvlan_dev_get_stats64()
962 stats->tx_packets += tx_packets; in macvlan_dev_get_stats64()
963 stats->tx_bytes += tx_bytes; in macvlan_dev_get_stats64()
967 rx_errors += READ_ONCE(p->rx_errors); in macvlan_dev_get_stats64()
968 tx_dropped += READ_ONCE(p->tx_dropped); in macvlan_dev_get_stats64()
970 stats->rx_errors = rx_errors; in macvlan_dev_get_stats64()
971 stats->rx_dropped = rx_errors; in macvlan_dev_get_stats64()
972 stats->tx_dropped = tx_dropped; in macvlan_dev_get_stats64()
980 struct net_device *lowerdev = vlan->lowerdev; in macvlan_vlan_rx_add_vid()
989 struct net_device *lowerdev = vlan->lowerdev; in macvlan_vlan_rx_kill_vid()
997 const unsigned char *addr, u16 vid, in macvlan_fdb_add() argument
1002 int err = -EINVAL; in macvlan_fdb_add()
1007 if (!macvlan_passthru(vlan->port) && is_unicast_ether_addr(addr)) in macvlan_fdb_add()
1008 return -EOPNOTSUPP; in macvlan_fdb_add()
1011 return -EOPNOTSUPP; in macvlan_fdb_add()
1013 if (is_unicast_ether_addr(addr)) in macvlan_fdb_add()
1014 err = dev_uc_add_excl(dev, addr); in macvlan_fdb_add()
1015 else if (is_multicast_ether_addr(addr)) in macvlan_fdb_add()
1016 err = dev_mc_add_excl(dev, addr); in macvlan_fdb_add()
1023 const unsigned char *addr, u16 vid, in macvlan_fdb_del() argument
1027 int err = -EINVAL; in macvlan_fdb_del()
1032 if (!macvlan_passthru(vlan->port) && is_unicast_ether_addr(addr)) in macvlan_fdb_del()
1033 return -EOPNOTSUPP; in macvlan_fdb_del()
1035 if (is_unicast_ether_addr(addr)) in macvlan_fdb_del()
1036 err = dev_uc_del(dev, addr); in macvlan_fdb_del()
1037 else if (is_multicast_ether_addr(addr)) in macvlan_fdb_del()
1038 err = dev_mc_del(dev, addr); in macvlan_fdb_del()
1046 strscpy(drvinfo->driver, "macvlan", sizeof(drvinfo->driver)); in macvlan_ethtool_get_drvinfo()
1047 strscpy(drvinfo->version, "0.1", sizeof(drvinfo->version)); in macvlan_ethtool_get_drvinfo()
1055 return __ethtool_get_link_ksettings(vlan->lowerdev, cmd); in macvlan_ethtool_get_link_ksettings()
1062 const struct ethtool_ops *ops = real_dev->ethtool_ops; in macvlan_ethtool_get_ts_info()
1063 struct phy_device *phydev = real_dev->phydev; in macvlan_ethtool_get_ts_info()
1067 } else if (ops->get_ts_info) { in macvlan_ethtool_get_ts_info()
1068 return ops->get_ts_info(real_dev, info); in macvlan_ethtool_get_ts_info()
1070 info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE | in macvlan_ethtool_get_ts_info()
1072 info->phc_index = -1; in macvlan_ethtool_get_ts_info()
1082 netdev_features_t lowerdev_features = vlan->lowerdev->features; in macvlan_fix_features()
1086 features &= (vlan->set_features | ~MACVLAN_FEATURES); in macvlan_fix_features()
1106 struct net_device *real_dev = vlan->lowerdev; in macvlan_dev_netpoll_setup()
1111 err = -ENOMEM; in macvlan_dev_netpoll_setup()
1121 vlan->netpoll = netpoll; in macvlan_dev_netpoll_setup()
1130 struct netpoll *netpoll = vlan->netpoll; in macvlan_dev_netpoll_cleanup()
1135 vlan->netpoll = NULL; in macvlan_dev_netpoll_cleanup()
1145 return vlan->lowerdev->ifindex; in macvlan_dev_get_iflink()
1188 netdev_put(vlan->lowerdev, &vlan->dev_tracker); in macvlan_dev_free()
1195 /* ether_setup() has set dev->min_mtu to ETH_MIN_MTU. */ in macvlan_common_setup()
1196 dev->max_mtu = ETH_MAX_MTU; in macvlan_common_setup()
1197 dev->priv_flags &= ~IFF_TX_SKB_SHARING; in macvlan_common_setup()
1199 dev->priv_flags |= IFF_UNICAST_FLT | IFF_CHANGE_PROTO_DOWN; in macvlan_common_setup()
1200 dev->netdev_ops = &macvlan_netdev_ops; in macvlan_common_setup()
1201 dev->needs_free_netdev = true; in macvlan_common_setup()
1202 dev->priv_destructor = macvlan_dev_free; in macvlan_common_setup()
1203 dev->header_ops = &macvlan_hard_header_ops; in macvlan_common_setup()
1204 dev->ethtool_ops = &macvlan_ethtool_ops; in macvlan_common_setup()
1211 dev->priv_flags |= IFF_NO_QUEUE; in macvlan_setup()
1220 if (dev->type != ARPHRD_ETHER || dev->flags & IFF_LOOPBACK) in macvlan_port_create()
1221 return -EINVAL; in macvlan_port_create()
1224 return -EBUSY; in macvlan_port_create()
1228 return -ENOMEM; in macvlan_port_create()
1230 port->dev = dev; in macvlan_port_create()
1231 ether_addr_copy(port->perm_addr, dev->dev_addr); in macvlan_port_create()
1232 INIT_LIST_HEAD(&port->vlans); in macvlan_port_create()
1234 INIT_HLIST_HEAD(&port->vlan_hash[i]); in macvlan_port_create()
1236 INIT_HLIST_HEAD(&port->vlan_source_hash[i]); in macvlan_port_create()
1238 port->bc_queue_len_used = 0; in macvlan_port_create()
1239 skb_queue_head_init(&port->bc_queue); in macvlan_port_create()
1240 INIT_WORK(&port->bc_work, macvlan_process_broadcast); in macvlan_port_create()
1246 dev->priv_flags |= IFF_MACVLAN_PORT; in macvlan_port_create()
1255 dev->priv_flags &= ~IFF_MACVLAN_PORT; in macvlan_port_destroy()
1261 cancel_work_sync(&port->bc_work); in macvlan_port_destroy()
1263 while ((skb = __skb_dequeue(&port->bc_queue))) { in macvlan_port_destroy()
1264 const struct macvlan_dev *src = MACVLAN_SKB_CB(skb)->src; in macvlan_port_destroy()
1267 dev_put(src->dev); in macvlan_port_destroy()
1276 !ether_addr_equal(port->dev->dev_addr, port->perm_addr)) { in macvlan_port_destroy()
1279 sa.sa_family = port->dev->type; in macvlan_port_destroy()
1280 memcpy(&sa.sa_data, port->perm_addr, port->dev->addr_len); in macvlan_port_destroy()
1281 dev_set_mac_address(port->dev, &sa, NULL); in macvlan_port_destroy()
1295 return -EINVAL; in macvlan_validate()
1297 return -EADDRNOTAVAIL; in macvlan_validate()
1306 return -EINVAL; in macvlan_validate()
1317 return -EINVAL; in macvlan_validate()
1329 return -EINVAL; in macvlan_validate()
1335 return -EINVAL; in macvlan_validate()
1338 return -EADDRNOTAVAIL; in macvlan_validate()
1348 return -EINVAL; in macvlan_validate()
1351 return -EADDRNOTAVAIL; in macvlan_validate()
1356 return -EINVAL; in macvlan_validate()
1363 * (only for macvlan devices in source mode)
1367 static int macvlan_changelink_sources(struct macvlan_dev *vlan, u32 mode, in macvlan_changelink_sources() argument
1370 char *addr = NULL; in macvlan_changelink_sources() local
1376 addr = nla_data(data[IFLA_MACVLAN_MACADDR]); in macvlan_changelink_sources()
1378 if (mode == MACVLAN_MACADDR_ADD) { in macvlan_changelink_sources()
1379 if (!addr) in macvlan_changelink_sources()
1380 return -EINVAL; in macvlan_changelink_sources()
1382 return macvlan_hash_add_source(vlan, addr); in macvlan_changelink_sources()
1384 } else if (mode == MACVLAN_MACADDR_DEL) { in macvlan_changelink_sources()
1385 if (!addr) in macvlan_changelink_sources()
1386 return -EINVAL; in macvlan_changelink_sources()
1388 entry = macvlan_hash_lookup_source(vlan, addr); in macvlan_changelink_sources()
1391 vlan->macaddr_count--; in macvlan_changelink_sources()
1393 } else if (mode == MACVLAN_MACADDR_FLUSH) { in macvlan_changelink_sources()
1394 macvlan_flush_sources(vlan->port, vlan); in macvlan_changelink_sources()
1395 } else if (mode == MACVLAN_MACADDR_SET) { in macvlan_changelink_sources()
1396 macvlan_flush_sources(vlan->port, vlan); in macvlan_changelink_sources()
1398 if (addr) { in macvlan_changelink_sources()
1399 ret = macvlan_hash_add_source(vlan, addr); in macvlan_changelink_sources()
1411 addr = nla_data(nla); in macvlan_changelink_sources()
1412 ret = macvlan_hash_add_source(vlan, addr); in macvlan_changelink_sources()
1417 return -EINVAL; in macvlan_changelink_sources()
1435 return -EINVAL; in macvlan_common_newlink()
1439 return -ENODEV; in macvlan_common_newlink()
1441 /* When creating macvlans or macvtaps on top of other macvlans - use in macvlan_common_newlink()
1448 dev->mtu = lowerdev->mtu; in macvlan_common_newlink()
1449 else if (dev->mtu > lowerdev->mtu) in macvlan_common_newlink()
1450 return -EINVAL; in macvlan_common_newlink()
1452 /* MTU range: 68 - lowerdev->max_mtu */ in macvlan_common_newlink()
1453 dev->min_mtu = ETH_MIN_MTU; in macvlan_common_newlink()
1454 dev->max_mtu = lowerdev->max_mtu; in macvlan_common_newlink()
1467 /* Only 1 macvlan device can be created in passthru mode */ in macvlan_common_newlink()
1472 err = -EINVAL; in macvlan_common_newlink()
1476 vlan->lowerdev = lowerdev; in macvlan_common_newlink()
1477 vlan->dev = dev; in macvlan_common_newlink()
1478 vlan->port = port; in macvlan_common_newlink()
1479 vlan->set_features = MACVLAN_FEATURES; in macvlan_common_newlink()
1481 vlan->mode = MACVLAN_MODE_VEPA; in macvlan_common_newlink()
1483 vlan->mode = nla_get_u32(data[IFLA_MACVLAN_MODE]); in macvlan_common_newlink()
1486 vlan->flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]); in macvlan_common_newlink()
1488 if (vlan->mode == MACVLAN_MODE_PASSTHRU) { in macvlan_common_newlink()
1489 if (port->count) { in macvlan_common_newlink()
1490 err = -EINVAL; in macvlan_common_newlink()
1498 if (vlan->mode != MACVLAN_MODE_SOURCE) { in macvlan_common_newlink()
1499 err = -EINVAL; in macvlan_common_newlink()
1508 vlan->bc_queue_len_req = MACVLAN_DEFAULT_BC_QUEUE_LEN; in macvlan_common_newlink()
1510 vlan->bc_queue_len_req = nla_get_u32(data[IFLA_MACVLAN_BC_QUEUE_LEN]); in macvlan_common_newlink()
1516 dev->priv_flags |= IFF_MACVLAN; in macvlan_common_newlink()
1521 list_add_tail_rcu(&vlan->list, &port->vlans); in macvlan_common_newlink()
1522 update_port_bc_queue_len(vlan->port); in macvlan_common_newlink()
1538 macvlan_port_destroy(port->dev); in macvlan_common_newlink()
1555 if (vlan->mode == MACVLAN_MODE_SOURCE) in macvlan_dellink()
1556 macvlan_flush_sources(vlan->port, vlan); in macvlan_dellink()
1557 list_del_rcu(&vlan->list); in macvlan_dellink()
1558 update_port_bc_queue_len(vlan->port); in macvlan_dellink()
1560 netdev_upper_dev_unlink(vlan->lowerdev, dev); in macvlan_dellink()
1569 enum macvlan_mode mode; in macvlan_changelink() local
1574 /* Validate mode, but don't set yet: setting flags may fail. */ in macvlan_changelink()
1577 mode = nla_get_u32(data[IFLA_MACVLAN_MODE]); in macvlan_changelink()
1578 /* Passthrough mode can't be set or cleared dynamically */ in macvlan_changelink()
1579 if ((mode == MACVLAN_MODE_PASSTHRU) != in macvlan_changelink()
1580 (vlan->mode == MACVLAN_MODE_PASSTHRU)) in macvlan_changelink()
1581 return -EINVAL; in macvlan_changelink()
1582 if (vlan->mode == MACVLAN_MODE_SOURCE && in macvlan_changelink()
1583 vlan->mode != mode) in macvlan_changelink()
1584 macvlan_flush_sources(vlan->port, vlan); in macvlan_changelink()
1589 bool promisc = (flags ^ vlan->flags) & MACVLAN_FLAG_NOPROMISC; in macvlan_changelink()
1590 if (macvlan_passthru(vlan->port) && promisc) { in macvlan_changelink()
1594 err = dev_set_promiscuity(vlan->lowerdev, -1); in macvlan_changelink()
1596 err = dev_set_promiscuity(vlan->lowerdev, 1); in macvlan_changelink()
1600 vlan->flags = flags; in macvlan_changelink()
1604 vlan->bc_queue_len_req = nla_get_u32(data[IFLA_MACVLAN_BC_QUEUE_LEN]); in macvlan_changelink()
1605 update_port_bc_queue_len(vlan->port); in macvlan_changelink()
1609 vlan->mode = mode; in macvlan_changelink()
1611 if (vlan->mode != MACVLAN_MODE_SOURCE) in macvlan_changelink()
1612 return -EINVAL; in macvlan_changelink()
1623 if (vlan->macaddr_count == 0) in macvlan_get_size_mac()
1626 + vlan->macaddr_count * nla_total_size(sizeof(u8) * ETH_ALEN); in macvlan_get_size_mac()
1647 struct hlist_head *h = &vlan->port->vlan_source_hash[i]; in macvlan_fill_info_macaddr()
1651 if (entry->vlan != vlan) in macvlan_fill_info_macaddr()
1653 if (nla_put(skb, IFLA_MACVLAN_MACADDR, ETH_ALEN, entry->addr)) in macvlan_fill_info_macaddr()
1663 struct macvlan_port *port = vlan->port; in macvlan_fill_info()
1667 if (nla_put_u32(skb, IFLA_MACVLAN_MODE, vlan->mode)) in macvlan_fill_info()
1669 if (nla_put_u16(skb, IFLA_MACVLAN_FLAGS, vlan->flags)) in macvlan_fill_info()
1671 if (nla_put_u32(skb, IFLA_MACVLAN_MACADDR_COUNT, vlan->macaddr_count)) in macvlan_fill_info()
1673 if (vlan->macaddr_count > 0) { in macvlan_fill_info()
1684 if (nla_put_u32(skb, IFLA_MACVLAN_BC_QUEUE_LEN, vlan->bc_queue_len_req)) in macvlan_fill_info()
1686 if (nla_put_u32(skb, IFLA_MACVLAN_BC_QUEUE_LEN_USED, port->bc_queue_len_used)) in macvlan_fill_info()
1691 return -EMSGSIZE; in macvlan_fill_info()
1708 ops->validate = macvlan_validate; in macvlan_link_register()
1709 ops->maxtype = IFLA_MACVLAN_MAX; in macvlan_link_register()
1710 ops->policy = macvlan_policy; in macvlan_link_register()
1711 ops->changelink = macvlan_changelink; in macvlan_link_register()
1712 ops->get_size = macvlan_get_size; in macvlan_link_register()
1713 ops->fill_info = macvlan_fill_info; in macvlan_link_register()
1738 list_for_each_entry(vlan, &port->vlans, list) { in update_port_bc_queue_len()
1739 if (vlan->bc_queue_len_req > max_bc_queue_len_req) in update_port_bc_queue_len()
1740 max_bc_queue_len_req = vlan->bc_queue_len_req; in update_port_bc_queue_len()
1742 port->bc_queue_len_used = max_bc_queue_len_req; in update_port_bc_queue_len()
1762 list_for_each_entry(vlan, &port->vlans, list) in macvlan_device_event()
1763 netif_stacked_transfer_operstate(vlan->lowerdev, in macvlan_device_event()
1764 vlan->dev); in macvlan_device_event()
1767 list_for_each_entry(vlan, &port->vlans, list) { in macvlan_device_event()
1768 netif_inherit_tso_max(vlan->dev, dev); in macvlan_device_event()
1769 netdev_update_features(vlan->dev); in macvlan_device_event()
1773 list_for_each_entry(vlan, &port->vlans, list) { in macvlan_device_event()
1774 if (vlan->dev->mtu <= dev->mtu) in macvlan_device_event()
1776 dev_set_mtu(vlan->dev, dev->mtu); in macvlan_device_event()
1783 vlan = list_first_entry_or_null(&port->vlans, in macvlan_device_event()
1787 if (vlan && macvlan_sync_address(vlan->dev, dev->dev_addr)) in macvlan_device_event()
1793 if (dev->reg_state != NETREG_UNREGISTERING) in macvlan_device_event()
1796 list_for_each_entry_safe(vlan, next, &port->vlans, list) in macvlan_device_event()
1797 vlan->dev->rtnl_link_ops->dellink(vlan->dev, &list_kill); in macvlan_device_event()
1808 list_for_each_entry(vlan, &port->vlans, list) in macvlan_device_event()
1809 call_netdevice_notifiers(event, vlan->dev); in macvlan_device_event()