Skip to content

Commit

Permalink
refine some log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jyyi1 committed Dec 4, 2024
1 parent 89029fb commit d91d388
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 30 deletions.
8 changes: 3 additions & 5 deletions client/go/outline/electron/outline_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,15 @@ func (d *outlineDevice) Connect() (perr *perrs.PlatformError) {
}
slog.Debug("[OutlineNetDev] lwIP network stack configured")

slog.Info("successfully connected Outline network device")
slog.Info("[VPN] successfully connected to Outline server")
return nil
}

func (d *outlineDevice) Close() (err error) {
if d.IPDevice != nil {
if err = d.IPDevice.Close(); err == nil {
d.IPDevice = nil
}
err = d.IPDevice.Close()
}
slog.Info("successfully closed Outline network device")
slog.Info("[VPN] successfully disconnected from Outline server")
return
}

Expand Down
12 changes: 6 additions & 6 deletions client/go/outline/electron/vpn.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ func EstablishVPN(configStr string) (_ string, perr *perrs.PlatformError) {
c.Close()
return
}
slog.Debug("Establishing VPN connection ...", "id", c.ID())
slog.Debug("[VPN] Establishing VPN connection ...", "id", c.ID())
if perr = c.Establish(); perr != nil {
// No need to call c.Close() cuz it's tracked in the global conn already
return
}
slog.Info("VPN connection established", "id", c.ID())
slog.Info("[VPN] VPN connection established", "id", c.ID())

connJson, err := json.Marshal(vpnConnectionJSON{c.ID(), string(c.Status()), c.RouteUDP()})
if err != nil {
Expand All @@ -106,23 +106,23 @@ func CloseVPN() *perrs.PlatformError {
func atomicReplaceVPNConn(newConn VPNConnection) *perrs.PlatformError {
mu.Lock()
defer mu.Unlock()
slog.Debug("Adding VPN Connection ...", "id", newConn.ID())
slog.Debug("[VPN] Creating VPN Connection ...", "id", newConn.ID())
if err := closeVPNNoLock(); err != nil {
return err
}
conn = newConn
slog.Info("VPN Connection added", "id", newConn.ID())
slog.Info("[VPN] VPN Connection created", "id", newConn.ID())
return nil
}

func closeVPNNoLock() (perr *perrs.PlatformError) {
if conn == nil {
return nil
}
slog.Debug("Closing existing VPN Connection ...", "id", conn.ID())
slog.Debug("[VPN] Closing existing VPN Connection ...", "id", conn.ID())
if perr = conn.Close(); perr == nil {
slog.Info("[VPN] VPN Connection closed", "id", conn.ID())
conn = nil
slog.Info("VPN Connection closed", "id", conn.ID())
}
return
}
8 changes: 4 additions & 4 deletions client/go/outline/electron/vpn_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ func (c *linuxVPNConn) Establish() (perr *perrs.PlatformError) {
c.wgCopy.Add(2)
go func() {
defer c.wgCopy.Done()
slog.Debug("Copying traffic from TUN Device -> OutlineDevice...")
slog.Debug("[IO] Copying traffic from TUN Device -> OutlineDevice...")
n, err := io.Copy(c.outline, c.tun.File)
slog.Debug("TUN Device -> OutlineDevice done", "n", n, "err", err)
slog.Debug("[IO] TUN Device -> OutlineDevice done", "n", n, "err", err)
}()
go func() {
defer c.wgCopy.Done()
slog.Debug("Copying traffic from OutlineDevice -> TUN Device...")
slog.Debug("[IO] Copying traffic from OutlineDevice -> TUN Device...")
n, err := io.Copy(c.tun.File, c.outline)
slog.Debug("OutlineDevice -> TUN Device done", "n", n, "err", err)
slog.Debug("[IO] OutlineDevice -> TUN Device done", "n", n, "err", err)
}()

return nil
Expand Down
4 changes: 2 additions & 2 deletions client/go/outline/electron/vpnlinux/nmconn_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func NewNMConnection(tun *TUNDevice, dns net.IP) (_ *NMConnection, perr *perrs.P
}
slog.Debug(nmLogPfx+"saved all new setting values", "setting", c.c.GetPath())

slog.Info("successfully configured NetworkManager connection", "conn", c.ac.GetPath())
slog.Info(nmLogPfx+"successfully configured NetworkManager connection", "conn", c.ac.GetPath())
return c, nil
}

Expand All @@ -95,7 +95,7 @@ func (c *NMConnection) Close() *perrs.PlatformError {
slog.Debug(nmLogPfx+"connection setting deleted", "setting", c.c.GetPath())
}

slog.Info("cleaned up NetworkManager connection", "conn", c.ac.GetPath(), "setting", c.c.GetPath())
slog.Info(nmLogPfx+"cleaned up NetworkManager connection", "conn", c.ac.GetPath(), "setting", c.c.GetPath())
return nil
}

Expand Down
16 changes: 8 additions & 8 deletions client/go/outline/electron/vpnlinux/routing_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func NewRoutingRule(tun *TUNDevice, table, priority int, fwmark uint32) (_ *Rout
if err := netlink.RouteAdd(rt); err != nil {
return nil, errSetupVPN(nlLogPfx, "failed to add routing entry", err, "table", r.table, "route", rt)
}
slog.Debug(nlLogPfx+"routing entry added", "table", r.table, "route", rt)
slog.Info(nlLogPfx+"routing entry added", "table", r.table, "route", rt)

// ip rule add not fwmark "0x711E" table "113" priority "456"
r.rule = netlink.NewRule()
Expand All @@ -60,9 +60,8 @@ func NewRoutingRule(tun *TUNDevice, table, priority int, fwmark uint32) (_ *Rout
if err := netlink.RuleAdd(r.rule); err != nil {
return nil, errSetupVPN(nlLogPfx, "failed to add IP rule", err, "rule", r.rule)
}
slog.Debug(nlLogPfx+"IP rule added", "rule", r.rule)
slog.Info(nlLogPfx+"IP rule added", "rule", r.rule)

slog.Info("successfully configured routing", "table", r.table, "rule", r.rule)
return r, nil
}

Expand All @@ -75,7 +74,7 @@ func (r *RoutingRule) Close() *perrs.PlatformError {
if err := netlink.RuleDel(r.rule); err != nil {
return errCloseVPN(nlLogPfx, "failed to delete IP rule", err, "rule", r.rule)
}
slog.Debug(nlLogPfx+"deleted IP rule", "rule", r.rule)
slog.Info(nlLogPfx+"deleted IP rule", "rule", r.rule)
r.rule = nil
}

Expand All @@ -90,19 +89,20 @@ func (r *RoutingRule) Close() *perrs.PlatformError {
var errs error
for _, rt := range rts {
if err := netlink.RouteDel(&rt); err == nil {
slog.Debug("successfully deleted routing entry", "table", r.table, "route", rt)
slog.Debug(nlLogPfx+"successfully deleted routing entry", "table", r.table, "route", rt)
nDel++
} else {
slog.Warn("failed to delete routing entry", "table", r.table, "route", rt, "err", err)
slog.Warn(nlLogPfx+"failed to delete routing entry", "table", r.table, "route", rt, "err", err)
errs = errors.Join(errs, err)
}
}
if errs != nil {
return errCloseVPN(nlLogPfx, "failed to delete all routig entries", errs, "table", r.table)
}
slog.Debug(nlLogPfx+"deleted all routing entries", "table", r.table, "n", nDel)
if nDel > 0 {
slog.Info(nlLogPfx+"deleted all routing entries", "table", r.table, "n", nDel)
}
}

slog.Info("successfully cleaned up routing", "table", r.table)
return nil
}
8 changes: 3 additions & 5 deletions client/go/outline/electron/vpnlinux/tun_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func NewTUNDevice(name string, ipCidr *net.IPNet) (_ *TUNDevice, perr *perrs.Pla
}
slog.Debug(nlLogPfx+"brought up TUN device", "name", tun.name)

slog.Info("successfully configured Outline TUN device", "name", tun.name)
slog.Info("[TUN] successfully configured TUN device", "name", tun.name)
return tun, nil
}

Expand All @@ -93,20 +93,18 @@ func (tun *TUNDevice) Close() *perrs.PlatformError {
if err := tun.File.Close(); err != nil {
return errCloseVPN(ioLogPfx, "failed to close TUN file", err, "name", tun.name)
}
slog.Debug(ioLogPfx+"closed TUN file", "name", tun.name)
slog.Info(ioLogPfx+"closed TUN device", "name", tun.name)
tun.File = nil
}

if tun.link != nil {
// Typically the previous Close call should delete the TUN device
if err := netlink.LinkDel(tun.link); err != nil && errors.Is(err, syscall.ENODEV) {
if err := netlink.LinkDel(tun.link); err != nil && !errors.Is(err, syscall.ENODEV) {
return errCloseVPN(nlLogPfx, "failed to delete TUN device", err, "name", tun.name)
}
slog.Debug(nlLogPfx+"deleted TUN device", "name", tun.name)
tun.link = nil
}

slog.Info("cleaned up Outline TUN device", "name", tun.name)
tun.name = ""
return nil
}

0 comments on commit d91d388

Please sign in to comment.