Skip to content

Commit a029fe2

Browse files
xemuldavem330
authored andcommitted
inet_diag: Cleanup type2proto last user
Now all the code works with sock_diag_req-compatible structs, so it's possible to stop using the inet_diag_type2proto in inet_csk_diag_fill. Pass the inet_diag_req into it and use the sdiag_protocol field. At the same time remove the explicit ext argument, since it's also on the req. However, this conversion is still required in _compat code, so just move this routine, not remove. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent d23deaa commit a029fe2

1 file changed

Lines changed: 24 additions & 23 deletions

File tree

‎net/ipv4/inet_diag.c‎

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,6 @@ static struct sock *sdiagnl;
5151
#define INET_DIAG_PUT(skb, attrtype, attrlen) \
5252
RTA_DATA(__RTA_PUT(skb, attrtype, attrlen))
5353

54-
static inline int inet_diag_type2proto(int type)
55-
{
56-
switch (type) {
57-
case TCPDIAG_GETSOCK:
58-
return IPPROTO_TCP;
59-
case DCCPDIAG_GETSOCK:
60-
return IPPROTO_DCCP;
61-
default:
62-
return 0;
63-
}
64-
}
65-
6654
static DEFINE_MUTEX(inet_diag_table_mutex);
6755

6856
static const struct inet_diag_handler *inet_diag_lock_handler(int proto)
@@ -85,8 +73,8 @@ static inline void inet_diag_unlock_handler(
8573
}
8674

8775
static int inet_csk_diag_fill(struct sock *sk,
88-
struct sk_buff *skb,
89-
int ext, u32 pid, u32 seq, u16 nlmsg_flags,
76+
struct sk_buff *skb, struct inet_diag_req *req,
77+
u32 pid, u32 seq, u16 nlmsg_flags,
9078
const struct nlmsghdr *unlh)
9179
{
9280
const struct inet_sock *inet = inet_sk(sk);
@@ -97,8 +85,9 @@ static int inet_csk_diag_fill(struct sock *sk,
9785
struct inet_diag_meminfo *minfo = NULL;
9886
unsigned char *b = skb_tail_pointer(skb);
9987
const struct inet_diag_handler *handler;
88+
int ext = req->idiag_ext;
10089

101-
handler = inet_diag_table[inet_diag_type2proto(unlh->nlmsg_type)];
90+
handler = inet_diag_table[req->sdiag_protocol];
10291
BUG_ON(handler == NULL);
10392

10493
nlh = NLMSG_PUT(skb, pid, seq, unlh->nlmsg_type, sizeof(*r));
@@ -198,8 +187,8 @@ static int inet_csk_diag_fill(struct sock *sk,
198187
}
199188

200189
static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
201-
struct sk_buff *skb, int ext, u32 pid,
202-
u32 seq, u16 nlmsg_flags,
190+
struct sk_buff *skb, struct inet_diag_req *req,
191+
u32 pid, u32 seq, u16 nlmsg_flags,
203192
const struct nlmsghdr *unlh)
204193
{
205194
long tmo;
@@ -250,14 +239,14 @@ static int inet_twsk_diag_fill(struct inet_timewait_sock *tw,
250239
}
251240

252241
static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
253-
int ext, u32 pid, u32 seq, u16 nlmsg_flags,
242+
struct inet_diag_req *r, u32 pid, u32 seq, u16 nlmsg_flags,
254243
const struct nlmsghdr *unlh)
255244
{
256245
if (sk->sk_state == TCP_TIME_WAIT)
257246
return inet_twsk_diag_fill((struct inet_timewait_sock *)sk,
258-
skb, ext, pid, seq, nlmsg_flags,
247+
skb, r, pid, seq, nlmsg_flags,
259248
unlh);
260-
return inet_csk_diag_fill(sk, skb, ext, pid, seq, nlmsg_flags, unlh);
249+
return inet_csk_diag_fill(sk, skb, r, pid, seq, nlmsg_flags, unlh);
261250
}
262251

263252
static int inet_diag_get_exact(struct sk_buff *in_skb,
@@ -317,7 +306,7 @@ static int inet_diag_get_exact(struct sk_buff *in_skb,
317306
if (!rep)
318307
goto out;
319308

320-
err = sk_diag_fill(sk, rep, req->idiag_ext,
309+
err = sk_diag_fill(sk, rep, req,
321310
NETLINK_CB(in_skb).pid,
322311
nlh->nlmsg_seq, 0, nlh);
323312
if (err < 0) {
@@ -530,7 +519,7 @@ static int inet_csk_diag_dump(struct sock *sk,
530519
return 0;
531520
}
532521

533-
return inet_csk_diag_fill(sk, skb, r->idiag_ext,
522+
return inet_csk_diag_fill(sk, skb, r,
534523
NETLINK_CB(cb->skb).pid,
535524
cb->nlh->nlmsg_seq, NLM_F_MULTI, cb->nlh);
536525
}
@@ -565,7 +554,7 @@ static int inet_twsk_diag_dump(struct inet_timewait_sock *tw,
565554
return 0;
566555
}
567556

568-
return inet_twsk_diag_fill(tw, skb, r->idiag_ext,
557+
return inet_twsk_diag_fill(tw, skb, r,
569558
NETLINK_CB(cb->skb).pid,
570559
cb->nlh->nlmsg_seq, NLM_F_MULTI, cb->nlh);
571560
}
@@ -876,6 +865,18 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
876865
return __inet_diag_dump(skb, cb, (struct inet_diag_req *)NLMSG_DATA(cb->nlh), bc);
877866
}
878867

868+
static inline int inet_diag_type2proto(int type)
869+
{
870+
switch (type) {
871+
case TCPDIAG_GETSOCK:
872+
return IPPROTO_TCP;
873+
case DCCPDIAG_GETSOCK:
874+
return IPPROTO_DCCP;
875+
default:
876+
return 0;
877+
}
878+
}
879+
879880
static int inet_diag_dump_compat(struct sk_buff *skb, struct netlink_callback *cb)
880881
{
881882
struct inet_diag_req_compat *rc = NLMSG_DATA(cb->nlh);

0 commit comments

Comments
 (0)