nlmon.c (58e16d792a6a8c6b750f637a4649967fcac853dc) | nlmon.c (3ed912264f1c057be6afcbbd2a362787ee020a92) |
---|---|
1// SPDX-License-Identifier: GPL-2.0-only 2#include <linux/module.h> 3#include <linux/kernel.h> 4#include <linux/netdevice.h> 5#include <linux/netlink.h> 6#include <net/net_namespace.h> 7#include <linux/if_arp.h> 8#include <net/rtnetlink.h> 9 10static netdev_tx_t nlmon_xmit(struct sk_buff *skb, struct net_device *dev) 11{ | 1// SPDX-License-Identifier: GPL-2.0-only 2#include <linux/module.h> 3#include <linux/kernel.h> 4#include <linux/netdevice.h> 5#include <linux/netlink.h> 6#include <net/net_namespace.h> 7#include <linux/if_arp.h> 8#include <net/rtnetlink.h> 9 10static netdev_tx_t nlmon_xmit(struct sk_buff *skb, struct net_device *dev) 11{ |
12 int len = skb->len; 13 struct pcpu_lstats *stats = this_cpu_ptr(dev->lstats); | 12 dev_lstats_add(dev, skb->len); |
14 | 13 |
15 u64_stats_update_begin(&stats->syncp); 16 stats->bytes += len; 17 stats->packets++; 18 u64_stats_update_end(&stats->syncp); 19 | |
20 dev_kfree_skb(skb); 21 22 return NETDEV_TX_OK; 23} 24 25static int nlmon_dev_init(struct net_device *dev) 26{ 27 dev->lstats = netdev_alloc_pcpu_stats(struct pcpu_lstats); --- 23 unchanged lines hidden (view full) --- 51 struct nlmon *nlmon = netdev_priv(dev); 52 53 return netlink_remove_tap(&nlmon->nt); 54} 55 56static void 57nlmon_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) 58{ | 14 dev_kfree_skb(skb); 15 16 return NETDEV_TX_OK; 17} 18 19static int nlmon_dev_init(struct net_device *dev) 20{ 21 dev->lstats = netdev_alloc_pcpu_stats(struct pcpu_lstats); --- 23 unchanged lines hidden (view full) --- 45 struct nlmon *nlmon = netdev_priv(dev); 46 47 return netlink_remove_tap(&nlmon->nt); 48} 49 50static void 51nlmon_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) 52{ |
59 int i; 60 u64 bytes = 0, packets = 0; | 53 u64 packets, bytes; |
61 | 54 |
62 for_each_possible_cpu(i) { 63 const struct pcpu_lstats *nl_stats; 64 u64 tbytes, tpackets; 65 unsigned int start; | 55 dev_lstats_read(dev, &packets, &bytes); |
66 | 56 |
67 nl_stats = per_cpu_ptr(dev->lstats, i); 68 69 do { 70 start = u64_stats_fetch_begin_irq(&nl_stats->syncp); 71 tbytes = nl_stats->bytes; 72 tpackets = nl_stats->packets; 73 } while (u64_stats_fetch_retry_irq(&nl_stats->syncp, start)); 74 75 packets += tpackets; 76 bytes += tbytes; 77 } 78 | |
79 stats->rx_packets = packets; 80 stats->tx_packets = 0; 81 82 stats->rx_bytes = bytes; 83 stats->tx_bytes = 0; 84} 85 86static u32 always_on(struct net_device *dev) --- 71 unchanged lines hidden --- | 57 stats->rx_packets = packets; 58 stats->tx_packets = 0; 59 60 stats->rx_bytes = bytes; 61 stats->tx_bytes = 0; 62} 63 64static u32 always_on(struct net_device *dev) --- 71 unchanged lines hidden --- |