sonic-buildimage/files/image_config/interfaces/interfaces.j2

78 lines
3.3 KiB
Django/Jinja

#
{% block banner %}
# =============== Managed by SONiC Config Engine DO NOT EDIT! ===============
# generated from /usr/share/sonic/templates/interfaces.j2 using sonic-cfggen
# file: /etc/network/interfaces
#
{% endblock banner %}
{% if (MGMT_VRF_CONFIG) and (MGMT_VRF_CONFIG['vrf_global']['mgmtVrfEnabled'] == "true") %}
auto mgmt
iface mgmt
vrf-table 5000
{% endif %}
{% block loopback %}
# The loopback network interface
auto lo
iface lo inet loopback
{% if (MGMT_VRF_CONFIG) and (MGMT_VRF_CONFIG['vrf_global']['mgmtVrfEnabled'] == "true") %}
# The loopback network interface for mgmt VRF that is required for applications like NTP
up ip link add lo-m type dummy
up ip addr add 127.0.0.1/8 dev lo-m
up ip link set lo-m up
up ip link set dev lo-m master mgmt
down ip link delete dev lo-m
{% endif %}
{% endblock loopback %}
{% block mgmt_interface %}
# The management network interface
auto eth0
{% if MGMT_INTERFACE %}
{% for (name, prefix) in MGMT_INTERFACE|pfx_filter %}
iface eth0 {{ 'inet' if prefix | ipv4 else 'inet6' }} static
address {{ prefix | ip }}
netmask {{ prefix | netmask if prefix | ipv4 else prefix | prefixlen }}
{% set vrf_table = 'default' %}
{% if (MGMT_VRF_CONFIG) and (MGMT_VRF_CONFIG['vrf_global']['mgmtVrfEnabled'] == "true") %}
{% set vrf_table = '5000' %}
vrf mgmt
{% endif %}
########## management network policy routing rules
# management port up rules
up ip {{ '-4' if prefix | ipv4 else '-6' }} route add default via {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} dev eth0 table {{ vrf_table }} metric 201
up ip {{ '-4' if prefix | ipv4 else '-6' }} route add {{ prefix | network }}/{{ prefix | prefixlen }} dev eth0 table {{ vrf_table }}
up ip {{ '-4' if prefix | ipv4 else '-6' }} rule add from {{ prefix | ip }}/{{ '32' if prefix | ipv4 else '128' }} table {{ vrf_table }}
{% if (MGMT_VRF_CONFIG) and (MGMT_VRF_CONFIG['vrf_global']['mgmtVrfEnabled'] == "true") %}
up cgcreate -g l3mdev:mgmt
up cgset -r l3mdev.master-device=mgmt mgmt
{% endif %}
{% for route in MGMT_INTERFACE[(name, prefix)]['forced_mgmt_routes'] %}
up ip rule add to {{ route }} table {{ vrf_table }}
{% endfor %}
# management port down rules
down ip {{ '-4' if prefix | ipv4 else '-6' }} route delete default via {{ MGMT_INTERFACE[(name, prefix)]['gwaddr'] }} dev eth0 table {{ vrf_table }}
down ip {{ '-4' if prefix | ipv4 else '-6' }} route delete {{ prefix | network }}/{{ prefix | prefixlen }} dev eth0 table {{ vrf_table }}
down ip {{ '-4' if prefix | ipv4 else '-6' }} rule delete from {{ prefix | ip }}/{{ '32' if prefix | ipv4 else '128' }} table {{ vrf_table }}
{% if (MGMT_VRF_CONFIG) and (MGMT_VRF_CONFIG['vrf_global']['mgmtVrfEnabled'] == "true") %}
down cgdelete -g l3mdev:mgmt
{% endif %}
{% for route in MGMT_INTERFACE[(name, prefix)]['forced_mgmt_routes'] %}
down ip rule delete to {{ route }} table {{ vrf_table }}
{% endfor %}
{# TODO: COPP policy type rules #}
{% endfor %}
{% else %}
iface eth0 inet dhcp
metric 202
{% if (MGMT_VRF_CONFIG) and (MGMT_VRF_CONFIG['vrf_global']['mgmtVrfEnabled'] == "true") %}
vrf mgmt
up cgcreate -g l3mdev:mgmt
up cgset -r l3mdev.master-device=mgmt mgmt
down cgdelete -g l3mdev:mgmt
{% endif %}
{% endif %}
#
source /etc/network/interfaces.d/*
#
{% endblock mgmt_interface %}