]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
tipc: convert legacy nl link dump to nl compat
authorRichard Alpe <richard.alpe@ericsson.com>
Mon, 9 Feb 2015 08:50:07 +0000 (09:50 +0100)
committerDavid S. Miller <davem@davemloft.net>
Mon, 9 Feb 2015 21:20:48 +0000 (13:20 -0800)
Convert TIPC_CMD_GET_LINKS to compat dumpit and remove global link
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>
net/tipc/config.c
net/tipc/netlink_compat.c
net/tipc/node.c
net/tipc/node.h

index 67b76ee847f33084585928fead2a659ed6cce411..1b17f5846e86d9b81e13e29b33df06a8c722097b 100644 (file)
@@ -209,10 +209,6 @@ struct sk_buff *tipc_cfg_do_cmd(struct net *net, u32 orig_node, u16 cmd,
                rep_tlv_buf = tipc_node_get_nodes(net, req_tlv_area,
                                                  req_tlv_space);
                break;
-       case TIPC_CMD_GET_LINKS:
-               rep_tlv_buf = tipc_node_get_links(net, req_tlv_area,
-                                                 req_tlv_space);
-               break;
        case TIPC_CMD_RESET_LINK_STATS:
                rep_tlv_buf = tipc_link_cmd_reset_stats(net, req_tlv_area,
                                                        req_tlv_space);
index 899bd94da4678637c1cfbbb7de672ba1a430374f..bff9403899eda93ef533c6d9a0e0b07edc93082a 100644 (file)
@@ -553,6 +553,22 @@ static int tipc_nl_compat_link_stat_dump(struct tipc_nl_compat_msg *msg,
        return 0;
 }
 
+static int tipc_nl_compat_link_dump(struct tipc_nl_compat_msg *msg,
+                                   struct nlattr **attrs)
+{
+       struct nlattr *link[TIPC_NLA_LINK_MAX + 1];
+       struct tipc_link_info link_info;
+
+       nla_parse_nested(link, TIPC_NLA_LINK_MAX, attrs[TIPC_NLA_LINK], NULL);
+
+       link_info.dest = nla_get_flag(link[TIPC_NLA_LINK_DEST]);
+       link_info.up = htonl(nla_get_flag(link[TIPC_NLA_LINK_UP]));
+       strcpy(link_info.str, nla_data(link[TIPC_NLA_LINK_NAME]));
+
+       return tipc_add_tlv(msg->rep, TIPC_TLV_LINK_INFO,
+                           &link_info, sizeof(link_info));
+}
+
 static int tipc_nl_compat_handle(struct tipc_nl_compat_msg *msg)
 {
        struct tipc_nl_compat_cmd_dump dump;
@@ -584,6 +600,12 @@ static int tipc_nl_compat_handle(struct tipc_nl_compat_msg *msg)
                dump.dumpit = tipc_nl_link_dump;
                dump.format = tipc_nl_compat_link_stat_dump;
                return tipc_nl_compat_dumpit(&dump, msg);
+       case TIPC_CMD_GET_LINKS:
+               msg->req_type = TIPC_TLV_NET_ADDR;
+               msg->rep_size = ULTRA_STRING_MAX_LEN;
+               dump.dumpit = tipc_nl_link_dump;
+               dump.format = tipc_nl_compat_link_dump;
+               return tipc_nl_compat_dumpit(&dump, msg);
        }
 
        return -EOPNOTSUPP;
@@ -684,6 +706,7 @@ static int tipc_nl_compat_tmp_wrap(struct sk_buff *skb, struct genl_info *info)
        case TIPC_CMD_ENABLE_BEARER:
        case TIPC_CMD_DISABLE_BEARER:
        case TIPC_CMD_SHOW_LINK_STATS:
+       case TIPC_CMD_GET_LINKS:
                return tipc_nl_compat_recv(skb, info);
        }
 
index 995618d6da9d74986755c57939fc53d6ababe19b..46b87f77d3427381bef8e7a4e98222374426c9c4 100644 (file)
@@ -319,27 +319,18 @@ int tipc_node_is_up(struct tipc_node *n_ptr)
 
 void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr)
 {
-       struct tipc_net *tn = net_generic(n_ptr->net, tipc_net_id);
-
        n_ptr->links[l_ptr->bearer_id] = l_ptr;
-       spin_lock_bh(&tn->node_list_lock);
-       tn->num_links++;
-       spin_unlock_bh(&tn->node_list_lock);
        n_ptr->link_cnt++;
 }
 
 void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr)
 {
-       struct tipc_net *tn = net_generic(n_ptr->net, tipc_net_id);
        int i;
 
        for (i = 0; i < MAX_BEARERS; i++) {
                if (l_ptr != n_ptr->links[i])
                        continue;
                n_ptr->links[i] = NULL;
-               spin_lock_bh(&tn->node_list_lock);
-               tn->num_links--;
-               spin_unlock_bh(&tn->node_list_lock);
                n_ptr->link_cnt--;
        }
 }
@@ -467,70 +458,6 @@ struct sk_buff *tipc_node_get_nodes(struct net *net, const void *req_tlv_area,
        return buf;
 }
 
-struct sk_buff *tipc_node_get_links(struct net *net, const void *req_tlv_area,
-                                   int req_tlv_space)
-{
-       struct tipc_net *tn = net_generic(net, tipc_net_id);
-       u32 domain;
-       struct sk_buff *buf;
-       struct tipc_node *n_ptr;
-       struct tipc_link_info link_info;
-       u32 payload_size;
-
-       if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
-               return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
-
-       domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
-       if (!tipc_addr_domain_valid(domain))
-               return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
-                                                  " (network address)");
-
-       if (!tn->own_addr)
-               return tipc_cfg_reply_none();
-
-       spin_lock_bh(&tn->node_list_lock);
-       /* Get space for all unicast links + broadcast link */
-       payload_size = TLV_SPACE((sizeof(link_info)) * (tn->num_links + 1));
-       if (payload_size > 32768u) {
-               spin_unlock_bh(&tn->node_list_lock);
-               return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
-                                                  " (too many links)");
-       }
-       spin_unlock_bh(&tn->node_list_lock);
-
-       buf = tipc_cfg_reply_alloc(payload_size);
-       if (!buf)
-               return NULL;
-
-       /* Add TLV for broadcast link */
-       link_info.dest = htonl(tipc_cluster_mask(tn->own_addr));
-       link_info.up = htonl(1);
-       strlcpy(link_info.str, tipc_bclink_name, TIPC_MAX_LINK_NAME);
-       tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, &link_info, sizeof(link_info));
-
-       /* Add TLVs for any other links in scope */
-       rcu_read_lock();
-       list_for_each_entry_rcu(n_ptr, &tn->node_list, list) {
-               u32 i;
-
-               if (!tipc_in_scope(domain, n_ptr->addr))
-                       continue;
-               tipc_node_lock(n_ptr);
-               for (i = 0; i < MAX_BEARERS; i++) {
-                       if (!n_ptr->links[i])
-                               continue;
-                       link_info.dest = htonl(n_ptr->addr);
-                       link_info.up = htonl(tipc_link_is_up(n_ptr->links[i]));
-                       strcpy(link_info.str, n_ptr->links[i]->name);
-                       tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO,
-                                           &link_info, sizeof(link_info));
-               }
-               tipc_node_unlock(n_ptr);
-       }
-       rcu_read_unlock();
-       return buf;
-}
-
 /**
  * tipc_node_get_linkname - get the name of a link
  *
index 20ec13f9bede631d3aee5cff6521f775d7fdc321..59dafee61aa04394335eaa92993b035c067d8495 100644 (file)
@@ -142,8 +142,6 @@ void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr);
 void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr);
 int tipc_node_active_links(struct tipc_node *n_ptr);
 int tipc_node_is_up(struct tipc_node *n_ptr);
-struct sk_buff *tipc_node_get_links(struct net *net, const void *req_tlv_area,
-                                   int req_tlv_space);
 struct sk_buff *tipc_node_get_nodes(struct net *net, const void *req_tlv_area,
                                    int req_tlv_space);
 int tipc_node_get_linkname(struct net *net, u32 bearer_id, u32 node,