tipc: add media set to new netlink api
authorRichard Alpe <richard.alpe@ericsson.com>
Thu, 20 Nov 2014 09:29:16 +0000 (10:29 +0100)
committerDavid S. Miller <davem@davemloft.net>
Fri, 21 Nov 2014 20:01:31 +0000 (15:01 -0500)
Add TIPC_NL_MEDIA_SET command to the new tipc netlink API.

This command can set one or more link properties for a particular
media.

Netlink logical layout of bearer set 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>
include/uapi/linux/tipc_netlink.h
net/tipc/bearer.c
net/tipc/bearer.h
net/tipc/netlink.c

index 4101b70991cc46acf36f490087363d2999d9e58b..43beef28d67fc23df013d6e5f96178da55d20e6d 100644 (file)
@@ -51,6 +51,7 @@ enum {
        TIPC_NL_LINK_SET,
        TIPC_NL_LINK_RESET_STATS,
        TIPC_NL_MEDIA_GET,
+       TIPC_NL_MEDIA_SET,
 
        __TIPC_NL_CMD_MAX,
        TIPC_NL_CMD_MAX = __TIPC_NL_CMD_MAX - 1
index 26630a51fcae8b23dfbf2a7a2526b12bba270629..5f6f32369c16067bc4d27b93b3028d3a7f673d83 100644 (file)
@@ -1023,3 +1023,50 @@ err_out:
 
        return err;
 }
+
+int tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info)
+{
+       int err;
+       char *name;
+       struct tipc_media *m;
+       struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1];
+
+       if (!info->attrs[TIPC_NLA_MEDIA])
+               return -EINVAL;
+
+       err = nla_parse_nested(attrs, TIPC_NLA_MEDIA_MAX,
+                              info->attrs[TIPC_NLA_MEDIA],
+                              tipc_nl_media_policy);
+
+       if (!attrs[TIPC_NLA_MEDIA_NAME])
+               return -EINVAL;
+       name = nla_data(attrs[TIPC_NLA_MEDIA_NAME]);
+
+       rtnl_lock();
+       m = tipc_media_find(name);
+       if (!m) {
+               rtnl_unlock();
+               return -EINVAL;
+       }
+
+       if (attrs[TIPC_NLA_MEDIA_PROP]) {
+               struct nlattr *props[TIPC_NLA_PROP_MAX + 1];
+
+               err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_MEDIA_PROP],
+                                             props);
+               if (err) {
+                       rtnl_unlock();
+                       return err;
+               }
+
+               if (props[TIPC_NLA_PROP_TOL])
+                       m->tolerance = nla_get_u32(props[TIPC_NLA_PROP_TOL]);
+               if (props[TIPC_NLA_PROP_PRIO])
+                       m->priority = nla_get_u32(props[TIPC_NLA_PROP_PRIO]);
+               if (props[TIPC_NLA_PROP_WIN])
+                       m->window = nla_get_u32(props[TIPC_NLA_PROP_WIN]);
+       }
+       rtnl_unlock();
+
+       return 0;
+}
index bacd225bccfbaf9dbd280e235b19f519e2ed81b0..b1d905209e83f9558c4d01ddebf6a6327cc4ad5c 100644 (file)
@@ -186,6 +186,7 @@ int tipc_nl_bearer_set(struct sk_buff *skb, struct genl_info *info);
 
 int tipc_nl_media_dump(struct sk_buff *skb, struct netlink_callback *cb);
 int tipc_nl_media_get(struct sk_buff *skb, struct genl_info *info);
+int tipc_nl_media_set(struct sk_buff *skb, struct genl_info *info);
 
 int tipc_media_set_priority(const char *name, u32 new_value);
 int tipc_media_set_window(const char *name, u32 new_value);
index 742e51a0afbb2a776c1e9858769e2ea6c5e776c5..8673e370b7ed4d466a434309d9fff4905ca25f40 100644 (file)
@@ -161,6 +161,11 @@ static const struct genl_ops tipc_genl_v2_ops[] = {
                .doit   = tipc_nl_media_get,
                .dumpit = tipc_nl_media_dump,
                .policy = tipc_nl_policy,
+       },
+       {
+               .cmd    = TIPC_NL_MEDIA_SET,
+               .doit   = tipc_nl_media_set,
+               .policy = tipc_nl_policy,
        }
 };