2019-02-04 17:29:52 +01:00
// +build !windows
2019-01-02 01:55:51 +01:00
/ * SPDX - License - Identifier : MIT
2018-05-03 15:04:00 +02:00
*
2021-01-28 17:52:15 +01:00
* Copyright ( C ) 2017 - 2021 WireGuard LLC . All Rights Reserved .
2018-05-03 15:04:00 +02:00
* /
2017-05-30 22:36:49 +02:00
package main
2017-06-26 13:14:02 +02:00
import (
2021-08-16 20:58:15 +02:00
"flag"
2017-07-20 15:06:24 +02:00
"fmt"
2021-08-16 20:58:15 +02:00
"io/ioutil"
2017-06-29 14:39:21 +02:00
"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
)
2017-06-04 21:48:15 +02:00
2017-07-20 15:06:24 +02:00
func printUsage ( ) {
2021-08-16 20:58:15 +02:00
fmt . Printf ( "Usage: %s -s/c CONFIG-PATH\n" , os . Args [ 0 ] )
2017-07-20 15:06:24 +02:00
}
2021-08-16 20:58:15 +02:00
func readYaml ( filePath string , out interface { } ) ( err error ) {
yamlFile , err := ioutil . ReadFile ( filePath )
if err != nil {
2018-05-14 15:58:40 +02:00
return
}
2021-08-16 20:58:15 +02:00
err = yaml . Unmarshal ( yamlFile , out )
return
}
2018-05-07 22:27:03 +02:00
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 ( )
2017-07-15 13:41:02 +02:00
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
2017-05-30 22:36:49 +02:00
}