lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241203124921.200637-1-robert.marko@sartura.hr>
Date: Tue,  3 Dec 2024 13:47:59 +0100
From: Robert Marko <robert.marko@...tura.hr>
To: netdev@...r.kernel.org,
	stephen@...workplumber.org,
	davem@...emloft.net,
	edumazet@...gle.com,
	kuba@...nel.org,
	dsahern@...nel.org,
	jiri@...nulli.us,
	andrew@...n.ch
Cc: luka.perkov@...tura.hr,
	Robert Marko <robert.marko@...tura.hr>
Subject: [iproute2-next] ip: link: rmnet: add support for flag handling

Extend the current rmnet support to allow enabling or disabling
IFLA_RMNET_FLAGS via ip link as well as printing the current settings.

Signed-off-by: Robert Marko <robert.marko@...tura.hr>
---
 ip/iplink_rmnet.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)

diff --git a/ip/iplink_rmnet.c b/ip/iplink_rmnet.c
index 1d16440c..49d487cc 100644
--- a/ip/iplink_rmnet.c
+++ b/ip/iplink_rmnet.c
@@ -16,6 +16,10 @@ static void print_explain(FILE *f)
 {
 	fprintf(f,
 		"Usage: ... rmnet mux_id MUXID\n"
+		"		[ deaggregate { on | off } ]\n"
+		"		[ commands { on | off } ]\n"
+		"		[ qmapv4 { on | off } ]\n"
+		"		[ qmapv5 { on | off } ]\n"
 		"\n"
 		"MUXID := 1-254\n"
 	);
@@ -26,9 +30,16 @@ static void explain(void)
 	print_explain(stderr);
 }
 
+static int on_off(const char *msg, const char *arg)
+{
+	fprintf(stderr, "Error: argument of \"%s\" must be \"on\" or \"off\", not \"%s\"\n", msg, arg);
+	return -1;
+}
+
 static int rmnet_parse_opt(struct link_util *lu, int argc, char **argv,
 			   struct nlmsghdr *n)
 {
+	struct ifla_rmnet_flags flags = { 0 };
 	__u16 mux_id;
 
 	while (argc > 0) {
@@ -37,6 +48,48 @@ static int rmnet_parse_opt(struct link_util *lu, int argc, char **argv,
 			if (get_u16(&mux_id, *argv, 0))
 				invarg("mux_id is invalid", *argv);
 			addattr16(n, 1024, IFLA_RMNET_MUX_ID, mux_id);
+		} else if (matches(*argv, "deaggregate") == 0) {
+			NEXT_ARG();
+			flags.mask |= RMNET_FLAGS_INGRESS_DEAGGREGATION;
+			if (strcmp(*argv, "on") == 0)
+				flags.flags |= RMNET_FLAGS_INGRESS_DEAGGREGATION;
+			else if (strcmp(*argv, "off") == 0)
+				flags.flags &= RMNET_FLAGS_INGRESS_DEAGGREGATION;
+			else
+				return on_off("deaggregate", *argv);
+		} else if (matches(*argv, "commands") == 0) {
+			NEXT_ARG();
+			flags.mask |= RMNET_FLAGS_INGRESS_MAP_COMMANDS;
+			if (strcmp(*argv, "on") == 0)
+				flags.flags |= RMNET_FLAGS_INGRESS_MAP_COMMANDS;
+			else if (strcmp(*argv, "off") == 0)
+				flags.flags &= RMNET_FLAGS_INGRESS_MAP_COMMANDS;
+			else
+				return on_off("commands", *argv);
+		} else if (matches(*argv, "qmapv4") == 0) {
+			NEXT_ARG();
+			flags.mask |= RMNET_FLAGS_INGRESS_MAP_CKSUMV4;
+			flags.mask |= RMNET_FLAGS_EGRESS_MAP_CKSUMV4;
+			if (strcmp(*argv, "on") == 0) {
+				flags.flags |= RMNET_FLAGS_INGRESS_MAP_CKSUMV4;
+				flags.flags |= RMNET_FLAGS_EGRESS_MAP_CKSUMV4;
+			} else if (strcmp(*argv, "off") == 0) {
+				flags.flags &= RMNET_FLAGS_INGRESS_MAP_CKSUMV4;
+				flags.flags &= RMNET_FLAGS_EGRESS_MAP_CKSUMV4;
+			} else
+				return on_off("qmapv4", *argv);
+		} else if (matches(*argv, "qmapv5") == 0) {
+			NEXT_ARG();
+			flags.mask |= RMNET_FLAGS_INGRESS_MAP_CKSUMV5;
+			flags.mask |= RMNET_FLAGS_EGRESS_MAP_CKSUMV5;
+			if (strcmp(*argv, "on") == 0) {
+				flags.flags |= RMNET_FLAGS_INGRESS_MAP_CKSUMV5;
+				flags.flags |= RMNET_FLAGS_EGRESS_MAP_CKSUMV5;
+			} else if (strcmp(*argv, "off") == 0) {
+				flags.flags &= RMNET_FLAGS_INGRESS_MAP_CKSUMV5;
+				flags.flags &= RMNET_FLAGS_EGRESS_MAP_CKSUMV5;
+			} else
+				return on_off("qmapv5", *argv);
 		} else if (matches(*argv, "help") == 0) {
 			explain();
 			return -1;
@@ -48,11 +101,34 @@ static int rmnet_parse_opt(struct link_util *lu, int argc, char **argv,
 		argc--, argv++;
 	}
 
+	if (flags.mask)
+		addattr_l(n, 1024, IFLA_RMNET_FLAGS, &flags, sizeof(flags));
+
 	return 0;
 }
+static void rmnet_print_flags(FILE *fp, __u32 flags)
+{
+	open_json_array(PRINT_ANY, is_json_context() ? "flags" : "<");
+#define _PF(f)	if (flags & RMNET_FLAGS_##f) {				\
+		flags &= ~RMNET_FLAGS_##f;				\
+		print_string(PRINT_ANY, NULL, flags ? "%s," : "%s", #f); \
+	}
+	_PF(INGRESS_DEAGGREGATION);
+	_PF(INGRESS_MAP_COMMANDS);
+	_PF(INGRESS_MAP_CKSUMV4);
+	_PF(EGRESS_MAP_CKSUMV4);
+	_PF(INGRESS_MAP_CKSUMV5);
+	_PF(EGRESS_MAP_CKSUMV5);
+#undef _PF
+	if (flags)
+		print_hex(PRINT_ANY, NULL, "%x", flags);
+	close_json_array(PRINT_ANY, "> ");
+}
 
 static void rmnet_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 {
+	struct ifla_rmnet_flags *flags;
+
 	if (!tb)
 		return;
 
@@ -64,6 +140,13 @@ static void rmnet_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 		   "mux_id",
 		   "mux_id %u ",
 		   rta_getattr_u16(tb[IFLA_RMNET_MUX_ID]));
+
+	if (tb[IFLA_RMNET_FLAGS]) {
+		if (RTA_PAYLOAD(tb[IFLA_RMNET_FLAGS]) < sizeof(*flags))
+			return;
+		flags = RTA_DATA(tb[IFLA_RMNET_FLAGS]);
+		rmnet_print_flags(f, flags->flags);
+	}
 }
 
 static void rmnet_print_help(struct link_util *lu, int argc, char **argv,
-- 
2.47.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ