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"
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." )
mode = flag . String ( "mode" , "edge" , "Running mode. [super|edge]" )
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-01-28 17:23:39 +01:00
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 <Jason@zx2c4.com>.\n" , Version , 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-16 20:58:15 +02:00
case "path" :
path . Solve ( )
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
}