Commit 25c4cd2b authored by Pavel Emelyanov's avatar Pavel Emelyanov Committed by David S. Miller

inet_diag: Switch the _dump to work with new header

Make inet_diag_dumo work with given header instead of calculating
one from the nl message.

The SOCK_DIAG_BY_FAMILY just passes skb's one through, the compat code
converts the old header to new one.

Also fix the bytecode calculation to find one at proper offset.
Signed-off-by: default avatarPavel Emelyanov <xemul@parallels.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent fe50ce28
...@@ -502,10 +502,9 @@ static int inet_diag_bc_audit(const void *bytecode, int bytecode_len) ...@@ -502,10 +502,9 @@ static int inet_diag_bc_audit(const void *bytecode, int bytecode_len)
static int inet_csk_diag_dump(struct sock *sk, static int inet_csk_diag_dump(struct sock *sk,
struct sk_buff *skb, struct sk_buff *skb,
struct netlink_callback *cb, struct netlink_callback *cb,
struct inet_diag_req *r,
const struct nlattr *bc) const struct nlattr *bc)
{ {
struct inet_diag_req_compat *r = NLMSG_DATA(cb->nlh);
if (bc != NULL) { if (bc != NULL) {
struct inet_diag_entry entry; struct inet_diag_entry entry;
struct inet_sock *inet = inet_sk(sk); struct inet_sock *inet = inet_sk(sk);
...@@ -539,10 +538,9 @@ static int inet_csk_diag_dump(struct sock *sk, ...@@ -539,10 +538,9 @@ static int inet_csk_diag_dump(struct sock *sk,
static int inet_twsk_diag_dump(struct inet_timewait_sock *tw, static int inet_twsk_diag_dump(struct inet_timewait_sock *tw,
struct sk_buff *skb, struct sk_buff *skb,
struct netlink_callback *cb, struct netlink_callback *cb,
struct inet_diag_req *r,
const struct nlattr *bc) const struct nlattr *bc)
{ {
struct inet_diag_req_compat *r = NLMSG_DATA(cb->nlh);
if (bc != NULL) { if (bc != NULL) {
struct inet_diag_entry entry; struct inet_diag_entry entry;
...@@ -626,10 +624,10 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk, ...@@ -626,10 +624,10 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk, static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk,
struct netlink_callback *cb, struct netlink_callback *cb,
struct inet_diag_req *r,
const struct nlattr *bc) const struct nlattr *bc)
{ {
struct inet_diag_entry entry; struct inet_diag_entry entry;
struct inet_diag_req_compat *r = NLMSG_DATA(cb->nlh);
struct inet_connection_sock *icsk = inet_csk(sk); struct inet_connection_sock *icsk = inet_csk(sk);
struct listen_sock *lopt; struct listen_sock *lopt;
struct inet_sock *inet = inet_sk(sk); struct inet_sock *inet = inet_sk(sk);
...@@ -708,19 +706,15 @@ static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk, ...@@ -708,19 +706,15 @@ static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk,
return err; return err;
} }
static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb) static int __inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
struct inet_diag_req *r, struct nlattr *bc)
{ {
int i, num; int i, num;
int s_i, s_num; int s_i, s_num;
struct inet_diag_req_compat *r = NLMSG_DATA(cb->nlh);
const struct inet_diag_handler *handler; const struct inet_diag_handler *handler;
struct inet_hashinfo *hashinfo; struct inet_hashinfo *hashinfo;
const struct nlattr *bc = NULL;
if (nlmsg_attrlen(cb->nlh, sizeof(struct inet_diag_req_compat))) handler = inet_diag_lock_handler(r->sdiag_protocol);
bc = nlmsg_find_attr(cb->nlh, sizeof(*r), INET_DIAG_REQ_BYTECODE);
handler = inet_diag_lock_handler(inet_diag_type2proto(cb->nlh->nlmsg_type));
if (IS_ERR(handler)) if (IS_ERR(handler))
goto unlock; goto unlock;
...@@ -758,7 +752,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -758,7 +752,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
cb->args[3] > 0) cb->args[3] > 0)
goto syn_recv; goto syn_recv;
if (inet_csk_diag_dump(sk, skb, cb, bc) < 0) { if (inet_csk_diag_dump(sk, skb, cb, r, bc) < 0) {
spin_unlock_bh(&ilb->lock); spin_unlock_bh(&ilb->lock);
goto done; goto done;
} }
...@@ -767,7 +761,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -767,7 +761,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
if (!(r->idiag_states & TCPF_SYN_RECV)) if (!(r->idiag_states & TCPF_SYN_RECV))
goto next_listen; goto next_listen;
if (inet_diag_dump_reqs(skb, sk, cb, bc) < 0) { if (inet_diag_dump_reqs(skb, sk, cb, r, bc) < 0) {
spin_unlock_bh(&ilb->lock); spin_unlock_bh(&ilb->lock);
goto done; goto done;
} }
...@@ -820,7 +814,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -820,7 +814,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
if (r->id.idiag_dport != inet->inet_dport && if (r->id.idiag_dport != inet->inet_dport &&
r->id.idiag_dport) r->id.idiag_dport)
goto next_normal; goto next_normal;
if (inet_csk_diag_dump(sk, skb, cb, bc) < 0) { if (inet_csk_diag_dump(sk, skb, cb, r, bc) < 0) {
spin_unlock_bh(lock); spin_unlock_bh(lock);
goto done; goto done;
} }
...@@ -842,7 +836,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -842,7 +836,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
if (r->id.idiag_dport != tw->tw_dport && if (r->id.idiag_dport != tw->tw_dport &&
r->id.idiag_dport) r->id.idiag_dport)
goto next_dying; goto next_dying;
if (inet_twsk_diag_dump(tw, skb, cb, bc) < 0) { if (inet_twsk_diag_dump(tw, skb, cb, r, bc) < 0) {
spin_unlock_bh(lock); spin_unlock_bh(lock);
goto done; goto done;
} }
...@@ -861,6 +855,36 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -861,6 +855,36 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
return skb->len; return skb->len;
} }
static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
{
struct nlattr *bc = NULL;
int hdrlen = sizeof(struct inet_diag_req);
if (nlmsg_attrlen(cb->nlh, hdrlen))
bc = nlmsg_find_attr(cb->nlh, hdrlen, INET_DIAG_REQ_BYTECODE);
return __inet_diag_dump(skb, cb, (struct inet_diag_req *)NLMSG_DATA(cb->nlh), bc);
}
static int inet_diag_dump_compat(struct sk_buff *skb, struct netlink_callback *cb)
{
struct inet_diag_req_compat *rc = NLMSG_DATA(cb->nlh);
struct inet_diag_req req;
struct nlattr *bc = NULL;
int hdrlen = sizeof(struct inet_diag_req_compat);
req.sdiag_family = rc->idiag_family;
req.sdiag_protocol = inet_diag_type2proto(cb->nlh->nlmsg_type);
req.idiag_ext = rc->idiag_ext;
req.idiag_states = rc->idiag_states;
req.id = rc->id;
if (nlmsg_attrlen(cb->nlh, hdrlen))
bc = nlmsg_find_attr(cb->nlh, hdrlen, INET_DIAG_REQ_BYTECODE);
return __inet_diag_dump(skb, cb, &req, bc);
}
static int inet_diag_get_exact_compat(struct sk_buff *in_skb, static int inet_diag_get_exact_compat(struct sk_buff *in_skb,
const struct nlmsghdr *nlh) const struct nlmsghdr *nlh)
{ {
...@@ -897,7 +921,7 @@ static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -897,7 +921,7 @@ static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh)
} }
return netlink_dump_start(sdiagnl, skb, nlh, return netlink_dump_start(sdiagnl, skb, nlh,
inet_diag_dump, NULL, 0); inet_diag_dump_compat, NULL, 0);
} }
return inet_diag_get_exact_compat(skb, nlh); return inet_diag_get_exact_compat(skb, nlh);
...@@ -911,7 +935,18 @@ static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) ...@@ -911,7 +935,18 @@ static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)
return -EINVAL; return -EINVAL;
if (h->nlmsg_flags & NLM_F_DUMP) { if (h->nlmsg_flags & NLM_F_DUMP) {
return -EAFNOSUPPORT; if (nlmsg_attrlen(h, hdrlen)) {
struct nlattr *attr;
attr = nlmsg_find_attr(h, hdrlen,
INET_DIAG_REQ_BYTECODE);
if (attr == NULL ||
nla_len(attr) < sizeof(struct inet_diag_bc_op) ||
inet_diag_bc_audit(nla_data(attr), nla_len(attr)))
return -EINVAL;
}
return netlink_dump_start(sdiagnl, skb, h,
inet_diag_dump, NULL, 0);
} }
return inet_diag_get_exact(skb, h, (struct inet_diag_req *)NLMSG_DATA(h)); return inet_diag_get_exact(skb, h, (struct inet_diag_req *)NLMSG_DATA(h));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment