summaryrefslogtreecommitdiff
path: root/net/p5-Net-Libdnet6/patches/patch-_get_routes
blob: fff705272ec40012311b5d5c89da0b97a3569b26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
$NetBSD: patch-_get_routes,v 1.1 2017/10/11 07:34:51 wiz Exp $

fix netstat -r parsing
https://rt.cpan.org/Public/Bug/Display.html?id=114642

--- lib/Net/Libdnet6.pm.orig	2016-05-24 19:26:45.000000000 +0200
+++ lib/Net/Libdnet6.pm	2016-05-24 19:27:28.000000000 +0200
@@ -68,11 +68,11 @@
    }
 
    my $osname = {
-      linux   => [ \&_get_routes_linux, ],
-      freebsd => [ \&_get_routes_bsd,   ],
-      openbsd => [ \&_get_routes_bsd,   ],
-      netbsd  => [ \&_get_routes_bsd,   ],
-      darwin  => [ \&_get_routes_bsd,   ],
+      linux   => [ \&_get_routes_linux,   ],
+      freebsd => [ \&_get_routes_freebsd, ],
+      openbsd => [ \&_get_routes_netbsd,  ],
+      netbsd  => [ \&_get_routes_netbsd,  ],
+      darwin  => [ \&_get_routes_freebsd, ],
    };
 
    *_get_routes = $osname->{$^O}->[0] || \&_get_routes_other;
@@ -227,7 +227,7 @@
    return;
 }
 
-sub _get_routes_bsd {
+sub _get_routes_freebsd {
    return unless $_pathNetstat;
 
    my $buf = `$_pathNetstat -rnf inet6 2> /dev/null`;
@@ -294,6 +294,62 @@
    return;
 }
 
+sub _get_routes_netbsd {
+   return unless $_pathNetstat;
+
+   my $buf = `$_pathNetstat -rnf inet6 2> /dev/null`;
+   return unless $buf;
+
+   my @ifRoutes = ();
+   my %devIps;
+   my $lno;
+   for (split('\n', $buf)) {
+      $lno++; next unless $lno >= 5; # skip header
+      my @elts = split(/\s+/);
+
+      my $destination = $elts[0] || undef;
+      my $gateway = $elts[1] || undef;
+      my $flags = $elts[2] || undef;
+      my $if = $elts[6] || undef;
+
+      if (defined($destination)) {
+         $destination =~ s/%[a-z]+[0-9]+//;
+      }
+      if (defined($gateway)) {
+         $gateway =~ s/%[a-z]+[0-9]+//;
+      }
+
+      next if ! defined($destination);
+
+      if (Net::IPv6Addr::is_ipv6($destination)) {
+         my $route = {
+            destination => $destination,
+            interface   => $if,
+         };
+         if (Net::IPv6Addr::is_ipv6($gateway)) {
+            $route->{nextHop} = $gateway;
+         }
+         push @ifRoutes, $route;
+      }
+      elsif ($destination eq 'default') {
+         my $route = {
+            destination => $destination,
+            interface => $if,
+         };
+         if (Net::IPv6Addr::is_ipv6($gateway)) {
+            $route->{nextHop} = $gateway;
+         }
+         push @ifRoutes, $route;
+      }
+   }
+
+   if (@ifRoutes > 1) {
+      return \@ifRoutes;
+   }
+
+   return;
+}
+
 sub _is_in_network {
    my ($src, $net, $mask) = @_;
    my $net1 = addr_net6($src.'/'.$mask);