On 2016-05-23 15:27, Parthasarathy Bhuvaragan wrote:
> Signed-off-by: Parthasarathy Bhuvaragan 
> <[email protected]>
> ---
>  tipc/link.c | 105 
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 98 insertions(+), 7 deletions(-)
> 
> diff --git a/tipc/link.c b/tipc/link.c
> index 2e67be1d0470..42c48d4beed1 100644
> --- a/tipc/link.c
> +++ b/tipc/link.c
> @@ -497,12 +497,7 @@ static int cmd_link_mon_set_prop(struct nlmsghdr *nlh, 
> const struct cmd *cmd,
>       char buf[MNL_SOCKET_BUFFER_SIZE];
>       struct nlattr *attrs;
>  
> -     if (help_flag) {
> -             (cmd->help)(cmdl);
> -             return -EINVAL;
> -     }
> -
> -     if (cmdl->optind >= cmdl->argc) {
> +     if (cmdl->argc != cmdl->optind + 1) {
Shouldn’t this be a fixup on the previous patch?

>               fprintf(stderr, "error, missing value\n");
>               return -EINVAL;
>       }
> @@ -521,6 +516,46 @@ static int cmd_link_mon_set_prop(struct nlmsghdr *nlh, 
> const struct cmd *cmd,
>       return msg_doit(nlh, NULL, NULL);
>  }
>  
> +static int link_mon_list_cb(const struct nlmsghdr *nlh, void *data)
> +{
> +     struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
> +     struct nlattr *info[TIPC_NLA_MAX + 1] = {};
> +     struct nlattr *attrs[TIPC_NLA_MON_MAX + 1] = {};
> +
> +     mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
> +     if (!info[TIPC_NLA_MON])
> +             return MNL_CB_ERROR;
> +
> +     mnl_attr_parse_nested(info[TIPC_NLA_MON], parse_attrs, attrs);
> +     if (!attrs[TIPC_NLA_MON_ACTIVATION_THRESHOLD])
> +             return MNL_CB_ERROR;
> +
> +     printf("Monitor Activation Threshold :%u\n",
> +            mnl_attr_get_u32(attrs[TIPC_NLA_MON_ACTIVATION_THRESHOLD]));
This sentence seems a bit verbose and not very parser friendly. What's up
with the space before :%u?

> +
> +     return MNL_CB_OK;
> +}
> +
> +static int cmd_link_mon_list(struct nlmsghdr *nlh, const struct cmd *cmd,
> +                          struct cmdl *cmdl, void *data)
> +{
> +     char buf[MNL_SOCKET_BUFFER_SIZE];
> +
> +     if (help_flag) {
> +             fprintf(stderr,
> +                     "Usage: %s monitor list [media MEDIA device DEVICE]\n",
Hm. This isn't entirely true. If this is a udp bearer its [media MEDIA name 
NAME].
The rest of the tipc command doesn't print future things like this. I have a
patch that clean up the bearer parsing a bit. I think we should create a generic
bearer_identity() function that adds the identification of a bearer to a netlink
message. I will send my patchset tomorrow so you can have a look.

> +                     cmdl->argv[0]);
> +             return -EINVAL;
> +     }
> +
> +     if (!(nlh = msg_init(buf, TIPC_NL_MON_GET))) {
> +             fprintf(stderr, "error, message initialisation failed\n");
> +             return -1;
> +     }
> +
> +     return msg_dumpit(nlh, link_mon_list_cb, NULL);
> +}
> +
>  static void cmd_link_mon_set_help(struct cmdl *cmdl)
>  {
>       fprintf(stderr, "Usage: %s monitor set PPROPERTY \n\n"
> @@ -540,12 +575,66 @@ static int cmd_link_mon_set(struct nlmsghdr *nlh, const 
> struct cmd *cmd,
>       return run_cmd(nlh, cmd, cmds, cmdl, NULL);
>  }
>  
> +static void cmd_link_mon_get_help(struct cmdl *cmdl)
> +{
> +     fprintf(stderr, "Usage: %s monitor get PPROPERTY \n\n"
> +             "PROPERTIES\n"
> +             " threshold     - Get activation threshold for monitor\n",
"Get monitor activation threshold" sounds better to me.

> +             cmdl->argv[0]);
> +}
> +
> +static int link_mon_get_cb(const struct nlmsghdr *nlh, void *data)
> +{
> +     struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh);
> +     struct nlattr *info[TIPC_NLA_MAX + 1] = {};
> +     struct nlattr *attrs[TIPC_NLA_MON_MAX + 1] = {};
> +
> +     mnl_attr_parse(nlh, sizeof(*genl), parse_attrs, info);
> +     if (!info[TIPC_NLA_MON])
> +             return MNL_CB_ERROR;
> +
> +     mnl_attr_parse_nested(info[TIPC_NLA_MON], parse_attrs, attrs);
> +     if (!attrs[TIPC_NLA_MON_ACTIVATION_THRESHOLD])
> +             return MNL_CB_ERROR;
> +
> +     printf("%u\n",
> +            mnl_attr_get_u32(attrs[TIPC_NLA_MON_ACTIVATION_THRESHOLD]));
> +
> +     return MNL_CB_OK;
> +}
> +
> +static int cmd_link_mon_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
> +                          struct cmdl *cmdl, void *data)
> +{
> +     char buf[MNL_SOCKET_BUFFER_SIZE];
> +
> +     if (!(nlh = msg_init(buf, TIPC_NL_MON_GET))) {
> +             fprintf(stderr, "error, message initialisation failed\n");
> +             return -1;
> +     }
> +
> +     return msg_doit(nlh, link_mon_get_cb, NULL);
> +}
> +
> +static int cmd_link_mon_get(struct nlmsghdr *nlh, const struct cmd *cmd,
> +                     struct cmdl *cmdl, void *data)
> +{
> +     const struct cmd cmds[] = {
> +             { "threshold", cmd_link_mon_get_prop, NULL },
> +             { NULL }
> +     };
> +
> +     return run_cmd(nlh, cmd, cmds, cmdl, NULL);
> +}
> +
>  static void cmd_link_mon_help(struct cmdl *cmdl)
>  {
>       fprintf(stderr,
>               "Usage: %s montior COMMAND [ARGS] ...\n\n"
>               "COMMANDS\n"
> -             " set                  - Set monitor properties\n",
> +             " set                   - Set monitor properties\n"
> +             " get                   - Get monitor properties\n"
> +             " list                  - List monitored links\n",
>               cmdl->argv[0]);
>  }
>  
> @@ -554,6 +643,8 @@ static int cmd_link_mon(struct nlmsghdr *nlh, const 
> struct cmd *cmd, struct cmdl
>  {
>       const struct cmd cmds[] = {
>               { "set",        cmd_link_mon_set,       cmd_link_mon_set_help},
> +             { "get",        cmd_link_mon_get,       cmd_link_mon_get_help},
> +             { "list",       cmd_link_mon_list,      NULL },
>               { NULL }
>       };
>  
> 


------------------------------------------------------------------------------
Mobile security can be enabling, not merely restricting. Employees who
bring their own devices (BYOD) to work are irked by the imposition of MDM
restrictions. Mobile Device Manager Plus allows you to control only the
apps on BYO-devices by containerizing them, leaving personal data untouched!
https://ad.doubleclick.net/ddm/clk/304595813;131938128;j
_______________________________________________
tipc-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tipc-discussion

Reply via email to