From: Pavel Emelyanov <xemul@parallels.com>
To: David Miller <davem@davemloft.net>,
Linux Netdev List <netdev@vger.kernel.org>
Subject: [PATCH 3/13] sock_diag: Generalize requests cookies managements
Date: Thu, 15 Dec 2011 16:43:44 +0400 [thread overview]
Message-ID: <4EE9EB80.7020909@parallels.com> (raw)
In-Reply-To: <4EE9EB2A.4040909@parallels.com>
The sk address is used as a cookie between dump/get_exact calls.
It will be required for unix socket sdumping, so move it from
inet_diag to sock_diag.
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
---
include/linux/inet_diag.h | 1 -
include/linux/sock_diag.h | 3 +++
net/core/sock_diag.c | 19 +++++++++++++++++++
net/ipv4/inet_diag.c | 23 ++++-------------------
net/ipv4/udp_diag.c | 2 +-
5 files changed, 27 insertions(+), 21 deletions(-)
diff --git a/include/linux/inet_diag.h b/include/linux/inet_diag.h
index a27e621..afa5d5c 100644
--- a/include/linux/inet_diag.h
+++ b/include/linux/inet_diag.h
@@ -168,7 +168,6 @@ int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo,
struct inet_diag_req *req);
int inet_diag_bc_sk(const struct nlattr *_bc, struct sock *sk);
-int inet_diag_check_cookie(struct sock *sk, struct inet_diag_req *req);
extern int inet_diag_register(const struct inet_diag_handler *handler);
extern void inet_diag_unregister(const struct inet_diag_handler *handler);
diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
index 7999778..379d5dc 100644
--- a/include/linux/sock_diag.h
+++ b/include/linux/sock_diag.h
@@ -22,5 +22,8 @@ void sock_diag_unregister(struct sock_diag_handler *h);
void sock_diag_register_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh));
void sock_diag_unregister_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh));
+int sock_diag_check_cookie(void *sk, __u32 *cookie);
+void sock_diag_save_cookie(void *sk, __u32 *cookie);
+
extern struct sock *sock_diag_nlsk;
#endif
diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
index cee96f3..711bdef 100644
--- a/net/core/sock_diag.c
+++ b/net/core/sock_diag.c
@@ -12,6 +12,25 @@ static struct sock_diag_handler *sock_diag_handlers[AF_MAX];
static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
static DEFINE_MUTEX(sock_diag_table_mutex);
+int sock_diag_check_cookie(void *sk, __u32 *cookie)
+{
+ if ((cookie[0] != INET_DIAG_NOCOOKIE ||
+ cookie[1] != INET_DIAG_NOCOOKIE) &&
+ ((u32)(unsigned long)sk != cookie[0] ||
+ (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
+ return -ESTALE;
+ else
+ return 0;
+}
+EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
+
+void sock_diag_save_cookie(void *sk, __u32 *cookie)
+{
+ cookie[0] = (u32)(unsigned long)sk;
+ cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
+}
+EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
+
void sock_diag_register_inet_compat(int (*fn)(struct sk_buff *skb, struct nlmsghdr *nlh))
{
mutex_lock(&sock_diag_table_mutex);
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index fa27313..fb2e47f 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -102,8 +102,7 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
r->idiag_retrans = 0;
r->id.idiag_if = sk->sk_bound_dev_if;
- r->id.idiag_cookie[0] = (u32)(unsigned long)sk;
- r->id.idiag_cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
+ sock_diag_save_cookie(sk, r->id.idiag_cookie);
r->id.idiag_sport = inet->inet_sport;
r->id.idiag_dport = inet->inet_dport;
@@ -221,8 +220,7 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
r->idiag_family = tw->tw_family;
r->idiag_retrans = 0;
r->id.idiag_if = tw->tw_bound_dev_if;
- r->id.idiag_cookie[0] = (u32)(unsigned long)tw;
- r->id.idiag_cookie[1] = (u32)(((unsigned long)tw >> 31) >> 1);
+ sock_diag_save_cookie(tw, r->id.idiag_cookie);
r->id.idiag_sport = tw->tw_sport;
r->id.idiag_dport = tw->tw_dport;
r->id.idiag_src[0] = tw->tw_rcv_saddr;
@@ -261,18 +259,6 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
return inet_csk_diag_fill(sk, skb, r, pid, seq, nlmsg_flags, unlh);
}
-int inet_diag_check_cookie(struct sock *sk, struct inet_diag_req *req)
-{
- if ((req->id.idiag_cookie[0] != INET_DIAG_NOCOOKIE ||
- req->id.idiag_cookie[1] != INET_DIAG_NOCOOKIE) &&
- ((u32)(unsigned long)sk != req->id.idiag_cookie[0] ||
- (u32)((((unsigned long)sk) >> 31) >> 1) != req->id.idiag_cookie[1]))
- return -ESTALE;
- else
- return 0;
-}
-EXPORT_SYMBOL_GPL(inet_diag_check_cookie);
-
int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo, struct sk_buff *in_skb,
const struct nlmsghdr *nlh, struct inet_diag_req *req)
{
@@ -304,7 +290,7 @@ int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo, struct sk_buff *in_s
if (sk == NULL)
goto out_nosk;
- err = inet_diag_check_cookie(sk, req);
+ err = sock_diag_check_cookie(sk, req->id.idiag_cookie);
if (err)
goto out;
@@ -617,8 +603,7 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
r->idiag_retrans = req->retrans;
r->id.idiag_if = sk->sk_bound_dev_if;
- r->id.idiag_cookie[0] = (u32)(unsigned long)req;
- r->id.idiag_cookie[1] = (u32)(((unsigned long)req >> 31) >> 1);
+ sock_diag_save_cookie(req, r->id.idiag_cookie);
tmo = req->expires - jiffies;
if (tmo < 0)
diff --git a/net/ipv4/udp_diag.c b/net/ipv4/udp_diag.c
index fe9db86..69f8a7c 100644
--- a/net/ipv4/udp_diag.c
+++ b/net/ipv4/udp_diag.c
@@ -57,7 +57,7 @@ static int udp_dump_one(struct udp_table *tbl, struct sk_buff *in_skb,
if (sk == NULL)
goto out_nosk;
- err = inet_diag_check_cookie(sk, req);
+ err = sock_diag_check_cookie(sk, req->id.idiag_cookie);
if (err)
goto out;
--
1.5.5.6
next prev parent reply other threads:[~2011-12-15 12:43 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-15 12:42 [PATCH 0/13] Dumping AF_UNIX sockets via netlink Pavel Emelyanov
2011-12-15 12:42 ` [PATCH 1/13] sock_diag: Move the SOCK_DIAG_BY_FAMILY cmd declaration Pavel Emelyanov
2011-12-15 12:43 ` [PATCH 2/13] sock_diag: Fix module netlink aliases Pavel Emelyanov
2011-12-15 12:43 ` Pavel Emelyanov [this message]
2011-12-15 12:44 ` [PATCH 4/13] af_unix: Export stuff required for diag module Pavel Emelyanov
2011-12-15 12:44 ` [PATCH 5/13] unix_diag: Basic module skeleton Pavel Emelyanov
2011-12-15 12:44 ` [PATCH 6/13] unix_diag: Dumping all sockets core Pavel Emelyanov
2011-12-15 12:45 ` [PATCH 7/13] unix_diag: Dumping exact socket core Pavel Emelyanov
2011-12-15 12:45 ` [PATCH 8/13] unix_diag: Unix socket name NLA Pavel Emelyanov
2011-12-15 12:45 ` [PATCH 9/13] unix_diag: Unix inode info NLA Pavel Emelyanov
2011-12-15 12:45 ` [PATCH 10/13] unix_diag: Unix peer inode NLA Pavel Emelyanov
2011-12-15 12:46 ` [PATCH 11/13] unix_diag: Pending connections IDs NLA Pavel Emelyanov
2011-12-15 12:46 ` [PATCH 12/13] unix_diag: Receive queue lenght NLA Pavel Emelyanov
2011-12-15 12:46 ` [PATCH 13/13] unix_diag: Write it into kbuild Pavel Emelyanov
2011-12-15 13:28 ` [PATCH] iproute: Dump unix sockets via netlink Pavel Emelyanov
2012-01-20 20:51 ` Stephen Hemminger
2011-12-16 18:50 ` [PATCH 0/13] Dumping AF_UNIX " David Miller
2011-12-17 9:54 ` Pavel Emelyanov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4EE9EB80.7020909@parallels.com \
--to=xemul@parallels.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).