Discussion:
how to get FreeBSD ping.c into NetBSD?
(too old to reply)
Gert Doering
2006-11-22 17:17:15 UTC
Permalink
Hi folks,

today I was (again) in need of being able to "ping" with a specific source
address, as opposed to "whatever interface the packet happens to leave via".

This is fairly regularily needed in environments where different source IPs
are handled differently - for example due to IPSEC rules, or due to different
firewall rules.

NetBSD ping doesn't have a "-S <src addr>" flag, while FreeBSD ping has
- and just compiling the FreeBSD 6.x "ping.c" source on NetBSD made it
work (with two minor changes).

Additionally, FreeBSD ping has a "-W <milliseconds>" flag and some other
usefull goodies...:

usage: ping [-AaDdfnoQqRrv] [-c count] [-G sweepmaxsize] [-g sweepminsize]
[-h sweepincrsize] [-i wait] [-l preload] [-M mask | time] [-m ttl]
[-p pattern] [-S src_addr] [-s packetsize] [-t timeout]
[-W waittime] [-z tos] host

So... how to get FreeBSD ping.c (or at least "-S <src addr>" functionality)
into NetBSD?

Can we just import their ping.c, due to all being BSD licensed (actually,
FreeBSD ping.c claims to be "public domain")?

gert
--
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany ***@greenie.muc.de
fax: +49-89-35655025 ***@net.informatik.tu-muenchen.de

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
David Young
2006-11-22 17:27:55 UTC
Permalink
Post by Gert Doering
Hi folks,
today I was (again) in need of being able to "ping" with a specific source
address, as opposed to "whatever interface the packet happens to leave via".
This is fairly regularily needed in environments where different source IPs
are handled differently - for example due to IPSEC rules, or due to different
firewall rules.
NetBSD ping doesn't have a "-S <src addr>" flag, while FreeBSD ping has
- and just compiling the FreeBSD 6.x "ping.c" source on NetBSD made it
work (with two minor changes).
Gert,

ping -I does what you want, however, you wouldn't know it from reading
the manual page:

-I ifaddr
Send multicast datagrams on the network interface specified by
the interface's hostname or IP address.

Dave
--
David Young OJC Technologies
***@ojctech.com Urbana, IL * (217) 278-3933

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Gert Doering
2006-11-22 17:50:54 UTC
Permalink
Hi,
Post by David Young
Gert,
ping -I does what you want, however, you wouldn't know it from reading
-I ifaddr
Send multicast datagrams on the network interface specified by
the interface's hostname or IP address.
Indeed. *surprise*.

Hmmm. The FreeBSD man page has a "-I", which is *only* for multicast...

-I interface
Source multicast packets with the given interface address. This
flag only applies if the ping destination is a multicast address.

... so I admit I didn't try NetBSD's "-I" in the first place (after
having read the sentence about "multicast datagrams").


So how to fix it? "Find out what the available options really do and
update the man page"?

gert
--
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany ***@greenie.muc.de
fax: +49-89-35655025 ***@net.informatik.tu-muenchen.de

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Christos Zoulas
2006-11-22 20:03:51 UTC
Permalink
Post by Gert Doering
Hi,
Post by David Young
Gert,
ping -I does what you want, however, you wouldn't know it from reading
-I ifaddr
Send multicast datagrams on the network interface specified by
the interface's hostname or IP address.
Indeed. *surprise*.
Hmmm. The FreeBSD man page has a "-I", which is *only* for multicast...
-I interface
Source multicast packets with the given interface address. This
flag only applies if the ping destination is a multicast address.
... so I admit I didn't try NetBSD's "-I" in the first place (after
having read the sentence about "multicast datagrams").
So how to fix it? "Find out what the available options really do and
update the man page"?
gert
Sure, that would be nice.

christos


--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Hubert Feyrer
2006-11-22 19:10:18 UTC
Permalink
Post by David Young
-I ifaddr
Send multicast datagrams on the network interface specified by
the interface's hostname or IP address.
How about:

-I ipaddr
Send datagrams on the network interface specified by the
interface's hostname or IP address, and use that as the
source address of outgoing packets. On hosts with more than one IP
address, this option can be used to force the source address to be
something other than the IP address of the interface the probe
packet is sent on. If the IP address is not one of this machine's
interface addresses, an error is returned and nothing is sent.

(taken mostly from FreeBSD; someone please confirm if the error handling
is actually true!)


- Hubert

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Gert Doering
2006-11-22 19:20:07 UTC
Permalink
Hi,
Post by Hubert Feyrer
Post by David Young
-I ifaddr
Send multicast datagrams on the network interface specified by
the interface's hostname or IP address.
-I ipaddr
Send datagrams on the network interface specified by the
interface's hostname or IP address,
Hmmm, that's not actually what it's doing ("send out on *that* network
interface"). It's just using that IP address, and sending out the
packets via the normal routing table (unless "-r" is set).

More like:

-I ipaddr
Send datagrams using the specified source IP address. This option
can be used to force the source address to be [...]
Post by Hubert Feyrer
and use that as the source address of outgoing packets.
On hosts with more than one IP
address, this option can be used to force the source address to be
something other than the IP address of the interface the probe
packet is sent on. If the IP address is not one of this machine's
interface addresses, an error is returned and nothing is sent.
(taken mostly from FreeBSD; someone please confirm if the error handling
is actually true!)
Yep, the error handling works:

***@delta.greenie.net:/home/gert$ ping -I 96.0.16.1 195.30.0.1
...
64 bytes from 195.30.0.1: icmp_seq=0 ttl=61 time=1.553 ms
...
***@delta.greenie.net:/home/gert$ ping -I 96.0.16.2 195.30.0.1
ping: Can't set source interface/address: Can't assign requested address

(96.0.16.1 is an alias on lo0, used for routing/IPSEC tests)

gert
--
USENET is *not* the non-clickable part of WWW!
//www.muc.de/~gert/
Gert Doering - Munich, Germany ***@greenie.muc.de
fax: +49-89-35655025 ***@net.informatik.tu-muenchen.de

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
David Young
2006-11-23 06:24:00 UTC
Permalink
Post by Gert Doering
Hi,
Post by Hubert Feyrer
Post by David Young
-I ifaddr
Send multicast datagrams on the network interface specified by
the interface's hostname or IP address.
-I ipaddr
Send datagrams on the network interface specified by the
interface's hostname or IP address,
Hmmm, that's not actually what it's doing ("send out on *that* network
interface"). It's just using that IP address, and sending out the
packets via the normal routing table (unless "-r" is set).
I believe there is a difference between unicast and multicast: for
multicast, ping really does use the interface specified by the IP for
multicast.

Dave
--
David Young OJC Technologies
***@ojctech.com Urbana, IL * (217) 278-3933

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Pavel Cahyna
2006-11-22 19:41:50 UTC
Permalink
Hubert, Gert: please read the manpage in -current. I added that some half
year ago.

Pavel

--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-***@muc.de
Loading...