Release 4.11 drivers/net/nlmon.c
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/netdevice.h>
#include <linux/netlink.h>
#include <net/net_namespace.h>
#include <linux/if_arp.h>
#include <net/rtnetlink.h>
struct pcpu_lstats {
u64 packets;
u64 bytes;
struct u64_stats_sync syncp;
};
static netdev_tx_t nlmon_xmit(struct sk_buff *skb, struct net_device *dev)
{
int len = skb->len;
struct pcpu_lstats *stats = this_cpu_ptr(dev->lstats);
u64_stats_update_begin(&stats->syncp);
stats->bytes += len;
stats->packets++;
u64_stats_update_end(&stats->syncp);
dev_kfree_skb(skb);
return NETDEV_TX_OK;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Daniel Borkmann | 70 | 100.00% | 1 | 100.00% |
Total | 70 | 100.00% | 1 | 100.00% |
static int nlmon_dev_init(struct net_device *dev)
{
dev->lstats = netdev_alloc_pcpu_stats(struct pcpu_lstats);
return dev->lstats == NULL ? -ENOMEM : 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Daniel Borkmann | 32 | 96.97% | 1 | 50.00% |
Américo Wang | 1 | 3.03% | 1 | 50.00% |
Total | 33 | 100.00% | 2 | 100.00% |
static void nlmon_dev_uninit(struct net_device *dev)
{
free_percpu(dev->lstats);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Daniel Borkmann | 18 | 100.00% | 1 | 100.00% |
Total | 18 | 100.00% | 1 | 100.00% |
struct nlmon {
struct netlink_tap nt;
};
static int nlmon_open(struct net_device *dev)
{
struct nlmon *nlmon = netdev_priv(dev);
nlmon->nt.dev = dev;
nlmon->nt.module = THIS_MODULE;
return netlink_add_tap(&nlmon->nt);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jiri Pirko | 29 | 63.04% | 1 | 50.00% |
Daniel Borkmann | 17 | 36.96% | 1 | 50.00% |
Total | 46 | 100.00% | 2 | 100.00% |
static int nlmon_close(struct net_device *dev)
{
struct nlmon *nlmon = netdev_priv(dev);
return netlink_remove_tap(&nlmon->nt);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Daniel Borkmann | 17 | 56.67% | 1 | 50.00% |
Jiri Pirko | 13 | 43.33% | 1 | 50.00% |
Total | 30 | 100.00% | 2 | 100.00% |
static void
nlmon_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats)
{
int i;
u64 bytes = 0, packets = 0;
for_each_possible_cpu(i) {
const struct pcpu_lstats *nl_stats;
u64 tbytes, tpackets;
unsigned int start;
nl_stats = per_cpu_ptr(dev->lstats, i);
do {
start = u64_stats_fetch_begin_irq(&nl_stats->syncp);
tbytes = nl_stats->bytes;
tpackets = nl_stats->packets;
} while (u64_stats_fetch_retry_irq(&nl_stats->syncp, start));
packets += tpackets;
bytes += tbytes;
}
stats->rx_packets = packets;
stats->tx_packets = 0;
stats->rx_bytes = bytes;
stats->tx_bytes = 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Daniel Borkmann | 127 | 97.69% | 1 | 33.33% |
Eric W. Biedermann | 2 | 1.54% | 1 | 33.33% |
Stephen Hemminger | 1 | 0.77% | 1 | 33.33% |
Total | 130 | 100.00% | 3 | 100.00% |
static u32 always_on(struct net_device *dev)
{
return 1;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Daniel Borkmann | 14 | 100.00% | 1 | 100.00% |
Total | 14 | 100.00% | 1 | 100.00% |
static const struct ethtool_ops nlmon_ethtool_ops = {
.get_link = always_on,
};
static const struct net_device_ops nlmon_ops = {
.ndo_init = nlmon_dev_init,
.ndo_uninit = nlmon_dev_uninit,
.ndo_open = nlmon_open,
.ndo_stop = nlmon_close,
.ndo_start_xmit = nlmon_xmit,
.ndo_get_stats64 = nlmon_get_stats64,
};
static void nlmon_setup(struct net_device *dev)
{
dev->type = ARPHRD_NETLINK;
dev->priv_flags |= IFF_NO_QUEUE;
dev->netdev_ops = &nlmon_ops;
dev->ethtool_ops = &nlmon_ethtool_ops;
dev->destructor = free_netdev;
dev->features = NETIF_F_SG | NETIF_F_FRAGLIST |
NETIF_F_HIGHDMA | NETIF_F_LLTX;
dev->flags = IFF_NOARP;
/* That's rather a softlimit here, which, of course,
* can be altered. Not a real MTU, but what is to be
* expected in most cases.
*/
dev->mtu = NLMSG_GOODSIZE;
dev->min_mtu = sizeof(struct nlmsghdr);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Daniel Borkmann | 65 | 83.33% | 2 | 50.00% |
Zhang Shengju | 10 | 12.82% | 1 | 25.00% |
Phil Sutter | 3 | 3.85% | 1 | 25.00% |
Total | 78 | 100.00% | 4 | 100.00% |
static int nlmon_validate(struct nlattr *tb[], struct nlattr *data[])
{
if (tb[IFLA_ADDRESS])
return -EINVAL;
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jiri Pirko | 21 | 65.62% | 1 | 50.00% |
Daniel Borkmann | 11 | 34.38% | 1 | 50.00% |
Total | 32 | 100.00% | 2 | 100.00% |
static struct rtnl_link_ops nlmon_link_ops __read_mostly = {
.kind = "nlmon",
.priv_size = sizeof(struct nlmon),
.setup = nlmon_setup,
.validate = nlmon_validate,
};
static __init int nlmon_register(void)
{
return rtnl_link_register(&nlmon_link_ops);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Jiri Pirko | 12 | 75.00% | 1 | 50.00% |
Daniel Borkmann | 4 | 25.00% | 1 | 50.00% |
Total | 16 | 100.00% | 2 | 100.00% |
static __exit void nlmon_unregister(void)
{
rtnl_link_unregister(&nlmon_link_ops);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Daniel Borkmann | 12 | 80.00% | 1 | 50.00% |
Jiri Pirko | 3 | 20.00% | 1 | 50.00% |
Total | 15 | 100.00% | 2 | 100.00% |
module_init(nlmon_register);
module_exit(nlmon_unregister);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Daniel Borkmann <dborkman@redhat.com>");
MODULE_AUTHOR("Mathieu Geli <geli@enseirb.fr>");
MODULE_DESCRIPTION("Netlink monitoring device");
MODULE_ALIAS_RTNL_LINK("nlmon");
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Daniel Borkmann | 507 | 78.60% | 2 | 25.00% |
Jiri Pirko | 121 | 18.76% | 1 | 12.50% |
Zhang Shengju | 10 | 1.55% | 1 | 12.50% |
Phil Sutter | 3 | 0.47% | 1 | 12.50% |
Eric W. Biedermann | 2 | 0.31% | 1 | 12.50% |
Stephen Hemminger | 1 | 0.16% | 1 | 12.50% |
Américo Wang | 1 | 0.16% | 1 | 12.50% |
Total | 645 | 100.00% | 8 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.