Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] - perl packages for devShell.networkSub to run switch_config_loader #804

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
7 changes: 7 additions & 0 deletions nix/dev-shells/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ inputs.nixpkgs.lib.genAttrs

networkSub = with pkgs; [
perl
perlPackages.libnet
perlPackages.Expect
perlPackages.TermReadKey
perlPackages.NetSFTPForeign
scale-network.perlNetArp
scale-network.perlNetInterface
scale-network.perlNetPing
ghostscript
];
in
Expand Down
3 changes: 3 additions & 0 deletions nix/packages/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ inputs.nixpkgs.lib.genAttrs
massflash
scaleInventory
serverspec
perlNetArp
perlNetInterface
perlNetPing
;
})
13 changes: 13 additions & 0 deletions nix/packages/perl-net-arp/package.nix
Original file line number Diff line number Diff line change
@@ -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=";
};
}
Original file line number Diff line number Diff line change
@@ -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/} (<F>)) {
- 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);
17 changes: 17 additions & 0 deletions nix/packages/perl-net-interface/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
perlPackages,
fetchurl,
}:
perlPackages.buildPerlPackage {
pname = "NetInterface";
version = "1.016";

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;
}
48 changes: 48 additions & 0 deletions nix/packages/perl-net-ping/linux-isroot-capability.patch
Original file line number Diff line number Diff line change
@@ -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};
9 changes: 9 additions & 0 deletions nix/packages/perl-net-ping/package.nix
Original file line number Diff line number Diff line change
@@ -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 ];
}
Loading