• 网络协议源码分析


    从UDP开始看吧,udp_rcv时,数据包已经经过了驱动,网络层的层层过滤来到了传输层,在这里还是要经过层层的考验才会进入到最终socket

    重要数据结构:udp_table:

     67 /**
     68  *  struct udp_table - UDP table
     69  *  套接字都是本地创建的
     70  *  @hash:  hash table, sockets are hashed on (local port) 本地接收的
     71  *  @hash2: hash table, sockets are hashed on (local port, local address) 端口号和IP地址作为键值的索引
     72  *  @mask:  number of slots in hash tables, minus 1
     73  *  @log:   log2(number of slots in hash table)
     74  */
     75 struct udp_table {
     76     struct udp_hslot    *hash;
     77     struct udp_hslot    *hash2;
     78     unsigned int        mask;
     79     unsigned int        log;
     80 };

    54 /**
     55  *  struct udp_hslot - UDP hash slot
     56  *
     57  *  @head:  head of list of sockets
     58  *  @count: number of sockets in 'head' list
     59  *  @lock:  spinlock protecting changes to head/count
     60  */
     61 struct udp_hslot {
     62     struct hlist_head   head;
     63     int         count;
     64     spinlock_t      lock;
     65 } __attribute__((aligned(2 * sizeof(long))));
     66
     67 /**
     68  *  struct udp_table - UDP table
     

    inet_iif

    __udp_lib_lookup

    怎么样判断一个数据包在udp_table->hash中的哪个位置?根据接受到的数据包的目的端口地址,也就是说目的端口地址非常之重要;根据目的端口找到slot,然后遍历slot上所有的套接字 

    socket->sk_receive_queue 

    the to call receive_from to get packet from the kernel

  • 相关阅读:
    weblogic静默安装指导
    简单说一下 servlet的生命周期?
    简单讲一下 SpringMVC的执行流程?
    讲一下 Spring的事务传播特性
    Spring事务的隔离级别
    面试资料
    ArrayList 和 HashMap 的默认大小是多数?
    spring-mvc里的 <mvc:resources> 及静态资源访问
    说说Java中的资源文件的读取
    JVM-String常量池与运行时常量池
  • 原文地址:https://www.cnblogs.com/honpey/p/8673388.html
Copyright © 2020-2023  润新知