2 GoVPN -- simple secure free software virtual private network daemon
3 Copyright (C) 2014-2019 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 "go.cypherpunks.ru/govpn/v7"
32 RefreshRate = time.Minute
36 confs map[govpn.PeerID]*govpn.PeerConf
37 idsCache *govpn.MACCache
40 func confRead() (*map[govpn.PeerID]*govpn.PeerConf, error) {
41 data, err := ioutil.ReadFile(*confPath)
45 confsRaw := new(map[string]govpn.PeerConf)
46 err = yaml.Unmarshal(data, confsRaw)
51 confs := make(map[govpn.PeerID]*govpn.PeerConf, len(*confsRaw))
52 for name, pc := range *confsRaw {
53 verifier, err := govpn.VerifierFromString(pc.VerifierRaw)
55 return nil, errors.New("Unable to decode verifier: " + err.Error())
61 pc.MTU = govpn.MTUDefault
63 if pc.MTU > govpn.MTUMax {
64 govpn.Printf(`[mtu-high bind="%s" value="%d" overriden="%d"]`, *bindAddr, pc.MTU, govpn.MTUMax)
67 conf := govpn.PeerConf{
78 TimeSync: pc.TimeSync,
80 if pc.TimeoutInt <= 0 {
81 pc.TimeoutInt = govpn.TimeoutDefault
83 conf.Timeout = time.Second * time.Duration(pc.TimeoutInt)
84 confs[*verifier.ID] = &conf
89 func confRefresh() error {
90 newConfs, err := confRead()
92 govpn.Printf(`[conf-parse-failed bind="%s" err="%s"]`, *bindAddr, err)
96 idsCache.Update(newConfs)
101 idsCache = govpn.NewMACCache()
102 if err := confRefresh(); err != nil {
107 time.Sleep(RefreshRate)