为什么需要软中断
引入软中断的目的是为了中断要尽快返回。 把一些不紧急的工作放到下半部里执行。 软中断是下半部的一种实现方式。其他的还有tasklet和workqueue。
软中断特点
软中断特点是可以同时运行在CPU上,而tasklet则是整个系统中只有一个。 软中断和tasklet都不允许睡眠,因此必须避免执行引发睡眠的操作。 workqueue则允许睡眠。
##应用层通过pfkey,dump sa的步骤:
1 | static void __init bootmem_init(void) |
1 | 936 static int __devinit e1000_probe(struct pci_dev *pdev, |
1 | 53 #define alloc_etherdev(sizeof_priv) alloc_etherdev_mq(sizeof_priv, 1) |
1 | 365 struct net_device *alloc_etherdev_mqs(int sizeof_priv, unsigned int txqs, |
1 | 5821 struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name, |
1 | 334 void ether_setup(struct net_device *dev) |
IPv6 route tree 原理.
IPv6路由采用二叉树的形式进行存储, 查找任意路由最多需要128次比较(128次,说法不太严格)。
因此其算法复杂度为常数,因此IPv6里没有像IPv4那样的cache。
1 | /** |
1 | int register_pernet_subsys(struct pernet_operations *ops) |
####Fox example
inet6_init in pernet.
1 | static struct pernet_operations inet6_net_ops = { |
When we compile a glibc(or eglibc), we need generated the timezone data file with it. although, it is stable and no change almost in every version update.
Today a problem is met about it.
We use the old glibc’s timezone file, which is used by many different toolchain for several paltforms.
unfortunately.the data file has been change after 2007 year by GNU official. but I did not found the exact version(date) of glibc, which change the timezone data file.
btw: toolchain = binutils + gcc + glibc(eglic) + kernel(header)
###af_key.c
linux kernel provide 3 method to manager SA/SP,
such as add/del/flush/dump SAs/SPs.
The af_key.c implement the pf_key socket.
###part 1. pf_key socket defination about socket opertion.
important function is
pfkey_create,pfkey_sendmsg,pfkey_recvmsg,
pfkey_release,datagram_poll,
1 | static const struct proto_ops pfkey_ops = { |
###part 2. pf_key kernel message
1 | static struct xfrm_mgr pfkeyv2_mgr = |
in kernel 3.0, pf_key message format
A traditional TLV format.
header + (extenion-header + extention_value)*n
The header is sadb_msg.
extention header is sadb_ext.
extention value is different according the extention header.
Such as sadb_sa,sadb_x_policy and so on.
1 | struct sadb_msg { |
The application program(such as setkey) sent a command to kernel by sendmsg system API.
Thus in kernel pf_key will call pfkey_sendmsg.
pfkey_sendmsg will call pfkey_get_base_msg to do some simple check, and
then call pfkey_process.
pfkey_process will first pfkey_broadcast, then divid the extention message
to a pointer array one by one.void *ext_hdrs\[SADB_EXT_MAX\];
SADB_EXT_SA
—->SADB_EXT_ADDRESS_SRC
—->SADB_EXT_ADDRESS_DST
—->
this pointer array will be used by the following handler.
and then call the pfkey_handler according the sadb_msg_type in the pf_key messag header.
typedef int (*pfkey_handler)(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs);
1 | typedef int (*pfkey_handler)(struct sock *sk, struct sk_buff *skb, struct sadb_msg *hdr, void **ext_hdrs); |
The policy related function was done in xfrm_policy.c and xfrm_state.c
3.1 policy add handler: pfkey_spdadd
3.2 polcy dump handler: pfkey_spddump
function pfkey_xfrm_policy2msg
3.3 policy flush handler: pfkey_spdflush.
3.4 SA add handler:pfkey_add
3.2 SA dump handler:pfkey_dump
3.3 SA flush handler:pfkey_flush
目标: 在mipsel架构的嵌入式linux系统上支持USB盘的读写。
思路: 使用可加载模块的形式增加 scsimod.ko, sdmod.ko, usbstorage.ko, fat.ko, vfat.ko.
##具体实现:
###步骤I 准备必须的驱动(可加载模块)