-##finds the dhcp range available via interface
-##uses first 8 IPs, after 2nd IP
-##params: interface
-function find_dhcp_range {
- local dhcp_range_start dhcp_range_end interface_ip
- interface_ip=$(find_ip $1)
- if [ -z "$interface_ip" ]; then
- return 1
- fi
- dhcp_range_start=$(increment_ip ${interface_ip} 2)
- dhcp_range_end=$(increment_ip ${dhcp_range_start} 8)
- echo "${dhcp_range_start},${dhcp_range_end}"
+ if [ -z "$if_mask" ]; then
+ if_prefix=$(sed -n 's/^PREFIX=[^0-9]*\([0-9][0-9]*\)[^0-9]*$/\1/p' ${net_path}/ifcfg-${bridge})
+ if_mask=$(prefix2mask ${if_prefix})
+ fi
+
+ if [[ -z "$if_ip" || -z "$if_mask" ]]; then
+ echo "ERROR: IPADDR or PREFIX/NETMASK missing for ${bridge} and no .orig file for interface ${line}"
+ return 1
+ fi
+
+ # create if cfg
+ echo "DEVICE=${line}
+IPADDR=${if_ip}
+NETMASK=${if_mask}
+BOOTPROTO=static
+ONBOOT=yes
+TYPE=Ethernet
+NM_CONTROLLED=no
+PEERDNS=no" > ${net_path}/ifcfg-${line}
+
+ if [ -n "$if_gw" ]; then
+ echo "GATEWAY=${if_gw}" >> ${net_path}/ifcfg-${line}
+ fi
+
+ if [ -n "$if_metric" ]; then
+ echo "METRIC=${if_metric}" >> ${net_path}/ifcfg-${line}
+ fi
+
+ if [[ -n "$if_dns1" || -n "$if_dns2" ]]; then
+ sed -i '/PEERDNS/c\PEERDNS=yes' ${net_path}/ifcfg-${line}
+
+ if [ -n "$if_dns1" ]; then
+ echo "DNS1=${if_dns1}" >> ${net_path}/ifcfg-${line}
+ fi
+
+ if [ -n "$if_dns2" ]; then
+ echo "DNS2=${if_dns2}" >> ${net_path}/ifcfg-${line}
+ fi
+ fi
+ break
+ else
+ echo "ERROR: Real interface ${line} attached to bridge, but no interface or ${bridge} ifcfg file exists"
+ return 1
+ fi
+
+ done <<< "$port_output"
+
+ # modify the bridge ifcfg file
+ # to remove IP params
+ sudo sed -i 's/IPADDR=.*//' ${net_path}/ifcfg-${bridge}
+ sudo sed -i 's/NETMASK=.*//' ${net_path}/ifcfg-${bridge}
+ sudo sed -i 's/GATEWAY=.*//' ${net_path}/ifcfg-${bridge}
+ sudo sed -i 's/DNS1=.*//' ${net_path}/ifcfg-${bridge}
+ sudo sed -i 's/DNS2=.*//' ${net_path}/ifcfg-${bridge}
+ sudo sed -i 's/METRIC=.*//' ${net_path}/ifcfg-${bridge}
+ sudo sed -i 's/PEERDNS=.*//' ${net_path}/ifcfg-${bridge}
+
+ sudo systemctl restart network