All of lore.kernel.org
 help / color / mirror / Atom feed
* [iproute2-next  1/1] tipc: Add support to set and get MTU for UDP bearer
@ 2018-05-07 11:14 GhantaKrishnamurthy MohanKrishna
  2018-05-07 14:46 ` Stephen Hemminger
  0 siblings, 1 reply; 2+ messages in thread
From: GhantaKrishnamurthy MohanKrishna @ 2018-05-07 11:14 UTC (permalink / raw)
  To: tipc-discussion, jon.maloy, maloy, ying.xue,
	mohan.krishna.ghanta.krishnamurthy, netdev, davem, dsahern

In this commit we introduce the ability to set and get
MTU for UDP media and bearer.

For set and get properties such as tolerance, window and priority,
we already do:

    $ tipc media set PPROPERTY media MEDIA
    $ tipc media get PPROPERTY media MEDIA

    $ tipc bearer set OPTION media MEDIA ARGS
    $ tipc bearer get [OPTION] media MEDIA ARGS

The same has been extended for MTU, with an exception to support
only media type UDP.

Acked-by: Jon Maloy <jon.maloy@ericsson.com>
Signed-off-by: GhantaKrishnamurthy MohanKrishna <mohan.krishna.ghanta.krishnamurthy@ericsson.com>
---
 tipc/bearer.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++---------
 tipc/media.c  | 24 ++++++++++++++++++++++--
 2 files changed, 68 insertions(+), 11 deletions(-)

diff --git a/tipc/bearer.c b/tipc/bearer.c
index 0d8457015062..27e8d77f5635 100644
--- a/tipc/bearer.c
+++ b/tipc/bearer.c
@@ -42,7 +42,8 @@ static void _print_bearer_opts(void)
 		"OPTIONS\n"
 		" priority              - Bearer link priority\n"
 		" tolerance             - Bearer link tolerance\n"
-		" window                - Bearer link window\n");
+		" window                - Bearer link window\n"
+		" mtu                   - Bearer link mtu\n");
 }
 
 void print_bearer_media(void)
@@ -194,6 +195,21 @@ static int nl_add_udp_enable_opts(struct nlmsghdr *nlh, struct opt *opts,
 	return 0;
 }
 
+static char *cmd_get_media_type(const struct cmd *cmd, struct cmdl *cmdl,
+				struct opt *opts)
+{
+	struct opt *opt;
+
+	if (!(opt = get_opt(opts, "media"))) {
+		if (help_flag)
+			(cmd->help)(cmdl);
+		else
+			fprintf(stderr, "error, missing bearer media\n");
+		return NULL;
+	}
+	return opt->val;
+}
+
 static int nl_add_bearer_name(struct nlmsghdr *nlh, const struct cmd *cmd,
 			      struct cmdl *cmdl, struct opt *opts,
 			      const struct tipc_sup_media *sup_media)
@@ -217,15 +233,8 @@ int cmd_get_unique_bearer_name(const struct cmd *cmd, struct cmdl *cmdl,
 	struct opt *opt;
 	const struct tipc_sup_media *entry;
 
-
-	if (!(opt = get_opt(opts, "media"))) {
-		if (help_flag)
-			(cmd->help)(cmdl);
-		else
-			fprintf(stderr, "error, missing bearer media\n");
+	if (!(media = cmd_get_media_type(cmd, cmdl, opts)))
 		return -EINVAL;
-	}
-	media = opt->val;
 
 	for (entry = sup_media; entry->media; entry++) {
 		if (strcmp(entry->media, media))
@@ -559,6 +568,8 @@ static int cmd_bearer_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
 		prop = TIPC_NLA_PROP_TOL;
 	else if ((strcmp(cmd->cmd, "window") == 0))
 		prop = TIPC_NLA_PROP_WIN;
+	else if ((strcmp(cmd->cmd, "mtu") == 0))
+		prop = TIPC_NLA_PROP_MTU;
 	else
 		return -EINVAL;
 
@@ -571,6 +582,17 @@ static int cmd_bearer_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
 	if (parse_opts(opts, cmdl) < 0)
 		return -EINVAL;
 
+	if (prop == TIPC_NLA_PROP_MTU) {
+		char *media;
+
+		if (!(media = cmd_get_media_type(cmd, cmdl, opts)))
+			return -EINVAL;
+		else if (strcmp(media, "udp")) {
+			fprintf(stderr, "error, not supported for media\n");
+			return -EINVAL;
+		}
+	}
+
 	if (!(nlh = msg_init(buf, TIPC_NL_BEARER_SET))) {
 		fprintf(stderr, "error, message initialisation failed\n");
 		return -1;
@@ -597,6 +619,7 @@ static int cmd_bearer_set(struct nlmsghdr *nlh, const struct cmd *cmd,
 		{ "priority",	cmd_bearer_set_prop,	cmd_bearer_set_help },
 		{ "tolerance",	cmd_bearer_set_prop,	cmd_bearer_set_help },
 		{ "window",	cmd_bearer_set_prop,	cmd_bearer_set_help },
+		{ "mtu",	cmd_bearer_set_prop,	cmd_bearer_set_help },
 		{ NULL }
 	};
 
@@ -877,12 +900,25 @@ static int cmd_bearer_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
 		prop = TIPC_NLA_PROP_TOL;
 	else if ((strcmp(cmd->cmd, "window") == 0))
 		prop = TIPC_NLA_PROP_WIN;
+	else if ((strcmp(cmd->cmd, "mtu") == 0))
+		prop = TIPC_NLA_PROP_MTU;
 	else
 		return -EINVAL;
 
 	if (parse_opts(opts, cmdl) < 0)
 		return -EINVAL;
 
+	if (prop == TIPC_NLA_PROP_MTU) {
+		char *media;
+
+		if (!(media = cmd_get_media_type(cmd, cmdl, opts)))
+			return -EINVAL;
+		else if (strcmp(media, "udp")) {
+			fprintf(stderr, "error, not supported for media\n");
+			return -EINVAL;
+		}
+	}
+
 	if (!(nlh = msg_init(buf, TIPC_NL_BEARER_GET))) {
 		fprintf(stderr, "error, message initialisation failed\n");
 		return -1;
@@ -904,6 +940,7 @@ static int cmd_bearer_get(struct nlmsghdr *nlh, const struct cmd *cmd,
 		{ "priority",	cmd_bearer_get_prop,	cmd_bearer_get_help },
 		{ "tolerance",	cmd_bearer_get_prop,	cmd_bearer_get_help },
 		{ "window",	cmd_bearer_get_prop,	cmd_bearer_get_help },
+		{ "mtu",	cmd_bearer_get_prop,	cmd_bearer_get_help },
 		{ "media",	cmd_bearer_get_media,	cmd_bearer_get_help },
 		{ NULL }
 	};
diff --git a/tipc/media.c b/tipc/media.c
index 6e10c7e5d8e6..969ef6578b3b 100644
--- a/tipc/media.c
+++ b/tipc/media.c
@@ -103,6 +103,8 @@ static int cmd_media_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
 		prop = TIPC_NLA_PROP_TOL;
 	else if ((strcmp(cmd->cmd, "window") == 0))
 		prop = TIPC_NLA_PROP_WIN;
+	else if ((strcmp(cmd->cmd, "mtu") == 0))
+		prop = TIPC_NLA_PROP_MTU;
 	else
 		return -EINVAL;
 
@@ -123,6 +125,12 @@ static int cmd_media_get_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
 		fprintf(stderr, "error, missing media\n");
 		return -EINVAL;
 	}
+
+	if ((prop == TIPC_NLA_PROP_MTU) &&
+	    (strcmp(opt->val, "udp"))) {
+		fprintf(stderr, "error, not supported for media\n");
+		return -EINVAL;
+	}
 	nest = mnl_attr_nest_start(nlh, TIPC_NLA_MEDIA);
 	mnl_attr_put_strz(nlh, TIPC_NLA_MEDIA_NAME, opt->val);
 	mnl_attr_nest_end(nlh, nest);
@@ -136,7 +144,8 @@ static void cmd_media_get_help(struct cmdl *cmdl)
 		"PROPERTIES\n"
 		" tolerance             - Get media tolerance\n"
 		" priority              - Get media priority\n"
-		" window                - Get media window\n",
+		" window                - Get media window\n"
+		" mtu                   - Get media mtu\n",
 		cmdl->argv[0]);
 }
 
@@ -147,6 +156,7 @@ static int cmd_media_get(struct nlmsghdr *nlh, const struct cmd *cmd,
 		{ "priority",	cmd_media_get_prop,	cmd_media_get_help },
 		{ "tolerance",	cmd_media_get_prop,	cmd_media_get_help },
 		{ "window",	cmd_media_get_prop,	cmd_media_get_help },
+		{ "mtu",	cmd_media_get_prop,	cmd_media_get_help },
 		{ NULL }
 	};
 
@@ -159,7 +169,8 @@ static void cmd_media_set_help(struct cmdl *cmdl)
 		"PROPERTIES\n"
 		" tolerance TOLERANCE   - Set media tolerance\n"
 		" priority PRIORITY     - Set media priority\n"
-		" window WINDOW         - Set media window\n",
+		" window WINDOW         - Set media window\n"
+		" mtu MTU               - Set media mtu\n",
 		cmdl->argv[0]);
 }
 
@@ -183,6 +194,8 @@ static int cmd_media_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
 		prop = TIPC_NLA_PROP_TOL;
 	else if ((strcmp(cmd->cmd, "window") == 0))
 		prop = TIPC_NLA_PROP_WIN;
+	else if ((strcmp(cmd->cmd, "mtu") == 0))
+		prop = TIPC_NLA_PROP_MTU;
 	else
 		return -EINVAL;
 
@@ -210,6 +223,12 @@ static int cmd_media_set_prop(struct nlmsghdr *nlh, const struct cmd *cmd,
 		fprintf(stderr, "error, missing media\n");
 		return -EINVAL;
 	}
+
+	if ((prop == TIPC_NLA_PROP_MTU) &&
+	    (strcmp(opt->val, "udp"))) {
+		fprintf(stderr, "error, not supported for media\n");
+		return -EINVAL;
+	}
 	mnl_attr_put_strz(nlh, TIPC_NLA_MEDIA_NAME, opt->val);
 
 	props = mnl_attr_nest_start(nlh, TIPC_NLA_MEDIA_PROP);
@@ -228,6 +247,7 @@ static int cmd_media_set(struct nlmsghdr *nlh, const struct cmd *cmd,
 		{ "priority",	cmd_media_set_prop,	cmd_media_set_help },
 		{ "tolerance",	cmd_media_set_prop,	cmd_media_set_help },
 		{ "window",	cmd_media_set_prop,	cmd_media_set_help },
+		{ "mtu",	cmd_media_set_prop,	cmd_media_set_help },
 		{ NULL }
 	};
 
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [iproute2-next  1/1] tipc: Add support to set and get MTU for UDP bearer
  2018-05-07 11:14 [iproute2-next 1/1] tipc: Add support to set and get MTU for UDP bearer GhantaKrishnamurthy MohanKrishna
@ 2018-05-07 14:46 ` Stephen Hemminger
  0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2018-05-07 14:46 UTC (permalink / raw)
  To: GhantaKrishnamurthy MohanKrishna
  Cc: tipc-discussion, jon.maloy, maloy, ying.xue, netdev, davem, dsahern

On Mon, 7 May 2018 13:14:33 +0200
GhantaKrishnamurthy MohanKrishna         <mohan.krishna.ghanta.krishnamurthy@ericsson.com> wrote:

> +				struct opt *opts)
> +{
> +	struct opt *opt;
> +
> +	if (!(opt = get_opt(opts, "media"))) {

You don't need to have assignment in conditional context in this case.
Please split the assignment and the if.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-05-07 14:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-07 11:14 [iproute2-next 1/1] tipc: Add support to set and get MTU for UDP bearer GhantaKrishnamurthy MohanKrishna
2018-05-07 14:46 ` Stephen Hemminger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.