2017-05-30 22:36:49 +02:00
|
|
|
package main
|
|
|
|
|
2017-06-26 13:14:02 +02:00
|
|
|
import (
|
2017-06-29 14:39:21 +02:00
|
|
|
"fmt"
|
2017-06-28 23:45:45 +02:00
|
|
|
"log"
|
|
|
|
"net"
|
2017-06-29 14:39:21 +02:00
|
|
|
"os"
|
2017-06-26 13:14:02 +02:00
|
|
|
)
|
2017-06-04 21:48:15 +02:00
|
|
|
|
2017-06-29 14:39:21 +02:00
|
|
|
/* TODO: Fix logging
|
|
|
|
* TODO: Fix daemon
|
2017-06-28 23:45:45 +02:00
|
|
|
*/
|
|
|
|
|
2017-06-04 21:48:15 +02:00
|
|
|
func main() {
|
2017-06-29 14:39:21 +02:00
|
|
|
|
|
|
|
if len(os.Args) != 2 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
deviceName := os.Args[1]
|
|
|
|
|
2017-06-28 23:45:45 +02:00
|
|
|
// Open TUN device
|
2017-06-04 21:48:15 +02:00
|
|
|
|
2017-06-28 23:45:45 +02:00
|
|
|
// TODO: Fix capabilities
|
2017-06-04 21:48:15 +02:00
|
|
|
|
2017-06-29 14:39:21 +02:00
|
|
|
tun, err := CreateTUN(deviceName)
|
2017-06-28 23:45:45 +02:00
|
|
|
log.Println(tun, err)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
2017-06-04 21:48:15 +02:00
|
|
|
|
2017-06-28 23:45:45 +02:00
|
|
|
device := NewDevice(tun)
|
2017-06-04 21:48:15 +02:00
|
|
|
|
2017-06-28 23:45:45 +02:00
|
|
|
// Start configuration lister
|
2017-06-04 21:48:15 +02:00
|
|
|
|
2017-06-29 14:39:21 +02:00
|
|
|
socketPath := fmt.Sprintf("/var/run/wireguard/%s.sock", deviceName)
|
|
|
|
l, err := net.Listen("unix", socketPath)
|
2017-05-30 22:36:49 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal("listen error:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
2017-06-29 14:39:21 +02:00
|
|
|
conn, err := l.Accept()
|
2017-05-30 22:36:49 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal("accept error:", err)
|
|
|
|
}
|
2017-06-29 14:39:21 +02:00
|
|
|
go ipcHandle(device, conn)
|
2017-05-30 22:36:49 +02:00
|
|
|
}
|
|
|
|
}
|