Skip to content

Commit

Permalink
fixed intends and verbose errors
Browse files Browse the repository at this point in the history
  • Loading branch information
acfnews committed Jan 23, 2012
1 parent 36a41f9 commit 9f987fd
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions rip44d
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ $Getopt::Std::STANDARD_HELP_VERSION = 1;

sub do_syslog($)
{
my($logtxt) = @_;
warn "$logtxt\n";
syslog("info", "%s", "$logtxt");
my($logtxt) = @_;
warn "$logtxt\n";
syslog("info", "%s", "$logtxt");
}

sub HELP_MESSAGE()
Expand Down Expand Up @@ -119,7 +119,7 @@ sub fill_local_ifs()
my $s = `$ifconfig -a`;

while ($s =~ s/inet addr:(\d+\.\d+\.\d+\.\d+)//) {
do_syslog("found local address: $1") if ( $verbose >= 1 );
do_syslog("found local address: $1") if ( $verbose >= 1 );
$my_addresses{$1} = 1;
}
}
Expand All @@ -141,7 +141,7 @@ sub mask2prefix($)
return -1 if ($bits !~ /^(1*)(0*)$/);

# The amount of 1's in the beginning is the prefix length.
do_syslog("subroutine mask2prefix " . length($1)) if ($verbose > 1);
do_syslog("subroutine mask2prefix " . length($1)) if ($verbose > 1);
return length($1);
}

Expand All @@ -159,7 +159,7 @@ sub route_delete($)
$out = `$cmd 2>&1`;
if ($?) {
if ($verbose > 1 || $out !~ /No such process/) {
do_syslog("route del failed: '$cmd': $out");
do_syslog("route del failed: '$cmd': $out");
}
}
}
Expand All @@ -168,15 +168,15 @@ sub route_delete($)

sub expire_routes()
{
do_syslog("expiring old routes") if ($verbose);
do_syslog("expiring old routes") if ($verbose);

my $exp_t = time() - $route_ttl;
my $now = time();

foreach my $rkey (keys %current_routes) {
if ($current_routes{$rkey}->{'t'} < $exp_t) {
# expire route
do_syslog("route $rkey has expired, deleting") if ($verbose);
do_syslog("route $rkey has expired, deleting") if ($verbose);
route_delete($rkey);
delete $current_routes{$rkey};
} elsif ($current_routes{$rkey}->{'t'} > $now) {
Expand All @@ -199,12 +199,12 @@ sub consider_route($$$$)
&& $current_routes{$rkey}->{'nh'} eq $nexthop
&& $current_routes{$rkey}->{'rtag'} eq $rtag) {
# ok, current route is fine
do_syslog("route $rkey is installed and current") if ($verbose > 1);
do_syslog("route $rkey is installed and current") if ($verbose > 1);
$current_routes{$rkey}->{'t'} = time();
return;
}

do_syslog("route $rkey updated: via $nexthop rtag $rtag") if ($verbose > 1);
do_syslog("route $rkey updated: via $nexthop rtag $rtag") if ($verbose > 1);

$current_routes{$rkey} = {
'nh' => $nexthop,
Expand All @@ -218,7 +218,7 @@ sub consider_route($$$$)
$cmd = "LANG=C $routebin route add $rkey via $nexthop dev $tunnel_if window $tcp_window onlink";
$out = `$cmd 2>&1\n`;
if ($?) {
do_syslog("route add failed: '$cmd': $out");
do_syslog("route add failed: '$cmd': $out");
}
}

Expand All @@ -230,26 +230,26 @@ sub process_rip_auth_entry($)

my $e_af = unpack('n', substr($entry, 0, 2));
if ($e_af != 0xFFFF) {
do_syslog("RIPv2 first message does not contain auth password: ignoring") if ($verbose);
do_syslog("RIPv2 first message does not contain auth password: ignoring") if ($verbose);
return 0;
}

my $e_type = unpack('n', substr($entry, 2, 2));
if ($e_type != RIP_AUTH_PASSWD) {
do_syslog("ignoring unsupported rip auth type $e_type") if ($verbose);
do_syslog("ignoring unsupported rip auth type $e_type") if ($verbose);
return 0;
}

my $e_passwd = substr($entry, 4, 16);
$e_passwd =~ s/\0*$//; # it's null-padded in the end

if (!defined $rip_passwd) {
do_syslog("RIPv2 packet contains password $e_passwd but we require none") if ($verbose);
do_syslog("RIPv2 packet contains password $e_passwd but we require none") if ($verbose);
return 0;
}

if ($e_passwd ne $rip_passwd) {
do_syslog("RIPv2 invalid password $e_passwd") if ($verbose);
do_syslog("RIPv2 invalid password $e_passwd") if ($verbose);
return 0;
}

Expand All @@ -266,37 +266,37 @@ sub validate_route($$$$$)
# netmask is correct and not too wide
my $prefix_len = mask2prefix($e_netmask);
if ($prefix_len < 0) {
do_syslog("invalid netmask: $e_netmask_s") if ($verbose);
do_syslog("invalid netmask: $e_netmask_s") if ($verbose);
return (0, 'invalid netmask');
}

if ($prefix_len < $minimum_prefix_len) {
do_syslog("$e_net_s/$e_netmask_s => $e_nexthop_s blocked, prefix too short") if ($verbose);
do_syslog("$e_net_s/$e_netmask_s => $e_nexthop_s blocked, prefix too short");
return (0, 'prefix length too short');
}

# the network-netmask pair makes sense: network & netmask == network
if (($e_net_i & $e_netmask) != $e_net_i) {
#print "e_net '$e_net_i' e_netmask '$e_netmask' ANDs to " . ($e_net_i & $e_netmask) . "\n";
do_syslog("$e_net_s/$e_netmask_s => $e_nexthop_s blocked, subnet-netmask pair does not make sense") if ($verbose);
do_syslog("$e_net_s/$e_netmask_s => $e_nexthop_s blocked, subnet-netmask pair does not make sense") if ($verbose);
return (0, 'invalid subnet-netmask pair');
}

# network is in 44/8
if ($e_net_s !~ /$net_44_regexp/) {
do_syslog("$e_net_s/$e_netmask_s => $e_nexthop_s blocked, non-amprnet address") if ($verbose);
do_syslog("$e_net_s/$e_netmask_s => $e_nexthop_s blocked, non-amprnet address") if ($verbose);
return (0, 'net not in 44/8');
}

# nexthop address is not in 44/8
if ($e_nexthop_s =~ /$net_44_regexp/) {
do_syslog("$e_net_s/$e_netmask_s => $e_nexthop_s blocked, nexthop is within amprnet") if ($verbose);
do_syslog("$e_net_s/$e_netmask_s => $e_nexthop_s blocked, nexthop is within amprnet") if ($verbose);
return (0, 'nexthop is in 44/8');
}

# nexthop address does not point to self
if (defined $my_addresses{$e_nexthop_s}) {
do_syslog("$e_net_s/$e_netmask_s => $e_nexthop_s blocked, local gw") if ($verbose);
do_syslog("$e_net_s/$e_netmask_s => $e_nexthop_s blocked, local gw") if ($verbose);
return (0, 'local gw');
}

Expand Down Expand Up @@ -456,7 +456,7 @@ my $next_expire = time() + $expire_interval;

# Main loop: receive broadcasts, check that they're from the correct
# address and port, and pass them on to processing
do_syslog("entering main loop, waiting for RIPv2 datagrams") if ( $verbose >= 0 );
do_syslog("entering main loop, waiting for RIPv2 datagrams") if ($verbose);
while (1) {
my $msg;
my $remote_address = recv($socket, $msg, 1500, 0);
Expand All @@ -469,14 +469,14 @@ while (1) {
my $addr_s = inet_ntoa($peer_addr);

if ($addr_s ne '44.0.0.1' || $peer_port ne 520) {
do_syslog("ignored packet from $addr_s: $peer_port: " . length($msg) ) if ( $verbose >= 1 );
do_syslog("ignored packet from $addr_s: $peer_port: " . length($msg) );
next;
}

do_syslog("received from $addr_s: $peer_port: " . length($msg) . " bytes") if ($verbose);
do_syslog("received from $addr_s: $peer_port: " . length($msg) . " bytes") if ($verbose);

my $routes = process_msg($addr_s, $peer_port, $msg);
do_syslog("processed $routes route entries") if ($verbose && $routes >= 0);
do_syslog("processed $routes route entries") if ($verbose && $routes >= 0);

# Consider expiring old routes. This is actually never run if we do not receive
# any RIP broadcasts at all (the recv() is blocking)
Expand Down

0 comments on commit 9f987fd

Please sign in to comment.