diff options
author | Richard Alpe <richard.alpe@ericsson.com> | 2015-02-09 03:50:11 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-02-09 16:20:48 -0500 |
commit | 487d2a3a1326d339ce273ffbcd03247f2b7b052e (patch) | |
tree | 6ffa649e50216a6a894cf4fe0143b587ee2e190d /net/tipc/netlink_compat.c | |
parent | 44a8ae94fd5525aa06a8c71cb52efbc418fb8b7c (diff) |
tipc: convert legacy nl socket dump to nl compat
Convert socket (port) listing to compat dumpit call. If a socket
(port) has publications a second dumpit call is issued to collect them
and format then into the legacy buffer before continuing to process
the sockets (ports).
Command converted in this patch:
TIPC_CMD_SHOW_PORTS
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>
Diffstat (limited to 'net/tipc/netlink_compat.c')
-rw-r--r-- | net/tipc/netlink_compat.c | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/net/tipc/netlink_compat.c b/net/tipc/netlink_compat.c index 40c24ea31231..48e15a4a36d8 100644 --- a/net/tipc/netlink_compat.c +++ b/net/tipc/netlink_compat.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include "bearer.h" | 36 | #include "bearer.h" |
37 | #include "link.h" | 37 | #include "link.h" |
38 | #include "name_table.h" | 38 | #include "name_table.h" |
39 | #include "socket.h" | ||
39 | #include <net/genetlink.h> | 40 | #include <net/genetlink.h> |
40 | #include <linux/tipc_config.h> | 41 | #include <linux/tipc_config.h> |
41 | 42 | ||
@@ -718,6 +719,109 @@ out: | |||
718 | return 0; | 719 | return 0; |
719 | } | 720 | } |
720 | 721 | ||
722 | static int __tipc_nl_compat_publ_dump(struct tipc_nl_compat_msg *msg, | ||
723 | struct nlattr **attrs) | ||
724 | { | ||
725 | u32 type, lower, upper; | ||
726 | struct nlattr *publ[TIPC_NLA_PUBL_MAX + 1]; | ||
727 | |||
728 | nla_parse_nested(publ, TIPC_NLA_PUBL_MAX, attrs[TIPC_NLA_PUBL], NULL); | ||
729 | |||
730 | type = nla_get_u32(publ[TIPC_NLA_PUBL_TYPE]); | ||
731 | lower = nla_get_u32(publ[TIPC_NLA_PUBL_LOWER]); | ||
732 | upper = nla_get_u32(publ[TIPC_NLA_PUBL_UPPER]); | ||
733 | |||
734 | if (lower == upper) | ||
735 | tipc_tlv_sprintf(msg->rep, " {%u,%u}", type, lower); | ||
736 | else | ||
737 | tipc_tlv_sprintf(msg->rep, " {%u,%u,%u}", type, lower, upper); | ||
738 | |||
739 | return 0; | ||
740 | } | ||
741 | |||
742 | static int tipc_nl_compat_publ_dump(struct tipc_nl_compat_msg *msg, u32 sock) | ||
743 | { | ||
744 | int err; | ||
745 | void *hdr; | ||
746 | struct nlattr *nest; | ||
747 | struct sk_buff *args; | ||
748 | struct tipc_nl_compat_cmd_dump dump; | ||
749 | |||
750 | args = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | ||
751 | if (!args) | ||
752 | return -ENOMEM; | ||
753 | |||
754 | hdr = genlmsg_put(args, 0, 0, &tipc_genl_family, NLM_F_MULTI, | ||
755 | TIPC_NL_PUBL_GET); | ||
756 | |||
757 | nest = nla_nest_start(args, TIPC_NLA_SOCK); | ||
758 | if (!nest) { | ||
759 | kfree_skb(args); | ||
760 | return -EMSGSIZE; | ||
761 | } | ||
762 | |||
763 | if (nla_put_u32(args, TIPC_NLA_SOCK_REF, sock)) { | ||
764 | kfree_skb(args); | ||
765 | return -EMSGSIZE; | ||
766 | } | ||
767 | |||
768 | nla_nest_end(args, nest); | ||
769 | genlmsg_end(args, hdr); | ||
770 | |||
771 | dump.dumpit = tipc_nl_publ_dump; | ||
772 | dump.format = __tipc_nl_compat_publ_dump; | ||
773 | |||
774 | err = __tipc_nl_compat_dumpit(&dump, msg, args); | ||
775 | |||
776 | kfree_skb(args); | ||
777 | |||
778 | return err; | ||
779 | } | ||
780 | |||
781 | static int tipc_nl_compat_sk_dump(struct tipc_nl_compat_msg *msg, | ||
782 | struct nlattr **attrs) | ||
783 | { | ||
784 | int err; | ||
785 | u32 sock_ref; | ||
786 | struct nlattr *sock[TIPC_NLA_SOCK_MAX + 1]; | ||
787 | |||
788 | nla_parse_nested(sock, TIPC_NLA_SOCK_MAX, attrs[TIPC_NLA_SOCK], NULL); | ||
789 | |||
790 | sock_ref = nla_get_u32(sock[TIPC_NLA_SOCK_REF]); | ||
791 | tipc_tlv_sprintf(msg->rep, "%u:", sock_ref); | ||
792 | |||
793 | if (sock[TIPC_NLA_SOCK_CON]) { | ||
794 | u32 node; | ||
795 | struct nlattr *con[TIPC_NLA_CON_MAX + 1]; | ||
796 | |||
797 | nla_parse_nested(con, TIPC_NLA_CON_MAX, sock[TIPC_NLA_SOCK_CON], | ||
798 | NULL); | ||
799 | |||
800 | node = nla_get_u32(con[TIPC_NLA_CON_NODE]); | ||
801 | tipc_tlv_sprintf(msg->rep, " connected to <%u.%u.%u:%u>", | ||
802 | tipc_zone(node), | ||
803 | tipc_cluster(node), | ||
804 | tipc_node(node), | ||
805 | nla_get_u32(con[TIPC_NLA_CON_SOCK])); | ||
806 | |||
807 | if (con[TIPC_NLA_CON_FLAG]) | ||
808 | tipc_tlv_sprintf(msg->rep, " via {%u,%u}\n", | ||
809 | nla_get_u32(con[TIPC_NLA_CON_TYPE]), | ||
810 | nla_get_u32(con[TIPC_NLA_CON_INST])); | ||
811 | else | ||
812 | tipc_tlv_sprintf(msg->rep, "\n"); | ||
813 | } else if (sock[TIPC_NLA_SOCK_HAS_PUBL]) { | ||
814 | tipc_tlv_sprintf(msg->rep, " bound to"); | ||
815 | |||
816 | err = tipc_nl_compat_publ_dump(msg, sock_ref); | ||
817 | if (err) | ||
818 | return err; | ||
819 | } | ||
820 | tipc_tlv_sprintf(msg->rep, "\n"); | ||
821 | |||
822 | return 0; | ||
823 | } | ||
824 | |||
721 | static int tipc_nl_compat_handle(struct tipc_nl_compat_msg *msg) | 825 | static int tipc_nl_compat_handle(struct tipc_nl_compat_msg *msg) |
722 | { | 826 | { |
723 | struct tipc_nl_compat_cmd_dump dump; | 827 | struct tipc_nl_compat_cmd_dump dump; |
@@ -775,6 +879,12 @@ static int tipc_nl_compat_handle(struct tipc_nl_compat_msg *msg) | |||
775 | dump.dumpit = tipc_nl_name_table_dump; | 879 | dump.dumpit = tipc_nl_name_table_dump; |
776 | dump.format = tipc_nl_compat_name_table_dump; | 880 | dump.format = tipc_nl_compat_name_table_dump; |
777 | return tipc_nl_compat_dumpit(&dump, msg); | 881 | return tipc_nl_compat_dumpit(&dump, msg); |
882 | case TIPC_CMD_SHOW_PORTS: | ||
883 | msg->rep_size = ULTRA_STRING_MAX_LEN; | ||
884 | msg->rep_type = TIPC_TLV_ULTRA_STRING; | ||
885 | dump.dumpit = tipc_nl_sk_dump; | ||
886 | dump.format = tipc_nl_compat_sk_dump; | ||
887 | return tipc_nl_compat_dumpit(&dump, msg); | ||
778 | } | 888 | } |
779 | 889 | ||
780 | return -EOPNOTSUPP; | 890 | return -EOPNOTSUPP; |
@@ -881,6 +991,7 @@ static int tipc_nl_compat_tmp_wrap(struct sk_buff *skb, struct genl_info *info) | |||
881 | case TIPC_CMD_SET_LINK_WINDOW: | 991 | case TIPC_CMD_SET_LINK_WINDOW: |
882 | case TIPC_CMD_RESET_LINK_STATS: | 992 | case TIPC_CMD_RESET_LINK_STATS: |
883 | case TIPC_CMD_SHOW_NAME_TABLE: | 993 | case TIPC_CMD_SHOW_NAME_TABLE: |
994 | case TIPC_CMD_SHOW_PORTS: | ||
884 | return tipc_nl_compat_recv(skb, info); | 995 | return tipc_nl_compat_recv(skb, info); |
885 | } | 996 | } |
886 | 997 | ||