forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
smc: netlink interface for SMC sockets
Support for SMC socket monitoring via netlink sockets of protocol NETLINK_SOCK_DIAG. Signed-off-by: Ursula Braun <ubraun@linux.vnet.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
- v6.12.9
- v6.12.8
- v6.12.7
- v6.12.6
- v6.12.5
- v6.12.4
- v6.12.3
- v6.12.2
- v6.12.1
- v6.12
- v6.6.77
- v6.6.76
- v6.6.75
- v6.6.74
- v6.6.73
- v6.6.72
- v6.6.71
- v6.6.70
- v6.6.69
- v6.6.68
- v6.6.67
- v6.6.66
- v6.6.65
- v6.6.64
- v6.6.63
- v6.6.62
- v6.6.61
- v6.6.60
- v6.6.59
- v6.6.58
- v6.6.57
- v6.6.56
- v6.6.55
- v6.6.54
- v6.6.53
- v6.6.52
- v6.6.51
- v6.6.50
- v6.6.49
- v6.6.48
- v6.6.47
- v6.6.46
- v6.6.45
- v6.6.44
- v6.6.43
- v6.6.42
- v6.6.41
- v6.6.40
- v6.6.39
- v6.6.38
- v6.6.37
- v6.6.36
- v6.6.35
- v6.6.34
- v6.6.33
- v6.6.32
- v6.6.31
- v6.6.30
- v6.6.29
- v6.6.28
- v6.6.27
- v6.6.26
- v6.6.25
- v6.6.24
- v6.6.23
- v6.6.16
- v6.6.15
- v6.6.14
- v6.6.13
- v6.6.12
- v6.6.11
- v6.6.10
- v6.6.9
- v6.6.8
- v6.6.7
- v6.6.6
- v6.6.5
- v6.6.4
- v6.6.3
- v6.6.2
- v6.6.1
- v6.6
- v6.5.11
- v6.5.10
- v6.5.9
- v6.5.8
- v6.5.7
- v6.5.6
- v6.5.5
- v6.5.4
- v6.5.3
- v6.5.2
- v6.5.1
- v6.5
- v6.4
- v6.3
- v6.2
- v6.1.51
- v6.1.50
- v6.1.49
- v6.1.48
- v6.1.46
- v6.1.45
- v6.1.44
- v6.1.43
- v6.1.42
- v6.1.41
- v6.1.40
- v6.1.39
- v6.1.38
- v6.1.37
- v6.1.36
- v6.1.35
- v6.1.34
- v6.1.33
- v6.1.32
- v6.1.31
- v6.1.30
- v6.1.29
- v6.1.28
- v6.1.27
- v6.1.26
- v6.1.25
- v6.1.24
- v6.1.23
- v6.1.22
- v6.1.21
- v6.1.20
- v6.1.19
- v6.1.18
- v6.1.17
- v6.1.16
- v6.1.15
- v6.1.14
- v6.1.13
- v6.1.12
- v6.1.11
- v6.1.10
- v6.1.9
- v6.1.8
- v6.1.7
- v6.1.6
- v6.1.5
- v6.1.4
- v6.1.3
- v6.1.2
- v6.1.1
- v6.1
- v6.0.19
- v6.0.18
- v6.0.17
- v6.0.16
- v6.0.15
- v6.0.14
- v6.0.13
- v6.0.12
- v6.0.11
- v6.0.10
- v6.0.9
- v6.0.8
- v6.0.7
- v6.0.6
- v6.0.5
- v6.0.4
- v6.0.3
- v6.0.2
- v6.0.1
- v6.0
- v5.19
- v5.18
- v5.17
- v5.16
- v5.15.80
- v5.15.79
- v5.15.78
- v5.15.77
- v5.15.76
- v5.15.75
- v5.15.74
- v5.15.73
- v5.15.72
- v5.15.71
- v5.15.70
- v5.15.69
- v5.15.68
- v5.15.67
- v5.15.66
- v5.15.65
- v5.15.64
- v5.15.63
- v5.15.62
- v5.15.61
- v5.15.60
- v5.15.59
- v5.15.58
- v5.15.57
- v5.15.56
- v5.15.55
- v5.15.54
- v5.15.53
- v5.15.52
- v5.15.51
- v5.15.50
- v5.15.49
- v5.15.48
- v5.15.47
- v5.15.46
- v5.15.45
- v5.15.44
- v5.15.43
- v5.15.42
- v5.15.41
- v5.15.40
- v5.15.39
- v5.15.38
- v5.15.37
- v5.15.36
- v5.15.35
- v5.15.34
- v5.15.33
- v5.15.32
- v5.15.31
- v5.15.30
- v5.15.29
- v5.15.28
- v5.15.27
- v5.15.26
- v5.15.25
- v5.15.24
- v5.15.23
- v5.15.22
- v5.15.21
- v5.15.20
- v5.15.19
- v5.15.18
- v5.15.17
- v5.15.16
- v5.15.15
- v5.15.10
- v5.15.9
- v5.15.8
- v5.15.7
- v5.15.6
- v5.15.5
- v5.15.4
- v5.15.3
- v5.15.2
- v5.15.1
- v5.15
- v5.14.14
- v5.14.13
- v5.14.12
- v5.14.11
- v5.14.10
- v5.14.9
- v5.14.8
- v5.14.7
- v5.14.6
- v5.14.5
- v5.14.4
- v5.14.3
- v5.14.2
- v5.14.1
- v5.14
- v5.13
- v5.12
- v5.11
- v5.10.67
- v5.10.66
- v5.10.65
- v5.10.64
- v5.10.63
- v5.10.62
- v5.10.61
- v5.10.60
- v5.10.53
- v5.10.52
- v5.10.51
- v5.10.50
- v5.10.49
- v5.10.46
- v5.10.43
- v5.10.42
- v5.10.41
- v5.10.40
- v5.10.39
- v5.10.36
- v5.10.35
- v5.10.34
- v5.10.33
- v5.10.32
- v5.10.31
- v5.10.30
- v5.10.27
- v5.10.26
- v5.10.25
- v5.10.24
- v5.10.23
- v5.10.22
- v5.10.21
- v5.10.20
- v5.10.19
- v5.10.18
- v5.10.17
- v5.10.16
- v5.10.15
- v5.10.14
- v5.10
- v5.9
- v5.8.17
- v5.8.16
- v5.8.15
- v5.8.14
- v5.8.13
- v5.8.12
- v5.8.11
- v5.8.10
- v5.8.9
- v5.8.8
- v5.8.7
- v5.8.6
- v5.8.5
- v5.8.4
- v5.8.3
- v5.8.2
- v5.8.1
- v5.8
- v5.7.12
- v5.7.11
- v5.7.10
- v5.7.9
- v5.7.8
- v5.7.7
- v5.7.6
- v5.7.5
- v5.7.4
- v5.7.3
- v5.7.2
- v5.7.1
- v5.7
- v5.6
- v5.5
- v5.4.173
- v5.4.119
- v5.4.116
- v5.4.101
- v5.4.62
- v5.4.61
- v5.4.60
- v5.4.59
- v5.4.58
- v5.4.57
- v5.4.56
- v5.4.55
- v5.4.54
- v5.4.53
- v5.4.52
- v5.4.51
- v5.4.50
- v5.4.49
- v5.4.48
- v5.4.47
- v5.4.46
- v5.4.45
- v5.4.44
- v5.4.43
- v5.4.42
- v5.4.41
- v5.4.40
- v5.4.39
- v5.4.38
- v5.4.37
- v5.4.36
- v5.4.35
- v5.4.34
- v5.4.33
- v5.4.32
- v5.4.31
- v5.4.30
- v5.4.29
- v5.4.28
- v5.4.27
- v5.4.26
- v5.4.25
- v5.4.24
- v5.4.23
- v5.4.22
- v5.4.21
- v5.4.20
- v5.4.19
- v5.4.18
- v5.4.17
- v5.4.16
- v5.4.15
- v5.4.14
- v5.4.13
- v5.4.12
- v5.4.11
- v5.4.10
- v5.4.9
- v5.4.8
- v5.4.7
- v5.4.6
- v5.4.5
- v5.4.4
- v5.4.3
- v5.4.2
- v5.4.1
- v5.4
- v5.3.15
- v5.3.14
- v5.3.13
- v5.3.12
- v5.3.11
- v5.3.10
- v5.3.9
- v5.3.8
- v5.3.7
- v5.3.6
- v5.3.5
- v5.3.4
- v5.3.3
- v5.3.2
- v5.3.1
- v5.3
- v5.3-rc8
- v5.2.14
- v5.2.13
- v5.2.12
- v5.2.11
- v5.2.10
- v5.2.9
- v5.2.8
- v5.2.7
- v5.2.6
- v5.2.5
- v5.2.4
- v5.2.3
- v5.2.2
- v5.2.1
- v5.2
- v5.1.16
- v5.1.15
- v5.1.14
- v5.1.13
- v5.1.12
- v5.1.11
- v5.1.10
- v5.1.9
- v5.1.8
- v5.1.7
- v5.1.6
- v5.1.5
- v5.1.4
- v5.1.3
- v5.1.2
- v5.1.1
- v5.1
- v5.0.14
- v5.0.13
- v5.0.12
- v5.0.11
- v5.0.10
- v5.0.9
- v5.0.8
- v5.0.7
- v5.0.6
- v5.0.5
- v5.0.4
- v5.0.3
- v5.0.2
- v5.0.1
- v5.0
- v4.19.29
- v4.19.28
- v4.19.27
- v4.19.26
- v4.19.25
- v4.19.24
- v4.19.23
- v4.19.22
- v4.19.21
- v4.19.20
- v4.19.19
- v4.19.18
- v4.19.17
- v4.19.16
- v4.19.15
- v4.19.14
- v4.19.13
- v4.19.12
- v4.19.11
- v4.19.10
- v4.19.9
- v4.19.8
- v4.19.7
- v4.19.6
- v4.19.5
- v4.19.4
- v4.19.3
- v4.19.2
- v4.19.1
- v4.19
- v4.18.20
- v4.18.19
- v4.18.18
- v4.18.17
- v4.18.16
- v4.18.15
- v4.18.14
- v4.18.13
- v4.18.12
- v4.18.11
- v4.18.10
- v4.18.9
- v4.18.7
- v4.18.6
- v4.18.5
- v4.18.4
- v4.18.3
- v4.18.2
- v4.18.1
- v4.18
- v4.17.18
- v4.17.17
- v4.17.16
- v4.17.15
- v4.17.14
- v4.17.13
- v4.17.12
- v4.17.11
- v4.17.10
- v4.17.9
- v4.17.8
- v4.17.7
- v4.17.6
- v4.17.5
- v4.17.4
- v4.17.3
- v4.17.2
- v4.17.1
- v4.17
- v4.16
- v4.15
- v4.14
- v4.13.16
- v4.13.5
- v4.13
- v4.12
Showing
10 changed files
with
379 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Shared Memory Communications over RDMA (SMC-R) and RoCE | ||
* | ||
* Definitions for the SMC module (socket related) | ||
* | ||
* Copyright IBM Corp. 2016 | ||
* | ||
* Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com> | ||
*/ | ||
#ifndef _SMC_H | ||
#define _SMC_H | ||
|
||
struct smc_hashinfo { | ||
rwlock_t lock; | ||
struct hlist_head ht; | ||
}; | ||
|
||
int smc_hash_sk(struct sock *sk); | ||
void smc_unhash_sk(struct sock *sk); | ||
#endif /* _SMC_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#ifndef _UAPI_SMC_DIAG_H_ | ||
#define _UAPI_SMC_DIAG_H_ | ||
|
||
#include <linux/types.h> | ||
#include <linux/inet_diag.h> | ||
#include <rdma/ib_verbs.h> | ||
|
||
/* Request structure */ | ||
struct smc_diag_req { | ||
__u8 diag_family; | ||
__u8 pad[2]; | ||
__u8 diag_ext; /* Query extended information */ | ||
struct inet_diag_sockid id; | ||
}; | ||
|
||
/* Base info structure. It contains socket identity (addrs/ports/cookie) based | ||
* on the internal clcsock, and more SMC-related socket data | ||
*/ | ||
struct smc_diag_msg { | ||
__u8 diag_family; | ||
__u8 diag_state; | ||
__u8 diag_fallback; | ||
__u8 diag_shutdown; | ||
struct inet_diag_sockid id; | ||
|
||
__u32 diag_uid; | ||
__u64 diag_inode; | ||
}; | ||
|
||
/* Extensions */ | ||
|
||
enum { | ||
SMC_DIAG_NONE, | ||
SMC_DIAG_CONNINFO, | ||
SMC_DIAG_LGRINFO, | ||
SMC_DIAG_SHUTDOWN, | ||
__SMC_DIAG_MAX, | ||
}; | ||
|
||
#define SMC_DIAG_MAX (__SMC_DIAG_MAX - 1) | ||
|
||
/* SMC_DIAG_CONNINFO */ | ||
|
||
struct smc_diag_cursor { | ||
__u16 reserved; | ||
__u16 wrap; | ||
__u32 count; | ||
}; | ||
|
||
struct smc_diag_conninfo { | ||
__u32 token; /* unique connection id */ | ||
__u32 sndbuf_size; /* size of send buffer */ | ||
__u32 rmbe_size; /* size of RMB element */ | ||
__u32 peer_rmbe_size; /* size of peer RMB element */ | ||
/* local RMB element cursors */ | ||
struct smc_diag_cursor rx_prod; /* received producer cursor */ | ||
struct smc_diag_cursor rx_cons; /* received consumer cursor */ | ||
/* peer RMB element cursors */ | ||
struct smc_diag_cursor tx_prod; /* sent producer cursor */ | ||
struct smc_diag_cursor tx_cons; /* sent consumer cursor */ | ||
__u8 rx_prod_flags; /* received producer flags */ | ||
__u8 rx_conn_state_flags; /* recvd connection flags*/ | ||
__u8 tx_prod_flags; /* sent producer flags */ | ||
__u8 tx_conn_state_flags; /* sent connection flags*/ | ||
/* send buffer cursors */ | ||
struct smc_diag_cursor tx_prep; /* prepared to be sent cursor */ | ||
struct smc_diag_cursor tx_sent; /* sent cursor */ | ||
struct smc_diag_cursor tx_fin; /* confirmed sent cursor */ | ||
}; | ||
|
||
/* SMC_DIAG_LINKINFO */ | ||
|
||
struct smc_diag_linkinfo { | ||
__u8 link_id; /* link identifier */ | ||
__u8 ibname[IB_DEVICE_NAME_MAX]; /* name of the RDMA device */ | ||
__u8 ibport; /* RDMA device port number */ | ||
__u8 gid[40]; /* local GID */ | ||
__u8 peer_gid[40]; /* peer GID */ | ||
}; | ||
|
||
struct smc_diag_lgrinfo { | ||
struct smc_diag_linkinfo lnk[1]; | ||
__u8 role; | ||
}; | ||
#endif /* _UAPI_SMC_DIAG_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
obj-$(CONFIG_SMC) += smc.o | ||
obj-$(CONFIG_SMC_DIAG) += smc_diag.o | ||
smc-y := af_smc.o smc_pnet.o smc_ib.o smc_clc.o smc_core.o smc_wr.o smc_llc.o | ||
smc-y += smc_cdc.o smc_tx.o smc_rx.o smc_close.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
/* | ||
* Shared Memory Communications over RDMA (SMC-R) and RoCE | ||
* | ||
* Monitoring SMC transport protocol sockets | ||
* | ||
* Copyright IBM Corp. 2016 | ||
* | ||
* Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com> | ||
*/ | ||
|
||
#include <linux/kernel.h> | ||
#include <linux/module.h> | ||
#include <linux/types.h> | ||
#include <linux/init.h> | ||
#include <linux/sock_diag.h> | ||
#include <linux/inet_diag.h> | ||
#include <linux/smc_diag.h> | ||
#include <net/netlink.h> | ||
#include <net/smc.h> | ||
|
||
#include "smc.h" | ||
#include "smc_core.h" | ||
|
||
static void smc_gid_be16_convert(__u8 *buf, u8 *gid_raw) | ||
{ | ||
sprintf(buf, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x", | ||
be16_to_cpu(((__be16 *)gid_raw)[0]), | ||
be16_to_cpu(((__be16 *)gid_raw)[1]), | ||
be16_to_cpu(((__be16 *)gid_raw)[2]), | ||
be16_to_cpu(((__be16 *)gid_raw)[3]), | ||
be16_to_cpu(((__be16 *)gid_raw)[4]), | ||
be16_to_cpu(((__be16 *)gid_raw)[5]), | ||
be16_to_cpu(((__be16 *)gid_raw)[6]), | ||
be16_to_cpu(((__be16 *)gid_raw)[7])); | ||
} | ||
|
||
static void smc_diag_msg_common_fill(struct smc_diag_msg *r, struct sock *sk) | ||
{ | ||
struct smc_sock *smc = smc_sk(sk); | ||
|
||
r->diag_family = sk->sk_family; | ||
if (!smc->clcsock) | ||
return; | ||
r->id.idiag_sport = htons(smc->clcsock->sk->sk_num); | ||
r->id.idiag_dport = smc->clcsock->sk->sk_dport; | ||
r->id.idiag_if = smc->clcsock->sk->sk_bound_dev_if; | ||
sock_diag_save_cookie(sk, r->id.idiag_cookie); | ||
memset(&r->id.idiag_src, 0, sizeof(r->id.idiag_src)); | ||
memset(&r->id.idiag_dst, 0, sizeof(r->id.idiag_dst)); | ||
r->id.idiag_src[0] = smc->clcsock->sk->sk_rcv_saddr; | ||
r->id.idiag_dst[0] = smc->clcsock->sk->sk_daddr; | ||
} | ||
|
||
static int smc_diag_msg_attrs_fill(struct sock *sk, struct sk_buff *skb, | ||
struct smc_diag_msg *r, | ||
struct user_namespace *user_ns) | ||
{ | ||
if (nla_put_u8(skb, SMC_DIAG_SHUTDOWN, sk->sk_shutdown)) | ||
return 1; | ||
|
||
r->diag_uid = from_kuid_munged(user_ns, sock_i_uid(sk)); | ||
r->diag_inode = sock_i_ino(sk); | ||
return 0; | ||
} | ||
|
||
static int __smc_diag_dump(struct sock *sk, struct sk_buff *skb, | ||
struct netlink_callback *cb, | ||
const struct smc_diag_req *req, | ||
struct nlattr *bc) | ||
{ | ||
struct smc_sock *smc = smc_sk(sk); | ||
struct user_namespace *user_ns; | ||
struct smc_diag_msg *r; | ||
struct nlmsghdr *nlh; | ||
|
||
nlh = nlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq, | ||
cb->nlh->nlmsg_type, sizeof(*r), NLM_F_MULTI); | ||
if (!nlh) | ||
return -EMSGSIZE; | ||
|
||
r = nlmsg_data(nlh); | ||
smc_diag_msg_common_fill(r, sk); | ||
r->diag_state = sk->sk_state; | ||
r->diag_fallback = smc->use_fallback; | ||
user_ns = sk_user_ns(NETLINK_CB(cb->skb).sk); | ||
if (smc_diag_msg_attrs_fill(sk, skb, r, user_ns)) | ||
goto errout; | ||
|
||
if ((req->diag_ext & (1 << (SMC_DIAG_CONNINFO - 1))) && smc->conn.lgr) { | ||
struct smc_connection *conn = &smc->conn; | ||
struct smc_diag_conninfo cinfo = { | ||
.token = conn->alert_token_local, | ||
.sndbuf_size = conn->sndbuf_size, | ||
.rmbe_size = conn->rmbe_size, | ||
.peer_rmbe_size = conn->peer_rmbe_size, | ||
|
||
.rx_prod.wrap = conn->local_rx_ctrl.prod.wrap, | ||
.rx_prod.count = conn->local_rx_ctrl.prod.count, | ||
.rx_cons.wrap = conn->local_rx_ctrl.cons.wrap, | ||
.rx_cons.count = conn->local_rx_ctrl.cons.count, | ||
|
||
.tx_prod.wrap = conn->local_tx_ctrl.prod.wrap, | ||
.tx_prod.count = conn->local_tx_ctrl.prod.count, | ||
.tx_cons.wrap = conn->local_tx_ctrl.cons.wrap, | ||
.tx_cons.count = conn->local_tx_ctrl.cons.count, | ||
|
||
.tx_prod_flags = | ||
*(u8 *)&conn->local_tx_ctrl.prod_flags, | ||
.tx_conn_state_flags = | ||
*(u8 *)&conn->local_tx_ctrl.conn_state_flags, | ||
.rx_prod_flags = *(u8 *)&conn->local_rx_ctrl.prod_flags, | ||
.rx_conn_state_flags = | ||
*(u8 *)&conn->local_rx_ctrl.conn_state_flags, | ||
|
||
.tx_prep.wrap = conn->tx_curs_prep.wrap, | ||
.tx_prep.count = conn->tx_curs_prep.count, | ||
.tx_sent.wrap = conn->tx_curs_sent.wrap, | ||
.tx_sent.count = conn->tx_curs_sent.count, | ||
.tx_fin.wrap = conn->tx_curs_fin.wrap, | ||
.tx_fin.count = conn->tx_curs_fin.count, | ||
}; | ||
|
||
if (nla_put(skb, SMC_DIAG_CONNINFO, sizeof(cinfo), &cinfo) < 0) | ||
goto errout; | ||
} | ||
|
||
if ((req->diag_ext & (1 << (SMC_DIAG_LGRINFO - 1))) && smc->conn.lgr) { | ||
struct smc_diag_lgrinfo linfo = { | ||
.role = smc->conn.lgr->role, | ||
.lnk[0].ibport = smc->conn.lgr->lnk[0].ibport, | ||
.lnk[0].link_id = smc->conn.lgr->lnk[0].link_id, | ||
}; | ||
|
||
memcpy(linfo.lnk[0].ibname, | ||
smc->conn.lgr->lnk[0].smcibdev->ibdev->name, | ||
sizeof(smc->conn.lgr->lnk[0].smcibdev->ibdev->name)); | ||
smc_gid_be16_convert(linfo.lnk[0].gid, | ||
smc->conn.lgr->lnk[0].gid.raw); | ||
smc_gid_be16_convert(linfo.lnk[0].peer_gid, | ||
smc->conn.lgr->lnk[0].peer_gid); | ||
|
||
if (nla_put(skb, SMC_DIAG_LGRINFO, sizeof(linfo), &linfo) < 0) | ||
goto errout; | ||
} | ||
|
||
nlmsg_end(skb, nlh); | ||
return 0; | ||
|
||
errout: | ||
nlmsg_cancel(skb, nlh); | ||
return -EMSGSIZE; | ||
} | ||
|
||
static int smc_diag_dump(struct sk_buff *skb, struct netlink_callback *cb) | ||
{ | ||
struct net *net = sock_net(skb->sk); | ||
struct nlattr *bc = NULL; | ||
struct hlist_head *head; | ||
struct sock *sk; | ||
int rc = 0; | ||
|
||
read_lock(&smc_proto.h.smc_hash->lock); | ||
head = &smc_proto.h.smc_hash->ht; | ||
if (hlist_empty(head)) | ||
goto out; | ||
|
||
sk_for_each(sk, head) { | ||
if (!net_eq(sock_net(sk), net)) | ||
continue; | ||
rc = __smc_diag_dump(sk, skb, cb, nlmsg_data(cb->nlh), bc); | ||
if (rc) | ||
break; | ||
} | ||
|
||
out: | ||
read_unlock(&smc_proto.h.smc_hash->lock); | ||
return rc; | ||
} | ||
|
||
static int smc_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h) | ||
{ | ||
struct net *net = sock_net(skb->sk); | ||
|
||
if (h->nlmsg_type == SOCK_DIAG_BY_FAMILY && | ||
h->nlmsg_flags & NLM_F_DUMP) { | ||
{ | ||
struct netlink_dump_control c = { | ||
.dump = smc_diag_dump, | ||
.min_dump_alloc = SKB_WITH_OVERHEAD(32768), | ||
}; | ||
return netlink_dump_start(net->diag_nlsk, skb, h, &c); | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
static const struct sock_diag_handler smc_diag_handler = { | ||
.family = AF_SMC, | ||
.dump = smc_diag_handler_dump, | ||
}; | ||
|
||
static int __init smc_diag_init(void) | ||
{ | ||
return sock_diag_register(&smc_diag_handler); | ||
} | ||
|
||
static void __exit smc_diag_exit(void) | ||
{ | ||
sock_diag_unregister(&smc_diag_handler); | ||
} | ||
|
||
module_init(smc_diag_init); | ||
module_exit(smc_diag_exit); | ||
MODULE_LICENSE("GPL"); | ||
MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 43 /* AF_SMC */); |