Skip to content

Commit

Permalink
simplify restrictions, fixes #29, #32
Browse files Browse the repository at this point in the history
  • Loading branch information
schweikert committed Jan 16, 2017
1 parent 2cf801f commit 8481d74
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 59 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Unreleased
* (feature) Support kernel-timestamping of received packets (#46)
* (feature) Simplify restrictions: only -i >= 1 and -p >= 10 are enforced now
* (bugfix) Fix compatibility issue with AIX (#69, @blentzgh)
* (bugfix) Fix -q not suppressing some ICMP error messages (#83)

Expand Down
34 changes: 5 additions & 29 deletions ci/test-03-forbidden.pl
Original file line number Diff line number Diff line change
@@ -1,41 +1,23 @@
#!/usr/bin/perl -w

use Test::Command tests => 33;
use Test::Command tests => 24;

# fping -i 0
my $cmd1 = Test::Command->new(cmd => "fping -i 0 -T10 -g 127.0.0.1/29");
$cmd1->exit_is_num(1);
$cmd1->stdout_is_eq("");
$cmd1->stderr_is_eq(<<END);
fping: these options are too risky for mere mortals.
fping: You need i >= 1, p >= 20, r < 20, and t >= 50
fping: You need -i >= 1 and -p >= 10
END

# fping -p 15
my $cmd2 = Test::Command->new(cmd => "fping -c3 -p 15 127.0.0.1");
# fping -p 9
my $cmd2 = Test::Command->new(cmd => "fping -c3 -p 9 127.0.0.1");
$cmd2->exit_is_num(1);
$cmd2->stdout_is_eq("");
$cmd2->stderr_is_eq(<<END);
fping: these options are too risky for mere mortals.
fping: You need i >= 1, p >= 20, r < 20, and t >= 50
END

# fping -r 30
my $cmd3 = Test::Command->new(cmd => "fping -r 30 127.0.0.1");
$cmd3->exit_is_num(1);
$cmd3->stdout_is_eq("");
$cmd3->stderr_is_eq(<<END);
fping: these options are too risky for mere mortals.
fping: You need i >= 1, p >= 20, r < 20, and t >= 50
END

# fping -t 40
my $cmd4 = Test::Command->new(cmd => "fping -t 40 127.0.0.1");
$cmd4->exit_is_num(1);
$cmd4->stdout_is_eq("");
$cmd4->stderr_is_eq(<<END);
fping: these options are too risky for mere mortals.
fping: You need i >= 1, p >= 20, r < 20, and t >= 50
fping: You need -i >= 1 and -p >= 10
END

# fping -H 300
Expand Down Expand Up @@ -74,9 +56,3 @@ END
$cmd10->stdout_is_eq("");
$cmd10->stderr_is_eq("fping: backoff factor 5.1 not valid, must be between 1.0 and 5.0\n");

# fping -C 11000
my $cmd11 = Test::Command->new(cmd => "fping -C 11000 127.0.0.1");
$cmd11->exit_is_num(1);
$cmd11->stdout_is_eq("");
$cmd11->stderr_is_eq("fping: count 11000 not valid, must be less than 10000\n");

2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dnl Process this file with autoconf to produce a configure script.
dnl Minimum Autoconf version required.
AC_PREREQ(2.59)

AC_INIT([fping],[3.15])
AC_INIT([fping],[3.16-rc1])

dnl make ipv4 and ipv6 options
AC_ARG_ENABLE([ipv4],
Expand Down
18 changes: 6 additions & 12 deletions doc/fping.pod
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Print usage message.
=item B<-i> I<n>

The minimum amount of time (in milliseconds) between sending a ping packet
to any target (default is 25).
to any target (default is 25, minimum is 1).

=item B<-l>

Expand All @@ -137,7 +137,7 @@ Same as -d.

=item B<-N>

Format output for netdata (-l -Q are required). See: http://my-netdata.io/
Format output for netdata (-l -Q are required). See: L<http://my-netdata.io/>

=item B<-o>

Expand All @@ -152,7 +152,7 @@ Set the typ of service flag (TOS). I<n> can be either decimal or hexadecimal

In looping or counting modes (B<-l>, B<-c>, or B<-C>), this parameter sets
the time in milliseconds that B<fping> waits between successive packets to
an individual target. Default is 1000.
an individual target. Default is 1000 and minimum is 10.

=item B<-q>

Expand Down Expand Up @@ -252,10 +252,8 @@ line arguments, and 4 for a system call failure.

=head1 RESTRICTIONS

If certain options are used (i.e, a low value for B<-i> and B<-t>, and a high value
for B<-r>) it is possible to flood the network. This program must be installed as
setuid root in order to open up a raw socket, or must be run by root. In order
to stop mere mortals from hosing the network, normal users can't specify the following:
In order to avoid users mistakingly flooding the network, the following values
are not allowed for non-root users:

=over 4

Expand All @@ -265,11 +263,7 @@ B<-i> I<n>, where I<n> < 1 msec

=item *

B<-r> I<n>, where I<n> > 20

=item *

B<-t> I<n>, where n < 250 msec
B<-p> I<n>, where I<n> < 10 msec

=back

Expand Down
21 changes: 4 additions & 17 deletions src/fping.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,8 @@ extern int h_errno;
#define DEFAULT_PING_DATA_SIZE 56

/* maxima and minima */
#define MAX_COUNT 10000
#define MIN_INTERVAL 1 /* in millisec */
#define MIN_PERHOST_INTERVAL 20 /* in millisec */
#define MIN_TIMEOUT 50 /* in millisec */
#define MAX_RETRY 20
#define MIN_PERHOST_INTERVAL 10 /* in millisec */

/* response time array flags */
#define RESP_WAITING -1
Expand Down Expand Up @@ -617,14 +614,12 @@ int main( int argc, char **argv )
}/* IF */

if( ( interval < MIN_INTERVAL * 100 ||
perhost_interval < MIN_PERHOST_INTERVAL * 100 ||
retry > MAX_RETRY ||
timeout < MIN_TIMEOUT * 100 )
perhost_interval < MIN_PERHOST_INTERVAL * 100 )
&& getuid() )
{
fprintf( stderr, "%s: these options are too risky for mere mortals.\n", prog );
fprintf( stderr, "%s: You need i >= %u, p >= %u, r < %u, and t >= %u\n",
prog, MIN_INTERVAL, MIN_PERHOST_INTERVAL, MAX_RETRY, MIN_TIMEOUT );
fprintf( stderr, "%s: You need -i >= %u and -p >= %u\n",
prog, MIN_INTERVAL, MIN_PERHOST_INTERVAL );
exit(1);
}/* IF */

Expand All @@ -644,14 +639,6 @@ int main( int argc, char **argv )

}/* IF */

if( count > MAX_COUNT )
{
fprintf( stderr, "%s: count %u not valid, must be less than %u\n",
prog, count, MAX_COUNT );
exit(1);

}/* IF */

if( alive_flag || unreachable_flag )
verbose_flag = 0;

Expand Down

0 comments on commit 8481d74

Please sign in to comment.