summaryrefslogtreecommitdiff
path: root/overlays/preserve-dscp
diff options
context:
space:
mode:
Diffstat (limited to 'overlays/preserve-dscp')
-rw-r--r--overlays/preserve-dscp/default.nix36
-rw-r--r--overlays/preserve-dscp/kern_env.patch24
-rw-r--r--overlays/preserve-dscp/kern_sec_classifier.patch22
3 files changed, 82 insertions, 0 deletions
diff --git a/overlays/preserve-dscp/default.nix b/overlays/preserve-dscp/default.nix
new file mode 100644
index 00000000..7f956a12
--- /dev/null
+++ b/overlays/preserve-dscp/default.nix
@@ -0,0 +1,36 @@
1{ final, prev, sources, ... }:
2{
3 preserve-dscp = prev.stdenv.mkDerivation rec {
4 pname = "preserve-dscp";
5 inherit (sources.bpf-examples) version src;
6
7 patches = [ ./kern_env.patch ./kern_sec_classifier.patch ];
8
9 makeFlags = [ "PREFIX=$(out)" ];
10 buildFlags = [ "preserve-dscp" ];
11
12 CPATH = prev.lib.makeSearchPathOutput "dev" "include" (buildInputs ++ nativeBuildInputs);
13 BPF_CFLAGS = "-Wno-unused-command-line-argument -fno-stack-protector";
14
15 outputs = [ "out" "lib" ];
16
17 buildInputs = with final; [ elfutils libpcap zlib ];
18 nativeBuildInputs = with final; [ llvmPackages.clang llvmPackages.llvm pkgconfig bpftool libmnl gnum4 glibc_multi makeWrapper ];
19
20 installPhase = ''
21 mkdir -p $lib/lib/bpf
22 install -t $lib/lib/bpf \
23 preserve-dscp/preserve_dscp_kern.o
24
25 mkdir -p $out/bin
26 install -m 555 -t $out/bin \
27 preserve-dscp/preserve-dscp
28 wrapProgram $out/bin/preserve-dscp \
29 --set-default PRESERVE_DSCP_KERN $lib/lib/bpf/preserve_dscp_kern.o
30 '';
31
32 dontFixup = true;
33
34 meta.mainProgram = "preserve-dscp";
35 };
36}
diff --git a/overlays/preserve-dscp/kern_env.patch b/overlays/preserve-dscp/kern_env.patch
new file mode 100644
index 00000000..7fe57b19
--- /dev/null
+++ b/overlays/preserve-dscp/kern_env.patch
@@ -0,0 +1,24 @@
1diff --git a/preserve-dscp/preserve-dscp.c b/preserve-dscp/preserve-dscp.c
2index 8c66186..5916fc5 100644
3--- a/preserve-dscp/preserve-dscp.c
4+++ b/preserve-dscp/preserve-dscp.c
5@@ -13,7 +13,7 @@
6
7 int main(int argc, char *argv[])
8 {
9- const char *filename = "preserve_dscp_kern.o";
10+ char *filename = 0;
11 char *ifname_pre, *ifname_post;
12 int ifindex_pre, ifindex_post;
13 struct bpf_map *map = NULL;
14@@ -26,6 +26,10 @@ int main(int argc, char *argv[])
15 DECLARE_LIBBPF_OPTS(bpf_tc_opts, attach_post);
16
17
18+ if (!(filename = getenv("PRESERVE_DSCP_KERN")))
19+ filename = "preserve_dscp_kern.o";
20+
21+
22 if (argc < 3) {
23 fprintf(stderr, "Usage: %s <if pre> <if post> [--unload]\n", argv[0]);
24 return 1;
diff --git a/overlays/preserve-dscp/kern_sec_classifier.patch b/overlays/preserve-dscp/kern_sec_classifier.patch
new file mode 100644
index 00000000..465b36f6
--- /dev/null
+++ b/overlays/preserve-dscp/kern_sec_classifier.patch
@@ -0,0 +1,22 @@
1diff --git a/preserve-dscp/preserve_dscp_kern.c b/preserve-dscp/preserve_dscp_kern.c
2index 24120cb..b070733 100644
3--- a/preserve-dscp/preserve_dscp_kern.c
4+++ b/preserve-dscp/preserve_dscp_kern.c
5@@ -91,7 +91,7 @@ static void set_dscp(struct __sk_buff *skb, __u8 dscp)
6 ipv6_change_dsfield(ipv6hdr, INET_ECN_MASK, dscp << 2);
7 }
8
9-SEC("classifier/read")
10+SEC("classifier")
11 int read_dscp(struct __sk_buff *skb)
12 {
13 __u32 key = bpf_get_hash_recalc(skb);
14@@ -106,7 +106,7 @@ int read_dscp(struct __sk_buff *skb)
15 return TC_ACT_OK;
16 }
17
18-SEC("classifier/write")
19+SEC("classifier")
20 int write_dscp(struct __sk_buff *skb)
21 {
22 __u32 key = skb->hash;