@@ -15,9 +15,9 @@ the use of higher priority ip rules (Policy Based Routing, PBR) to take
15
15
precedence over the VRF device rules directing specific traffic as desired.
16
16
17
17
In addition, VRF devices allow VRFs to be nested within namespaces. For
18
- example network namespaces provide separation of network interfaces at L1
19
- (Layer 1 separation) , VLANs on the interfaces within a namespace provide
20
- L2 separation and then VRF devices provide L3 separation.
18
+ example network namespaces provide separation of network interfaces at the
19
+ device layer , VLANs on the interfaces within a namespace provide L2 separation
20
+ and then VRF devices provide L3 separation.
21
21
22
22
Design
23
23
------
@@ -37,45 +37,56 @@ are then enslaved to a VRF device:
37
37
+------+ +------+
38
38
39
39
Packets received on an enslaved device and are switched to the VRF device
40
- using an rx_handler which gives the impression that packets flow through
41
- the VRF device. Similarly on egress routing rules are used to send packets
42
- to the VRF device driver before getting sent out the actual interface. This
43
- allows tcpdump on a VRF device to capture all packets into and out of the
44
- VRF as a whole.[1] Similarly, netfilter [2] and tc rules can be applied
45
- using the VRF device to specify rules that apply to the VRF domain as a whole.
40
+ in the IPv4 and IPv6 processing stacks giving the impression that packets
41
+ flow through the VRF device. Similarly on egress routing rules are used to
42
+ send packets to the VRF device driver before getting sent out the actual
43
+ interface. This allows tcpdump on a VRF device to capture all packets into
44
+ and out of the VRF as a whole.[1] Similarly, netfilter[2] and tc rules can be
45
+ applied using the VRF device to specify rules that apply to the VRF domain
46
+ as a whole.
46
47
47
48
[1] Packets in the forwarded state do not flow through the device, so those
48
49
packets are not seen by tcpdump. Will revisit this limitation in a
49
50
future release.
50
51
51
- [2] Iptables on ingress is limited to NF_INET_PRE_ROUTING only with skb->dev
52
- set to real ingress device and egress is limited to NF_INET_POST_ROUTING.
53
- Will revisit this limitation in a future release.
54
-
52
+ [2] Iptables on ingress supports PREROUTING with skb->dev set to the real
53
+ ingress device and both INPUT and PREROUTING rules with skb->dev set to
54
+ the VRF device. For egress POSTROUTING and OUTPUT rules can be written
55
+ using either the VRF device or real egress device.
55
56
56
57
Setup
57
58
-----
58
59
1. VRF device is created with an association to a FIB table.
59
60
e.g, ip link add vrf-blue type vrf table 10
60
61
ip link set dev vrf-blue up
61
62
62
- 2. Rules are added that send lookups to the associated FIB table when the
63
- iif or oif is the VRF device. e.g.,
63
+ 2. An l3mdev FIB rule directs lookups to the table associated with the device.
64
+ A single l3mdev rule is sufficient for all VRFs. The VRF device adds the
65
+ l3mdev rule for IPv4 and IPv6 when the first device is created with a
66
+ default preference of 1000. Users may delete the rule if desired and add
67
+ with a different priority or install per-VRF rules.
68
+
69
+ Prior to the v4.8 kernel iif and oif rules are needed for each VRF device:
64
70
ip ru add oif vrf-blue table 10
65
71
ip ru add iif vrf-blue table 10
66
72
67
- Set the default route for the table (and hence default route for the VRF).
68
- e.g, ip route add table 10 prohibit default
73
+ 3. Set the default route for the table (and hence default route for the VRF).
74
+ ip route add table 10 unreachable default
69
75
70
- 3 . Enslave L3 interfaces to a VRF device.
71
- e.g, ip link set dev eth1 master vrf-blue
76
+ 4 . Enslave L3 interfaces to a VRF device.
77
+ ip link set dev eth1 master vrf-blue
72
78
73
79
Local and connected routes for enslaved devices are automatically moved to
74
80
the table associated with VRF device. Any additional routes depending on
75
- the enslaved device will need to be reinserted following the enslavement.
81
+ the enslaved device are dropped and will need to be reinserted to the VRF
82
+ FIB table following the enslavement.
83
+
84
+ The IPv6 sysctl option keep_addr_on_down can be enabled to keep IPv6 global
85
+ addresses as VRF enslavement changes.
86
+ sysctl -w net.ipv6.conf.all.keep_addr_on_down=1
76
87
77
- 4 . Additional VRF routes are added to associated table.
78
- e.g., ip route add table 10 ...
88
+ 5 . Additional VRF routes are added to associated table.
89
+ ip route add table 10 ...
79
90
80
91
81
92
Applications
@@ -87,39 +98,34 @@ VRF device:
87
98
88
99
or to specify the output device using cmsg and IP_PKTINFO.
89
100
101
+ TCP services running in the default VRF context (ie., not bound to any VRF
102
+ device) can work across all VRF domains by enabling the tcp_l3mdev_accept
103
+ sysctl option:
104
+ sysctl -w net.ipv4.tcp_l3mdev_accept=1
90
105
91
- Limitations
92
- -----------
93
- Index of original ingress interface is not available via cmsg. Will address
94
- soon.
106
+ netfilter rules on the VRF device can be used to limit access to services
107
+ running in the default VRF context as well.
108
+
109
+ The default VRF does not have limited scope with respect to port bindings.
110
+ That is, if a process does a wildcard bind to a port in the default VRF it
111
+ owns the port across all VRF domains within the network namespace.
95
112
96
113
################################################################################
97
114
98
115
Using iproute2 for VRFs
99
116
=======================
100
- VRF devices do *not* have to start with 'vrf-'. That is a convention used here
101
- for emphasis of the device type, similar to use of 'br' in bridge names.
117
+ iproute2 supports the vrf keyword as of v4.7. For backwards compatibility this
118
+ section lists both commands where appropriate -- with the vrf keyword and the
119
+ older form without it.
102
120
103
121
1. Create a VRF
104
122
105
123
To instantiate a VRF device and associate it with a table:
106
124
$ ip link add dev NAME type vrf table ID
107
125
108
- Remember to add the ip rules as well:
109
- $ ip ru add oif NAME table 10
110
- $ ip ru add iif NAME table 10
111
- $ ip -6 ru add oif NAME table 10
112
- $ ip -6 ru add iif NAME table 10
113
-
114
- Without the rules route lookups are not directed to the table.
115
-
116
- For example:
117
- $ ip link add dev vrf-blue type vrf table 10
118
- $ ip ru add pref 200 oif vrf-blue table 10
119
- $ ip ru add pref 200 iif vrf-blue table 10
120
- $ ip -6 ru add pref 200 oif vrf-blue table 10
121
- $ ip -6 ru add pref 200 iif vrf-blue table 10
122
-
126
+ As of v4.8 the kernel supports the l3mdev FIB rule where a single rule
127
+ covers all VRFs. The l3mdev rule is created for IPv4 and IPv6 on first
128
+ device create.
123
129
124
130
2. List VRFs
125
131
@@ -129,60 +135,61 @@ for emphasis of the device type, similar to use of 'br' in bridge names.
129
135
130
136
For example:
131
137
$ ip -d link show type vrf
132
- 11: vrf- mgmt: <NOARP,MASTER,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
138
+ 11: mgmt: <NOARP,MASTER,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
133
139
link/ether 72:b3:ba:91:e2:24 brd ff:ff:ff:ff:ff:ff promiscuity 0
134
140
vrf table 1 addrgenmode eui64
135
- 12: vrf- red: <NOARP,MASTER,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
141
+ 12: red: <NOARP,MASTER,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
136
142
link/ether b6:6f:6e:f6:da:73 brd ff:ff:ff:ff:ff:ff promiscuity 0
137
143
vrf table 10 addrgenmode eui64
138
- 13: vrf- blue: <NOARP,MASTER,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
144
+ 13: blue: <NOARP,MASTER,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
139
145
link/ether 36:62:e8:7d:bb:8c brd ff:ff:ff:ff:ff:ff promiscuity 0
140
146
vrf table 66 addrgenmode eui64
141
- 14: vrf- green: <NOARP,MASTER,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
147
+ 14: green: <NOARP,MASTER,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
142
148
link/ether e6:28:b8:63:70:bb brd ff:ff:ff:ff:ff:ff promiscuity 0
143
149
vrf table 81 addrgenmode eui64
144
150
145
151
146
152
Or in brief output:
147
153
148
154
$ ip -br link show type vrf
149
- vrf- mgmt UP 72:b3:ba:91:e2:24 <NOARP,MASTER,UP,LOWER_UP>
150
- vrf- red UP b6:6f:6e:f6:da:73 <NOARP,MASTER,UP,LOWER_UP>
151
- vrf- blue UP 36:62:e8:7d:bb:8c <NOARP,MASTER,UP,LOWER_UP>
152
- vrf- green UP e6:28:b8:63:70:bb <NOARP,MASTER,UP,LOWER_UP>
155
+ mgmt UP 72:b3:ba:91:e2:24 <NOARP,MASTER,UP,LOWER_UP>
156
+ red UP b6:6f:6e:f6:da:73 <NOARP,MASTER,UP,LOWER_UP>
157
+ blue UP 36:62:e8:7d:bb:8c <NOARP,MASTER,UP,LOWER_UP>
158
+ green UP e6:28:b8:63:70:bb <NOARP,MASTER,UP,LOWER_UP>
153
159
154
160
155
161
3. Assign a Network Interface to a VRF
156
162
157
163
Network interfaces are assigned to a VRF by enslaving the netdevice to a
158
164
VRF device:
159
- $ ip link set dev NAME master VRF- NAME
165
+ $ ip link set dev NAME master NAME
160
166
161
167
On enslavement connected and local routes are automatically moved to the
162
168
table associated with the VRF device.
163
169
164
170
For example:
165
- $ ip link set dev eth0 master vrf- mgmt
171
+ $ ip link set dev eth0 master mgmt
166
172
167
173
168
174
4. Show Devices Assigned to a VRF
169
175
170
176
To show devices that have been assigned to a specific VRF add the master
171
177
option to the ip command:
172
- $ ip link show master VRF-NAME
178
+ $ ip link show vrf NAME
179
+ $ ip link show master NAME
173
180
174
181
For example:
175
- $ ip link show master vrf- red
176
- 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master vrf- red state UP mode DEFAULT group default qlen 1000
182
+ $ ip link show vrf red
183
+ 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master red state UP mode DEFAULT group default qlen 1000
177
184
link/ether 02:00:00:00:02:02 brd ff:ff:ff:ff:ff:ff
178
- 4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master vrf- red state UP mode DEFAULT group default qlen 1000
185
+ 4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master red state UP mode DEFAULT group default qlen 1000
179
186
link/ether 02:00:00:00:02:03 brd ff:ff:ff:ff:ff:ff
180
- 7: eth5: <BROADCAST,MULTICAST> mtu 1500 qdisc noop master vrf- red state DOWN mode DEFAULT group default qlen 1000
187
+ 7: eth5: <BROADCAST,MULTICAST> mtu 1500 qdisc noop master red state DOWN mode DEFAULT group default qlen 1000
181
188
link/ether 02:00:00:00:02:06 brd ff:ff:ff:ff:ff:ff
182
189
183
190
184
191
Or using the brief output:
185
- $ ip -br link show master vrf- red
192
+ $ ip -br link show master red
186
193
eth1 UP 02:00:00:00:02:02 <BROADCAST,MULTICAST,UP,LOWER_UP>
187
194
eth2 UP 02:00:00:00:02:03 <BROADCAST,MULTICAST,UP,LOWER_UP>
188
195
eth5 DOWN 02:00:00:00:02:06 <BROADCAST,MULTICAST>
@@ -192,46 +199,48 @@ for emphasis of the device type, similar to use of 'br' in bridge names.
192
199
193
200
To list neighbor entries associated with devices enslaved to a VRF device
194
201
add the master option to the ip command:
195
- $ ip [-6] neigh show master VRF-NAME
202
+ $ ip [-6] neigh show vrf NAME
203
+ $ ip [-6] neigh show master NAME
196
204
197
205
For example:
198
- $ ip neigh show master vrf- red
206
+ $ ip neigh show vrf red
199
207
10.2.1.254 dev eth1 lladdr a6:d9:c7:4f:06:23 REACHABLE
200
208
10.2.2.254 dev eth2 lladdr 5e:54:01:6a:ee:80 REACHABLE
201
209
202
- $ ip -6 neigh show master vrf- red
210
+ $ ip -6 neigh show vrf red
203
211
2002:1::64 dev eth1 lladdr a6:d9:c7:4f:06:23 REACHABLE
204
212
205
213
206
214
6. Show Addresses for a VRF
207
215
208
216
To show addresses for interfaces associated with a VRF add the master
209
217
option to the ip command:
210
- $ ip addr show master VRF-NAME
218
+ $ ip addr show vrf NAME
219
+ $ ip addr show master NAME
211
220
212
221
For example:
213
- $ ip addr show master vrf- red
214
- 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master vrf- red state UP group default qlen 1000
222
+ $ ip addr show vrf red
223
+ 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master red state UP group default qlen 1000
215
224
link/ether 02:00:00:00:02:02 brd ff:ff:ff:ff:ff:ff
216
225
inet 10.2.1.2/24 brd 10.2.1.255 scope global eth1
217
226
valid_lft forever preferred_lft forever
218
227
inet6 2002:1::2/120 scope global
219
228
valid_lft forever preferred_lft forever
220
229
inet6 fe80::ff:fe00:202/64 scope link
221
230
valid_lft forever preferred_lft forever
222
- 4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master vrf- red state UP group default qlen 1000
231
+ 4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master red state UP group default qlen 1000
223
232
link/ether 02:00:00:00:02:03 brd ff:ff:ff:ff:ff:ff
224
233
inet 10.2.2.2/24 brd 10.2.2.255 scope global eth2
225
234
valid_lft forever preferred_lft forever
226
235
inet6 2002:2::2/120 scope global
227
236
valid_lft forever preferred_lft forever
228
237
inet6 fe80::ff:fe00:203/64 scope link
229
238
valid_lft forever preferred_lft forever
230
- 7: eth5: <BROADCAST,MULTICAST> mtu 1500 qdisc noop master vrf- red state DOWN group default qlen 1000
239
+ 7: eth5: <BROADCAST,MULTICAST> mtu 1500 qdisc noop master red state DOWN group default qlen 1000
231
240
link/ether 02:00:00:00:02:06 brd ff:ff:ff:ff:ff:ff
232
241
233
242
Or in brief format:
234
- $ ip -br addr show master vrf- red
243
+ $ ip -br addr show vrf red
235
244
eth1 UP 10.2.1.2/24 2002:1::2/120 fe80::ff:fe00:202/64
236
245
eth2 UP 10.2.2.2/24 2002:2::2/120 fe80::ff:fe00:203/64
237
246
eth5 DOWN
@@ -241,10 +250,11 @@ for emphasis of the device type, similar to use of 'br' in bridge names.
241
250
242
251
To show routes for a VRF use the ip command to display the table associated
243
252
with the VRF device:
253
+ $ ip [-6] route show vrf NAME
244
254
$ ip [-6] route show table ID
245
255
246
256
For example:
247
- $ ip route show table vrf- red
257
+ $ ip route show vrf red
248
258
prohibit default
249
259
broadcast 10.2.1.0 dev eth1 proto kernel scope link src 10.2.1.2
250
260
10.2.1.0/24 dev eth1 proto kernel scope link src 10.2.1.2
@@ -255,7 +265,7 @@ for emphasis of the device type, similar to use of 'br' in bridge names.
255
265
local 10.2.2.2 dev eth2 proto kernel scope host src 10.2.2.2
256
266
broadcast 10.2.2.255 dev eth2 proto kernel scope link src 10.2.2.2
257
267
258
- $ ip -6 route show table vrf- red
268
+ $ ip -6 route show vrf red
259
269
local 2002:1:: dev lo proto none metric 0 pref medium
260
270
local 2002:1::2 dev lo proto none metric 0 pref medium
261
271
2002:1::/120 dev eth1 proto kernel metric 256 pref medium
@@ -268,23 +278,24 @@ for emphasis of the device type, similar to use of 'br' in bridge names.
268
278
local fe80::ff:fe00:203 dev lo proto none metric 0 pref medium
269
279
fe80::/64 dev eth1 proto kernel metric 256 pref medium
270
280
fe80::/64 dev eth2 proto kernel metric 256 pref medium
271
- ff00::/8 dev vrf- red metric 256 pref medium
281
+ ff00::/8 dev red metric 256 pref medium
272
282
ff00::/8 dev eth1 metric 256 pref medium
273
283
ff00::/8 dev eth2 metric 256 pref medium
274
284
275
285
276
286
8. Route Lookup for a VRF
277
287
278
- A test route lookup can be done for a VRF by adding the oif option to ip:
279
- $ ip [-6] route get oif VRF-NAME ADDRESS
288
+ A test route lookup can be done for a VRF:
289
+ $ ip [-6] route get vrf NAME ADDRESS
290
+ $ ip [-6] route get oif NAME ADDRESS
280
291
281
292
For example:
282
- $ ip route get 10.2.1.40 oif vrf- red
283
- 10.2.1.40 dev eth1 table vrf- red src 10.2.1.2
293
+ $ ip route get 10.2.1.40 vrf red
294
+ 10.2.1.40 dev eth1 table red src 10.2.1.2
284
295
cache
285
296
286
- $ ip -6 route get 2002:1::32 oif vrf- red
287
- 2002:1::32 from :: dev eth1 table vrf- red proto kernel src 2002:1::2 metric 256 pref medium
297
+ $ ip -6 route get 2002:1::32 vrf red
298
+ 2002:1::32 from :: dev eth1 table red proto kernel src 2002:1::2 metric 256 pref medium
288
299
289
300
290
301
9. Removing Network Interface from a VRF
@@ -303,46 +314,40 @@ for emphasis of the device type, similar to use of 'br' in bridge names.
303
314
304
315
Commands used in this example:
305
316
306
- cat >> /etc/iproute2/rt_tables <<EOF
307
- 1 vrf- mgmt
308
- 10 vrf- red
309
- 66 vrf- blue
310
- 81 vrf- green
317
+ cat >> /etc/iproute2/rt_tables.d/vrf.conf <<EOF
318
+ 1 mgmt
319
+ 10 red
320
+ 66 blue
321
+ 81 green
311
322
EOF
312
323
313
324
function vrf_create
314
325
{
315
326
VRF=$1
316
327
TBID=$2
317
- # create VRF device
318
- ip link add vrf-${VRF} type vrf table ${TBID}
319
328
320
- # add rules that direct lookups to vrf table
321
- ip ru add pref 200 oif vrf-${VRF} table ${TBID}
322
- ip ru add pref 200 iif vrf-${VRF} table ${TBID}
323
- ip -6 ru add pref 200 oif vrf-${VRF} table ${TBID}
324
- ip -6 ru add pref 200 iif vrf-${VRF} table ${TBID}
329
+ # create VRF device
330
+ ip link add ${VRF} type vrf table ${TBID}
325
331
326
332
if [ "${VRF}" != "mgmt" ]; then
327
- ip route add table ${TBID} prohibit default
333
+ ip route add table ${TBID} unreachable default
328
334
fi
329
- ip link set dev vrf-${VRF} up
330
- ip link set dev vrf-${VRF} state up
335
+ ip link set dev ${VRF} up
331
336
}
332
337
333
338
vrf_create mgmt 1
334
- ip link set dev eth0 master vrf- mgmt
339
+ ip link set dev eth0 master mgmt
335
340
336
341
vrf_create red 10
337
- ip link set dev eth1 master vrf- red
338
- ip link set dev eth2 master vrf- red
339
- ip link set dev eth5 master vrf- red
342
+ ip link set dev eth1 master red
343
+ ip link set dev eth2 master red
344
+ ip link set dev eth5 master red
340
345
341
346
vrf_create blue 66
342
- ip link set dev eth3 master vrf- blue
347
+ ip link set dev eth3 master blue
343
348
344
349
vrf_create green 81
345
- ip link set dev eth4 master vrf- green
350
+ ip link set dev eth4 master green
346
351
347
352
348
353
Interface addresses from /etc/network/interfaces:
0 commit comments