- 论坛徽章:
- 0
|
1, 初始化
对于每个ipv4的上层协议,如:icmp,udp,tcp,igmp,esp,ah 都会定义一个inet_protocol的结构,并把这些结构放入到ip上层的协议链中。
处理ip包时,若需要调用上层处理函数,就根据上层协议号调用协议链中的handler来进行处理。
若使用klips的话, esp,ah协议在ipsec_klips_init()函数中注册,其他的协议都在inet_init()函数中进行注册。
1.1 数据结构
ip上层协议注册数据结构: /* This is used to register protocols. */ struct net_protocol { int (*handler)(struct sk_buff *skb); void (*err_handler)(struct sk_buff *skb, u32 info); int (*gso_send_check)(struct sk_buff *skb); struct sk_buff *(*gso_segment)(struct sk_buff *skb, int features); int no_policy; };
static struct net_protocol udp_protocol = { .handler = udp_rcv, .err_handler = udp_err, .no_policy = 1, };
struct inet_protocol esp_protocol = { ipsec_rcv, /* ESP handler */ NULL, };
struct inet_protocol ah_protocol = { .handler = ipsec_rcv, .no_policy = 1, };
1.2 esp,ah协议的初始化流程:
ipsec_klips_init() | openswan_inet_add_protocol() //该函数就是调用内核的inet_add_protocol函数 | inet_add_protocol()
1.3 包的处理路径
ip_rcv() | ip_local_deliver() | ipsec_rcv() | ipsec_rcv_decap() | ipsec_rcv_decap_once()
|
|