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