Browse Source

feat: log level option for radvd

v1.x.x
dnomd343 2 years ago
parent
commit
9b55383b19
  1. 1
      cmd/config/decode.go
  2. 11
      cmd/controller.go
  3. 4
      cmd/process/daemon.go
  4. 27
      cmd/radvd/radvd.go
  5. 2
      cmd/xproxy.go

1
cmd/config/decode.go

@ -106,6 +106,7 @@ func decodeProxy(rawConfig *yamlConfig, config *Config) {
func decodeRadvd(rawConfig *yamlConfig, config *Config) { func decodeRadvd(rawConfig *yamlConfig, config *Config) {
config.Radvd = rawConfig.Radvd config.Radvd = rawConfig.Radvd
log.Debugf("Radvd log level -> %d", config.Radvd.Log)
log.Debugf("Radvd enable -> %t", config.Radvd.Enable) log.Debugf("Radvd enable -> %t", config.Radvd.Enable)
log.Debugf("Radvd options -> %v", config.Radvd.Option) log.Debugf("Radvd options -> %v", config.Radvd.Option)
log.Debugf("Radvd prefix -> %v", config.Radvd.Prefix) log.Debugf("Radvd prefix -> %v", config.Radvd.Prefix)

11
cmd/controller.go

@ -12,7 +12,9 @@ import (
"os" "os"
"os/signal" "os/signal"
"path" "path"
"strconv"
"syscall" "syscall"
"time"
) )
func runProcess(command ...string) { func runProcess(command ...string) {
@ -72,6 +74,13 @@ func runProxy(settings *config.Config) {
func runRadvd(settings *config.Config) { func runRadvd(settings *config.Config) {
if settings.Radvd.Enable { if settings.Radvd.Enable {
runProcess("radvd", "-n", "-m", "logfile", "-l", path.Join(exposeDir, "log/radvd.log")) radvdCmd := []string{"radvd", "--nodaemon"}
if settings.Radvd.Log > 0 { // with log option
radvdCmd = append(radvdCmd, "--logmethod", "logfile")
radvdCmd = append(radvdCmd, "--logfile", path.Join(exposeDir, "log/radvd.log"))
radvdCmd = append(radvdCmd, "--debug", strconv.Itoa(settings.Radvd.Log))
time.Sleep(time.Second) // radvd will crash on first boot without delay (enable debug), why???
}
runProcess(radvdCmd...)
} }
} }

4
cmd/process/daemon.go

@ -10,8 +10,8 @@ func daemonSub(sub *Process) {
sub.Wait() sub.Wait()
} }
log.Warningf("Catch process %s exit", sub.name) log.Warningf("Catch process %s exit", sub.name)
time.Sleep(3 * time.Second) // delay 3s time.Sleep(3 * time.Second) // delay 3s -> try to restart
if !exitFlag { // not in exit process if !exitFlag {
sub.Run(true) sub.Run(true)
log.Infof("Process %s restart success", sub.name) log.Infof("Process %s restart success", sub.name)
daemonSub(sub) daemonSub(sub)

27
cmd/radvd/radvd.go

@ -7,6 +7,7 @@ import (
) )
type Config struct { type Config struct {
Log int `yaml:"log" json:"log"`
Enable bool `yaml:"enable" json:"enable"` Enable bool `yaml:"enable" json:"enable"`
Client []string `yaml:"client" json:"client"` Client []string `yaml:"client" json:"client"`
Option map[string]string `yaml:"option" json:"option"` Option map[string]string `yaml:"option" json:"option"`
@ -40,9 +41,9 @@ func loadOption(options map[string]string, intend int) string { // load options
return ret return ret
} }
func loadClient(clients []string) string { func loadClient(clients []string) string { // load radvd client configure
if len(clients) == 0 { // without client settings if len(clients) == 0 {
return "" return "" // without client settings
} }
ret := genSpace(4) + "clients {\n" ret := genSpace(4) + "clients {\n"
for _, client := range clients { for _, client := range clients {
@ -52,32 +53,32 @@ func loadClient(clients []string) string {
} }
func loadPrefix(prefix string, option map[string]string) string { // load radvd prefix configure func loadPrefix(prefix string, option map[string]string) string { // load radvd prefix configure
if prefix == "" { // without prefix settings if prefix == "" {
return "" return "" // without prefix settings
} }
header := genSpace(4) + "prefix " + prefix + " {\n" header := genSpace(4) + "prefix " + prefix + " {\n"
return header + loadOption(option, 8) + genSpace(4) + "};\n" return header + loadOption(option, 8) + genSpace(4) + "};\n"
} }
func loadRoute(cidr string, option map[string]string) string { // load radvd route configure func loadRoute(cidr string, option map[string]string) string { // load radvd route configure
if cidr == "" { // without route settings if cidr == "" {
return "" return "" // without route settings
} }
header := genSpace(4) + "route " + cidr + " {\n" header := genSpace(4) + "route " + cidr + " {\n"
return header + loadOption(option, 8) + genSpace(4) + "};\n" return header + loadOption(option, 8) + genSpace(4) + "};\n"
} }
func loadRdnss(ip []string, option map[string]string) string { func loadRdnss(ip []string, option map[string]string) string { // load radvd RDNSS configure
if len(ip) == 0 { // without rdnss settings if len(ip) == 0 {
return "" return "" // without rdnss settings
} }
header := genSpace(4) + "RDNSS " + strings.Join(ip, " ") + " {\n" header := genSpace(4) + "RDNSS " + strings.Join(ip, " ") + " {\n"
return header + loadOption(option, 8) + genSpace(4) + "};\n" return header + loadOption(option, 8) + genSpace(4) + "};\n"
} }
func loadDnssl(suffix []string, option map[string]string) string { func loadDnssl(suffix []string, option map[string]string) string { // load radvd DNSSL configure
if len(suffix) == 0 { // without dnssl settings if len(suffix) == 0 {
return "" return "" // without dnssl settings
} }
header := genSpace(4) + "DNSSL " + strings.Join(suffix, " ") + " {\n" header := genSpace(4) + "DNSSL " + strings.Join(suffix, " ") + " {\n"
return header + loadOption(option, 8) + genSpace(4) + "};\n" return header + loadOption(option, 8) + genSpace(4) + "};\n"

2
cmd/xproxy.go

@ -79,8 +79,8 @@ func main() {
loadRadvd(&settings) loadRadvd(&settings)
runScript(&settings) runScript(&settings)
runProxy(&settings)
runRadvd(&settings) runRadvd(&settings)
runProxy(&settings)
blockWait() blockWait()
process.Exit(subProcess...) process.Exit(subProcess...)
} }

Loading…
Cancel
Save