mirror of https://github.com/dnomd343/XProxy.git
dnomd343
2 years ago
5 changed files with 72 additions and 4 deletions
@ -0,0 +1,33 @@ |
|||||
|
package radvd |
||||
|
|
||||
|
import ( |
||||
|
"XProxy/cmd/common" |
||||
|
log "github.com/sirupsen/logrus" |
||||
|
"strings" |
||||
|
) |
||||
|
|
||||
|
func optionList(options map[string]string, intendNum int) string { |
||||
|
var result string |
||||
|
intend := strings.Repeat(" ", intendNum) |
||||
|
for option, value := range options { |
||||
|
result += intend + option + " " + value + ";\n" |
||||
|
} |
||||
|
return result |
||||
|
} |
||||
|
|
||||
|
func loadPrefix(prefix string, options map[string]string) string { |
||||
|
result := " prefix " + prefix + " {\n" |
||||
|
result += optionList(options, 8) |
||||
|
return result + " };\n" |
||||
|
} |
||||
|
|
||||
|
func Load(options map[string]string, prefixes map[string]map[string]string) { |
||||
|
radvdConfig := "interface eth0 {\n" |
||||
|
radvdConfig += optionList(options, 4) |
||||
|
for prefix, prefixOptions := range prefixes { |
||||
|
radvdConfig += loadPrefix(prefix, prefixOptions) |
||||
|
} |
||||
|
radvdConfig += "};\n" |
||||
|
log.Debugf("Radvd configure -> \n%s", radvdConfig) |
||||
|
common.WriteFile("/etc/radvd.conf", radvdConfig, true) |
||||
|
} |
Loading…
Reference in new issue