Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Nov 2005 21:41:19 +0200
From:      Ruslan Ermilov <ru@freebsd.org>
To:        Martin <marwos@sbcglobal.net>
Cc:        freebsd-net@freebsd.org
Subject:   Re: egress interface index lookup through a route SACK_RAW socket call
Message-ID:  <20051116194119.GA87976@ip.net.ua>
In-Reply-To: <000201c5ead8$79dded30$3be48647@compaq>
References:  <000201c5ead8$79dded30$3be48647@compaq>

next in thread | previous in thread | raw e-mail | index | archive | help

--liOOAslEiF7prFVr
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Nov 16, 2005 at 10:06:27AM -0800, Martin wrote:
> What / how do I construct a routing raw socket call to retrieve the
> outgoing interface index for a particular route that is destined out of
> an interface other than Ethernet such as a point to point?
> =20
> With Ethernet interfaces I was able to contruct a rt_msghdr with RTM_GET
> and RTA_DST- retrieve the gateway IP for the route then recursively call
> the same function passing the gateway IP and the sock_addr_in
> ->sin_addr.s_port would return with the interface index.
> =20
> But this does not work with PPP interfaces or other non-Ethernet.  Any
> insight to what i am lacking in the route request would be appreciated.
> =20
Apply the below patch to the route(8) command, then issue this:

route -vn get -host x.x.x.x

The IFP sockaddr will always be sockaddr_dl (AF_LINK) which has an
interface index.  For example,

: # ifconfig ng0 10.0.0.1 10.0.0.2
: # ./route -vn get -host 10.0.0.2
: u: inet 10.0.0.2; u: link ; RTM_GET: Report Metrics: len 164, pid: 0, seq=
 1, errno 0, flags:<UP,GATEWAY,HOST,STATIC>
: locks:  inits:=20
: sockaddrs: <DST,IFP>
:  10.0.0.2 :0
:    route to: 10.0.0.2
: destination: 10.0.0.2
:   interface: ng0
:       flags: <UP,HOST,DONE>
:  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     =
expire
:        0         0         0         0         0         0      1500     =
    0=20
:=20
: locks:  inits:=20
: sockaddrs: <DST,GATEWAY,IFP,IFA,BRD>
:  10.0.0.2 10.0.0.1 ng0:3 10.0.0.1 10.0.0.2
                     ^^^^^

%%%
Index: route.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /home/ncvs/src/sbin/route/route.c,v
retrieving revision 1.81
diff -u -r1.81 route.c
--- route.c	28 Sep 2005 12:12:15 -0000	1.81
+++ route.c	16 Nov 2005 19:35:30 -0000
@@ -385,7 +385,12 @@
 		break;
=20
 	case AF_LINK:
-		return (link_ntoa((struct sockaddr_dl *)sa));
+		{
+		static char buf[80];
+		struct sockaddr_dl *sdl =3D (struct sockaddr_dl *)sa;
+		sprintf(buf, "%s:%d", link_ntoa(sdl), sdl->sdl_index);
+		return (buf);
+		}
=20
 	default:
 	    {	u_short *s =3D (u_short *)sa;
%%%


Cheers,
--=20
Ruslan Ermilov
ru@FreeBSD.org
FreeBSD committer

--liOOAslEiF7prFVr
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (FreeBSD)

iD8DBQFDe4tfqRfpzJluFF4RArMQAJ0Ze0IkIyb29aezyc4cMjdFBIw02gCbBkd5
sZzF9v253Q5T1tRFgnp+hmo=
=C5WY
-----END PGP SIGNATURE-----

--liOOAslEiF7prFVr--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051116194119.GA87976>