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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
06-11-2004, 03:20 AM
|
#1
|
|
LQ Newbie
Registered: Jun 2004
Posts: 5
Rep:
|
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/
|
|
|
|
06-11-2004, 05:08 AM
|
#2
|
|
Member
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251
Rep:
|
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.
|
|
|
|
06-11-2004, 07:47 AM
|
#3
|
|
LQ Newbie
Registered: Jun 2004
Posts: 5
Original Poster
Rep:
|
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
|
|
|
|
06-11-2004, 09:23 AM
|
#4
|
|
Member
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251
Rep:
|
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.
|
|
|
|
06-11-2004, 11:08 AM
|
#5
|
|
LQ Newbie
Registered: Jun 2004
Posts: 5
Original Poster
Rep:
|
THank you very much indeed.
|
|
|
|
06-11-2004, 12:30 PM
|
#6
|
|
Member
Registered: Mar 2003
Posts: 804
Rep:
|
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
|
|
|
|
06-12-2004, 01:44 AM
|
#7
|
|
Member
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251
Rep:
|
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...
|
|
|
|
06-12-2004, 12:03 PM
|
#8
|
|
LQ Newbie
Registered: Jun 2004
Posts: 5
Original Poster
Rep:
|
THanks very much shishir and infamous41md
To infamous41md: I found the paragraph you wrote about netlink
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 04:51 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|