1
1
Fork 0

changed dns address

This commit is contained in:
Sangbum Kim 2016-03-13 23:06:08 +09:00
parent a6b9b566af
commit 107ef036de
4 changed files with 126 additions and 2 deletions

View File

@ -342,11 +342,11 @@ dhcp-option=option:router,10.0.0.1
#dhcp-option=option:ntp-server,1ww,w #dhcp-option=option:ntp-server,1ww,w
# Send DHCPv6 option. Note [] around IPv6 addresses. # Send DHCPv6 option. Note [] around IPv6 addresses.
#dhcp-option=option6:dns-server,[fec0::3] #dhcp-option=option6:dns-server,[fec0::b08d:adff:fead:cda1]
# Send DHCPv6 option for namservers as the machine running # Send DHCPv6 option for namservers as the machine running
# dnsmasq and another. # dnsmasq and another.
dhcp-option=option6:dns-server,[fec0::3] dhcp-option=option6:dns-server,[fec0::b08d:adff:fead:cda1]
# Ask client to poll for option changes every six hours. (RFC4242) # Ask client to poll for option changes every six hours. (RFC4242)
#dhcp-option=option6:information-refresh-time,6h #dhcp-option=option6:information-refresh-time,6h

BIN
gp/gp Executable file

Binary file not shown.

123
gp/main.go Normal file
View File

@ -0,0 +1,123 @@
package main
import (
"github.com/vishvananda/netlink"
"io/ioutil"
"strings"
"net"
"fmt"
"os"
"regexp"
)
var env map[string]string=make(map[string]string)
func main(){
readInitEnviron()
macAddr,_ := net.ParseMAC(getEnv("IF_ADDR"))
// fpAddr,_ := netlink.ParseAddr(getEnv("IP_ADDR"))
// gatewayAddr := net.ParseIP(getEnv("GATEWAY_ADDR"))
linkInterfaceType:=getEnvWithDefault("IF_TYPE","macvlan")
link:=findFirstInterface(linkInterfaceType)
renameInterface(link,"eth0")
renameMacAddress(link,macAddr)
/*
#netlink.AddrAdd(link,ipAddr)
#netlink.LinkSetUp(link)
#addRoute(gatewayAddr,link)
*/
}
func readInitEnviron(){
envFilePath:="/proc/1/environ"
content, err := ioutil.ReadFile(envFilePath)
kvParseRegex,_:=regexp.Compile("^([^=]+)=(.+)$")
if err != nil {
panic(fmt.Sprintf("environ file %s not existed!",envFilePath))
}
lines := strings.Split(string(content), "\x00")
for _,element := range lines {
result_slice := kvParseRegex.FindStringSubmatch(element)
if len(result_slice) < 2 {
continue
}else{
env[result_slice[1]]=result_slice[2]
}
}
}
func renameMacAddress(link netlink.Link,new_name net.HardwareAddr){
err:=netlink.LinkSetHardwareAddr(link,new_name)
if(err != nil){
panic(fmt.Sprintf("cannot rename mac address %s -> %s",link.Attrs().HardwareAddr,new_name))
} else {
fmt.Printf("rename mac address %s -> %s\n",link.Attrs().HardwareAddr,new_name)
}
}
func renameInterface(link netlink.Link,new_name string) {
err:=netlink.LinkSetName(link,new_name)
if(err != nil){
panic(fmt.Sprintf("cannot rename interface %s -> %s",link.Attrs().Name,new_name))
} else {
fmt.Printf("rename interface %s -> %s\n",link.Attrs().Name,new_name)
}
}
func findFirstInterface(if_type string) netlink.Link {
links,_:=netlink.LinkList()
for _,element := range links {
if(element.Type() == if_type){
fmt.Println(element.Attrs().Name)
return element
}
}
panic(fmt.Sprintf("cannot get type: %s interface",if_type))
}
func getEnv(variable string) string {
envValue,ok:=env[variable]
if ok {
return envValue
}
envValue=os.Getenv(variable)
if(envValue == ""){
panic(fmt.Sprintf("cannot get ${%s}",variable))
} else{
return envValue
}
}
func getEnvWithDefault(variable string, ret_is_empty string) string {
envValue,ok:=env[variable]
if ok {
return envValue
}
envValue=os.Getenv(variable)
if(envValue == ""){
return ret_is_empty
} else{
return envValue
}
}
func addRoute(gateway net.IP,link netlink.Link){
default_network := &net.IPNet{
IP: net.IPv4(0, 0, 0, 0),
Mask: net.CIDRMask(0, 32),
}
route := &netlink.Route{LinkIndex: link.Attrs().Index, Dst: default_network, Gw:gateway}
netlink.RouteAdd(route)
}

@ -0,0 +1 @@
Subproject commit 814b43a0c71f01a137581a3fadf37619e71751b8