网络子系统49_ip协议报头id选取

来源:互联网 发布:高德地图提示网络错误 编辑:程序博客网 时间:2024/06/11 16:22
//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中指定的idinet_sk(sk)->id += 1 + more;//sock中id递增} elseiph->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获取id1.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_peerif (rt->peer) {//通过inet_peer的计数器,生成与接收方相关的递增idiph->id = htons(inet_getid(rt->peer, more));return;}} elseprintk(KERN_DEBUG "rt_bind_peer(0) @%p\n", NET_CALLER(iph));//之前尝试都失败,通过一个静态变量ip_fallback_id,再和端点的目的地ip地址结合,通过secure_ip_id获取idip_select_fb_ident(iph);}//调用路径ip_select_ident_more->__ip_select_ident->inet_getid1.3 static inline __u16inet_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;}

原创粉丝点击