220
技术社区[云栖]
网络子系统49_ip协议报头id选取
//more = skb_shinfo(skb)->tso_segs,由tcp传递
1.1 static inline void ip_select_ident_more(struct iphdr *iph, struct dst_entry *dst, struct sock *sk, int more)
{
if (iph->frag_off & htons(IP_DF)) {//禁止分片
if (sk && inet_sk(sk)->daddr) {
iph->id = htons(inet_sk(sk)->id);//使用sock中指定的id
inet_sk(sk)->id += 1 + more;//sock中id递增
} else
iph->id = 0;
} else
__ip_select_ident(iph, dst, more);//可分片ip报文选择id
}
//调用路径ip_select_ident_more->__ip_select_ident
//函数主要任务:
// 1.处理路由项与inet_peer的绑定
// 2.通过inet_peer,或者全局ip_fallback_id获取id
1.2 void __ip_select_ident(struct iphdr *iph, struct dst_entry *dst, int more)
{
struct rtable *rt = (struct rtable *) dst;
if (rt) {//存在到目的地址的路由
if (rt->peer == NULL)//inet_peer结构,表示该缓存路由项的目的ip地址对应的主机
rt_bind_peer(rt, 1);//寻找和该端点相匹配的inet_peer结构,如果不存在,尝试创建一个新的inet_peer
if (rt->peer) {//通过inet_peer的计数器,生成与接收方相关的递增id
iph->id = htons(inet_getid(rt->peer, more));
return;
}
} else
printk(KERN_DEBUG "rt_bind_peer(0) @%p\n", NET_CALLER(iph));
//之前尝试都失败,通过一个静态变量ip_fallback_id,再和端点的目的地ip地址结合,通过secure_ip_id获取id
ip_select_fb_ident(iph);
}
//调用路径ip_select_ident_more->__ip_select_ident->inet_getid
1.3 static inline __u16 inet_getid(struct inet_peer *p, int more)
{
__u16 id;
spin_lock_bh(&inet_peer_idlock);//获取一个全局的锁
id = p->ip_id_count;
p->ip_id_count += 1 + more;//更新inet_peer中的id计数器
spin_unlock_bh(&inet_peer_idlock);
return id;
}
最后更新:2017-04-03 14:53:41