diff options
author | Erik Hugne <erik.hugne@ericsson.com> | 2014-04-24 10:26:47 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-04-26 12:13:24 -0400 |
commit | 78acb1f9b898e85fa2c1e28e700b54b66b288e8d (patch) | |
tree | 0520313d3d6afcc42d7aaf27fbe699e8bc71e2d5 | |
parent | a89778d8baf19cd7e728d81121a294a06cedaad1 (diff) |
tipc: add ioctl to fetch link names
We add a new ioctl for AF_TIPC that can be used to fetch the
logical name for a link to a remote node on a given bearer. This
should be used in combination with link state subscriptions.
The logical name size limit definitions are moved to tipc.h, as
they are now also needed by the new ioctl.
Signed-off-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Ying Xue <ying.xue@windriver.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/uapi/linux/tipc.h | 22 | ||||
-rw-r--r-- | include/uapi/linux/tipc_config.h | 10 | ||||
-rw-r--r-- | net/tipc/node.c | 27 | ||||
-rw-r--r-- | net/tipc/node.h | 1 | ||||
-rw-r--r-- | net/tipc/socket.c | 29 |
5 files changed, 77 insertions, 12 deletions
diff --git a/include/uapi/linux/tipc.h b/include/uapi/linux/tipc.h index 53cd7902d34e..6f71b9b41595 100644 --- a/include/uapi/linux/tipc.h +++ b/include/uapi/linux/tipc.h | |||
@@ -38,6 +38,7 @@ | |||
38 | #define _LINUX_TIPC_H_ | 38 | #define _LINUX_TIPC_H_ |
39 | 39 | ||
40 | #include <linux/types.h> | 40 | #include <linux/types.h> |
41 | #include <linux/sockios.h> | ||
41 | 42 | ||
42 | /* | 43 | /* |
43 | * TIPC addressing primitives | 44 | * TIPC addressing primitives |
@@ -207,4 +208,25 @@ struct sockaddr_tipc { | |||
207 | #define TIPC_NODE_RECVQ_DEPTH 131 /* Default: none (read only) */ | 208 | #define TIPC_NODE_RECVQ_DEPTH 131 /* Default: none (read only) */ |
208 | #define TIPC_SOCK_RECVQ_DEPTH 132 /* Default: none (read only) */ | 209 | #define TIPC_SOCK_RECVQ_DEPTH 132 /* Default: none (read only) */ |
209 | 210 | ||
211 | /* | ||
212 | * Maximum sizes of TIPC bearer-related names (including terminating NULL) | ||
213 | * The string formatting for each name element is: | ||
214 | * media: media | ||
215 | * interface: media:interface name | ||
216 | * link: Z.C.N:interface-Z.C.N:interface | ||
217 | * | ||
218 | */ | ||
219 | |||
220 | #define TIPC_MAX_MEDIA_NAME 16 | ||
221 | #define TIPC_MAX_IF_NAME 16 | ||
222 | #define TIPC_MAX_BEARER_NAME 32 | ||
223 | #define TIPC_MAX_LINK_NAME 60 | ||
224 | |||
225 | #define SIOCGETLINKNAME SIOCPROTOPRIVATE | ||
226 | |||
227 | struct tipc_sioc_ln_req { | ||
228 | __u32 peer; | ||
229 | __u32 bearer_id; | ||
230 | char linkname[TIPC_MAX_LINK_NAME]; | ||
231 | }; | ||
210 | #endif | 232 | #endif |
diff --git a/include/uapi/linux/tipc_config.h b/include/uapi/linux/tipc_config.h index 6b0bff09b3a7..41a76acbb305 100644 --- a/include/uapi/linux/tipc_config.h +++ b/include/uapi/linux/tipc_config.h | |||
@@ -39,6 +39,7 @@ | |||
39 | 39 | ||
40 | #include <linux/types.h> | 40 | #include <linux/types.h> |
41 | #include <linux/string.h> | 41 | #include <linux/string.h> |
42 | #include <linux/tipc.h> | ||
42 | #include <asm/byteorder.h> | 43 | #include <asm/byteorder.h> |
43 | 44 | ||
44 | #ifndef __KERNEL__ | 45 | #ifndef __KERNEL__ |
@@ -155,15 +156,6 @@ | |||
155 | #define TIPC_TLV_PORT_REF 26 /* 32-bit port reference */ | 156 | #define TIPC_TLV_PORT_REF 26 /* 32-bit port reference */ |
156 | 157 | ||
157 | /* | 158 | /* |
158 | * Maximum sizes of TIPC bearer-related names (including terminating NUL) | ||
159 | */ | ||
160 | |||
161 | #define TIPC_MAX_MEDIA_NAME 16 /* format = media */ | ||
162 | #define TIPC_MAX_IF_NAME 16 /* format = interface */ | ||
163 | #define TIPC_MAX_BEARER_NAME 32 /* format = media:interface */ | ||
164 | #define TIPC_MAX_LINK_NAME 60 /* format = Z.C.N:interface-Z.C.N:interface */ | ||
165 | |||
166 | /* | ||
167 | * Link priority limits (min, default, max, media default) | 159 | * Link priority limits (min, default, max, media default) |
168 | */ | 160 | */ |
169 | 161 | ||
diff --git a/net/tipc/node.c b/net/tipc/node.c index 3b86a74cb31f..1f938f3dba4b 100644 --- a/net/tipc/node.c +++ b/net/tipc/node.c | |||
@@ -438,3 +438,30 @@ struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space) | |||
438 | rcu_read_unlock(); | 438 | rcu_read_unlock(); |
439 | return buf; | 439 | return buf; |
440 | } | 440 | } |
441 | |||
442 | /** | ||
443 | * tipc_node_get_linkname - get the name of a link | ||
444 | * | ||
445 | * @bearer_id: id of the bearer | ||
446 | * @node: peer node address | ||
447 | * @linkname: link name output buffer | ||
448 | * | ||
449 | * Returns 0 on success | ||
450 | */ | ||
451 | int tipc_node_get_linkname(u32 bearer_id, u32 addr, char *linkname, size_t len) | ||
452 | { | ||
453 | struct tipc_link *link; | ||
454 | struct tipc_node *node = tipc_node_find(addr); | ||
455 | |||
456 | if ((bearer_id > MAX_BEARERS) || !node) | ||
457 | return -EINVAL; | ||
458 | tipc_node_lock(node); | ||
459 | link = node->links[bearer_id]; | ||
460 | if (link) { | ||
461 | strncpy(linkname, link->name, len); | ||
462 | tipc_node_unlock(node); | ||
463 | return 0; | ||
464 | } | ||
465 | tipc_node_unlock(node); | ||
466 | return -EINVAL; | ||
467 | } | ||
diff --git a/net/tipc/node.h b/net/tipc/node.h index 7cbb8cec1a93..411b19114064 100644 --- a/net/tipc/node.h +++ b/net/tipc/node.h | |||
@@ -118,6 +118,7 @@ int tipc_node_active_links(struct tipc_node *n_ptr); | |||
118 | int tipc_node_is_up(struct tipc_node *n_ptr); | 118 | int tipc_node_is_up(struct tipc_node *n_ptr); |
119 | struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space); | 119 | struct sk_buff *tipc_node_get_links(const void *req_tlv_area, int req_tlv_space); |
120 | struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space); | 120 | struct sk_buff *tipc_node_get_nodes(const void *req_tlv_area, int req_tlv_space); |
121 | int tipc_node_get_linkname(u32 bearer_id, u32 node, char *linkname, size_t len); | ||
121 | 122 | ||
122 | static inline void tipc_node_lock(struct tipc_node *n_ptr) | 123 | static inline void tipc_node_lock(struct tipc_node *n_ptr) |
123 | { | 124 | { |
diff --git a/net/tipc/socket.c b/net/tipc/socket.c index 3c0256962f7d..3f9912f87d0d 100644 --- a/net/tipc/socket.c +++ b/net/tipc/socket.c | |||
@@ -36,6 +36,7 @@ | |||
36 | 36 | ||
37 | #include "core.h" | 37 | #include "core.h" |
38 | #include "port.h" | 38 | #include "port.h" |
39 | #include "node.h" | ||
39 | 40 | ||
40 | #include <linux/export.h> | 41 | #include <linux/export.h> |
41 | 42 | ||
@@ -1905,6 +1906,28 @@ static int tipc_getsockopt(struct socket *sock, int lvl, int opt, | |||
1905 | return put_user(sizeof(value), ol); | 1906 | return put_user(sizeof(value), ol); |
1906 | } | 1907 | } |
1907 | 1908 | ||
1909 | int tipc_ioctl(struct socket *sk, unsigned int cmd, unsigned long arg) | ||
1910 | { | ||
1911 | struct tipc_sioc_ln_req lnr; | ||
1912 | void __user *argp = (void __user *)arg; | ||
1913 | |||
1914 | switch (cmd) { | ||
1915 | case SIOCGETLINKNAME: | ||
1916 | if (copy_from_user(&lnr, argp, sizeof(lnr))) | ||
1917 | return -EFAULT; | ||
1918 | if (!tipc_node_get_linkname(lnr.bearer_id, lnr.peer, | ||
1919 | lnr.linkname, TIPC_MAX_LINK_NAME)) { | ||
1920 | if (copy_to_user(argp, &lnr, sizeof(lnr))) | ||
1921 | return -EFAULT; | ||
1922 | return 0; | ||
1923 | } | ||
1924 | return -EADDRNOTAVAIL; | ||
1925 | break; | ||
1926 | default: | ||
1927 | return -ENOIOCTLCMD; | ||
1928 | } | ||
1929 | } | ||
1930 | |||
1908 | /* Protocol switches for the various types of TIPC sockets */ | 1931 | /* Protocol switches for the various types of TIPC sockets */ |
1909 | 1932 | ||
1910 | static const struct proto_ops msg_ops = { | 1933 | static const struct proto_ops msg_ops = { |
@@ -1917,7 +1940,7 @@ static const struct proto_ops msg_ops = { | |||
1917 | .accept = sock_no_accept, | 1940 | .accept = sock_no_accept, |
1918 | .getname = tipc_getname, | 1941 | .getname = tipc_getname, |
1919 | .poll = tipc_poll, | 1942 | .poll = tipc_poll, |
1920 | .ioctl = sock_no_ioctl, | 1943 | .ioctl = tipc_ioctl, |
1921 | .listen = sock_no_listen, | 1944 | .listen = sock_no_listen, |
1922 | .shutdown = tipc_shutdown, | 1945 | .shutdown = tipc_shutdown, |
1923 | .setsockopt = tipc_setsockopt, | 1946 | .setsockopt = tipc_setsockopt, |
@@ -1938,7 +1961,7 @@ static const struct proto_ops packet_ops = { | |||
1938 | .accept = tipc_accept, | 1961 | .accept = tipc_accept, |
1939 | .getname = tipc_getname, | 1962 | .getname = tipc_getname, |
1940 | .poll = tipc_poll, | 1963 | .poll = tipc_poll, |
1941 | .ioctl = sock_no_ioctl, | 1964 | .ioctl = tipc_ioctl, |
1942 | .listen = tipc_listen, | 1965 | .listen = tipc_listen, |
1943 | .shutdown = tipc_shutdown, | 1966 | .shutdown = tipc_shutdown, |
1944 | .setsockopt = tipc_setsockopt, | 1967 | .setsockopt = tipc_setsockopt, |
@@ -1959,7 +1982,7 @@ static const struct proto_ops stream_ops = { | |||
1959 | .accept = tipc_accept, | 1982 | .accept = tipc_accept, |
1960 | .getname = tipc_getname, | 1983 | .getname = tipc_getname, |
1961 | .poll = tipc_poll, | 1984 | .poll = tipc_poll, |
1962 | .ioctl = sock_no_ioctl, | 1985 | .ioctl = tipc_ioctl, |
1963 | .listen = tipc_listen, | 1986 | .listen = tipc_listen, |
1964 | .shutdown = tipc_shutdown, | 1987 | .shutdown = tipc_shutdown, |
1965 | .setsockopt = tipc_setsockopt, | 1988 | .setsockopt = tipc_setsockopt, |