From 44fbbf60906264270ce1621ab15569162934a020 Mon Sep 17 00:00:00 2001 From: Dirk Koopman Date: Fri, 20 Jan 2023 09:56:51 +0000 Subject: [PATCH] Allow synonyms for localhost This allows all internal addresses to be identified and then masked as one IPV4 and one IPV6 external address. --- Changes | 18 ++++++++++++++++++ cmd/dx.pl | 4 +--- perl/DXCommandmode.pm | 22 ++++++++++++++++++---- perl/cluster.pl | 2 ++ 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/Changes b/Changes index f9f83e6b..ce05214a 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,21 @@ +20Jan23======================================================================= +1. Add the variable @main::localhost_names to allow other IP addresses to + be treated in the same way as localhost in item 1 on 19Jan23 below. NOTE + you must include ALL the normal localhost names + any other interface + names that you might want to include: + + set/var @main::localhost_names qw(127.0.0.1 ::1 192.168.1.30) + + using the qw() construction is easier than: + + set/var @main::localhost_names ('127.0.0.1', '::1', '192.168.1.30') + + but either will work. You can define as many IP addresses as you like and + they can be IPV4 or 6. + + You do NOT need to fiddle with this unless you specifically have more + than just the normal definitions of localhost. So for 'normal' nodes with + one external interface, you DO NOT NEED TO DO ANY OF THIS. 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: diff --git a/cmd/dx.pl b/cmd/dx.pl index 956dc4c1..d1e27883 100644 --- a/cmd/dx.pl +++ b/cmd/dx.pl @@ -24,9 +24,7 @@ return (1, $self->msg('e5')) if $self->remotecmd || $self->inscript; 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; +my $addr = DXCommandmode::alias_localhost($self->hostname || '127.0.0.1'); Log('cmd', "$self->{call}|$addr|dx|$line"); diff --git a/perl/DXCommandmode.pm b/perl/DXCommandmode.pm index 32263997..ffad39cf 100644 --- a/perl/DXCommandmode.pm +++ b/perl/DXCommandmode.pm @@ -49,7 +49,8 @@ use DXCIDR; use strict; use vars qw(%Cache %cmd_cache $errstr %aliases $scriptbase %nothereslug - $maxbadcount $msgpolltime $default_pagelth $cmdimportdir $users $maxusers); + $maxbadcount $msgpolltime $default_pagelth $cmdimportdir $users $maxusers +); %Cache = (); # cache of dynamically loaded routine's mod times %cmd_cache = (); # cache of short names @@ -75,9 +76,7 @@ sub new my $pkg = shift; my $call = shift; # 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; + my $ipaddr = alias_localhost($self->hostname); DXProt::_add_thingy($main::routeroot, [$call, 0, 0, 1, undef, undef, $ipaddr], ); # ALWAYS output the user @@ -1441,5 +1440,20 @@ sub user_count return ($users, $maxusers); } +# alias localhost if required. This is designed to repress all localhost and other +# internal interfaces to a fixed (outside) IPv4 or IPV6 address +sub alias_localhost +{ + my $hostname = shift; + if ($hostname =~ /./) { + return $hostname unless $main::localhost_alias_ipv4; + return (grep $hostname eq $_, @main::localhost_names) ? $main::localhost_alias_ipv4 : $hostname; + } elsif ($hostname =~ /:/) { + return $hostname unless $main::localhost_alias_ipv6; + return (grep $hostname eq $_, @main::localhost_names) ? $main::localhost_alias_ipv6 : $hostname; + } + return $hostname; +} + 1; __END__ diff --git a/perl/cluster.pl b/perl/cluster.pl index 5d26be28..900d57a8 100755 --- a/perl/cluster.pl +++ b/perl/cluster.pl @@ -218,6 +218,8 @@ 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_names = qw(127.0.0.1 ::1); # all ip addresses that will need to be aliased below (ipv4 or ipv6) + 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 -- 2.34.1