From 39f9822cb4aa0f69926a00ae19e855166dc2e00e Mon Sep 17 00:00:00 2001 From: Robert James Hernandez Date: Sun, 1 Dec 2024 16:54:10 +0000 Subject: [PATCH 1/9] packages.perlNetArp: init at 1.0.12 Required perl lib for running switch-configurations/config/scripts/switch_config_loader --- nix/packages/default.nix | 1 + nix/packages/perl-net-arp/package.nix | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 nix/packages/perl-net-arp/package.nix diff --git a/nix/packages/default.nix b/nix/packages/default.nix index 68f83b55..21c84c47 100644 --- a/nix/packages/default.nix +++ b/nix/packages/default.nix @@ -9,5 +9,6 @@ inputs.nixpkgs.lib.genAttrs massflash scaleInventory serverspec + perlNetArp ; }) diff --git a/nix/packages/perl-net-arp/package.nix b/nix/packages/perl-net-arp/package.nix new file mode 100644 index 00000000..8d9506a2 --- /dev/null +++ b/nix/packages/perl-net-arp/package.nix @@ -0,0 +1,13 @@ +{ + perlPackages, + fetchurl, +}: + +perlPackages.buildPerlPackage { + pname = "NetArp"; + version = "1.0.12"; + src = fetchurl { + url = "mirror://cpan/authors/id/C/CR/CRAZYDJ/Net-ARP-1.0.12.tar.gz"; + hash = "sha256-KK2GBaOh4PhoqYmIJvVGHYCSPm66GtXgRzfmDoug7HA="; + }; +} From 4fbc75824a52f8adb46af3c511f0df65c46712fd Mon Sep 17 00:00:00 2001 From: Robert James Hernandez Date: Sun, 1 Dec 2024 17:01:42 +0000 Subject: [PATCH 2/9] packages.perlNetInterface: init at 1.015 Required lib for switch-configuration/config/scripts/switch_config_loader --- nix/packages/default.nix | 1 + nix/packages/perl-net-interface/package.nix | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 nix/packages/perl-net-interface/package.nix diff --git a/nix/packages/default.nix b/nix/packages/default.nix index 21c84c47..0781f74a 100644 --- a/nix/packages/default.nix +++ b/nix/packages/default.nix @@ -10,5 +10,6 @@ inputs.nixpkgs.lib.genAttrs scaleInventory serverspec perlNetArp + perlNetInterface ; }) diff --git a/nix/packages/perl-net-interface/package.nix b/nix/packages/perl-net-interface/package.nix new file mode 100644 index 00000000..ef9a457c --- /dev/null +++ b/nix/packages/perl-net-interface/package.nix @@ -0,0 +1,16 @@ +{ + perlPackages, + fetchurl, + linuxHeaders, +}: + +perlPackages.buildPerlPackage { + pname = "NetInterface"; + version = "1.015"; + buildInputs = [ linuxHeaders ]; + doCheck = false; + src = fetchurl { + url = "mirror://cpan/authors/id/M/MI/MIKER/Net-Interface-1.015.tar.gz"; + hash = "sha256-x6MFjTGh73k+eAtqTJCQEI/SxMNFeQ774AeFKgIvf4E="; + }; +} From d2a6b69681de03d39709d2479b0c7de991e77a48 Mon Sep 17 00:00:00 2001 From: Robert James Hernandez Date: Sun, 1 Dec 2024 17:11:08 +0000 Subject: [PATCH 3/9] devShells.networkSub: include perl deps Include all of the perl libs required for running switch-configuration/config/scripts/switch_config_loader in the devShell. --- nix/dev-shells/default.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nix/dev-shells/default.nix b/nix/dev-shells/default.nix index 73e04d7b..de2035c2 100644 --- a/nix/dev-shells/default.nix +++ b/nix/dev-shells/default.nix @@ -48,6 +48,12 @@ inputs.nixpkgs.lib.genAttrs networkSub = with pkgs; [ perl + perlPackages.libnet + perlPackages.Expect + perlPackages.TermReadKey + perlPackages.NetSFTPForeign + scale-network.perlNetArp + scale-network.perlNetInterface ghostscript ]; in From 993aa2c289bcc9398b8fc441977a17c848d4cf79 Mon Sep 17 00:00:00 2001 From: Robert James Hernandez Date: Sun, 1 Dec 2024 17:15:58 +0000 Subject: [PATCH 4/9] packages.perlNetInterface: bumping to 1.016 Latest version of perlNetInterface and includes the necessary workaround for the build failure with newer linux kernels: https://rt.cpan.org/Public/Bug/Display.html?id=124582 --- nix/packages/perl-net-interface/package.nix | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/nix/packages/perl-net-interface/package.nix b/nix/packages/perl-net-interface/package.nix index ef9a457c..af440c41 100644 --- a/nix/packages/perl-net-interface/package.nix +++ b/nix/packages/perl-net-interface/package.nix @@ -6,11 +6,11 @@ perlPackages.buildPerlPackage { pname = "NetInterface"; - version = "1.015"; + version = "1.016"; buildInputs = [ linuxHeaders ]; doCheck = false; src = fetchurl { - url = "mirror://cpan/authors/id/M/MI/MIKER/Net-Interface-1.015.tar.gz"; - hash = "sha256-x6MFjTGh73k+eAtqTJCQEI/SxMNFeQ774AeFKgIvf4E="; + url = "mirror://cpan/authors/id/M/MI/MIKER/Net-Interface-1.016.tar.gz"; + hash = "sha256-e+RGk14BPQ7dPTcfkvuQo7s4q+mVYoidgXiVMSnlNQg="; }; } From 6adb4e310f12b950d7f6218f9fe22a582b1108e4 Mon Sep 17 00:00:00 2001 From: Robert James Hernandez Date: Sun, 1 Dec 2024 17:31:15 +0000 Subject: [PATCH 5/9] packages.perlNetInterface: include which in buildInputs Without `which` the resulting error happens at build time: ... checking for LOCAL_SIZEOF_SOCKADDR_OSITP... not defined configure: creating ./config.status config.status: creating config.h Can't exec "which": No such file or directory at inst/netsymbols.pl line 55 (#1) (W exec) A system(), exec(), or piped open call could not execute the named program for the indicated reason. Typical reasons include: the permissions were wrong on the file, the file wasn't found in $ENV{PATH}, the executable in question was compiled for another architecture, or the #! line in a script points to an interpreter that can't be run for similar reasons. (Or maybe your system doesn't support #! at all.) Use of uninitialized value $grep in pattern match (m//) at inst/netsymbols.pl line 56 (#1) (W uninitialized) An undefined value was used as if it were already defined. It was interpreted as a "" or a 0, but maybe it was a mistake. To suppress this warning assign a defined value to your variables. To help you figure out what was undefined, perl will try to tell you the name of the variable (if any) that was undefined. In some cases it cannot do this, so it also tells you what operation you used the undefined value in. Note, however, that perl optimizes your program and the operation displayed in the warning may not necessarily appear literally in your program. For example, "that $foo" is usually optimized into "that " . $foo, and the warning will refer to the concatenation (.) operator, even though there is no . in your program. Use of uninitialized value $grep in concatenation (.) or string at inst/netsymbols.pl line 60 (#1) sh: illegal option -r sh: illegal option -r sh: illegal option -r Uncaught exception from user code: AF_INET not found in netsymbolsC.inc, prerequisite development library header files missing from /usr/include/sys --- nix/packages/perl-net-interface/package.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nix/packages/perl-net-interface/package.nix b/nix/packages/perl-net-interface/package.nix index af440c41..2f73336d 100644 --- a/nix/packages/perl-net-interface/package.nix +++ b/nix/packages/perl-net-interface/package.nix @@ -2,12 +2,13 @@ perlPackages, fetchurl, linuxHeaders, + which }: perlPackages.buildPerlPackage { pname = "NetInterface"; version = "1.016"; - buildInputs = [ linuxHeaders ]; + buildInputs = [ linuxHeaders which ]; doCheck = false; src = fetchurl { url = "mirror://cpan/authors/id/M/MI/MIKER/Net-Interface-1.016.tar.gz"; From 0290733bb867a728e4f9c589258c9208e350fae9 Mon Sep 17 00:00:00 2001 From: Robert James Hernandez Date: Sun, 1 Dec 2024 17:50:06 +0000 Subject: [PATCH 6/9] trying to refer to headers during build --- nix/packages/perl-net-interface/package.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/nix/packages/perl-net-interface/package.nix b/nix/packages/perl-net-interface/package.nix index 2f73336d..382615de 100644 --- a/nix/packages/perl-net-interface/package.nix +++ b/nix/packages/perl-net-interface/package.nix @@ -10,6 +10,18 @@ perlPackages.buildPerlPackage { version = "1.016"; buildInputs = [ linuxHeaders which ]; doCheck = false; + + CPPFLAGS="-Iusr/include"; + + postPatch = '' + mkdir -p usr/include/sys/ + cp -pr ${linuxHeaders}/include usr/ + ln -s ${linuxHeaders}/include/linux/socket.h usr/include/sys/socket.h + ls -lahR usr/ + echo "aaaaaaaa" + echo $CPPFLAGS + ''; + src = fetchurl { url = "mirror://cpan/authors/id/M/MI/MIKER/Net-Interface-1.016.tar.gz"; hash = "sha256-e+RGk14BPQ7dPTcfkvuQo7s4q+mVYoidgXiVMSnlNQg="; From 2b9569c18903833b0ae4c32aaf8f34e2b7d84794 Mon Sep 17 00:00:00 2001 From: Robert James Hernandez Date: Sun, 1 Dec 2024 19:51:22 +0000 Subject: [PATCH 7/9] packages.perlNetPing: overrideAttrs for CAP_NET_RAW patch Creating our own NetPing package to incorporate an existing patch (thanks Owen) that has yet to land upstream. --- nix/packages/default.nix | 1 + .../linux-isroot-capability.patch | 48 +++++++++++++++++++ nix/packages/perl-net-ping/package.nix | 9 ++++ 3 files changed, 58 insertions(+) create mode 100644 nix/packages/perl-net-ping/linux-isroot-capability.patch create mode 100644 nix/packages/perl-net-ping/package.nix diff --git a/nix/packages/default.nix b/nix/packages/default.nix index 0781f74a..666c3f36 100644 --- a/nix/packages/default.nix +++ b/nix/packages/default.nix @@ -11,5 +11,6 @@ inputs.nixpkgs.lib.genAttrs serverspec perlNetArp perlNetInterface + perlNetPing ; }) diff --git a/nix/packages/perl-net-ping/linux-isroot-capability.patch b/nix/packages/perl-net-ping/linux-isroot-capability.patch new file mode 100644 index 00000000..f100dd3f --- /dev/null +++ b/nix/packages/perl-net-ping/linux-isroot-capability.patch @@ -0,0 +1,48 @@ +diff --git a/lib/Net/Ping.pm b/lib/Net/Ping.pm +index 0b7be8c..60aca57 100644 +--- a/lib/Net/Ping.pm ++++ b/lib/Net/Ping.pm +@@ -227,13 +227,21 @@ sub new + } + elsif ($self->{proto} eq "icmp") + { +- croak("icmp ping requires root privilege") if !_isroot(); ++ croak("icmp ping requires root privilege") if !_isroot() && ($^O ne "linux"); + $self->{proto_num} = eval { (getprotobyname('icmp'))[2] } || + croak("Can't get icmp protocol by name"); + $self->{pid} = $$ & 0xffff; # Save lower 16 bits of pid + $self->{fh} = FileHandle->new(); +- socket($self->{fh}, PF_INET, SOCK_RAW, $self->{proto_num}) || +- croak("icmp socket error - $!"); ++ if ($^O eq "linux") ++ { ++ socket($self->{fh}, PF_INET, SOCK_DGRAM, $self->{proto_num}) || ++ croak("icmp socket error - $!"); ++ } ++ else ++ { ++ socket($self->{fh}, PF_INET, SOCK_RAW, $self->{proto_num}) || ++ croak("icmp socket error - $!"); ++ } + $self->_setopts(); + if ($self->{'ttl'}) { + setsockopt($self->{fh}, IPPROTO_IP, IP_TTL, pack("I*", $self->{'ttl'})) +@@ -250,8 +258,16 @@ sub new + croak("Can't get ipv6-icmp protocol by name"); # 58 + $self->{pid} = $$ & 0xffff; # Save lower 16 bits of pid + $self->{fh} = FileHandle->new(); +- socket($self->{fh}, $AF_INET6, SOCK_RAW, $self->{proto_num}) || +- croak("icmp socket error - $!"); ++ if ($^O eq "linux") ++ { ++ socket($self->{fh}, $AF_INET6, SOCK_DGRAM, $self->{proto_num}) || ++ croak("icmp socket error - $!"); ++ } ++ else ++ { ++ socket($self->{fh}, $AF_INET6, SOCK_RAW, $self->{proto_num}) || ++ croak("icmp socket error - $!"); ++ } + $self->_setopts(); + if ($self->{'gateway'}) { + my $g = $self->{gateway}; diff --git a/nix/packages/perl-net-ping/package.nix b/nix/packages/perl-net-ping/package.nix new file mode 100644 index 00000000..0b2a7dd9 --- /dev/null +++ b/nix/packages/perl-net-ping/package.nix @@ -0,0 +1,9 @@ +{ + perlPackages, +}: + +perlPackages.NetPing.overrideAttrs { + # Owen's patch for _isroot should consider CAP_NET_RAW capability on Linux + # related to: https://rt.cpan.org/Public/Bug/Display.html?id=139820 + patches = [ ./linux-isroot-capability.patch ]; +} From bfc6d195476c624681b6134f6f926575219485dc Mon Sep 17 00:00:00 2001 From: Robert James Hernandez Date: Sun, 1 Dec 2024 20:17:39 +0000 Subject: [PATCH 8/9] devShell.networkSub: include packages.perlNetPing This is required for a subset of functionality in Loader.pm for switch-configurations. --- nix/dev-shells/default.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nix/dev-shells/default.nix b/nix/dev-shells/default.nix index de2035c2..88c0b483 100644 --- a/nix/dev-shells/default.nix +++ b/nix/dev-shells/default.nix @@ -54,6 +54,7 @@ inputs.nixpkgs.lib.genAttrs perlPackages.NetSFTPForeign scale-network.perlNetArp scale-network.perlNetInterface + scale-network.perlNetPing ghostscript ]; in From 3179981d34834933f1886d1f04a8d50e7698b732 Mon Sep 17 00:00:00 2001 From: Daniel Baker Date: Tue, 3 Dec 2024 21:01:42 -0800 Subject: [PATCH 9/9] packages.perlNetInterface: patch grepping for library headers The make file has a check to grep for the AF_INET symbol in /usr/include/sys. Patching this out so that it builds. Not certain if this will cause runtime failures. --- .../net-interface-remove-grep-af-inet.patch | 16 +++++++++++++++ nix/packages/perl-net-interface/package.nix | 20 ++++--------------- 2 files changed, 20 insertions(+), 16 deletions(-) create mode 100644 nix/packages/perl-net-interface/net-interface-remove-grep-af-inet.patch diff --git a/nix/packages/perl-net-interface/net-interface-remove-grep-af-inet.patch b/nix/packages/perl-net-interface/net-interface-remove-grep-af-inet.patch new file mode 100644 index 00000000..eb742ded --- /dev/null +++ b/nix/packages/perl-net-interface/net-interface-remove-grep-af-inet.patch @@ -0,0 +1,16 @@ +diff --git a/Makefile.PL b/Makefile.PL +index 973e65e..6ad0d51 100644 +--- a/Makefile.PL ++++ b/Makefile.PL +@@ -176,11 +176,6 @@ unless (open(F,'./netsymbolC.inc')) { + exit; + } + +-unless (scalar grep {/# define\s+_NI_AF_INET/} ()) { +- close F; +- die "AF_INET not found in netsymbolsC.inc,\nprerequisite development library header files missing from /usr/include/sys\n"; +- exit 0; +-} + close F; + + WriteMakefile(%makeparms); diff --git a/nix/packages/perl-net-interface/package.nix b/nix/packages/perl-net-interface/package.nix index 382615de..eaf3d27a 100644 --- a/nix/packages/perl-net-interface/package.nix +++ b/nix/packages/perl-net-interface/package.nix @@ -1,29 +1,17 @@ { perlPackages, fetchurl, - linuxHeaders, - which }: - perlPackages.buildPerlPackage { pname = "NetInterface"; version = "1.016"; - buildInputs = [ linuxHeaders which ]; - doCheck = false; - - CPPFLAGS="-Iusr/include"; - - postPatch = '' - mkdir -p usr/include/sys/ - cp -pr ${linuxHeaders}/include usr/ - ln -s ${linuxHeaders}/include/linux/socket.h usr/include/sys/socket.h - ls -lahR usr/ - echo "aaaaaaaa" - echo $CPPFLAGS - ''; src = fetchurl { url = "mirror://cpan/authors/id/M/MI/MIKER/Net-Interface-1.016.tar.gz"; hash = "sha256-e+RGk14BPQ7dPTcfkvuQo7s4q+mVYoidgXiVMSnlNQg="; }; + + patches = [ ./net-interface-remove-grep-af-inet.patch ]; + + doCheck = false; }