[Nagiosplug-devel] feature request -selecting your network interface
bobi at netshel.net
bobi at netshel.net
Fri Sep 29 23:48:59 CEST 2006
Hi,
I don't know why I felt like doing this - guess I was curious if you could
bind to a local address for a TCP stream prior to calling connect(2). I
didn't think it would work, because the routing table usually controls
which interface to send a packet out on (and hence, which source IP
address to emebed in the IP header.) But if an address is reachable from
more than one interface, I supposed it could work.
Anyway, please find attached a tar-ball containing three patch files for:
1. netutils.h
2. netutils.c
3. check_tcp.c
If you patch the above three files, and re-make check_tcp, it will allow
you to specify the source IP address.
The new option is: -I src-ip-address
I've tested it on my Linux box which has two interfaces (plus loopback,)
and it seems to work well. I watched the packets go out with tcpdump and,
sure enough, the IP headers had the source IP address that I'd specified
in the command line.
One note, though: If you specify an interface IP address which can't
reach your destination host, the connect(2) call inside netutils.c will
return an EINVAL error. I know this because I tried accessing an external
host through the loopback interface (127.0.0.1) and it returned EINVAL,
which is what you'd expect.
Try it out and please let me know if it works for you.
BTW, I modified the netutils' np_net_connect() routine so that it won't
break the other plugins that depend upon it. If you want other plugins to
use the new source-interface functionality of np_net_connect(), those
plugins will have to modified individually.
Regards,
Bob
> Only thing here is that I'm not what you can call a C programmer at all. I
> do some Perl, I learned the basis of C some time ago... The hack for
> check_ping was trivial as I only redirected an argument to another
> program.
> And even for that simple hack I managed to segfault before getting it
> right
> (I was checking for valid IP address though).
>
> If you really insist and encourage me I'll try it :) But for now I don't
> even have an idea how to set the source IP on a socket...
>
> Thomas
>
>> -----Original Message-----
>> From: nagiosplug-devel-bounces at lists.sourceforge.net
>> [mailto:nagiosplug-devel-bounces at lists.sourceforge.net] On
>> Behalf Of Andreas Ericsson
>> Sent: September 29, 2006 11:30
>> To: Nagios Plugin Development Mailing List
>> Subject: Re: [Nagiosplug-devel] feature request -selecting
>> yournetwork interface
>>
>> Thomas Guyot-Sionnest wrote:
>> >
>> > Using Linux VLAN support I'd like to be able to have one IP
>> per VLAN and
>> > check all interconectivity between vlans and other sites.
>> So for example I
>> > may want to know if hosts in the .7 vlan can connect to the
>> mail server in
>> > the .4 vlan, but since I have an IP in the .4 vlan already
>> it won't go
>> > trough the firewall. So I must specify to sent it from the .7 vlan.
>> >
>>
>> Ah. This makes your request make sense. If you wish for the outbound
>> traffic to go through a specific interface, that's very easy
>> to fix. You
>> just need to bind(2) the socket to an IP specified by the
>> user prior to
>> calling connect(2) on it. The IP ofcourse have to exist and be
>> associated with the interface you want to use for the
>> outbound traffic.
>>
>> Provided you don't have two interfaces with the same IP (which would
>> indeed be completely insane), this will work magnificently while
>> avoiding the portability problems associated with finding a specific
>> interface (have a look at check_dhcp for some true
>> portability horror).
>>
>> Happy hacking, and make sure you send in the patch when you're done.
>>
>> --
>> Andreas Ericsson andreas.ericsson at op5.se
>> OP5 AB www.op5.se
>> Tel: +46 8-230225 Fax: +46 8-230231
>>
>> --------------------------------------------------------------
>> -----------
>> Take Surveys. Earn Cash. Influence the Future of IT
>> Join SourceForge.net's Techsay panel and you'll get the
>> chance to share your
>> opinions on IT & business topics through brief surveys -- and
>> earn cash
>> http://www.techsay.com/default.php?page=join.php&p=sourceforge
>> &CID=DEVDEV
>> _______________________________________________________
>> Nagios Plugin Development Mailing List
>> Nagiosplug-devel at lists.sourceforge.net
>> Unsubscribe at
>> https://lists.sourceforge.net/lists/listinfo/nagiosplug-devel
>> ::: Please include plugins version (-v) and OS when reporting
>> any issue.
>> ::: Messages without supporting info will risk being sent to /dev/null
>>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share
> your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV_______________________________________________________
> Nagios Plugin Development Mailing List
> Nagiosplug-devel at lists.sourceforge.net
> Unsubscribe at
> https://lists.sourceforge.net/lists/listinfo/nagiosplug-devel
> ::: Please include plugins version (-v) and OS when reporting any issue.
> ::: Messages without supporting info will risk being sent to /dev/null
-------------- next part --------------
A non-text attachment was scrubbed...
Name: check_tcp-patches.tgz
Type: application/x-gzip-compressed
Size: 1904 bytes
Desc: not available
URL: <https://www.monitoring-plugins.org/archive/devel/attachments/20060929/baf36785/attachment.bin>
More information about the Devel
mailing list