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) {
config.Radvd = rawConfig.Radvd
log.Debugf("Radvd log level -> %d", config.Radvd.Log)
log.Debugf("Radvd enable -> %t", config.Radvd.Enable)
log.Debugf("Radvd options -> %v", config.Radvd.Option)
log.Debugf("Radvd prefix -> %v", config.Radvd.Prefix)

11
cmd/controller.go

@ -12,7 +12,9 @@ import (
"os"
"os/signal"
"path"
"strconv"
"syscall"
"time"
)
func runProcess(command ...string) {
@ -72,6 +74,13 @@ func runProxy(settings *config.Config) {
func runRadvd(settings *config.Config) {
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()
}
log.Warningf("Catch process %s exit", sub.name)
time.Sleep(3 * time.Second) // delay 3s
if !exitFlag { // not in exit process
time.Sleep(3 * time.Second) // delay 3s -> try to restart
if !exitFlag {
sub.Run(true)
log.Infof("Process %s restart success", sub.name)
daemonSub(sub)

27
cmd/radvd/radvd.go

@ -7,6 +7,7 @@ import (
)
type Config struct {
Log int `yaml:"log" json:"log"`
Enable bool `yaml:"enable" json:"enable"`
Client []string `yaml:"client" json:"client"`
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
}
func loadClient(clients []string) string {
if len(clients) == 0 { // without client settings
return ""
func loadClient(clients []string) string { // load radvd client configure
if len(clients) == 0 {
return "" // without client settings
}
ret := genSpace(4) + "clients {\n"
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
if prefix == "" { // without prefix settings
return ""
if prefix == "" {
return "" // without prefix settings
}
header := genSpace(4) + "prefix " + prefix + " {\n"
return header + loadOption(option, 8) + genSpace(4) + "};\n"
}
func loadRoute(cidr string, option map[string]string) string { // load radvd route configure
if cidr == "" { // without route settings
return ""
if cidr == "" {
return "" // without route settings
}
header := genSpace(4) + "route " + cidr + " {\n"
return header + loadOption(option, 8) + genSpace(4) + "};\n"
}
func loadRdnss(ip []string, option map[string]string) string {
if len(ip) == 0 { // without rdnss settings
return ""
func loadRdnss(ip []string, option map[string]string) string { // load radvd RDNSS configure
if len(ip) == 0 {
return "" // without rdnss settings
}
header := genSpace(4) + "RDNSS " + strings.Join(ip, " ") + " {\n"
return header + loadOption(option, 8) + genSpace(4) + "};\n"
}
func loadDnssl(suffix []string, option map[string]string) string {
if len(suffix) == 0 { // without dnssl settings
return ""
func loadDnssl(suffix []string, option map[string]string) string { // load radvd DNSSL configure
if len(suffix) == 0 {
return "" // without dnssl settings
}
header := genSpace(4) + "DNSSL " + strings.Join(suffix, " ") + " {\n"
return header + loadOption(option, 8) + genSpace(4) + "};\n"

2
cmd/xproxy.go

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

Loading…
Cancel
Save