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:
parent
80e9807dff
commit
d2ba0b0bbb
|
|
@ -45,7 +45,7 @@ static void _print_bearer_opts(void)
|
||||||
" window - Bearer link window\n");
|
" window - Bearer link window\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _print_bearer_media(void)
|
void print_bearer_media(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"\nMEDIA\n"
|
"\nMEDIA\n"
|
||||||
|
|
@ -192,14 +192,28 @@ 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,
|
static int nl_add_bearer_name(struct nlmsghdr *nlh, const struct cmd *cmd,
|
||||||
struct cmdl *cmdl, struct opt *opts,
|
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 *media;
|
||||||
char *identifier;
|
char *identifier;
|
||||||
struct opt *opt;
|
struct opt *opt;
|
||||||
struct tipc_sup_media *entry;
|
const struct tipc_sup_media *entry;
|
||||||
|
|
||||||
|
|
||||||
if (!(opt = get_opt(opts, "media"))) {
|
if (!(opt = get_opt(opts, "media"))) {
|
||||||
if (help_flag)
|
if (help_flag)
|
||||||
|
|
@ -219,13 +233,12 @@ static int nl_add_bearer_name(struct nlmsghdr *nlh, const struct cmd *cmd,
|
||||||
(entry->help)(cmdl, media);
|
(entry->help)(cmdl, media);
|
||||||
else
|
else
|
||||||
fprintf(stderr, "error, missing bearer %s\n",
|
fprintf(stderr, "error, missing bearer %s\n",
|
||||||
entry->identifier);
|
entry->identifier);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
identifier = opt->val;
|
identifier = opt->val;
|
||||||
snprintf(id, sizeof(id), "%s:%s", media, identifier);
|
snprintf(bname, TIPC_MAX_BEARER_NAME, "%s:%s", media, identifier);
|
||||||
mnl_attr_put_strz(nlh, TIPC_NLA_BEARER_NAME, id);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -270,13 +283,13 @@ static int udp_bearer_add(struct nlmsghdr *nlh, struct opt *opts,
|
||||||
|
|
||||||
if ((err = getaddrinfo(ip, remport, &hints, &addr))) {
|
if ((err = getaddrinfo(ip, remport, &hints, &addr))) {
|
||||||
fprintf(stderr, "UDP address error: %s\n",
|
fprintf(stderr, "UDP address error: %s\n",
|
||||||
gai_strerror(err));
|
gai_strerror(err));
|
||||||
freeaddrinfo(addr);
|
freeaddrinfo(addr);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
mnl_attr_put(nlh, TIPC_NLA_UDP_REMOTE, addr->ai_addrlen,
|
mnl_attr_put(nlh, TIPC_NLA_UDP_REMOTE, addr->ai_addrlen,
|
||||||
addr->ai_addr);
|
addr->ai_addr);
|
||||||
freeaddrinfo(addr);
|
freeaddrinfo(addr);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "error, missing remoteip\n");
|
fprintf(stderr, "error, missing remoteip\n");
|
||||||
|
|
@ -302,7 +315,7 @@ static int cmd_bearer_add_media(struct nlmsghdr *nlh, const struct cmd *cmd,
|
||||||
{ "media", OPT_KEYVAL, NULL },
|
{ "media", OPT_KEYVAL, NULL },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
struct tipc_sup_media sup_media[] = {
|
const struct tipc_sup_media sup_media[] = {
|
||||||
{ "udp", "name", cmd_bearer_add_udp_help},
|
{ "udp", "name", cmd_bearer_add_udp_help},
|
||||||
{ NULL, },
|
{ NULL, },
|
||||||
};
|
};
|
||||||
|
|
@ -366,7 +379,7 @@ static void cmd_bearer_enable_help(struct cmdl *cmdl)
|
||||||
" domain DOMAIN - Discovery domain\n"
|
" domain DOMAIN - Discovery domain\n"
|
||||||
" priority PRIORITY - Bearer priority\n",
|
" priority PRIORITY - Bearer priority\n",
|
||||||
cmdl->argv[0]);
|
cmdl->argv[0]);
|
||||||
_print_bearer_media();
|
print_bearer_media();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmd_bearer_enable(struct nlmsghdr *nlh, const struct cmd *cmd,
|
static int cmd_bearer_enable(struct nlmsghdr *nlh, const struct cmd *cmd,
|
||||||
|
|
@ -389,9 +402,9 @@ static int cmd_bearer_enable(struct nlmsghdr *nlh, const struct cmd *cmd,
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
struct tipc_sup_media sup_media[] = {
|
struct tipc_sup_media sup_media[] = {
|
||||||
{ "udp", "name", cmd_bearer_enable_udp_help},
|
{ "udp", "name", cmd_bearer_enable_udp_help},
|
||||||
{ "eth", "device", cmd_bearer_enable_l2_help },
|
{ "eth", "device", cmd_bearer_enable_l2_help },
|
||||||
{ "ib", "device", cmd_bearer_enable_l2_help },
|
{ "ib", "device", cmd_bearer_enable_l2_help },
|
||||||
{ NULL, },
|
{ NULL, },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -449,7 +462,7 @@ static void cmd_bearer_disable_help(struct cmdl *cmdl)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Usage: %s bearer disable media MEDIA ARGS...\n",
|
fprintf(stderr, "Usage: %s bearer disable media MEDIA ARGS...\n",
|
||||||
cmdl->argv[0]);
|
cmdl->argv[0]);
|
||||||
_print_bearer_media();
|
print_bearer_media();
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmd_bearer_disable(struct nlmsghdr *nlh, const struct cmd *cmd,
|
static int cmd_bearer_disable(struct nlmsghdr *nlh, const struct cmd *cmd,
|
||||||
|
|
@ -465,9 +478,9 @@ static int cmd_bearer_disable(struct nlmsghdr *nlh, const struct cmd *cmd,
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
struct tipc_sup_media sup_media[] = {
|
struct tipc_sup_media sup_media[] = {
|
||||||
{ "udp", "name", cmd_bearer_disable_udp_help},
|
{ "udp", "name", cmd_bearer_disable_udp_help},
|
||||||
{ "eth", "device", cmd_bearer_disable_l2_help },
|
{ "eth", "device", cmd_bearer_disable_l2_help },
|
||||||
{ "ib", "device", cmd_bearer_disable_l2_help },
|
{ "ib", "device", cmd_bearer_disable_l2_help },
|
||||||
{ NULL, },
|
{ NULL, },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -497,7 +510,7 @@ static void cmd_bearer_set_help(struct cmdl *cmdl)
|
||||||
fprintf(stderr, "Usage: %s bearer set OPTION media MEDIA ARGS...\n",
|
fprintf(stderr, "Usage: %s bearer set OPTION media MEDIA ARGS...\n",
|
||||||
cmdl->argv[0]);
|
cmdl->argv[0]);
|
||||||
_print_bearer_opts();
|
_print_bearer_opts();
|
||||||
_print_bearer_media();
|
print_bearer_media();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_bearer_set_udp_help(struct cmdl *cmdl, char *media)
|
static void cmd_bearer_set_udp_help(struct cmdl *cmdl, char *media)
|
||||||
|
|
@ -516,7 +529,7 @@ static void cmd_bearer_set_l2_help(struct cmdl *cmdl, char *media)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int cmd_bearer_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
|
static int cmd_bearer_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
|
||||||
struct cmdl *cmdl, void *data)
|
struct cmdl *cmdl, void *data)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
int val;
|
int val;
|
||||||
|
|
@ -531,9 +544,9 @@ static int cmd_bearer_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
struct tipc_sup_media sup_media[] = {
|
struct tipc_sup_media sup_media[] = {
|
||||||
{ "udp", "name", cmd_bearer_set_udp_help},
|
{ "udp", "name", cmd_bearer_set_udp_help},
|
||||||
{ "eth", "device", cmd_bearer_set_l2_help },
|
{ "eth", "device", cmd_bearer_set_l2_help },
|
||||||
{ "ib", "device", cmd_bearer_set_l2_help },
|
{ "ib", "device", cmd_bearer_set_l2_help },
|
||||||
{ NULL, },
|
{ NULL, },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -592,7 +605,7 @@ static void cmd_bearer_get_help(struct cmdl *cmdl)
|
||||||
fprintf(stderr, "Usage: %s bearer get [OPTION] media MEDIA ARGS...\n",
|
fprintf(stderr, "Usage: %s bearer get [OPTION] media MEDIA ARGS...\n",
|
||||||
cmdl->argv[0]);
|
cmdl->argv[0]);
|
||||||
_print_bearer_opts();
|
_print_bearer_opts();
|
||||||
_print_bearer_media();
|
print_bearer_media();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmd_bearer_get_udp_help(struct cmdl *cmdl, char *media)
|
static void cmd_bearer_get_udp_help(struct cmdl *cmdl, char *media)
|
||||||
|
|
@ -639,7 +652,7 @@ static int bearer_dump_udp_cb(const struct nlmsghdr *nlh, void *data)
|
||||||
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *) addr;
|
struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *) addr;
|
||||||
|
|
||||||
if (!inet_ntop(AF_INET6, &ipv6->sin6_addr, straddr,
|
if (!inet_ntop(AF_INET6, &ipv6->sin6_addr, straddr,
|
||||||
sizeof(straddr))) {
|
sizeof(straddr))) {
|
||||||
fprintf(stderr, "error, parsing IPv6 addr\n");
|
fprintf(stderr, "error, parsing IPv6 addr\n");
|
||||||
return MNL_CB_ERROR;
|
return MNL_CB_ERROR;
|
||||||
}
|
}
|
||||||
|
|
@ -705,7 +718,7 @@ static int bearer_get_udp_cb(const struct nlmsghdr *nlh, void *data)
|
||||||
switch (cb_data->prop) {
|
switch (cb_data->prop) {
|
||||||
case UDP_PROP_IP:
|
case UDP_PROP_IP:
|
||||||
if (!inet_ntop(AF_INET6, &ipv6->sin6_addr, straddr,
|
if (!inet_ntop(AF_INET6, &ipv6->sin6_addr, straddr,
|
||||||
sizeof(straddr))) {
|
sizeof(straddr))) {
|
||||||
fprintf(stderr, "error, parsing IPv6 addr\n");
|
fprintf(stderr, "error, parsing IPv6 addr\n");
|
||||||
return MNL_CB_ERROR;
|
return MNL_CB_ERROR;
|
||||||
}
|
}
|
||||||
|
|
@ -769,7 +782,7 @@ static int cmd_bearer_get_media(struct nlmsghdr *nlh, const struct cmd *cmd,
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
struct tipc_sup_media sup_media[] = {
|
struct tipc_sup_media sup_media[] = {
|
||||||
{ "udp", "name", cmd_bearer_get_udp_help},
|
{ "udp", "name", cmd_bearer_get_udp_help},
|
||||||
{ NULL, },
|
{ NULL, },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -844,9 +857,9 @@ static int cmd_bearer_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
struct tipc_sup_media sup_media[] = {
|
struct tipc_sup_media sup_media[] = {
|
||||||
{ "udp", "name", cmd_bearer_get_udp_help},
|
{ "udp", "name", cmd_bearer_get_udp_help},
|
||||||
{ "eth", "device", cmd_bearer_get_l2_help },
|
{ "eth", "device", cmd_bearer_get_l2_help },
|
||||||
{ "ib", "device", cmd_bearer_get_l2_help },
|
{ "ib", "device", cmd_bearer_get_l2_help },
|
||||||
{ NULL, },
|
{ NULL, },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,4 +19,8 @@ extern int help_flag;
|
||||||
int cmd_bearer(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data);
|
int cmd_bearer(struct nlmsghdr *nlh, const struct cmd *cmd, struct cmdl *cmdl, void *data);
|
||||||
void cmd_bearer_help(struct cmdl *cmdl);
|
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
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue