iputils ping/ping6: add (non-raw) ICMP socket support
Subsystems (2)
PATCH v3 2/2 iputils ping/ping6: add (non-raw) ICMP socket support
This patch allows running ping and ping6 without root privileges on kernels that support it. Almost identical to Lorenzo Colitti's original patch except:
- Applies to latest git iputils.
- Prevent ICMP_FILTER from being applied to non-raw sockets
- Does not change code formatting
- Changes comments and doc to reflect the new behavior
N.B.
Some functionalities in ping6 still require raw sockets.
Signed-off-by Lorenzo Colitti <[email protected]>
Signed-off-by Salvatore Mesoraca <[email protected]>
--- doc/ping.sgml | 5 ++-- ping.c | 72 ++++++++++++++++++++++++++++++++++++++++++------------ ping6.c | 78 +++++++++++++++++++++++++++++++++++------------------------ ping_common.c | 9 ++++--- ping_common.h | 1 + 5 files changed, 112 insertions(+), 53 deletions(-)
doc/ping.sgml +3 -2
@@ -628,8 +628,9 @@ The version described here is its descendant specific to Linux. <refsect1><title>SECURITY</title> <para> -<command/ping/ requires <constant/CAP_NET_RAW/ capability -to be executed. It may be used as set-uid root. +<command/ping/ doesn't require <constant/CAP_NET_RAW/ capability +to be executed if kernel supports non-raw ICMP sockets. +Otherwise it can also be used as set-uid root. </para> </refsect1>
ping.c +57 -15
138 lines not on this page · raw message
ping6.c +46 -32
119 lines not on this page · raw message
ping_common.c +5 -4
@@ -13,6 +13,7 @@ int rtt_addend;__u16 acked;struct rcvd_table rcvd_tbl; +int using_ping_socket =0 ;/* counters */
@@ -677,7 +678,8 @@ void setup(int icmp_sock) *p++ = i; } - ident =htons (getpid () &0xFFFF ); +if (!using_ping_socket) + ident =htons (getpid () &0xFFFF );set_signal (SIGINT , sigexit);set_signal (SIGALRM , sigexit);
@@ -836,7 +838,7 @@ void main_loop(int icmp_sock, __u8 *packet, int packlen) }/* See? ... someone runs another ping on this host. */ -if (not_ours) +if (not_ours && !using_ping_socket)install_filter ();/* If nothing is in flight, "break" returns us to pinger. */
@@ -1073,6 +1075,5 @@ void status(void) }inline int is_ours (uint16_t id) { -return id == ident; +return using_ping_socket || id == ident; } -
ping_common.h +1 -0
@@ -127,6 +127,7 @@ extern char *hostname;extern int uid;extern int ident;/* process id to identify our packets */ +extern int using_ping_socket;extern int sndbuf;extern int ttl;
--
2.0.5