dump rtnl_msg_handlers and rtnl_link

本文介绍了Linux内核中TC过滤器的注册过程,包括rt_nl_register函数的应用及RTM消息类型的定义。通过具体代码示例展示了不同类型的TC过滤器如何在内核中进行注册,并解释了相关枚举和宏定义的作用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值