static int __init tc_filter_init(void)
{
rtnl_register(PF_UNSPEC, RTM_NEWTFILTER, tc_ctl_tfilter, NULL, NULL);
rtnl_register(PF_UNSPEC, RTM_DELTFILTER, tc_ctl_tfilter, NULL, NULL);
rtnl_register(PF_UNSPEC, RTM_GETTFILTER, tc_ctl_tfilter,
tc_dump_tfilter, NULL);
return 0;
}
注册的函数如何在kernel里面找到呢?首先要清楚如下定义。
enum {
RTM_BASE = 16,
#define RTM_BASE RTM_BASE
...
RTM_NEWTFILTER = 44,
#define RTM_NEWTFILTER RTM_NEWTFILTER
...
}
#define PF_UNSPEC AF_UNSPEC
#define AF_UNSPEC 0
$ bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
44 - 16 + 1
29
29 * 3 * 8
696
[chrism@bjglab-18 ~]$ x 696
0x2b8 = 696 = 0.68K = 0.00M = 0.00G
0000 0000 0000 0000 0000 0010 1011 1000
x是一个自定义的python程序
#!/usr/bin/python
import re
import sys
import string
if len(sys.argv) == 1:
exit()
argv1 = sys.argv[1]
if re.match('^(0x|0X)', argv1) or re.search('([a-fA-F]+)', argv1):
i = string.atoi(argv1, base=16)
elif re.match('^\d+$', argv1):
i = string.atoi(argv1, base=10)
else:
print "Error input!"
exit()
r=''
n = 0x80000000
while n:
r += '1' if n & i else '0'
if len(re.sub(' ', '', r)) % 4 == 0:
r += ' '
n >>= 1
print '0x%x = %d = %.2fK =' % (i, i, i / 1024.0),
print '%.2fM = %.2fG' % (i / 1024.0 ** 2.0, i / 1024.0 ** 3.0)
print r
ffff880c88496800+2b8=ffff880c88496ab8
crash> rd rtnl_msg_handlers 1
ffffffff82071bc0: ffff880c88496800 .hI.....
crash> rtnl_link ffff880c88496ab8
struct rtnl_link {
doit = 0xffffffff8163b320 <tc_ctl_tfilter>,
dumpit = 0x0,
calcit = 0x0
}