diff --git a/.gitignore b/.gitignore index 50092c8..676c272 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ go.sum etherguard-go +etherguard-go-vpp vendor .ipynb_checkpoints \ No newline at end of file diff --git a/.vscode/launch.json b/.vscode/launch.json index e2ef4ec..c18040f 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,8 +10,9 @@ "request": "launch", "mode": "auto", "program": "${workspaceFolder}", + "buildFlags": "-tags=vpp", "env": {"CGO_CFLAGS":"-I/usr/include/memif"}, - "args":["-config","example_config/static_mode/path.txt","-mode","solve"/*,"-example"*/], + "args":["-config","example_config/super_mode/n1.yaml","-mode","edge"/*,"-example"*/], } ] } \ No newline at end of file diff --git a/Makefile b/Makefile index 231e114..32b3342 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,22 @@ generate-version-and-build: @$(MAKE) etherguard-go etherguard-go: $(wildcard *.go) $(wildcard */*.go) + go mod download && \ + go mod tidy && \ + go mod vendor && \ + patch -p0 -i govpp_remove_crcstring_check.patch && \ + go build -v -tags novpp -o "$@" + +vpp: + @export GIT_CEILING_DIRECTORIES="$(realpath $(CURDIR)/..)" && \ + tag="$$(git describe --dirty 2>/dev/null)" && \ + ver="$$(printf 'package main\n\nconst Version = "%s"\n' "$$tag")" && \ + [ "$$(cat version.go 2>/dev/null)" != "$$ver" ] && \ + echo "$$ver" > version.go && \ + git update-index --assume-unchanged version.go || true + @$(MAKE) etherguard-go-vpp + +etherguard-go-vpp: $(wildcard *.go) $(wildcard */*.go) go mod download && \ go mod tidy && \ go mod vendor && \ diff --git a/device/peer.go b/device/peer.go index 554233d..021210f 100644 --- a/device/peer.go +++ b/device/peer.go @@ -95,7 +95,7 @@ func (device *Device) NewPeer(pk NoisePublicKey, id config.Vertex) (*Peer, error // create peer if device.LogLevel.LogControl { - fmt.Println("Create peer with ID : " + id.ToString() + " and PubKey:" + base64.StdEncoding.EncodeToString(pk[:])) + fmt.Println("Control: Create peer with ID : " + id.ToString() + " and PubKey:" + base64.StdEncoding.EncodeToString(pk[:])) } peer := new(Peer) peer.Lock() diff --git a/example_config/super_mode/n1.yaml b/example_config/super_mode/n1.yaml index 8f35905..a2b017f 100644 --- a/example_config/super_mode/n1.yaml +++ b/example_config/super_mode/n1.yaml @@ -1,8 +1,8 @@ interface: - itype: stdio + itype: vpp name: tap1 vppifaceid: 1 - vppbridgeid: 0 + vppbridgeid: 4242 macaddrprefix: AA:BB:CC:DD:EE mtu: 1400 recvaddr: 127.0.0.1:4001 diff --git a/example_config/super_mode/n2.yaml b/example_config/super_mode/n2.yaml index 0e37439..d84be9c 100644 --- a/example_config/super_mode/n2.yaml +++ b/example_config/super_mode/n2.yaml @@ -2,7 +2,7 @@ interface: itype: stdio name: tap2 vppifaceid: 2 - vppbridgeid: 0 + vppbridgeid: 4242 macaddrprefix: AA:BB:CC:DD:EE mtu: 1400 recvaddr: 127.0.0.1:4002 diff --git a/main.go b/main.go index e65efec..d5ce811 100644 --- a/main.go +++ b/main.go @@ -54,7 +54,7 @@ var ( func main() { flag.Parse() if *version == true { - fmt.Printf("wireguard-go v%s\n\nUserspace WireGuard daemon for %s-%s.\nInformation available at https://www.wireguard.com.\nCopyright (C) Jason A. Donenfeld .\n", Version, runtime.GOOS, runtime.GOARCH) + fmt.Printf("etherguard-go v%s\n\nA mesh VPN %s-%s.\nInformation available at https://github.com/KusakabeSi/EtherGuardVPN.\nCopyright (C) Kusakabe Si .\n", Version, runtime.GOOS, runtime.GOARCH) return } if *help == true { diff --git a/main_edge.go b/main_edge.go index c79774d..de8462c 100644 --- a/main_edge.go +++ b/main_edge.go @@ -108,18 +108,18 @@ func printExampleEdgeConf() { } g := path.NewGraph(3, false, tconfig.DynamicRoute.P2P.GraphRecalculateSetting, tconfig.DynamicRoute.NTPconfig, false) - g.UpdateLentancy(1, 2, path.S2TD(0.5), false,false) - g.UpdateLentancy(2, 1, path.S2TD(0.5), false,false) - g.UpdateLentancy(2, 3, path.S2TD(0.5), false,false) - g.UpdateLentancy(3, 2, path.S2TD(0.5), false,false) - g.UpdateLentancy(2, 4, path.S2TD(0.5), false,false) - g.UpdateLentancy(4, 2, path.S2TD(0.5), false,false) - g.UpdateLentancy(3, 4, path.S2TD(0.5), false,false) - g.UpdateLentancy(4, 3, path.S2TD(0.5), false,false) - g.UpdateLentancy(5, 3, path.S2TD(0.5), false,false) - g.UpdateLentancy(3, 5, path.S2TD(0.5), false,false) - g.UpdateLentancy(6, 4, path.S2TD(0.5), false,false) - g.UpdateLentancy(4, 6, path.S2TD(0.5), false,false) + g.UpdateLentancy(1, 2, path.S2TD(0.5), false, false) + g.UpdateLentancy(2, 1, path.S2TD(0.5), false, false) + g.UpdateLentancy(2, 3, path.S2TD(0.5), false, false) + g.UpdateLentancy(3, 2, path.S2TD(0.5), false, false) + g.UpdateLentancy(2, 4, path.S2TD(0.5), false, false) + g.UpdateLentancy(4, 2, path.S2TD(0.5), false, false) + g.UpdateLentancy(3, 4, path.S2TD(0.5), false, false) + g.UpdateLentancy(4, 3, path.S2TD(0.5), false, false) + g.UpdateLentancy(5, 3, path.S2TD(0.5), false, false) + g.UpdateLentancy(3, 5, path.S2TD(0.5), false, false) + g.UpdateLentancy(6, 4, path.S2TD(0.5), false, false) + g.UpdateLentancy(4, 6, path.S2TD(0.5), false, false) _, next := path.FloydWarshall(g) tconfig.NextHopTable = next toprint, _ := yaml.Marshal(tconfig) @@ -155,6 +155,8 @@ func Edge(configPath string, useUAPI bool, printExample bool) (err error) { logLevel = device.LogLevelError case "silent": logLevel = device.LogLevelSilent + default: + logLevel = device.LogLevelError } logger := device.NewLogger( logLevel, diff --git a/main_super.go b/main_super.go index e4edd1c..16ac17b 100644 --- a/main_super.go +++ b/main_super.go @@ -88,6 +88,8 @@ func Super(configPath string, useUAPI bool, printExample bool) (err error) { logLevel = device.LogLevelError case "silent": logLevel = device.LogLevelSilent + default: + logLevel = device.LogLevelError } logger4 := device.NewLogger( diff --git a/tap/tap_vpp.go b/tap/tap_vpp.go index d27f0c9..b033d02 100644 --- a/tap/tap_vpp.go +++ b/tap/tap_vpp.go @@ -1,3 +1,5 @@ +//+build !novpp + package tap import ( @@ -135,6 +137,7 @@ func CreateVppTAP(iconfig config.InterfaceConf, loglevel string) (tapdev Device, memifSockPath: path.Join(vppMemifSocketDir, iconfig.Name+".sock"), secret: config.RandomStr(16, iconfig.Name), logger: log, + RxintChNext: make(chan uint8, 1<<6), errors: make(chan error, 1<<5), events: make(chan Event, 1<<4), } @@ -235,8 +238,8 @@ func CreateVppTAP(iconfig config.InterfaceConf, loglevel string) (tapdev Device, tap.RxintCh = memif.GetInterruptChan() tap.RxintErrCh = memif.GetInterruptErrorChan() tap.TxQueues = len(details.TxQueues) - tapdev.Events() <- EventUp - return + tap.events <- EventUp + return tap, nil } // SetMTU sets the Maximum Tansmission Unit Size for a @@ -323,8 +326,6 @@ func (tap *VppTap) Close() error { memifservice := memif.NewServiceClient(conn) - tap.memif.Close() - libmemif.Cleanup() // delete interface memif memif1/1 _, err = memifservice.MemifDelete(context.Background(), &memif.MemifDelete{ SwIfIndex: tap.SwIfIndex, @@ -335,7 +336,10 @@ func (tap *VppTap) Close() error { SocketID: tap.ifuid, SocketFilename: tap.memifSockPath, }) + go tap.memif.Close() + go libmemif.Cleanup() tap.events <- EventDown + close(tap.errors) close(tap.events) return nil } // stops the device and closes the event channel diff --git a/tap/tap_vpp_fake.go b/tap/tap_vpp_fake.go new file mode 100644 index 0000000..647ba25 --- /dev/null +++ b/tap/tap_vpp_fake.go @@ -0,0 +1,41 @@ +//+build novpp + +package tap + +import ( + "errors" + + "github.com/KusakabeSi/EtherGuardVPN/config" +) + +type VppTap struct { + stopRead chan struct{} + events chan Event +} + +// New creates and returns a new TUN interface for the application. +func CreateVppTAP(iconfig config.InterfaceConf, loglevel string) (tapdev Device, err error) { + return nil, errors.New("VPP tap not compiled.") +} + +func (tap *VppTap) Read([]byte, int) (int, error) { + return 0, errors.New("Device stopped") +} +func (tap *VppTap) Write(packet []byte, size int) (int, error) { + return size, nil +} +func (tap *VppTap) Flush() error { + return nil +} +func (tap *VppTap) MTU() (int, error) { + return 1500, nil +} +func (tap *VppTap) Name() (string, error) { + return "Invalid device", nil +} +func (tap *VppTap) Events() chan Event { + return tap.events +} +func (tap *VppTap) Close() error { + return nil +}