@@ -10,6 +10,7 @@ import (
1010 "net/http"
1111 "os"
1212 "os/exec"
13+ "slices"
1314 "strings"
1415 "time"
1516
@@ -58,7 +59,7 @@ func main() {
5859 log .Fatal (err )
5960 }
6061 for _ , link := range links {
61- if contains (expected , link .Attrs ().Name ) {
62+ if slices . Contains (expected , link .Attrs ().Name ) {
6263 log .Infof ("interface %s prevented this program to run" , link .Attrs ().Name )
6364 return
6465 }
@@ -71,23 +72,16 @@ func main() {
7172 }
7273}
7374
74- func contains (s []string , e string ) bool {
75- for _ , a := range s {
76- if a == e {
77- return true
78- }
79- }
80- return false
81- }
82-
8375func run () error {
76+ log .Infof ("Dialing to %s…" , endpoint )
8477 conn , path , err := transport .Dial (endpoint )
8578 if err != nil {
8679 return errors .Wrap (err , "cannot connect to host" )
8780 }
8881 defer conn .Close ()
8982
9083 if path != "" {
84+ log .Infof ("Sending post request to %s" , path )
9185 req , err := http .NewRequest ("POST" , path , nil )
9286 if err != nil {
9387 return err
@@ -97,6 +91,7 @@ func run() error {
9791 }
9892 }
9993
94+ log .Infof ("Configuring tap device %s" , iface )
10095 tap , err := water .New (water.Config {
10196 DeviceType : water .TAP ,
10297 PlatformSpecificParams : water.PlatformSpecificParams {
@@ -109,11 +104,14 @@ func run() error {
109104 defer tap .Close ()
110105
111106 if ! tapPreexists {
107+ log .Infof ("Enabling tap device %s" , iface )
112108 if err := linkUp (); err != nil {
113109 return errors .Wrap (err , "cannot set mac address" )
114110 }
115111 }
116112
113+ log .Infof ("Starting rx/tx loops" )
114+
117115 errCh := make (chan error , 1 )
118116 go tx (conn , tap , errCh , mtu )
119117 go rx (conn , tap , errCh , mtu )
@@ -177,7 +175,7 @@ func rx(conn net.Conn, tap *water.Interface, errCh chan error, mtu int) {
177175 }
178176
179177 if n < 0 || n > math .MaxUint16 {
180- log .Errorf ("invalid frame length" )
178+ errCh <- fmt .Errorf ("invalid frame length (%d > %d)" , n , math . MaxUint16 )
181179 return
182180 }
183181 binary .LittleEndian .PutUint16 (size , uint16 (n ))
0 commit comments