##summary:
- struct rq is basic data structure.
- there is a realtime process(es) and normal process(es) are stored in
different sub-runqueue*_rq
of rq?1
2426 struct cfs_rq cfs;
427 struct rt_rq rt;
##summary:
*_rq
of rq? 1 | 426 struct cfs_rq cfs; |
1 | git send-email --annotate --subject-prefix="PATCH v2 net-next" \ |
promisc is one bit of struct net_device’s flag, which is used to indicate if a device is in promisc status.
1 | 30 /* Standard interface flags (netdevice->flags). */ |
There are two kinds of operataion, could cause a NIC enter/leave promisc status.
ip command
run mutli on
command, just need one off
to recover.
1 | ip link set dev eth0 promisc on |
tcpdump command
When tcpdump starts, it let dev to promisc,
and just before exit, tcpdump let dev left promisc.
All these is done by call kernel api dev_set_promiscuity.
##netlink介绍
netlink是一种用于内核和用户空间进行数据交互的socket。 关于netlink的具体介绍,google给出更好的解释。
netlink是socket的一种,其的family号是PF_NETLINK, netlink包括很多种proto,并且用户可以根据自己的需要进行扩展。
每个netlinksocket都有一个pid,该pid在所属proto下是唯一的。 在netlink消息
传递是,pid常被用来标识目的地socket。
Every netlink socket is indicated by (net, proto, pid).
对nl_table
的操作:
读操作: netlink_lock_table
和 netlink_unlock_table
写操作netlink_table_grab
和 netlink_table_ungrab
原子变量nl_table_users
用来保存对nl_table
的读者引用计数。
只要没有进行的写者,即使有n个写者在等待,m个读者也可以同时读。
当没有任何读者时,写着才可以获得权限。
一旦一个写着获得权限,所有的读者和写者都得等待。
有时候我们需要从内核输出大量的消息。 例如,dump interface, xfrm sa,sp(几千甚至几万条)等 这些信息显然无法放到一个skb里。
这是我们需要借助netlinkcallback机制。 原理:
netlink_callback
1 | 93 struct netlink_callback { |
netlink_dump_control
1 | 117 struct netlink_dump_control { |
和
done`1 | dump: 每次输出时调用,接着上次的数据输出。如果全部输出完成返回0. |
1 | 1. 当dump的消息非常多时候,首先创建struct netlink_callback, 并创建这个cb挂到netlink socket(nlk)上。 |
netlink_recvmsg
调用netlink_dump
形成闭环反馈。闭环反馈过程:
1 | 这样应用程序每次通过系统调用rcv, 在将数据从内核中收上来的 |
1 | nlk->cb = NULL; |
1 | 2359 stati int netlink_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, |
#netlink socket framework.
##netlink socket proto
netlink socket is a kind of socket. There are many proto of netlink. There may have many groups under each proto. See example in following.
Every netlink socket is indicated by <net, proto, pid>
.
##socket type
socket is a widely used in kernel/net. There are many kind of sockets with different ‘family/proto’. They can be divided by family, and under each family, there are many kinds of proto. such as inet(ipv4)/stream, netlink/(xfrm, rt).