去看看内核sock数据包流经过程就会比较清晰了。
一下是引用“端木隐”大哥的总结。
貌似这位大哥这两年隐居了。
QUOTE:5个挂接点
以下内核代码版本2.6.17.11。
1.1 PREROTING
/* net/ipv4/ip_input.c */
int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
{
......
return NF_HOOK(PF_INET, NF_IP_PRE_ROUTING, skb, dev, NULL,
         ip_rcv_finish);
......
}
1.2 INPUT
/* net/ipv4/ip_input.c */
int ip_local_deliver(struct sk_buff *skb)
{
......
return NF_HOOK(PF_INET, NF_IP_LOCAL_IN, skb, skb->dev, NULL,
         ip_local_deliver_finish);
}
1.3 FORWARD
/* net/ipv4/ip_forward.c */
int ip_forward(struct sk_buff *skb)
{
......
return NF_HOOK(PF_INET, NF_IP_FORWARD, skb, skb->dev, rt->u.dst.dev,
         ip_forward_finish);
......
}
1.4 OUTPUT
/* net/ipv4/ip_output.c */
int ip_build_and_send_pkt(struct sk_buff *skb, struct sock *sk,
     u32 saddr, u32 daddr, struct ip_options *opt)
{
......
return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
         dst_output);
}
int ip_queue_xmit(struct sk_buff *skb, int ipfragok)
{
......
return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,
         dst_output);
......
}
int ip_push_pending_frames(struct sock *sk)
{
......
/* Netfilter gets whole the not fragmented skb. */
err = NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL,
        skb->dst->dev, dst_output);
......
}
1.5 POSTROUTING
/* net/ipv4/ip_output.c */
int ip_output(struct sk_buff *skb)
{
struct net_device *dev = skb->dst->dev;
IP_INC_STATS(IPSTATS_MIB_OUTREQUESTS);
skb->dev = dev;
skb->protocol = htons(ETH_P_IP);
return NF_HOOK_COND(PF_INET, NF_IP_POST_ROUTING, skb, NULL, dev,
              ip_finish_output,
       !(IPCB(skb)->flags & IPSKB_REROUTED));
}
以下是2.6.25的 ,但是 NF_INET_POST_ROUTING 我没看到定义????奇怪了!!!
# 1.4 OUTPUT  
# /* net/ipv4/ip_output.c */  
# int ip_build_and_send_pkt(struct sk_buff *skb, struct sock *sk,  
#   __be32 saddr, __be32 daddr, struct ip_options *opt)  
# {  
# ......  
# return NF_HOOK(PF_INET, NF_IP_LOCAL_OUT, skb, NULL, rt->u.dst.dev,  
#          dst_output);  
# }  
#   
# int __ip_local_out(struct sk_buff *skb)  
# {  
#     struct iphdr *iph = ip_hdr(skb);  
#   
#     iph->tot_len = htons(skb->len);  
#     ip_send_check(iph);  
#     return nf_hook(PF_INET, NF_INET_LOCAL_OUT, skb, NULL, skb->dst->dev,dst_output);  
# }  
# 1.5 POSTROUTING  
#   
# /* net/ipv4/ip_output.c */  
#   
# int ip_mc_output(struct sk_buff *skb)  
# {  
#  ......  
# return NF_HOOK_COND(PF_INET, NF_INET_POST_ROUTING, skb, NULL, skb->dev,ip_finish_output,!(IPCB(skb)->flags & IPSKB_REROUTED));  
# }  
#   
# int ip_output(struct sk_buff *skb)  
# {  
# ......  
#     return NF_HOOK_COND(PF_INET, NF_INET_POST_ROUTING, skb, NULL, dev,ip_finish_output,!(IPCB(skb)->flags & IPSKB_REROUTED));  
# ......  
# }  
[ 本帖最后由 C__J 于 2009-5-5 02:07 编辑 ]