@@ -18,7 +18,6 @@ import (
1818 "fmt"
1919 "net"
2020 "strings"
21- "time"
2221
2322 "github.com/google/gopacket"
2423 "github.com/google/gopacket/layers"
@@ -32,27 +31,12 @@ import (
3231// that match with the prefix given to libnetwork
3332func RunContainerArping (net_ns_path string , pg_ifc_prefix string ) error {
3433
35- Log .Printf ("Attempting to acces the container %s NetNS" , net_ns_path )
3634 var netns ns.NetNS
3735 var err error
38- success := false
3936
40- for attempts := 0 ; attempts <= 5 ; attempts ++ {
41-
42- netns , err = ns .GetNS (net_ns_path )
43-
44- if err != nil {
45- Log .Printf ("Attempt %d: failed to open netns %s: %v" , attempts , net_ns_path , err )
46- time .Sleep (1 * time .Second )
47- } else {
48- success = true
49- break
50- }
51- attempts += 1
52- }
53-
54- if ! success {
55- return fmt .Errorf ("Attempts exhaused, could not access %s, exiting" , net_ns_path )
37+ netns , err = ns .GetNS (net_ns_path )
38+ if err != nil {
39+ return fmt .Errorf ("Failed to open netns %s: %v" , net_ns_path , err )
5640 }
5741 defer netns .Close ()
5842
@@ -70,8 +54,6 @@ func RunContainerArping(net_ns_path string, pg_ifc_prefix string) error {
7054 if strings .HasPrefix (ifc .Name , pg_ifc_prefix ) {
7155 // Valid PG-created ifc
7256
73- // TODO we might want to add a retry here to make sure,
74- // in case the IFC is up but still has no IP, we retry
7557 address_slice , err := ifc .Addrs ()
7658 if err != nil {
7759 Log .Errorf ("Failed to get Address slice for ifc %s: %v" , ifc .Name , err )
@@ -83,7 +65,6 @@ func RunContainerArping(net_ns_path string, pg_ifc_prefix string) error {
8365 continue
8466 }
8567
86- Log .Printf ("Attempting raw socket open on %s" , ifc .Name )
8768 handle , err := pcap .OpenLive (ifc .Name , 65536 , true , pcap .BlockForever )
8869 if err != nil {
8970 return fmt .Errorf ("Failed to open raw socket %s : %v" , ifc .Name , err )
@@ -105,18 +86,14 @@ func RunContainerArping(net_ns_path string, pg_ifc_prefix string) error {
10586 // Get ARP packet
10687 arp_pkt := getGratuitousArp (ifc .HardwareAddr , ip )
10788
108- for i := 0 ; i <= 3 ; i ++ {
109- Log .Printf ("Sending %d GARP on %s : %s - %s" ,
110- i , ifc .Name , ifc .HardwareAddr .String (), ip .String ())
89+ Log .Printf ("Sending %s GARP on %s : %s" ,
90+ ifc .Name , ifc .HardwareAddr .String (), ip .String ())
11191
112- if err := handle .WritePacketData (arp_pkt ); err != nil {
113- handle .Close ()
114- return fmt .Errorf ("Failed to write ARP packet data on %s : %v" , ifc .Name , err )
115- }
116- time .Sleep (750 * time .Millisecond )
92+ if err := handle .WritePacketData (arp_pkt ); err != nil {
93+ Log .Printf ("Failed to write ARP packet data on %s : %v" , ifc .Name , err )
94+ continue
11795 }
11896 }
119-
12097 // Close the socket
12198 handle .Close ()
12299 }
0 commit comments