Skip to content

Commit dff2c03

Browse files
Arnaldo Carvalho de Melodavem330
authored andcommitted
[INET_DIAG]: Introduce sk_diag_fill
To be called from inet_diag_get_exact, also rename inet_diag_fill to inet_csk_diag_fill, for consistency with inet_twsk_diag_fill. Signed-off-by: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c7d58aa commit dff2c03

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

net/ipv4/inet_diag.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ static struct sock *idiagnl;
5050
#define INET_DIAG_PUT(skb, attrtype, attrlen) \
5151
RTA_DATA(__RTA_PUT(skb, attrtype, attrlen))
5252

53-
static int inet_diag_fill(struct sk_buff *skb, struct sock *sk,
54-
int ext, u32 pid, u32 seq, u16 nlmsg_flags,
55-
const struct nlmsghdr *unlh)
53+
static int inet_csk_diag_fill(struct sock *sk,
54+
struct sk_buff *skb,
55+
int ext, u32 pid, u32 seq, u16 nlmsg_flags,
56+
const struct nlmsghdr *unlh)
5657
{
5758
const struct inet_sock *inet = inet_sk(sk);
5859
const struct inet_connection_sock *icsk = inet_csk(sk);
@@ -212,6 +213,17 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
212213
return -1;
213214
}
214215

216+
static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
217+
int ext, u32 pid, u32 seq, u16 nlmsg_flags,
218+
const struct nlmsghdr *unlh)
219+
{
220+
if (sk->sk_state == TCP_TIME_WAIT)
221+
return inet_twsk_diag_fill((struct inet_timewait_sock *)sk,
222+
skb, ext, pid, seq, nlmsg_flags,
223+
unlh);
224+
return inet_csk_diag_fill(sk, skb, ext, pid, seq, nlmsg_flags, unlh);
225+
}
226+
215227
static int inet_diag_get_exact(struct sk_buff *in_skb,
216228
const struct nlmsghdr *nlh)
217229
{
@@ -263,7 +275,7 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
263275
if (!rep)
264276
goto out;
265277

266-
if (inet_diag_fill(rep, sk, req->idiag_ext,
278+
if (sk_diag_fill(sk, rep, req->idiag_ext,
267279
NETLINK_CB(in_skb).pid,
268280
nlh->nlmsg_seq, 0, nlh) <= 0)
269281
BUG();
@@ -442,8 +454,9 @@ static int inet_diag_bc_audit(const void *bytecode, int bytecode_len)
442454
return len == 0 ? 0 : -EINVAL;
443455
}
444456

445-
static int inet_diag_dump_sock(struct sk_buff *skb, struct sock *sk,
446-
struct netlink_callback *cb)
457+
static int inet_csk_diag_dump(struct sock *sk,
458+
struct sk_buff *skb,
459+
struct netlink_callback *cb)
447460
{
448461
struct inet_diag_req *r = NLMSG_DATA(cb->nlh);
449462

@@ -473,8 +486,9 @@ static int inet_diag_dump_sock(struct sk_buff *skb, struct sock *sk,
473486
return 0;
474487
}
475488

476-
return inet_diag_fill(skb, sk, r->idiag_ext, NETLINK_CB(cb->skb).pid,
477-
cb->nlh->nlmsg_seq, NLM_F_MULTI, cb->nlh);
489+
return inet_csk_diag_fill(sk, skb, r->idiag_ext,
490+
NETLINK_CB(cb->skb).pid,
491+
cb->nlh->nlmsg_seq, NLM_F_MULTI, cb->nlh);
478492
}
479493

480494
static int inet_twsk_diag_dump(struct inet_timewait_sock *tw,
@@ -694,7 +708,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
694708
cb->args[3] > 0)
695709
goto syn_recv;
696710

697-
if (inet_diag_dump_sock(skb, sk, cb) < 0) {
711+
if (inet_csk_diag_dump(sk, skb, cb) < 0) {
698712
inet_listen_unlock(hashinfo);
699713
goto done;
700714
}
@@ -750,7 +764,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
750764
if (r->id.idiag_dport != inet->dport &&
751765
r->id.idiag_dport)
752766
goto next_normal;
753-
if (inet_diag_dump_sock(skb, sk, cb) < 0) {
767+
if (inet_csk_diag_dump(sk, skb, cb) < 0) {
754768
read_unlock_bh(&head->lock);
755769
goto done;
756770
}

0 commit comments

Comments
 (0)