fix: restart openvpn without vrf master.

This commit is contained in:
Daniel Ding
2024-09-29 14:12:53 +08:00
parent 58f4d6f773
commit 11b4e86325
3 changed files with 39 additions and 32 deletions

View File

@@ -64,7 +64,7 @@ type Router interface {
} }
type VPNer interface { type VPNer interface {
RestartVpn() RestartVPN()
} }
type Qoser interface { type Qoser interface {

View File

@@ -116,7 +116,7 @@ func (h Network) RestartVPN(w http.ResponseWriter, r *http.Request) {
return return
} }
worker.RestartVpn() worker.RestartVPN()
ResponseJson(w, true) ResponseJson(w, true)
} }

View File

@@ -428,25 +428,8 @@ func (w *WorkerImpl) UndoZTrust() {
} }
} }
func (w *WorkerImpl) Start(v api.Switcher) { func (w *WorkerImpl) letVPN2VRF() {
cfg, vpn := w.GetCfgs() _, vpn := w.GetCfgs()
w.out.Info("WorkerImpl.Start")
w.loadVRF()
w.loadRoutes()
w.acl.Start()
w.toACL(cfg.Bridge.Name)
for _, output := range cfg.Outputs {
output.GenName()
w.addOutput(cfg.Bridge.Name, output)
}
if !(w.vpn == nil) {
w.vpn.Start()
if !(w.vrf == nil) {
promise := libol.NewPromise() promise := libol.NewPromise()
promise.Go(func() error { promise.Go(func() error {
link, err := nl.LinkByName(vpn.Device) link, err := nl.LinkByName(vpn.Device)
@@ -475,8 +458,29 @@ func (w *WorkerImpl) Start(v api.Switcher) {
return nil return nil
}) })
}
func (w *WorkerImpl) Start(v api.Switcher) {
cfg, vpn := w.GetCfgs()
w.out.Info("WorkerImpl.Start")
w.loadVRF()
w.loadRoutes()
w.acl.Start()
w.toACL(cfg.Bridge.Name)
for _, output := range cfg.Outputs {
output.GenName()
w.addOutput(cfg.Bridge.Name, output)
} }
if !(w.vpn == nil) {
w.vpn.Start()
if !(w.vrf == nil) {
w.letVPN2VRF()
}
w.fire.Mangle.In.AddRule(cn.IPRule{ w.fire.Mangle.In.AddRule(cn.IPRule{
Input: vpn.Device, Input: vpn.Device,
Jump: w.qos.ChainIn(), Jump: w.qos.ChainIn(),
@@ -559,9 +563,12 @@ func (w *WorkerImpl) unloadRoutes() {
} }
} }
func (w *WorkerImpl) RestartVpn() { func (w *WorkerImpl) RestartVPN() {
if w.vpn != nil { if w.vpn != nil {
w.vpn.Restart() w.vpn.Restart()
if !(w.vrf == nil) {
w.letVPN2VRF()
}
} }
} }