From 816009c22fff302a532596c5eaf368b2d31a4e07 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Fri, 9 Dec 2011 06:21:53 +0000 Subject: [PATCH] --- yaml --- r: 278542 b: refs/heads/master c: b005ab4ef8805dc4604848c9d2ccca9d71f8fc46 h: refs/heads/master v: v3 --- [refs] | 2 +- trunk/include/linux/inet_diag.h | 2 ++ trunk/net/ipv4/inet_diag.c | 19 ++++++++++++++----- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/[refs] b/[refs] index 984e0b96cba3..1db76c6bfe74 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 87c22ea52e1bb467f58b3e9a71509fccb70c7bd3 +refs/heads/master: b005ab4ef8805dc4604848c9d2ccca9d71f8fc46 diff --git a/trunk/include/linux/inet_diag.h b/trunk/include/linux/inet_diag.h index 851feff0747f..503674738368 100644 --- a/trunk/include/linux/inet_diag.h +++ b/trunk/include/linux/inet_diag.h @@ -144,6 +144,8 @@ struct inet_diag_handler { __u16 idiag_type; }; +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); #endif /* __KERNEL__ */ diff --git a/trunk/net/ipv4/inet_diag.c b/trunk/net/ipv4/inet_diag.c index bd3f661803a7..ba3ae1f73abf 100644 --- a/trunk/net/ipv4/inet_diag.c +++ b/trunk/net/ipv4/inet_diag.c @@ -246,6 +246,18 @@ 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); + static int inet_diag_get_exact(struct sk_buff *in_skb, const struct nlmsghdr *nlh, struct inet_diag_req *req) @@ -288,11 +300,8 @@ static int inet_diag_get_exact(struct sk_buff *in_skb, if (sk == NULL) goto unlock; - err = -ESTALE; - 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])) + err = inet_diag_check_cookie(sk, req); + if (err) goto out; err = -ENOMEM;