-
Notifications
You must be signed in to change notification settings - Fork 130
/
net_topology
180 lines (158 loc) · 6.28 KB
/
net_topology
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
=============================================================================
TOP1 (Use tapip instead of linux kernel TCP/IP stack)
=============================================================================
+----------+
| internet |
+----|-----+
+----|-----+
| eth0 |
+----|-----+
+----|-----+
| bridge |
+----|-----+
+----|---------+
| tap0 |
|--------------|
| /dev/net/tun |
+--|----|---|--+
poll | |
| read |
| | write
+--|----|---|--+
| my netstack |
+--------------+
=============================================================================
real network of TOP1
gateway (10.20.133.20)
|
eth0 (0.0.0.0)
|
br0 (0.0.0.0)
|
tap0
(0.0.0.0)
|
/dev/net/tun
|
veth0 (10.20.133.21)
usermode
network
=============================================================================
How to build net environment of TOP1
# (set "CONFIG_TOP = 1" in global Makefile)
# (config real net environment in doc/brctl.sh)
# ./doc/brctl.sh open (run as root)
# ./tapip (run as root)
[net shell]: (run some commands)
...
# ./doc/brctl.sh close (run as root)
=============================================================================
kernel-usermode stream of TOP1 ( usermode network stack receiving packet )
network
|
| packet recv
\|/
xxx_interrupt() --> netif_rx()
{ eth0 } |
|
|
.----------------------'
| raise irq
\|/
softirq: net_rx_action() --> netif_receive_skb() --> handle_bridge()
{ br0 }
|
|
.------------------------------------------------------'
|
\|/
dev_queue_xmit(skb) --> tun_net_xmit()
[skb->dev == tap0] 1. put skb into tun's skbqueue
2. wake up process(./tapip) waiting
for /dev/net/tun (read/poll)
|
|
\|/
process (read/poll)
( ./tapip )
{ usermode network stack }
=============================================================================
kernel-usermode stream of TOP1 ( usermode network stack sending packet )
usermode
network
stack
|
| write
\|/
/dev/net/tun --> tun_chr_aio_write() --> tun_get_user()
1. copy data from usermode
2. make skb(sending packet)
3. netif_rx_ni
|
|
.-----------------------------------------'
|
\|/
netif_rx(skb)
1. put packet into queue
2. raise softirq
|
\|/
softirq: net_rx_action() --> netif_receive_skb() --> handle_bridge()
{ br0 }
|
|
.------------------------------------------------------'
|
\|/
dev_queue_xmit(skb) --> {eth0 netdevice}_hard_xmit()
[skb->dev == eth0] |
| packet send
\|/
network
=============================================================================
TOP2 (tapip communicates with kernel TCP/IP stack)
=============================================================================
localhost outside network
kernel stack usermode stack [ ./tapip ]
| (10.0.0.1)
| (write) | . (read)
| \|/ /|\
| ' |
tap0 <---- netif_rx() -----/dev/net/tun
(10.0.0.2) `-- tun_net_xmit() ------------^
=============================================================================
arping model of TOP2
The following diagram shows arp packet flow of command `# arping 10.0.0.1`.
Refer to https://github.com/chobits/tapip/blob/master/doc/test#L18 for how to
run this test.
tap0
(10.0.0.2)
route:
Destination Use Iface
10.0.0.0 tap0
+-------------------[Linux kernel TCP/IP stack]---------------------+
| |
arping 10.0.0.1 -----> socket send --> route --> tap0 --> tap0::dev_hard_xmit |
| ( arp packet: | |
| 10.0.0.2 request | |
| hwaddr of 10.0.0.1) | _tap0 (10.0.0.2)_ |
| | |
arping received <----- socket recv <-- tap0(netif_rx) <----. | |
| | | |
+-----------------------------------------|--|----------------------+
| |
/dev/net/tun
| |
(write) | | (read)
| |
.--------> reply --> netdev_tx-' | _veth (10.0.0.1)_
| \|/
| '
'- arp_in <-- netif_in <----- process
update arp cache <------' { usermode network stack }
[ route module and netif_rx() are from linux kernel ]
NOTE: 10.0.0.2 is tap0 ip address, not our network stack ip address.
Our network stack(veth) is `outside network` in terms of tap0,
so our program is just an emulator of outside network,
we must assign a fake ip address(10.0.0.1) for ./tapip virtual netif veth!