发新话题
打印

[随意] "协议栈相关函数注释"在完美论坛只是灌水!?

本主题由 鸡气猫 于 2008-7-23 13:47 分类

"协议栈相关函数注释"在完美论坛只是灌水!?

我很无奈!

原帖http://bbs.ye-soft.net/thread-9169-1-1.html被移动到灌水区?

此贴在喊疼----核心技术专版却成为精品文章

http://www.htforever.cn/thread-1551-1-1.html

协议栈相关函数注释

static inline int ip_finish_output2(struct sk_buff *skb)
{
struct dst_entry *dst = skb->dst;
struct hh_cache *hh = dst->hh;
#ifdef CONFIG_NETFILTER_DEBUG
nf_debug_ip_finish_output2(skb);
#endif /*CONFIG_NETFILTER_DEBUG*/
      /*/如果该dst_entry(相当于我们自己的contrace)已经发送
      过数据,那么在dst中就已经包含了相关的硬件头信息*/
if (hh) {
  read_lock_bh(&hh->hh_lock);
  //将硬件头信息拷贝到skb的head中
    memcpy(skb->data - 16, hh->hh_data, 16);
  read_unlock_bh(&hh->hh_lock);
  //在包体前部扩展长度为len的数据块, 返回扩展块的地址,
  //该函数为未校验版本
         skb_push(skb, hh->hh_len);/*实际上是调用dev_queue_xmit*/
  return hh->hh_output(skb);
} else if (dst->neighbour)
  return dst->neighbour->output(skb);/*neigh_resolve_output,在硬件地址解析结束后,都是调用dev_queue_xmit*/
/* arp.c中定义了hh_output:  dev_queue_xmit,
hh 就是通过arp解析得来的 ,hh不空表示需要进行arp然后dev_queue_xmit
static struct neigh_ops arp_hh_ops = {
  family:   AF_INET,
  solicit:  arp_solicit,
  error_report:  arp_error_report,
  output:   neigh_resolve_output,
  connected_output: neigh_resolve_output,
  hh_output:  dev_queue_xmit,
  queue_xmit:  dev_queue_xmit,
};
*/
if (net_ratelimit())
  printk(KERN_DEBUG "ip_finish_output2: No header cache and no neighbour!\n");
kfree_skb(skb);
return -EINVAL;
}


int ip_forward(struct sk_buff *skb)
{
        struct net_device *dev2;        /* Output device */
        struct iphdr *iph;        /* Our header */
        struct rtable *rt;        /* Route we use */
        struct ip_options * opt        = &(IPCB(skb)->opt);
        unsigned short mtu;

        if (IPCB(skb)->opt.router_alert && ip_call_ra_chain(skb))
                return NET_RX_SUCCESS;

        if (skb->pkt_type != PACKET_HOST)/*广播报,多播,混杂模式得到的包不允许转发*/
                goto drop;
        
        /*
         *        According to the RFC, we must first decrease the TTL field. If
         *        that reaches zero, we must reply an ICMP control message telling
         *        that the packet's lifetime expired.
         */

        iph = skb->nh.iph;
        rt = (struct rtable*)skb->dst;                        /*到这里,这个包的skb->dst肯定是有内容的*/

        if (iph->ttl <= 1)                        /*TTL值太小了。*/
                goto too_many_hops;

        if (opt->is_strictroute && rt->rt_dst != rt->rt_gateway)                        /*如果路由选出的源路由包的下一站不是网关,丢弃这个包*/
                goto sr_failed;

        /*
         *        Having picked a route we can now send the frame out
         *        after asking the firewall permission to do so.
         */

        skb->priority = rt_tos2priority(iph->tos);                /*优先级*/
        dev2 = rt->u.dst.dev;                /*通过这个设备发送出去*/
        mtu = rt->u.dst.pmtu;                /*得到这个设备连接网络的mtu*/

        /*
         *        We now generate an ICMP HOST REDIRECT giving the route
         *        we calculated.
         */

        /*路由重新定向且没有源路由选项的时候,必须产生一个重定向的icmp包*/
        if (rt->rt_flags&RTCF_DOREDIRECT && !opt->srr)
                /*重新定向*/
                ip_rt_send_redirect(skb);

        /* We are about to mangle packet. Copy it! */
        if ((skb = skb_cow(skb, dev2->hard_header_len)) == NULL)                /*重新组织这个SKBUFF结构*/
                return NET_RX_DROP;
        iph = skb->nh.iph;
        opt = &(IPCB(skb)->opt);

        /* Decrease ttl after skb cow done */
        /*减少ttl,当然也要重新计算校验和*/
        ip_decrease_ttl(iph);

        /*
         * We now may allocate a new buffer, and copy the datagram into it.
         * If the indicated interface is up and running, kick it.
         */

        if (skb->len > mtu && (ntohs(iph->frag_off) & IP_DF))                /*如果设置了不分片,但是这个包需要分片,发送icmp包*/
                goto frag_needed;

#ifdef CONFIG_IP_ROUTE_NAT
        if (rt->rt_flags & RTCF_NAT) {        /*如果编译了nat转换且这条路由是要NAT转换的*/
                if (ip_do_nat(skb)) {                /*NAT地址转换处理*/
                        kfree_skb(skb);
                        return NET_RX_BAD;
                }
        }
#endif
        /*转发检测点,检测完后若不丢弃,调用ip_forward_finish*/
        return NF_HOOK(PF_INET, NF_IP_FORWARD, skb, skb->dev, dev2,
                       ip_forward_finish);

frag_needed:
        /*设置了DF,而需要分片的时候到这里处理*/
        IP_INC_STATS_BH(IpFragFails);
        icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED, htonl(mtu));
        goto drop;

sr_failed:
        /*
         *        Strict routing permits no gatewaying
         */
         icmp_send(skb, ICMP_DEST_UNREACH, ICMP_SR_FAILED, 0);
         goto drop;

too_many_hops:
        /* Tell the sender its packet died... */
        icmp_send(skb, ICMP_TIME_EXCEEDED, ICMP_EXC_TTL, 0);
drop:
        kfree_skb(skb);
        return NET_RX_DROP;
}

static inline int ip_forward_finish(struct sk_buff *skb)
{
        struct ip_options * opt        = &(IPCB(skb)->opt);                /*opt指向选项*/

        IP_INC_STATS_BH(IpForwDatagrams);

        if (opt->optlen == 0) {
#ifdef CONFIG_NET_FASTROUTE
                struct rtable *rt = (struct rtable*)skb->dst;

                if (rt->rt_flags&RTCF_FAST && !netdev_fastroute_obstacles) {
                        struct dst_entry *old_dst;
                        unsigned h = ((*(u8*)&rt->key.dst)^(*(u8*)&rt->key.src))&NETDEV_FASTROUTE_HMASK;

                        write_lock_irq(&skb->dev->fastpath_lock);
                        old_dst = skb->dev->fastpath[h];
                        skb->dev->fastpath[h] = dst_clone(&rt->u.dst);
                        write_unlock_irq(&skb->dev->fastpath_lock);

                        dst_release(old_dst);
                }
#endif
                return (ip_send(skb));
        }

        ip_forward_options(skb);                /*转发时候的选项处理*/
        return (ip_send(skb));                        /*发送包*/
}

static inline int ip_send(struct sk_buff *skb)
{
        if (skb->len > skb->dst->pmtu)                /*判断是否需要分片*/
                return ip_fragment(skb, ip_finish_output);                /*分片发送,ip_finish_output是分片完以后的回调函数*/
        else
                return ip_finish_output(skb);                /*转发处理结束,发送出去*/
}

__inline__ int ip_finish_output(struct sk_buff *skb)
{
        struct net_device *dev = skb->dst->dev;

        skb->dev = dev;                /*设置发送的设备*/
        skb->protocol = __constant_htons(ETH_P_IP);                /*发送包的协议类型*/


        /*发送之前的检测,如果没有丢弃,调用ip_finish_output2*/
        return NF_HOOK(PF_INET, NF_IP_POST_ROUTING, skb, NULL, dev,
                       ip_finish_output2);
}

static inline int ip_finish_output2(struct sk_buff *skb)
{
        struct dst_entry *dst = skb->dst;
        struct hh_cache *hh = dst->hh;

#ifdef CONFIG_NETFILTER_DEBUG
        nf_debug_ip_finish_output2(skb);
#endif /*CONFIG_NETFILTER_DEBUG*/

        if (hh) {                /*有硬件缓存结构*/
                read_lock_bh(&hh->hh_lock);
                  memcpy(skb->data - 16, hh->hh_data, 16);
                read_unlock_bh(&hh->hh_lock);
                skb_push(skb, hh->hh_len);
                return hh->hh_output(skb);                /*实际上是调用dev_queue_xmit*/
        } else if (dst->neighbour)
                return dst->neighbour->output(skb);                /*neigh_resolve_output,在硬件地址解析结束后,都是调用dev_queue_xmit*/

        printk(KERN_DEBUG "khm\n");
        kfree_skb(skb);
        return -EINVAL;
}

TOP

哪位版主移的?
C语言的吧,看着头晕,源码应该不全,连头文件什么的都没有
坛在我在,坛亡我亡!

TOP

引用:
原帖由 lvehe 于 2008-7-22 20:33 发表
哪位版主移的?
C语言的吧,看着头晕,源码应该不全,连头文件什么的都没有
这是相关函数注释,不是编译时用的代码
要开头文件当然要自己编写了

TOP

引用:
原帖由 chentiyi 于 2008-7-22 20:36 发表

这是相关函数注释,不是编译时用的代码
要开头文件当然要自己编写了
没仔细看,惭愧
坛在我在,坛亡我亡!

TOP

为什么要移走呢????????
今天,你咒死马化腾了吗?

TOP

管理员移动的~~~~
管理员是谁

来也匆匆去也冲冲

TOP

回复 6楼 的帖子

管理员就是管理员喽~


CNPDA-The First Intelligent Phone Station


My Technilogy Space


PS:双显的帖子被一个XE的人水产了,是谁?

TOP

应该是VC的……

TOP

回复 7楼 的帖子

呵呵。。。我知道管理员是谁~~~
只是随便问问罢了。。。

我替你移动到综合讨论去吧

来也匆匆去也冲冲

TOP

回复 9楼 的帖子

管理员是不是完美的老大?

TOP

发新话题