Skip to content

Commit 5a1ae53

Browse files
author
Harish Venkatraman
committed
[sonic-buildimage] New feature managementVRF(L3mdev)
This commit adds support for New feature management VRF using L3mdev. Added commands to enable/disable management VRF. Config vrf add mgmt will enable management VRF, enslave the eth0 device to the master device mgmt and restart interfaces-configs in mgmt-vrf context. management interface (eth0) can be configured using config interface eth0 ip add command and removed using config interface eth0 ip remove command. Requirement and design are covered in mgmt vrf design document. Currently show command displays linux command output; will update show command display in next PR after concluding what would be the output for the show commands. Added metric for default routes in dhcp and static, any changes for metric will be addressed subsequently after discussing. Signed-off-by: Harish Venkatraman <[email protected]>
1 parent 401f704 commit 5a1ae53

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

build_debian.sh

+1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install \
205205
## Note: don't install python-apt by pip, older than Debian repo one
206206
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install \
207207
file \
208+
ifmetric \
208209
iproute2 \
209210
bridge-utils \
210211
isc-dhcp-client \

files/image_config/interfaces/interfaces.j2

+32-8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55
# file: /etc/network/interfaces
66
#
77
{% endblock banner %}
8+
{% if (MGMT_VRF_CONFIG) and (MGMT_VRF_CONFIG['vrf_global']['mgmtVrfEnabled'] == "true") %}
9+
auto mgmt
10+
iface mgmt
11+
vrf-table 5000
12+
{% endif %}
813
{% block loopback %}
914
# The loopback network interface
1015
auto lo
@@ -26,25 +31,44 @@ auto eth0
2631
iface eth0 {{ 'inet' if prefix | ipv4 else 'inet6' }} static
2732
address {{ prefix | ip }}
2833
netmask {{ prefix | netmask if prefix | ipv4 else prefix | prefixlen }}
34+
{% set vrf_table = 'default' %}
35+
{% if (MGMT_VRF_CONFIG) and (MGMT_VRF_CONFIG['vrf_global']['mgmtVrfEnabled'] == "true") %}
36+
{% set vrf_table = '5000' %}
37+
vrf mgmt
38+
{% endif %}
2939
########## management network policy routing rules
3040
# management port up rules
31-
up ip {{ '-4' if prefix | ipv4 else '-6' }} route add default via {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} dev eth0 table default
32-
up ip {{ '-4' if prefix | ipv4 else '-6' }} route add {{ prefix | network }}/{{ prefix | prefixlen }} dev eth0 table default
33-
up ip {{ '-4' if prefix | ipv4 else '-6' }} rule add from {{ prefix | ip }}/{{ '32' if prefix | ipv4 else '128' }} table default
41+
up ip {{ '-4' if prefix | ipv4 else '-6' }} route add default via {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} dev eth0 table {{ vrf_table }} metric 201
42+
up ip {{ '-4' if prefix | ipv4 else '-6' }} route add {{ prefix | network }}/{{ prefix | prefixlen }} dev eth0 table {{ vrf_table }}
43+
up ip {{ '-4' if prefix | ipv4 else '-6' }} rule add from {{ prefix | ip }}/{{ '32' if prefix | ipv4 else '128' }} table {{ vrf_table }}
44+
{% if (MGMT_VRF_CONFIG) and (MGMT_VRF_CONFIG['vrf_global']['mgmtVrfEnabled'] == "true") %}
45+
up cgcreate -g l3mdev:mgmt
46+
up cgset -r l3mdev.master-device=mgmt mgmt
47+
{% endif %}
3448
{% for route in MGMT_INTERFACE[(name, prefix)]['forced_mgmt_routes'] %}
35-
up ip rule add to {{ route }} table default
49+
up ip rule add to {{ route }} table {{ vrf_table }}
3650
{% endfor %}
3751
# management port down rules
38-
down ip {{ '-4' if prefix | ipv4 else '-6' }} route delete default via {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} dev eth0 table default
39-
down ip {{ '-4' if prefix | ipv4 else '-6' }} route delete {{ prefix | network }}/{{ prefix | prefixlen }} dev eth0 table default
40-
down ip {{ '-4' if prefix | ipv4 else '-6' }} rule delete from {{ prefix | ip }}/{{ '32' if prefix | ipv4 else '128' }} table default
52+
down ip {{ '-4' if prefix | ipv4 else '-6' }} route delete default via {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} dev eth0 table {{ vrf_table }}
53+
down ip {{ '-4' if prefix | ipv4 else '-6' }} route delete {{ prefix | network }}/{{ prefix | prefixlen }} dev eth0 table {{ vrf_table }}
54+
down ip {{ '-4' if prefix | ipv4 else '-6' }} rule delete from {{ prefix | ip }}/{{ '32' if prefix | ipv4 else '128' }} table {{ vrf_table }}
55+
{% if (MGMT_VRF_CONFIG) and (MGMT_VRF_CONFIG['vrf_global']['mgmtVrfEnabled'] == "true") %}
56+
down cgdelete -g l3mdev:mgmt
57+
{% endif %}
4158
{% for route in MGMT_INTERFACE[(name, prefix)]['forced_mgmt_routes'] %}
42-
down ip rule delete to {{ route }} table default
59+
down ip rule delete to {{ route }} table {{ vrf_table }}
4360
{% endfor %}
4461
{# TODO: COPP policy type rules #}
4562
{% endfor %}
4663
{% else %}
4764
iface eth0 inet dhcp
65+
metric 202
66+
{% if (MGMT_VRF_CONFIG) and (MGMT_VRF_CONFIG['vrf_global']['mgmtVrfEnabled'] == "true") %}
67+
vrf mgmt
68+
up cgcreate -g l3mdev:mgmt
69+
up cgset -r l3mdev.master-device=mgmt mgmt
70+
down cgdelete -g l3mdev:mgmt
71+
{% endif %}
4872
{% endif %}
4973
#
5074
source /etc/network/interfaces.d/*

src/sonic-config-engine/tests/sample_output/interfaces

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ iface eth0 inet static
2727
netmask 255.255.255.0
2828
########## management network policy routing rules
2929
# management port up rules
30-
up ip -4 route add default via 10.0.0.1 dev eth0 table default
30+
up ip -4 route add default via 10.0.0.1 dev eth0 table default metric 201
3131
up ip -4 route add 10.0.0.0/24 dev eth0 table default
3232
up ip -4 rule add from 10.0.0.100/32 table default
3333
# management port down rules
@@ -39,7 +39,7 @@ iface eth0 inet6 static
3939
netmask 64
4040
########## management network policy routing rules
4141
# management port up rules
42-
up ip -6 route add default via 2603:10e2:0:2902::1 dev eth0 table default
42+
up ip -6 route add default via 2603:10e2:0:2902::1 dev eth0 table default metric 201
4343
up ip -6 route add 2603:10e2:0:2902::/64 dev eth0 table default
4444
up ip -6 rule add from 2603:10e2:0:2902::8/128 table default
4545
# management port down rules

0 commit comments

Comments
 (0)