Skip to content

Commit 6e07653

Browse files
David Aherndavem330
authored andcommitted
net: vrf: Documentation update
Update vrf documentation for changes made to 4.4 - 4.8 kernels and iproute2 support for vrf keyword. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b38a75d commit 6e07653

File tree

1 file changed

+103
-98
lines changed

1 file changed

+103
-98
lines changed

Documentation/networking/vrf.txt

Lines changed: 103 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ the use of higher priority ip rules (Policy Based Routing, PBR) to take
1515
precedence over the VRF device rules directing specific traffic as desired.
1616

1717
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.
2121

2222
Design
2323
------
@@ -37,45 +37,56 @@ are then enslaved to a VRF device:
3737
+------+ +------+
3838

3939
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.
4647

4748
[1] Packets in the forwarded state do not flow through the device, so those
4849
packets are not seen by tcpdump. Will revisit this limitation in a
4950
future release.
5051

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.
5556

5657
Setup
5758
-----
5859
1. VRF device is created with an association to a FIB table.
5960
e.g, ip link add vrf-blue type vrf table 10
6061
ip link set dev vrf-blue up
6162

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:
6470
ip ru add oif vrf-blue table 10
6571
ip ru add iif vrf-blue table 10
6672

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
6975

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
7278

7379
Local and connected routes for enslaved devices are automatically moved to
7480
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
7687

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 ...
7990

8091

8192
Applications
@@ -87,39 +98,34 @@ VRF device:
8798

8899
or to specify the output device using cmsg and IP_PKTINFO.
89100

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
90105

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.
95112

96113
################################################################################
97114

98115
Using iproute2 for VRFs
99116
=======================
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.
102120

103121
1. Create a VRF
104122

105123
To instantiate a VRF device and associate it with a table:
106124
$ ip link add dev NAME type vrf table ID
107125

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.
123129

124130
2. List VRFs
125131

@@ -129,60 +135,61 @@ for emphasis of the device type, similar to use of 'br' in bridge names.
129135

130136
For example:
131137
$ 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
133139
link/ether 72:b3:ba:91:e2:24 brd ff:ff:ff:ff:ff:ff promiscuity 0
134140
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
136142
link/ether b6:6f:6e:f6:da:73 brd ff:ff:ff:ff:ff:ff promiscuity 0
137143
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
139145
link/ether 36:62:e8:7d:bb:8c brd ff:ff:ff:ff:ff:ff promiscuity 0
140146
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
142148
link/ether e6:28:b8:63:70:bb brd ff:ff:ff:ff:ff:ff promiscuity 0
143149
vrf table 81 addrgenmode eui64
144150

145151

146152
Or in brief output:
147153

148154
$ 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>
153159

154160

155161
3. Assign a Network Interface to a VRF
156162

157163
Network interfaces are assigned to a VRF by enslaving the netdevice to a
158164
VRF device:
159-
$ ip link set dev NAME master VRF-NAME
165+
$ ip link set dev NAME master NAME
160166

161167
On enslavement connected and local routes are automatically moved to the
162168
table associated with the VRF device.
163169

164170
For example:
165-
$ ip link set dev eth0 master vrf-mgmt
171+
$ ip link set dev eth0 master mgmt
166172

167173

168174
4. Show Devices Assigned to a VRF
169175

170176
To show devices that have been assigned to a specific VRF add the master
171177
option to the ip command:
172-
$ ip link show master VRF-NAME
178+
$ ip link show vrf NAME
179+
$ ip link show master NAME
173180

174181
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
177184
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
179186
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
181188
link/ether 02:00:00:00:02:06 brd ff:ff:ff:ff:ff:ff
182189

183190

184191
Or using the brief output:
185-
$ ip -br link show master vrf-red
192+
$ ip -br link show master red
186193
eth1 UP 02:00:00:00:02:02 <BROADCAST,MULTICAST,UP,LOWER_UP>
187194
eth2 UP 02:00:00:00:02:03 <BROADCAST,MULTICAST,UP,LOWER_UP>
188195
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.
192199

193200
To list neighbor entries associated with devices enslaved to a VRF device
194201
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
196204

197205
For example:
198-
$ ip neigh show master vrf-red
206+
$ ip neigh show vrf red
199207
10.2.1.254 dev eth1 lladdr a6:d9:c7:4f:06:23 REACHABLE
200208
10.2.2.254 dev eth2 lladdr 5e:54:01:6a:ee:80 REACHABLE
201209

202-
$ ip -6 neigh show master vrf-red
210+
$ ip -6 neigh show vrf red
203211
2002:1::64 dev eth1 lladdr a6:d9:c7:4f:06:23 REACHABLE
204212

205213

206214
6. Show Addresses for a VRF
207215

208216
To show addresses for interfaces associated with a VRF add the master
209217
option to the ip command:
210-
$ ip addr show master VRF-NAME
218+
$ ip addr show vrf NAME
219+
$ ip addr show master NAME
211220

212221
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
215224
link/ether 02:00:00:00:02:02 brd ff:ff:ff:ff:ff:ff
216225
inet 10.2.1.2/24 brd 10.2.1.255 scope global eth1
217226
valid_lft forever preferred_lft forever
218227
inet6 2002:1::2/120 scope global
219228
valid_lft forever preferred_lft forever
220229
inet6 fe80::ff:fe00:202/64 scope link
221230
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
223232
link/ether 02:00:00:00:02:03 brd ff:ff:ff:ff:ff:ff
224233
inet 10.2.2.2/24 brd 10.2.2.255 scope global eth2
225234
valid_lft forever preferred_lft forever
226235
inet6 2002:2::2/120 scope global
227236
valid_lft forever preferred_lft forever
228237
inet6 fe80::ff:fe00:203/64 scope link
229238
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
231240
link/ether 02:00:00:00:02:06 brd ff:ff:ff:ff:ff:ff
232241

233242
Or in brief format:
234-
$ ip -br addr show master vrf-red
243+
$ ip -br addr show vrf red
235244
eth1 UP 10.2.1.2/24 2002:1::2/120 fe80::ff:fe00:202/64
236245
eth2 UP 10.2.2.2/24 2002:2::2/120 fe80::ff:fe00:203/64
237246
eth5 DOWN
@@ -241,10 +250,11 @@ for emphasis of the device type, similar to use of 'br' in bridge names.
241250

242251
To show routes for a VRF use the ip command to display the table associated
243252
with the VRF device:
253+
$ ip [-6] route show vrf NAME
244254
$ ip [-6] route show table ID
245255

246256
For example:
247-
$ ip route show table vrf-red
257+
$ ip route show vrf red
248258
prohibit default
249259
broadcast 10.2.1.0 dev eth1 proto kernel scope link src 10.2.1.2
250260
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.
255265
local 10.2.2.2 dev eth2 proto kernel scope host src 10.2.2.2
256266
broadcast 10.2.2.255 dev eth2 proto kernel scope link src 10.2.2.2
257267

258-
$ ip -6 route show table vrf-red
268+
$ ip -6 route show vrf red
259269
local 2002:1:: dev lo proto none metric 0 pref medium
260270
local 2002:1::2 dev lo proto none metric 0 pref medium
261271
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.
268278
local fe80::ff:fe00:203 dev lo proto none metric 0 pref medium
269279
fe80::/64 dev eth1 proto kernel metric 256 pref medium
270280
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
272282
ff00::/8 dev eth1 metric 256 pref medium
273283
ff00::/8 dev eth2 metric 256 pref medium
274284

275285

276286
8. Route Lookup for a VRF
277287

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
280291

281292
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
284295
cache
285296

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
288299

289300

290301
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.
303314

304315
Commands used in this example:
305316

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
311322
EOF
312323

313324
function vrf_create
314325
{
315326
VRF=$1
316327
TBID=$2
317-
# create VRF device
318-
ip link add vrf-${VRF} type vrf table ${TBID}
319328

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}
325331

326332
if [ "${VRF}" != "mgmt" ]; then
327-
ip route add table ${TBID} prohibit default
333+
ip route add table ${TBID} unreachable default
328334
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
331336
}
332337

333338
vrf_create mgmt 1
334-
ip link set dev eth0 master vrf-mgmt
339+
ip link set dev eth0 master mgmt
335340

336341
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
340345

341346
vrf_create blue 66
342-
ip link set dev eth3 master vrf-blue
347+
ip link set dev eth3 master blue
343348

344349
vrf_create green 81
345-
ip link set dev eth4 master vrf-green
350+
ip link set dev eth4 master green
346351

347352

348353
Interface addresses from /etc/network/interfaces:

0 commit comments

Comments
 (0)