Skip to content

Commit cb2050a

Browse files
lxindavem330
authored andcommitted
sctp: export some functions for sctp_diag in inet_diag
inet_diag_msg_common_fill is used to fill the diag msg common info, we need to use it in sctp_diag as well, so export it. inet_diag_msg_attrs_fill is used to fill some common attrs info between sctp diag and tcp diag. v2->v3: - do not need to define and export inet_diag_get_handler any more. cause all the functions in it are in sctp_diag.ko, we just call them in sctp_diag.ko. - add inet_diag_msg_attrs_fill to make codes clear. Signed-off-by: Xin Long <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 626d16f commit cb2050a

File tree

1 file changed

+41
-26
lines changed

1 file changed

+41
-26
lines changed

net/ipv4/inet_diag.c

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static void inet_diag_unlock_handler(const struct inet_diag_handler *handler)
6666
mutex_unlock(&inet_diag_table_mutex);
6767
}
6868

69-
static void inet_diag_msg_common_fill(struct inet_diag_msg *r, struct sock *sk)
69+
void inet_diag_msg_common_fill(struct inet_diag_msg *r, struct sock *sk)
7070
{
7171
r->idiag_family = sk->sk_family;
7272

@@ -89,6 +89,7 @@ static void inet_diag_msg_common_fill(struct inet_diag_msg *r, struct sock *sk)
8989
r->id.idiag_dst[0] = sk->sk_daddr;
9090
}
9191
}
92+
EXPORT_SYMBOL_GPL(inet_diag_msg_common_fill);
9293

9394
static size_t inet_sk_attr_size(void)
9495
{
@@ -104,13 +105,50 @@ static size_t inet_sk_attr_size(void)
104105
+ 64;
105106
}
106107

108+
int inet_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb,
109+
struct inet_diag_msg *r, int ext,
110+
struct user_namespace *user_ns)
111+
{
112+
const struct inet_sock *inet = inet_sk(sk);
113+
114+
if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
115+
goto errout;
116+
117+
/* IPv6 dual-stack sockets use inet->tos for IPv4 connections,
118+
* hence this needs to be included regardless of socket family.
119+
*/
120+
if (ext & (1 << (INET_DIAG_TOS - 1)))
121+
if (nla_put_u8(skb, INET_DIAG_TOS, inet->tos) < 0)
122+
goto errout;
123+
124+
#if IS_ENABLED(CONFIG_IPV6)
125+
if (r->idiag_family == AF_INET6) {
126+
if (ext & (1 << (INET_DIAG_TCLASS - 1)))
127+
if (nla_put_u8(skb, INET_DIAG_TCLASS,
128+
inet6_sk(sk)->tclass) < 0)
129+
goto errout;
130+
131+
if (((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) &&
132+
nla_put_u8(skb, INET_DIAG_SKV6ONLY, ipv6_only_sock(sk)))
133+
goto errout;
134+
}
135+
#endif
136+
137+
r->idiag_uid = from_kuid_munged(user_ns, sock_i_uid(sk));
138+
r->idiag_inode = sock_i_ino(sk);
139+
140+
return 0;
141+
errout:
142+
return 1;
143+
}
144+
EXPORT_SYMBOL_GPL(inet_diag_msg_attrs_fill);
145+
107146
int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
108147
struct sk_buff *skb, const struct inet_diag_req_v2 *req,
109148
struct user_namespace *user_ns,
110149
u32 portid, u32 seq, u16 nlmsg_flags,
111150
const struct nlmsghdr *unlh)
112151
{
113-
const struct inet_sock *inet = inet_sk(sk);
114152
const struct tcp_congestion_ops *ca_ops;
115153
const struct inet_diag_handler *handler;
116154
int ext = req->idiag_ext;
@@ -135,32 +173,9 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
135173
r->idiag_timer = 0;
136174
r->idiag_retrans = 0;
137175

138-
if (nla_put_u8(skb, INET_DIAG_SHUTDOWN, sk->sk_shutdown))
176+
if (inet_diag_msg_attrs_fill(sk, skb, r, ext, user_ns))
139177
goto errout;
140178

141-
/* IPv6 dual-stack sockets use inet->tos for IPv4 connections,
142-
* hence this needs to be included regardless of socket family.
143-
*/
144-
if (ext & (1 << (INET_DIAG_TOS - 1)))
145-
if (nla_put_u8(skb, INET_DIAG_TOS, inet->tos) < 0)
146-
goto errout;
147-
148-
#if IS_ENABLED(CONFIG_IPV6)
149-
if (r->idiag_family == AF_INET6) {
150-
if (ext & (1 << (INET_DIAG_TCLASS - 1)))
151-
if (nla_put_u8(skb, INET_DIAG_TCLASS,
152-
inet6_sk(sk)->tclass) < 0)
153-
goto errout;
154-
155-
if (((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) &&
156-
nla_put_u8(skb, INET_DIAG_SKV6ONLY, ipv6_only_sock(sk)))
157-
goto errout;
158-
}
159-
#endif
160-
161-
r->idiag_uid = from_kuid_munged(user_ns, sock_i_uid(sk));
162-
r->idiag_inode = sock_i_ino(sk);
163-
164179
if (ext & (1 << (INET_DIAG_MEMINFO - 1))) {
165180
struct inet_diag_meminfo minfo = {
166181
.idiag_rmem = sk_rmem_alloc_get(sk),

0 commit comments

Comments
 (0)