aboutsummaryrefslogtreecommitdiffstats
path: root/net/tipc/port.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/tipc/port.c')
-rw-r--r--net/tipc/port.c58
1 files changed, 32 insertions, 26 deletions
diff --git a/net/tipc/port.c b/net/tipc/port.c
index 2cbac3956fc9..07c42fba672b 100644
--- a/net/tipc/port.c
+++ b/net/tipc/port.c
@@ -581,67 +581,73 @@ exit:
581 kfree_skb(buf); 581 kfree_skb(buf);
582} 582}
583 583
584static void port_print(struct tipc_port *p_ptr, struct print_buf *buf, int full_id) 584static int port_print(struct tipc_port *p_ptr, char *buf, int len, int full_id)
585{ 585{
586 struct publication *publ; 586 struct publication *publ;
587 int ret;
587 588
588 if (full_id) 589 if (full_id)
589 tipc_printf(buf, "<%u.%u.%u:%u>:", 590 ret = tipc_snprintf(buf, len, "<%u.%u.%u:%u>:",
590 tipc_zone(tipc_own_addr), tipc_cluster(tipc_own_addr), 591 tipc_zone(tipc_own_addr),
591 tipc_node(tipc_own_addr), p_ptr->ref); 592 tipc_cluster(tipc_own_addr),
593 tipc_node(tipc_own_addr), p_ptr->ref);
592 else 594 else
593 tipc_printf(buf, "%-10u:", p_ptr->ref); 595 ret = tipc_snprintf(buf, len, "%-10u:", p_ptr->ref);
594 596
595 if (p_ptr->connected) { 597 if (p_ptr->connected) {
596 u32 dport = port_peerport(p_ptr); 598 u32 dport = port_peerport(p_ptr);
597 u32 destnode = port_peernode(p_ptr); 599 u32 destnode = port_peernode(p_ptr);
598 600
599 tipc_printf(buf, " connected to <%u.%u.%u:%u>", 601 ret += tipc_snprintf(buf + ret, len - ret,
600 tipc_zone(destnode), tipc_cluster(destnode), 602 " connected to <%u.%u.%u:%u>",
601 tipc_node(destnode), dport); 603 tipc_zone(destnode),
604 tipc_cluster(destnode),
605 tipc_node(destnode), dport);
602 if (p_ptr->conn_type != 0) 606 if (p_ptr->conn_type != 0)
603 tipc_printf(buf, " via {%u,%u}", 607 ret += tipc_snprintf(buf + ret, len - ret,
604 p_ptr->conn_type, 608 " via {%u,%u}", p_ptr->conn_type,
605 p_ptr->conn_instance); 609 p_ptr->conn_instance);
606 } else if (p_ptr->published) { 610 } else if (p_ptr->published) {
607 tipc_printf(buf, " bound to"); 611 ret += tipc_snprintf(buf + ret, len - ret, " bound to");
608 list_for_each_entry(publ, &p_ptr->publications, pport_list) { 612 list_for_each_entry(publ, &p_ptr->publications, pport_list) {
609 if (publ->lower == publ->upper) 613 if (publ->lower == publ->upper)
610 tipc_printf(buf, " {%u,%u}", publ->type, 614 ret += tipc_snprintf(buf + ret, len - ret,
611 publ->lower); 615 " {%u,%u}", publ->type,
616 publ->lower);
612 else 617 else
613 tipc_printf(buf, " {%u,%u,%u}", publ->type, 618 ret += tipc_snprintf(buf + ret, len - ret,
614 publ->lower, publ->upper); 619 " {%u,%u,%u}", publ->type,
620 publ->lower, publ->upper);
615 } 621 }
616 } 622 }
617 tipc_printf(buf, "\n"); 623 ret += tipc_snprintf(buf + ret, len - ret, "\n");
624 return ret;
618} 625}
619 626
620#define MAX_PORT_QUERY 32768
621
622struct sk_buff *tipc_port_get_ports(void) 627struct sk_buff *tipc_port_get_ports(void)
623{ 628{
624 struct sk_buff *buf; 629 struct sk_buff *buf;
625 struct tlv_desc *rep_tlv; 630 struct tlv_desc *rep_tlv;
626 struct print_buf pb; 631 char *pb;
632 int pb_len;
627 struct tipc_port *p_ptr; 633 struct tipc_port *p_ptr;
628 int str_len; 634 int str_len = 0;
629 635
630 buf = tipc_cfg_reply_alloc(TLV_SPACE(MAX_PORT_QUERY)); 636 buf = tipc_cfg_reply_alloc(TLV_SPACE(ULTRA_STRING_MAX_LEN));
631 if (!buf) 637 if (!buf)
632 return NULL; 638 return NULL;
633 rep_tlv = (struct tlv_desc *)buf->data; 639 rep_tlv = (struct tlv_desc *)buf->data;
640 pb = TLV_DATA(rep_tlv);
641 pb_len = ULTRA_STRING_MAX_LEN;
634 642
635 tipc_printbuf_init(&pb, TLV_DATA(rep_tlv), MAX_PORT_QUERY);
636 spin_lock_bh(&tipc_port_list_lock); 643 spin_lock_bh(&tipc_port_list_lock);
637 list_for_each_entry(p_ptr, &ports, port_list) { 644 list_for_each_entry(p_ptr, &ports, port_list) {
638 spin_lock_bh(p_ptr->lock); 645 spin_lock_bh(p_ptr->lock);
639 port_print(p_ptr, &pb, 0); 646 str_len += port_print(p_ptr, pb, pb_len, 0);
640 spin_unlock_bh(p_ptr->lock); 647 spin_unlock_bh(p_ptr->lock);
641 } 648 }
642 spin_unlock_bh(&tipc_port_list_lock); 649 spin_unlock_bh(&tipc_port_list_lock);
643 str_len = tipc_printbuf_validate(&pb); 650 str_len += 1; /* for "\0" */
644
645 skb_put(buf, TLV_SPACE(str_len)); 651 skb_put(buf, TLV_SPACE(str_len));
646 TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len); 652 TLV_SET(rep_tlv, TIPC_TLV_ULTRA_STRING, NULL, str_len);
647 653