From 224336aa077020c35d3feb8a534f92c814b232e9 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Sat, 21 Nov 2020 15:45:08 +0100 Subject: tunnel: enable {Pre,Post}{Up,Down} scripts gated behind admin knob Signed-off-by: Jason A. Donenfeld --- conf/config.go | 4 ++++ conf/filewriter_windows.go | 2 +- conf/parser.go | 8 ++++++++ conf/writer.go | 13 +++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) (limited to 'conf') diff --git a/conf/config.go b/conf/config.go index 1ce1988d..9eb6157e 100644 --- a/conf/config.go +++ b/conf/config.go @@ -49,6 +49,10 @@ type Interface struct { MTU uint16 DNS []net.IP DNSSearch []string + PreUp string + PostUp string + PreDown string + PostDown string } type Peer struct { diff --git a/conf/filewriter_windows.go b/conf/filewriter_windows.go index 9fb1f566..8860ba31 100644 --- a/conf/filewriter_windows.go +++ b/conf/filewriter_windows.go @@ -69,4 +69,4 @@ func writeEncryptedFile(destination string, contents []byte) error { return err } return nil -} \ No newline at end of file +} diff --git a/conf/parser.go b/conf/parser.go index da21e796..17b0e21f 100644 --- a/conf/parser.go +++ b/conf/parser.go @@ -282,6 +282,14 @@ func FromWgQuick(s string, name string) (*Config, error) { conf.Interface.DNS = append(conf.Interface.DNS, a) } } + case "preup": + conf.Interface.PreUp = val + case "postup": + conf.Interface.PostUp = val + case "predown": + conf.Interface.PreDown = val + case "postdown": + conf.Interface.PostDown = val default: return nil, &ParseError{l18n.Sprintf("Invalid key for [Interface] section"), key} } diff --git a/conf/writer.go b/conf/writer.go index 365e65e9..6b16f843 100644 --- a/conf/writer.go +++ b/conf/writer.go @@ -41,6 +41,19 @@ func (conf *Config) ToWgQuick() string { output.WriteString(fmt.Sprintf("MTU = %d\n", conf.Interface.MTU)) } + if len(conf.Interface.PreUp) > 0 { + output.WriteString(fmt.Sprintf("PreUp = %s\n", conf.Interface.PreUp)) + } + if len(conf.Interface.PostUp) > 0 { + output.WriteString(fmt.Sprintf("PostUp = %s\n", conf.Interface.PostUp)) + } + if len(conf.Interface.PreDown) > 0 { + output.WriteString(fmt.Sprintf("PreDown = %s\n", conf.Interface.PreDown)) + } + if len(conf.Interface.PostDown) > 0 { + output.WriteString(fmt.Sprintf("PostDown = %s\n", conf.Interface.PostDown)) + } + for _, peer := range conf.Peers { output.WriteString("\n[Peer]\n") -- cgit v1.2.3-59-g8ed1b