This patch introduces "tipc bearer add" which can be used to add
remoteip addresses to an existing UDP bearer.

This puts the bearer in replicast mode, which means the bearer will
emulate mutlicast by sending multiple unicast copies of the same
packet. This allow more than two nodes to communicate in environments
where IP multicast is disabled.

Signed-off-by: Richard Alpe <richard.a...@ericsson.com>
---
 include/linux/tipc_netlink.h |  1 +
 man/man8/tipc-bearer.8       | 15 +++++++
 tipc/bearer.c                | 95 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 111 insertions(+)

diff --git a/include/linux/tipc_netlink.h b/include/linux/tipc_netlink.h
index d4c8f14..3388330 100644
--- a/include/linux/tipc_netlink.h
+++ b/include/linux/tipc_netlink.h
@@ -56,6 +56,7 @@ enum {
        TIPC_NL_NET_GET,
        TIPC_NL_NET_SET,
        TIPC_NL_NAME_TABLE_GET,
+       TIPC_NL_BEARER_ADD,
 
        __TIPC_NL_CMD_MAX,
        TIPC_NL_CMD_MAX = __TIPC_NL_CMD_MAX - 1
diff --git a/man/man8/tipc-bearer.8 b/man/man8/tipc-bearer.8
index 0f22ca3..b71739d 100644
--- a/man/man8/tipc-bearer.8
+++ b/man/man8/tipc-bearer.8
@@ -11,6 +11,10 @@ tipc-bearer \- show or modify TIPC bearers
 .in +8
 
 .ti -8
+.B tipc bearer add remoteip REMOTEIP media udp name NAME
+.br
+
+.ti -8
 .B tipc bearer enable
 .RB "[ " domain
 .IR DOMAIN " ]"
@@ -197,6 +201,17 @@ IP is specified the
 .B UDP
 bearer runs in point-to-point mode.
 
+Multiple
+.B remoteip
+addresses can be added via the
+.B bearer add
+command. The UDP bearer will then use replicast to emulate multicast. This 
means
+that TIPC broadcast and multicast messages are copied and sent using unicast to
+each configured
+.B remoteip.
+This allow more than two nodes to communicate in environments where IP 
multicast
+is disabled.
+
 .TP
 .B remoteport
 .br
diff --git a/tipc/bearer.c b/tipc/bearer.c
index ff7ee57..ecb9446 100644
--- a/tipc/bearer.c
+++ b/tipc/bearer.c
@@ -403,6 +403,99 @@ static int cmd_bearer_disable(struct nlmsghdr *nlh, const 
struct cmd *cmd,
 
 }
 
+static void cmd_bearer_add_help(struct cmdl *cmdl)
+{
+       fprintf(stderr,
+               "Usage: %s bearer add remoteip REMOTEIP media udp name NAME\n",
+               cmdl->argv[0]);
+}
+
+static int udp_bearer_add(struct nlmsghdr *nlh, struct opt *opts,
+                         struct cmdl *cmdl)
+{
+       int err;
+       struct opt *opt;
+       struct nlattr *opts_nest;
+
+       opts_nest = mnl_attr_nest_start(nlh, TIPC_NLA_BEARER_UDP_OPTS);
+       if ((opt = get_opt(opts, "remoteip"))) {
+               char *ip = opt->val;
+               struct addrinfo *addr = NULL;
+               struct addrinfo hints = {
+                       .ai_family = AF_UNSPEC,
+                       .ai_socktype = SOCK_DGRAM
+               };
+
+               if ((err = getaddrinfo(ip, NULL, &hints, &addr))) {
+                       fprintf(stderr, "UDP address error: %s\n",
+                               gai_strerror(err));
+                       freeaddrinfo(addr);
+                       return err;
+               }
+
+               mnl_attr_put(nlh, TIPC_NLA_UDP_REMOTE, addr->ai_addrlen,
+                            addr->ai_addr);
+               freeaddrinfo(addr);
+       }
+       mnl_attr_nest_end(nlh, opts_nest);
+
+       return 0;
+}
+
+static int cmd_bearer_add(struct nlmsghdr *nlh, const struct cmd *cmd,
+                            struct cmdl *cmdl, void *data)
+{
+       int err;
+       struct opt *opt;
+       struct nlattr *nest;
+       char buf[MNL_SOCKET_BUFFER_SIZE];
+       char *media;
+       struct opt opts[] = {
+               { "media",              NULL },
+               { "name",               NULL },
+               { "remoteip",           NULL },
+               { NULL }
+       };
+
+       /* We can do this here as there's currently only one help function */
+       if (help_flag) {
+               (cmd->help)(cmdl);
+               return -EINVAL;
+       }
+
+       if (parse_opts(opts, cmdl) < 0)
+               return -EINVAL;
+
+       if (!get_opt(opts, "remoteip")) {
+               fprintf(stderr, "error, missing remoteip\n");
+               return -EINVAL;
+       }
+       if (!(opt = get_opt(opts, "media"))) {
+               fprintf(stderr, "error, missing bearer media\n");
+               return -EINVAL;
+       }
+       media = opt->val;
+
+       if (!(nlh = msg_init(buf, TIPC_NL_BEARER_ADD))) {
+               fprintf(stderr, "error: message initialisation failed\n");
+               return -1;
+       }
+       nest = mnl_attr_nest_start(nlh, TIPC_NLA_BEARER);
+
+       if (strcmp(media, "udp") == 0) {
+               if ((err = udp_bearer_add(nlh, opts, cmdl)))
+                       return err;
+               if ((err = add_udp_bearer(nlh, opts)))
+                       return err;
+       } else {
+               fprintf(stderr, "error, invalid media type \"%s\"\n", media);
+               return -EINVAL;
+       }
+       mnl_attr_nest_end(nlh, nest);
+
+       return msg_doit(nlh, NULL, NULL);
+}
+
 static void cmd_bearer_set_help(struct cmdl *cmdl)
 {
        fprintf(stderr, "Usage: %s bearer set OPTION media MEDIA ARGS...\n",
@@ -793,6 +886,7 @@ void cmd_bearer_help(struct cmdl *cmdl)
                "Usage: %s bearer COMMAND [ARGS] ...\n"
                "\n"
                "COMMANDS\n"
+               " add                   - Add parameters to a bearer\n"
                " enable                - Enable a bearer\n"
                " disable               - Disable a bearer\n"
                " set                   - Set various bearer properties\n"
@@ -804,6 +898,7 @@ int cmd_bearer(struct nlmsghdr *nlh, const struct cmd *cmd, 
struct cmdl *cmdl,
               void *data)
 {
        const struct cmd cmds[] = {
+               { "add",        cmd_bearer_add,         cmd_bearer_add_help },
                { "disable",    cmd_bearer_disable,     cmd_bearer_disable_help 
},
                { "enable",     cmd_bearer_enable,      cmd_bearer_enable_help 
},
                { "get",        cmd_bearer_get,         cmd_bearer_get_help },
-- 
2.1.4


------------------------------------------------------------------------------
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
tipc-discussion@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tipc-discussion

Reply via email to