diff options
| author | Richard Alpe <richard.alpe@ericsson.com> | 2014-11-20 04:29:15 -0500 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2014-11-21 15:01:31 -0500 |
| commit | 46f15c6794fb744bb7741d26143a85b9012c10d4 (patch) | |
| tree | 29c63892638de7511ccc87c1970462a7e888e979 /net/tipc | |
| parent | ae36342b50a91cff188e417201452dc075a8f444 (diff) | |
tipc: add media get/dump to new netlink api
Add TIPC_NL_MEDIA_GET command to the new tipc netlink API.
This command supports dumping all information about all defined
media as well as getting all information about a specific media.
The information about a media includes name and link properties.
Netlink logical layout of media get response message:
-> media
-> name
-> link properties
-> tolerance
-> priority
-> window
Signed-off-by: Richard Alpe <richard.alpe@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tipc')
| -rw-r--r-- | net/tipc/bearer.c | 125 | ||||
| -rw-r--r-- | net/tipc/bearer.h | 3 | ||||
| -rw-r--r-- | net/tipc/netlink.c | 7 |
3 files changed, 135 insertions, 0 deletions
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index 6d547d0b3f31..26630a51fcae 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c | |||
| @@ -61,6 +61,12 @@ tipc_nl_bearer_policy[TIPC_NLA_BEARER_MAX + 1] = { | |||
| 61 | [TIPC_NLA_BEARER_DOMAIN] = { .type = NLA_U32 } | 61 | [TIPC_NLA_BEARER_DOMAIN] = { .type = NLA_U32 } |
| 62 | }; | 62 | }; |
| 63 | 63 | ||
| 64 | static const struct nla_policy tipc_nl_media_policy[TIPC_NLA_MEDIA_MAX + 1] = { | ||
| 65 | [TIPC_NLA_MEDIA_UNSPEC] = { .type = NLA_UNSPEC }, | ||
| 66 | [TIPC_NLA_MEDIA_NAME] = { .type = NLA_STRING }, | ||
| 67 | [TIPC_NLA_MEDIA_PROP] = { .type = NLA_NESTED } | ||
| 68 | }; | ||
| 69 | |||
| 64 | struct tipc_bearer __rcu *bearer_list[MAX_BEARERS + 1]; | 70 | struct tipc_bearer __rcu *bearer_list[MAX_BEARERS + 1]; |
| 65 | 71 | ||
| 66 | static void bearer_disable(struct tipc_bearer *b_ptr, bool shutting_down); | 72 | static void bearer_disable(struct tipc_bearer *b_ptr, bool shutting_down); |
| @@ -898,3 +904,122 @@ int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info) | |||
| 898 | 904 | ||
| 899 | return 0; | 905 | return 0; |
| 900 | } | 906 | } |
| 907 | |||
| 908 | int __tipc_nl_add_media(struct tipc_nl_msg *msg, struct tipc_media *media) | ||
| 909 | { | ||
| 910 | void *hdr; | ||
| 911 | struct nlattr *attrs; | ||
| 912 | struct nlattr *prop; | ||
| 913 | |||
| 914 | hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family, | ||
| 915 | NLM_F_MULTI, TIPC_NL_MEDIA_GET); | ||
| 916 | if (!hdr) | ||
| 917 | return -EMSGSIZE; | ||
| 918 | |||
| 919 | attrs = nla_nest_start(msg->skb, TIPC_NLA_MEDIA); | ||
| 920 | if (!attrs) | ||
| 921 | goto msg_full; | ||
| 922 | |||
| 923 | if (nla_put_string(msg->skb, TIPC_NLA_MEDIA_NAME, media->name)) | ||
| 924 | goto attr_msg_full; | ||
| 925 | |||
| 926 | prop = nla_nest_start(msg->skb, TIPC_NLA_MEDIA_PROP); | ||
| 927 | if (!prop) | ||
| 928 | goto prop_msg_full; | ||
| 929 | if (nla_put_u32(msg->skb, TIPC_NLA_PROP_PRIO, media->priority)) | ||
| 930 | goto prop_msg_full; | ||
| 931 | if (nla_put_u32(msg->skb, TIPC_NLA_PROP_TOL, media->tolerance)) | ||
| 932 | goto prop_msg_full; | ||
| 933 | if (nla_put_u32(msg->skb, TIPC_NLA_PROP_WIN, media->window)) | ||
| 934 | goto prop_msg_full; | ||
| 935 | |||
| 936 | nla_nest_end(msg->skb, prop); | ||
| 937 | nla_nest_end(msg->skb, attrs); | ||
| 938 | genlmsg_end(msg->skb, hdr); | ||
| 939 | |||
| 940 | return 0; | ||
| 941 | |||
| 942 | prop_msg_full: | ||
| 943 | nla_nest_cancel(msg->skb, prop); | ||
| 944 | attr_msg_full: | ||
| 945 | nla_nest_cancel(msg->skb, attrs); | ||
| 946 | msg_full: | ||
| 947 | genlmsg_cancel(msg->skb, hdr); | ||
| 948 | |||
| 949 | return -EMSGSIZE; | ||
| 950 | } | ||
| 951 | |||
| 952 | int tipc_nl_media_dump(struct sk_buff *skb, struct netlink_callback *cb) | ||
| 953 | { | ||
| 954 | int err; | ||
| 955 | int i = cb->args[0]; | ||
| 956 | struct tipc_nl_msg msg; | ||
| 957 | |||
| 958 | if (i == MAX_MEDIA) | ||
| 959 | return 0; | ||
| 960 | |||
| 961 | msg.skb = skb; | ||
| 962 | msg.portid = NETLINK_CB(cb->skb).portid; | ||
| 963 | msg.seq = cb->nlh->nlmsg_seq; | ||
| 964 | |||
| 965 | rtnl_lock(); | ||
| 966 | for (; media_info_array[i] != NULL; i++) { | ||
| 967 | err = __tipc_nl_add_media(&msg, media_info_array[i]); | ||
| 968 | if (err) | ||
| 969 | break; | ||
| 970 | } | ||
| 971 | rtnl_unlock(); | ||
| 972 | |||
| 973 | cb->args[0] = i; | ||
| 974 | return skb->len; | ||
| 975 | } | ||
| 976 | |||
| 977 | int tipc_nl_media_get(struct sk_buff *skb, struct genl_info *info) | ||
| 978 | { | ||
| 979 | int err; | ||
| 980 | char *name; | ||
| 981 | struct tipc_nl_msg msg; | ||
| 982 | struct tipc_media *media; | ||
| 983 | struct sk_buff *rep; | ||
| 984 | struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; | ||
| 985 | |||
| 986 | if (!info->attrs[TIPC_NLA_MEDIA]) | ||
| 987 | return -EINVAL; | ||
| 988 | |||
| 989 | err = nla_parse_nested(attrs, TIPC_NLA_MEDIA_MAX, | ||
| 990 | info->attrs[TIPC_NLA_MEDIA], | ||
| 991 | tipc_nl_media_policy); | ||
| 992 | if (err) | ||
| 993 | return err; | ||
| 994 | |||
| 995 | if (!attrs[TIPC_NLA_MEDIA_NAME]) | ||
| 996 | return -EINVAL; | ||
| 997 | name = nla_data(attrs[TIPC_NLA_MEDIA_NAME]); | ||
| 998 | |||
| 999 | rep = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | ||
| 1000 | if (!rep) | ||
| 1001 | return -ENOMEM; | ||
| 1002 | |||
| 1003 | msg.skb = rep; | ||
| 1004 | msg.portid = info->snd_portid; | ||
| 1005 | msg.seq = info->snd_seq; | ||
| 1006 | |||
| 1007 | rtnl_lock(); | ||
| 1008 | media = tipc_media_find(name); | ||
| 1009 | if (!media) { | ||
| 1010 | err = -EINVAL; | ||
| 1011 | goto err_out; | ||
| 1012 | } | ||
| 1013 | |||
| 1014 | err = __tipc_nl_add_media(&msg, media); | ||
| 1015 | if (err) | ||
| 1016 | goto err_out; | ||
| 1017 | rtnl_unlock(); | ||
| 1018 | |||
| 1019 | return genlmsg_reply(rep, info); | ||
| 1020 | err_out: | ||
| 1021 | rtnl_unlock(); | ||
| 1022 | nlmsg_free(rep); | ||
| 1023 | |||
| 1024 | return err; | ||
| 1025 | } | ||
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h index c6cf9df31375..bacd225bccfb 100644 --- a/net/tipc/bearer.h +++ b/net/tipc/bearer.h | |||
| @@ -184,6 +184,9 @@ int tipc_nl_bearer_dump(struct sk_buff *skb, struct netlink_callback *cb); | |||
| 184 | int tipc_nl_bearer_get(struct sk_buff *skb, struct genl_info *info); | 184 | int tipc_nl_bearer_get(struct sk_buff *skb, struct genl_info *info); |
| 185 | int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info); | 185 | int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info); |
| 186 | 186 | ||
| 187 | int tipc_nl_media_dump(struct sk_buff *skb, struct netlink_callback *cb); | ||
| 188 | int tipc_nl_media_get(struct sk_buff *skb, struct genl_info *info); | ||
| 189 | |||
| 187 | int tipc_media_set_priority(const char *name, u32 new_value); | 190 | int tipc_media_set_priority(const char *name, u32 new_value); |
| 188 | int tipc_media_set_window(const char *name, u32 new_value); | 191 | int tipc_media_set_window(const char *name, u32 new_value); |
| 189 | void tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a); | 192 | void tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a); |
diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c index 68bfd11f232d..742e51a0afbb 100644 --- a/net/tipc/netlink.c +++ b/net/tipc/netlink.c | |||
| @@ -77,6 +77,7 @@ static const struct nla_policy tipc_nl_policy[TIPC_NLA_MAX + 1] = { | |||
| 77 | [TIPC_NLA_SOCK] = { .type = NLA_NESTED, }, | 77 | [TIPC_NLA_SOCK] = { .type = NLA_NESTED, }, |
| 78 | [TIPC_NLA_PUBL] = { .type = NLA_NESTED, }, | 78 | [TIPC_NLA_PUBL] = { .type = NLA_NESTED, }, |
| 79 | [TIPC_NLA_LINK] = { .type = NLA_NESTED, }, | 79 | [TIPC_NLA_LINK] = { .type = NLA_NESTED, }, |
| 80 | [TIPC_NLA_MEDIA] = { .type = NLA_NESTED, }, | ||
| 80 | }; | 81 | }; |
| 81 | 82 | ||
| 82 | /* Legacy ASCII API */ | 83 | /* Legacy ASCII API */ |
| @@ -154,6 +155,12 @@ static const struct genl_ops tipc_genl_v2_ops[] = { | |||
| 154 | .cmd = TIPC_NL_LINK_RESET_STATS, | 155 | .cmd = TIPC_NL_LINK_RESET_STATS, |
| 155 | .doit = tipc_nl_link_reset_stats, | 156 | .doit = tipc_nl_link_reset_stats, |
| 156 | .policy = tipc_nl_policy, | 157 | .policy = tipc_nl_policy, |
| 158 | }, | ||
| 159 | { | ||
| 160 | .cmd = TIPC_NL_MEDIA_GET, | ||
| 161 | .doit = tipc_nl_media_get, | ||
| 162 | .dumpit = tipc_nl_media_dump, | ||
| 163 | .policy = tipc_nl_policy, | ||
| 157 | } | 164 | } |
| 158 | }; | 165 | }; |
| 159 | 166 | ||
