Networking Forums

Networking Forums > Computer Networking > Linux Networking > How to send packets out and come back ?

Reply
Thread Tools Display Modes

How to send packets out and come back ?

 
 
frank19991@hotmail.com
Guest
Posts: n/a

 
      05-07-2004, 09:44 AM

Hi, folks,

I have two ports on the NiC of my Linux machine, say port A and B. I have
another machine acted as router R. How can I send packets out from A to R
and then come back to B ?

If I "ping B", the Ping packets automatically goes to B port directly
without going out of this machine.

I used static routing like "route add -host B gw R". It didn't work with
Linux, though it worked with BSD. Any better ways ?

I tried iptunnel but it's hard to make it work (the help is not clear
enough and it's hard to find good doc on the Internet through google).

Anyone has better ideas and pointers ?

Thanks!

Frank
 
Reply With Quote
 
 
 
 
Paul Black
Guest
Posts: n/a

 
      05-07-2004, 10:05 AM
(E-Mail Removed) wrote:
> If I "ping B", the Ping packets automatically goes to B port directly
> without going out of this machine.


Indeed.


> Anyone has better ideas and pointers ?


What are you trying to achieve?

--
Paul Black mailto(E-Mail Removed)
Oxford Semiconductor Ltd http://www.oxsemi.com
25 Milton Park, Abingdon, Tel: +44 (0) 1235 824 909
Oxfordshire. OX14 4SH Fax: +44 (0) 1235 821 141
 
Reply With Quote
 
Michael Heiming
Guest
Posts: n/a

 
      05-07-2004, 10:27 AM
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message

In comp.os.linux.networking (E-Mail Removed) suggested:

> Hi, folks,


> I have two ports on the NiC of my Linux machine, say port A and B. I have
> another machine acted as router R. How can I send packets out from A to R
> and then come back to B ?


> If I "ping B", the Ping packets automatically goes to B port directly
> without going out of this machine.


Yep, the Linux kernel is clever enough to know that some device
is locally connected, so sending them out doesn't make real
sense.

> I used static routing like "route add -host B gw R". It didn't work with
> Linux, though it worked with BSD. Any better ways ?


Are those devices on the same subnet?

Unsure, what you are going to do, perhaps you explain a bit more
and someone has an idea.

[..]

--
Michael Heiming (GPG-Key ID: 0xEDD27B94)
mail: echo (E-Mail Removed) | perl -pe 'y/a-z/n-za-m/'
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFAm2SBAkPEju3Se5QRAluVAKDTWQedSrLj/roq2oK0bjW9qjoqgwCeM1nz
88VTE+Bdl+bqgb4b5LSjonU=
=6VPU
-----END PGP SIGNATURE-----
 
Reply With Quote
 
Toni Erdmann
Guest
Posts: n/a

 
      05-07-2004, 10:37 AM
(E-Mail Removed) wrote:
> Hi, folks,
>
> I have two ports on the NiC of my Linux machine, say port A and B. I have
> another machine acted as router R. How can I send packets out from A to R
> and then come back to B ?
>
> If I "ping B", the Ping packets automatically goes to B port directly
> without going out of this machine.
>
> I used static routing like "route add -host B gw R". It didn't work with
> Linux, though it worked with BSD. Any better ways ?
>
> I tried iptunnel but it's hard to make it work (the help is not clear
> enough and it's hard to find good doc on the Internet through google).
>
> Anyone has better ideas and pointers ?


There was aposting "pinging between two NIC on my PC"
on 2004-04-22 here in this group and I answered:
(also Paul Black answered to that)

<quote myself>
Hi,

that's not so easy.

1.) Linux tries to find a shorter path - local loop,
IP stack recognized IP address as being it's own
and therefore does not use any NIC

2.) even if you tell 'ping' to use a certain NIC
'ping -I eth0 <ip of eth1>' it does not work,
because:

3.) Kernel does not accept incoming IP packets from
any NIC that has source and destination address
being it's own. To allow this, this would
require

4.) a kernel patch: I must search for it ...
... its a 'delete 2 lines' fix for UDP only ...
but even then it does not work, because

5.) you can't tell the responding ICMP stack
(Echo Response) which NIC to use for sending,
so that the response goes again the short path.

We had such problems with UDP test program with
ppp0 interface and eth0 interface, both connected
via Cellular Phone over GPRS and back to eth0
(Test Center for GSM/GPRS). We tried to measure
the up- and downlink delays using only one
Laptop. Having 2 Laptops (1 for ppp0 and 1 for eth0)
causes problems with time synchronization.

</quote myself>

Toni
 
Reply With Quote
 
Toni Erdmann
Guest
Posts: n/a

 
      05-07-2004, 11:24 AM
Some more info from google-search for 'Ben Greear'
all posted to newsgroup 'linux.kernel'

http://groups.google.de/groups?q=Gre...ofh.it&rnum=10

http://groups.google.de/groups?hl=de...om%26rnum%3D19

http://groups.google.de/groups?hl=de...om%26rnum%3D27

Toni
 
Reply With Quote
 
Frank Chu
Guest
Posts: n/a

 
      05-07-2004, 02:07 PM

Thanks, folks.

The reason I want to do so is to measure the end-to-end delay of a packet
trip. Making the sending host same as the receiving host can avoid clock
sychrnoization.

I hope there is some quick way that this can be done.

Frank
 
Reply With Quote
 
Toni Erdmann
Guest
Posts: n/a

 
      05-07-2004, 02:31 PM
Frank Chu wrote:

> Thanks, folks.
>
> The reason I want to do so is to measure the end-to-end delay of a packet
> trip. Making the sending host same as the receiving host can avoid clock
> sychrnoization.


Yes, that's exactly what we did here with ppp0 and eth0.

This is the patch that you must apply to Kernel to enable
at least UDP packets flying around.

--- linux-2.4.19/net/ipv4/fib_frontend.c Fri Aug 2 17:39:46 2002
+++ linux-2.4.19.dev/net/ipv4/fib_frontend.c Sun Sep 15 21:16:44 2002
@@ -233,8 +233,19 @@

- if (res.type != RTN_UNICAST)
- goto e_inval_res;

Your hint with the "route add -host" is good and should be
applied for both A and B giving the right IP address of the
both interface of the router.

I call my programs 'udp-loader' and 'udp-reflector'
with options like '-I eth0' and/or '-b ipaddr'.
This binds the socket to the NIC via interface name
or via ip of the interface, so that alls send() calls
will definitelly send via this NIC. It does not work
if there's no route to the partner via this interface.

udp-loader -I eth0 -b 192.168.10.2 <sendto-ip>

Here's the code sniplet:


int sockfd;
struct sockaddr_in client;
char interface_name[32];
char interface_ip[16];
struct ifreq iface;

if ( strlen(interface_name) > 0 )
{
strncpy(iface.ifr_ifrn.ifrn_name,interface_name,IF NAMSIZ);
if ( setsockopt(sockfd,SOL_SOCKET,SO_BINDTODEVICE,
(void *)&iface,sizeof(iface)) < 0 )
{
perror("setsockopt(...,SO_BINDTODEVICE,...) failed\n" );
exit(1);
}
}
if ( strlen(interface_ip) > 0 )
{
if ( inet_aton(interface_ip,&client.sin_addr) == 0 )
{
perror("inet_aton(...) failed\n" );
exit(1);
}
}

/* bind server address to the end point */
if ( bind(sockfd,(struct sockaddr*)&client,sizeof(client)) == -1 )
{
perror( "bind(...) failed : %s\n" );
exit(1);
}

Toni
 
Reply With Quote
 
Toni Erdmann
Guest
Posts: n/a

 
      05-07-2004, 02:34 PM
Toni Erdmann wrote:

> perror( "bind(...) failed : %s\n" );

^^^^

delete %s please, copy-and-paste problem.

Toni
 
Reply With Quote
 
frank19991@hotmail.com
Guest
Posts: n/a

 
      05-07-2004, 02:50 PM

Thanks, Toni, for your detailed reply.

I don't have 2.4.19 (need to install and it's pretty hassle as I have some
other packages need to put in). However, I guess you mean the following
two lines are the only thing I need to add to net/ipv4/fib_frontend.c for
the kernel modification part. Am I right ? Just to confirm my
understanding.

- if (res.type != RTN_UNICAST)
- goto e_inval_res;

Thanks!
Frank

On Fri, 7 May 2004, Toni Erdmann wrote:

> Frank Chu wrote:
>
> > Thanks, folks.
> >
> > The reason I want to do so is to measure the end-to-end delay of a packet
> > trip. Making the sending host same as the receiving host can avoid clock
> > sychrnoization.

>
> Yes, that's exactly what we did here with ppp0 and eth0.
>
> This is the patch that you must apply to Kernel to enable
> at least UDP packets flying around.
>
> --- linux-2.4.19/net/ipv4/fib_frontend.c Fri Aug 2 17:39:46 2002
> +++ linux-2.4.19.dev/net/ipv4/fib_frontend.c Sun Sep 15 21:16:44 2002
> @@ -233,8 +233,19 @@
>
> - if (res.type != RTN_UNICAST)
> - goto e_inval_res;
>
> Your hint with the "route add -host" is good and should be
> applied for both A and B giving the right IP address of the
> both interface of the router.
>
> I call my programs 'udp-loader' and 'udp-reflector'
> with options like '-I eth0' and/or '-b ipaddr'.
> This binds the socket to the NIC via interface name
> or via ip of the interface, so that alls send() calls
> will definitelly send via this NIC. It does not work
> if there's no route to the partner via this interface.
>
> udp-loader -I eth0 -b 192.168.10.2 <sendto-ip>
>
> Here's the code sniplet:
>
>
> int sockfd;
> struct sockaddr_in client;
> char interface_name[32];
> char interface_ip[16];
> struct ifreq iface;
>
> if ( strlen(interface_name) > 0 )
> {
> strncpy(iface.ifr_ifrn.ifrn_name,interface_name,IF NAMSIZ);
> if ( setsockopt(sockfd,SOL_SOCKET,SO_BINDTODEVICE,
> (void *)&iface,sizeof(iface)) < 0 )
> {
> perror("setsockopt(...,SO_BINDTODEVICE,...) failed\n" );
> exit(1);
> }
> }
> if ( strlen(interface_ip) > 0 )
> {
> if ( inet_aton(interface_ip,&client.sin_addr) == 0 )
> {
> perror("inet_aton(...) failed\n" );
> exit(1);
> }
> }
>
> /* bind server address to the end point */
> if ( bind(sockfd,(struct sockaddr*)&client,sizeof(client)) == -1 )
> {
> perror( "bind(...) failed : %s\n" );
> exit(1);
> }
>
> Toni
>

 
Reply With Quote
 
Toni Erdmann
Guest
Posts: n/a

 
      05-07-2004, 03:00 PM
(E-Mail Removed) wrote:

> Thanks, Toni, for your detailed reply.
>
> I don't have 2.4.19 (need to install and it's pretty hassle as I have some
> other packages need to put in). However, I guess you mean the following
> two lines are the only thing I need to add to net/ipv4/fib_frontend.c for
> the kernel modification part. Am I right ? Just to confirm my
> understanding.
>
> - if (res.type != RTN_UNICAST)
> - goto e_inval_res;
>


Yes - and no. Take the kernel you have and find those two lines
in net/ipv4/fib_frontend.c at about lines 223 ff.

*Delete* or comment that section, '-' means 'delete'.

Have fun.
Toni
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to send packets kernel.lover Linux Networking 0 02-05-2005 12:19 PM
I can send packets but I receive nothing, routing problem riviereg Linux Networking 8 09-06-2004 12:49 PM
I can send packets but I receive nothing, routing problem riviereg Linux Networking 0 09-03-2004 09:44 AM
How can I send and recieve packets of data using TAPI to_rachit@rediffmail.com Windows Networking 0 01-30-2004 04:58 PM
Send custom TCP packets Ishwar Linux Networking 3 07-15-2003 10:51 PM



1 2 3 4 5 6 7 8 9 10 11