Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensuring ipv4 config ahead of ipv6 in /etc/network/interfaces file for mgmt interface #1544

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion files/image_config/interfaces/interfaces.j2
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ iface lo {{ 'inet' if prefix | ipv4 else 'inet6' }} static
# The management network interface
auto eth0
{% if MGMT_INTERFACE %}
{% for (name, prefix) in MGMT_INTERFACE %}
{% for (name, prefix) in MGMT_INTERFACE|siftupipv4 %}
iface eth0 {{ 'inet' if prefix | ipv4 else 'inet6' }} static
address {{ prefix | ip }}
netmask {{ prefix | netmask if prefix | ipv4 else prefix | prefixlen }}
Expand Down
6 changes: 6 additions & 0 deletions src/sonic-config-engine/sonic-cfggen
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ from swsssdk import ConfigDBConnector
from collections import OrderedDict
from natsort import natsorted

def sift_up_ipv4(value):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort_by_prefix

add comments:
for interface name is the same, then sort by prefix. v4 address is before v6 address

if not value:
return None
return sorted(value.keys(), key = lambda k: (k[0], 4) if is_ipv4(k[1]) else (k[0], 6))

def is_ipv4(value):
if not value:
return False
Expand Down Expand Up @@ -204,6 +209,7 @@ def main():
loader = jinja2.FileSystemLoader(paths)

env = jinja2.Environment(loader=loader, trim_blocks=True)
env.filters['siftupipv4'] = sift_up_ipv4
env.filters['ipv4'] = is_ipv4
env.filters['ipv6'] = is_ipv6
env.filters['unique_name'] = unique_name
Expand Down