From owner-freebsd-net@FreeBSD.ORG Wed Nov 16 19:42:02 2005 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 54AFD16A46F for ; Wed, 16 Nov 2005 19:42:02 +0000 (GMT) (envelope-from ru@ip.net.ua) Received: from tigra.ip.net.ua (tigra.ip.net.ua [82.193.96.10]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2F9F343D49 for ; Wed, 16 Nov 2005 19:42:00 +0000 (GMT) (envelope-from ru@ip.net.ua) Received: from localhost (rocky.ip.net.ua [82.193.96.2]) by tigra.ip.net.ua (8.12.11/8.12.11) with ESMTP id jAGJfwI0027477; Wed, 16 Nov 2005 21:41:58 +0200 (EET) (envelope-from ru@ip.net.ua) Received: from tigra.ip.net.ua ([82.193.96.10]) by localhost (rocky.ipnet [82.193.96.2]) (amavisd-new, port 10024) with LMTP id 11210-03-3; Wed, 16 Nov 2005 21:41:56 +0200 (EET) Received: from heffalump.ip.net.ua (heffalump.ip.net.ua [82.193.96.213]) by tigra.ip.net.ua (8.12.11/8.12.11) with ESMTP id jAGJfBb0027404 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 16 Nov 2005 21:41:11 +0200 (EET) (envelope-from ru@ip.net.ua) Received: (from ru@localhost) by heffalump.ip.net.ua (8.13.4/8.13.4) id jAGJfJ8g089424; Wed, 16 Nov 2005 21:41:19 +0200 (EET) (envelope-from ru) Date: Wed, 16 Nov 2005 21:41:19 +0200 From: Ruslan Ermilov To: Martin Message-ID: <20051116194119.GA87976@ip.net.ua> References: <000201c5ead8$79dded30$3be48647@compaq> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="liOOAslEiF7prFVr" Content-Disposition: inline In-Reply-To: <000201c5ead8$79dded30$3be48647@compaq> User-Agent: Mutt/1.5.9i X-Virus-Scanned: by amavisd-new at ip.net.ua Cc: freebsd-net@freebsd.org Subject: Re: egress interface index lookup through a route SACK_RAW socket call X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Nov 2005 19:42:03 -0000 --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: : locks: inits:=20 : sockaddrs: : 10.0.0.2 :0 : route to: 10.0.0.2 : destination: 10.0.0.2 : interface: ng0 : flags: : recvpipe sendpipe ssthresh rtt,msec rttvar hopcount mtu = expire : 0 0 0 0 0 0 1500 = 0=20 :=20 : locks: inits:=20 : sockaddrs: : 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--