Allow synonyms for localhost

This allows all internal addresses to be identified and then masked
as one IPV4 and one IPV6 external address.
This commit is contained in:
Dirk Koopman 2023-01-20 09:56:51 +00:00
parent f91073b993
commit 44fbbf6090
4 changed files with 39 additions and 7 deletions

18
Changes
View File

@ -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:

View File

@ -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");

View File

@ -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__

View File

@ -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