From f78744f16a8ec2f2baf54e88c8f455f86c753edf Mon Sep 17 00:00:00 2001 From: Kannan KVS Date: Fri, 30 Aug 2019 09:33:29 -0700 Subject: [PATCH 1/2] Redoing the management VRF NTP changes with lo-m --- build_debian.sh | 3 +++ files/image_config/interfaces/interfaces.j2 | 7 +++++++ files/image_config/ntp/mgmtvrf_add_cgexec_to_ntp.sh | 3 +++ 3 files changed, 13 insertions(+) create mode 100755 files/image_config/ntp/mgmtvrf_add_cgexec_to_ntp.sh diff --git a/build_debian.sh b/build_debian.sh index 3cb6beda30e..8e9a25be4dc 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -449,6 +449,9 @@ sudo cp files/dhcp/graphserviceurl $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks sudo cp files/dhcp/snmpcommunity $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d/ sudo cp files/dhcp/vrf $FILESYSTEM_ROOT/etc/dhcp/dhclient-exit-hooks.d/ sudo cp files/dhcp/dhclient.conf $FILESYSTEM_ROOT/etc/dhcp/ +if [ -f files/image_config/ntp/mgmtvrf_add_cgexec_to_ntp.sh ]; then + ./files/image_config/ntp/mgmtvrf_add_cgexec_to_ntp.sh $FILESYSTEM_ROOT/etc/init.d/ntp +fi ## Version file sudo mkdir -p $FILESYSTEM_ROOT/etc/sonic diff --git a/files/image_config/interfaces/interfaces.j2 b/files/image_config/interfaces/interfaces.j2 index e0f9a290d18..3b0dfc0cc26 100644 --- a/files/image_config/interfaces/interfaces.j2 +++ b/files/image_config/interfaces/interfaces.j2 @@ -21,6 +21,13 @@ iface lo {{ 'inet' if prefix | ipv4 else 'inet6' }} static netmask {{ prefix | netmask if prefix | ipv4 else prefix | prefixlen }} # {% endfor %} +# The loopback network interface for mgmt VRF that is required for applications like NTP +{% if (MGMT_VRF_CONFIG) and (MGMT_VRF_CONFIG['vrf_global']['mgmtVrfEnabled'] == "true") %} + 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 +{% endif %} {% endblock loopback %} {% block mgmt_interface %} diff --git a/files/image_config/ntp/mgmtvrf_add_cgexec_to_ntp.sh b/files/image_config/ntp/mgmtvrf_add_cgexec_to_ntp.sh new file mode 100755 index 00000000000..15cb6b93bfa --- /dev/null +++ b/files/image_config/ntp/mgmtvrf_add_cgexec_to_ntp.sh @@ -0,0 +1,3 @@ +#!/bin/bash +sudo sed -i '/start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -- -p $PIDFILE $NTPD_OPTS/d' $1 +sudo sed -i '/flock -w 180 9/a \\t\t\tvrfEnabled=$(/usr/local/bin/sonic-cfggen -d -v '"'MGMT_VRF_CONFIG[\"vrf_global\"][\"mgmtVrfEnabled\"]'"')\n\t\t\tif [ "$vrfEnabled" = "true" ]\n\t\t\tthen\n\t\t\t\tlog_daemon_msg "Starting NTP server in mgmt-vrf" "ntpd"\n\t\t\t\tcgexec -g l3mdev:mgmt start-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -- -p $PIDFILE $NTPD_OPTS\n\t\t\telse\n\t\t\t\tlog_daemon_msg "Starting NTP server in default-vrf" "ntpd"\n\t\t\t\tstart-stop-daemon --start --quiet --oknodo --pidfile $PIDFILE --startas $DAEMON -- -p $PIDFILE $NTPD_OPTS\n\t\t\tfi' $1 From 205a5ee1d9cdc4dc3ed6e3b882e0b9e6f60ba6a8 Mon Sep 17 00:00:00 2001 From: Kannan KVS Date: Fri, 30 Aug 2019 12:31:46 -0700 Subject: [PATCH 2/2] deleting lo-m during interface down added --- files/image_config/interfaces/interfaces.j2 | 1 + 1 file changed, 1 insertion(+) diff --git a/files/image_config/interfaces/interfaces.j2 b/files/image_config/interfaces/interfaces.j2 index 3b0dfc0cc26..50d82c3c954 100644 --- a/files/image_config/interfaces/interfaces.j2 +++ b/files/image_config/interfaces/interfaces.j2 @@ -27,6 +27,7 @@ iface lo {{ 'inet' if prefix | ipv4 else 'inet6' }} static 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 %}