Patchwork [TESTING] Add support for configuring route entry features

login
register
mail settings
Submitter Gilad Ben-Yossef
Date Oct. 20, 2009, 4:22 p.m.
Message ID <1256055721-22065-1-git-send-email-gilad@codefidence.com>
Download mbox | patch
Permalink /patch/36476/
State RFC
Delegated to: David Miller
Headers show

Comments

Gilad Ben-Yossef - Oct. 20, 2009, 4:22 p.m.
This is needed to test my previous per route entry TCP options patch.

Feature display is still numeric, so this is not the final version yet.

To use: add "features nows nots nosack nodsack to a route entry.

Based loosley on original patch by Ilpo Järvinen.

Signed-off-by: Gilad Ben-Yossef <gilad@codefidence.com>

CC: Ilpo Järvinen <ilpo.jarvinen@helsinki.fi>

---
 include/linux/rtnetlink.h |   10 ++++++----
 ip/iproute.c              |   45 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 50 insertions(+), 5 deletions(-)

Patch

diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h
index 63d1c69..35964d4 100644
--- a/include/linux/rtnetlink.h
+++ b/include/linux/rtnetlink.h
@@ -376,10 +376,12 @@  enum
 
 #define RTAX_MAX (__RTAX_MAX - 1)
 
-#define RTAX_FEATURE_ECN	0x00000001
-#define RTAX_FEATURE_SACK	0x00000002
-#define RTAX_FEATURE_TIMESTAMP	0x00000004
-#define RTAX_FEATURE_ALLFRAG	0x00000008
+#define RTAX_FEATURE_ECN        0x00000001
+#define RTAX_FEATURE_NO_SACK    0x00000002
+#define RTAX_FEATURE_NO_TSTAMP  0x00000004
+#define RTAX_FEATURE_ALLFRAG    0x00000008
+#define RTAX_FEATURE_NO_WSCALE  0x00000010
+#define RTAX_FEATURE_NO_DSACK   0x00000020
 
 struct rta_session
 {
diff --git a/ip/iproute.c b/ip/iproute.c
index aeea93d..9dcc0e0 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -54,6 +54,22 @@  static const char *mx_names[RTAX_MAX+1] = {
 	[RTAX_FEATURES] = "features",
 	[RTAX_RTO_MIN]	= "rto_min",
 };
+
+struct valname {
+	unsigned int	val;
+	const char	*name;
+};
+
+static const struct valname features[] = {
+	{ RTAX_FEATURE_NO_SACK, "nosack" },
+	{ RTAX_FEATURE_NO_TSTAMP, "notimestamps" },
+	{ RTAX_FEATURE_NO_TSTAMP, "nots" },
+	{ RTAX_FEATURE_NO_WSCALE, "nowindowscale" },
+	{ RTAX_FEATURE_NO_WSCALE, "nows" },
+	{ RTAX_FEATURE_NO_DSACK, "nodsack" },
+	
+};
+
 static void usage(void) __attribute__((noreturn));
 
 static void usage(void)
@@ -75,7 +91,8 @@  static void usage(void)
 	fprintf(stderr, "           [ rtt TIME ] [ rttvar TIME ] [reordering NUMBER ]\n");
 	fprintf(stderr, "           [ window NUMBER] [ cwnd NUMBER ] [ initcwnd NUMBER ]\n");
 	fprintf(stderr, "           [ ssthresh NUMBER ] [ realms REALM ] [ src ADDRESS ]\n");
-	fprintf(stderr, "           [ rto_min TIME ] [ hoplimit NUMBER ] \n");
+	fprintf(stderr, "           [ rto_min TIME ] [ hoplimit NUMBER ]\n"); 
+	fprintf(stderr, "           [ features DISABLED_FEATURES ]\n");
 	fprintf(stderr, "TYPE := [ unicast | local | broadcast | multicast | throw |\n");
 	fprintf(stderr, "          unreachable | prohibit | blackhole | nat ]\n");
 	fprintf(stderr, "TABLE_ID := [ local | main | default | all | NUMBER ]\n");
@@ -85,6 +102,8 @@  static void usage(void)
 	fprintf(stderr, "NHFLAGS := [ onlink | pervasive ]\n");
 	fprintf(stderr, "RTPROTO := [ kernel | boot | static | NUMBER ]\n");
 	fprintf(stderr, "TIME := NUMBER[s|ms|us|ns|j]\n");
+	fprintf(stderr, "DISABLED_FEATURES := sack | timestamps | ts | ecn | frto |\n");
+	fprintf(stderr, "                     [ DISABLED_FEATURES ]\n");
 	exit(-1);
 }
 
@@ -877,6 +896,30 @@  int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
 			if (get_unsigned(&win, *argv, 0))
 				invarg("\"ssthresh\" value is invalid\n", *argv);
 			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_SSTHRESH, win);
+		} else if (matches(*argv, "features") == 0) {
+			int j;
+			unsigned int f = 0;
+			NEXT_ARG();
+			while (1) {
+				for (j = 0; j < ARRAY_SIZE(features); j++) {
+					if (strcmp(*argv, features[j].name) == 0) {
+						f |= features[j].val;
+						if (!NEXT_ARG_OK())
+							goto feat_out;
+						NEXT_ARG();
+						break;
+					}
+				}
+				if (j == ARRAY_SIZE(features)) {
+					if (f)
+						PREV_ARG();
+					break;
+				}
+			}
+feat_out:
+			if (!f)
+				invarg("\"features\" list is invalid\n", *argv);
+			rta_addattr32(mxrta, sizeof(mxbuf), RTAX_FEATURES, f);
 		} else if (matches(*argv, "realms") == 0) {
 			__u32 realm;
 			NEXT_ARG();