Skip to content

Commit fe50ce2

Browse files
xemuldavem330
authored andcommitted
inet_diag: Switch the _get_exact to work with new header
Make inet_diag_get_exact 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. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 126fdc3 commit fe50ce2

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

‎net/ipv4/inet_diag.c‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -261,16 +261,16 @@ static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
261261
}
262262

263263
static int inet_diag_get_exact(struct sk_buff *in_skb,
264-
const struct nlmsghdr *nlh)
264+
const struct nlmsghdr *nlh,
265+
struct inet_diag_req *req)
265266
{
266267
int err;
267268
struct sock *sk;
268-
struct inet_diag_req_compat *req = NLMSG_DATA(nlh);
269269
struct sk_buff *rep;
270270
struct inet_hashinfo *hashinfo;
271271
const struct inet_diag_handler *handler;
272272

273-
handler = inet_diag_lock_handler(inet_diag_type2proto(nlh->nlmsg_type));
273+
handler = inet_diag_lock_handler(req->sdiag_protocol);
274274
if (IS_ERR(handler)) {
275275
err = PTR_ERR(handler);
276276
goto unlock;
@@ -279,13 +279,13 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
279279
hashinfo = handler->idiag_hashinfo;
280280
err = -EINVAL;
281281

282-
if (req->idiag_family == AF_INET) {
282+
if (req->sdiag_family == AF_INET) {
283283
sk = inet_lookup(&init_net, hashinfo, req->id.idiag_dst[0],
284284
req->id.idiag_dport, req->id.idiag_src[0],
285285
req->id.idiag_sport, req->id.idiag_if);
286286
}
287287
#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
288-
else if (req->idiag_family == AF_INET6) {
288+
else if (req->sdiag_family == AF_INET6) {
289289
sk = inet6_lookup(&init_net, hashinfo,
290290
(struct in6_addr *)req->id.idiag_dst,
291291
req->id.idiag_dport,
@@ -861,6 +861,21 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
861861
return skb->len;
862862
}
863863

864+
static int inet_diag_get_exact_compat(struct sk_buff *in_skb,
865+
const struct nlmsghdr *nlh)
866+
{
867+
struct inet_diag_req_compat *rc = NLMSG_DATA(nlh);
868+
struct inet_diag_req req;
869+
870+
req.sdiag_family = rc->idiag_family;
871+
req.sdiag_protocol = inet_diag_type2proto(nlh->nlmsg_type);
872+
req.idiag_ext = rc->idiag_ext;
873+
req.idiag_states = rc->idiag_states;
874+
req.id = rc->id;
875+
876+
return inet_diag_get_exact(in_skb, nlh, &req);
877+
}
878+
864879
static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh)
865880
{
866881
int hdrlen = sizeof(struct inet_diag_req_compat);
@@ -885,7 +900,7 @@ static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh)
885900
inet_diag_dump, NULL, 0);
886901
}
887902

888-
return inet_diag_get_exact(skb, nlh);
903+
return inet_diag_get_exact_compat(skb, nlh);
889904
}
890905

891906
static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)
@@ -899,7 +914,7 @@ static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)
899914
return -EAFNOSUPPORT;
900915
}
901916

902-
return -EAFNOSUPPORT;
917+
return inet_diag_get_exact(skb, h, (struct inet_diag_req *)NLMSG_DATA(h));
903918
}
904919

905920
static struct sock_diag_handler inet_diag_handler = {

0 commit comments

Comments
 (0)