]> Cypherpunks.ru repositories - govpn.git/commitdiff
Ability to explicitly specify TAP interface, without up-script using
authorSergey Matveev <stargrave@stargrave.org>
Tue, 5 Jan 2016 10:17:56 +0000 (13:17 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 5 Jan 2016 10:17:56 +0000 (13:17 +0300)
Signed-off-by: Sergey Matveev <stargrave@stargrave.org>
doc/example.texi
doc/server.texi
src/govpn/cmd/govpn-client/main.go
src/govpn/cmd/govpn-server/common.go
src/govpn/cmd/govpn-server/conf.go
src/govpn/conf.go
utils/newclient.sh

index 6fd62dfd12becda2f470b11ec204e98793b4bbde..f734c65de829ba19e5e5ede3ff47e58d9268c2e6 100644 (file)
@@ -29,6 +29,7 @@ Place the following JSON configuration entry on the server's side:
 
     "Alice": {
         "up": "/path/to/up.sh",
+        "iface": "or TAP interface name",
         "verifier": "$argon2d$m=4096,t=128,p=1$bwR5VjeCYIQaa8SeaI3rqg$KCNIqfS4DGsBTtVytamAzcISgrlEWvNxan1UfBrFu10"
     }
 
@@ -39,14 +40,21 @@ Verifier was generated with:
 @end verbatim
 
 @strong{Prepare the server}. Add this entry to @code{peers.json}
-configuration file.
+configuration file:
+
+@verbatim
+{
+    "Alice": {
+        "iface": "tap10",
+        "verifier": "$argon2d$m=4096,t=128,p=1$bwR5VjeCYIQaa8SeaI3rqg$KCNIqfS4DGsBTtVytamAzcISgrlEWvNxan1UfBrFu10"
+    }
+}
+@end verbatim
 
 @strong{Prepare network on GNU/Linux IPv4 server}:
 
 @example
 server% umask 077
-server% echo "#!/bin/sh" > /path/to/up.sh
-server% echo "echo tap10" >> /path/to/up.sh
 server% ip addr add 192.168.0.1/24 dev wlan0
 server% tunctl -t tap10
 server% ip link set mtu 1432 dev tap10
index a00c45219329c0bc460deb2f712e92d6656f3776..7139ab3db45f30a0f0e3e306f88d637575e004c8 100644 (file)
@@ -26,7 +26,8 @@ Configuration file is JSON file with following example structure:
 @verbatim
 {
   "stargrave": {                        <-- Peer human readable name
-    "up": "./stargrave-up.sh",          <-- up-script
+    "iface": "tap10",                   <-- OPTIONAL TAP interface name
+    "up": "./stargrave-up.sh",          <-- OPTIONAL up-script
     "down": "./stargrave-down.sh",      <-- OPTIONAL down-script
     "timeout": 60,                      <-- OPTIONAL overriden timeout
     "noise": true,                      <-- OPTIONAL noise enabler
@@ -39,10 +40,14 @@ Configuration file is JSON file with following example structure:
 }
 @end verbatim
 
-up-script executes each time connection with the client is established.
-Its @emph{stdout} output must contain TAP interface name as the first
-line. This script can be simple @code{echo tap10}, or maybe more
-advanced like this:
+At least one of either @code{iface} or @code{up} must be specified. If
+you specify @code{iface}, then it will be forcefully used to determine
+what TAP interface will be used. If it is not specified, then up-script
+must output interface's name to stdout (first output line).
+
+For example up-script can be just @code{echo tap10}, or more advanced
+like the following one:
+
 @example
 #!/bin/sh
 $tap=$(ifconfig tap create)
@@ -65,6 +70,7 @@ Place the following JSON configuration entry on the server's side:
 
     "Alice": {
         "up": "/path/to/up.sh",
+        "iface": "or TAP interface name",
         "verifier": "$argon2d$m=4096,t=128,p=1$bwR5VjeCYIQaa8SeaI3rqg$KCNIqfS4DGsBTtVytamAzcISgrlEWvNxan1UfBrFu10"
     }
 [...]
index da7ac2bb270f54831a5eb51026e29e3f86d6d71f..9b5bf1891ad6fa00f110c5dec8987bd0c8046a78 100644 (file)
@@ -82,6 +82,7 @@ func main() {
        }
        conf = &govpn.PeerConf{
                Id:       verifier.Id,
+               Iface:    *ifaceName,
                Timeout:  time.Second * time.Duration(timeout),
                Noise:    *noisy,
                CPR:      *cpr,
index 3b3fcdae97f6168feeea8dccbcb067a694caca1a..313fc394aed7b70fc21e28d32b7f01bf5236ac9b 100644 (file)
@@ -67,15 +67,23 @@ Processor:
 }
 
 func callUp(peerId *govpn.PeerId) (string, error) {
-       result, err := govpn.ScriptCall(confs[*peerId].Up, "")
-       if err != nil {
-               log.Println("Script", confs[*peerId].Up, "call failed", err)
-               return "", err
+       ifaceName := confs[*peerId].Iface
+       if confs[*peerId].Up != "" {
+               result, err := govpn.ScriptCall(confs[*peerId].Up, "")
+               if err != nil {
+                       log.Println("Script", confs[*peerId].Up, "call failed", err)
+                       return "", err
+               }
+               if ifaceName == "" {
+                       sepIndex := bytes.Index(result, []byte{'\n'})
+                       if sepIndex < 0 {
+                               sepIndex = len(result)
+                       }
+                       ifaceName = string(result[:sepIndex])
+               }
        }
-       sepIndex := bytes.Index(result, []byte{'\n'})
-       if sepIndex < 0 {
-               sepIndex = len(result)
+       if ifaceName == "" {
+               log.Println("Can not obtain interface name for", *peerId)
        }
-       ifaceName := string(result[:sepIndex])
        return ifaceName, nil
 }
index 67ee695bcf753fa59a069418ce0949d7f5be3a4b..284f4f9dc5a2047b0cefed8c5f6d6e1728f15ad1 100644 (file)
@@ -60,6 +60,7 @@ func confRead() map[govpn.PeerId]*govpn.PeerConf {
                        Verifier: verifier,
                        Id:       verifier.Id,
                        Name:     name,
+                       Iface:    pc.Iface,
                        Up:       pc.Up,
                        Down:     pc.Down,
                        Noise:    pc.Noise,
index 600c83bff2f3ebdd8ed1ccd0f7cb957acd1f016c..eb69ec6d1de34b34dbe19e776cca5197e5613436 100644 (file)
@@ -27,6 +27,7 @@ import (
 type PeerConf struct {
        Id          *PeerId       `json:"-"`
        Name        string        `json:"name"`
+       Iface       string        `json:"iface"`
        Up          string        `json:"up"`
        Down        string        `json:"down"`
        TimeoutInt  int           `json:"timeout"`
index 4d49ff4cbb199601d856dfbf84794af6c2fb1266..a57becbd80af8544beea2a7772bfe31f67cd520f 100755 (executable)
@@ -30,6 +30,7 @@ Place the following JSON configuration entry on the server's side:
 
     "$username": {
         "up": "/path/to/up.sh",
+        "iface": "or TAP interface name",
         "verifier": "$verifierS"
     }