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