mirror of
https://github.com/KusakabeShi/EtherGuard-VPN.git
synced 2024-11-21 23:03:08 +01:00
new log type: internal
This commit is contained in:
parent
dcd82f9893
commit
f689aadccf
34
README.md
34
README.md
@ -50,21 +50,25 @@ Usage of ./etherguard-go:
|
||||
|
||||
1. `interface`
|
||||
1. `itype`: Interface type.
|
||||
1. `dummy`: Dymmy interface, drop any packet received. You need this if you want to setup it as a relay node.
|
||||
2. `stdio`: Wrtie to stdout,read from stdin.
|
||||
Paramaters: `macaddrprefix`,`l2headermode`
|
||||
3. `udpsock`: Read/Write the raw packet to an udp socket.
|
||||
Paramaters: `recvaddr`,`sendaddr`
|
||||
3. `tcpsock`: Read/Write the raw packet to a tcp socket.
|
||||
Paramaters: `recvaddr`,`sendaddr`
|
||||
3. `unixsock`: Read/Write the raw packet to an unix socket.
|
||||
Paramaters: `recvaddr`,`sendaddr`
|
||||
3. `fd`: Read/Write the raw packet to specific file descriptor.
|
||||
Paramaters: None. But require environment variable `EG_FD_RX` and `EG_FD_TX`
|
||||
4. `vpp`: Integrate to VPP by libmemif.
|
||||
Paramaters: `name`,`vppifaceid`,`vppbridgeid`,`macaddrprefix`,`mtu`
|
||||
5. `tap`: Read/Write to tap device from linux.
|
||||
Paramaters: `name`,`macaddrprefix`,`vppifaceid`,`mtu`
|
||||
1. `dummy`: Dymmy interface, drop any packet received. You need this if you want to setup it as a relay node.
|
||||
2. `stdio`: Wrtie to stdout,read from stdin.
|
||||
Paramaters: `macaddrprefix`,`l2headermode`
|
||||
3. `udpsock`: Read/Write the raw packet to an udp socket.
|
||||
Paramaters: `recvaddr`,`sendaddr`
|
||||
3. `tcpsock`: Read/Write the raw packet to a tcp socket.
|
||||
Paramaters: `recvaddr`,`sendaddr`
|
||||
3. `unixsock`: Read/Write the raw packet to an unix socket(SOCK_STREAM mode).
|
||||
Paramaters: `recvaddr`,`sendaddr`
|
||||
3. `unixgramsock`: Read/Write the raw packet to an unix socket(SOCK_DGRAM mode).
|
||||
Paramaters: `recvaddr`,`sendaddr`
|
||||
3. `unixpacketsock`: Read/Write the raw packet to an unix socket((SOCK_SEQPACKET mode).
|
||||
Paramaters: `recvaddr`,`sendaddr`
|
||||
3. `fd`: Read/Write the raw packet to specific file descriptor.
|
||||
Paramaters: None. But require environment variable `EG_FD_RX` and `EG_FD_TX`
|
||||
4. `vpp`: Integrate to VPP by libmemif.
|
||||
Paramaters: `name`,`vppifaceid`,`vppbridgeid`,`macaddrprefix`,`mtu`
|
||||
5. `tap`: Read/Write to tap device from linux.
|
||||
Paramaters: `name`,`macaddrprefix`,`vppifaceid`,`mtu`
|
||||
2. `name` : Device name
|
||||
3. `vppifaceid`: Interface ID。Muse be unique in same VPP runtime
|
||||
4. `vppbridgeid`: VPP Bridge ID. Fill 0 if you don't use it.
|
||||
|
34
README_zh.md
34
README_zh.md
@ -56,21 +56,25 @@ Usage of ./etherguard-go-vpp:
|
||||
|
||||
1. `interface`
|
||||
1. `itype`: 裝置類型,意味著從VPN網路收到的封包要丟去哪個硬體
|
||||
1. `dummy`: 收到的封包直接丟棄,也不發出任何封包。作為中繼節點使用
|
||||
2. `stdio`: 收到的封包丟stdout,stdin進來的資料丟入vpn網路
|
||||
需要參數: `macaddrprefix`,`l2headermode`
|
||||
3. `udpsock`: 把VPN網路收到的layer2封包讀寫去一個udp socket.
|
||||
Paramaters: `recvaddr`,`sendaddr`
|
||||
3. `tcpsock`: 把VPN網路收到的layer2封包讀寫去一個tcp socket.
|
||||
Paramaters: `recvaddr`,`sendaddr`
|
||||
3. `unixsock`: 把VPN網路收到的layer2封包讀寫去一個unix socket.
|
||||
Paramaters: `recvaddr`,`sendaddr`
|
||||
3. `fd`: 把VPN網路收到的layer2封包讀寫去一個特定的file descriptor.
|
||||
Paramaters: 無. 但是使用環境變數 `EG_FD_RX` 和 `EG_FD_TX` 來指定
|
||||
4. `vpp`: 使用libmemif使vpp加入VPN網路
|
||||
需要參數: `name`,`vppifaceid`,`vppbridgeid`,`macaddrprefix`,`mtu`
|
||||
5. `tap`: Linux的tap設備。讓linux加入VPN網路
|
||||
需要參數: `name`,`macaddrprefix`,`mtu`
|
||||
1. `dummy`: 收到的封包直接丟棄,也不發出任何封包。作為中繼節點使用
|
||||
2. `stdio`: 收到的封包丟stdout,stdin進來的資料丟入vpn網路
|
||||
需要參數: `macaddrprefix`,`l2headermode`
|
||||
3. `udpsock`: 把VPN網路收到的layer2封包讀寫去一個udp socket.
|
||||
Paramaters: `recvaddr`,`sendaddr`
|
||||
3. `tcpsock`: 把VPN網路收到的layer2封包讀寫去一個tcp socket.
|
||||
Paramaters: `recvaddr`,`sendaddr`
|
||||
3. `unixsock`: 把VPN網路收到的layer2封包讀寫去一個unix socket(SOCK_STREAM 模式).
|
||||
Paramaters: `recvaddr`,`sendaddr`
|
||||
3. `unixgramsock`: 把VPN網路收到的layer2封包讀寫去一個unix socket(SOCK_DGRAM 模式).
|
||||
Paramaters: `recvaddr`,`sendaddr`
|
||||
3. `unixpacketsock`: 把VPN網路收到的layer2封包讀寫去一個unix socket(SOCK_SEQPACKET 模式).
|
||||
Paramaters: `recvaddr`,`sendaddr`
|
||||
3. `fd`: 把VPN網路收到的layer2封包讀寫去一個特定的file descriptor.
|
||||
Paramaters: 無. 但是使用環境變數 `EG_FD_RX` 和 `EG_FD_TX` 來指定
|
||||
4. `vpp`: 使用libmemif使vpp加入VPN網路
|
||||
需要參數: `name`,`vppifaceid`,`vppbridgeid`,`macaddrprefix`,`mtu`
|
||||
5. `tap`: Linux的tap設備。讓linux加入VPN網路
|
||||
需要參數: `name`,`macaddrprefix`,`mtu`
|
||||
2. `name` : 裝置名稱
|
||||
3. `vppifaceid`: VPP 的 interface ID。一個VPP runtime內不能重複
|
||||
4. `vppbridgeid`: VPP 的網橋ID。不使用VPP網橋功能的話填0
|
||||
|
@ -80,11 +80,12 @@ type SuperPeerInfo struct {
|
||||
}
|
||||
|
||||
type LoggerInfo struct {
|
||||
LogLevel string
|
||||
LogTransit bool
|
||||
LogControl bool
|
||||
LogNormal bool
|
||||
LogNTP bool
|
||||
LogLevel string
|
||||
LogTransit bool
|
||||
LogControl bool
|
||||
LogNormal bool
|
||||
LogInternal bool
|
||||
LogNTP bool
|
||||
}
|
||||
|
||||
func (v *Vertex) ToString() string {
|
||||
|
@ -570,8 +570,8 @@ func (peer *Peer) RoutineSequentialReceiver() {
|
||||
idtime := val.(*IdAndTime)
|
||||
if idtime.ID != src_nodeID {
|
||||
idtime.ID = src_nodeID
|
||||
if device.LogLevel.LogNormal {
|
||||
fmt.Printf("Normal: L2FIB [%v -> %v] updated.\n", src_macaddr.String(), src_nodeID)
|
||||
if device.LogLevel.LogInternal {
|
||||
fmt.Printf("Internal: L2FIB [%v -> %v] updated.\n", src_macaddr.String(), src_nodeID)
|
||||
}
|
||||
}
|
||||
idtime.Time = time.Now()
|
||||
@ -580,8 +580,8 @@ func (peer *Peer) RoutineSequentialReceiver() {
|
||||
ID: src_nodeID,
|
||||
Time: time.Now(),
|
||||
}) // Write to l2fib table
|
||||
if device.LogLevel.LogNormal {
|
||||
fmt.Printf("Normal: L2FIB [%v -> %v] added.\n", src_macaddr.String(), src_nodeID)
|
||||
if device.LogLevel.LogInternal {
|
||||
fmt.Printf("Internal: L2FIB [%v -> %v] added.\n", src_macaddr.String(), src_nodeID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -814,8 +814,8 @@ func (device *Device) RoutineClearL2FIB() {
|
||||
if time.Now().After(val.Time.Add(timeout)) {
|
||||
mac := k.(tap.MacAddress)
|
||||
device.l2fib.Delete(k)
|
||||
if device.LogLevel.LogNormal {
|
||||
fmt.Printf("Normal: L2FIB [%v -> %v] deleted.\n", mac.String(), val.ID)
|
||||
if device.LogLevel.LogInternal {
|
||||
fmt.Printf("Internal: L2FIB [%v -> %v] deleted.\n", mac.String(), val.ID)
|
||||
}
|
||||
}
|
||||
return true
|
||||
|
@ -19,6 +19,7 @@ loglevel:
|
||||
logtransit: true
|
||||
logcontrol: true
|
||||
lognormal: true
|
||||
loginternal: true
|
||||
logntp: true
|
||||
dynamicroute:
|
||||
sendpinginterval: 20
|
||||
|
@ -19,6 +19,7 @@ loglevel:
|
||||
logtransit: true
|
||||
logcontrol: true
|
||||
lognormal: true
|
||||
loginternal: true
|
||||
logntp: true
|
||||
dynamicroute:
|
||||
sendpinginterval: 20
|
||||
|
@ -19,6 +19,7 @@ loglevel:
|
||||
logtransit: true
|
||||
logcontrol: true
|
||||
lognormal: true
|
||||
loginternal: true
|
||||
logntp: true
|
||||
dynamicroute:
|
||||
sendpinginterval: 20
|
||||
|
@ -19,6 +19,7 @@ loglevel:
|
||||
logtransit: true
|
||||
logcontrol: true
|
||||
lognormal: true
|
||||
loginternal: true
|
||||
logntp: true
|
||||
dynamicroute:
|
||||
sendpinginterval: 20
|
||||
|
@ -19,6 +19,7 @@ loglevel:
|
||||
logtransit: true
|
||||
logcontrol: true
|
||||
lognormal: true
|
||||
loginternal: true
|
||||
logntp: true
|
||||
dynamicroute:
|
||||
sendpinginterval: 20
|
||||
|
@ -19,6 +19,7 @@ loglevel:
|
||||
logtransit: true
|
||||
logcontrol: true
|
||||
lognormal: true
|
||||
loginternal: true
|
||||
logntp: true
|
||||
dynamicroute:
|
||||
sendpinginterval: 20
|
||||
|
@ -19,6 +19,7 @@ loglevel:
|
||||
logtransit: true
|
||||
logcontrol: true
|
||||
lognormal: true
|
||||
loginternal: true
|
||||
logntp: true
|
||||
dynamicroute:
|
||||
sendpinginterval: 20
|
||||
|
@ -19,6 +19,7 @@ loglevel:
|
||||
logtransit: true
|
||||
logcontrol: true
|
||||
lognormal: true
|
||||
loginternal: true
|
||||
logntp: true
|
||||
dynamicroute:
|
||||
sendpinginterval: 20
|
||||
|
@ -19,6 +19,7 @@ loglevel:
|
||||
logtransit: true
|
||||
logcontrol: true
|
||||
lognormal: true
|
||||
loginternal: true
|
||||
logntp: true
|
||||
dynamicroute:
|
||||
sendpinginterval: 20
|
||||
|
@ -19,6 +19,7 @@ loglevel:
|
||||
logtransit: true
|
||||
logcontrol: true
|
||||
lognormal: true
|
||||
loginternal: true
|
||||
logntp: true
|
||||
dynamicroute:
|
||||
sendpinginterval: 20
|
||||
|
@ -19,6 +19,7 @@ loglevel:
|
||||
logtransit: true
|
||||
logcontrol: true
|
||||
lognormal: true
|
||||
loginternal: true
|
||||
logntp: true
|
||||
dynamicroute:
|
||||
sendpinginterval: 20
|
||||
|
@ -19,6 +19,7 @@ loglevel:
|
||||
logtransit: true
|
||||
logcontrol: true
|
||||
lognormal: true
|
||||
loginternal: true
|
||||
logntp: true
|
||||
dynamicroute:
|
||||
sendpinginterval: 20
|
||||
|
@ -19,6 +19,7 @@ loglevel:
|
||||
logtransit: true
|
||||
logcontrol: true
|
||||
lognormal: true
|
||||
loginternal: true
|
||||
logntp: true
|
||||
dynamicroute:
|
||||
sendpinginterval: 16
|
||||
|
@ -19,6 +19,7 @@ loglevel:
|
||||
logtransit: true
|
||||
logcontrol: true
|
||||
lognormal: true
|
||||
loginternal: true
|
||||
logntp: true
|
||||
dynamicroute:
|
||||
sendpinginterval: 16
|
||||
|
19
main_edge.go
19
main_edge.go
@ -44,11 +44,12 @@ func printExampleEdgeConf() {
|
||||
PrivKey: "6GyDagZKhbm5WNqMiRHhkf43RlbMJ34IieTlIuvfJ1M=",
|
||||
ListenPort: 3001,
|
||||
LogLevel: config.LoggerInfo{
|
||||
LogLevel: "error",
|
||||
LogTransit: true,
|
||||
LogControl: true,
|
||||
LogNormal: true,
|
||||
LogNTP: false,
|
||||
LogLevel: "error",
|
||||
LogTransit: true,
|
||||
LogControl: true,
|
||||
LogNormal: true,
|
||||
LogInternal: true,
|
||||
LogNTP: false,
|
||||
},
|
||||
DynamicRoute: config.DynamicRouteInfo{
|
||||
SendPingInterval: 20,
|
||||
@ -191,9 +192,13 @@ func Edge(configPath string, useUAPI bool, printExample bool, bindmode string) (
|
||||
case "udpsock":
|
||||
thetap, err = tap.CreateUDPSockTAP(econfig.Interface, econfig.NodeID)
|
||||
case "tcpsock":
|
||||
thetap, err = tap.CreateSockTAP(econfig.Interface, "tcp", econfig.NodeID)
|
||||
thetap, err = tap.CreateSockTAP(econfig.Interface, "tcp", econfig.NodeID, econfig.LogLevel)
|
||||
case "unixsock":
|
||||
thetap, err = tap.CreateSockTAP(econfig.Interface, "unix", econfig.NodeID)
|
||||
thetap, err = tap.CreateSockTAP(econfig.Interface, "unix", econfig.NodeID, econfig.LogLevel)
|
||||
case "unixgramsock":
|
||||
thetap, err = tap.CreateSockTAP(econfig.Interface, "unixgram", econfig.NodeID, econfig.LogLevel)
|
||||
case "unixpacketsock":
|
||||
thetap, err = tap.CreateSockTAP(econfig.Interface, "unixpacket", econfig.NodeID, econfig.LogLevel)
|
||||
case "fd":
|
||||
thetap, err = tap.CreateFdTAP(econfig.Interface, econfig.NodeID)
|
||||
case "vpp":
|
||||
|
@ -2,6 +2,7 @@ package tap
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
@ -16,13 +17,14 @@ type SockServerTap struct {
|
||||
connRx *net.Conn
|
||||
connTx *net.Conn
|
||||
static bool
|
||||
loglevel config.LoggerInfo
|
||||
|
||||
closed bool
|
||||
events chan Event
|
||||
}
|
||||
|
||||
// New creates and returns a new TUN interface for the application.
|
||||
func CreateSockTAP(iconfig config.InterfaceConf, protocol string, NodeID config.Vertex) (tapdev Device, err error) {
|
||||
func CreateSockTAP(iconfig config.InterfaceConf, protocol string, NodeID config.Vertex, loglevel config.LoggerInfo) (tapdev Device, err error) {
|
||||
// Setup TUN Config
|
||||
|
||||
tap := &SockServerTap{
|
||||
@ -34,6 +36,7 @@ func CreateSockTAP(iconfig config.InterfaceConf, protocol string, NodeID config.
|
||||
connTx: nil,
|
||||
static: false,
|
||||
closed: false,
|
||||
loglevel: loglevel,
|
||||
events: make(chan Event, 1<<5),
|
||||
}
|
||||
|
||||
@ -75,21 +78,29 @@ func (tap *SockServerTap) RoutineAcceptConnection() {
|
||||
return
|
||||
}
|
||||
for {
|
||||
fd, err := (*tap.server).Accept()
|
||||
conn, err := (*tap.server).Accept()
|
||||
if tap.closed == true {
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
println("accept error", err)
|
||||
return
|
||||
if tap.loglevel.LogInternal {
|
||||
fmt.Printf("Internal: Accept error %v\n", err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
if tap.loglevel.LogInternal {
|
||||
fmt.Printf("Internal: New connection accepted from %v\n", conn.RemoteAddr())
|
||||
}
|
||||
if tap.connRx != nil {
|
||||
if tap.loglevel.LogInternal {
|
||||
fmt.Printf("Internal: Old connection %v closed due to new connection\n", (*tap.connRx).RemoteAddr())
|
||||
}
|
||||
(*tap.connRx).Close()
|
||||
}
|
||||
|
||||
tap.connRx = &fd
|
||||
tap.connRx = &conn
|
||||
if tap.static == false {
|
||||
tap.connTx = &fd
|
||||
tap.connTx = &conn
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -107,6 +118,9 @@ func (tap *SockServerTap) Read(buf []byte, offset int) (size int, err error) {
|
||||
}
|
||||
size, err = (*tap.connRx).Read(buf[offset:])
|
||||
if err != nil && tap.server != nil {
|
||||
if tap.loglevel.LogInternal {
|
||||
fmt.Printf("Internal: Connection closed: %v\n", (*tap.connRx).RemoteAddr())
|
||||
}
|
||||
tap.connRx = nil
|
||||
return 0, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user