Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Linux/net/core/   (Open Source Betriebssystem Version 6.17.9©)  Datei vom 24.10.2025 mit Größe 329 kB image not shown  

Quelle  dev.c   Sprache: C

 
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 *      NET3    Protocol independent device support routines.
 *
 * Derived from the non IP parts of dev.c 1.0.19
 *              Authors: Ross Biro
 * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
 * Mark Evans, <evansmp@uhura.aston.ac.uk>
 *
 * Additional Authors:
 * Florian la Roche <rzsfl@rz.uni-sb.de>
 * Alan Cox <gw4pts@gw4pts.ampr.org>
 * David Hinds <dahinds@users.sourceforge.net>
 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
 * Adam Sulmicki <adam@cfar.umd.edu>
 *              Pekka Riikonen <priikone@poesidon.pspt.fi>
 *
 * Changes:
 *              D.J. Barrow     :       Fixed bug where dev->refcnt gets set
 *                                      to 2 if register_netdev gets called
 *                                      before net_dev_init & also removed a
 *                                      few lines of code in the process.
 * Alan Cox : device private ioctl copies fields back.
 * Alan Cox : Transmit queue code does relevant
 * stunts to keep the queue safe.
 * Alan Cox : Fixed double lock.
 * Alan Cox : Fixed promisc NULL pointer trap
 * ???????? : Support the full private ioctl range
 * Alan Cox : Moved ioctl permission check into
 * drivers
 * Tim Kordas : SIOCADDMULTI/SIOCDELMULTI
 * Alan Cox : 100 backlog just doesn't cut it when
 * you start doing multicast video 8)
 * Alan Cox : Rewrote net_bh and list manager.
 *              Alan Cox        :       Fix ETH_P_ALL echoback lengths.
 * Alan Cox : Took out transmit every packet pass
 * Saved a few bytes in the ioctl handler
 * Alan Cox : Network driver sets packet type before
 * calling netif_rx. Saves a function
 * call a packet.
 * Alan Cox : Hashed net_bh()
 * Richard Kooijman: Timestamp fixes.
 * Alan Cox : Wrong field in SIOCGIFDSTADDR
 * Alan Cox : Device lock protection.
 *              Alan Cox        :       Fixed nasty side effect of device close
 * changes.
 * Rudi Cilibrasi : Pass the right thing to
 * set_mac_address()
 * Dave Miller : 32bit quantity for the device lock to
 * make it work out on a Sparc.
 * Bjorn Ekwall : Added KERNELD hack.
 * Alan Cox : Cleaned up the backlog initialise.
 * Craig Metz : SIOCGIFCONF fix if space for under
 * 1 device.
 *     Thomas Bogendoerfer : Return ENODEV for dev_open, if there
 * is no device open function.
 * Andi Kleen : Fix error reporting for SIOCGIFCONF
 *     Michael Chastain : Fix signed/unsigned for SIOCGIFCONF
 * Cyrus Durgin : Cleaned for KMOD
 * Adam Sulmicki   : Bug Fix : Network Device Unload
 * A network device unload needs to purge
 * the backlog queue.
 * Paul Rusty Russell : SIOCSIFNAME
 *              Pekka Riikonen  : Netdev boot-time settings code
 *              Andrew Morton   :       Make unregister_netdevice wait
 *                                      indefinitely on dev->refcnt
 *              J Hadi Salim    :       - Backlog queue sampling
 *         - netif_rx() feedback
 */


#include <linux/uaccess.h>
#include <linux/bitmap.h>
#include <linux/capability.h>
#include <linux/cpu.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/hash.h>
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/sched/isolation.h>
#include <linux/sched/mm.h>
#include <linux/smpboot.h>
#include <linux/mutex.h>
#include <linux/rwsem.h>
#include <linux/string.h>
#include <linux/mm.h>
#include <linux/socket.h>
#include <linux/sockios.h>
#include <linux/errno.h>
#include <linux/interrupt.h>
#include <linux/if_ether.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/ethtool.h>
#include <linux/ethtool_netlink.h>
#include <linux/skbuff.h>
#include <linux/kthread.h>
#include <linux/bpf.h>
#include <linux/bpf_trace.h>
#include <net/net_namespace.h>
#include <net/sock.h>
#include <net/busy_poll.h>
#include <linux/rtnetlink.h>
#include <linux/stat.h>
#include <net/dsa.h>
#include <net/dst.h>
#include <net/dst_metadata.h>
#include <net/gro.h>
#include <net/netdev_queues.h>
#include <net/pkt_sched.h>
#include <net/pkt_cls.h>
#include <net/checksum.h>
#include <net/xfrm.h>
#include <net/tcx.h>
#include <linux/highmem.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/netpoll.h>
#include <linux/rcupdate.h>
#include <linux/delay.h>
#include <net/iw_handler.h>
#include <asm/current.h>
#include <linux/audit.h>
#include <linux/dmaengine.h>
#include <linux/err.h>
#include <linux/ctype.h>
#include <linux/if_arp.h>
#include <linux/if_vlan.h>
#include <linux/ip.h>
#include <net/ip.h>
#include <net/mpls.h>
#include <linux/ipv6.h>
#include <linux/in.h>
#include <linux/jhash.h>
#include <linux/random.h>
#include <trace/events/napi.h>
#include <trace/events/net.h>
#include <trace/events/skb.h>
#include <trace/events/qdisc.h>
#include <trace/events/xdp.h>
#include <linux/inetdevice.h>
#include <linux/cpu_rmap.h>
#include <linux/static_key.h>
#include <linux/hashtable.h>
#include <linux/vmalloc.h>
#include <linux/if_macvlan.h>
#include <linux/errqueue.h>
#include <linux/hrtimer.h>
#include <linux/netfilter_netdev.h>
#include <linux/crash_dump.h>
#include <linux/sctp.h>
#include <net/udp_tunnel.h>
#include <linux/net_namespace.h>
#include <linux/indirect_call_wrapper.h>
#include <net/devlink.h>
#include <linux/pm_runtime.h>
#include <linux/prandom.h>
#include <linux/once_lite.h>
#include <net/netdev_lock.h>
#include <net/netdev_rx_queue.h>
#include <net/page_pool/types.h>
#include <net/page_pool/helpers.h>
#include <net/page_pool/memory_provider.h>
#include <net/rps.h>
#include <linux/phy_link_topology.h>

#include "dev.h"
#include "devmem.h"
#include "net-sysfs.h"

static DEFINE_SPINLOCK(ptype_lock);
struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly;

static int netif_rx_internal(struct sk_buff *skb);
static int call_netdevice_notifiers_extack(unsigned long val,
        struct net_device *dev,
        struct netlink_ext_ack *extack);

static DEFINE_MUTEX(ifalias_mutex);

/* protects napi_hash addition/deletion and napi_gen_id */
static DEFINE_SPINLOCK(napi_hash_lock);

static unsigned int napi_gen_id = NR_CPUS;
static DEFINE_READ_MOSTLY_HASHTABLE(napi_hash, 8);

static inline void dev_base_seq_inc(struct net *net)
{
 unsigned int val = net->dev_base_seq + 1;

 WRITE_ONCE(net->dev_base_seq, val ?: 1);
}

static inline struct hlist_head *dev_name_hash(struct net *net, const char *name)
{
 unsigned int hash = full_name_hash(net, name, strnlen(name, IFNAMSIZ));

 return &net->dev_name_head[hash_32(hash, NETDEV_HASHBITS)];
}

static inline struct hlist_head *dev_index_hash(struct net *net, int ifindex)
{
 return &net->dev_index_head[ifindex & (NETDEV_HASHENTRIES - 1)];
}

#ifndef CONFIG_PREEMPT_RT

static DEFINE_STATIC_KEY_FALSE(use_backlog_threads_key);

static int __init setup_backlog_napi_threads(char *arg)
{
 static_branch_enable(&use_backlog_threads_key);
 return 0;
}
early_param("thread_backlog_napi", setup_backlog_napi_threads);

static bool use_backlog_threads(void)
{
 return static_branch_unlikely(&use_backlog_threads_key);
}

#else

static bool use_backlog_threads(void)
{
 return true;
}

#endif

static inline void backlog_lock_irq_save(struct softnet_data *sd,
      unsigned long *flags)
{
 if (IS_ENABLED(CONFIG_RPS) || use_backlog_threads())
  spin_lock_irqsave(&sd->input_pkt_queue.lock, *flags);
 else
  local_irq_save(*flags);
}

static inline void backlog_lock_irq_disable(struct softnet_data *sd)
{
 if (IS_ENABLED(CONFIG_RPS) || use_backlog_threads())
  spin_lock_irq(&sd->input_pkt_queue.lock);
 else
  local_irq_disable();
}

static inline void backlog_unlock_irq_restore(struct softnet_data *sd,
           unsigned long *flags)
{
 if (IS_ENABLED(CONFIG_RPS) || use_backlog_threads())
  spin_unlock_irqrestore(&sd->input_pkt_queue.lock, *flags);
 else
  local_irq_restore(*flags);
}

static inline void backlog_unlock_irq_enable(struct softnet_data *sd)
{
 if (IS_ENABLED(CONFIG_RPS) || use_backlog_threads())
  spin_unlock_irq(&sd->input_pkt_queue.lock);
 else
  local_irq_enable();
}

static struct netdev_name_node *netdev_name_node_alloc(struct net_device *dev,
             const char *name)
{
 struct netdev_name_node *name_node;

 name_node = kmalloc(sizeof(*name_node), GFP_KERNEL);
 if (!name_node)
  return NULL;
 INIT_HLIST_NODE(&name_node->hlist);
 name_node->dev = dev;
 name_node->name = name;
 return name_node;
}

static struct netdev_name_node *
netdev_name_node_head_alloc(struct net_device *dev)
{
 struct netdev_name_node *name_node;

 name_node = netdev_name_node_alloc(dev, dev->name);
 if (!name_node)
  return NULL;
 INIT_LIST_HEAD(&name_node->list);
 return name_node;
}

static void netdev_name_node_free(struct netdev_name_node *name_node)
{
 kfree(name_node);
}

static void netdev_name_node_add(struct net *net,
     struct netdev_name_node *name_node)
{
 hlist_add_head_rcu(&name_node->hlist,
      dev_name_hash(net, name_node->name));
}

static void netdev_name_node_del(struct netdev_name_node *name_node)
{
 hlist_del_rcu(&name_node->hlist);
}

static struct netdev_name_node *netdev_name_node_lookup(struct net *net,
       const char *name)
{
 struct hlist_head *head = dev_name_hash(net, name);
 struct netdev_name_node *name_node;

 hlist_for_each_entry(name_node, head, hlist)
  if (!strcmp(name_node->name, name))
   return name_node;
 return NULL;
}

static struct netdev_name_node *netdev_name_node_lookup_rcu(struct net *net,
           const char *name)
{
 struct hlist_head *head = dev_name_hash(net, name);
 struct netdev_name_node *name_node;

 hlist_for_each_entry_rcu(name_node, head, hlist)
  if (!strcmp(name_node->name, name))
   return name_node;
 return NULL;
}

bool netdev_name_in_use(struct net *net, const char *name)
{
 return netdev_name_node_lookup(net, name);
}
EXPORT_SYMBOL(netdev_name_in_use);

int netdev_name_node_alt_create(struct net_device *dev, const char *name)
{
 struct netdev_name_node *name_node;
 struct net *net = dev_net(dev);

 name_node = netdev_name_node_lookup(net, name);
 if (name_node)
  return -EEXIST;
 name_node = netdev_name_node_alloc(dev, name);
 if (!name_node)
  return -ENOMEM;
 netdev_name_node_add(net, name_node);
 /* The node that holds dev->name acts as a head of per-device list. */
 list_add_tail_rcu(&name_node->list, &dev->name_node->list);

 return 0;
}

static void netdev_name_node_alt_free(struct rcu_head *head)
{
 struct netdev_name_node *name_node =
  container_of(head, struct netdev_name_node, rcu);

 kfree(name_node->name);
 netdev_name_node_free(name_node);
}

static void __netdev_name_node_alt_destroy(struct netdev_name_node *name_node)
{
 netdev_name_node_del(name_node);
 list_del(&name_node->list);
 call_rcu(&name_node->rcu, netdev_name_node_alt_free);
}

int netdev_name_node_alt_destroy(struct net_device *dev, const char *name)
{
 struct netdev_name_node *name_node;
 struct net *net = dev_net(dev);

 name_node = netdev_name_node_lookup(net, name);
 if (!name_node)
  return -ENOENT;
 /* lookup might have found our primary name or a name belonging
 * to another device.
 */

 if (name_node == dev->name_node || name_node->dev != dev)
  return -EINVAL;

 __netdev_name_node_alt_destroy(name_node);
 return 0;
}

static void netdev_name_node_alt_flush(struct net_device *dev)
{
 struct netdev_name_node *name_node, *tmp;

 list_for_each_entry_safe(name_node, tmp, &dev->name_node->list, list) {
  list_del(&name_node->list);
  netdev_name_node_alt_free(&name_node->rcu);
 }
}

/* Device list insertion */
static void list_netdevice(struct net_device *dev)
{
 struct netdev_name_node *name_node;
 struct net *net = dev_net(dev);

 ASSERT_RTNL();

 list_add_tail_rcu(&dev->dev_list, &net->dev_base_head);
 netdev_name_node_add(net, dev->name_node);
 hlist_add_head_rcu(&dev->index_hlist,
      dev_index_hash(net, dev->ifindex));

 netdev_for_each_altname(dev, name_node)
  netdev_name_node_add(net, name_node);

 /* We reserved the ifindex, this can't fail */
 WARN_ON(xa_store(&net->dev_by_index, dev->ifindex, dev, GFP_KERNEL));

 dev_base_seq_inc(net);
}

/* Device list removal
 * caller must respect a RCU grace period before freeing/reusing dev
 */

static void unlist_netdevice(struct net_device *dev)
{
 struct netdev_name_node *name_node;
 struct net *net = dev_net(dev);

 ASSERT_RTNL();

 xa_erase(&net->dev_by_index, dev->ifindex);

 netdev_for_each_altname(dev, name_node)
  netdev_name_node_del(name_node);

 /* Unlink dev from the device chain */
 list_del_rcu(&dev->dev_list);
 netdev_name_node_del(dev->name_node);
 hlist_del_rcu(&dev->index_hlist);

 dev_base_seq_inc(dev_net(dev));
}

/*
 * Our notifier list
 */


static RAW_NOTIFIER_HEAD(netdev_chain);

/*
 * Device drivers call our routines to queue packets here. We empty the
 * queue in the local softnet handler.
 */


DEFINE_PER_CPU_ALIGNED(struct softnet_data, softnet_data) = {
 .process_queue_bh_lock = INIT_LOCAL_LOCK(process_queue_bh_lock),
};
EXPORT_PER_CPU_SYMBOL(softnet_data);

/* Page_pool has a lockless array/stack to alloc/recycle pages.
 * PP consumers must pay attention to run APIs in the appropriate context
 * (e.g. NAPI context).
 */

DEFINE_PER_CPU(struct page_pool_bh, system_page_pool) = {
 .bh_lock = INIT_LOCAL_LOCK(bh_lock),
};

#ifdef CONFIG_LOCKDEP
/*
 * register_netdevice() inits txq->_xmit_lock and sets lockdep class
 * according to dev->type
 */

static const unsigned short netdev_lock_type[] = {
  ARPHRD_NETROM, ARPHRD_ETHER, ARPHRD_EETHER, ARPHRD_AX25,
  ARPHRD_PRONET, ARPHRD_CHAOS, ARPHRD_IEEE802, ARPHRD_ARCNET,
  ARPHRD_APPLETLK, ARPHRD_DLCI, ARPHRD_ATM, ARPHRD_METRICOM,
  ARPHRD_IEEE1394, ARPHRD_EUI64, ARPHRD_INFINIBAND, ARPHRD_SLIP,
  ARPHRD_CSLIP, ARPHRD_SLIP6, ARPHRD_CSLIP6, ARPHRD_RSRVD,
  ARPHRD_ADAPT, ARPHRD_ROSE, ARPHRD_X25, ARPHRD_HWX25,
  ARPHRD_PPP, ARPHRD_CISCO, ARPHRD_LAPB, ARPHRD_DDCMP,
  ARPHRD_RAWHDLC, ARPHRD_TUNNEL, ARPHRD_TUNNEL6, ARPHRD_FRAD,
  ARPHRD_SKIP, ARPHRD_LOOPBACK, ARPHRD_LOCALTLK, ARPHRD_FDDI,
  ARPHRD_BIF, ARPHRD_SIT, ARPHRD_IPDDP, ARPHRD_IPGRE,
  ARPHRD_PIMREG, ARPHRD_HIPPI, ARPHRD_ASH, ARPHRD_ECONET,
  ARPHRD_IRDA, ARPHRD_FCPP, ARPHRD_FCAL, ARPHRD_FCPL,
  ARPHRD_FCFABRIC, ARPHRD_IEEE80211, ARPHRD_IEEE80211_PRISM,
  ARPHRD_IEEE80211_RADIOTAP, ARPHRD_PHONET, ARPHRD_PHONET_PIPE,
  ARPHRD_IEEE802154, ARPHRD_VOID, ARPHRD_NONE};

static const char *const netdev_lock_name[] = {
 "_xmit_NETROM""_xmit_ETHER""_xmit_EETHER""_xmit_AX25",
 "_xmit_PRONET""_xmit_CHAOS""_xmit_IEEE802""_xmit_ARCNET",
 "_xmit_APPLETLK""_xmit_DLCI""_xmit_ATM""_xmit_METRICOM",
 "_xmit_IEEE1394""_xmit_EUI64""_xmit_INFINIBAND""_xmit_SLIP",
 "_xmit_CSLIP""_xmit_SLIP6""_xmit_CSLIP6""_xmit_RSRVD",
 "_xmit_ADAPT""_xmit_ROSE""_xmit_X25""_xmit_HWX25",
 "_xmit_PPP""_xmit_CISCO""_xmit_LAPB""_xmit_DDCMP",
 "_xmit_RAWHDLC""_xmit_TUNNEL""_xmit_TUNNEL6""_xmit_FRAD",
 "_xmit_SKIP""_xmit_LOOPBACK""_xmit_LOCALTLK""_xmit_FDDI",
 "_xmit_BIF""_xmit_SIT""_xmit_IPDDP""_xmit_IPGRE",
 "_xmit_PIMREG""_xmit_HIPPI""_xmit_ASH""_xmit_ECONET",
 "_xmit_IRDA""_xmit_FCPP""_xmit_FCAL""_xmit_FCPL",
 "_xmit_FCFABRIC""_xmit_IEEE80211""_xmit_IEEE80211_PRISM",
 "_xmit_IEEE80211_RADIOTAP""_xmit_PHONET""_xmit_PHONET_PIPE",
 "_xmit_IEEE802154""_xmit_VOID""_xmit_NONE"};

static struct lock_class_key netdev_xmit_lock_key[ARRAY_SIZE(netdev_lock_type)];
static struct lock_class_key netdev_addr_lock_key[ARRAY_SIZE(netdev_lock_type)];

static inline unsigned short netdev_lock_pos(unsigned short dev_type)
{
 int i;

 for (i = 0; i < ARRAY_SIZE(netdev_lock_type); i++)
  if (netdev_lock_type[i] == dev_type)
   return i;
 /* the last key is used by default */
 return ARRAY_SIZE(netdev_lock_type) - 1;
}

static inline void netdev_set_xmit_lockdep_class(spinlock_t *lock,
       unsigned short dev_type)
{
 int i;

 i = netdev_lock_pos(dev_type);
 lockdep_set_class_and_name(lock, &netdev_xmit_lock_key[i],
       netdev_lock_name[i]);
}

static inline void netdev_set_addr_lockdep_class(struct net_device *dev)
{
 int i;

 i = netdev_lock_pos(dev->type);
 lockdep_set_class_and_name(&dev->addr_list_lock,
       &netdev_addr_lock_key[i],
       netdev_lock_name[i]);
}
#else
static inline void netdev_set_xmit_lockdep_class(spinlock_t *lock,
       unsigned short dev_type)
{
}

static inline void netdev_set_addr_lockdep_class(struct net_device *dev)
{
}
#endif

/*******************************************************************************
 *
 * Protocol management and registration routines
 *
 *******************************************************************************/



/*
 * Add a protocol ID to the list. Now that the input handler is
 * smarter we can dispense with all the messy stuff that used to be
 * here.
 *
 * BEWARE!!! Protocol handlers, mangling input packets,
 * MUST BE last in hash buckets and checking protocol handlers
 * MUST start from promiscuous ptype_all chain in net_bh.
 * It is true now, do not change it.
 * Explanation follows: if protocol handler, mangling packet, will
 * be the first on list, it is not able to sense, that packet
 * is cloned and should be copied-on-write, so that it will
 * change it and subsequent readers will get broken packet.
 * --ANK (980803)
 */


static inline struct list_head *ptype_head(const struct packet_type *pt)
{
 if (pt->type == htons(ETH_P_ALL)) {
  if (!pt->af_packet_net && !pt->dev)
   return NULL;

  return pt->dev ? &pt->dev->ptype_all :
     &pt->af_packet_net->ptype_all;
 }

 if (pt->dev)
  return &pt->dev->ptype_specific;

 return pt->af_packet_net ? &pt->af_packet_net->ptype_specific :
     &ptype_base[ntohs(pt->type) & PTYPE_HASH_MASK];
}

/**
 * dev_add_pack - add packet handler
 * @pt: packet type declaration
 *
 * Add a protocol handler to the networking stack. The passed &packet_type
 * is linked into kernel lists and may not be freed until it has been
 * removed from the kernel lists.
 *
 * This call does not sleep therefore it can not
 * guarantee all CPU's that are in middle of receiving packets
 * will see the new packet type (until the next received packet).
 */


void dev_add_pack(struct packet_type *pt)
{
 struct list_head *head = ptype_head(pt);

 if (WARN_ON_ONCE(!head))
  return;

 spin_lock(&ptype_lock);
 list_add_rcu(&pt->list, head);
 spin_unlock(&ptype_lock);
}
EXPORT_SYMBOL(dev_add_pack);

/**
 * __dev_remove_pack  - remove packet handler
 * @pt: packet type declaration
 *
 * Remove a protocol handler that was previously added to the kernel
 * protocol handlers by dev_add_pack(). The passed &packet_type is removed
 * from the kernel lists and can be freed or reused once this function
 * returns.
 *
 *      The packet type might still be in use by receivers
 * and must not be freed until after all the CPU's have gone
 * through a quiescent state.
 */

void __dev_remove_pack(struct packet_type *pt)
{
 struct list_head *head = ptype_head(pt);
 struct packet_type *pt1;

 if (!head)
  return;

 spin_lock(&ptype_lock);

 list_for_each_entry(pt1, head, list) {
  if (pt == pt1) {
   list_del_rcu(&pt->list);
   goto out;
  }
 }

 pr_warn("dev_remove_pack: %p not found\n", pt);
out:
 spin_unlock(&ptype_lock);
}
EXPORT_SYMBOL(__dev_remove_pack);

/**
 * dev_remove_pack  - remove packet handler
 * @pt: packet type declaration
 *
 * Remove a protocol handler that was previously added to the kernel
 * protocol handlers by dev_add_pack(). The passed &packet_type is removed
 * from the kernel lists and can be freed or reused once this function
 * returns.
 *
 * This call sleeps to guarantee that no CPU is looking at the packet
 * type after return.
 */

void dev_remove_pack(struct packet_type *pt)
{
 __dev_remove_pack(pt);

 synchronize_net();
}
EXPORT_SYMBOL(dev_remove_pack);


/*******************************************************************************
 *
 *     Device Interface Subroutines
 *
 *******************************************************************************/


/**
 * dev_get_iflink - get 'iflink' value of a interface
 * @dev: targeted interface
 *
 * Indicates the ifindex the interface is linked to.
 * Physical interfaces have the same 'ifindex' and 'iflink' values.
 */


int dev_get_iflink(const struct net_device *dev)
{
 if (dev->netdev_ops && dev->netdev_ops->ndo_get_iflink)
  return dev->netdev_ops->ndo_get_iflink(dev);

 return READ_ONCE(dev->ifindex);
}
EXPORT_SYMBOL(dev_get_iflink);

/**
 * dev_fill_metadata_dst - Retrieve tunnel egress information.
 * @dev: targeted interface
 * @skb: The packet.
 *
 * For better visibility of tunnel traffic OVS needs to retrieve
 * egress tunnel information for a packet. Following API allows
 * user to get this info.
 */

int dev_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)
{
 struct ip_tunnel_info *info;

 if (!dev->netdev_ops  || !dev->netdev_ops->ndo_fill_metadata_dst)
  return -EINVAL;

 info = skb_tunnel_info_unclone(skb);
 if (!info)
  return -ENOMEM;
 if (unlikely(!(info->mode & IP_TUNNEL_INFO_TX)))
  return -EINVAL;

 return dev->netdev_ops->ndo_fill_metadata_dst(dev, skb);
}
EXPORT_SYMBOL_GPL(dev_fill_metadata_dst);

static struct net_device_path *dev_fwd_path(struct net_device_path_stack *stack)
{
 int k = stack->num_paths++;

 if (WARN_ON_ONCE(k >= NET_DEVICE_PATH_STACK_MAX))
  return NULL;

 return &stack->path[k];
}

int dev_fill_forward_path(const struct net_device *dev, const u8 *daddr,
     struct net_device_path_stack *stack)
{
 const struct net_device *last_dev;
 struct net_device_path_ctx ctx = {
  .dev = dev,
 };
 struct net_device_path *path;
 int ret = 0;

 memcpy(ctx.daddr, daddr, sizeof(ctx.daddr));
 stack->num_paths = 0;
 while (ctx.dev && ctx.dev->netdev_ops->ndo_fill_forward_path) {
  last_dev = ctx.dev;
  path = dev_fwd_path(stack);
  if (!path)
   return -1;

  memset(path, 0, sizeof(struct net_device_path));
  ret = ctx.dev->netdev_ops->ndo_fill_forward_path(&ctx, path);
  if (ret < 0)
   return -1;

  if (WARN_ON_ONCE(last_dev == ctx.dev))
   return -1;
 }

 if (!ctx.dev)
  return ret;

 path = dev_fwd_path(stack);
 if (!path)
  return -1;
 path->type = DEV_PATH_ETHERNET;
 path->dev = ctx.dev;

 return ret;
}
EXPORT_SYMBOL_GPL(dev_fill_forward_path);

/* must be called under rcu_read_lock(), as we dont take a reference */
static struct napi_struct *napi_by_id(unsigned int napi_id)
{
 unsigned int hash = napi_id % HASH_SIZE(napi_hash);
 struct napi_struct *napi;

 hlist_for_each_entry_rcu(napi, &napi_hash[hash], napi_hash_node)
  if (napi->napi_id == napi_id)
   return napi;

 return NULL;
}

/* must be called under rcu_read_lock(), as we dont take a reference */
static struct napi_struct *
netdev_napi_by_id(struct net *net, unsigned int napi_id)
{
 struct napi_struct *napi;

 napi = napi_by_id(napi_id);
 if (!napi)
  return NULL;

 if (WARN_ON_ONCE(!napi->dev))
  return NULL;
 if (!net_eq(net, dev_net(napi->dev)))
  return NULL;

 return napi;
}

/**
 * netdev_napi_by_id_lock() - find a device by NAPI ID and lock it
 * @net: the applicable net namespace
 * @napi_id: ID of a NAPI of a target device
 *
 * Find a NAPI instance with @napi_id. Lock its device.
 * The device must be in %NETREG_REGISTERED state for lookup to succeed.
 * netdev_unlock() must be called to release it.
 *
 * Return: pointer to NAPI, its device with lock held, NULL if not found.
 */

struct napi_struct *
netdev_napi_by_id_lock(struct net *net, unsigned int napi_id)
{
 struct napi_struct *napi;
 struct net_device *dev;

 rcu_read_lock();
 napi = netdev_napi_by_id(net, napi_id);
 if (!napi || READ_ONCE(napi->dev->reg_state) != NETREG_REGISTERED) {
  rcu_read_unlock();
  return NULL;
 }

 dev = napi->dev;
 dev_hold(dev);
 rcu_read_unlock();

 dev = __netdev_put_lock(dev, net);
 if (!dev)
  return NULL;

 rcu_read_lock();
 napi = netdev_napi_by_id(net, napi_id);
 if (napi && napi->dev != dev)
  napi = NULL;
 rcu_read_unlock();

 if (!napi)
  netdev_unlock(dev);
 return napi;
}

/**
 * __dev_get_by_name - find a device by its name
 * @net: the applicable net namespace
 * @name: name to find
 *
 * Find an interface by name. Must be called under RTNL semaphore.
 * If the name is found a pointer to the device is returned.
 * If the name is not found then %NULL is returned. The
 * reference counters are not incremented so the caller must be
 * careful with locks.
 */


struct net_device *__dev_get_by_name(struct net *net, const char *name)
{
 struct netdev_name_node *node_name;

 node_name = netdev_name_node_lookup(net, name);
 return node_name ? node_name->dev : NULL;
}
EXPORT_SYMBOL(__dev_get_by_name);

/**
 * dev_get_by_name_rcu - find a device by its name
 * @net: the applicable net namespace
 * @name: name to find
 *
 * Find an interface by name.
 * If the name is found a pointer to the device is returned.
 * If the name is not found then %NULL is returned.
 * The reference counters are not incremented so the caller must be
 * careful with locks. The caller must hold RCU lock.
 */


struct net_device *dev_get_by_name_rcu(struct net *net, const char *name)
{
 struct netdev_name_node *node_name;

 node_name = netdev_name_node_lookup_rcu(net, name);
 return node_name ? node_name->dev : NULL;
}
EXPORT_SYMBOL(dev_get_by_name_rcu);

/* Deprecated for new users, call netdev_get_by_name() instead */
struct net_device *dev_get_by_name(struct net *net, const char *name)
{
 struct net_device *dev;

 rcu_read_lock();
 dev = dev_get_by_name_rcu(net, name);
 dev_hold(dev);
 rcu_read_unlock();
 return dev;
}
EXPORT_SYMBOL(dev_get_by_name);

/**
 * netdev_get_by_name() - find a device by its name
 * @net: the applicable net namespace
 * @name: name to find
 * @tracker: tracking object for the acquired reference
 * @gfp: allocation flags for the tracker
 *
 * Find an interface by name. This can be called from any
 * context and does its own locking. The returned handle has
 * the usage count incremented and the caller must use netdev_put() to
 * release it when it is no longer needed. %NULL is returned if no
 * matching device is found.
 */

struct net_device *netdev_get_by_name(struct net *net, const char *name,
          netdevice_tracker *tracker, gfp_t gfp)
{
 struct net_device *dev;

 dev = dev_get_by_name(net, name);
 if (dev)
  netdev_tracker_alloc(dev, tracker, gfp);
 return dev;
}
EXPORT_SYMBOL(netdev_get_by_name);

/**
 * __dev_get_by_index - find a device by its ifindex
 * @net: the applicable net namespace
 * @ifindex: index of device
 *
 * Search for an interface by index. Returns %NULL if the device
 * is not found or a pointer to the device. The device has not
 * had its reference counter increased so the caller must be careful
 * about locking. The caller must hold the RTNL semaphore.
 */


struct net_device *__dev_get_by_index(struct net *net, int ifindex)
{
 struct net_device *dev;
 struct hlist_head *head = dev_index_hash(net, ifindex);

 hlist_for_each_entry(dev, head, index_hlist)
  if (dev->ifindex == ifindex)
   return dev;

 return NULL;
}
EXPORT_SYMBOL(__dev_get_by_index);

/**
 * dev_get_by_index_rcu - find a device by its ifindex
 * @net: the applicable net namespace
 * @ifindex: index of device
 *
 * Search for an interface by index. Returns %NULL if the device
 * is not found or a pointer to the device. The device has not
 * had its reference counter increased so the caller must be careful
 * about locking. The caller must hold RCU lock.
 */


struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex)
{
 struct net_device *dev;
 struct hlist_head *head = dev_index_hash(net, ifindex);

 hlist_for_each_entry_rcu(dev, head, index_hlist)
  if (dev->ifindex == ifindex)
   return dev;

 return NULL;
}
EXPORT_SYMBOL(dev_get_by_index_rcu);

/* Deprecated for new users, call netdev_get_by_index() instead */
struct net_device *dev_get_by_index(struct net *net, int ifindex)
{
 struct net_device *dev;

 rcu_read_lock();
 dev = dev_get_by_index_rcu(net, ifindex);
 dev_hold(dev);
 rcu_read_unlock();
 return dev;
}
EXPORT_SYMBOL(dev_get_by_index);

/**
 * netdev_get_by_index() - find a device by its ifindex
 * @net: the applicable net namespace
 * @ifindex: index of device
 * @tracker: tracking object for the acquired reference
 * @gfp: allocation flags for the tracker
 *
 * Search for an interface by index. Returns NULL if the device
 * is not found or a pointer to the device. The device returned has
 * had a reference added and the pointer is safe until the user calls
 * netdev_put() to indicate they have finished with it.
 */

struct net_device *netdev_get_by_index(struct net *net, int ifindex,
           netdevice_tracker *tracker, gfp_t gfp)
{
 struct net_device *dev;

 dev = dev_get_by_index(net, ifindex);
 if (dev)
  netdev_tracker_alloc(dev, tracker, gfp);
 return dev;
}
EXPORT_SYMBOL(netdev_get_by_index);

/**
 * dev_get_by_napi_id - find a device by napi_id
 * @napi_id: ID of the NAPI struct
 *
 * Search for an interface by NAPI ID. Returns %NULL if the device
 * is not found or a pointer to the device. The device has not had
 * its reference counter increased so the caller must be careful
 * about locking. The caller must hold RCU lock.
 */

struct net_device *dev_get_by_napi_id(unsigned int napi_id)
{
 struct napi_struct *napi;

 WARN_ON_ONCE(!rcu_read_lock_held());

 if (!napi_id_valid(napi_id))
  return NULL;

 napi = napi_by_id(napi_id);

 return napi ? napi->dev : NULL;
}

/* Release the held reference on the net_device, and if the net_device
 * is still registered try to lock the instance lock. If device is being
 * unregistered NULL will be returned (but the reference has been released,
 * either way!)
 *
 * This helper is intended for locking net_device after it has been looked up
 * using a lockless lookup helper. Lock prevents the instance from going away.
 */

struct net_device *__netdev_put_lock(struct net_device *dev, struct net *net)
{
 netdev_lock(dev);
 if (dev->reg_state > NETREG_REGISTERED ||
     dev->moving_ns || !net_eq(dev_net(dev), net)) {
  netdev_unlock(dev);
  dev_put(dev);
  return NULL;
 }
 dev_put(dev);
 return dev;
}

static struct net_device *
__netdev_put_lock_ops_compat(struct net_device *dev, struct net *net)
{
 netdev_lock_ops_compat(dev);
 if (dev->reg_state > NETREG_REGISTERED ||
     dev->moving_ns || !net_eq(dev_net(dev), net)) {
  netdev_unlock_ops_compat(dev);
  dev_put(dev);
  return NULL;
 }
 dev_put(dev);
 return dev;
}

/**
 * netdev_get_by_index_lock() - find a device by its ifindex
 * @net: the applicable net namespace
 * @ifindex: index of device
 *
 * Search for an interface by index. If a valid device
 * with @ifindex is found it will be returned with netdev->lock held.
 * netdev_unlock() must be called to release it.
 *
 * Return: pointer to a device with lock held, NULL if not found.
 */

struct net_device *netdev_get_by_index_lock(struct net *net, int ifindex)
{
 struct net_device *dev;

 dev = dev_get_by_index(net, ifindex);
 if (!dev)
  return NULL;

 return __netdev_put_lock(dev, net);
}

struct net_device *
netdev_get_by_index_lock_ops_compat(struct net *net, int ifindex)
{
 struct net_device *dev;

 dev = dev_get_by_index(net, ifindex);
 if (!dev)
  return NULL;

 return __netdev_put_lock_ops_compat(dev, net);
}

struct net_device *
netdev_xa_find_lock(struct net *net, struct net_device *dev,
      unsigned long *index)
{
 if (dev)
  netdev_unlock(dev);

 do {
  rcu_read_lock();
  dev = xa_find(&net->dev_by_index, index, ULONG_MAX, XA_PRESENT);
  if (!dev) {
   rcu_read_unlock();
   return NULL;
  }
  dev_hold(dev);
  rcu_read_unlock();

  dev = __netdev_put_lock(dev, net);
  if (dev)
   return dev;

  (*index)++;
 } while (true);
}

struct net_device *
netdev_xa_find_lock_ops_compat(struct net *net, struct net_device *dev,
          unsigned long *index)
{
 if (dev)
  netdev_unlock_ops_compat(dev);

 do {
  rcu_read_lock();
  dev = xa_find(&net->dev_by_index, index, ULONG_MAX, XA_PRESENT);
  if (!dev) {
   rcu_read_unlock();
   return NULL;
  }
  dev_hold(dev);
  rcu_read_unlock();

  dev = __netdev_put_lock_ops_compat(dev, net);
  if (dev)
   return dev;

  (*index)++;
 } while (true);
}

static DEFINE_SEQLOCK(netdev_rename_lock);

void netdev_copy_name(struct net_device *dev, char *name)
{
 unsigned int seq;

 do {
  seq = read_seqbegin(&netdev_rename_lock);
  strscpy(name, dev->name, IFNAMSIZ);
 } while (read_seqretry(&netdev_rename_lock, seq));
}

/**
 * netdev_get_name - get a netdevice name, knowing its ifindex.
 * @net: network namespace
 * @name: a pointer to the buffer where the name will be stored.
 * @ifindex: the ifindex of the interface to get the name from.
 */

int netdev_get_name(struct net *net, char *name, int ifindex)
{
 struct net_device *dev;
 int ret;

 rcu_read_lock();

 dev = dev_get_by_index_rcu(net, ifindex);
 if (!dev) {
  ret = -ENODEV;
  goto out;
 }

 netdev_copy_name(dev, name);

 ret = 0;
out:
 rcu_read_unlock();
 return ret;
}

static bool dev_addr_cmp(struct net_device *dev, unsigned short type,
    const char *ha)
{
 return dev->type == type && !memcmp(dev->dev_addr, ha, dev->addr_len);
}

/**
 * dev_getbyhwaddr_rcu - find a device by its hardware address
 * @net: the applicable net namespace
 * @type: media type of device
 * @ha: hardware address
 *
 * Search for an interface by MAC address. Returns NULL if the device
 * is not found or a pointer to the device.
 * The caller must hold RCU.
 * The returned device has not had its ref count increased
 * and the caller must therefore be careful about locking
 *
 */


struct net_device *dev_getbyhwaddr_rcu(struct net *net, unsigned short type,
           const char *ha)
{
 struct net_device *dev;

 for_each_netdev_rcu(net, dev)
  if (dev_addr_cmp(dev, type, ha))
   return dev;

 return NULL;
}
EXPORT_SYMBOL(dev_getbyhwaddr_rcu);

/**
 * dev_getbyhwaddr() - find a device by its hardware address
 * @net: the applicable net namespace
 * @type: media type of device
 * @ha: hardware address
 *
 * Similar to dev_getbyhwaddr_rcu(), but the owner needs to hold
 * rtnl_lock.
 *
 * Context: rtnl_lock() must be held.
 * Return: pointer to the net_device, or NULL if not found
 */

struct net_device *dev_getbyhwaddr(struct net *net, unsigned short type,
       const char *ha)
{
 struct net_device *dev;

 ASSERT_RTNL();
 for_each_netdev(net, dev)
  if (dev_addr_cmp(dev, type, ha))
   return dev;

 return NULL;
}
EXPORT_SYMBOL(dev_getbyhwaddr);

struct net_device *dev_getfirstbyhwtype(struct net *net, unsigned short type)
{
 struct net_device *dev, *ret = NULL;

 rcu_read_lock();
 for_each_netdev_rcu(net, dev)
  if (dev->type == type) {
   dev_hold(dev);
   ret = dev;
   break;
  }
 rcu_read_unlock();
 return ret;
}
EXPORT_SYMBOL(dev_getfirstbyhwtype);

/**
 * netdev_get_by_flags_rcu - find any device with given flags
 * @net: the applicable net namespace
 * @tracker: tracking object for the acquired reference
 * @if_flags: IFF_* values
 * @mask: bitmask of bits in if_flags to check
 *
 * Search for any interface with the given flags.
 *
 * Context: rcu_read_lock() must be held.
 * Returns: NULL if a device is not found or a pointer to the device.
 */

struct net_device *netdev_get_by_flags_rcu(struct net *net, netdevice_tracker *tracker,
        unsigned short if_flags, unsigned short mask)
{
 struct net_device *dev;

 for_each_netdev_rcu(net, dev) {
  if (((READ_ONCE(dev->flags) ^ if_flags) & mask) == 0) {
   netdev_hold(dev, tracker, GFP_ATOMIC);
   return dev;
  }
 }

 return NULL;
}
EXPORT_IPV6_MOD(netdev_get_by_flags_rcu);

/**
 * dev_valid_name - check if name is okay for network device
 * @name: name string
 *
 * Network device names need to be valid file names to
 * allow sysfs to work.  We also disallow any kind of
 * whitespace.
 */

bool dev_valid_name(const char *name)
{
 if (*name == '\0')
  return false;
 if (strnlen(name, IFNAMSIZ) == IFNAMSIZ)
  return false;
 if (!strcmp(name, ".") || !strcmp(name, ".."))
  return false;

 while (*name) {
  if (*name == '/' || *name == ':' || isspace(*name))
   return false;
  name++;
 }
 return true;
}
EXPORT_SYMBOL(dev_valid_name);

/**
 * __dev_alloc_name - allocate a name for a device
 * @net: network namespace to allocate the device name in
 * @name: name format string
 * @res: result name string
 *
 * Passed a format string - eg "lt%d" it will try and find a suitable
 * id. It scans list of devices to build up a free map, then chooses
 * the first empty slot. The caller must hold the dev_base or rtnl lock
 * while allocating the name and adding the device in order to avoid
 * duplicates.
 * Limited to bits_per_byte * page size devices (ie 32K on most platforms).
 * Returns the number of the unit assigned or a negative errno code.
 */


static int __dev_alloc_name(struct net *net, const char *name, char *res)
{
 int i = 0;
 const char *p;
 const int max_netdevices = 8*PAGE_SIZE;
 unsigned long *inuse;
 struct net_device *d;
 char buf[IFNAMSIZ];

 /* Verify the string as this thing may have come from the user.
 * There must be one "%d" and no other "%" characters.
 */

 p = strchr(name, '%');
 if (!p || p[1] != 'd' || strchr(p + 2, '%'))
  return -EINVAL;

 /* Use one page as a bit array of possible slots */
 inuse = bitmap_zalloc(max_netdevices, GFP_ATOMIC);
 if (!inuse)
  return -ENOMEM;

 for_each_netdev(net, d) {
  struct netdev_name_node *name_node;

  netdev_for_each_altname(d, name_node) {
   if (!sscanf(name_node->name, name, &i))
    continue;
   if (i < 0 || i >= max_netdevices)
    continue;

   /* avoid cases where sscanf is not exact inverse of printf */
   snprintf(buf, IFNAMSIZ, name, i);
   if (!strncmp(buf, name_node->name, IFNAMSIZ))
    __set_bit(i, inuse);
  }
  if (!sscanf(d->name, name, &i))
   continue;
  if (i < 0 || i >= max_netdevices)
   continue;

  /* avoid cases where sscanf is not exact inverse of printf */
  snprintf(buf, IFNAMSIZ, name, i);
  if (!strncmp(buf, d->name, IFNAMSIZ))
   __set_bit(i, inuse);
 }

 i = find_first_zero_bit(inuse, max_netdevices);
 bitmap_free(inuse);
 if (i == max_netdevices)
  return -ENFILE;

 /* 'res' and 'name' could overlap, use 'buf' as an intermediate buffer */
 strscpy(buf, name, IFNAMSIZ);
 snprintf(res, IFNAMSIZ, buf, i);
 return i;
}

/* Returns negative errno or allocated unit id (see __dev_alloc_name()) */
static int dev_prep_valid_name(struct net *net, struct net_device *dev,
          const char *want_name, char *out_name,
          int dup_errno)
{
 if (!dev_valid_name(want_name))
  return -EINVAL;

 if (strchr(want_name, '%'))
  return __dev_alloc_name(net, want_name, out_name);

 if (netdev_name_in_use(net, want_name))
  return -dup_errno;
 if (out_name != want_name)
  strscpy(out_name, want_name, IFNAMSIZ);
 return 0;
}

/**
 * dev_alloc_name - allocate a name for a device
 * @dev: device
 * @name: name format string
 *
 * Passed a format string - eg "lt%d" it will try and find a suitable
 * id. It scans list of devices to build up a free map, then chooses
 * the first empty slot. The caller must hold the dev_base or rtnl lock
 * while allocating the name and adding the device in order to avoid
 * duplicates.
 * Limited to bits_per_byte * page size devices (ie 32K on most platforms).
 * Returns the number of the unit assigned or a negative errno code.
 */


int dev_alloc_name(struct net_device *dev, const char *name)
{
 return dev_prep_valid_name(dev_net(dev), dev, name, dev->name, ENFILE);
}
EXPORT_SYMBOL(dev_alloc_name);

static int dev_get_valid_name(struct net *net, struct net_device *dev,
         const char *name)
{
 int ret;

 ret = dev_prep_valid_name(net, dev, name, dev->name, EEXIST);
 return ret < 0 ? ret : 0;
}

int netif_change_name(struct net_device *dev, const char *newname)
{
 struct net *net = dev_net(dev);
 unsigned char old_assign_type;
 char oldname[IFNAMSIZ];
 int err = 0;
 int ret;

 ASSERT_RTNL_NET(net);

 if (!strncmp(newname, dev->name, IFNAMSIZ))
  return 0;

 memcpy(oldname, dev->name, IFNAMSIZ);

 write_seqlock_bh(&netdev_rename_lock);
 err = dev_get_valid_name(net, dev, newname);
 write_sequnlock_bh(&netdev_rename_lock);

 if (err < 0)
  return err;

 if (oldname[0] && !strchr(oldname, '%'))
  netdev_info(dev, "renamed from %s%s\n", oldname,
       dev->flags & IFF_UP ? " (while UP)" : "");

 old_assign_type = dev->name_assign_type;
 WRITE_ONCE(dev->name_assign_type, NET_NAME_RENAMED);

rollback:
 ret = device_rename(&dev->dev, dev->name);
 if (ret) {
  write_seqlock_bh(&netdev_rename_lock);
  memcpy(dev->name, oldname, IFNAMSIZ);
  write_sequnlock_bh(&netdev_rename_lock);
  WRITE_ONCE(dev->name_assign_type, old_assign_type);
  return ret;
 }

 netdev_adjacent_rename_links(dev, oldname);

 netdev_name_node_del(dev->name_node);

 synchronize_net();

 netdev_name_node_add(net, dev->name_node);

 ret = call_netdevice_notifiers(NETDEV_CHANGENAME, dev);
 ret = notifier_to_errno(ret);

 if (ret) {
  /* err >= 0 after dev_alloc_name() or stores the first errno */
  if (err >= 0) {
   err = ret;
   write_seqlock_bh(&netdev_rename_lock);
   memcpy(dev->name, oldname, IFNAMSIZ);
   write_sequnlock_bh(&netdev_rename_lock);
   memcpy(oldname, newname, IFNAMSIZ);
   WRITE_ONCE(dev->name_assign_type, old_assign_type);
   old_assign_type = NET_NAME_RENAMED;
   goto rollback;
  } else {
   netdev_err(dev, "name change rollback failed: %d\n",
       ret);
  }
 }

 return err;
}

int netif_set_alias(struct net_device *dev, const char *alias, size_t len)
{
 struct dev_ifalias *new_alias = NULL;

 if (len >= IFALIASZ)
  return -EINVAL;

 if (len) {
  new_alias = kmalloc(sizeof(*new_alias) + len + 1, GFP_KERNEL);
  if (!new_alias)
   return -ENOMEM;

  memcpy(new_alias->ifalias, alias, len);
  new_alias->ifalias[len] = 0;
 }

 mutex_lock(&ifalias_mutex);
 new_alias = rcu_replace_pointer(dev->ifalias, new_alias,
     mutex_is_locked(&ifalias_mutex));
 mutex_unlock(&ifalias_mutex);

 if (new_alias)
  kfree_rcu(new_alias, rcuhead);

 return len;
}

/**
 * dev_get_alias - get ifalias of a device
 * @dev: device
 * @name: buffer to store name of ifalias
 * @len: size of buffer
 *
 * get ifalias for a device.  Caller must make sure dev cannot go
 * away,  e.g. rcu read lock or own a reference count to device.
 */

int dev_get_alias(const struct net_device *dev, char *name, size_t len)
{
 const struct dev_ifalias *alias;
 int ret = 0;

 rcu_read_lock();
 alias = rcu_dereference(dev->ifalias);
 if (alias)
  ret = snprintf(name, len, "%s", alias->ifalias);
 rcu_read_unlock();

 return ret;
}

/**
 * netdev_features_change - device changes features
 * @dev: device to cause notification
 *
 * Called to indicate a device has changed features.
 */

void netdev_features_change(struct net_device *dev)
{
 call_netdevice_notifiers(NETDEV_FEAT_CHANGE, dev);
}
EXPORT_SYMBOL(netdev_features_change);

void netif_state_change(struct net_device *dev)
{
 netdev_ops_assert_locked_or_invisible(dev);

 if (dev->flags & IFF_UP) {
  struct netdev_notifier_change_info change_info = {
   .info.dev = dev,
  };

  call_netdevice_notifiers_info(NETDEV_CHANGE,
           &change_info.info);
  rtmsg_ifinfo(RTM_NEWLINK, dev, 0, GFP_KERNEL, 0, NULL);
 }
}

/**
 * __netdev_notify_peers - notify network peers about existence of @dev,
 * to be called when rtnl lock is already held.
 * @dev: network device
 *
 * Generate traffic such that interested network peers are aware of
 * @dev, such as by generating a gratuitous ARP. This may be used when
 * a device wants to inform the rest of the network about some sort of
 * reconfiguration such as a failover event or virtual machine
 * migration.
 */

void __netdev_notify_peers(struct net_device *dev)
{
 ASSERT_RTNL();
 call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, dev);
 call_netdevice_notifiers(NETDEV_RESEND_IGMP, dev);
}
EXPORT_SYMBOL(__netdev_notify_peers);

/**
 * netdev_notify_peers - notify network peers about existence of @dev
 * @dev: network device
 *
 * Generate traffic such that interested network peers are aware of
 * @dev, such as by generating a gratuitous ARP. This may be used when
 * a device wants to inform the rest of the network about some sort of
 * reconfiguration such as a failover event or virtual machine
 * migration.
 */

void netdev_notify_peers(struct net_device *dev)
{
 rtnl_lock();
 __netdev_notify_peers(dev);
 rtnl_unlock();
}
EXPORT_SYMBOL(netdev_notify_peers);

static int napi_threaded_poll(void *data);

static int napi_kthread_create(struct napi_struct *n)
{
 int err = 0;

 /* Create and wake up the kthread once to put it in
 * TASK_INTERRUPTIBLE mode to avoid the blocked task
 * warning and work with loadavg.
 */

 n->thread = kthread_run(napi_threaded_poll, n, "napi/%s-%d",
    n->dev->name, n->napi_id);
 if (IS_ERR(n->thread)) {
  err = PTR_ERR(n->thread);
  pr_err("kthread_run failed with err %d\n", err);
  n->thread = NULL;
 }

 return err;
}

static int __dev_open(struct net_device *dev, struct netlink_ext_ack *extack)
{
 const struct net_device_ops *ops = dev->netdev_ops;
 int ret;

 ASSERT_RTNL();
 dev_addr_check(dev);

 if (!netif_device_present(dev)) {
  /* may be detached because parent is runtime-suspended */
  if (dev->dev.parent)
   pm_runtime_resume(dev->dev.parent);
  if (!netif_device_present(dev))
   return -ENODEV;
 }

 /* Block netpoll from trying to do any rx path servicing.
 * If we don't do this there is a chance ndo_poll_controller
 * or ndo_poll may be running while we open the device
 */

 netpoll_poll_disable(dev);

 ret = call_netdevice_notifiers_extack(NETDEV_PRE_UP, dev, extack);
 ret = notifier_to_errno(ret);
 if (ret)
  return ret;

 set_bit(__LINK_STATE_START, &dev->state);

 netdev_ops_assert_locked(dev);

 if (ops->ndo_validate_addr)
  ret = ops->ndo_validate_addr(dev);

 if (!ret && ops->ndo_open)
  ret = ops->ndo_open(dev);

 netpoll_poll_enable(dev);

 if (ret)
  clear_bit(__LINK_STATE_START, &dev->state);
 else {
  netif_set_up(dev, true);
  dev_set_rx_mode(dev);
  dev_activate(dev);
  add_device_randomness(dev->dev_addr, dev->addr_len);
 }

 return ret;
}

int netif_open(struct net_device *dev, struct netlink_ext_ack *extack)
{
 int ret;

 if (dev->flags & IFF_UP)
  return 0;

 ret = __dev_open(dev, extack);
 if (ret < 0)
  return ret;

 rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP | IFF_RUNNING, GFP_KERNEL, 0, NULL);
 call_netdevice_notifiers(NETDEV_UP, dev);

 return ret;
}

static void __dev_close_many(struct list_head *head)
{
 struct net_device *dev;

 ASSERT_RTNL();
 might_sleep();

 list_for_each_entry(dev, head, close_list) {
  /* Temporarily disable netpoll until the interface is down */
  netpoll_poll_disable(dev);

  call_netdevice_notifiers(NETDEV_GOING_DOWN, dev);

  clear_bit(__LINK_STATE_START, &dev->state);

  /* Synchronize to scheduled poll. We cannot touch poll list, it
 * can be even on different cpu. So just clear netif_running().
 *
 * dev->stop() will invoke napi_disable() on all of it's
 * napi_struct instances on this device.
 */

  smp_mb__after_atomic(); /* Commit netif_running(). */
 }

 dev_deactivate_many(head);

 list_for_each_entry(dev, head, close_list) {
  const struct net_device_ops *ops = dev->netdev_ops;

  /*
 * Call the device specific close. This cannot fail.
 * Only if device is UP
 *
 * We allow it to be called even after a DETACH hot-plug
 * event.
 */


  netdev_ops_assert_locked(dev);

  if (ops->ndo_stop)
   ops->ndo_stop(dev);

  netif_set_up(dev, false);
  netpoll_poll_enable(dev);
 }
}

static void __dev_close(struct net_device *dev)
{
 LIST_HEAD(single);

 list_add(&dev->close_list, &single);
 __dev_close_many(&single);
 list_del(&single);
}

void netif_close_many(struct list_head *head, bool unlink)
{
 struct net_device *dev, *tmp;

 /* Remove the devices that don't need to be closed */
 list_for_each_entry_safe(dev, tmp, head, close_list)
  if (!(dev->flags & IFF_UP))
   list_del_init(&dev->close_list);

 __dev_close_many(head);

 list_for_each_entry_safe(dev, tmp, head, close_list) {
  rtmsg_ifinfo(RTM_NEWLINK, dev, IFF_UP | IFF_RUNNING, GFP_KERNEL, 0, NULL);
  call_netdevice_notifiers(NETDEV_DOWN, dev);
  if (unlink)
   list_del_init(&dev->close_list);
 }
}
EXPORT_SYMBOL_NS_GPL(netif_close_many, "NETDEV_INTERNAL");

void netif_close(struct net_device *dev)
{
 if (dev->flags & IFF_UP) {
  LIST_HEAD(single);

  list_add(&dev->close_list, &single);
  netif_close_many(&single, true);
  list_del(&single);
 }
}
EXPORT_SYMBOL(netif_close);

void netif_disable_lro(struct net_device *dev)
{
 struct net_device *lower_dev;
 struct list_head *iter;

 dev->wanted_features &= ~NETIF_F_LRO;
 netdev_update_features(dev);

 if (unlikely(dev->features & NETIF_F_LRO))
  netdev_WARN(dev, "failed to disable LRO!\n");

 netdev_for_each_lower_dev(dev, lower_dev, iter) {
  netdev_lock_ops(lower_dev);
  netif_disable_lro(lower_dev);
  netdev_unlock_ops(lower_dev);
 }
}
EXPORT_IPV6_MOD(netif_disable_lro);

/**
 * dev_disable_gro_hw - disable HW Generic Receive Offload on a device
 * @dev: device
 *
 * Disable HW Generic Receive Offload (GRO_HW) on a net device.  Must be
 * called under RTNL.  This is needed if Generic XDP is installed on
 * the device.
 */

static void dev_disable_gro_hw(struct net_device *dev)
{
 dev->wanted_features &= ~NETIF_F_GRO_HW;
 netdev_update_features(dev);

 if (unlikely(dev->features & NETIF_F_GRO_HW))
  netdev_WARN(dev, "failed to disable GRO_HW!\n");
}

const char *netdev_cmd_to_name(enum netdev_cmd cmd)
{
#define N(val)       \
 case NETDEV_##val:    \
  return "NETDEV_" __stringify(val);
 switch (cmd) {
 N(UP) N(DOWN) N(REBOOT) N(CHANGE) N(REGISTER) N(UNREGISTER)
 N(CHANGEMTU) N(CHANGEADDR) N(GOING_DOWN) N(CHANGENAME) N(FEAT_CHANGE)
 N(BONDING_FAILOVER) N(PRE_UP) N(PRE_TYPE_CHANGE) N(POST_TYPE_CHANGE)
 N(POST_INIT) N(PRE_UNINIT) N(RELEASE) N(NOTIFY_PEERS) N(JOIN)
 N(CHANGEUPPER) N(RESEND_IGMP) N(PRECHANGEMTU) N(CHANGEINFODATA)
 N(BONDING_INFO) N(PRECHANGEUPPER) N(CHANGELOWERSTATE)
 N(UDP_TUNNEL_PUSH_INFO) N(UDP_TUNNEL_DROP_INFO) N(CHANGE_TX_QUEUE_LEN)
 N(CVLAN_FILTER_PUSH_INFO) N(CVLAN_FILTER_DROP_INFO)
 N(SVLAN_FILTER_PUSH_INFO) N(SVLAN_FILTER_DROP_INFO)
 N(PRE_CHANGEADDR) N(OFFLOAD_XSTATS_ENABLE) N(OFFLOAD_XSTATS_DISABLE)
 N(OFFLOAD_XSTATS_REPORT_USED) N(OFFLOAD_XSTATS_REPORT_DELTA)
 N(XDP_FEAT_CHANGE)
 }
#undef N
 return "UNKNOWN_NETDEV_EVENT";
}
EXPORT_SYMBOL_GPL(netdev_cmd_to_name);

static int call_netdevice_notifier(struct notifier_block *nb, unsigned long val,
       struct net_device *dev)
{
 struct netdev_notifier_info info = {
  .dev = dev,
 };

 return nb->notifier_call(nb, val, &info);
}

static int call_netdevice_register_notifiers(struct notifier_block *nb,
          struct net_device *dev)
{
 int err;

 err = call_netdevice_notifier(nb, NETDEV_REGISTER, dev);
 err = notifier_to_errno(err);
 if (err)
  return err;

 if (!(dev->flags & IFF_UP))
  return 0;

 call_netdevice_notifier(nb, NETDEV_UP, dev);
 return 0;
}

static void call_netdevice_unregister_notifiers(struct notifier_block *nb,
      struct net_device *dev)
{
 if (dev->flags & IFF_UP) {
  call_netdevice_notifier(nb, NETDEV_GOING_DOWN,
     dev);
  call_netdevice_notifier(nb, NETDEV_DOWN, dev);
 }
 call_netdevice_notifier(nb, NETDEV_UNREGISTER, dev);
}

static int call_netdevice_register_net_notifiers(struct notifier_block *nb,
       struct net *net)
{
 struct net_device *dev;
 int err;

 for_each_netdev(net, dev) {
  netdev_lock_ops(dev);
  err = call_netdevice_register_notifiers(nb, dev);
  netdev_unlock_ops(dev);
  if (err)
   goto rollback;
 }
 return 0;

rollback:
 for_each_netdev_continue_reverse(net, dev)
  call_netdevice_unregister_notifiers(nb, dev);
 return err;
}

static void call_netdevice_unregister_net_notifiers(struct notifier_block *nb,
          struct net *net)
{
 struct net_device *dev;

 for_each_netdev(net, dev)
  call_netdevice_unregister_notifiers(nb, dev);
}

static int dev_boot_phase = 1;

/**
 * register_netdevice_notifier - register a network notifier block
 * @nb: notifier
 *
 * Register a notifier to be called when network device events occur.
 * The notifier passed is linked into the kernel structures and must
 * not be reused until it has been unregistered. A negative errno code
 * is returned on a failure.
 *
 * When registered all registration and up events are replayed
 * to the new notifier to allow device to have a race free
 * view of the network device list.
 */


int register_netdevice_notifier(struct notifier_block *nb)
{
 struct net *net;
 int err;

 /* Close race with setup_net() and cleanup_net() */
 down_write(&pernet_ops_rwsem);

 /* When RTNL is removed, we need protection for netdev_chain. */
 rtnl_lock();

 err = raw_notifier_chain_register(&netdev_chain, nb);
 if (err)
  goto unlock;
 if (dev_boot_phase)
  goto unlock;
 for_each_net(net) {
  __rtnl_net_lock(net);
  err = call_netdevice_register_net_notifiers(nb, net);
  __rtnl_net_unlock(net);
  if (err)
   goto rollback;
 }

unlock:
 rtnl_unlock();
 up_write(&pernet_ops_rwsem);
 return err;

rollback:
 for_each_net_continue_reverse(net) {
  __rtnl_net_lock(net);
  call_netdevice_unregister_net_notifiers(nb, net);
  __rtnl_net_unlock(net);
 }

 raw_notifier_chain_unregister(&netdev_chain, nb);
 goto unlock;
}
EXPORT_SYMBOL(register_netdevice_notifier);

/**
 * unregister_netdevice_notifier - unregister a network notifier block
 * @nb: notifier
 *
 * Unregister a notifier previously registered by
 * register_netdevice_notifier(). The notifier is unlinked into the
 * kernel structures and may then be reused. A negative errno code
 * is returned on a failure.
 *
 * After unregistering unregister and down device events are synthesized
 * for all devices on the device list to the removed notifier to remove
 * the need for special case cleanup code.
 */


int unregister_netdevice_notifier(struct notifier_block *nb)
{
 struct net *net;
 int err;

 /* Close race with setup_net() and cleanup_net() */
 down_write(&pernet_ops_rwsem);
 rtnl_lock();
 err = raw_notifier_chain_unregister(&netdev_chain, nb);
 if (err)
  goto unlock;

 for_each_net(net) {
  __rtnl_net_lock(net);
  call_netdevice_unregister_net_notifiers(nb, net);
  __rtnl_net_unlock(net);
 }

unlock:
 rtnl_unlock();
 up_write(&pernet_ops_rwsem);
 return err;
}
EXPORT_SYMBOL(unregister_netdevice_notifier);

static int __register_netdevice_notifier_net(struct net *net,
          struct notifier_block *nb,
          bool ignore_call_fail)
{
 int err;

 err = raw_notifier_chain_register(&net->netdev_chain, nb);
 if (err)
  return err;
 if (dev_boot_phase)
  return 0;

 err = call_netdevice_register_net_notifiers(nb, net);
 if (err && !ignore_call_fail)
  goto chain_unregister;

 return 0;

chain_unregister:
 raw_notifier_chain_unregister(&net->netdev_chain, nb);
 return err;
}

static int __unregister_netdevice_notifier_net(struct net *net,
            struct notifier_block *nb)
{
 int err;

 err = raw_notifier_chain_unregister(&net->netdev_chain, nb);
 if (err)
  return err;

 call_netdevice_unregister_net_notifiers(nb, net);
 return 0;
}

/**
 * register_netdevice_notifier_net - register a per-netns network notifier block
 * @net: network namespace
 * @nb: notifier
 *
 * Register a notifier to be called when network device events occur.
 * The notifier passed is linked into the kernel structures and must
 * not be reused until it has been unregistered. A negative errno code
 * is returned on a failure.
 *
 * When registered all registration and up events are replayed
 * to the new notifier to allow device to have a race free
 * view of the network device list.
 */


int register_netdevice_notifier_net(struct net *net, struct notifier_block *nb)
{
 int err;

 rtnl_net_lock(net);
 err = __register_netdevice_notifier_net(net, nb, false);
 rtnl_net_unlock(net);

 return err;
}
EXPORT_SYMBOL(register_netdevice_notifier_net);

/**
 * unregister_netdevice_notifier_net - unregister a per-netns
 *                                     network notifier block
 * @net: network namespace
 * @nb: notifier
 *
 * Unregister a notifier previously registered by
 * register_netdevice_notifier_net(). The notifier is unlinked from the
 * kernel structures and may then be reused. A negative errno code
 * is returned on a failure.
 *
 * After unregistering unregister and down device events are synthesized
 * for all devices on the device list to the removed notifier to remove
 * the need for special case cleanup code.
 */


int unregister_netdevice_notifier_net(struct net *net,
          struct notifier_block *nb)
{
 int err;

 rtnl_net_lock(net);
 err = __unregister_netdevice_notifier_net(net, nb);
 rtnl_net_unlock(net);

 return err;
}
EXPORT_SYMBOL(unregister_netdevice_notifier_net);

static void __move_netdevice_notifier_net(struct net *src_net,
       struct net *dst_net,
       struct notifier_block *nb)
{
 __unregister_netdevice_notifier_net(src_net, nb);
 __register_netdevice_notifier_net(dst_net, nb, true);
}

static void rtnl_net_dev_lock(struct net_device *dev)
{
 bool again;

 do {
  struct net *net;

  again = false;

  /* netns might be being dismantled. */
  rcu_read_lock();
  net = dev_net_rcu(dev);
  net_passive_inc(net);
  rcu_read_unlock();

  rtnl_net_lock(net);

#ifdef CONFIG_NET_NS
  /* dev might have been moved to another netns. */
  if (!net_eq(net, rcu_access_pointer(dev->nd_net.net))) {
   rtnl_net_unlock(net);
   net_passive_dec(net);
   again = true;
  }
#endif
 } while (again);
}

static void rtnl_net_dev_unlock(struct net_device *dev)
{
 struct net *net = dev_net(dev);

 rtnl_net_unlock(net);
 net_passive_dec(net);
}

int register_netdevice_notifier_dev_net(struct net_device *dev,
     struct notifier_block *nb,
     struct netdev_net_notifier *nn)
{
 int err;

 rtnl_net_dev_lock(dev);
 err = __register_netdevice_notifier_net(dev_net(dev), nb, false);
 if (!err) {
  nn->nb = nb;
  list_add(&nn->list, &dev->net_notifier_list);
 }
 rtnl_net_dev_unlock(dev);

 return err;
}
EXPORT_SYMBOL(register_netdevice_notifier_dev_net);

int unregister_netdevice_notifier_dev_net(struct net_device *dev,
       struct notifier_block *nb,
       struct netdev_net_notifier *nn)
{
 int err;

 rtnl_net_dev_lock(dev);
 list_del(&nn->list);
 err = __unregister_netdevice_notifier_net(dev_net(dev), nb);
 rtnl_net_dev_unlock(dev);

 return err;
}
EXPORT_SYMBOL(unregister_netdevice_notifier_dev_net);

static void move_netdevice_notifiers_dev_net(struct net_device *dev,
          struct net *net)
{
 struct netdev_net_notifier *nn;

 list_for_each_entry(nn, &dev->net_notifier_list, list)
  __move_netdevice_notifier_net(dev_net(dev), net, nn->nb);
}

/**
 * call_netdevice_notifiers_info - call all network notifier blocks
 * @val: value passed unmodified to notifier function
 * @info: notifier information data
 *
 * Call all network notifier blocks.  Parameters and return value
 * are as for raw_notifier_call_chain().
 */


int call_netdevice_notifiers_info(unsigned long val,
      struct netdev_notifier_info *info)
{
 struct net *net = dev_net(info->dev);
 int ret;

 ASSERT_RTNL();

 /* Run per-netns notifier block chain first, then run the global one.
 * Hopefully, one day, the global one is going to be removed after
 * all notifier block registrators get converted to be per-netns.
 */

 ret = raw_notifier_call_chain(&net->netdev_chain, val, info);
 if (ret & NOTIFY_STOP_MASK)
  return ret;
 return raw_notifier_call_chain(&netdev_chain, val, info);
}

/**
 * call_netdevice_notifiers_info_robust - call per-netns notifier blocks
 *                                        for and rollback on error
 * @val_up: value passed unmodified to notifier function
 * @val_down: value passed unmodified to the notifier function when
 *            recovering from an error on @val_up
 * @info: notifier information data
 *
 * Call all per-netns network notifier blocks, but not notifier blocks on
 * the global notifier chain. Parameters and return value are as for
 * raw_notifier_call_chain_robust().
 */


static int
call_netdevice_notifiers_info_robust(unsigned long val_up,
         unsigned long val_down,
         struct netdev_notifier_info *info)
{
 struct net *net = dev_net(info->dev);

 ASSERT_RTNL();

 return raw_notifier_call_chain_robust(&net->netdev_chain,
           val_up, val_down, info);
}

static int call_netdevice_notifiers_extack(unsigned long val,
        struct net_device *dev,
        struct netlink_ext_ack *extack)
{
 struct netdev_notifier_info info = {
  .dev = dev,
  .extack = extack,
 };

 return call_netdevice_notifiers_info(val, &info);
}

/**
 * call_netdevice_notifiers - call all network notifier blocks
 *      @val: value passed unmodified to notifier function
 *      @dev: net_device pointer passed unmodified to notifier function
 *
 * Call all network notifier blocks.  Parameters and return value
 * are as for raw_notifier_call_chain().
 */


int call_netdevice_notifiers(unsigned long val, struct net_device *dev)
{
 return call_netdevice_notifiers_extack(val, dev, NULL);
}
EXPORT_SYMBOL(call_netdevice_notifiers);

/**
 * call_netdevice_notifiers_mtu - call all network notifier blocks
 * @val: value passed unmodified to notifier function
 * @dev: net_device pointer passed unmodified to notifier function
 * @arg: additional u32 argument passed to the notifier function
 *
 * Call all network notifier blocks.  Parameters and return value
 * are as for raw_notifier_call_chain().
 */

static int call_netdevice_notifiers_mtu(unsigned long val,
     struct net_device *dev, u32 arg)
{
 struct netdev_notifier_info_ext info = {
  .info.dev = dev,
  .ext.mtu = arg,
 };

 BUILD_BUG_ON(offsetof(struct netdev_notifier_info_ext, info) != 0);

 return call_netdevice_notifiers_info(val, &info.info);
}

#ifdef CONFIG_NET_INGRESS
static DEFINE_STATIC_KEY_FALSE(ingress_needed_key);

void net_inc_ingress_queue(void)
{
 static_branch_inc(&ingress_needed_key);
}
EXPORT_SYMBOL_GPL(net_inc_ingress_queue);

void net_dec_ingress_queue(void)
{
 static_branch_dec(&ingress_needed_key);
}
EXPORT_SYMBOL_GPL(net_dec_ingress_queue);
#endif

#ifdef CONFIG_NET_EGRESS
static DEFINE_STATIC_KEY_FALSE(egress_needed_key);

void net_inc_egress_queue(void)
{
 static_branch_inc(&egress_needed_key);
}
EXPORT_SYMBOL_GPL(net_inc_egress_queue);

void net_dec_egress_queue(void)
{
 static_branch_dec(&egress_needed_key);
}
EXPORT_SYMBOL_GPL(net_dec_egress_queue);
#endif

#ifdef CONFIG_NET_CLS_ACT
DEFINE_STATIC_KEY_FALSE(tcf_sw_enabled_key);
EXPORT_SYMBOL(tcf_sw_enabled_key);
#endif

DEFINE_STATIC_KEY_FALSE(netstamp_needed_key);
EXPORT_SYMBOL(netstamp_needed_key);
#ifdef CONFIG_JUMP_LABEL
static atomic_t netstamp_needed_deferred;
static atomic_t netstamp_wanted;
static void netstamp_clear(struct work_struct *work)
{
 int deferred = atomic_xchg(&netstamp_needed_deferred, 0);
 int wanted;

 wanted = atomic_add_return(deferred, &netstamp_wanted);
 if (wanted > 0)
  static_branch_enable(&netstamp_needed_key);
 else
  static_branch_disable(&netstamp_needed_key);
}
static DECLARE_WORK(netstamp_work, netstamp_clear);
#endif

void net_enable_timestamp(void)
{
#ifdef CONFIG_JUMP_LABEL
 int wanted = atomic_read(&netstamp_wanted);

 while (wanted > 0) {
  if (atomic_try_cmpxchg(&netstamp_wanted, &wanted, wanted + 1))
   return;
 }
 atomic_inc(&netstamp_needed_deferred);
 schedule_work(&netstamp_work);
#else
 static_branch_inc(&netstamp_needed_key);
#endif
}
EXPORT_SYMBOL(net_enable_timestamp);

void net_disable_timestamp(void)
{
#ifdef CONFIG_JUMP_LABEL
 int wanted = atomic_read(&netstamp_wanted);

 while (wanted > 1) {
  if (atomic_try_cmpxchg(&netstamp_wanted, &wanted, wanted - 1))
   return;
 }
 atomic_dec(&netstamp_needed_deferred);
 schedule_work(&netstamp_work);
#else
 static_branch_dec(&netstamp_needed_key);
#endif
}
EXPORT_SYMBOL(net_disable_timestamp);

static inline void net_timestamp_set(struct sk_buff *skb)
{
 skb->tstamp = 0;
 skb->tstamp_type = SKB_CLOCK_REALTIME;
 if (static_branch_unlikely(&netstamp_needed_key))
  skb->tstamp = ktime_get_real();
}

#define net_timestamp_check(COND, SKB)    \
 if (static_branch_unlikely(&netstamp_needed_key)) { \
  if ((COND) && !(SKB)->tstamp)   \
   (SKB)->tstamp = ktime_get_real(); \
 }       \

bool is_skb_forwardable(const struct net_device *dev, const struct sk_buff *skb)
{
 return __is_skb_forwardable(dev, skb, true);
}
EXPORT_SYMBOL_GPL(is_skb_forwardable);

static int __dev_forward_skb2(struct net_device *dev, struct sk_buff *skb,
         bool check_mtu)
{
 int ret = ____dev_forward_skb(dev, skb, check_mtu);

 if (likely(!ret)) {
  skb->protocol = eth_type_trans(skb, dev);
  skb_postpull_rcsum(skb, eth_hdr(skb), ETH_HLEN);
 }

 return ret;
}

int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
{
 return __dev_forward_skb2(dev, skb, true);
}
EXPORT_SYMBOL_GPL(__dev_forward_skb);

/**
 * dev_forward_skb - loopback an skb to another netif
 *
 * @dev: destination network device
 * @skb: buffer to forward
 *
 * return values:
 * NET_RX_SUCCESS (no congestion)
 * NET_RX_DROP     (packet was dropped, but freed)
 *
 * dev_forward_skb can be used for injecting an skb from the
 * start_xmit function of one device into the receive queue
 * of another device.
 *
 * The receiving device may be in another namespace, so
 * we have to clear all information in the skb that could
 * impact namespace isolation.
 */

int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
{
 return __dev_forward_skb(dev, skb) ?: netif_rx_internal(skb);
}
EXPORT_SYMBOL_GPL(dev_forward_skb);

int dev_forward_skb_nomtu(struct net_device *dev, struct sk_buff *skb)
{
 return __dev_forward_skb2(dev, skb, false) ?: netif_rx_internal(skb);
}

static inline int deliver_skb(struct sk_buff *skb,
         struct packet_type *pt_prev,
         struct net_device *orig_dev)
{
 if (unlikely(skb_orphan_frags_rx(skb, GFP_ATOMIC)))
  return -ENOMEM;
--> --------------------

--> maximum size reached

--> --------------------

Messung V0.5
C=96 H=95 G=95

¤ Dauer der Verarbeitung: 0.51 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.