summaryrefslogtreecommitdiff
path: root/src/etc/dhcp/dhclient-enter-hooks.d/05-vyos-mtureplace
blob: 4a08765ba9775aa08089914b1e330a6ce18a1bfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# replace MTU with value from configuration

# get MTU value via Python
# as configuration is not available to cli-shell-api at the first boot, we must use vyos.config, which contain workaround for this, instead clean shell
function get_mtu {
python3 - <<PYEND
from vyos.config import Config
import os
import re

# check if interface is not VLAN and fix name if necessary
interface_name = os.getenv('interface', '')
regex_filter = re.compile('^(?P<interface>\w+)\.(?P<vid>\d+)$')
if regex_filter.search(interface_name):
    iface = regex_filter.search(interface_name).group('interface')
    vid = regex_filter.search(interface_name).group('vid')
    interface_name = "{} vif {}".format(iface, vid)

# initialize config
config = Config()
if config.exists('interfaces'):
    iface_types = config.list_nodes('interfaces')
    for iface_type in iface_types:
        # check if configuration contain MTU value for interface and return (print) it
        if config.exists("interfaces {} {} mtu".format(iface_type, interface_name)):
            print(format(config.return_value("interfaces {} {} mtu".format(iface_type, interface_name))))
PYEND
}

# check if DHCP server return MTU value
if [ -n "$new_interface_mtu" ]; then
    # try to get MTU from config and replace original one
    configured_mtu="$(get_mtu)"
    if [[ -n $configured_mtu ]] ; then
        logmsg info "Replacing MTU value for $interface with preconfigured one: $configured_mtu"
        new_interface_mtu="$configured_mtu"
    fi
fi