tipc: refractor bearer to facilitate link monitor

In this commit, we:
1. Export print_bearer_media()
2. Move the bearer name handling from nl_add_bearer_name() into
   a new function cmd_get_unique_bearer_name().

These exported functions will be used by link monitor used in
subsequent commits.

Signed-off-by: Parthasarathy Bhuvaragan <parthasarathy.bhuvaragan@ericsson.com>
This commit is contained in:
Parthasarathy Bhuvaragan 2016-09-12 17:17:19 +02:00 committed by Stephen Hemminger
parent 80e9807dff
commit d2ba0b0bbb
2 changed files with 48 additions and 31 deletions

View File

@ -45,7 +45,7 @@ static void _print_bearer_opts(void)
" window - Bearer link window\n");
}
static void _print_bearer_media(void)
void print_bearer_media(void)
{
fprintf(stderr,
"\nMEDIA\n"
@ -193,13 +193,27 @@ static int nl_add_udp_enable_opts(struct nlmsghdr *nlh, struct opt *opts,
static int nl_add_bearer_name(struct nlmsghdr *nlh, const struct cmd *cmd,
struct cmdl *cmdl, struct opt *opts,
struct tipc_sup_media sup_media[])
const struct tipc_sup_media *sup_media)
{
char bname[TIPC_MAX_BEARER_NAME];
int err;
if ((err = cmd_get_unique_bearer_name(cmd, cmdl, opts, bname, sup_media)))
return err;
mnl_attr_put_strz(nlh, TIPC_NLA_BEARER_NAME, bname);
return 0;
}
int cmd_get_unique_bearer_name(const struct cmd *cmd, struct cmdl *cmdl,
struct opt *opts, char *bname,
const struct tipc_sup_media *sup_media)
{
char id[TIPC_MAX_BEARER_NAME];
char *media;
char *identifier;
struct opt *opt;
struct tipc_sup_media *entry;
const struct tipc_sup_media *entry;
if (!(opt = get_opt(opts, "media"))) {
if (help_flag)
@ -224,8 +238,7 @@ static int nl_add_bearer_name(struct nlmsghdr *nlh, const struct cmd *cmd,
}
identifier = opt->val;
snprintf(id, sizeof(id), "%s:%s", media, identifier);
mnl_attr_put_strz(nlh, TIPC_NLA_BEARER_NAME, id);
snprintf(bname, TIPC_MAX_BEARER_NAME, "%s:%s", media, identifier);
return 0;
}
@ -302,7 +315,7 @@ static int cmd_bearer_add_media(struct nlmsghdr *nlh, const struct cmd *cmd,
{ "media", OPT_KEYVAL, NULL },
{ NULL }
};
struct tipc_sup_media sup_media[] = {
const struct tipc_sup_media sup_media[] = {
{ "udp", "name", cmd_bearer_add_udp_help},
{ NULL, },
};
@ -366,7 +379,7 @@ static void cmd_bearer_enable_help(struct cmdl *cmdl)
" domain DOMAIN - Discovery domain\n"
" priority PRIORITY - Bearer priority\n",
cmdl->argv[0]);
_print_bearer_media();
print_bearer_media();
}
static int cmd_bearer_enable(struct nlmsghdr *nlh, const struct cmd *cmd,
@ -449,7 +462,7 @@ static void cmd_bearer_disable_help(struct cmdl *cmdl)
{
fprintf(stderr, "Usage: %s bearer disable media MEDIA ARGS...\n",
cmdl->argv[0]);
_print_bearer_media();
print_bearer_media();
}
static int cmd_bearer_disable(struct nlmsghdr *nlh, const struct cmd *cmd,
@ -497,7 +510,7 @@ static void cmd_bearer_set_help(struct cmdl *cmdl)
fprintf(stderr, "Usage: %s bearer set OPTION media MEDIA ARGS...\n",
cmdl->argv[0]);
_print_bearer_opts();
_print_bearer_media();
print_bearer_media();
}
static void cmd_bearer_set_udp_help(struct cmdl *cmdl, char *media)
@ -592,7 +605,7 @@ static void cmd_bearer_get_help(struct cmdl *cmdl)
fprintf(stderr, "Usage: %s bearer get [OPTION] media MEDIA ARGS...\n",
cmdl->argv[0]);
_print_bearer_opts();
_print_bearer_media();
print_bearer_media();
}
static void cmd_bearer_get_udp_help(struct cmdl *cmdl, char *media)

View File

@ -19,4 +19,8 @@ extern int help_flag;
int cmd_bearer(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data);
void cmd_bearer_help(struct cmdl *cmdl);
void print_bearer_media(void);
int cmd_get_unique_bearer_name(const struct cmd *cmd, struct cmdl *cmdl,
struct opt *opts, char *bname,
const struct tipc_sup_media *sup_media);
#endif