Skip to content

Commit

Permalink
Upgrade to ifupdown2 3.0.0 with a patch to fix using broadcast addresses
Browse files Browse the repository at this point in the history
In version 3.0.0, If a broadcast address is specified in
/etc/network/interfaces, then when ifup is run, it will fail with an
error saying `'str' object has no attribute 'packed'`. This appears to
be because it expects all attributes for an interface to be "packable"
into a compact binary representation. However, it doesn't actually
convert the broadcast address into an IPNetwork object (other addresses
are handled).

Therefore, convert the broadcast address it reads in from a str to an
IPNetwork object.

Also explicitly specify the scope of the loopback address in
/etc/network/interfaces as host scope. Otherwise, it will get added as
global scope by default. As part of this, use JSON to parse ip's output
instead of text, for robustness.

Signed-off-by: Saikrishna Arcot <[email protected]>
  • Loading branch information
saiarcot895 committed Aug 12, 2021
1 parent 868982c commit 8941a17
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 4 deletions.
6 changes: 5 additions & 1 deletion files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ sudo mkdir -p $FILESYSTEM_ROOT_USR_SHARE_SONIC_FIRMWARE/
# Keeping it generic. It should not harm anyways.
sudo mkdir -p $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM

# Install a more recent version of ifupdown2 (and its dependencies via 'apt-get -y install -f')
# Install a patched version of ifupdown2 (and its dependencies via 'apt-get -y install -f')
sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/ifupdown2_*.deb || \
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f

Expand Down Expand Up @@ -139,6 +139,10 @@ sudo rm -rf $FILESYSTEM_ROOT/$REDIS_DUMP_LOAD_PY2_WHEEL_NAME
# Install Python module for psutil
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install psutil

# Install Python module for ipaddr
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip2 install ipaddr
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT pip3 install ipaddr

# Install SwSS SDK Python 3 package
# Note: the scripts will be overwritten by corresponding Python 2 package
SWSSSDK_PY3_WHEEL_NAME=$(basename {{swsssdk_py3_wheel_path}})
Expand Down
1 change: 1 addition & 0 deletions files/image_config/interfaces/interfaces.j2
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ auto lo
iface lo inet loopback
address 127.0.0.1
netmask 255.255.0.0
scope host
post-up ip addr del 127.0.0.1/8 dev lo
{% endblock loopback %}
{% block mgmt_interface %}
Expand Down
4 changes: 2 additions & 2 deletions files/image_config/rsyslog/rsyslog-config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ fi
# on Single NPU platforms we continue to use loopback adddres

if [[ ($NUM_ASIC -gt 1) ]]; then
udp_server_ip=$(ip -o -4 addr list docker0 | awk '{print $4}' | cut -d/ -f1)
udp_server_ip=$(ip -j -4 addr list docker0 | jq -r -M '.[0].addr_info[0].local')
else
udp_server_ip=$(ip -o -4 addr list lo scope host | awk '{print $4}' | cut -d/ -f1)
udp_server_ip=$(ip -j -4 addr list lo scope host | jq -r -M '.[0].addr_info[0].local')
fi

sonic-cfggen -d -t /usr/share/sonic/templates/rsyslog.conf.j2 -a "{\"udp_server_ip\": \"$udp_server_ip\"}" >/etc/rsyslog.conf
Expand Down
2 changes: 1 addition & 1 deletion rules/ifupdown2.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ifupdown2 package

IFUPDOWN2_VERSION = 1.2.8-1
IFUPDOWN2_VERSION = 3.0.0-1
export IFUPDOWN2_VERSION

IFUPDOWN2 = ifupdown2_$(IFUPDOWN2_VERSION)_all.deb
Expand Down
8 changes: 8 additions & 0 deletions src/ifupdown2/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ $(addprefix $(DEST)/, $(MAIN_TARGET)): $(DEST)/% :
tar -z -f $(IFUPDOWN2_VERSION).tar.gz -x
pushd ./ifupdown2-$(IFUPDOWN2_VERSION)

git init
git add -f *
git commit -m "unmodified ifupdown2 source"

# Apply patch series
stg init
stg import -s ../patch/series

# Build source and Debian packages
dpkg-buildpackage -rfakeroot -b -us -uc -j$(SONIC_CONFIG_MAKE_JOBS) --admindir $(SONIC_DPKG_ADMINDIR)
popd
Expand Down
31 changes: 31 additions & 0 deletions src/ifupdown2/patch/0001-fix-broadcast-addr-encoding.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Fix reading and using broadcast address

When reading the broadcast address, convert it to an IPNetwork object,
so that it can be encoded/packed later.

From: Saikrishna Arcot <[email protected]>
---
ifupdown2/addons/address.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/ifupdown2/addons/address.py b/ifupdown2/addons/address.py
index 8b99b25..2ca41fc 100644
--- a/ifupdown2/addons/address.py
+++ b/ifupdown2/addons/address.py
@@ -441,11 +441,15 @@ class address(Addon, moduleBase):
else:
addr_obj = ipnetwork.IPNetwork(addr)

- for attr_name in ("broadcast", "scope", "preferred-lifetime"):
+ for attr_name in ("scope", "preferred-lifetime"):
attr_value = ifaceobj.get_attr_value_n(attr_name, index)
if attr_value:
addr_attributes[attr_name] = attr_value

+ broadcast = ifaceobj.get_attr_value_n("broadcast", index)
+ if broadcast:
+ addr_attributes["broadcast"] = ipnetwork.IPNetwork(broadcast)
+
pointopoint = ifaceobj.get_attr_value_n("pointopoint", index)
try:
if pointopoint:
1 change: 1 addition & 0 deletions src/ifupdown2/patch/series
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0001-fix-broadcast-addr-encoding.patch
1 change: 1 addition & 0 deletions src/sonic-config-engine/tests/sample_output/py2/interfaces
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ auto lo
iface lo inet loopback
address 127.0.0.1
netmask 255.255.0.0
scope host
post-up ip addr del 127.0.0.1/8 dev lo

# The management network interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ auto lo
iface lo inet loopback
address 127.0.0.1
netmask 255.255.0.0
scope host
post-up ip addr del 127.0.0.1/8 dev lo

# The management network interface
Expand Down
1 change: 1 addition & 0 deletions src/sonic-config-engine/tests/sample_output/py3/interfaces
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ auto lo
iface lo inet loopback
address 127.0.0.1
netmask 255.255.0.0
scope host
post-up ip addr del 127.0.0.1/8 dev lo

# The management network interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ auto lo
iface lo inet loopback
address 127.0.0.1
netmask 255.255.0.0
scope host
post-up ip addr del 127.0.0.1/8 dev lo

# The management network interface
Expand Down

0 comments on commit 8941a17

Please sign in to comment.