summaryrefslogtreecommitdiff
path: root/overlays
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2023-03-10 22:24:40 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2023-03-10 22:24:40 +0100
commitc2fbcde4449ffaf798f9ba4f742b942d33a1c1c8 (patch)
tree71822737cbc6d60d1949a4b07a93dcaaff415bb0 /overlays
parente275caddb607b8ff37569be66f1bf44303919502 (diff)
downloadnixos-c2fbcde4449ffaf798f9ba4f742b942d33a1c1c8.tar
nixos-c2fbcde4449ffaf798f9ba4f742b942d33a1c1c8.tar.gz
nixos-c2fbcde4449ffaf798f9ba4f742b942d33a1c1c8.tar.bz2
nixos-c2fbcde4449ffaf798f9ba4f742b942d33a1c1c8.tar.xz
nixos-c2fbcde4449ffaf798f9ba4f742b942d33a1c1c8.zip
libdscp
Diffstat (limited to 'overlays')
-rw-r--r--overlays/libdscp/default.nix11
-rw-r--r--overlays/libdscp/src/Makefile16
-rw-r--r--overlays/libdscp/src/libdscp.c38
3 files changed, 65 insertions, 0 deletions
diff --git a/overlays/libdscp/default.nix b/overlays/libdscp/default.nix
new file mode 100644
index 00000000..47103fd3
--- /dev/null
+++ b/overlays/libdscp/default.nix
@@ -0,0 +1,11 @@
1{ final, prev, ... }:
2{
3 libdscp = prev.stdenv.mkDerivation {
4 pname = "libdscp";
5 version = "0.0.0";
6
7 src = ./src;
8
9 makeFlags = [ "PREFIX=$(out)" ];
10 };
11}
diff --git a/overlays/libdscp/src/Makefile b/overlays/libdscp/src/Makefile
new file mode 100644
index 00000000..e76930d7
--- /dev/null
+++ b/overlays/libdscp/src/Makefile
@@ -0,0 +1,16 @@
1ifeq ($(PREFIX),)
2 PREFIX := /usr/local
3endif
4
5.PHONY: all install
6
7all: libdscp
8
9libdscp:
10 $(CC) \
11 -o $@.so $@.c \
12 -D_GNU_SOURCE \
13 -nostartfiles -shared
14install: libdscp
15 install -d $(DESTDIR)$(PREFIX)/lib/
16 install -m 644 libdscp.so $(DESTDIR)$(PREFIX)/lib/
diff --git a/overlays/libdscp/src/libdscp.c b/overlays/libdscp/src/libdscp.c
new file mode 100644
index 00000000..1bc9a16d
--- /dev/null
+++ b/overlays/libdscp/src/libdscp.c
@@ -0,0 +1,38 @@
1#include <dlfcn.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <errno.h>
5#include <arpa/inet.h>
6
7void _init(void);
8int (*sys_connect)(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
9int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
10
11int dscp_val = 0;
12
13void _init(void) {
14 const char* err;
15
16 char* env_dscp;
17
18 env_dscp = getenv("DSCP");
19
20 if (env_dscp)
21 dscp_val = atoi(env_dscp) << 2;
22
23 sys_connect = dlsym(RTLD_NEXT, "connect");
24
25 err = dlerror();
26 if (err != NULL)
27 (void)fprintf(stderr, "libdscp:dlsym (connect): %s\n", err);
28}
29
30int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) {
31 int oerrno = errno;
32
33 setsockopt(sockfd, IPPROTO_IP, IP_TOS, &dscp_val, sizeof dscp_val);
34 setsockopt(sockfd, IPPROTO_IPV6, IPV6_TCLASS, &dscp_val, sizeof dscp_val);
35
36 errno = oerrno;
37 return sys_connect(sockfd, addr, addrlen);
38}