When L2 interface (e.g VXLAN) pseudo support broadcast, we should make it
possible for the user to disable this manually and switch to replicast.

Usage:
- Enable broadcast for bearer:
$tipc link set broadcast 1 link broadcast-link

- Disable broadcast (means replicast used) for bearer:
$tipc link set broadcast 0 link broadcast-link

Signed-off-by: Hoang Le <[email protected]>
---
 include/uapi/linux/tipc_netlink.h |  3 ++-
 tipc/link.c                       | 40 +++++++++++++++++++++++++++----
 2 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/include/uapi/linux/tipc_netlink.h 
b/include/uapi/linux/tipc_netlink.h
index 0ebe02ef1a86..a4a765f69352 100644
--- a/include/uapi/linux/tipc_netlink.h
+++ b/include/uapi/linux/tipc_netlink.h
@@ -273,7 +273,7 @@ enum {
        TIPC_NLA_SOCK_STAT_MAX = __TIPC_NLA_SOCK_STAT_MAX - 1
 };
 
-/* Nest, link propreties. Valid for link, media and bearer */
+/* Nest, link properties. Valid for link, media and bearer */
 enum {
        TIPC_NLA_PROP_UNSPEC,
 
@@ -281,6 +281,7 @@ enum {
        TIPC_NLA_PROP_TOL,              /* u32 */
        TIPC_NLA_PROP_WIN,              /* u32 */
        TIPC_NLA_PROP_MTU,              /* u32 */
+       TIPC_NLA_PROP_BCAST,            /* u8 */
 
        __TIPC_NLA_PROP_MAX,
        TIPC_NLA_PROP_MAX = __TIPC_NLA_PROP_MAX - 1
diff --git a/tipc/link.c b/tipc/link.c
index 43e26da3fa6b..45f2070d5a6d 100644
--- a/tipc/link.c
+++ b/tipc/link.c
@@ -28,6 +28,7 @@
 #define PRIORITY_STR "priority"
 #define TOLERANCE_STR "tolerance"
 #define WINDOW_STR "window"
+#define BCAST_STR "broadcast"
 
 static int link_list_cb(const struct nlmsghdr *nlh, void *data)
 {
@@ -111,6 +112,11 @@ static int link_get_cb(const struct nlmsghdr *nlh, void 
*data)
                case TIPC_NLA_PROP_WIN:
                        print_uint(PRINT_ANY, WINDOW_STR, "%u\n", 
mnl_attr_get_u32(props[*prop]));
                break;
+               case TIPC_NLA_PROP_BCAST:
+                       print_string(PRINT_ANY, NULL, "%s\n",
+                                    mnl_attr_get_u32(props[*prop]) ?
+                                    "BROADCAST" : "REPLICAST");
+               break;
                default:
                        break;
        }
@@ -137,6 +143,8 @@ static int cmd_link_get_prop(struct nlmsghdr *nlh, const 
struct cmd *cmd,
                prop = TIPC_NLA_PROP_TOL;
        else if ((strcmp(cmd->cmd, WINDOW_STR) == 0))
                prop = TIPC_NLA_PROP_WIN;
+       else if ((strcmp(cmd->cmd, BCAST_STR) == 0))
+               prop = TIPC_NLA_PROP_BCAST;
        else
                return -EINVAL;
 
@@ -172,7 +180,8 @@ static void cmd_link_get_help(struct cmdl *cmdl)
                "PROPERTIES\n"
                " tolerance             - Get link tolerance\n"
                " priority              - Get link priority\n"
-               " window                - Get link window\n",
+               " window                - Get link window\n"
+               " broadcast             - Get link broadcast supporting\n",
                cmdl->argv[0]);
 }
 
@@ -183,6 +192,7 @@ static int cmd_link_get(struct nlmsghdr *nlh, const struct 
cmd *cmd,
                { PRIORITY_STR, cmd_link_get_prop,      cmd_link_get_help },
                { TOLERANCE_STR,        cmd_link_get_prop,      
cmd_link_get_help },
                { WINDOW_STR,   cmd_link_get_prop,      cmd_link_get_help },
+               { BCAST_STR,    cmd_link_get_prop,      cmd_link_get_help },
                { NULL }
        };
 
@@ -249,6 +259,14 @@ static int _show_link_stat(const char *name, struct nlattr 
*attrs[],
        open_json_object(NULL);
 
        print_string(PRINT_ANY, "link", "\nLink <%s>\n", name);
+       print_string(PRINT_JSON, "flag", "", NULL);
+       open_json_array(PRINT_JSON, NULL);
+       if (mnl_attr_get_u8(prop[TIPC_NLA_PROP_BCAST]))
+               print_string(PRINT_ANY, NULL, "  %s", "BROADCAST");
+       else
+               print_string(PRINT_ANY, NULL, "  %s", "REPLICAST");
+       close_json_array(PRINT_JSON, NULL);
+
        print_string(PRINT_JSON, "state", "", NULL);
        open_json_array(PRINT_JSON, NULL);
        if (attrs[TIPC_NLA_LINK_ACTIVE])
@@ -355,10 +373,17 @@ static int _show_link_stat(const char *name, struct 
nlattr *attrs[],
 }
 
 static int _show_bc_link_stat(const char *name, struct nlattr *prop[],
-                          struct nlattr *stats[])
+                             struct nlattr *stats[])
 {
        open_json_object(NULL);
        print_string(PRINT_ANY, "link", "Link <%s>\n", name);
+       print_string(PRINT_JSON, "flag", "", NULL);
+       open_json_array(PRINT_JSON, NULL);
+       if (mnl_attr_get_u8(prop[TIPC_NLA_PROP_BCAST]))
+               print_string(PRINT_ANY, NULL, "  %s", "BROADCAST");
+       else
+               print_string(PRINT_ANY, NULL, "  %s", "REPLICAST");
+       close_json_array(PRINT_JSON, NULL);
        print_uint(PRINT_ANY, WINDOW_STR, "  Window:%u packets\n",
                           mnl_attr_get_u32(prop[TIPC_NLA_PROP_WIN]));
 
@@ -521,7 +546,8 @@ static void cmd_link_set_help(struct cmdl *cmdl)
                "PROPERTIES\n"
                " tolerance TOLERANCE   - Set link tolerance\n"
                " priority PRIORITY     - Set link priority\n"
-               " window WINDOW         - Set link window\n",
+               " window WINDOW         - Set link window\n"
+               " broadcast [0|1]       - Set <broadcast-link> 
[replicast|broadcast] supporting\n",
                cmdl->argv[0]);
 }
 
@@ -545,6 +571,8 @@ static int cmd_link_set_prop(struct nlmsghdr *nlh, const 
struct cmd *cmd,
                prop = TIPC_NLA_PROP_TOL;
        else if ((strcmp(cmd->cmd, WINDOW_STR) == 0))
                prop = TIPC_NLA_PROP_WIN;
+       else if ((strcmp(cmd->cmd, BCAST_STR) == 0))
+               prop = TIPC_NLA_PROP_BCAST;
        else
                return -EINVAL;
 
@@ -577,7 +605,10 @@ static int cmd_link_set_prop(struct nlmsghdr *nlh, const 
struct cmd *cmd,
        mnl_attr_put_strz(nlh, TIPC_NLA_LINK_NAME, opt->val);
 
        props = mnl_attr_nest_start(nlh, TIPC_NLA_LINK_PROP);
-       mnl_attr_put_u32(nlh, prop, val);
+       if (prop == TIPC_NLA_PROP_BCAST)
+               mnl_attr_put_u8(nlh, prop, val);
+       else
+               mnl_attr_put_u32(nlh, prop, val);
        mnl_attr_nest_end(nlh, props);
 
        mnl_attr_nest_end(nlh, attrs);
@@ -592,6 +623,7 @@ static int cmd_link_set(struct nlmsghdr *nlh, const struct 
cmd *cmd,
                { PRIORITY_STR, cmd_link_set_prop,      cmd_link_set_help },
                { TOLERANCE_STR,        cmd_link_set_prop,      
cmd_link_set_help },
                { WINDOW_STR,   cmd_link_set_prop,      cmd_link_set_help },
+               { BCAST_STR,    cmd_link_set_prop,      cmd_link_set_help },
                { NULL }
        };
 
-- 
2.17.1



_______________________________________________
tipc-discussion mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tipc-discussion

Reply via email to