从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