xref: /freebsd/contrib/hyperv/tools/scripts/hv_set_ifconfig (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1#!/bin/sh
2
3# This script activates an interface based on the specified
4# configuration. The kvp daemon code invokes this external script
5# to configure the interface.
6#
7# The only argument to this script is the configuration file that is to
8# be used to configure the interface.
9#
10# Here is the format of the ip configuration file:
11#
12# HWADDR=macaddr
13# IF_NAME=interface name
14# DHCP=yes (This is optional; if yes, DHCP is configured)
15#
16# IPADDR=ipaddr1
17# IPADDR_1=ipaddr2
18# IPADDR_x=ipaddry (where y = x + 1)
19#
20# NETMASK=netmask1
21# NETMASK_x=netmasky (where y = x + 1)
22#
23# GATEWAY=ipaddr1
24# GATEWAY_x=ipaddry (where y = x + 1)
25#
26# DNSx=ipaddrx (where first DNS address is tagged as DNS1 etc)
27#
28# IPV6 addresses will be tagged as IPV6ADDR, IPV6 gateway will be
29# tagged as IPV6_DEFAULTGW and IPV6 NETMASK will be tagged as
30# IPV6NETMASK.
31#
32# The host can specify multiple ipv4 and ipv6 addresses to be
33# configured for the interface. Furthermore, the configuration
34# needs to be persistent. A subsequent GET call on the interface
35# is expected to return the configuration that is set via the SET
36# call.
37#
38
39. $1
40
41sed -i".bak" '/ifconfig_hn0="SYNCDHCP"/d' /etc/rc.conf
42sed -i".bak" '/ifconfig_hn0="DHCP"/d' /etc/rc.conf
43
44# MAC Address
45ifconfig $IF_NAME ether $HWADDR
46
47# IP and Subnet Mask
48ifconfig $IF_NAME inet $IP_ADDR netmask $SUBNET
49
50# DNS
51sed -i".bak" '/nameserver/d' /etc/resolv.conf
52echo "nameserver" $DNS >> /etc/resolv.conf
53
54#Gateway
55# Need to implment if Gateway is not present
56route flush
57route add default $GATEWAY
58#route change default $GATEWAY
59
60#/etc/rc.d/netif restart
61#/etc/rc.d/routing restart
62
63
64# DHCP
65if [ $DHCP -eq 1 ]
66then
67	echo ifconfig_hn0=\"DHCP\" >> /etc/rc.conf
68	echo Enabled
69else
70	echo Disabled DHCP >> /var/log/messages
71	echo Disabled
72fi
73echo "Set IP-Injection Success"
74