In this commit, we do the following:
1. Remove multiple instantiations of struct tipc_sup_media and
   replace it with a single constant instance.
2. Export print_bearer_media()
3. 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.bhuvara...@ericsson.com>
---
 tipc/bearer.c | 76 ++++++++++++++++++++++++++++-------------------------------
 tipc/bearer.h |  3 +++
 2 files changed, 39 insertions(+), 40 deletions(-)

diff --git a/tipc/bearer.c b/tipc/bearer.c
index 018bc0d41ac7..c26dfcb526ac 100644
--- a/tipc/bearer.c
+++ b/tipc/bearer.c
@@ -26,6 +26,9 @@
 #include "msg.h"
 #include "bearer.h"
 
+static void cmd_bearer_disable_udp_help(struct cmdl *cmdl, char *media);
+static void cmd_bearer_disable_l2_help(struct cmdl *cmdl, char *media);
+
 static void _print_bearer_opts(void)
 {
        fprintf(stderr,
@@ -35,7 +38,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"
@@ -179,14 +182,32 @@ 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[])
+                             struct cmdl *cmdl, struct opt *opts)
+{
+       char bname[TIPC_MAX_BEARER_NAME];
+       int err;
+
+       if ((err = cmd_get_unique_bearer_name(cmd, cmdl, opts, bname)))
+               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)
 {
-       char id[TIPC_MAX_BEARER_NAME];
        char *media;
        char *identifier;
        struct opt *opt;
-       struct tipc_sup_media *entry;
+       const struct tipc_sup_media sup_media[] = {
+               { "udp",        "name",         cmd_bearer_disable_udp_help},
+               { "eth",        "device",       cmd_bearer_disable_l2_help },
+               { "ib",         "device",       cmd_bearer_disable_l2_help },
+               { NULL, },
+       };
+       const struct tipc_sup_media *entry;
+
 
        if (!(opt = get_opt(opts, "media"))) {
                if (help_flag)
@@ -206,13 +227,12 @@ static int nl_add_bearer_name(struct nlmsghdr *nlh, const 
struct cmd *cmd,
                                (entry->help)(cmdl, media);
                        else
                                fprintf(stderr, "error, missing bearer %s\n",
-                                               entry->identifier);
+                                       entry->identifier);
                        return -EINVAL;
                }
 
                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;
        }
@@ -230,7 +250,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,
@@ -252,12 +272,6 @@ static int cmd_bearer_enable(struct nlmsghdr *nlh, const 
struct cmd *cmd,
                { "remoteport",         NULL },
                { NULL }
        };
-       struct tipc_sup_media sup_media[] = {
-               { "udp",        "name",         cmd_bearer_enable_udp_help},
-               { "eth",        "device",       cmd_bearer_enable_l2_help },
-               { "ib",         "device",       cmd_bearer_enable_l2_help },
-               { NULL, },
-       };
 
        if (parse_opts(opts, cmdl) < 0) {
                if (help_flag)
@@ -282,7 +296,7 @@ static int cmd_bearer_enable(struct nlmsghdr *nlh, const 
struct cmd *cmd,
                mnl_attr_nest_end(nlh, props);
        }
 
-       err = nl_add_bearer_name(nlh, cmd, cmdl, opts, sup_media);
+       err = nl_add_bearer_name(nlh, cmd, cmdl, opts);
        if (err)
                return err;
 
@@ -313,7 +327,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,
@@ -329,12 +343,6 @@ static int cmd_bearer_disable(struct nlmsghdr *nlh, const 
struct cmd *cmd,
                { "media",              NULL },
                { NULL }
        };
-       struct tipc_sup_media sup_media[] = {
-               { "udp",        "name",         cmd_bearer_disable_udp_help},
-               { "eth",        "device",       cmd_bearer_disable_l2_help },
-               { "ib",         "device",       cmd_bearer_disable_l2_help },
-               { NULL, },
-       };
 
        if (parse_opts(opts, cmdl) < 0) {
                if (help_flag)
@@ -348,7 +356,7 @@ static int cmd_bearer_disable(struct nlmsghdr *nlh, const 
struct cmd *cmd,
        }
 
        nest = mnl_attr_nest_start(nlh, TIPC_NLA_BEARER);
-       err = nl_add_bearer_name(nlh, cmd, cmdl, opts, sup_media);
+       err = nl_add_bearer_name(nlh, cmd, cmdl, opts);
        if (err)
                return err;
        mnl_attr_nest_end(nlh, nest);
@@ -362,7 +370,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)
@@ -395,12 +403,6 @@ static int cmd_bearer_set_prop(struct nlmsghdr *nlh, const 
struct cmd *cmd,
                { "name",               NULL },
                { NULL }
        };
-       struct tipc_sup_media sup_media[] = {
-               { "udp",        "name",         cmd_bearer_set_udp_help},
-               { "eth",        "device",       cmd_bearer_set_l2_help },
-               { "ib",         "device",       cmd_bearer_set_l2_help },
-               { NULL, },
-       };
 
        if (strcmp(cmd->cmd, "priority") == 0)
                prop = TIPC_NLA_PROP_PRIO;
@@ -430,7 +432,7 @@ static int cmd_bearer_set_prop(struct nlmsghdr *nlh, const 
struct cmd *cmd,
        mnl_attr_put_u32(nlh, prop, val);
        mnl_attr_nest_end(nlh, props);
 
-       err = nl_add_bearer_name(nlh, cmd, cmdl, opts, sup_media);
+       err = nl_add_bearer_name(nlh, cmd, cmdl, opts);
        if (err)
                return err;
 
@@ -457,7 +459,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)
@@ -513,12 +515,6 @@ static int cmd_bearer_get_prop(struct nlmsghdr *nlh, const 
struct cmd *cmd,
                { "name",               NULL },
                { NULL }
        };
-       struct tipc_sup_media sup_media[] = {
-               { "udp",        "name",         cmd_bearer_get_udp_help},
-               { "eth",        "device",       cmd_bearer_get_l2_help },
-               { "ib",         "device",       cmd_bearer_get_l2_help },
-               { NULL, },
-       };
 
        if (strcmp(cmd->cmd, "priority") == 0)
                prop = TIPC_NLA_PROP_PRIO;
@@ -538,7 +534,7 @@ static int cmd_bearer_get_prop(struct nlmsghdr *nlh, const 
struct cmd *cmd,
        }
 
        attrs = mnl_attr_nest_start(nlh, TIPC_NLA_BEARER);
-       err = nl_add_bearer_name(nlh, cmd, cmdl, opts, sup_media);
+       err = nl_add_bearer_name(nlh, cmd, cmdl, opts);
        if (err)
                return err;
        mnl_attr_nest_end(nlh, attrs);
diff --git a/tipc/bearer.h b/tipc/bearer.h
index 9459d65ebb5f..c0a34c110f59 100644
--- a/tipc/bearer.h
+++ b/tipc/bearer.h
@@ -19,4 +19,7 @@ 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);
 #endif
-- 
2.1.4


------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are 
consuming the most bandwidth. Provides multi-vendor support for NetFlow, 
J-Flow, sFlow and other flows. Make informed decisions using capacity 
planning reports. http://sdm.link/zohodev2dev
_______________________________________________
tipc-discussion mailing list
tipc-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tipc-discussion

Reply via email to