^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) #!/bin/bash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) # SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) # This example script activates an interface based on the specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) # configuration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) # In the interest of keeping the KVP daemon code free of distro specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) # information; the kvp daemon code invokes this external script to configure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) # the interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) # The only argument to this script is the configuration file that is to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) # be used to configure the interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) # Each Distro is expected to implement this script in a distro specific
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) # fashion. For instance, on Distros that ship with Network Manager enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) # this script can be based on the Network Manager APIs for configuring the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) # interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) # This example script is based on a RHEL environment.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) # Here is the format of the ip configuration file:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) # HWADDR=macaddr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) # DEVICE=interface name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) # BOOTPROTO=<protocol> (where <protocol> is "dhcp" if DHCP is configured
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) # or "none" if no boot-time protocol should be used)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) # IPADDR0=ipaddr1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) # IPADDR1=ipaddr2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) # IPADDRx=ipaddry (where y = x + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) # NETMASK0=netmask1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) # NETMASKx=netmasky (where y = x + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) # GATEWAY=ipaddr1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) # GATEWAYx=ipaddry (where y = x + 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) # DNSx=ipaddrx (where first DNS address is tagged as DNS1 etc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) # IPV6 addresses will be tagged as IPV6ADDR, IPV6 gateway will be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) # tagged as IPV6_DEFAULTGW and IPV6 NETMASK will be tagged as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) # IPV6NETMASK.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) # The host can specify multiple ipv4 and ipv6 addresses to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) # configured for the interface. Furthermore, the configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) # needs to be persistent. A subsequent GET call on the interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) # is expected to return the configuration that is set via the SET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) # call.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) echo "IPV6INIT=yes" >> $1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) echo "NM_CONTROLLED=no" >> $1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) echo "PEERDNS=yes" >> $1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) echo "ONBOOT=yes" >> $1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) cp $1 /etc/sysconfig/network-scripts/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) interface=$(echo $1 | awk -F - '{ print $2 }')
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /sbin/ifdown $interface 2>/dev/null
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /sbin/ifup $interface 2>/dev/null