add localhost client aliasing on spots and PC92A
authorDirk Koopman <djk@tobit.co.uk>
Thu, 19 Jan 2023 23:36:46 +0000 (23:36 +0000)
committerDirk Koopman <djk@tobit.co.uk>
Thu, 19 Jan 2023 23:36:46 +0000 (23:36 +0000)
Changes
cmd/dx.pl
perl/DXChannel.pm
perl/DXCommandmode.pm
perl/Listeners.pm
perl/Msg.pm
perl/cluster.pl

diff --git a/Changes b/Changes
index 44fe04abba23ec6a248bbbd7399adc6cdab48cd1..f9f83e6bbd30f33e45f43802dc9026a4aad6bac0 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,3 +1,15 @@
+19Jan23=======================================================================
+1. Introduce aliasing for localhost in DX Spots and outgoing PC92 A records
+   on login. There are two variables which can be set with the alias to use:
+      $main::localhost_alias_ipv4
+      $main::localhost_alias_ipv6 
+   These can be set in the /spider/scripts/startup, but this is only 
+   necessary if the node has more than one interface, or virtual hosts. If 
+   there is ONLY ONE ipv4 and/or ipv6 IP address on the node machine then 
+   these variables will be automatically populated on first use. But the SAFE
+   thing to do is to set them in the startup file.  
+
+   THIS FEATURE IS EXPERIMENTAL... 
 18Jan23=======================================================================
 1. Make sure than *every* channel has an IP address. Thank you (I think) Kin 
    for pointing out that PC92 A records were not going out with IP addresses.
index e8e56dc1e596e91408cd50bab9e7544933a58fee..956dc4c17b6a2e2233bb63b09862871fb3b2421f 100644 (file)
--- a/cmd/dx.pl
+++ b/cmd/dx.pl
@@ -25,6 +25,9 @@ return (1, $self->msg('e28')) unless $self->isregistered;
 
 
 my $addr = $self->hostname || '127.0.0.1';
+$addr = $main::localhost_alias_ipv6 if $addr eq '::1' && $main::localhost_alias_ipv6;
+$addr = $main::localhost_alias_ipv4 if $addr =~ /^127\./ && $main::localhost_alias_ipv4;
+
 Log('cmd', "$self->{call}|$addr|dx|$line");
 
 my @bad;
index 56b96faa126d91d1b3256d7bba8944dfc453402b..84585ef1ee240f8d19ad10ba6d3468d386b26953 100644 (file)
@@ -185,7 +185,10 @@ sub alloc
        }
        $self->{inqueue} = [];
 
-       $self->{hostname} = $self->{conn}->peerhost if $conn;
+       if ($conn) {
+               $self->{hostname} = $self->{conn}->peerhost;
+               $self->{sockhost} = $self->{conn}->sockhost;
+       }
 
        $count++;
        dbg("DXChannel $self->{call} created ($count)") if isdbg('chan');
index 90812225dfe772c4bd8b2671f6ff3600bc70a521..3226399746a15385b4582544994e4c0f7b959ba9 100644 (file)
@@ -74,8 +74,11 @@ sub new
        # routing, this must go out here to prevent race condx
        my $pkg = shift;
        my $call = shift;
-#      my @rout = $main::routeroot->add_user($call, Route::here(1));
-       DXProt::_add_thingy($main::routeroot, [$call, 0, 0, 1, undef, undef, $self->hostname], );
+       #       my @rout = $main::routeroot->add_user($call, Route::here(1));
+       my $ipaddr = $self->hostname;
+       $ipaddr = $main::localhost_alias_ipv6 if $ipaddr eq '::1' && $main::localhost_alias_ipv6;
+       $ipaddr = $main::localhost_alias_ipv4 if $ipaddr =~ /^127\./ && $main::localhost_alias_ipv4;
+       DXProt::_add_thingy($main::routeroot, [$call, 0, 0, 1, undef, undef, $ipaddr], );
 
        # ALWAYS output the user
        my $ref = Route::User::get($call);
index 78209cc88ff60e861ca747f08a54d68d9f65cbda..a012fda37f582a36102ae386d49169198c292b03 100644 (file)
@@ -14,10 +14,16 @@ use vars qw(@listen);
 
 @listen = (
 # remove the '#' character from the next line to enable the listener!
-  #               ["0.0.0.0", 7300],
+  #               ["0.0.0.0", 7300],     # IPV4 only
+# ^
+# |
+#                 
+# OR (IF you listen on IPV6 as well) This one!!!!!
+  #               ["::", 7300],     # IPV4 and IPV6
 # ^
 # |
 # This one!!!!!
 );
+
+$
 1;
index 9a6f8d1f06894cd25d749afc9d2bac8019fd132d..c81273e29b329a5070b2bd53e34e7371564e3c68 100644 (file)
@@ -137,6 +137,24 @@ sub peerhost
        return $conn->{peerhost};
 }
 
+sub sockhost
+{
+       my $conn = shift;
+       unless ($conn->{sockhost}) {
+               $conn->{sockhost} ||= 'ax25' if $conn->ax25;
+               $conn->{sockhost} ||= $conn->{sock}->handle->sockhost if $conn->{sock};
+               $conn->{sockhost} ||= 'UNKNOWN';
+       }
+       $conn->{sockhost} =~ s/^::ffff://;
+       if (! defined $main::localhost_alias_ipv4 && $conn->{sockhost} =~ /\./ && $conn->{sockhost} !~ /^127\./) {
+               $main::localhost_alias_ipv4 = $conn->{sockhost};
+               dbg("Msg: localhost_alias_ipv4 = '$main::localhost_alias_ipv4'");
+       } elsif (! defined $main::localhost_alias_ipv6 && $conn->{sockhost} =~ /:/ && $conn->{sockhost} !~ /^::1$/) {
+               $main::localhost_alias_ipv6 = $conn->{sockhost};
+               dbg("Msg: localhost_alias_ipv6 = '$main::localhost_alias_ipv6'");
+       }
+       return $conn->{sockhost};
+}
 #-----------------------------------------------------------------
 # Send side routines
 
@@ -152,7 +170,8 @@ sub _on_connect
        $sock->timeout(0);
        $sock->start;
        $conn->{peerhost} = eval { $handle->peerhost; };
-       dbg((ref $conn) . " connected $conn->{cnum} to $conn->{peerhost}:$conn->{peerport}") if isdbg('conn') || isdbg ('connect');
+       $conn->{sockhost} = eval { $handle->sockhost; };
+       dbg((ref $conn) . " connected $conn->{cnum}:$conn->{sockhost} to $conn->{peerhost}:$conn->{peerport}") if isdbg('conn') || isdbg ('connect');
        if ($conn->{on_connect}) {
                &{$conn->{on_connect}}($conn, $handle);
        }
@@ -449,7 +468,7 @@ sub _rcv {                     # Complement to _send
        my $msg = shift;
     my $sock = $conn->{sock};
     return unless defined($sock);
-       return if $conn->{disconnecting};
+       return if $conn->{disonnecting};
 
        $total_in += length $msg;
        $conn->{datain} += length $msg;
@@ -493,9 +512,9 @@ sub new_client {
        $sock->timeout(0);
        $sock->start;
        $conn->{peerhost} = $handle->peerhost || 'unknown';
-       $conn->{peerhost} =~ s|^::ffff:||; # chop off leading pseudo IPV6 stuff on dual stack listeners
        $conn->{peerport} = $handle->peerport || 0;
-       dbg((ref $conn) . " accept $conn->{cnum} from $conn->{peerhost}:$conn->{peerport}") if isdbg('conn') || isdbg('connect');
+       $conn->{sockhost} = $handle->sockhost || '';
+       dbg((ref $conn) . " accept $conn->{cnum}:$conn->{sockhost} from $conn->{peerhost}:$conn->{peerport}") if isdbg('conn') || isdbg('connect');
        my ($rproc, $eproc) = &{$server_conn->{rproc}} ($conn, $conn->{peerhost}, $conn->{peerport});
        $conn->{sort} = 'Incoming';
        if ($eproc) {
index 177009ea20bb4a12cf63ed6d6e8aa994285c086c..5d26be28e0144f2db6033fc8976ab23a6c17b8d0 100755 (executable)
@@ -218,6 +218,10 @@ our $clssecs;                                      # the amount of cpu time the DXSpider process have consumed
 our $cldsecs;                                  # the amount of cpu time any child processes have consumed
 our $allowslashcall;                   # Allow / in connecting callsigns (ie PA0/G1TLH, or even PA0/G1TLH/2) 
 
+our $localhost_alias_ipv4;             # these are the IPV4 & 6 aliases for localhost connected clients
+our $localhost_alias_ipv6;             # for things (PC92, PC61 etc) that expose IP addresses. These *may*
+                                # be set by Msg.pm stuff if they are left undefined but, if you need
+                                # certanty then set/var them in the startup file.
 
 use vars qw($version $subversion $build $gitversion $gitbranch);
 
@@ -515,7 +519,6 @@ sub AGWrestart
        AGWMsg::init(\&new_channel);
 }
 
-
 sub setup_start
 {
        #############################################################