From 8195e33120634fe0063a79d4f3c38d537eaf42aa Mon Sep 17 00:00:00 2001 From: Saikrishna Arcot Date: Tue, 13 Jun 2023 18:45:39 -0700 Subject: [PATCH] Re-add 127.0.0.1/8 when bringing down the interfaces (#15080) * Re-add 127.0.0.1/8 when bringing down the interfaces With #5353, 127.0.0.1/16 was added to the lo interface, and then 127.0.0.1/8 was removed. However, when bringing down the lo interface, like during a config reload, 127.0.0.1/16 gets removed, but 127.0.0.1/8 isn't added back to the interface. This means that there's a period of time where 127.0.0.1 is not available at all, and services that need to connect to 127.0.01 (such as for redis DB) will fail. To fix this, when going down, add 127.0.0.1/8. Add this address before the existing configuration gets removed, so that 127.0.0.1 is available at all times. Note that running `ifdown lo` doesn't actually bring down the loopback interface; the interface always stays "physically" up. Signed-off-by: Saikrishna Arcot --- files/image_config/interfaces/interfaces.j2 | 1 + src/sonic-config-engine/tests/sample_output/py2/interfaces | 1 + .../tests/sample_output/py2/interfaces_nomgmt | 1 + .../tests/sample_output/py2/interfaces_nomgmt_ztp | 1 + .../tests/sample_output/py2/interfaces_nomgmt_ztp_inband | 1 + .../tests/sample_output/py2/interfaces_nomgmt_ztp_inband_ip | 1 + .../tests/sample_output/py2/interfaces_nomgmt_ztp_ip | 1 + src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces | 1 + .../tests/sample_output/py2/mvrf_interfaces_nomgmt | 1 + .../tests/sample_output/py2/two_mgmt_interfaces | 1 + src/sonic-config-engine/tests/sample_output/py3/interfaces | 1 + .../tests/sample_output/py3/interfaces_nomgmt | 1 + .../tests/sample_output/py3/interfaces_nomgmt_ztp | 1 + .../tests/sample_output/py3/interfaces_nomgmt_ztp_inband | 1 + .../tests/sample_output/py3/interfaces_nomgmt_ztp_inband_ip | 1 + .../tests/sample_output/py3/interfaces_nomgmt_ztp_ip | 1 + src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces | 1 + .../tests/sample_output/py3/mvrf_interfaces_nomgmt | 1 + .../tests/sample_output/py3/two_mgmt_interfaces | 1 + 19 files changed, 19 insertions(+) diff --git a/files/image_config/interfaces/interfaces.j2 b/files/image_config/interfaces/interfaces.j2 index 295cebe35201..18e1181c71cf 100644 --- a/files/image_config/interfaces/interfaces.j2 +++ b/files/image_config/interfaces/interfaces.j2 @@ -26,6 +26,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo {% endblock loopback %} {% block mgmt_interface %} diff --git a/src/sonic-config-engine/tests/sample_output/py2/interfaces b/src/sonic-config-engine/tests/sample_output/py2/interfaces index 360ecf7b13de..a47c89258e34 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/interfaces +++ b/src/sonic-config-engine/tests/sample_output/py2/interfaces @@ -10,6 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt index b2d854266c32..c447cfbc6d34 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt +++ b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt @@ -10,6 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp index 2080d7dfcdf3..b41038fd8d67 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp +++ b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp @@ -10,6 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_inband b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_inband index 85d476a9102f..543819734f03 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_inband +++ b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_inband @@ -10,6 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_inband_ip b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_inband_ip index 9e62929b5a66..57bf924ce717 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_inband_ip +++ b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_inband_ip @@ -10,6 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_ip b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_ip index 9ddde6b5e8e4..31a6d3325771 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_ip +++ b/src/sonic-config-engine/tests/sample_output/py2/interfaces_nomgmt_ztp_ip @@ -10,6 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces b/src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces index 6143d7ba8c4b..5777bce1837c 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces +++ b/src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces @@ -19,6 +19,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces_nomgmt b/src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces_nomgmt index a110a91980b0..04490892fe3f 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces_nomgmt +++ b/src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces_nomgmt @@ -19,6 +19,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py2/two_mgmt_interfaces b/src/sonic-config-engine/tests/sample_output/py2/two_mgmt_interfaces index 12136a316acb..ce3961f1a786 100644 --- a/src/sonic-config-engine/tests/sample_output/py2/two_mgmt_interfaces +++ b/src/sonic-config-engine/tests/sample_output/py2/two_mgmt_interfaces @@ -10,6 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth1 diff --git a/src/sonic-config-engine/tests/sample_output/py3/interfaces b/src/sonic-config-engine/tests/sample_output/py3/interfaces index 360ecf7b13de..a47c89258e34 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/interfaces +++ b/src/sonic-config-engine/tests/sample_output/py3/interfaces @@ -10,6 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt index b2d854266c32..c447cfbc6d34 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt +++ b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt @@ -10,6 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp index 2080d7dfcdf3..b41038fd8d67 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp +++ b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp @@ -10,6 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_inband b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_inband index 85d476a9102f..543819734f03 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_inband +++ b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_inband @@ -10,6 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_inband_ip b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_inband_ip index 9e62929b5a66..57bf924ce717 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_inband_ip +++ b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_inband_ip @@ -10,6 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_ip b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_ip index 9ddde6b5e8e4..31a6d3325771 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_ip +++ b/src/sonic-config-engine/tests/sample_output/py3/interfaces_nomgmt_ztp_ip @@ -10,6 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces b/src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces index 6143d7ba8c4b..5777bce1837c 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces +++ b/src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces @@ -19,6 +19,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces_nomgmt b/src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces_nomgmt index a110a91980b0..04490892fe3f 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces_nomgmt +++ b/src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces_nomgmt @@ -19,6 +19,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0 diff --git a/src/sonic-config-engine/tests/sample_output/py3/two_mgmt_interfaces b/src/sonic-config-engine/tests/sample_output/py3/two_mgmt_interfaces index 7fa99896e8c2..5e2680854cec 100644 --- a/src/sonic-config-engine/tests/sample_output/py3/two_mgmt_interfaces +++ b/src/sonic-config-engine/tests/sample_output/py3/two_mgmt_interfaces @@ -10,6 +10,7 @@ iface lo inet loopback netmask 255.255.0.0 scope host post-up ip addr del 127.0.0.1/8 dev lo + down ip addr add 127.0.0.1/8 dev lo # The management network interface auto eth0