网络管理

网络管理概述

../_images/ditaa-a2ded49c8b739635d6742479583443fb10ad120a.png

Sockets 实现概述

../_images/ditaa-79e3734c36891f6c04d684aa5caa39f76915dbaf.png

Sockets 系列和协议

../_images/ditaa-bf1244d1a5c3d99bd8d40148d81cb3e5748c0b94.png

示例:UDP 发送

char c;
struct sockaddr_in addr;
int s;

s = socket(AF_INET, SOCK_DGRAM, 0);
connect(s, (struct sockaddr*)&addr, sizeof(addr));
write(s, &c, 1);
close(s);

示例:UDP 发送

../_images/ditaa-ee04e3e544de75375b914f7645c79d5ae46fe6f3.png

网络处理阶段

数据包路由

../_images/ditaa-528948c80a3fd78b89fb6f7bd69503a58b93a4ae.png

路由表

tavi@desktop-tavi:~/src/linux$ ip route list table main
default via 172.30.240.1 dev eth0
172.30.240.0/20 dev eth0 proto kernel scope link src 172.30.249.241

tavi@desktop-tavi:~/src/linux$ ip route list table local
broadcast 127.0.0.0 dev lo proto kernel scope link src 127.0.0.1
local 127.0.0.0/8 dev lo proto kernel scope host src 127.0.0.1
local 127.0.0.1 dev lo proto kernel scope host src 127.0.0.1
broadcast 127.255.255.255 dev lo proto kernel scope link src 127.0.0.1
broadcast 172.30.240.0 dev eth0 proto kernel scope link src 172.30.249.241
local 172.30.249.241 dev eth0 proto kernel scope host src 172.30.249.241
broadcast 172.30.255.255 dev eth0 proto kernel scope link src 172.30.249.241

tavi@desktop-tavi:~/src/linux$ ip rule list
0:      from all lookup local
32766:  from all lookup main
32767:  from all lookup default

路由策略数据库

路由表处理

转发信息数据库(在 3.6 版本移除)

 

../_images/fidb-overview.png

转发信息数据库(在 3.6 版本移除)

../_images/fidb-details.png

路由缓存(在 3.6 版本移除)

 

../_images/routing-cache.png

FIB TRIE

 

../_images/fib-trie.png

Compressed Trie

 

../_images/fib-trie-compressed.png

Netfilter

网络数据包/skb

../_images/skb.png

结构 sk_buff

struct sk_buff {
    struct sk_buff *next;
    struct sk_buff *prev;

    struct sock *sk;
    ktime_t tstamp;
    struct net_device *dev;
    char cb[48];

    unsigned int len,
    data_len;
    __u16 mac_len,
    hdr_len;

    void (*destructor)(struct sk_buff *skb);

    sk_buff_data_t transport_header;
    sk_buff_data_t network_header;
    sk_buff_data_t mac_header;
    sk_buff_data_t tail;
    sk_buff_data_t end;

    unsigned char *head,
    *data;
    unsigned int truesize;
    atomic_t users;

skb APIs

/* 预留头部空间 */
void skb_reserve(struct sk_buff *skb, int len);

/* 在尾部添加数据 */
unsigned char *skb_put(struct sk_buff *skb, unsigned int len);

/* 在顶部添加数据 */
unsigned char *skb_push(struct sk_buff *skb, unsigned int len);

/* 丢弃顶部的数据 */
unsigned char *skb_pull(struct sk_buff *skb, unsigned int len);

/* 丢弃尾部的数据 */
unsigned char *skb_trim(struct sk_buff *skb, unsigned int len);

unsigned char *skb_transport_header(const struct sk_buff *skb);

void skb_reset_transport_header(struct sk_buff *skb);

void skb_set_transport_header(struct sk_buff *skb, const int offset);

unsigned char *skb_network_header(const struct sk_buff *skb);

void skb_reset_network_header(struct sk_buff *skb);

void skb_set_network_header(struct sk_buff *skb, const int offset);

unsigned char *skb_mac_header(const struct sk_buff *skb);

int skb_mac_header_was_set(const struct sk_buff *skb);

void skb_reset_mac_header(struct sk_buff *skb);

void skb_set_mac_header(struct sk_buff *skb, const int offset);

skb 数据管理

 

../_images/ditaa-91073cb05a3f537eb54ab10745c307531e6795a0.png

网络设备接口

../_images/net-dev-hw.png

高级特性

TCP 卸载

性能观察

无状态外包

TCP 分段外包

../_images/tso.png

大体量接收外包

../_images/lro.png