summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/config/config.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/tcpip/config/config.go')
-rw-r--r--pkg/tcpip/config/config.go34
1 files changed, 29 insertions, 5 deletions
diff --git a/pkg/tcpip/config/config.go b/pkg/tcpip/config/config.go
index 19e8711db..c3518ef35 100644
--- a/pkg/tcpip/config/config.go
+++ b/pkg/tcpip/config/config.go
@@ -5,6 +5,7 @@ import (
"encoding/base64"
"encoding/hex"
"fmt"
+ "io/ioutil"
"log"
"net"
"os"
@@ -65,10 +66,6 @@ type Tuntap struct {
type WireguardKey []byte
-type Config struct {
- routes []tcpip.Route
-}
-
func (wgKey *WireguardKey) UnmarshalYAML(value *yaml.Node) error{
key, err := base64.StdEncoding.DecodeString(value.Value)
fmt.Println("UnmarshalYAML", key, err)
@@ -116,6 +113,32 @@ type Netplan struct {
} `yaml:"network"`
}
+type Config struct {
+ np Netplan
+ routes []tcpip.Route
+}
+
+func Load(yamlname string) (*Config, error) {
+ data, err := ioutil.ReadFile(yamlname)
+ if err != nil {
+ log.Fatalf("File reading error", err)
+ }
+
+ var np Netplan
+ err = yaml.Unmarshal(data, &np)
+ fmt.Println("err", err)
+ fmt.Println("res", np)
+
+ if err != nil {
+ return nil, err
+ }
+
+ return &Config{
+ np: np,
+ routes: []tcpip.Route{},
+ }, nil
+}
+
func CheckError(err error) {
if err != nil {
log.Fatal("Error: " , err)
@@ -511,7 +534,8 @@ func (config *Config) SetRouteTable(s *stack.Stack) {
s.SetRouteTable(config.routes)
}
-func (config *Config) Setup(s *stack.Stack, np *Netplan) {
+func (config *Config) Setup(s *stack.Stack) {
+ var np *Netplan = &config.np
s.SetForwarding(true)
var nic tcpip.NICID = -1