From 3e32746ed50d6bc700d0550f528d9194e29c96e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=80=9D=E6=95=8F?= Date: Mon, 29 Aug 2022 15:14:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 43 +++++++++++++++++++++---------------------- netcard.go | 6 ++++-- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/main.go b/main.go index 34fd6b9..f302671 100644 --- a/main.go +++ b/main.go @@ -26,31 +26,28 @@ var ( flagAddr = flag.String("addr", "", "addr set") ) +func startCard() { + cmdstr := fmt.Sprintf("ip addr add %s dev stun", *flagAddr) + log.Println(cmdstr) + cmd := strings.Split(cmdstr, " ") + err := exec.Command(cmd[0], cmd[1:]...).Run() + if err != nil { + log.Panic(err) + } + + cmdstr = "ip link set dev stun up" + cmd = strings.Split(cmdstr, " ") + err = exec.Command(cmd[0], cmd[1:]...).Run() + if err != nil { + log.Panic(err) + } +} func testmain() { flag.Parse() - var a chan bool = make(chan bool) - go func() { - <-a - cmdstr := fmt.Sprintf("ip addr add %s dev stun", *flagAddr) - log.Println(cmdstr) - cmd := strings.Split(cmdstr, " ") - err := exec.Command(cmd[0], cmd[1:]...).Run() - if err != nil { - log.Panic(err) - } - - cmdstr = "ip link set dev stun up" - cmd = strings.Split(cmdstr, " ") - err = exec.Command(cmd[0], cmd[1:]...).Run() - if err != nil { - log.Panic(err) - } - }() - config := water.Config{ - DeviceType: water.TUN, + DeviceType: water.TAP, } config.Name = "stun" @@ -58,10 +55,12 @@ func testmain() { if err != nil { log.Fatal(err) } - a <- true - var frame ethernet.Frame + startCard() + + var frame ethernet.Frame for { + frame.Resize(1500) n, err := ifce.Read([]byte(frame)) if err != nil { diff --git a/netcard.go b/netcard.go index d0438a3..65f2327 100644 --- a/netcard.go +++ b/netcard.go @@ -145,8 +145,9 @@ func NewNetCard() *NetCard { config := water.Config{ DeviceType: water.TUN, PlatformSpecificParams: water.PlatformSpecificParams{ - Name: "stun", - Persist: true, + Name: "stun", + Persist: true, + MultiQueue: true, }, } @@ -219,6 +220,7 @@ func (nc *NetCard) runRead() { bytesMap[realAddr] = buffer } + ifce.Write([]byte(rframe)) buffer.BytesArray = append(buffer.BytesArray, []byte(rframe)) }