Release 4.11 net/ipv4/udp_diag.c
/*
* udp_diag.c Module for monitoring UDP transport protocols sockets.
*
* Authors: Pavel Emelyanov, <xemul@parallels.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include <linux/module.h>
#include <linux/inet_diag.h>
#include <linux/udp.h>
#include <net/udp.h>
#include <net/udplite.h>
#include <linux/sock_diag.h>
static int sk_diag_dump(struct sock *sk, struct sk_buff *skb,
struct netlink_callback *cb,
const struct inet_diag_req_v2 *req,
struct nlattr *bc, bool net_admin)
{
if (!inet_diag_bc_sk(bc, sk))
return 0;
return inet_sk_diag_fill(sk, NULL, skb, req,
sk_user_ns(NETLINK_CB(cb->skb).sk),
NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq, NLM_F_MULTI, cb->nlh, net_admin);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Pavel Emelyanov | 76 | 80.00% | 2 | 28.57% |
Eric W. Biedermann | 12 | 12.63% | 2 | 28.57% |
Lorenzo Colitti | 5 | 5.26% | 1 | 14.29% |
Eric Dumazet | 1 | 1.05% | 1 | 14.29% |
Patrick McHardy | 1 | 1.05% | 1 | 14.29% |
Total | 95 | 100.00% | 7 | 100.00% |
static int udp_dump_one(struct udp_table *tbl, struct sk_buff *in_skb,
const struct nlmsghdr *nlh,
const struct inet_diag_req_v2 *req)
{
int err = -EINVAL;
struct sock *sk = NULL;
struct sk_buff *rep;
struct net *net = sock_net(in_skb->sk);
rcu_read_lock();
if (req->sdiag_family == AF_INET)
sk = __udp4_lib_lookup(net,
req->id.idiag_src[0], req->id.idiag_sport,
req->id.idiag_dst[0], req->id.idiag_dport,
req->id.idiag_if, tbl, NULL);
#if IS_ENABLED(CONFIG_IPV6)
else if (req->sdiag_family == AF_INET6)
sk = __udp6_lib_lookup(net,
(struct in6_addr *)req->id.idiag_src,
req->id.idiag_sport,
(struct in6_addr *)req->id.idiag_dst,
req->id.idiag_dport,
req->id.idiag_if, tbl, NULL);
#endif
if (sk && !atomic_inc_not_zero(&sk->sk_refcnt))
sk = NULL;
rcu_read_unlock();
err = -ENOENT;
if (!sk)
goto out_nosk;
err = sock_diag_check_cookie(sk, req->id.idiag_cookie);
if (err)
goto out;
err = -ENOMEM;
rep = nlmsg_new(sizeof(struct inet_diag_msg) +
sizeof(struct inet_diag_meminfo) + 64,
GFP_KERNEL);
if (!rep)
goto out;
err = inet_sk_diag_fill(sk, NULL, rep, req,
sk_user_ns(NETLINK_CB(in_skb).sk),
NETLINK_CB(in_skb).portid,
nlh->nlmsg_seq, 0, nlh,
netlink_net_capable(in_skb, CAP_NET_ADMIN));
if (err < 0) {
WARN_ON(err == -EMSGSIZE);
kfree_skb(rep);
goto out;
}
err = netlink_unicast(net->diag_nlsk, rep, NETLINK_CB(in_skb).portid,
MSG_DONTWAIT);
if (err > 0)
err = 0;
out:
if (sk)
sock_put(sk);
out_nosk:
return err;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Pavel Emelyanov | 318 | 82.38% | 5 | 33.33% |
Eric Dumazet | 26 | 6.74% | 2 | 13.33% |
Andrey Vagin | 17 | 4.40% | 1 | 6.67% |
Eric W. Biedermann | 11 | 2.85% | 2 | 13.33% |
Lorenzo Colitti | 7 | 1.81% | 1 | 6.67% |
Craig Gallek | 4 | 1.04% | 1 | 6.67% |
Hong Zhi Guo | 1 | 0.26% | 1 | 6.67% |
Ian Morris | 1 | 0.26% | 1 | 6.67% |
Patrick McHardy | 1 | 0.26% | 1 | 6.67% |
Total | 386 | 100.00% | 15 | 100.00% |
static void udp_dump(struct udp_table *table, struct sk_buff *skb,
struct netlink_callback *cb,
const struct inet_diag_req_v2 *r, struct nlattr *bc)
{
bool net_admin = netlink_net_capable(cb->skb, CAP_NET_ADMIN);
struct net *net = sock_net(skb->sk);
int num, s_num, slot, s_slot;
s_slot = cb->args[0];
num = s_num = cb->args[1];
for (slot = s_slot; slot <= table->mask; s_num = 0, slot++) {
struct udp_hslot *hslot = &table->hash[slot];
struct sock *sk;
num = 0;
if (hlist_empty(&hslot->head))
continue;
spin_lock_bh(&hslot->lock);
sk_for_each(sk, &hslot->head) {
struct inet_sock *inet = inet_sk(sk);
if (!net_eq(sock_net(sk), net))
continue;
if (num < s_num)
goto next;
if (!(r->idiag_states & (1 << sk->sk_state)))
goto next;
if (r->sdiag_family != AF_UNSPEC &&
sk->sk_family != r->sdiag_family)
goto next;
if (r->id.idiag_sport != inet->inet_sport &&
r->id.idiag_sport)
goto next;
if (r->id.idiag_dport != inet->inet_dport &&
r->id.idiag_dport)
goto next;
if (sk_diag_dump(sk, skb, cb, r, bc, net_admin) < 0) {
spin_unlock_bh(&hslot->lock);
goto done;
}
next:
num++;
}
spin_unlock_bh(&hslot->lock);
}
done:
cb->args[0] = slot;
cb->args[1] = num;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Pavel Emelyanov | 273 | 81.74% | 3 | 37.50% |
Andrey Vagin | 26 | 7.78% | 1 | 12.50% |
Eric Dumazet | 17 | 5.09% | 2 | 25.00% |
Lorenzo Colitti | 14 | 4.19% | 1 | 12.50% |
Herbert Xu | 4 | 1.20% | 1 | 12.50% |
Total | 334 | 100.00% | 8 | 100.00% |
static void udp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
const struct inet_diag_req_v2 *r, struct nlattr *bc)
{
udp_dump(&udp_table, skb, cb, r, bc);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Pavel Emelyanov | 40 | 97.56% | 2 | 66.67% |
Eric Dumazet | 1 | 2.44% | 1 | 33.33% |
Total | 41 | 100.00% | 3 | 100.00% |
static int udp_diag_dump_one(struct sk_buff *in_skb, const struct nlmsghdr *nlh,
const struct inet_diag_req_v2 *req)
{
return udp_dump_one(&udp_table, in_skb, nlh, req);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Pavel Emelyanov | 35 | 97.22% | 2 | 66.67% |
Eric Dumazet | 1 | 2.78% | 1 | 33.33% |
Total | 36 | 100.00% | 3 | 100.00% |
static void udp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
void *info)
{
r->idiag_rqueue = sk_rmem_alloc_get(sk);
r->idiag_wqueue = sk_wmem_alloc_get(sk);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Shan Wei | 38 | 100.00% | 1 | 100.00% |
Total | 38 | 100.00% | 1 | 100.00% |
#ifdef CONFIG_INET_DIAG_DESTROY
static int __udp_diag_destroy(struct sk_buff *in_skb,
const struct inet_diag_req_v2 *req,
struct udp_table *tbl)
{
struct net *net = sock_net(in_skb->sk);
struct sock *sk;
int err;
rcu_read_lock();
if (req->sdiag_family == AF_INET)
sk = __udp4_lib_lookup(net,
req->id.idiag_dst[0], req->id.idiag_dport,
req->id.idiag_src[0], req->id.idiag_sport,
req->id.idiag_if, tbl, NULL);
#if IS_ENABLED(CONFIG_IPV6)
else if (req->sdiag_family == AF_INET6) {
if (ipv6_addr_v4mapped((struct in6_addr *)req->id.idiag_dst) &&
ipv6_addr_v4mapped((struct in6_addr *)req->id.idiag_src))
sk = __udp4_lib_lookup(net,
req->id.idiag_dst[3], req->id.idiag_dport,
req->id.idiag_src[3], req->id.idiag_sport,
req->id.idiag_if, tbl, NULL);
else
sk = __udp6_lib_lookup(net,
(struct in6_addr *)req->id.idiag_dst,
req->id.idiag_dport,
(struct in6_addr *)req->id.idiag_src,
req->id.idiag_sport,
req->id.idiag_if, tbl, NULL);
}
#endif
else {
rcu_read_unlock();
return -EINVAL;
}
if (sk && !atomic_inc_not_zero(&sk->sk_refcnt))
sk = NULL;
rcu_read_unlock();
if (!sk)
return -ENOENT;
if (sock_diag_check_cookie(sk, req->id.idiag_cookie)) {
sock_put(sk);
return -ENOENT;
}
err = sock_diag_destroy(sk, ECONNABORTED);
sock_put(sk);
return err;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
David Ahern | 326 | 99.39% | 1 | 50.00% |
Lorenzo Colitti | 2 | 0.61% | 1 | 50.00% |
Total | 328 | 100.00% | 2 | 100.00% |
static int udp_diag_destroy(struct sk_buff *in_skb,
const struct inet_diag_req_v2 *req)
{
return __udp_diag_destroy(in_skb, req, &udp_table);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
David Ahern | 28 | 100.00% | 1 | 100.00% |
Total | 28 | 100.00% | 1 | 100.00% |
static int udplite_diag_destroy(struct sk_buff *in_skb,
const struct inet_diag_req_v2 *req)
{
return __udp_diag_destroy(in_skb, req, &udplite_table);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
David Ahern | 28 | 100.00% | 1 | 100.00% |
Total | 28 | 100.00% | 1 | 100.00% |
#endif
static const struct inet_diag_handler udp_diag_handler = {
.dump = udp_diag_dump,
.dump_one = udp_diag_dump_one,
.idiag_get_info = udp_diag_get_info,
.idiag_type = IPPROTO_UDP,
.idiag_info_size = 0,
#ifdef CONFIG_INET_DIAG_DESTROY
.destroy = udp_diag_destroy,
#endif
};
static void udplite_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
const struct inet_diag_req_v2 *r,
struct nlattr *bc)
{
udp_dump(&udplite_table, skb, cb, r, bc);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Pavel Emelyanov | 40 | 97.56% | 2 | 66.67% |
Eric Dumazet | 1 | 2.44% | 1 | 33.33% |
Total | 41 | 100.00% | 3 | 100.00% |
static int udplite_diag_dump_one(struct sk_buff *in_skb, const struct nlmsghdr *nlh,
const struct inet_diag_req_v2 *req)
{
return udp_dump_one(&udplite_table, in_skb, nlh, req);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Pavel Emelyanov | 35 | 97.22% | 2 | 66.67% |
Eric Dumazet | 1 | 2.78% | 1 | 33.33% |
Total | 36 | 100.00% | 3 | 100.00% |
static const struct inet_diag_handler udplite_diag_handler = {
.dump = udplite_diag_dump,
.dump_one = udplite_diag_dump_one,
.idiag_get_info = udp_diag_get_info,
.idiag_type = IPPROTO_UDPLITE,
.idiag_info_size = 0,
#ifdef CONFIG_INET_DIAG_DESTROY
.destroy = udplite_diag_destroy,
#endif
};
static int __init udp_diag_init(void)
{
int err;
err = inet_diag_register(&udp_diag_handler);
if (err)
goto out;
err = inet_diag_register(&udplite_diag_handler);
if (err)
goto out_lite;
out:
return err;
out_lite:
inet_diag_unregister(&udp_diag_handler);
goto out;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Pavel Emelyanov | 58 | 100.00% | 1 | 100.00% |
Total | 58 | 100.00% | 1 | 100.00% |
static void __exit udp_diag_exit(void)
{
inet_diag_unregister(&udplite_diag_handler);
inet_diag_unregister(&udp_diag_handler);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Pavel Emelyanov | 21 | 100.00% | 1 | 100.00% |
Total | 21 | 100.00% | 1 | 100.00% |
module_init(udp_diag_init);
module_exit(udp_diag_exit);
MODULE_LICENSE("GPL");
MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 2-17 /* AF_INET - IPPROTO_UDP */);
MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 2-136 /* AF_INET - IPPROTO_UDPLITE */);
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Pavel Emelyanov | 998 | 61.57% | 7 | 31.82% |
David Ahern | 411 | 25.35% | 1 | 4.55% |
Shan Wei | 48 | 2.96% | 1 | 4.55% |
Eric Dumazet | 48 | 2.96% | 2 | 9.09% |
Andrey Vagin | 43 | 2.65% | 1 | 4.55% |
Lorenzo Colitti | 28 | 1.73% | 2 | 9.09% |
Eric W. Biedermann | 23 | 1.42% | 2 | 9.09% |
Craig Gallek | 14 | 0.86% | 2 | 9.09% |
Herbert Xu | 4 | 0.25% | 1 | 4.55% |
Patrick McHardy | 2 | 0.12% | 1 | 4.55% |
Hong Zhi Guo | 1 | 0.06% | 1 | 4.55% |
Ian Morris | 1 | 0.06% | 1 | 4.55% |
Total | 1621 | 100.00% | 22 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.