LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 06-11-2004, 03:20 AM   #1
thanh
LQ Newbie
 
Registered: Jun 2004
Posts: 5

Rep: Reputation: 0
How to know when a routing entry is used?


Hello every one.

I have this problem which makes me anxious recently.

I want to write a program to report about how many time a routing entry is used (or more clearly, how many packets have been sent through a route in a fixed period)

I think I may have to put some kind of trigger somewhere, but I don't know exactly how.

Anyone has any idea how to do it?


Thanks a lot.

Thanh/
 
Old 06-11-2004, 05:08 AM   #2
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
there are two counts associated with any route, reference count and usage count,
everytime the packet uses a route, the usage count is incremented.
reference count is just to see how many connections (or transactions) are using that route. Usage count can be seen using the route -nC command, this is to see the route cache...

--iptraf is a utility that shows how many packets and bytes have left that interface,


HTH

Last edited by shishir; 06-11-2004 at 05:11 AM.
 
Old 06-11-2004, 07:47 AM   #3
thanh
LQ Newbie
 
Registered: Jun 2004
Posts: 5

Original Poster
Rep: Reputation: 0
Thank you very much for your info Shishir

However, do you know the API to get those information (reference count and usage count), and is it possible to know whenever a packet is sent through an interface?

Thanks in advance
 
Old 06-11-2004, 09:23 AM   #4
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
i am not sure if there is any direct api that can give you this statistic...because netstat causes a read on the proc filesystem that contains these statistics...

you can write your own system call that can parse the whole of route cache and print the counts (these are in a structure called rtable, defined in net/route.h)..

it is not very difficult, infact, you can use a lot of kernel code to see how to write a call that can take the src and destination ips and give their statistics , by looking in the hash table (route cache)..

CORRECTION : the structure is that contains refcnt and use is not rtable but one it usesdst_entry (in net/dst.h). I apologise for the error.

Last edited by shishir; 06-12-2004 at 01:30 AM.
 
Old 06-11-2004, 11:08 AM   #5
thanh
LQ Newbie
 
Registered: Jun 2004
Posts: 5

Original Poster
Rep: Reputation: 0
THank you very much indeed.
 
Old 06-11-2004, 12:30 PM   #6
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
you can use netlink to get informatin about routes, i think that includes usage count. look on my site about 1/2 way down for a bunch of examle code, and the file /usr/include/linux/rtnetlink.h
 
Old 06-12-2004, 01:44 AM   #7
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
yeah, you can use the routing sockets for this purposes...damn, how could i forget that...., this function uses a structure rta_cacheinfo, that is filled in by the kernel using a function called inet_rtm_getroute(), which in turn uses the function rt_fill_info() to get the job done, the fields in the
structure rta_cacheinfo
{
__u32 rta_clntref;
__u32 rta_used;
}
would be the ones you are interested in...
 
Old 06-12-2004, 12:03 PM   #8
thanh
LQ Newbie
 
Registered: Jun 2004
Posts: 5

Original Poster
Rep: Reputation: 0
THanks very much shishir and infamous41md

To infamous41md: I found the paragraph you wrote about netlink
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to set default entry in routing table? cranium2004 Linux - Networking 7 03-15-2005 05:26 PM
Add routing entry at system startup ust Linux - General 2 10-22-2004 10:35 PM
Add routing entry at system startup ust Linux - Software 1 10-18-2004 01:23 PM
file for storing routing entry becky_starr Linux - Networking 1 03-15-2004 09:52 AM
routing tables - removing entry zigmund555 Linux - Networking 2 10-03-2003 07:57 AM


All times are GMT -5. The time now is 03:33 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration