Commit 6eb5d2e0 authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by David S. Miller

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: default avatarLorenzo Colitti <lorenzo@google.com>
Acked-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 64be0aed
...@@ -24,6 +24,10 @@ struct inet_diag_handler { ...@@ -24,6 +24,10 @@ struct inet_diag_handler {
void (*idiag_get_info)(struct sock *sk, void (*idiag_get_info)(struct sock *sk,
struct inet_diag_msg *r, struct inet_diag_msg *r,
void *info); void *info);
int (*destroy)(struct sk_buff *in_skb,
const struct inet_diag_req_v2 *req);
__u16 idiag_type; __u16 idiag_type;
__u16 idiag_info_size; __u16 idiag_info_size;
}; };
......
...@@ -426,7 +426,7 @@ int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo, ...@@ -426,7 +426,7 @@ int inet_diag_dump_one_icsk(struct inet_hashinfo *hashinfo,
} }
EXPORT_SYMBOL_GPL(inet_diag_dump_one_icsk); EXPORT_SYMBOL_GPL(inet_diag_dump_one_icsk);
static int inet_diag_get_exact(struct sk_buff *in_skb, static int inet_diag_cmd_exact(int cmd, struct sk_buff *in_skb,
const struct nlmsghdr *nlh, const struct nlmsghdr *nlh,
const struct inet_diag_req_v2 *req) const struct inet_diag_req_v2 *req)
{ {
...@@ -436,8 +436,12 @@ static int inet_diag_get_exact(struct sk_buff *in_skb, ...@@ -436,8 +436,12 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
handler = inet_diag_lock_handler(req->sdiag_protocol); handler = inet_diag_lock_handler(req->sdiag_protocol);
if (IS_ERR(handler)) if (IS_ERR(handler))
err = PTR_ERR(handler); err = PTR_ERR(handler);
else else if (cmd == SOCK_DIAG_BY_FAMILY)
err = handler->dump_one(in_skb, nlh, req); err = handler->dump_one(in_skb, nlh, req);
else if (cmd == SOCK_DESTROY && handler->destroy)
err = handler->destroy(in_skb, req);
else
err = -EOPNOTSUPP;
inet_diag_unlock_handler(handler); inet_diag_unlock_handler(handler);
return err; return err;
...@@ -950,7 +954,7 @@ static int inet_diag_get_exact_compat(struct sk_buff *in_skb, ...@@ -950,7 +954,7 @@ static int inet_diag_get_exact_compat(struct sk_buff *in_skb,
req.idiag_states = rc->idiag_states; req.idiag_states = rc->idiag_states;
req.id = rc->id; req.id = rc->id;
return inet_diag_get_exact(in_skb, nlh, &req); return inet_diag_cmd_exact(SOCK_DIAG_BY_FAMILY, in_skb, nlh, &req);
} }
static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh) static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh)
...@@ -984,7 +988,7 @@ static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -984,7 +988,7 @@ static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh)
return inet_diag_get_exact_compat(skb, nlh); return inet_diag_get_exact_compat(skb, nlh);
} }
static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) static int inet_diag_handler_cmd(struct sk_buff *skb, struct nlmsghdr *h)
{ {
int hdrlen = sizeof(struct inet_diag_req_v2); int hdrlen = sizeof(struct inet_diag_req_v2);
struct net *net = sock_net(skb->sk); struct net *net = sock_net(skb->sk);
...@@ -992,7 +996,8 @@ static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) ...@@ -992,7 +996,8 @@ static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)
if (nlmsg_len(h) < hdrlen) if (nlmsg_len(h) < hdrlen)
return -EINVAL; return -EINVAL;
if (h->nlmsg_flags & NLM_F_DUMP) { if (h->nlmsg_type == SOCK_DIAG_BY_FAMILY &&
h->nlmsg_flags & NLM_F_DUMP) {
if (nlmsg_attrlen(h, hdrlen)) { if (nlmsg_attrlen(h, hdrlen)) {
struct nlattr *attr; struct nlattr *attr;
...@@ -1011,7 +1016,7 @@ static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) ...@@ -1011,7 +1016,7 @@ static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)
} }
} }
return inet_diag_get_exact(skb, h, nlmsg_data(h)); return inet_diag_cmd_exact(h->nlmsg_type, skb, h, nlmsg_data(h));
} }
static static
...@@ -1062,14 +1067,16 @@ int inet_diag_handler_get_info(struct sk_buff *skb, struct sock *sk) ...@@ -1062,14 +1067,16 @@ int inet_diag_handler_get_info(struct sk_buff *skb, struct sock *sk)
static const struct sock_diag_handler inet_diag_handler = { static const struct sock_diag_handler inet_diag_handler = {
.family = AF_INET, .family = AF_INET,
.dump = inet_diag_handler_dump, .dump = inet_diag_handler_cmd,
.get_info = inet_diag_handler_get_info, .get_info = inet_diag_handler_get_info,
.destroy = inet_diag_handler_cmd,
}; };
static const struct sock_diag_handler inet6_diag_handler = { static const struct sock_diag_handler inet6_diag_handler = {
.family = AF_INET6, .family = AF_INET6,
.dump = inet_diag_handler_dump, .dump = inet_diag_handler_cmd,
.get_info = inet_diag_handler_get_info, .get_info = inet_diag_handler_get_info,
.destroy = inet_diag_handler_cmd,
}; };
int inet_diag_register(const struct inet_diag_handler *h) int inet_diag_register(const struct inet_diag_handler *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