naccyde / rpms / iproute

Forked from rpms/iproute 5 months ago
Clone

Blame SOURCES/0031-pedit-Introduce-ipv6-support.patch

cd1737
From 26ab66d7c43c3ef60ab058d4c3da8989a5c1dd46 Mon Sep 17 00:00:00 2001
cd1737
From: Kamal Heib <kheib@redhat.com>
cd1737
Date: Thu, 9 Nov 2017 04:44:32 -0500
cd1737
Subject: [PATCH] pedit: Introduce ipv6 support
cd1737
cd1737
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1456539
cd1737
cd1737
commit f3e1b2448a95baef587965b08f48d49b6e1ec2cb
cd1737
Author: Amir Vadai <amir@vadai.me>
cd1737
Date:   Sun May 14 11:17:46 2017 +0300
cd1737
cd1737
    pedit: Introduce ipv6 support
cd1737
cd1737
    Add support for modifying IPv6 headers using pedit.
cd1737
cd1737
    Signed-off-by: Amir Vadai <amir@vadai.me>
cd1737
cd1737
Signed-off-by: Kamal Heib <kheib@redhat.com>
cd1737
---
cd1737
 man/man8/tc-pedit.8 | 30 ++++++++++++++++++
cd1737
 tc/Makefile         |  1 +
cd1737
 tc/m_pedit.c        | 43 +++++++++++++++++++++++--
cd1737
 tc/p_ip.c           | 17 +---------
cd1737
 tc/p_ip6.c          | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++
cd1737
 5 files changed, 164 insertions(+), 18 deletions(-)
cd1737
 create mode 100644 tc/p_ip6.c
cd1737
cd1737
diff --git a/man/man8/tc-pedit.8 b/man/man8/tc-pedit.8
cd1737
index 9c4d57b..82d4217 100644
cd1737
--- a/man/man8/tc-pedit.8
cd1737
+++ b/man/man8/tc-pedit.8
cd1737
@@ -33,6 +33,8 @@ pedit - generic packet editor action
cd1737
 |
cd1737
 .BI ip " EX_IPHDR_FIELD"
cd1737
 |
cd1737
+.BI ip6 " IP6HDR_FIELD"
cd1737
+|
cd1737
 .BI tcp " TCPHDR_FIELD"
cd1737
 |
cd1737
 .BI udp " UDPHDR_FIELD"
cd1737
@@ -55,6 +57,12 @@ pedit - generic packet editor action
cd1737
 .IR EX_IPHDR_FIELD " := { "
cd1737
 .BR ttl " }"
cd1737
 
cd1737
+
cd1737
+.ti -8
cd1737
+.IR IP6HDR_FIELD " := { "
cd1737
+.BR src " | " dst " | " flow_lbl " | " payload_len " | " nexthdr " |"
cd1737
+.BR hoplimit " }"
cd1737
+
cd1737
 .ti -8
cd1737
 .IR TCPHDR_FIELD " := { "
cd1737
 .BR sport " | " dport " | " flags " }"
cd1737
@@ -211,6 +219,25 @@ are:
cd1737
 .B ttl
cd1737
 .RE
cd1737
 .TP
cd1737
+.BI ip6 " IP6HDR_FIELD"
cd1737
+The supported keywords for
cd1737
+.I IP6HDR_FIELD
cd1737
+are:
cd1737
+.RS
cd1737
+.TP
cd1737
+.B src
cd1737
+.TQ
cd1737
+.B dst
cd1737
+.TQ
cd1737
+.B flow_lbl
cd1737
+.TQ
cd1737
+.B payload_len
cd1737
+.TQ
cd1737
+.B nexthdr
cd1737
+.TQ
cd1737
+.B hoplimit
cd1737
+.RE
cd1737
+.TP
cd1737
 .BI tcp " TCPHDR_FIELD"
cd1737
 The supported keywords for
cd1737
 .I TCPHDR_FIELD
cd1737
@@ -331,6 +358,9 @@ tc filter add dev eth0 parent ffff: u32 \\
cd1737
 	action pedit ex munge ip dst set 192.168.1.199
cd1737
 tc filter add dev eth0 parent ffff: u32 \\
cd1737
 	match ip sport 22 0xffff \\
cd1737
+	action pedit ex munge ip6 dst set fe80::dacb:8aff:fec7:320e
cd1737
+tc filter add dev eth0 parent ffff: u32 \\
cd1737
+	match ip sport 22 0xffff \\
cd1737
 	action pedit ex munge eth dst set 11:22:33:44:55:66
cd1737
 tc filter add dev eth0 parent ffff: u32 \\
cd1737
 	match ip dport 23 0xffff \\
cd1737
diff --git a/tc/Makefile b/tc/Makefile
cd1737
index 446a113..9a6bb1d 100644
cd1737
--- a/tc/Makefile
cd1737
+++ b/tc/Makefile
cd1737
@@ -53,6 +53,7 @@ TCMODULES += m_bpf.o
cd1737
 TCMODULES += m_tunnel_key.o
cd1737
 TCMODULES += m_sample.o
cd1737
 TCMODULES += p_ip.o
cd1737
+TCMODULES += p_ip6.o
cd1737
 TCMODULES += p_icmp.o
cd1737
 TCMODULES += p_eth.o
cd1737
 TCMODULES += p_tcp.o
cd1737
diff --git a/tc/m_pedit.c b/tc/m_pedit.c
cd1737
index 9b74c96..dfa6b2c 100644
cd1737
--- a/tc/m_pedit.c
cd1737
+++ b/tc/m_pedit.c
cd1737
@@ -257,6 +257,32 @@ static int pack_mac(struct m_pedit_sel *sel, struct m_pedit_key *tkey,
cd1737
 	return ret;
cd1737
 }
cd1737
 
cd1737
+static int pack_ipv6(struct m_pedit_sel *sel, struct m_pedit_key *tkey,
cd1737
+		     __u32 *ipv6)
cd1737
+{
cd1737
+	int ret = 0;
cd1737
+	int i;
cd1737
+
cd1737
+	if (tkey->off & 0x3) {
cd1737
+		fprintf(stderr,
cd1737
+			"pack_ipv6: IPv6 offsets must begin in 32bit boundaries\n");
cd1737
+		return -1;
cd1737
+	}
cd1737
+
cd1737
+	for (i = 0; i < 4; i++) {
cd1737
+		tkey->mask = 0;
cd1737
+		tkey->val = ntohl(ipv6[i]);
cd1737
+
cd1737
+		ret = pack_key32(~0, sel, tkey);
cd1737
+		if (ret)
cd1737
+			return ret;
cd1737
+
cd1737
+		tkey->off += 4;
cd1737
+	}
cd1737
+
cd1737
+	return 0;
cd1737
+}
cd1737
+
cd1737
 int parse_val(int *argc_p, char ***argv_p, __u32 *val, int type)
cd1737
 {
cd1737
 	int argc = *argc_p;
cd1737
@@ -281,8 +307,16 @@ int parse_val(int *argc_p, char ***argv_p, __u32 *val, int type)
cd1737
 		return 0;
cd1737
 	}
cd1737
 
cd1737
-	if (type == TIPV6)
cd1737
-		return -1; /* not implemented yet */
cd1737
+	if (type == TIPV6) {
cd1737
+		inet_prefix addr;
cd1737
+
cd1737
+		if (get_prefix_1(&addr, *argv, AF_INET6))
cd1737
+			return -1;
cd1737
+
cd1737
+		memcpy(val, addr.data, addr.bytelen);
cd1737
+
cd1737
+		return 0;
cd1737
+	}
cd1737
 
cd1737
 	if (type == TMAC) {
cd1737
 #define MAC_ALEN 6
cd1737
@@ -364,6 +398,11 @@ int parse_cmd(int *argc_p, char ***argv_p, __u32 len, int type, __u32 retain,
cd1737
 		goto done;
cd1737
 	}
cd1737
 
cd1737
+	if (type == TIPV6) {
cd1737
+		res = pack_ipv6(sel, tkey, val);
cd1737
+		goto done;
cd1737
+	}
cd1737
+
cd1737
 	tkey->val = *v;
cd1737
 	tkey->mask = *m;
cd1737
 
cd1737
diff --git a/tc/p_ip.c b/tc/p_ip.c
cd1737
index 22fe650..0272a6e 100644
cd1737
--- a/tc/p_ip.c
cd1737
+++ b/tc/p_ip.c
cd1737
@@ -1,5 +1,5 @@
cd1737
 /*
cd1737
- * m_pedit.c		packet editor: IPV4/6 header
cd1737
+ * p_ip.c		packet editor: IPV4 header
cd1737
  *
cd1737
  *		This program is free software; you can distribute it and/or
cd1737
  *		modify it under the terms of the GNU General Public License
cd1737
@@ -156,23 +156,8 @@ done:
cd1737
 	return res;
cd1737
 }
cd1737
 
cd1737
-static int
cd1737
-parse_ip6(int *argc_p, char ***argv_p,
cd1737
-	  struct m_pedit_sel *sel, struct m_pedit_key *tkey)
cd1737
-{
cd1737
-	int res = -1;
cd1737
-	return res;
cd1737
-}
cd1737
-
cd1737
 struct m_pedit_util p_pedit_ip = {
cd1737
 	NULL,
cd1737
 	"ip",
cd1737
 	parse_ip,
cd1737
 };
cd1737
-
cd1737
-
cd1737
-struct m_pedit_util p_pedit_ip6 = {
cd1737
-	NULL,
cd1737
-	"ip6",
cd1737
-	parse_ip6,
cd1737
-};
cd1737
diff --git a/tc/p_ip6.c b/tc/p_ip6.c
cd1737
new file mode 100644
cd1737
index 0000000..a4824bd
cd1737
--- /dev/null
cd1737
+++ b/tc/p_ip6.c
cd1737
@@ -0,0 +1,91 @@
cd1737
+/*
cd1737
+ * p_ip6.c		packet editor: IPV6 header
cd1737
+ *
cd1737
+ *		This program is free software; you can distribute it and/or
cd1737
+ *		modify it under the terms of the GNU General Public License
cd1737
+ *		as published by the Free Software Foundation; either version
cd1737
+ *		2 of the License, or (at your option) any later version.
cd1737
+ *
cd1737
+ * Authors:  Amir Vadai <amir@vadai.me>
cd1737
+ *
cd1737
+ */
cd1737
+
cd1737
+#include <stdio.h>
cd1737
+#include <stdlib.h>
cd1737
+#include <unistd.h>
cd1737
+#include <syslog.h>
cd1737
+#include <fcntl.h>
cd1737
+#include <sys/socket.h>
cd1737
+#include <netinet/in.h>
cd1737
+#include <arpa/inet.h>
cd1737
+#include <string.h>
cd1737
+#include "utils.h"
cd1737
+#include "tc_util.h"
cd1737
+#include "m_pedit.h"
cd1737
+
cd1737
+static int
cd1737
+parse_ip6(int *argc_p, char ***argv_p,
cd1737
+	  struct m_pedit_sel *sel, struct m_pedit_key *tkey)
cd1737
+{
cd1737
+	int res = -1;
cd1737
+	int argc = *argc_p;
cd1737
+	char **argv = *argv_p;
cd1737
+
cd1737
+	if (argc < 2)
cd1737
+		return -1;
cd1737
+
cd1737
+	if (!sel->extended)
cd1737
+		return -1;
cd1737
+
cd1737
+	tkey->htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6;
cd1737
+
cd1737
+	if (strcmp(*argv, "src") == 0) {
cd1737
+		NEXT_ARG();
cd1737
+		tkey->off = 8;
cd1737
+		res = parse_cmd(&argc, &argv, 16, TIPV6, RU32, sel, tkey);
cd1737
+		goto done;
cd1737
+	}
cd1737
+	if (strcmp(*argv, "dst") == 0) {
cd1737
+		NEXT_ARG();
cd1737
+		tkey->off = 24;
cd1737
+		res = parse_cmd(&argc, &argv, 16, TIPV6, RU32, sel, tkey);
cd1737
+		goto done;
cd1737
+	}
cd1737
+	if (strcmp(*argv, "flow_lbl") == 0) {
cd1737
+		NEXT_ARG();
cd1737
+		tkey->off = 0;
cd1737
+		res = parse_cmd(&argc, &argv, 4, TU32, 0x0007ffff, sel, tkey);
cd1737
+		goto done;
cd1737
+	}
cd1737
+	if (strcmp(*argv, "payload_len") == 0) {
cd1737
+		NEXT_ARG();
cd1737
+		tkey->off = 4;
cd1737
+		res = parse_cmd(&argc, &argv, 2, TU32, RU16, sel, tkey);
cd1737
+		goto done;
cd1737
+	}
cd1737
+	if (strcmp(*argv, "nexthdr") == 0) {
cd1737
+		NEXT_ARG();
cd1737
+		tkey->off = 6;
cd1737
+		res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
cd1737
+		goto done;
cd1737
+	}
cd1737
+	if (strcmp(*argv, "hoplimit") == 0) {
cd1737
+		NEXT_ARG();
cd1737
+		tkey->off = 7;
cd1737
+		res = parse_cmd(&argc, &argv, 1, TU32, RU8, sel, tkey);
cd1737
+		goto done;
cd1737
+	}
cd1737
+
cd1737
+	return -1;
cd1737
+
cd1737
+done:
cd1737
+	*argc_p = argc;
cd1737
+	*argv_p = argv;
cd1737
+	return res;
cd1737
+}
cd1737
+
cd1737
+struct m_pedit_util p_pedit_ip6 = {
cd1737
+	NULL,
cd1737
+	"ipv6",
cd1737
+	parse_ip6,
cd1737
+};
cd1737
-- 
cd1737
1.8.3.1
cd1737