Skip to content
Snippets Groups Projects
Commit 25a1b042 authored by skorpy's avatar skorpy :construction_worker:
Browse files

network: cleanup old interface stuff

parent bbb80d17
No related branches found
No related tags found
1 merge request!550network: cleanup old interface stuff
{% set transport_interface = salt['pillar.get']('ferm:transport_interface', 'ens14') %}
/etc/network/interfaces.d/{{ transport_interface }}:
file.managed:
- source: salt://network/files/transport_interface.j2
- mode: '0644'
- user: root
- group: root
- template: jinja
- context:
name: {{ transport_interface }}
/etc/ferm/conf.d/20-{{ transport_interface }}-vxlan.conf:
file.managed:
- source: salt://network/files/ferm-vxlan.conf.j2
- user: root
- group: root
- mode: '0644'
- template: jinja
- context:
name: {{ transport_interface }}
{% for domain in salt['pillar.get']('domains', {}).keys() %}
{% set domain_id = salt['pillar.get']('domains:%s:domain_id'|format(domain)) %}
/etc/network/interfaces.d/dom{{ domain_id }}:
file.managed:
- source: salt://network/files/interfaces-domain.j2
- mode: '0644'
- user: root
- group: root
- template: jinja
- context:
domain: {{ domain }}
domain_id: {{ domain_id }}
{% if 'gateway' in salt['pillar.get']('roles', []) %}
/etc/ferm/conf.d/20-dom{{ domain_id }}.conf:
file.managed:
- source: salt://network/files/ferm-domain-batman.conf.j2
- user: root
- group: root
- mode: '0644'
- template: jinja
- context:
domain: {{ domain }}
domain_id: {{ domain_id }}
routing: {{ pillar['routing'] }}
{% endif %}
ifup-dom{{ domain_id }}-br:
cmd.run:
- name: /sbin/ifup dom{{ domain_id }}-br
- unless: /sbin/ip link show dev dom{{ domain_id }}-br
- require:
- cmd: ifreload
{% endfor %}
{%- set host_id = salt['pillar.get']('host:id:primary') -%}
{%- set with_batman_adv = salt['pillar.get']('domains:%s:batman-adv'|format(domain), False) -%}
{%- set with_fastd = salt['pillar.get']('domains:%s:fastd'|format(domain), False) -%}
# client bridge
# auto dom{{ domain_id }}-br
iface dom{{ domain_id }}-br inet manual
pre-up ip link add dev $IFACE type bridge
post-up ip link set address {{ salt['net.clientbr_mac'](domain_id, host_id) }} dev $IFACE
up ip link set dev $IFACE up
post-up ifup dom{{ domain_id }}-bat
{%- if salt['pillar.get']('domains:%s:IPv4:address'|format(domain), {}) %}
iface dom{{ domain_id }}-br inet static
address {{ salt['pillar.get']('domains:%s:IPv4:address'|format(domain)) }}
{%- endif %}
{%- if salt['pillar.get']('domains:%s:IPv6:address'|format(domain), {})%}
iface dom{{ domain_id }}-br inet6 static
{%- for address in salt['pillar.get']('domains:%s:IPv6:address'|format(domain), {}) %}
address {{ address }}/64
{%- endfor %}
dad-attempts 0
accept_ra 0
{%- endif %}
{% if with_batman_adv %}
# batman mesh interface
# auto dom{{ domain_id }}-bat
iface dom{{ domain_id }}-bat inet manual
pre-up ifup dom{{ domain_id }}-br
pre-up ip link add $IFACE type batadv
pre-up ip link set address {{ salt['net.batadv_mac'](domain_id, host_id) }} dev $IFACE
# actions
up ip link set dev $IFACE up
down ip link set dev $IFACE down
# Bridge to master
post-up ip link set master dom{{ domain_id }}-br dev $IFACE
pre-down ip link set nomaster dev $IFACE
# disable ipv6 autoconfig
pre-up echo 0 > /proc/sys/net/ipv6/conf/$IFACE/accept_ra
{%- if salt['pillar.get']('domains:%s:batman-adv:features:mm'|format(domain), False) %}
# multicast optimizations enabled
post-up batctl -m $IFACE mm 1
post-up echo 2 > /sys/class/net/$IFACE/brport/multicast_router
{%- else %}
# multicast optimizations disabled
post-up batctl -m $IFACE mm 0
{%- endif %}
{%- if salt['pillar.get']('domains:%s:batman-adv:features:dat'|format(domain), False) %}
# distributed arp table enabled
post-up batctl -m $IFACE dat 1
{%- else %}
# distributed arp table disabled
post-up batctl -m $IFACE dat 0
{%- endif %}
{%- if salt['pillar.get']('domains:%s:batman-adv:hop_penalty'|format(domain), False) %}
# hop penalty
post-up echo {{ salt['pillar.get']('domains:%s:batman-adv:hop_penalty'|format(domain)) }} > /sys/class/net/$IFACE/mesh/hop_penalty
{%- else %}
# hop penalty remains at default
{%- endif %}
{%- if salt['pillar.get']('domains:%s:batman-adv:gw_mode:enabled'|format(domain), False) %}
# gateway mode enabled
{%- set uplink = salt['pillar.get']('domains:%s:batman-adv:gw_mode:uplink', '100mbit') %}
{%- set downlink = salt['pillar.get']('domains:%s:batman-adv:gw_mode:uplink', '100mbit') %}
post-up batctl -m $IFACE gw server {{ uplink }}/{{ downlink }}
{%- endif %}
# Bring slave if's up
post-up ifup dom{{ domain_id }}-tp
# Restart fastd instance
post-up systemctl restart fastd@dom{{ domain_id }}_{{ salt['pillar.get']('domains:%s:mtu'|format(domain), 1312) }}
{% endif %}
{%- if salt['pillar.get']('domains:%s:vxlan_vid'|format(domain), {}) %}
#l2-transport-vxlan
# auto dom{{ domain_id }}-tp
iface dom{{ domain_id }}-tp inet manual
pre-up ifup dom{{ domain_id }}-bat
pre-up ip link add $IFACE type vxlan id {{ salt['pillar.get']('domains:%s:vxlan_vid'|format(domain)) }} group ff02::15c dev {{ salt['pillar.get']('ferm:transport_interface', 'ens14') }} dstport 4789
up ip link set up dev $IFACE
post-up ethtool -K $IFACE tx off rx off
{%- if with_batman_adv %}
# batman-adv specific hooks
post-up ip link set master dom{{ domain_id }}-bat dev $IFACE
pre-up ip link set mtu {{ salt['pillar.get']('domains:%s:mtu'|format(domain), 1312) }} dev $IFACE
{% endif %}
{% endif %}
{%- if 'gateway' in salt['pillar.get']('roles', []) and with_fastd %}
{%- for instance in salt['pillar.get']('domains:%s:fastd:instances'|format(domain)) %}
# l2 tunnel (fastd)
# allow-hotplug dom{{ domain_id }}-vpn-{{ instance['mtu'] }}
iface dom{{ domain_id }}-vpn-{{ instance['mtu'] }} inet manual
pre-up ifup dom{{ domain_id }}-bat
pre-up ip link set address {{ salt['fastd.mac'](domain_id, host_id) }} dev $IFACE
up ip link set up dev $IFACE
{%- if with_batman_adv %}
# batman-adv specific hooks
post-up ip link set master dom{{ domain_id }}-bat dev $IFACE
{%- endif %}
{%- endfor %}
{%- endif %}
#
# /etc/network/interfaces (Salt managed)
#
source /etc/network/interfaces.d/*
{#
# Configure any secondary IPs / router_id / infra-srv IPs on loopback, if present
#}
{%- set lo_prefixes = ifaces['lo']['prefixes'] %}
# The loopback network interface
auto lo
iface lo
{%- for prefix in lo_prefixes %}
{%- set mask = '128' if ':' in prefix else '32' %}
{%- set prefix = prefix if '/' in prefix else prefix ~ '/' ~ mask %}
address {{ prefix }}
{%- endfor %}
{#
# Set up ifaces dict with configured and generated interfaces.
#}
{%- for interface in ifaces|dictsort if interface not in ['lo'] %}
{%- set config = ifaces.get (interface) %}
{#- Let's go #}
# {{ config.get ('desc', interface) }}
{%- if config.get ('auto', True) == True %}
auto {{ interface }}
{%- endif %}
{%- if 'method' in config %}
iface {{ interface }} inet {{ config.get ('method') }}
{%- else %}
iface {{ interface }}
{%- endif %}
{#- Alias / Description set? #}
{%- if 'alias' in config or 'desc' in config %}
alias "{{ config.get ('alias', config.get ('desc')) }}"
#
{%- endif %}
{#- Configure stuff for bonding, bridging, etc.? #}
{%- for feature in ['batman', 'bond', 'bridge', 'vlan', 'vxlan'] if feature in config %}
{%- set feature_config = config.get (feature) %}
{%- for opt in feature_config|dictsort %}
{{ opt }} {{ feature_config.get (opt) }}
{%- endfor %}
#
{%- endfor %}
{#- Configure IP addresses #}
{%- for prefix in config.get ('prefixes', []) %}
address {{ prefix }}
{%- endfor %}
{#- Anything else... #}
{%- for keyword in config|dictsort %}
{%- set argument = config.get (keyword) %}
{%- if argument is none %}
{%- elif keyword.startswith ("_") %}
{%- elif keyword in [ 'auto', 'batman', 'bond', 'bridge', 'method', 'vlan', 'vxlan', 'desc', 'prefixes', 'ospf', 'babel' ] %}
{%- elif argument is string or argument is number %}
{{ keyword }} {{ argument }}
{%- else %}
{%- for item in argument %}
{{ keyword }} {{ item }}
{%- endfor %}
{%- endif %}
{%- endfor %}
{% endfor %}
......@@ -30,7 +30,5 @@ network-pkg:
ifreload:
cmd.wait:
- name: /sbin/ifreload -af
# - watch:
# - file: /etc/network/interfaces
- require:
- file: /etc/network/ifupdown2/ifupdown2.conf
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment