Skip to content

Commit

Permalink
inet_diag: Export inet diag cookie checking routine
Browse files Browse the repository at this point in the history
The netlink diag susbsys stores sk address bits in the nl message
as a "cookie" and uses one when dumps details about particular
socket.

The same will be required for udp diag module, so introduce a heler
in inet_diag module

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Pavel Emelyanov authored and David S. Miller committed Dec 9, 2011
1 parent 87c22ea commit b005ab4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions include/linux/inet_diag.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__ */
Expand Down
19 changes: 14 additions & 5 deletions net/ipv4/inet_diag.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit b005ab4

Please sign in to comment.