Skip to content

Commit 6eb5d2e

Browse files
lcolittidavem330
authored andcommitted
net: diag: Support SOCK_DESTROY for inet sockets.
This passes the SOCK_DESTROY operation to the underlying protocol diag handler, or returns -EOPNOTSUPP if that handler does not define a destroy operation. Most of this patch is just renaming functions. This is not strictly necessary, but it would be fairly counterintuitive to have the code to destroy inet sockets be in a function whose name starts with inet_diag_get. Signed-off-by: Lorenzo Colitti <lorenzo@google.com> Acked-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 64be0ae commit 6eb5d2e

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

include/linux/inet_diag.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ struct inet_diag_handler {
2424
void (*idiag_get_info)(struct sock *sk,
2525
struct inet_diag_msg *r,
2626
void *info);
27+
28+
int (*destroy)(struct sk_buff *in_skb,
29+
const struct inet_diag_req_v2 *req);
30+
2731
__u16 idiag_type;
2832
__u16 idiag_info_size;
2933
};

net/ipv4/inet_diag.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo,
426426
}
427427
EXPORT_SYMBOL_GPL(inet_diag_dump_one_icsk);
428428

429-
static int inet_diag_get_exact(struct sk_buff *in_skb,
429+
static int inet_diag_cmd_exact(int cmd, struct sk_buff *in_skb,
430430
const struct nlmsghdr *nlh,
431431
const struct inet_diag_req_v2 *req)
432432
{
@@ -436,8 +436,12 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
436436
handler = inet_diag_lock_handler(req->sdiag_protocol);
437437
if (IS_ERR(handler))
438438
err = PTR_ERR(handler);
439-
else
439+
else if (cmd == SOCK_DIAG_BY_FAMILY)
440440
err = handler->dump_one(in_skb, nlh, req);
441+
else if (cmd == SOCK_DESTROY && handler->destroy)
442+
err = handler->destroy(in_skb, req);
443+
else
444+
err = -EOPNOTSUPP;
441445
inet_diag_unlock_handler(handler);
442446

443447
return err;
@@ -950,7 +954,7 @@ static int inet_diag_get_exact_compat(struct sk_buff *in_skb,
950954
req.idiag_states = rc->idiag_states;
951955
req.id = rc->id;
952956

953-
return inet_diag_get_exact(in_skb, nlh, &req);
957+
return inet_diag_cmd_exact(SOCK_DIAG_BY_FAMILY, in_skb, nlh, &req);
954958
}
955959

956960
static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh)
@@ -984,15 +988,16 @@ static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh)
984988
return inet_diag_get_exact_compat(skb, nlh);
985989
}
986990

987-
static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)
991+
static int inet_diag_handler_cmd(struct sk_buff *skb, struct nlmsghdr *h)
988992
{
989993
int hdrlen = sizeof(struct inet_diag_req_v2);
990994
struct net *net = sock_net(skb->sk);
991995

992996
if (nlmsg_len(h) < hdrlen)
993997
return -EINVAL;
994998

995-
if (h->nlmsg_flags & NLM_F_DUMP) {
999+
if (h->nlmsg_type == SOCK_DIAG_BY_FAMILY &&
1000+
h->nlmsg_flags & NLM_F_DUMP) {
9961001
if (nlmsg_attrlen(h, hdrlen)) {
9971002
struct nlattr *attr;
9981003

@@ -1011,7 +1016,7 @@ static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)
10111016
}
10121017
}
10131018

1014-
return inet_diag_get_exact(skb, h, nlmsg_data(h));
1019+
return inet_diag_cmd_exact(h->nlmsg_type, skb, h, nlmsg_data(h));
10151020
}
10161021

10171022
static
@@ -1062,14 +1067,16 @@ int inet_diag_handler_get_info(struct sk_buff *skb, struct sock *sk)
10621067

10631068
static const struct sock_diag_handler inet_diag_handler = {
10641069
.family = AF_INET,
1065-
.dump = inet_diag_handler_dump,
1070+
.dump = inet_diag_handler_cmd,
10661071
.get_info = inet_diag_handler_get_info,
1072+
.destroy = inet_diag_handler_cmd,
10671073
};
10681074

10691075
static const struct sock_diag_handler inet6_diag_handler = {
10701076
.family = AF_INET6,
1071-
.dump = inet_diag_handler_dump,
1077+
.dump = inet_diag_handler_cmd,
10721078
.get_info = inet_diag_handler_get_info,
1079+
.destroy = inet_diag_handler_cmd,
10731080
};
10741081

10751082
int inet_diag_register(const struct inet_diag_handler *h)

0 commit comments

Comments
 (0)