#!/usr/bin/sh #---------------------------------------------------------------------------- # /usr/libexec/netconfig/nm-get-device - ip configuration of ethernet cards # # Creation : 2025-10-14 hbfl # Last Update: $Id$ # # Copyright (c) 2001-@@YEAR@@ the eisfair team, team(at)eisfair(dot)org # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- # include base config . /etc/config.d/base #exec 2>/tmp/nm-get-device$$-trace.log #set -x # --------------------------------------------------------------------------- # start network # --------------------------------------------------------------------------- network_start() { idx0=0 idx=1 while [ ${idx} -le ${IP_ETH_N:-0} ] do name='' eval name='${IP_ETH_'${idx}'_NAME}' # if no name given, get it, only for 1 netdevice if [ -z "${name}" ] then . /var/install/include/nm-get-device-name get_name eth${idx0} fi # flush existing device /usr/sbin/ip addr flush dev ${name} # check ipv4 ipv4_n='' ipv4_dhcp='' eval ipv4_n='${IP_ETH_'${idx}'_V4_IP_N}' eval ipv4_dhcp='${IP_ETH_'${idx}'_V4_DHCP}' # compability mode 2025-12-22 hbfl if [ -z "${ipv4_n}" ] then eval ipv4_n='${IP_ETH_'${idx}'_IP_N}' eval ipv4_dhcp='${IP_ETH_'${idx}'_DHCP}' fi # check ipv6 ipv6_n='' ipv6_dhcp='' eval ipv6_n='${IP_ETH_'${idx}'_V6_IP_N}' eval ipv6_dhcp='${IP_ETH_'${idx}'_V6_DHCP}' # check for dhcp active if [ "${ipv4_dhcp:-no}" = "yes" ] || [ "${ipv6_dhcp:-no}" = "yes" ] then nm_write=true fi # check for ip is set, if dhcp not given if ! "${nm_write:-false}" && [ ${ipv4_n} -eq 0 ] && [ ${ipv6_n} -eq 0 ] then idx=$((${idx} + 1)) continue fi # write nmconnection { # set interface parameter echo '[connection]' echo "id=${name}" echo 'type=ethernet' echo "interface-name=${name}" # ipv4 settings ipv4_dns='' ipv4_dhcp_host='' ipv4_dhcp_peer='' ipv4_method='' ipv4_gateway_m='' ipv4_gateway='' ipv4_metric='' eval ipv4_dhcp_host='${IP_ETH_'${idx}'_V4_DHCP_HOSTNAME}' eval ipv4_dhcp_peer='${IP_ETH_'${idx}'_V4_DHCP_PEERDNS}' eval ipv4_method='${IP_ETH_'${idx}'_V4_METHOD}' eval ipv4_gateway_m='${IP_ETH_'${idx}'_V4_GATEWAY}' # split gateway and metric ipv4_gateway=$(echo "${ipv4_gateway_m}" | cut -d ' ' -f1) ipv4_metric=$(echo "${ipv4_gateway_m}" | cut -s -d ' ' -f2) if [ -z "${ipv4_method}" ] then eval ipv4_dhcp_host='${IP_ETH_'${idx}'_DHCP_HOSTNAME}' eval ipv4_dhcp_peer='${IP_ETH_'${idx}'_DHCP_PEERDNS}' eval ipv4_method='${IP_ETH_'${idx}'_METHOD}' eval ipv4_gateway='${IP_DEFAULT_GATEWAY}' fi if [ -z "${ipv4_method}" ] then ipv4_method='manual' fi if [ "${ipv4_dhcp:-no}" = "yes" ] then ipv4_method='auto' fi echo echo '[ipv4]' case "${ipv4_method}" in manual) idxa=1 idy=1 while [ ${idy} -le ${ipv4_n:-0} ] do ipv4_addr='' ipv4_netmask='' eval ipv4_addr='${IP_ETH_'${idx}'_V4_IP_'${idy}'_IPADDR}' eval ipv4_netmask='${IP_ETH_'${idx}'_V4_IP_'${idy}'_NETMASK}' if [ -z "${ipv4_addr}" ] then eval ipv4_addr='${IP_ETH_'${idx}'_IP_'${idy}'_IPADDR}' eval ipv4_netmask='${IP_ETH_'${idx}'_IP_'${idy}'_NETMASK}' fi netmaskbits=$(/usr/bin/netcalc netmaskbits ${ipv4_netmask}) # skip configuration if no device name and ip address set if [ -n "${name}" ] && [ -n "${ipv4_addr}" ] && [ "${ipv4_addr}" != "0.0.0.0" ] then echo "address${idxa}=${ipv4_addr}/${netmaskbits}" fi idxa=$((${idxa} +1)) idy=$((${idy} +1)) done # dsl set this nm_route=$(/usr/bin/find /etc/sysconfig/network/route -maxdepth 1 -type f -printf '%f\n') if [ -z "${nm_route}" ] then if [ -n "${ipv4_gateway}" ] then echo "gateway=${ipv4_gateway}" if [ -n "${ipv4_metric}" ] then echo "route-metric=${ipv4_metric}" fi fi # include to set route . /var/install/include/nm-get-route get_route ipv4 fi if ! "${ipv4_dns:-false}" then # include to set dns rsponder . /var/install/include/nm-get-dns get_dns ipv4 ipv4_dns=true fi ;; auto) echo "dhcp-send-hostname-v2=-1" if [ -n "${ipv4_dhcp_host}" ] then echo "dhcp-hostname=${ipv4_dhcp_host}" fi if [ "${ipv4_dhcp_peer:-no}" != "yes" ] then echo 'ignore-auto-dns=true' # include to set dns responder . /var/install/include/nm-get-dns get_dns ipv4 fi ;; disabled) : # ;; link-local) : # ;; esac echo "method=${ipv4_method}" # ipv6 settings ipv6_dns='' ipv6_dhcp_host='' ipv6_dhcp_peer='' ipv6_method='' ipv6_gateway_m='' ipv6_gateway='' ipv6_metric='' ipv6_addr_mode='' eval ipv6_dhcp_host='${IP_ETH_'${idx}'_V6_DHCP_HOSTNAME}' eval ipv6_dhcp_peer='${IP_ETH_'${idx}'_V6_DHCP_PEERDNS}' eval ipv6_method='${IP_ETH_'${idx}'_V6_METHOD}' eval ipv6_addr_mode='${IP_ETH_'${idx}'_V6_ADDR_GEN_MODE}' eval ipv6_gateway_m='${IP_ETH_'${idx}'_V6_GATEWAY}' # split gateway and metric ipv6_gateway=$(echo "${ipv6_gateway_m}" | cut -d ' ' -f1) ipv6_metric=$(echo "${ipv6_gateway_m}" | cut -s -d ' ' -f2) if [ "${ipv6_dhcp:-no}" = "yes" ] then ipv6_method='auto' fi echo echo '[ipv6]' case "${ipv6_method}" in manual) idxa=1 id6=1 while [ ${id6} -le ${ipv6_n:-0} ] do ipv6_addr='' ipv6_prefix='' eval ipv6_addr='${IP_ETH_'${idx}'_V6_IP_'${id6}'_IPADDR}' eval ipv6_prefix='${IP_ETH_'${idx}'_V6_IP_'${id6}'_PREFIXLENGHT}' # skip configuration if no device name and ip address set if [ -n "${name}" ] && [ -n "${ipv6_addr}" ] then echo "address${idxa}=${ipv6_addr}/${ipv6_prefix}" fi idxa=$((${idxa} +1)) id6=$((${id6} +1)) done # dsl set this nm_route=$(/usr/bin/find /etc/sysconfig/network/route -maxdepth 1 -type f -printf '%f\n') if [ -z "${nm_route}" ] then if [ -n "${ipv6_gateway}" ] then echo "gateway=${ipv6_gateway}" if [ -n "${ipv6_metric}" ] then echo "route-metric=${ipv6_metric}" fi fi # include to set route . /var/install/include/nm-get-route get_route ipv6 fi if ! "${ipv6_dns:-false}" then # include to set dns rsponder . /var/install/include/nm-get-dns get_dns ipv6 ipv6_dns=true fi ;; disabled) : # ;; link-local) echo "addr-gen-mode=${ipv6_addr_mode}" ;; ignore) : # ;; auto) ipv6_privacy='' eval ipv6_privacy='${IP_ETH_'${idx}'_V6_PRIVACY}' echo "addr-gen-mode=${ipv6_addr_mode}" echo "ip6-privacy=${ipv6_privacy}" echo "dhcp-send-hostname-v2=-1" if [ -n "${ipv6_dhcp_host}" ] then echo "dhcp-hostname=${ipv6_dhcp_host}" fi if [ "${ipv6_dhcp_peer:-no}" != "yes" ] then echo 'ignore-auto-dns=true' # include to set dns responder . /var/install/include/nm-get-dns get_dns ipv6 fi ;; esac echo "method=${ipv6_method}" echo echo '[proxy]' echo } > /etc/NetworkManager/system-connections/${name}.nmconnection /usr/bin/chmod 0600 /etc/NetworkManager/system-connections/${name}.nmconnection # set marker for active nmconnection /usr/bin/mkdir -p /run/netconfig >/run/netconfig/${name}.nmconnection idx0=${idx} idx=$((${idx} + 1)) done # check for other modules like bonding, bridge, dsl ... nm_module=$(/usr/bin/find /etc/sysconfig/network/active -maxdepth 1 -type f -printf '%f\n') if [ -n "${nm_module}" ] then for mod in ${nm_module} do /usr/libexec/netconfig/nm-get-${mod} start done fi } # --------------------------------------------------------------------------- # stop network # --------------------------------------------------------------------------- network_stop() { # get marker from active nmconnection nmconnection="$(/usr/bin/find /run/netconfig -maxdepth 1 -name '*.nmconnection' -printf '%f\n')" if [ -n "${nmconnection}" ] then for con in ${nmconnection} do /usr/bin/rm -f /etc/NetworkManager/system-connections/${con} /usr/bin/rm -f /run/netconfig/${con} /usr/bin/ip addr flush dev ${con%%.nmconnection} done fi # check for other modules like bonding, bridge, dsl ... nm_module=$(/usr/bin/find /etc/sysconfig/network/active -maxdepth 1 -type f -printf '%f\n') if [ -n "${nm_module}" ] then for mod in ${nm_module} do /usr/libexec/netconfig/nm-get-${mod} stop done fi } # --------------------------------------------------------------------------- # main # --------------------------------------------------------------------------- main() { case "${1}" in start) network_start ;; stop) network_stop ;; esac } # --------------------------------------------------------------------------- # exec main # --------------------------------------------------------------------------- main "${@}" # --------------------------------------------------------------------------- # end # ---------------------------------------------------------------------------