Skip to content

Commit 357ebdb

Browse files
Richard Alpedavem330
authored andcommitted
tipc: convert legacy nl link dump to nl compat
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>
1 parent f2b3b2d commit 357ebdb

4 files changed

Lines changed: 23 additions & 79 deletions

File tree

‎net/tipc/config.c‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,6 @@ struct sk_buff *tipc_cfg_do_cmd(struct net *net, u32 orig_node, u16 cmd,
209209
rep_tlv_buf = tipc_node_get_nodes(net, req_tlv_area,
210210
req_tlv_space);
211211
break;
212-
case TIPC_CMD_GET_LINKS:
213-
rep_tlv_buf = tipc_node_get_links(net, req_tlv_area,
214-
req_tlv_space);
215-
break;
216212
case TIPC_CMD_RESET_LINK_STATS:
217213
rep_tlv_buf = tipc_link_cmd_reset_stats(net, req_tlv_area,
218214
req_tlv_space);

‎net/tipc/netlink_compat.c‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,22 @@ static int tipc_nl_compat_link_stat_dump(struct tipc_nl_compat_msg *msg,
553553
return 0;
554554
}
555555

556+
static int tipc_nl_compat_link_dump(struct tipc_nl_compat_msg *msg,
557+
struct nlattr **attrs)
558+
{
559+
struct nlattr *link[TIPC_NLA_LINK_MAX + 1];
560+
struct tipc_link_info link_info;
561+
562+
nla_parse_nested(link, TIPC_NLA_LINK_MAX, attrs[TIPC_NLA_LINK], NULL);
563+
564+
link_info.dest = nla_get_flag(link[TIPC_NLA_LINK_DEST]);
565+
link_info.up = htonl(nla_get_flag(link[TIPC_NLA_LINK_UP]));
566+
strcpy(link_info.str, nla_data(link[TIPC_NLA_LINK_NAME]));
567+
568+
return tipc_add_tlv(msg->rep, TIPC_TLV_LINK_INFO,
569+
&link_info, sizeof(link_info));
570+
}
571+
556572
static int tipc_nl_compat_handle(struct tipc_nl_compat_msg *msg)
557573
{
558574
struct tipc_nl_compat_cmd_dump dump;
@@ -584,6 +600,12 @@ static int tipc_nl_compat_handle(struct tipc_nl_compat_msg *msg)
584600
dump.dumpit = tipc_nl_link_dump;
585601
dump.format = tipc_nl_compat_link_stat_dump;
586602
return tipc_nl_compat_dumpit(&dump, msg);
603+
case TIPC_CMD_GET_LINKS:
604+
msg->req_type = TIPC_TLV_NET_ADDR;
605+
msg->rep_size = ULTRA_STRING_MAX_LEN;
606+
dump.dumpit = tipc_nl_link_dump;
607+
dump.format = tipc_nl_compat_link_dump;
608+
return tipc_nl_compat_dumpit(&dump, msg);
587609
}
588610

589611
return -EOPNOTSUPP;
@@ -684,6 +706,7 @@ static int tipc_nl_compat_tmp_wrap(struct sk_buff *skb, struct genl_info *info)
684706
case TIPC_CMD_ENABLE_BEARER:
685707
case TIPC_CMD_DISABLE_BEARER:
686708
case TIPC_CMD_SHOW_LINK_STATS:
709+
case TIPC_CMD_GET_LINKS:
687710
return tipc_nl_compat_recv(skb, info);
688711
}
689712

‎net/tipc/node.c‎

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -319,27 +319,18 @@ int tipc_node_is_up(struct tipc_node *n_ptr)
319319

320320
void tipc_node_attach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr)
321321
{
322-
struct tipc_net *tn = net_generic(n_ptr->net, tipc_net_id);
323-
324322
n_ptr->links[l_ptr->bearer_id] = l_ptr;
325-
spin_lock_bh(&tn->node_list_lock);
326-
tn->num_links++;
327-
spin_unlock_bh(&tn->node_list_lock);
328323
n_ptr->link_cnt++;
329324
}
330325

331326
void tipc_node_detach_link(struct tipc_node *n_ptr, struct tipc_link *l_ptr)
332327
{
333-
struct tipc_net *tn = net_generic(n_ptr->net, tipc_net_id);
334328
int i;
335329

336330
for (i = 0; i < MAX_BEARERS; i++) {
337331
if (l_ptr != n_ptr->links[i])
338332
continue;
339333
n_ptr->links[i] = NULL;
340-
spin_lock_bh(&tn->node_list_lock);
341-
tn->num_links--;
342-
spin_unlock_bh(&tn->node_list_lock);
343334
n_ptr->link_cnt--;
344335
}
345336
}
@@ -467,70 +458,6 @@ struct sk_buff *tipc_node_get_nodes(struct net *net, const void *req_tlv_area,
467458
return buf;
468459
}
469460

470-
struct sk_buff *tipc_node_get_links(struct net *net, const void *req_tlv_area,
471-
int req_tlv_space)
472-
{
473-
struct tipc_net *tn = net_generic(net, tipc_net_id);
474-
u32 domain;
475-
struct sk_buff *buf;
476-
struct tipc_node *n_ptr;
477-
struct tipc_link_info link_info;
478-
u32 payload_size;
479-
480-
if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_NET_ADDR))
481-
return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR);
482-
483-
domain = ntohl(*(__be32 *)TLV_DATA(req_tlv_area));
484-
if (!tipc_addr_domain_valid(domain))
485-
return tipc_cfg_reply_error_string(TIPC_CFG_INVALID_VALUE
486-
" (network address)");
487-
488-
if (!tn->own_addr)
489-
return tipc_cfg_reply_none();
490-
491-
spin_lock_bh(&tn->node_list_lock);
492-
/* Get space for all unicast links + broadcast link */
493-
payload_size = TLV_SPACE((sizeof(link_info)) * (tn->num_links + 1));
494-
if (payload_size > 32768u) {
495-
spin_unlock_bh(&tn->node_list_lock);
496-
return tipc_cfg_reply_error_string(TIPC_CFG_NOT_SUPPORTED
497-
" (too many links)");
498-
}
499-
spin_unlock_bh(&tn->node_list_lock);
500-
501-
buf = tipc_cfg_reply_alloc(payload_size);
502-
if (!buf)
503-
return NULL;
504-
505-
/* Add TLV for broadcast link */
506-
link_info.dest = htonl(tipc_cluster_mask(tn->own_addr));
507-
link_info.up = htonl(1);
508-
strlcpy(link_info.str, tipc_bclink_name, TIPC_MAX_LINK_NAME);
509-
tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO, &link_info, sizeof(link_info));
510-
511-
/* Add TLVs for any other links in scope */
512-
rcu_read_lock();
513-
list_for_each_entry_rcu(n_ptr, &tn->node_list, list) {
514-
u32 i;
515-
516-
if (!tipc_in_scope(domain, n_ptr->addr))
517-
continue;
518-
tipc_node_lock(n_ptr);
519-
for (i = 0; i < MAX_BEARERS; i++) {
520-
if (!n_ptr->links[i])
521-
continue;
522-
link_info.dest = htonl(n_ptr->addr);
523-
link_info.up = htonl(tipc_link_is_up(n_ptr->links[i]));
524-
strcpy(link_info.str, n_ptr->links[i]->name);
525-
tipc_cfg_append_tlv(buf, TIPC_TLV_LINK_INFO,
526-
&link_info, sizeof(link_info));
527-
}
528-
tipc_node_unlock(n_ptr);
529-
}
530-
rcu_read_unlock();
531-
return buf;
532-
}
533-
534461
/**
535462
* tipc_node_get_linkname - get the name of a link
536463
*

‎net/tipc/node.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ void tipc_node_link_down(struct tipc_node *n_ptr, struct tipc_link *l_ptr);
142142
void tipc_node_link_up(struct tipc_node *n_ptr, struct tipc_link *l_ptr);
143143
int tipc_node_active_links(struct tipc_node *n_ptr);
144144
int tipc_node_is_up(struct tipc_node *n_ptr);
145-
struct sk_buff *tipc_node_get_links(struct net *net, const void *req_tlv_area,
146-
int req_tlv_space);
147145
struct sk_buff *tipc_node_get_nodes(struct net *net, const void *req_tlv_area,
148146
int req_tlv_space);
149147
int tipc_node_get_linkname(struct net *net, u32 bearer_id, u32 node,

0 commit comments

Comments
 (0)