EtherGuard-VPN/main.go

88 lines
1.9 KiB
Go
Raw Normal View History

2019-02-04 17:29:52 +01:00
// +build !windows
2019-01-02 01:55:51 +01:00
/* SPDX-License-Identifier: MIT
*
* Copyright (C) 2017-2021 WireGuard LLC. All Rights Reserved.
*/
package main
2017-06-26 13:14:02 +02:00
import (
2021-08-16 20:58:15 +02:00
"flag"
"fmt"
2021-08-16 20:58:15 +02:00
"io/ioutil"
"os"
2018-05-04 19:50:08 +02:00
"runtime"
2019-05-14 09:09:52 +02:00
2021-08-16 02:43:17 +02:00
"github.com/KusakabeSi/EtherGuardVPN/ipc"
2021-08-16 20:58:15 +02:00
"github.com/KusakabeSi/EtherGuardVPN/path"
2021-08-26 14:09:07 +02:00
"github.com/KusakabeSi/EtherGuardVPN/tap"
2021-08-16 20:58:15 +02:00
yaml "gopkg.in/yaml.v2"
2017-11-14 18:26:28 +01:00
)
2017-11-30 23:30:29 +01:00
const (
ExitSetupSuccess = 0
ExitSetupFailed = 1
)
2017-11-14 18:26:28 +01:00
const (
2021-08-24 10:43:55 +02:00
ENV_EG_UAPI_FD = "EG_UAPI_FD"
ENV_EG_UAPI_DIR = "EG_UAPI_DIR"
2017-06-26 13:14:02 +02:00
)
func printUsage() {
2021-08-16 20:58:15 +02:00
fmt.Printf("Usage: %s -s/c CONFIG-PATH\n", os.Args[0])
}
2021-08-16 20:58:15 +02:00
func readYaml(filePath string, out interface{}) (err error) {
yamlFile, err := ioutil.ReadFile(filePath)
if err != nil {
return
}
2021-08-16 20:58:15 +02:00
err = yaml.Unmarshal(yamlFile, out)
return
}
2021-08-16 20:58:15 +02:00
var (
2021-08-20 19:32:50 +02:00
tconfig = flag.String("config", "", "Config path for the interface.")
2021-08-25 15:21:26 +02:00
mode = flag.String("mode", "", "Running mode. [super|edge|solve]")
2021-08-20 19:32:50 +02:00
printExample = flag.Bool("example", false, "Print example config")
nouapi = flag.Bool("no-uapi", false, "Do not use UAPI")
version = flag.Bool("version", false, "Show version")
help = flag.Bool("help", false, "Show this help")
2021-08-16 20:58:15 +02:00
)
2018-05-04 19:50:08 +02:00
func main() {
2021-08-16 20:58:15 +02:00
flag.Parse()
if *version == true {
2021-09-21 03:15:23 +02:00
fmt.Printf("etherguard-go %s\n%s\n\nA full mesh VPN %s-%s.\nInformation available at https://github.com/KusakabeSi/EtherGuardVPN.\nCopyright (C) Kusakabe Si <si@kskb.eu.org>.\n", Version, tap.VPP_SUPPORT, runtime.GOOS, runtime.GOARCH)
2018-05-24 01:52:22 +02:00
return
}
2021-08-16 20:58:15 +02:00
if *help == true {
flag.Usage()
return
}
2021-08-24 10:43:55 +02:00
uapiDir := os.Getenv(ENV_EG_UAPI_DIR)
2021-08-16 20:58:15 +02:00
if uapiDir != "" {
ipc.SetsocketDirectory(uapiDir)
2018-05-04 21:11:38 +02:00
}
2021-08-24 10:43:55 +02:00
var err error
2021-08-16 20:58:15 +02:00
switch *mode {
case "edge":
2021-08-24 10:43:55 +02:00
err = Edge(*tconfig, !*nouapi, *printExample)
2021-08-16 20:58:15 +02:00
case "super":
2021-08-24 10:43:55 +02:00
err = Super(*tconfig, !*nouapi, *printExample)
2021-08-25 15:21:26 +02:00
case "solve":
err = path.Solve(*tconfig, *printExample)
2021-08-16 20:58:15 +02:00
default:
flag.Usage()
2017-08-01 12:14:38 +02:00
}
2021-08-24 10:43:55 +02:00
if err != nil {
fmt.Fprintf(os.Stderr, "Error :%v\n", err)
os.Exit(1)
}
2021-08-16 20:58:15 +02:00
return
}