aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Alpe <richard.alpe@ericsson.com>2015-02-09 03:50:13 -0500
committerDavid S. Miller <davem@davemloft.net>2015-02-09 16:20:49 -0500
commit4b28cb581dd0df8d8ff19151f39683f641e576ba (patch)
tree83509766ab4e8c5d48fcbaa187c5069d9d8f88cc
parent5bfc335a637ad4aecededb67b0075aae72a6dbb3 (diff)
tipc: convert legacy nl node dump to nl compat
Convert TIPC_CMD_GET_NODES to compat dumpit and remove global node counter solely used by the legacy API. Signed-off-by: Richard Alpe <richard.alpe@ericsson.com> Reviewed-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--net/tipc/config.c4
-rw-r--r--net/tipc/netlink_compat.c22
-rw-r--r--net/tipc/node.c54
-rw-r--r--net/tipc/node.h2
4 files changed, 22 insertions, 60 deletions
diff --git a/net/tipc/config.c b/net/tipc/config.c
index df410823e889..74babd75c07d 100644
--- a/net/tipc/config.c
+++ b/net/tipc/config.c
@@ -205,10 +205,6 @@ struct sk_buff *tipc_cfg_do_cmd(struct net *net, u32 orig_node, u16 cmd,
205 case TIPC_CMD_NOOP: 205 case TIPC_CMD_NOOP:
206 rep_tlv_buf = tipc_cfg_reply_none(); 206 rep_tlv_buf = tipc_cfg_reply_none();
207 break; 207 break;
208 case TIPC_CMD_GET_NODES:
209 rep_tlv_buf = tipc_node_get_nodes(net, req_tlv_area,
210 req_tlv_space);
211 break;
212 case TIPC_CMD_SHOW_STATS: 208 case TIPC_CMD_SHOW_STATS:
213 rep_tlv_buf = tipc_show_stats(); 209 rep_tlv_buf = tipc_show_stats();
214 break; 210 break;
diff --git a/net/tipc/netlink_compat.c b/net/tipc/netlink_compat.c
index d23075efaa76..0dc448e77e13 100644
--- a/net/tipc/netlink_compat.c
+++ b/net/tipc/netlink_compat.c
@@ -37,6 +37,7 @@
37#include "link.h" 37#include "link.h"
38#include "name_table.h" 38#include "name_table.h"
39#include "socket.h" 39#include "socket.h"
40#include "node.h"
40#include <net/genetlink.h> 41#include <net/genetlink.h>
41#include <linux/tipc_config.h> 42#include <linux/tipc_config.h>
42 43
@@ -835,6 +836,21 @@ static int tipc_nl_compat_media_dump(struct tipc_nl_compat_msg *msg,
835 nla_len(media[TIPC_NLA_MEDIA_NAME])); 836 nla_len(media[TIPC_NLA_MEDIA_NAME]));
836} 837}
837 838
839static int tipc_nl_compat_node_dump(struct tipc_nl_compat_msg *msg,
840 struct nlattr **attrs)
841{
842 struct tipc_node_info node_info;
843 struct nlattr *node[TIPC_NLA_NODE_MAX + 1];
844
845 nla_parse_nested(node, TIPC_NLA_NODE_MAX, attrs[TIPC_NLA_NODE], NULL);
846
847 node_info.addr = htonl(nla_get_u32(node[TIPC_NLA_NODE_ADDR]));
848 node_info.up = htonl(nla_get_flag(node[TIPC_NLA_NODE_UP]));
849
850 return tipc_add_tlv(msg->rep, TIPC_TLV_NODE_INFO, &node_info,
851 sizeof(node_info));
852}
853
838static int tipc_nl_compat_handle(struct tipc_nl_compat_msg *msg) 854static int tipc_nl_compat_handle(struct tipc_nl_compat_msg *msg)
839{ 855{
840 struct tipc_nl_compat_cmd_dump dump; 856 struct tipc_nl_compat_cmd_dump dump;
@@ -903,6 +919,11 @@ static int tipc_nl_compat_handle(struct tipc_nl_compat_msg *msg)
903 dump.dumpit = tipc_nl_media_dump; 919 dump.dumpit = tipc_nl_media_dump;
904 dump.format = tipc_nl_compat_media_dump; 920 dump.format = tipc_nl_compat_media_dump;
905 return tipc_nl_compat_dumpit(&dump, msg); 921 return tipc_nl_compat_dumpit(&dump, msg);
922 case TIPC_CMD_GET_NODES:
923 msg->rep_size = ULTRA_STRING_MAX_LEN;
924 dump.dumpit = tipc_nl_node_dump;
925 dump.format = tipc_nl_compat_node_dump;
926 return tipc_nl_compat_dumpit(&dump, msg);
906 } 927 }
907 928
908 return -EOPNOTSUPP; 929 return -EOPNOTSUPP;
@@ -1011,6 +1032,7 @@ static int tipc_nl_compat_tmp_wrap(struct sk_buff *skb, struct genl_info *info)
1011 case TIPC_CMD_SHOW_NAME_TABLE: 1032 case TIPC_CMD_SHOW_NAME_TABLE:
1012 case TIPC_CMD_SHOW_PORTS: 1033 case TIPC_CMD_SHOW_PORTS:
1013 case TIPC_CMD_GET_MEDIA_NAMES: 1034 case TIPC_CMD_GET_MEDIA_NAMES:
1035 case TIPC_CMD_GET_NODES:
1014 return tipc_nl_compat_recv(skb, info); 1036 return tipc_nl_compat_recv(skb, info);
1015 } 1037 }
1016 1038
diff --git a/net/tipc/node.c b/net/tipc/node.c
index 46b87f77d342..ddaa2bbaa35d 100644
--- a/net/tipc/node.c
+++ b/net/tipc/node.c
@@ -120,7 +120,6 @@ struct tipc_node *tipc_node_create(struct net *net, u32 addr)
120 list_add_tail_rcu(&n_ptr->list, &temp_node->list); 120 list_add_tail_rcu(&n_ptr->list, &temp_node->list);
121 n_ptr->action_flags = TIPC_WAIT_PEER_LINKS_DOWN; 121 n_ptr->action_flags = TIPC_WAIT_PEER_LINKS_DOWN;
122 n_ptr->signature = INVALID_NODE_SIG; 122 n_ptr->signature = INVALID_NODE_SIG;
123 tn->num_nodes++;
124exit: 123exit:
125 spin_unlock_bh(&tn->node_list_lock); 124 spin_unlock_bh(&tn->node_list_lock);
126 return n_ptr; 125 return n_ptr;
@@ -131,8 +130,6 @@ static void tipc_node_delete(struct tipc_net *tn, struct tipc_node *n_ptr)
131 list_del_rcu(&n_ptr->list); 130 list_del_rcu(&n_ptr->list);
132 hlist_del_rcu(&n_ptr->hash); 131 hlist_del_rcu(&n_ptr->hash);
133 kfree_rcu(n_ptr, rcu); 132 kfree_rcu(n_ptr, rcu);
134
135 tn->num_nodes--;
136} 133}
137 134
138void tipc_node_stop(struct net *net) 135void tipc_node_stop(struct net *net)
@@ -407,57 +404,6 @@ static void node_lost_contact(struct tipc_node *n_ptr)
407 } 404 }
408} 405}
409 406
410struct sk_buff *tipc_node_get_nodes(struct net *net, const void *req_tlv_area,
411 int req_tlv_space)
412{
413 struct tipc_net *tn = net_generic(net, tipc_net_id);
414 u32 domain;
415 struct sk_buff *buf;
416 struct tipc_node *n_ptr;
417 struct tipc_node_info node_info;
418 u32 payload_size;
419
420 if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
421 return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
422
423 domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
424 if (!tipc_addr_domain_valid(domain))
425 return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
426 " (network address)");
427
428 spin_lock_bh(&tn->node_list_lock);
429 if (!tn->num_nodes) {
430 spin_unlock_bh(&tn->node_list_lock);
431 return tipc_cfg_reply_none();
432 }
433
434 /* For now, get space for all other nodes */
435 payload_size = TLV_SPACE(sizeof(node_info)) * tn->num_nodes;
436 if (payload_size > 32768u) {
437 spin_unlock_bh(&tn->node_list_lock);
438 return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
439 " (too many nodes)");
440 }
441 spin_unlock_bh(&tn->node_list_lock);
442
443 buf = tipc_cfg_reply_alloc(payload_size);
444 if (!buf)
445 return NULL;
446
447 /* Add TLVs for all nodes in scope */
448 rcu_read_lock();
449 list_for_each_entry_rcu(n_ptr, &tn->node_list, list) {
450 if (!tipc_in_scope(domain, n_ptr->addr))
451 continue;
452 node_info.addr = htonl(n_ptr->addr);
453 node_info.up = htonl(tipc_node_is_up(n_ptr));
454 tipc_cfg_append_tlv(buf, TIPC_TLV_NODE_INFO,
455 &node_info, sizeof(node_info));
456 }
457 rcu_read_unlock();
458 return buf;
459}
460
461/** 407/**
462 * tipc_node_get_linkname - get the name of a link 408 * tipc_node_get_linkname - get the name of a link
463 * 409 *
diff --git a/net/tipc/node.h b/net/tipc/node.h
index 59dafee61aa0..3d18c66b7f78 100644
--- a/net/tipc/node.h
+++ b/net/tipc/node.h
@@ -142,8 +142,6 @@ void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr);
142void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr); 142void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr);
143int tipc_node_active_links(struct tipc_node *n_ptr); 143int tipc_node_active_links(struct tipc_node *n_ptr);
144int tipc_node_is_up(struct tipc_node *n_ptr); 144int tipc_node_is_up(struct tipc_node *n_ptr);
145struct sk_buff *tipc_node_get_nodes(struct net *net, const void *req_tlv_area,
146 int req_tlv_space);
147int tipc_node_get_linkname(struct net *net, u32 bearer_id, u32 node, 145int tipc_node_get_linkname(struct net *net, u32 bearer_id, u32 node,
148 char *linkname, size_t len); 146 char *linkname, size_t len);
149void tipc_node_unlock(struct tipc_node *node); 147void tipc_node_unlock(struct tipc_node *node);