From c967cd0b3b3869ddb2e882edd23ef27c6387e664 Mon Sep 17 00:00:00 2001 From: sinavir Date: Mon, 27 Jan 2025 14:40:44 +0100 Subject: [PATCH] feat: init small iproute2 --- pkgs/default.nix | 1 + pkgs/iproute2-small/default.nix | 103 +++++++++++++++++ .../120-no_arpd_ifstat_rtacct_lnstat.patch | 20 ++++ .../130-no_netem_tipc_dcb_man_vdpa.patch | 14 +++ .../patches/140-allow_pfifo_fast.patch | 9 ++ .../patches/160-libnetlink-pic.patch | 11 ++ pkgs/iproute2-small/patches/170-ip_tiny.patch | 108 ++++++++++++++++++ .../patches/175-reduce-dynamic-syms.patch | 45 ++++++++ .../patches/180-drop_FAILED_POLICY.patch | 41 +++++++ .../patches/190-fix-nls-rpath-link.patch | 20 ++++ .../patches/195-build_variant_ip_tc.patch | 22 ++++ 11 files changed, 394 insertions(+) create mode 100644 pkgs/iproute2-small/default.nix create mode 100644 pkgs/iproute2-small/patches/120-no_arpd_ifstat_rtacct_lnstat.patch create mode 100644 pkgs/iproute2-small/patches/130-no_netem_tipc_dcb_man_vdpa.patch create mode 100644 pkgs/iproute2-small/patches/140-allow_pfifo_fast.patch create mode 100644 pkgs/iproute2-small/patches/160-libnetlink-pic.patch create mode 100644 pkgs/iproute2-small/patches/170-ip_tiny.patch create mode 100644 pkgs/iproute2-small/patches/175-reduce-dynamic-syms.patch create mode 100644 pkgs/iproute2-small/patches/180-drop_FAILED_POLICY.patch create mode 100644 pkgs/iproute2-small/patches/190-fix-nls-rpath-link.patch create mode 100644 pkgs/iproute2-small/patches/195-build_variant_ip_tc.patch diff --git a/pkgs/default.nix b/pkgs/default.nix index 75ecb28..821244e 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -66,6 +66,7 @@ in { go-l2tp = callPackage ./go-l2tp {}; hi = callPackage ./hi {}; ifwait = callPackage ./ifwait {}; + iproute2-small = callPackage ./iproute2-small {}; initramfs-peek = callPackage ./initramfs-peek {}; kernel-backport = callPackage ./kernel-backport {}; kmodloader = callPackage ./kmodloader {}; diff --git a/pkgs/iproute2-small/default.nix b/pkgs/iproute2-small/default.nix new file mode 100644 index 0000000..94d9d24 --- /dev/null +++ b/pkgs/iproute2-small/default.nix @@ -0,0 +1,103 @@ +{ lib, stdenv, fetchurl +, buildPackages, bison, flex, pkg-config +, libelf, libnl-tiny +, gitUpdater, breakpointHook, libmnl, db +}: + +stdenv.mkDerivation rec { + pname = "iproute2"; + version = "6.7.0"; + + src = fetchurl { + url = "mirror://kernel/linux/utils/net/${pname}/${pname}-${version}.tar.xz"; + hash = "sha256-/5Qt2YKNfR+Gf2H+cs5DMHjDHl2OSnjiDwLLWJLohB0="; + }; + + patches = [ + ./patches/120-no_arpd_ifstat_rtacct_lnstat.patch + ./patches/130-no_netem_tipc_dcb_man_vdpa.patch + ./patches/140-allow_pfifo_fast.patch + ./patches/160-libnetlink-pic.patch + ./patches/170-ip_tiny.patch + ./patches/175-reduce-dynamic-syms.patch + ./patches/180-drop_FAILED_POLICY.patch + ./patches/190-fix-nls-rpath-link.patch + ./patches/195-build_variant_ip_tc.patch + ]; + + postPatch = '' + # Don't try to create /var/lib/arpd: + sed -e '/ARPDDIR/d' -i Makefile + + substituteInPlace Makefile \ + --replace "CC := gcc" "CC ?= $CC" + ''; + + hardeningDisable = [ "pie" ]; + + makeFlags = [ + "PREFIX=$(out)" + "SBINDIR=$(out)/sbin" + "DOCDIR=$(TMPDIR)/share/doc/${pname}" # Don't install docs + "HDRDIR=$(dev)/include/iproute2" + + "V=1" + + "BUILD_VARIANT=ip" + + "AR=${stdenv.cc.cc}/bin/${stdenv.cc.targetPrefix}gcc-ar" + ] ++ lib.optionals stdenv.hostPlatform.isStatic [ + "SHARED_LIBS=n" + # all build .so plugins: + "TC_CONFIG_NO_XT=y" + ] ++ lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [ + "HOSTCC=$(CC_FOR_BUILD)" + ]; + + preBuild = '' + export CFLAGS="-Os -funit-at-a-time -ffunction-sections -fdata-sections -flto=auto -fno-fat-lto-objects" + export LDFLAGS="-Wl,--gc-sections -flto=auto -fuse-linker-plugin" + ''; + + buildFlags = [ + "CONFDIR=/etc/iproute2" + ]; + + installFlags = [ + "CONFDIR=$(out)/etc/iproute2" + ]; + + postInstall = '' + rm -r $out/share + rm -r $out/lib + ''; + + depsBuildBuild = [ buildPackages.stdenv.cc ]; # netem requires $HOSTCC + nativeBuildInputs = [ bison flex pkg-config ]; + buildInputs = [ + # db + # libelf + # libnl-tiny + # libmnl + ]; + + enableParallelBuilding = true; + + stripAllList = [ + "bin" + ]; + + passthru.updateScript = gitUpdater { + # No nicer place to find latest release. + url = "https://git.kernel.org/pub/scm/network/iproute2/iproute2.git"; + rev-prefix = "v"; + }; + + meta = with lib; { + homepage = "https://wiki.linuxfoundation.org/networking/iproute2"; + description = "A collection of utilities for controlling TCP/IP networking and traffic control in Linux"; + platforms = platforms.linux; + license = licenses.gpl2; + maintainers = with maintainers; [ ]; + }; +} diff --git a/pkgs/iproute2-small/patches/120-no_arpd_ifstat_rtacct_lnstat.patch b/pkgs/iproute2-small/patches/120-no_arpd_ifstat_rtacct_lnstat.patch new file mode 100644 index 0000000..bb6a8d0 --- /dev/null +++ b/pkgs/iproute2-small/patches/120-no_arpd_ifstat_rtacct_lnstat.patch @@ -0,0 +1,20 @@ +--- a/misc/Makefile ++++ b/misc/Makefile +@@ -2,13 +2,13 @@ + SSOBJ=ss.o ssfilter_check.o ssfilter.tab.o + LNSTATOBJ=lnstat.o lnstat_util.o + +-TARGETS=ss nstat ifstat rtacct lnstat ++TARGETS=ss nstat + + include ../config.mk + +-ifeq ($(HAVE_BERKELEY_DB),y) +- TARGETS += arpd +-endif ++#ifeq ($(HAVE_BERKELEY_DB),y) ++# TARGETS += arpd ++#endif + + all: $(TARGETS) + diff --git a/pkgs/iproute2-small/patches/130-no_netem_tipc_dcb_man_vdpa.patch b/pkgs/iproute2-small/patches/130-no_netem_tipc_dcb_man_vdpa.patch new file mode 100644 index 0000000..8c70c14 --- /dev/null +++ b/pkgs/iproute2-small/patches/130-no_netem_tipc_dcb_man_vdpa.patch @@ -0,0 +1,14 @@ +--- a/Makefile ++++ b/Makefile +@@ -68,9 +68,9 @@ WFLAGS += -Wmissing-declarations -Wold-s + CFLAGS := $(WFLAGS) $(CCOPTS) -I../include -I../include/uapi $(DEFINES) $(CFLAGS) + YACCFLAGS = -d -t -v + +-SUBDIRS=lib ip tc bridge misc netem genl man ++SUBDIRS=lib ip tc bridge misc genl + ifeq ($(HAVE_MNL),y) +-SUBDIRS += tipc devlink rdma dcb vdpa ++SUBDIRS += devlink rdma + endif + + LIBNETLINK=../lib/libutil.a ../lib/libnetlink.a diff --git a/pkgs/iproute2-small/patches/140-allow_pfifo_fast.patch b/pkgs/iproute2-small/patches/140-allow_pfifo_fast.patch new file mode 100644 index 0000000..8f5a7d3 --- /dev/null +++ b/pkgs/iproute2-small/patches/140-allow_pfifo_fast.patch @@ -0,0 +1,9 @@ +--- a/tc/q_fifo.c ++++ b/tc/q_fifo.c +@@ -90,5 +90,6 @@ struct qdisc_util pfifo_head_drop_qdisc_ + + struct qdisc_util pfifo_fast_qdisc_util = { + .id = "pfifo_fast", ++ .parse_qopt = fifo_parse_opt, + .print_qopt = prio_print_opt, + }; diff --git a/pkgs/iproute2-small/patches/160-libnetlink-pic.patch b/pkgs/iproute2-small/patches/160-libnetlink-pic.patch new file mode 100644 index 0000000..145ec7a --- /dev/null +++ b/pkgs/iproute2-small/patches/160-libnetlink-pic.patch @@ -0,0 +1,11 @@ +--- a/lib/Makefile ++++ b/lib/Makefile +@@ -1,7 +1,7 @@ + # SPDX-License-Identifier: GPL-2.0 + include ../config.mk + +-CFLAGS += -fPIC ++CFLAGS += $(FPIC) + + UTILOBJ = utils.o utils_math.o rt_names.o ll_map.o ll_types.o ll_proto.o ll_addr.o \ + inet_proto.o namespace.o json_writer.o json_print.o json_print_math.o \ diff --git a/pkgs/iproute2-small/patches/170-ip_tiny.patch b/pkgs/iproute2-small/patches/170-ip_tiny.patch new file mode 100644 index 0000000..71081c3 --- /dev/null +++ b/pkgs/iproute2-small/patches/170-ip_tiny.patch @@ -0,0 +1,108 @@ +--- a/ip/Makefile ++++ b/ip/Makefile +@@ -19,6 +19,13 @@ RTMONOBJ=rtmon.o + + include ../config.mk + ++STATIC_SYM_FILTER:= ++ifeq ($(IP_CONFIG_TINY),y) ++ STATIC_SYM_FILTER:=iplink_can.c iplink_ipoib.c iplink_vxlan.c ++ CFLAGS += -DIPROUTE2_TINY ++endif ++STATIC_SYM_SOURCES:=$(filter-out $(STATIC_SYM_FILTER),$(wildcard *.c)) ++ + ALLOBJ=$(IPOBJ) $(RTMONOBJ) + SCRIPTS=routel + TARGETS=ip rtmon +@@ -48,7 +55,7 @@ else + + ip: static-syms.o + static-syms.o: static-syms.h +-static-syms.h: $(wildcard *.c) ++static-syms.h: $(STATIC_SYM_SOURCES) + files="$^" ; \ + for s in `grep -B 3 '\ $@ + ++else ++ ++tc: dynsyms.list ++m_xt.so: dynsyms.list ++dynsyms.list: $(wildcard *.c) ++ files="$(filter-out $(patsubst %.so,%.c,$(TCSO)), $^)" ; \ ++ echo "{" > $@ ; \ ++ for s in `grep -B 3 '\> $@ ; \ ++ echo "show_stats; print_nl; print_tm; parse_rtattr; parse_rtattr_flags; get_u32; matches; addattr_l; addattr_nest; addattr_nest_end; };" >> $@ ++ + endif diff --git a/pkgs/iproute2-small/patches/180-drop_FAILED_POLICY.patch b/pkgs/iproute2-small/patches/180-drop_FAILED_POLICY.patch new file mode 100644 index 0000000..9ce7dd9 --- /dev/null +++ b/pkgs/iproute2-small/patches/180-drop_FAILED_POLICY.patch @@ -0,0 +1,41 @@ +From 4e7dbf76227e8c7be7897dc81def3011f637864d Mon Sep 17 00:00:00 2001 +From: Jonas Gorski +Date: Thu, 30 May 2013 11:54:04 +0200 +Subject: [PATCH] add support for dropping with FAILED_POLICY + +--- + include/linux/fib_rules.h | 4 ++++ + include/linux/rtnetlink.h | 1 + + ip/rtm_map.c | 4 ++++ + 3 files changed, 9 insertions(+) + +--- a/ip/rtm_map.c ++++ b/ip/rtm_map.c +@@ -49,6 +49,8 @@ char *rtnl_rtntype_n2a(int id, char *buf + return "nat"; + case RTN_XRESOLVE: + return "xresolve"; ++ case RTN_FAILED_POLICY: ++ return "failed_policy"; + default: + snprintf(buf, len, "%d", id); + return buf; +@@ -84,6 +86,8 @@ int rtnl_rtntype_a2n(int *id, char *arg) + res = RTN_UNICAST; + else if (strcmp(arg, "throw") == 0) + res = RTN_THROW; ++ else if (strcmp(arg, "failed_policy") == 0) ++ res = RTN_FAILED_POLICY; + else { + res = strtoul(arg, &end, 0); + if (!end || end == arg || *end || res > 255) +--- a/include/uapi/linux/rtnetlink.h ++++ b/include/uapi/linux/rtnetlink.h +@@ -265,6 +265,7 @@ enum { + RTN_THROW, /* Not in this table */ + RTN_NAT, /* Translate this address */ + RTN_XRESOLVE, /* Use external resolver */ ++ RTN_FAILED_POLICY, /* Source address failed policy */ + __RTN_MAX + }; + diff --git a/pkgs/iproute2-small/patches/190-fix-nls-rpath-link.patch b/pkgs/iproute2-small/patches/190-fix-nls-rpath-link.patch new file mode 100644 index 0000000..765e4ad --- /dev/null +++ b/pkgs/iproute2-small/patches/190-fix-nls-rpath-link.patch @@ -0,0 +1,20 @@ +--- a/configure ++++ b/configure +@@ -270,7 +270,7 @@ int main(int argc, char **argv) { + } + EOF + +- $CC -o $TMPDIR/libbpf_test $TMPDIR/libbpf_test.c $LIBBPF_CFLAGS $LIBBPF_LDLIBS >/dev/null 2>&1 ++ $CC -o $TMPDIR/libbpf_test $TMPDIR/libbpf_test.c $LIBBPF_CFLAGS $LIBBPF_LDLIBS $LDFLAGS >/dev/null 2>&1 + local ret=$? + + rm -f $TMPDIR/libbpf_test.c $TMPDIR/libbpf_test +@@ -288,7 +288,7 @@ int main(int argc, char **argv) { + } + EOF + +- $CC -o $TMPDIR/libbpf_sec_test $TMPDIR/libbpf_sec_test.c $LIBBPF_CFLAGS $LIBBPF_LDLIBS >/dev/null 2>&1 ++ $CC -o $TMPDIR/libbpf_sec_test $TMPDIR/libbpf_sec_test.c $LIBBPF_CFLAGS $LIBBPF_LDLIBS $LDFLAGS >/dev/null 2>&1 + local ret=$? + + rm -f $TMPDIR/libbpf_sec_test.c $TMPDIR/libbpf_sec_test diff --git a/pkgs/iproute2-small/patches/195-build_variant_ip_tc.patch b/pkgs/iproute2-small/patches/195-build_variant_ip_tc.patch new file mode 100644 index 0000000..8156adb --- /dev/null +++ b/pkgs/iproute2-small/patches/195-build_variant_ip_tc.patch @@ -0,0 +1,22 @@ +--- a/ip/Makefile ++++ b/ip/Makefile +@@ -28,7 +28,7 @@ STATIC_SYM_SOURCES:=$(filter-out $(STATI + + ALLOBJ=$(IPOBJ) $(RTMONOBJ) + SCRIPTS=routel +-TARGETS=ip rtmon ++TARGETS=$(findstring ip,$(BUILD_VARIANT)) rtmon + + all: $(TARGETS) $(SCRIPTS) + +--- a/tc/Makefile ++++ b/tc/Makefile +@@ -132,7 +132,7 @@ MODDESTDIR := $(DESTDIR)$(LIBDIR)/tc + $(QUIET_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -shared -fpic $< -o $@ + + +-all: tc $(TCSO) ++all: $(findstring tc,$(BUILD_VARIANT)) $(TCSO) + + tc: $(TCOBJ) $(LIBNETLINK) libtc.a + $(QUIET_LINK)$(CC) $(filter-out dynsyms.list, $^) $(LDFLAGS) $(LDLIBS) -o $@