route table
=====================================================
IPROUTE2 不能创建虚拟设备,但能给网卡分配不同子网的同一地址
如:192.168.0.1/24 和 192.168.0.1/25
ifconfig 可以创建虚拟设备 如:ifconfig eth0:5 192.168.5.1
linux 路由使用route table 和 route cache
linux 路由寻找规则
Cache
|
| hit
|---------------->|
| |
|Miss |
| |
Local address |
lookup |
| |
| hit |
----------------->|
| |
| |
|Miss |
| |
Remote address |
lookup |
| |
| hit |
|---------------->|
| |
| |
|Miss |
| |
| |
Drop packet Route/deliver packet
多路选择
1.)通过指定weight可以按比例分配流量
2.)多路选择有时会不可用
3.)2.6.12内核开始支持多路选择cache
多路选择对cache的查找方法
1.)随机。这种方法比较简单,实现平均分配
2.)权重随机。这种方法按比例分配流量,但不是轮流选择 //产生随机数
//寻找大于等于的权重
//每次都会减去当前权重
3.)轮流选择。轮流按次序选择。
4.)按设备轮流选择。轮流选择设备发送
在IPROUTE2Z中,脚本未指明mpath则默认mulitpath cache未打开
流的区别在于源IP或目的IP不同
IPROUTE2可以按“每个流”“每个连接”“每个包”来分派流量
hlist_head 与 hlist_node 的区别
===================================================================
hlist_head就包含一个元素------hlist_node
hlist_node是个双向链表,包含两个元素,指向前面一个和后面那个
in_ifaddr中为主机含有多个地址的情况定义了优先级,使用了IFA_F_SECONDARY定义第二优先级,
但没有用IFA_F_PRIMARY定义第一优先级,因为除了第二优先级就是第一优先级
当NETDEV_UP事件时,系统调用fib_add_ifaddr
当NETDEV_DOWN事件时,系统调用fib_del_ifaddr
===================================================================
neigh_lookup之类函数获得neighbour后需要判断其状态,用户态函数调用获得MAC也是这样需要判断
===================================================================
ip_route_input //收到数据包后的一个动作,判断数据包delivered locally,
//forwarded, or dropped,可查找是否可到目标
ip_route_output_slow //发送前被调用,返回网关和出口设备
===================================================================
19-2
When the L4 checksum is computed in hardware by the network card,
it could include the L2 padding if the card is not smart enough to leave it out.
Since here there is no way to know whether that was the case, to be on the safe side,
pskb_trim_rcsum simply invalidates the checksum and forces the L4 protocol to recompute it.
if (pskb_trim_rcsum(skb, len)) {
IP_INC_STATS_BH(IPSTATS_MIB_INDISCARDS);
goto drop;
}
为什么要这样呢?难道L2的checksum计算有误,把多余数据一起计算了?那NIC还支持checksum功能干啥呢?
有点奇怪
===================================================================
ip_fast_csum //快速计算IP checksum
nf_register_hook //添加HOOK,可以实现数据包过滤