2021-10-12 19:46:53 +02:00
|
|
|
//go:build ignore
|
2021-01-21 00:02:32 +01:00
|
|
|
|
|
|
|
/* SPDX-License-Identifier: MIT
|
|
|
|
*
|
2022-09-20 17:21:32 +02:00
|
|
|
* Copyright (C) 2017-2023 WireGuard LLC. All Rights Reserved.
|
2021-01-21 00:02:32 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
2022-03-17 00:09:48 +01:00
|
|
|
"net/netip"
|
2021-03-06 16:21:18 +01:00
|
|
|
|
2024-01-07 20:03:11 +01:00
|
|
|
"gitea.hbanafa.com/hesham/wireguard-go/conn"
|
|
|
|
"gitea.hbanafa.com/hesham/wireguard-go/device"
|
|
|
|
"gitea.hbanafa.com/hesham/wireguard-go/tun/netstack"
|
2021-01-21 00:02:32 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
tun, tnet, err := netstack.CreateNetTUN(
|
2021-11-05 01:52:54 +01:00
|
|
|
[]netip.Addr{netip.MustParseAddr("192.168.4.29")},
|
|
|
|
[]netip.Addr{netip.MustParseAddr("8.8.8.8"), netip.MustParseAddr("8.8.4.4")},
|
2021-01-21 00:02:32 +01:00
|
|
|
1420,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
log.Panic(err)
|
|
|
|
}
|
2021-03-06 16:21:18 +01:00
|
|
|
dev := device.NewDevice(tun, conn.NewDefaultBind(), device.NewLogger(device.LogLevelVerbose, ""))
|
2021-10-06 12:40:01 +02:00
|
|
|
dev.IpcSet(`private_key=003ed5d73b55806c30de3f8a7bdab38af13539220533055e635690b8b87ad641
|
|
|
|
listen_port=58120
|
|
|
|
public_key=f928d4f6c1b86c12f2562c10b07c555c5c57fd00f59e90c8d8d88767271cbf7c
|
|
|
|
allowed_ip=192.168.4.28/32
|
2021-01-21 00:02:32 +01:00
|
|
|
persistent_keepalive_interval=25
|
2021-03-06 16:21:18 +01:00
|
|
|
`)
|
2021-01-21 00:02:32 +01:00
|
|
|
dev.Up()
|
|
|
|
listener, err := tnet.ListenTCP(&net.TCPAddr{Port: 80})
|
|
|
|
if err != nil {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
|
|
|
http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
|
|
|
|
log.Printf("> %s - %s - %s", request.RemoteAddr, request.URL.String(), request.UserAgent())
|
|
|
|
io.WriteString(writer, "Hello from userspace TCP!")
|
|
|
|
})
|
|
|
|
err = http.Serve(listener, nil)
|
|
|
|
if err != nil {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
|
|
|
}
|