aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc
diff options
context:
space:
mode:
authorJon Maloy <jon.maloy@ericsson.com>2018-04-25 13:29:36 -0400
committerDavid S. Miller <davem@davemloft.net>2018-04-27 11:05:41 -0400
commit3e5cf362c34b14c8d01d19d4b821fb35e1779862 (patch)
treed798193490f920228a538594fb7422d264d888fa /net/tipc
parent79741a38b4a2538a68342c45b813ecb9dd648ee8 (diff)
tipc: introduce ioctl for fetching node identity
After the introduction of a 128-bit node identity it may be difficult for a user to correlate between this identity and the generated node hash address. We now try to make this easier by introducing a new ioctl() call for fetching a node identity by using the hash value as key. This will be particularly useful when we extend some of the commands in the 'tipc' tool, but we also expect regular user applications to need this feature. Acked-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc')
-rw-r--r--net/tipc/node.c21
-rw-r--r--net/tipc/node.h1
-rw-r--r--net/tipc/socket.c13
3 files changed, 33 insertions, 2 deletions
diff --git a/net/tipc/node.c b/net/tipc/node.c
index e9c52e1416c5..81e6dd0cd1ca 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -195,6 +195,27 @@ int tipc_node_get_mtu(struct net *net, u32 addr, u32 sel)
195 return mtu; 195 return mtu;
196} 196}
197 197
198bool tipc_node_get_id(struct net *net, u32 addr, u8 *id)
199{
200 u8 *own_id = tipc_own_id(net);
201 struct tipc_node *n;
202
203 if (!own_id)
204 return true;
205
206 if (addr == tipc_own_addr(net)) {
207 memcpy(id, own_id, TIPC_NODEID_LEN);
208 return true;
209 }
210 n = tipc_node_find(net, addr);
211 if (!n)
212 return false;
213
214 memcpy(id, &n->peer_id, TIPC_NODEID_LEN);
215 tipc_node_put(n);
216 return true;
217}
218
198u16 tipc_node_get_capabilities(struct net *net, u32 addr) 219u16 tipc_node_get_capabilities(struct net *net, u32 addr)
199{ 220{
200 struct tipc_node *n; 221 struct tipc_node *n;
diff --git a/net/tipc/node.h b/net/tipc/node.h
index bb271a37c93f..846c8f240872 100644
--- a/net/tipc/node.h
+++ b/net/tipc/node.h
@@ -60,6 +60,7 @@ enum {
60#define INVALID_BEARER_ID -1 60#define INVALID_BEARER_ID -1
61 61
62void tipc_node_stop(struct net *net); 62void tipc_node_stop(struct net *net);
63bool tipc_node_get_id(struct net *net, u32 addr, u8 *id);
63u32 tipc_node_try_addr(struct net *net, u8 *id, u32 addr); 64u32 tipc_node_try_addr(struct net *net, u8 *id, u32 addr);
64void tipc_node_check_dest(struct net *net, u32 onode, u8 *peer_id128, 65void tipc_node_check_dest(struct net *net, u32 onode, u8 *peer_id128,
65 struct tipc_bearer *bearer, 66 struct tipc_bearer *bearer,
diff --git a/net/tipc/socket.c b/net/tipc/socket.c
index 252a52ae0893..c4992002fd68 100644
--- a/net/tipc/socket.c
+++ b/net/tipc/socket.c
@@ -2973,7 +2973,8 @@ static int tipc_getsockopt(struct socket *sock, int lvl, int opt,
2973 2973
2974static int tipc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 2974static int tipc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
2975{ 2975{
2976 struct sock *sk = sock->sk; 2976 struct net *net = sock_net(sock->sk);
2977 struct tipc_sioc_nodeid_req nr = {0};
2977 struct tipc_sioc_ln_req lnr; 2978 struct tipc_sioc_ln_req lnr;
2978 void __user *argp = (void __user *)arg; 2979 void __user *argp = (void __user *)arg;
2979 2980
@@ -2981,7 +2982,7 @@ static int tipc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
2981 case SIOCGETLINKNAME: 2982 case SIOCGETLINKNAME:
2982 if (copy_from_user(&lnr, argp, sizeof(lnr))) 2983 if (copy_from_user(&lnr, argp, sizeof(lnr)))
2983 return -EFAULT; 2984 return -EFAULT;
2984 if (!tipc_node_get_linkname(sock_net(sk), 2985 if (!tipc_node_get_linkname(net,
2985 lnr.bearer_id & 0xffff, lnr.peer, 2986 lnr.bearer_id & 0xffff, lnr.peer,
2986 lnr.linkname, TIPC_MAX_LINK_NAME)) { 2987 lnr.linkname, TIPC_MAX_LINK_NAME)) {
2987 if (copy_to_user(argp, &lnr, sizeof(lnr))) 2988 if (copy_to_user(argp, &lnr, sizeof(lnr)))
@@ -2989,6 +2990,14 @@ static int tipc_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
2989 return 0; 2990 return 0;
2990 } 2991 }
2991 return -EADDRNOTAVAIL; 2992 return -EADDRNOTAVAIL;
2993 case SIOCGETNODEID:
2994 if (copy_from_user(&nr, argp, sizeof(nr)))
2995 return -EFAULT;
2996 if (!tipc_node_get_id(net, nr.peer, nr.node_id))
2997 return -EADDRNOTAVAIL;
2998 if (copy_to_user(argp, &nr, sizeof(nr)))
2999 return -EFAULT;
3000 return 0;
2992 default: 3001 default:
2993 return -ENOIOCTLCMD; 3002 return -ENOIOCTLCMD;
2994 } 3003 }