Sfoglia il codice sorgente

Migrating to use glide vendoring

Update to use new Makefile based build

Fixup k8s mgr for updated interface
Eugene Yakubovich 9 anni fa
parent
commit
20689b12e4
23 ha cambiato i file con 19 aggiunte e 1308 eliminazioni
  1. 0 6
      Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/.travis.yml
  2. 0 20
      Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/LICENSE
  3. 0 146
      Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/README.md
  4. 0 79
      Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/client.go
  5. 0 132
      Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/clientConn.go
  6. 0 5
      Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/doc.go
  7. 0 24
      Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/err.go
  8. 0 28
      Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/err_test.go
  9. 0 51
      Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/listConns.go
  10. 0 171
      Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/listSas.go
  11. 0 55
      Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/loadConn.go
  12. 0 28
      Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/loadShared.go
  13. 0 29
      Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/marshal.go
  14. 0 342
      Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/msg.go
  15. 0 110
      Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/msg_test.go
  16. 0 32
      Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/terminate.go
  17. 0 24
      Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/unloadConn.go
  18. 0 19
      Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/version.go
  19. 3 2
      backend/ipsec/handle_charon.go
  20. 2 2
      backend/ipsec/ipsec.go
  21. 3 3
      backend/ipsec/network.go
  22. 3 0
      glide.yaml
  23. 8 0
      subnet/kube/kube.go

+ 0 - 6
Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/.travis.yml

@@ -1,6 +0,0 @@
-language: go
-go:
- - release
-
-script:
- - go test -v

+ 0 - 20
Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/LICENSE

@@ -1,20 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2015 bronze1man
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

+ 0 - 146
Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/README.md

@@ -1,146 +0,0 @@
-strongswan vici golang client
-=============================
-[![Build Status](https://travis-ci.org/bronze1man/goStrongswanVici.svg)](https://travis-ci.org/bronze1man/goStrongswanVici)
-[![GoDoc](https://godoc.org/github.com/bronze1man/goStrongswanVici?status.svg)](https://godoc.org/github.com/bronze1man/goStrongswanVici)
-[![docs examples](https://sourcegraph.com/api/repos/github.com/bronze1man/goStrongswanVici/badges/docs-examples.png)](https://sourcegraph.com/github.com/bronze1man/goStrongswanVici)
-[![Total views](https://sourcegraph.com/api/repos/github.com/bronze1man/goStrongswanVici/counters/views.png)](https://sourcegraph.com/github.com/bronze1man/goStrongswanVici)
-[![GitHub issues](https://img.shields.io/github/issues/bronze1man/goStrongswanVici.svg)](https://github.com/bronze1man/goStrongswanVici/issues)
-[![GitHub stars](https://img.shields.io/github/stars/bronze1man/goStrongswanVici.svg)](https://github.com/bronze1man/goStrongswanVici/stargazers)
-[![GitHub forks](https://img.shields.io/github/forks/bronze1man/goStrongswanVici.svg)](https://github.com/bronze1man/goStrongswanVici/network)
-[![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/bronze1man/goStrongswanVici/blob/master/LICENSE)
-
-a golang implement of strongswan vici plugin client.
-
-### document
-* http://godoc.org/github.com/bronze1man/goStrongswanVici
-* https://github.com/strongswan/strongswan/tree/master/src/libcharon/plugins/vici
-
-### Implemented command list
-* version()
-* list-sas()
-* terminate()
-* load-conn()
-* list-conns()
-* unload-conn()
-* load-shared()
-
-If you need some commands, but it is not here .you can implement yourself, and send a pull request to this project.
-
-### example
-```go
-package main
-
-import (
-	"fmt"
-	"github.com/bronze1man/goStrongswanVici"
-)
-
-func main(){
-    // create a client.
-	client, err := goStrongswanVici.NewClientConnFromDefaultSocket()
-	if err != nil {
-		panic(err)
-	}
-	defer client.Close()
-
-	// get strongswan version
-	v, err := client.Version()
-	if err != nil {
-		panic(err)
-	}
-	fmt.Printf("%#v\n", v)
-
-	childConfMap := make(map[string]goStrongswanVici.ChildSAConf)
-        childSAConf := goStrongswanVici.ChildSAConf{
-                Local_ts:      []string{"10.10.59.0/24"},
-                Remote_ts:     []string{"10.10.40.0/24"},
-                ESPProposals:  []string{"aes256-sha256-modp2048"},
-                StartAction:   "trap",
-		CloseAction:   "restart",
-                Mode:          "tunnel",
-                ReqID:         "10",
-                RekeyTime:     "10m",
-                InstallPolicy: "no",
-        }
-        childConfMap["test-child-conn"] = childSAConf
-
-        localAuthConf := goStrongswanVici.AuthConf{
-                AuthMethod: "psk",
-        }
-        remoteAuthConf := goStrongswanVici.AuthConf{
-                AuthMethod: "psk",
-        }
-
-	ikeConfMap := make(map[string] goStrongswanVici.IKEConf)
-
-        ikeConf := goStrongswanVici.IKEConf{
-                LocalAddrs:  []string{"192.168.198.10"},
-                RemoteAddrs: []string{"192.168.198.11"},
-                Proposals:   []string{"aes256-sha256-modp2048"},
-                Version:     "1",
-                LocalAuth:   localAuthConf,
-                RemoteAuth:  remoteAuthConf,
-                Children:    childConfMap,
-                Encap:       "no",
-        }
-
-	ikeConfMap["test-connection"] = ikeConf
-
-	//load connenction information into strongswan
-        err = client.LoadConn(&ikeConfMap)
-        if err != nil {
-                fmt.Printf("error loading connection: %v")
-                panic(err)
-        }
-
-	sharedKey := &goStrongswanVici.Key{
-                Typ:    "IKE",
-                Data:   "this is the key",
-                Owners: []string{"192.168.198.10"}, //IP of the remote host
-        }
-
-	//load shared key into strongswan
-        err = client.LoadShared(sharedKey)
-        if err != nil {
-                fmt.Printf("error returned from loadsharedkey \n")
-                panic(err)
-        }
-
-	//list-conns 
-	connList, err := client.ListConns("")
-	if err != nil {
-		fmt.Printf("error list-conns: %v \n", err)
-	}
-
-	for _, connection := range connList {
-		fmt.Printf("connection map: %v", connection)
-	}	
-
-	// get all conns info from strongswan
-	connInfo, err := client.ListAllVpnConnInfo()
-	if err != nil {
-		panic(err)
-	}
-	fmt.Printf("found %d connections. \n", len(connInfo))
-
-	//unload connection from strongswan
-	unloadConnReq := &goStrongswanVici.UnloadConnRequest{
-			Name: "test-connection",
-			}
-	err = client.UnloadConn(unloadConnReq)
-	if err != nil {
-		panic(error)
-	}
-
-	// kill all conns in strongswan
-	for _, info := range connInfo {
-		fmt.Printf("kill connection id %s\n", info.Uniqueid)
-		err = client.Terminate(&goStrongswanVici.TerminateRequest{
-			Ike_id: info.Uniqueid,
-		})
-		if err != nil {
-			panic(err)
-		}
-	}
-}
-```

+ 0 - 79
Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/client.go

@@ -1,79 +0,0 @@
-package goStrongswanVici
-
-import (
-	"net"
-)
-
-type ClientOptions struct {
-	Network string
-	Addr    string
-	// Dialer creates new network connection and has priority over
-	// Network and Addr options.
-	Dialer func() (net.Conn, error)
-}
-
-type Client struct {
-	o ClientOptions
-}
-
-func NewClient(options ClientOptions) (client *Client) {
-	if options.Dialer == nil {
-		options.Dialer = func() (net.Conn, error) {
-			return net.Dial(options.Network, options.Addr)
-		}
-	}
-	return &Client{
-		o: options,
-	}
-}
-
-func NewClientFromDefaultSocket() (client *Client) {
-	return NewClient(ClientOptions{
-		Network: "unix",
-		Addr:    "/var/run/charon.vici",
-	})
-}
-
-func (c *Client) NewConn() (conn *ClientConn, err error) {
-	conn1, err := c.o.Dialer()
-	if err != nil {
-		return nil, err
-	}
-	return NewClientConn(conn1), nil
-}
-
-func (c *Client) ListSas(ike string, ike_id string) (sas []map[string]IkeSa, err error) {
-	conn, err := c.NewConn()
-	if err != nil {
-		return nil, err
-	}
-	defer conn.Close()
-	return conn.ListSas(ike, ike_id)
-}
-
-func (c *Client) ListAllVpnConnInfo() (list []VpnConnInfo, err error) {
-	conn, err := c.NewConn()
-	if err != nil {
-		return nil, err
-	}
-	defer conn.Close()
-	return conn.ListAllVpnConnInfo()
-}
-
-func (c *Client) Version() (out *Version, err error) {
-	conn, err := c.NewConn()
-	if err != nil {
-		return nil, err
-	}
-	defer conn.Close()
-	return conn.Version()
-}
-
-func (c *Client) Terminate(r *TerminateRequest) (err error) {
-	conn, err := c.NewConn()
-	if err != nil {
-		return err
-	}
-	defer conn.Close()
-	return conn.Terminate(r)
-}

+ 0 - 132
Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/clientConn.go

@@ -1,132 +0,0 @@
-package goStrongswanVici
-
-import (
-	"fmt"
-	"io"
-	"net"
-)
-
-// This object is not thread safe.
-// if you want concurrent, you need create more clients.
-type ClientConn struct {
-	conn          net.Conn
-	responseChan  chan segment
-	eventHandlers map[string]func(response map[string]interface{})
-	lastError     error
-}
-
-func (c *ClientConn) Close() error {
-	close(c.responseChan)
-	c.lastError = io.ErrClosedPipe
-	return c.conn.Close()
-}
-
-func NewClientConn(conn net.Conn) (client *ClientConn) {
-	client = &ClientConn{
-		conn:          conn,
-		responseChan:  make(chan segment, 2),
-		eventHandlers: map[string]func(response map[string]interface{}){},
-	}
-	go client.readThread()
-	return client
-}
-
-// it dial from unix:///var/run/charon.vici
-func NewClientConnFromDefaultSocket() (client *ClientConn, err error) {
-	conn, err := net.Dial("unix", "/var/run/charon.vici")
-	if err != nil {
-		return
-	}
-	return NewClientConn(conn), nil
-}
-
-func (c *ClientConn) Request(apiname string, request map[string]interface{}) (response map[string]interface{}, err error) {
-	err = writeSegment(c.conn, segment{
-		typ:  stCMD_REQUEST,
-		name: apiname,
-		msg:  request,
-	})
-	if err != nil {
-		fmt.Printf("error writing segment \n")
-		return
-	}
-	outMsg := <-c.responseChan
-
-	if c.lastError != nil {
-		return nil, c.lastError
-	}
-	if outMsg.typ != stCMD_RESPONSE {
-		return nil, fmt.Errorf("[%s] response error %d", apiname, outMsg.typ)
-	}
-	return outMsg.msg, nil
-}
-
-func (c *ClientConn) RegisterEvent(name string, handler func(response map[string]interface{})) (err error) {
-	if c.eventHandlers[name] != nil {
-		return fmt.Errorf("[event %s] register a event twice.", name)
-	}
-	c.eventHandlers[name] = handler
-	err = writeSegment(c.conn, segment{
-		typ:  stEVENT_REGISTER,
-		name: name,
-	})
-	if err != nil {
-		delete(c.eventHandlers, name)
-		return
-	}
-	outMsg := <-c.responseChan
-	//fmt.Printf("registerEvent %#v\n", outMsg)
-	if c.lastError != nil {
-		delete(c.eventHandlers, name)
-		return c.lastError
-	}
-
-	if outMsg.typ != stEVENT_CONFIRM {
-		delete(c.eventHandlers, name)
-		return fmt.Errorf("[event %s] response error %d", name, outMsg.typ)
-	}
-	return nil
-}
-
-func (c *ClientConn) UnregisterEvent(name string) (err error) {
-	err = writeSegment(c.conn, segment{
-		typ:  stEVENT_UNREGISTER,
-		name: name,
-	})
-	if err != nil {
-		return
-	}
-	outMsg := <-c.responseChan
-	//fmt.Printf("UnregisterEvent %#v\n", outMsg)
-	if c.lastError != nil {
-		return c.lastError
-	}
-
-	if outMsg.typ != stEVENT_CONFIRM {
-		return fmt.Errorf("[event %s] response error %d", name, outMsg.typ)
-	}
-	delete(c.eventHandlers, name)
-	return nil
-}
-
-func (c *ClientConn) readThread() {
-	for {
-		outMsg, err := readSegment(c.conn)
-		if err != nil {
-			c.lastError = err
-			return
-		}
-		switch outMsg.typ {
-		case stCMD_RESPONSE, stEVENT_CONFIRM:
-			c.responseChan <- outMsg
-		case stEVENT:
-			handler := c.eventHandlers[outMsg.name]
-			if handler != nil {
-				handler(outMsg.msg)
-			}
-		default:
-			c.lastError = fmt.Errorf("[Client.readThread] unknow msg type %d", outMsg.typ)
-			return
-		}
-	}
-}

+ 0 - 5
Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/doc.go

@@ -1,5 +0,0 @@
-/*
-a golang implement of strongswan vici plugin client.
-https://github.com/strongswan/strongswan/tree/master/src/libcharon/plugins/vici
-*/
-package goStrongswanVici

+ 0 - 24
Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/err.go

@@ -1,24 +0,0 @@
-package goStrongswanVici
-
-import (
-	"fmt"
-)
-
-func handlePanic(f func() error) (err error) {
-	defer func() {
-		r := recover()
-		//no panic
-		if r == nil {
-			return
-		}
-		//panic a error
-		if e, ok := r.(error); ok {
-			err = e
-			return
-		}
-		//panic another stuff
-		err = fmt.Errorf("%s", r)
-	}()
-	err = f()
-	return
-}

+ 0 - 28
Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/err_test.go

@@ -1,28 +0,0 @@
-package goStrongswanVici
-
-import (
-	"fmt"
-	"testing"
-)
-
-func TestHandlePanic(ot *testing.T) {
-	err := handlePanic(func() error {
-		panic("1")
-	})
-	if err == nil {
-		panic("err==nil")
-	}
-	if err.Error() != "1" {
-		panic(`err.Error()!="1"`)
-	}
-
-	err = handlePanic(func() error {
-		return fmt.Errorf("%d", 2)
-	})
-	if err == nil {
-		panic("err==nil")
-	}
-	if err.Error() != "2" {
-		panic(`err.Error()!="2" ` + err.Error())
-	}
-}

+ 0 - 51
Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/listConns.go

@@ -1,51 +0,0 @@
-package goStrongswanVici
-
-import (
-	"fmt"
-)
-
-func (c *ClientConn) ListConns(ike string) ([]map[string]IKEConf, error) {
-	conns := []map[string]IKEConf{}
-	var eventErr error
-	var err error
-
-	err = c.RegisterEvent("list-conn", func(response map[string]interface{}) {
-		fmt.Printf("Entered the response function \n")
-		conn := &map[string]IKEConf{}
-		err = ConvertFromGeneral(response, conn)
-		if err != nil {
-			fmt.Printf("error from convert from general\n")
-			eventErr = fmt.Errorf("list-conn event error: %v", err)
-			return
-		}
-		fmt.Printf("Converted from general \n")
-		conns = append(conns, *conn)
-		fmt.Printf("Appended to conn\n")
-	})
-
-	if err != nil {
-		return nil, fmt.Errorf("error registering list-conn event: %v", err)
-	}
-
-	if eventErr != nil {
-		return nil, eventErr
-	}
-
-	reqMap := map[string]interface{}{}
-
-	if ike != "" {
-		reqMap["ike"] = ike
-	}
-
-	_, err = c.Request("list-conns", reqMap)
-	if err != nil {
-		return nil, fmt.Errorf("error requesting list-conns: %v", err)
-	}
-
-	err = c.UnregisterEvent("list-conn")
-	if err != nil {
-		return nil, fmt.Errorf("error unregistering list-conns event: %v", err)
-	}
-
-	return conns, nil
-}

+ 0 - 171
Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/listSas.go

@@ -1,171 +0,0 @@
-package goStrongswanVici
-
-import (
-	"fmt"
-	"strconv"
-)
-
-//from list-sa event
-type IkeSa struct {
-	Uniqueid        string               `json:"uniqueid"` //called ike_id in terminate() argument.
-	Version         string               `json:"version"`
-	State           string               `json:"state"` //had saw: ESTABLISHED
-	Local_host      string               `json:"local-host"`
-	Local_id        string               `json:"local-id"`
-	Remote_host     string               `json:"remote-host"`
-	Remote_id       string               `json:"remote-id"`
-	Remote_xauth_id string               `json:"remote-xauth-id"` //client username
-	Initiator       string               `json:"initiator"`
-	Initiator_spi   string               `json:"initiator-spi"`
-	Responder_spi   string               `json:"responder-spi"`
-	Encr_alg        string               `json:"encr-alg"`
-	Encr_keysize    string               `json:"encr-keysize"`
-	Integ_alg       string               `json:"integ-alg"`
-	Integ_keysize   string               `json:"integ-keysize"`
-	Prf_alg         string               `json:"prf-alg"`
-	Dh_group        string               `json:"dh-group"`
-	Established     string               `json:"established"`
-	Rekey_time      string               `json:"rekey-time"`
-	Reauth_time     string               `json:"reauth-time"`
-	Child_sas       map[string]Child_sas `json:"child-sas"` //key means child-sa-name(conn name in ipsec.conf)
-}
-
-type Child_sas struct {
-	Reqid         string `json:"reqid"`
-	State         string `json:"state"` //had saw: INSTALLED
-	Mode          string `json:"mode"`  //had saw: TUNNEL
-	Protocol      string `json:"protocol"`
-	Encap         string `json:"encap"`
-	Spi_in        string `json:"spi-in"`
-	Spi_out       string `json:"spi-out"`
-	Cpi_in        string `json:"cpi-in"`
-	Cpi_out       string `json:"cpi-out"`
-	Encr_alg      string `json:"encr-alg"`
-	Encr_keysize  string `json:"encr-keysize"`
-	Integ_alg     string `json:"integ-alg"`
-	Integ_keysize string `json:"integ-keysize"`
-	Prf_alg       string `json:"prf-alg"`
-	Dh_group      string `json:"dh-group"`
-	Esn           string `json:"esn"`
-	Bytes_in      string `json:"bytes-in"` //bytes into this machine
-	Packets_in    string `json:"packets-in"`
-	Use_in        string `json:"use-in"`
-	Bytes_out     string `json:"bytes-out"` // bytes out of this machine
-	Packets_out   string `json:"packets-out"`
-	Use_out       string `json:"use-out"`
-	Rekey_time    string `json:"rekey-time"`
-	Life_time     string `json:"life-time"`
-	Install_time  string `json:"install-time"`
-}
-
-func (s *Child_sas) GetBytesIn() uint64 {
-	num, err := strconv.ParseUint(s.Bytes_in, 10, 64)
-	if err != nil {
-		return 0
-	}
-	return num
-}
-
-func (s *Child_sas) GetBytesOut() uint64 {
-	num, err := strconv.ParseUint(s.Bytes_out, 10, 64)
-	if err != nil {
-		return 0
-	}
-	return num
-}
-
-// To be simple, list all clients that are connecting to this server .
-// A client is a sa.
-// Lists currently active IKE_SAs
-func (c *ClientConn) ListSas(ike string, ike_id string) (sas []map[string]IkeSa, err error) {
-	sas = []map[string]IkeSa{}
-	var eventErr error
-	//register event
-	err = c.RegisterEvent("list-sa", func(response map[string]interface{}) {
-		sa := &map[string]IkeSa{}
-		err = ConvertFromGeneral(response, sa)
-		if err != nil {
-			fmt.Printf("list-sa event error: %s\n", err)
-			eventErr = err
-			return
-		}
-		sas = append(sas, *sa)
-		//fmt.Printf("event %#v\n", response)
-	})
-	if err != nil {
-		return
-	}
-	if eventErr != nil {
-		return
-	}
-
-	inMap := map[string]interface{}{}
-	if ike != "" {
-		inMap["ike"] = ike
-	}
-	if ike_id != "" {
-		inMap["ike_id"] = ike_id
-	}
-	_, err = c.Request("list-sas", inMap)
-	if err != nil {
-		return
-	}
-	//fmt.Printf("request finish %#v\n", sas)
-	err = c.UnregisterEvent("list-sa")
-	if err != nil {
-		return
-	}
-	return
-}
-
-//a vpn conn in the strongswan server
-type VpnConnInfo struct {
-	IkeSa
-	Child_sas
-	IkeSaName   string //looks like conn name in ipsec.conf, content is same as ChildSaName
-	ChildSaName string //looks like conn name in ipsec.conf
-}
-
-func (c *VpnConnInfo) GuessUserName() string {
-	if c.Remote_xauth_id != "" {
-		return c.Remote_xauth_id
-	}
-	if c.Remote_id != "" {
-		return c.Remote_id
-	}
-	return ""
-}
-
-// a helper method to avoid complex data struct in ListSas
-// if it only have one child_sas ,it will put it into info.Child_sas
-func (c *ClientConn) ListAllVpnConnInfo() (list []VpnConnInfo, err error) {
-	sasList, err := c.ListSas("", "")
-	if err != nil {
-		return
-	}
-	list = make([]VpnConnInfo, len(sasList))
-	for i, sa := range sasList {
-		info := VpnConnInfo{}
-		if len(sa) != 1 {
-			fmt.Printf("[vici.ListAllVpnConnInfo] warning: len(sa)[%d]!=1\n", len(sa))
-		}
-		for ikeSaName, ikeSa := range sa {
-			info.IkeSaName = ikeSaName
-			info.IkeSa = ikeSa
-			//if len(ikeSa.Child_sas) != 1 {
-			//	fmt.Println("[vici.ListAllVpnConnInfo] warning: len(ikeSa.Child_sas)[%d]!=1", len(ikeSa.Child_sas))
-			//}
-			for childSaName, childSa := range ikeSa.Child_sas {
-				info.ChildSaName = childSaName
-				info.Child_sas = childSa
-				break
-			}
-			break
-		}
-		if len(info.IkeSa.Child_sas) == 1 {
-			info.IkeSa.Child_sas = nil
-		}
-		list[i] = info
-	}
-	return
-}

+ 0 - 55
Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/loadConn.go

@@ -1,55 +0,0 @@
-package goStrongswanVici
-
-import (
-	"fmt"
-)
-
-type Connection struct {
-	ConnConf map[string]IKEConf `json:"connections"`
-}
-
-type IKEConf struct {
-	LocalAddrs  []string `json:"local_addrs"`
-	RemoteAddrs []string `json:"remote_addrs"`
-	Proposals   []string `json:"proposals"` //aes128-sha256-modp1024
-	Version     string   `json:"version"`   //1 for ikev1, 0 for ikev1 & ikev2
-	Encap       string   `json:"encap"`     //yes,no
-	KeyingTries string   `json:"keyingtries"`
-	//	RekyTime   string                 `json:"rekey_time"`
-	LocalAuth  AuthConf               `json:"local"`
-	RemoteAuth AuthConf               `json:"remote"`
-	Children   map[string]ChildSAConf `json:"children"`
-}
-
-type AuthConf struct {
-	AuthMethod string `json:"auth"` //psk
-}
-
-type ChildSAConf struct {
-	Local_ts      []string `json:"local_ts"`
-	Remote_ts     []string `json:"remote_ts"`
-	ESPProposals  []string `json:"esp_proposals"` //aes128-sha1_modp1024
-	StartAction   string   `json:"start_action"`  //none,trap,start
-	CloseAction   string   `json:"close_action"`
-	ReqID         string   `json:"reqid"`
-	RekeyTime     string   `json:"rekey_time"`
-	Mode          string   `json:"mode"`
-	InstallPolicy string   `json:"policies"`
-}
-
-func (c *ClientConn) LoadConn(conn *map[string]IKEConf) error {
-	requestMap := &map[string]interface{}{}
-
-	err := ConvertToGeneral(conn, requestMap)
-
-	if err != nil {
-		return fmt.Errorf("error creating request: %v", err)
-
-	}
-	msg, err := c.Request("load-conn", *requestMap)
-	if msg["success"] != "yes" {
-		return fmt.Errorf("unsuccessful LoadConn: %v", msg["success"])
-	}
-
-	return nil
-}

+ 0 - 28
Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/loadShared.go

@@ -1,28 +0,0 @@
-package goStrongswanVici
-
-import (
-	"fmt"
-)
-
-type Key struct {
-	Typ    string   `json:"type"`
-	Data   string   `json:"data"`
-	Owners []string `json:"owners"`
-}
-
-func (c *ClientConn) LoadShared(key *Key) error {
-	requestMap := &map[string]interface{}{}
-
-	err := ConvertToGeneral(key, requestMap)
-
-	if err != nil {
-		return fmt.Errorf("error creating request: %v", err)
-	}
-
-	msg, err := c.Request("load-shared", *requestMap)
-	if msg["success"] != "yes" {
-		return fmt.Errorf("unsuccessful loadSharedKey: %v", msg["success"])
-	}
-
-	return nil
-}

+ 0 - 29
Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/marshal.go

@@ -1,29 +0,0 @@
-package goStrongswanVici
-
-import (
-	"encoding/json"
-)
-
-//concrete data type to general data type
-// concrete data type like *Version
-// general data type include map[string]interface{} []string string
-// TODO make it faster
-func ConvertToGeneral(concrete interface{}, general interface{}) (err error) {
-	b, err := json.Marshal(concrete)
-	if err != nil {
-		return
-	}
-	return json.Unmarshal(b, general)
-}
-
-// general data type to concrete data type
-// concrete data type like *Version
-// general data type include map[string]interface{} []string string
-// TODO make it faster
-func ConvertFromGeneral(general interface{}, concrete interface{}) (err error) {
-	b, err := json.Marshal(general)
-	if err != nil {
-		return
-	}
-	return json.Unmarshal(b, concrete)
-}

+ 0 - 342
Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/msg.go

@@ -1,342 +0,0 @@
-package goStrongswanVici
-
-import (
-	"bufio"
-	"bytes"
-	"encoding/binary"
-	"fmt"
-	"io"
-)
-
-type segmentType byte
-
-const (
-	stCMD_REQUEST      segmentType = 0
-	stCMD_RESPONSE                 = 1
-	stCMD_UNKNOWN                  = 2
-	stEVENT_REGISTER               = 3
-	stEVENT_UNREGISTER             = 4
-	stEVENT_CONFIRM                = 5
-	stEVENT_UNKNOWN                = 6
-	stEVENT                        = 7
-)
-
-func (t segmentType) hasName() bool {
-	switch t {
-	case stCMD_REQUEST, stEVENT_REGISTER, stEVENT_UNREGISTER, stEVENT:
-		return true
-	}
-	return false
-}
-func (t segmentType) isValid() bool {
-	switch t {
-	case stCMD_REQUEST, stCMD_RESPONSE, stCMD_UNKNOWN, stEVENT_REGISTER,
-		stEVENT_UNREGISTER, stEVENT_CONFIRM, stEVENT_UNKNOWN, stEVENT:
-		return true
-	}
-	return false
-}
-
-func (t segmentType) hasMsg() bool {
-	switch t {
-	case stCMD_REQUEST, stCMD_RESPONSE, stEVENT:
-		return true
-	}
-	return false
-}
-
-type elementType byte
-
-const (
-	etSECTION_START elementType = 1
-	etSECTION_END               = 2
-	etKEY_VALUE                 = 3
-	etLIST_START                = 4
-	etLIST_ITEM                 = 5
-	etLIST_END                  = 6
-)
-
-type segment struct {
-	typ  segmentType
-	name string
-	msg  map[string]interface{}
-}
-
-//msg 在内部以下列3种类型表示(降低复杂度)
-// string
-// map[string]interface{}
-// []string
-func writeSegment(w io.Writer, msg segment) (err error) {
-	if !msg.typ.isValid() {
-		return fmt.Errorf("[writeSegment] msg.typ %d not defined", msg.typ)
-	}
-	buf := &bytes.Buffer{}
-	buf.WriteByte(byte(msg.typ))
-	//name
-	if msg.typ.hasName() {
-		err = writeString1(buf, msg.name)
-		if err != nil {
-			fmt.Printf("error returned from writeString1i \n")
-			return
-		}
-	}
-
-	if msg.typ.hasMsg() {
-		err = writeMap(buf, msg.msg)
-		if err != nil {
-			fmt.Printf("error retruned from writeMap \n")
-			return
-		}
-	}
-
-	//写长度
-	err = binary.Write(w, binary.BigEndian, uint32(buf.Len()))
-	if err != nil {
-		fmt.Printf("[writeSegment] error writing to binary \n")
-		return
-	}
-
-	_, err = buf.WriteTo(w)
-	if err != nil {
-		fmt.Printf("[writeSegment] error writing to buffer \n")
-		return
-	}
-
-	return nil
-}
-
-func readSegment(inR io.Reader) (msg segment, err error) {
-	//长度
-	var length uint32
-	err = binary.Read(inR, binary.BigEndian, &length)
-	if err != nil {
-		return
-	}
-	r := bufio.NewReader(&io.LimitedReader{
-		R: inR,
-		N: int64(length),
-	})
-	//类型
-	c, err := r.ReadByte()
-	if err != nil {
-		return
-	}
-	msg.typ = segmentType(c)
-	if !msg.typ.isValid() {
-		return msg, fmt.Errorf("[readSegment] msg.typ %d not defined", msg.typ)
-	}
-	if msg.typ.hasName() {
-		msg.name, err = readString1(r)
-		if err != nil {
-			return
-		}
-	}
-	if msg.typ.hasMsg() {
-		msg.msg, err = readMap(r, true)
-		if err != nil {
-			return
-		}
-	}
-	return
-}
-
-//一个字节长度的字符串
-func writeString1(w *bytes.Buffer, s string) (err error) {
-	length := len(s)
-	if length > 255 {
-		return fmt.Errorf("[writeString1] length>255")
-	}
-	w.WriteByte(byte(length))
-	w.WriteString(s)
-	return
-}
-
-func readString1(r *bufio.Reader) (s string, err error) {
-	length, err := r.ReadByte()
-	if err != nil {
-		return
-	}
-	buf := make([]byte, length)
-	_, err = io.ReadFull(r, buf)
-	if err != nil {
-		return
-	}
-	return string(buf), nil
-}
-
-//两个字节长度的字符串
-func writeString2(w *bytes.Buffer, s string) (err error) {
-	length := len(s)
-	if length > 65535 {
-		return fmt.Errorf("[writeString2] length>65535")
-	}
-	binary.Write(w, binary.BigEndian, uint16(length))
-	w.WriteString(s)
-	return
-}
-
-func readString2(r io.Reader) (s string, err error) {
-	var length uint16
-	err = binary.Read(r, binary.BigEndian, &length)
-	if err != nil {
-		return
-	}
-	buf := make([]byte, length)
-	_, err = io.ReadFull(r, buf)
-	if err != nil {
-		return
-	}
-	return string(buf), nil
-}
-
-func writeKeyMap(w *bytes.Buffer, name string, msg map[string]interface{}) (err error) {
-	w.WriteByte(byte(etSECTION_START))
-	err = writeString1(w, name)
-	if err != nil {
-		return
-	}
-	writeMap(w, msg)
-	w.WriteByte(byte(etSECTION_END))
-	return nil
-}
-
-func writeKeyList(w *bytes.Buffer, name string, msg []string) (err error) {
-	w.WriteByte(byte(etLIST_START))
-	err = writeString1(w, name)
-	if err != nil {
-		return
-	}
-	for _, s := range msg {
-		w.WriteByte(byte(etLIST_ITEM))
-		err = writeString2(w, s)
-		if err != nil {
-			return
-		}
-	}
-	w.WriteByte(byte(etLIST_END))
-	return nil
-}
-
-func writeKeyString(w *bytes.Buffer, name string, msg string) (err error) {
-	w.WriteByte(byte(etKEY_VALUE))
-	err = writeString1(w, name)
-	if err != nil {
-		return
-	}
-	err = writeString2(w, msg)
-	return
-}
-
-func writeMap(w *bytes.Buffer, msg map[string]interface{}) (err error) {
-	for k, v := range msg {
-		switch t := v.(type) {
-		case map[string]interface{}:
-			writeKeyMap(w, k, t)
-		case []string:
-			writeKeyList(w, k, t)
-		case string:
-			writeKeyString(w, k, t)
-		case []interface{}:
-			str := make([]string, len(t))
-			for i := range t {
-				str[i] = t[i].(string)
-			}
-			writeKeyList(w, k, str)
-		default:
-			return fmt.Errorf("[writeMap] can not write type %T right now", msg)
-		}
-	}
-	return nil
-}
-
-//SECTION_START has been read already.
-func readKeyMap(r *bufio.Reader) (key string, msg map[string]interface{}, err error) {
-	key, err = readString1(r)
-	if err != nil {
-		return
-	}
-	msg, err = readMap(r, false)
-	return
-}
-
-//LIST_START has been read already.
-func readKeyList(r *bufio.Reader) (key string, msg []string, err error) {
-	key, err = readString1(r)
-	if err != nil {
-		return
-	}
-	msg = []string{}
-	for {
-		var c byte
-		c, err = r.ReadByte()
-		if err != nil {
-			return
-		}
-		switch elementType(c) {
-		case etLIST_ITEM:
-			value, err := readString2(r)
-			if err != nil {
-				return "", nil, err
-			}
-			msg = append(msg, value)
-		case etLIST_END: //end of outer list
-			return key, msg, nil
-		default:
-			return "", nil, fmt.Errorf("[readKeyList] protocol error 2")
-		}
-	}
-	return
-}
-
-//KEY_VALUE has been read already.
-func readKeyString(r *bufio.Reader) (key string, msg string, err error) {
-	key, err = readString1(r)
-	if err != nil {
-		return
-	}
-	msg, err = readString2(r)
-	if err != nil {
-		return
-	}
-	return
-}
-
-//SECTION_START has been read already.
-func readMap(r *bufio.Reader, isRoot bool) (msg map[string]interface{}, err error) {
-	msg = map[string]interface{}{}
-	for {
-		c, err := r.ReadByte()
-		if err == io.EOF && isRoot { //may be root section
-			return msg, nil
-		}
-		if err != nil {
-			return nil, err
-		}
-		switch elementType(c) {
-		case etSECTION_START:
-			key, value, err := readKeyMap(r)
-			if err != nil {
-				return nil, err
-			}
-			msg[key] = value
-		case etLIST_START:
-			key, value, err := readKeyList(r)
-			if err != nil {
-				return nil, err
-			}
-			msg[key] = value
-		case etKEY_VALUE:
-			key, value, err := readKeyString(r)
-			if err != nil {
-				return nil, err
-			}
-			msg[key] = value
-		case etSECTION_END: //end of outer section
-			return msg, nil
-		default:
-			panic(fmt.Errorf("[readMap] protocol error 1, %d %#v", c, msg))
-			//return nil, fmt.Errorf("[readMap] protocol error 1, %d",c)
-		}
-	}
-	return
-}

+ 0 - 110
Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/msg_test.go

@@ -1,110 +0,0 @@
-package goStrongswanVici
-
-import (
-	"bytes"
-	"encoding/json"
-	"fmt"
-	"reflect"
-	"testing"
-)
-
-func TestMsg(ot *testing.T) {
-	for _, msg := range []map[string]interface{}{
-		map[string]interface{}{
-			"a": "1",
-		},
-		map[string]interface{}{
-			"a": []string{
-				"1", "2",
-			},
-		},
-		map[string]interface{}{
-			"a": map[string]interface{}{
-				"d": "e",
-				"e": []string{
-					"1", "2",
-				},
-			},
-		},
-		map[string]interface{}{
-			"a": []string{
-				"1", "2",
-			},
-			"b": "a",
-			"c": map[string]interface{}{
-				"d": "e",
-				"e": []string{
-					"1", "2",
-				},
-			},
-		},
-		map[string]interface{}{
-			"key1": "value1",
-			"section1": map[string]interface{}{
-				"sub-section": map[string]interface{}{
-					"key2": "value2",
-				},
-				"list1": []string{"item1", "item2"},
-			},
-		},
-	} {
-		buf := &bytes.Buffer{}
-		in := segment{
-			typ:  stCMD_REQUEST,
-			name: "good",
-			msg:  msg,
-		}
-		err := writeSegment(buf, in)
-		mustNotError(err)
-		content := buf.Bytes()
-		out, err := readSegment(buf)
-		mustNotError(err)
-		//fmt.Println(content)
-		if !reflect.DeepEqual(in, out) {
-			in1, err := json.Marshal(in.msg)
-			mustNotError(err)
-			out1, err := json.Marshal(out.msg)
-			mustNotError(err)
-			fmt.Println(content)
-			panic("!reflect.DeepEqual(in,out)\n" + string(in1) + "\n" + string(out1))
-		}
-	}
-
-	content := []byte{
-		0x0, 0x0, 0x0, 0x5e, //length 94
-		0x1,                                     //CMD_RESPONSE
-		0x3,                                     //KEY_VALUE
-		0x6, 0x64, 0x61, 0x65, 0x6d, 0x6f, 0x6e, //daemon
-		0x0, 0x6, 0x63, 0x68, 0x61, 0x72, 0x6f, 0x6e, //charon
-		0x3, 0x7, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x0, 0x5, 0x35, 0x2e, 0x32, 0x2e, 0x32,
-		0x3, 0x7, 0x73, 0x79, 0x73, 0x6e, 0x61, 0x6d, 0x65, 0x0, 0x5, 0x4c, 0x69, 0x6e, 0x75, 0x78, 0x3, 0x7, 0x72,
-		0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x0, 0x11, 0x33, 0x2e, 0x31, 0x33, 0x2e, 0x30, 0x2d, 0x34, 0x34, 0x2d,
-		0x67, 0x65, 0x6e, 0x65, 0x72, 0x69, 0x63, 0x3, 0x7, 0x6d, 0x61, 0x63, 0x68, 0x69, 0x6e, 0x65, 0x0, 0x6, 0x78,
-		0x38, 0x36, 0x5f, 0x36, 0x34}
-	buf := bytes.NewBuffer(content)
-	out, err := readSegment(buf)
-	mustNotError(err)
-
-	in := segment{
-		typ: stCMD_RESPONSE,
-		msg: map[string]interface{}{
-			"daemon":  "charon",
-			"machine": "x86_64",
-			"release": "3.13.0-44-generic",
-			"sysname": "Linux",
-			"version": "5.2.2",
-		},
-	}
-	if !reflect.DeepEqual(in, out) {
-		in1, err := json.Marshal(in.msg)
-		mustNotError(err)
-		out1, err := json.Marshal(out.msg)
-		mustNotError(err)
-		panic("!reflect.DeepEqual(in,out)\n" + string(in1) + "\n" + string(out1))
-	}
-}
-func mustNotError(err error) {
-	if err != nil {
-		panic(err)
-	}
-}

+ 0 - 32
Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/terminate.go

@@ -1,32 +0,0 @@
-package goStrongswanVici
-
-import (
-	"fmt"
-)
-
-type TerminateRequest struct {
-	Child    string `json:"child,omitempty"`
-	Ike      string `json:"ike,omitempty"`
-	Child_id string `json:"child-id,omitempty"`
-	Ike_id   string `json:"ike-id,omitempty"`
-	Timeout  string `json:"timeout,omitempty"`
-	Loglevel string `json:"loglevel,omitempty"`
-}
-
-// To be simple, kill a client that is connecting to this server. A client is a sa.
-//Terminates an SA while streaming control-log events.
-func (c *ClientConn) Terminate(r *TerminateRequest) (err error) {
-	err = handlePanic(func() (err error) {
-		reqMap := &map[string]interface{}{}
-		ConvertToGeneral(r, reqMap)
-		msg, err := c.Request("terminate", *reqMap)
-		if err != nil {
-			return
-		}
-		if msg["success"] != "yes" {
-			return fmt.Errorf("[Terminate] %s", msg["errmsg"])
-		}
-		return
-	})
-	return
-}

+ 0 - 24
Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/unloadConn.go

@@ -1,24 +0,0 @@
-package goStrongswanVici
-
-import (
-	"fmt"
-)
-
-type UnloadConnRequest struct {
-	Name string `json:"name"`
-}
-
-func (c *ClientConn) UnloadConn(r *UnloadConnRequest) error {
-	reqMap := &map[string]interface{}{}
-	ConvertToGeneral(r, reqMap)
-	msg, err := c.Request("unload-conn", *reqMap)
-	if err != nil {
-		return err
-	}
-
-	if msg["success"] != "yes" {
-		return fmt.Errorf("[Unload-Connection] %s", msg["errmsg"])
-	}
-
-	return nil
-}

+ 0 - 19
Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici/version.go

@@ -1,19 +0,0 @@
-package goStrongswanVici
-
-type Version struct {
-	Daemon  string `json:"daemon"`
-	Version string `json:"version"`
-	Sysname string `json:"sysname"`
-	Release string `json:"release"`
-	Machine string `json:"machine"`
-}
-
-func (c *ClientConn) Version() (out *Version, err error) {
-	msg, err := c.Request("version", nil)
-	if err != nil {
-		return
-	}
-	out = &Version{}
-	err = ConvertFromGeneral(msg, out)
-	return
-}

+ 3 - 2
backend/ipsec/handle_charon.go

@@ -21,8 +21,9 @@ import (
 	"syscall"
 	"time"
 
-	"github.com/coreos/flannel/Godeps/_workspace/src/github.com/bronze1man/goStrongswanVici"
-	log "github.com/coreos/flannel/Godeps/_workspace/src/github.com/golang/glog"
+	"github.com/bronze1man/goStrongswanVici"
+	log "github.com/golang/glog"
+
 	"github.com/coreos/flannel/subnet"
 )
 

+ 2 - 2
backend/ipsec/ipsec.go

@@ -20,8 +20,8 @@ import (
 	"encoding/json"
 	"fmt"
 
-	log "github.com/coreos/flannel/Godeps/_workspace/src/github.com/golang/glog"
-	"github.com/coreos/flannel/Godeps/_workspace/src/golang.org/x/net/context"
+	log "github.com/golang/glog"
+	"golang.org/x/net/context"
 
 	"github.com/coreos/flannel/backend"
 	"github.com/coreos/flannel/pkg/ip"

+ 3 - 3
backend/ipsec/network.go

@@ -21,9 +21,9 @@ import (
 	"sync"
 	"time"
 
-	log "github.com/coreos/flannel/Godeps/_workspace/src/github.com/golang/glog"
-	"github.com/coreos/flannel/Godeps/_workspace/src/github.com/vishvananda/netlink"
-	"github.com/coreos/flannel/Godeps/_workspace/src/golang.org/x/net/context"
+	log "github.com/golang/glog"
+	"github.com/vishvananda/netlink"
+	"golang.org/x/net/context"
 
 	"github.com/coreos/flannel/backend"
 	"github.com/coreos/flannel/subnet"

+ 3 - 0
glide.yaml

@@ -59,3 +59,6 @@ import:
   - pkg/watch
 - package: github.com/joho/godotenv
   version: v1.1
+- package: github.com/bronze1man/goStrongswanVici
+  version: 385ce24ffa11c0831da96e3e28b603464eaaa1a7
+

+ 8 - 0
subnet/kube/kube.go

@@ -325,3 +325,11 @@ func (ksm *kubeSubnetManager) WatchLease(ctx context.Context, sn ip.IP4Net, curs
 func (ksm *kubeSubnetManager) Name() string {
 	return fmt.Sprintf("Kubernetes Subnet Manager - %s", ksm.nodeName)
 }
+
+func (ksm *kubeSubnetManager) GetBackendData(ctx context.Context, network string) (string, error) {
+	return "", ErrUnimplemented
+}
+
+func (ksm *kubeSubnetManager) CreateBackendData(ctx context.Context, network, data string) error {
+	return ErrUnimplemented
+}