Blame 0103-network-use-arping2-if-available.patch

Harald Hoyer 414eba
From 9853791d376bee4a658d624424b32f7deae6ac79 Mon Sep 17 00:00:00 2001
Harald Hoyer 414eba
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 414eba
Date: Thu, 14 Jul 2016 14:24:31 +0200
Harald Hoyer 414eba
Subject: [PATCH] network: use arping2, if available
Harald Hoyer 414eba
Harald Hoyer 414eba
fixes https://github.com/dracutdevs/dracut/issues/135
Harald Hoyer 414eba
---
Harald Hoyer 414eba
 modules.d/40network/dhclient-script.sh | 13 ++++++++++---
Harald Hoyer 414eba
 modules.d/40network/ifup.sh            | 13 ++++++++++---
Harald Hoyer 414eba
 modules.d/40network/module-setup.sh    |  5 +++--
Harald Hoyer 414eba
 modules.d/40network/net-lib.sh         |  6 +++++-
Harald Hoyer 414eba
 4 files changed, 28 insertions(+), 9 deletions(-)
Harald Hoyer 414eba
Harald Hoyer 414eba
diff --git a/modules.d/40network/dhclient-script.sh b/modules.d/40network/dhclient-script.sh
Harald Hoyer 414eba
index 94ee9d1..2eade35 100755
Harald Hoyer 414eba
--- a/modules.d/40network/dhclient-script.sh
Harald Hoyer 414eba
+++ b/modules.d/40network/dhclient-script.sh
Harald Hoyer 414eba
@@ -159,9 +159,16 @@ case $reason in
Harald Hoyer 414eba
             read layer2 < /sys/class/net/$netif/device/layer2
Harald Hoyer 414eba
         fi
Harald Hoyer 414eba
         if [ "$layer2" != "0" ]; then
Harald Hoyer 414eba
-            if ! arping -f -q -D -c 2 -I $netif $new_ip_address ; then
Harald Hoyer 414eba
-                warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying"
Harald Hoyer 414eba
-                exit 1
Harald Hoyer 414eba
+            if command -v arping2 >/dev/null; then
Harald Hoyer 414eba
+                if arping2 -q -C 1 -c 2 -I $netif $new_ip_address ; then
Harald Hoyer 414eba
+                    warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying"
Harald Hoyer 414eba
+                    exit 1
Harald Hoyer 414eba
+                fi
Harald Hoyer 414eba
+            else
Harald Hoyer 414eba
+                if ! arping -f -q -D -c 2 -I $netif $new_ip_address ; then
Harald Hoyer 414eba
+                    warn "Duplicate address detected for $new_ip_address while doing dhcp. retrying"
Harald Hoyer 414eba
+                    exit 1
Harald Hoyer 414eba
+                fi
Harald Hoyer 414eba
             fi
Harald Hoyer 414eba
         fi
Harald Hoyer 414eba
         unset layer2
Harald Hoyer 414eba
diff --git a/modules.d/40network/ifup.sh b/modules.d/40network/ifup.sh
Harald Hoyer 414eba
index 41282e7..1461b91 100755
Harald Hoyer 414eba
--- a/modules.d/40network/ifup.sh
Harald Hoyer 414eba
+++ b/modules.d/40network/ifup.sh
Harald Hoyer 414eba
@@ -110,9 +110,16 @@ do_static() {
Harald Hoyer 414eba
         ip addr add $ip/$mask ${srv:+peer $srv} dev $netif
Harald Hoyer 414eba
         wait_for_ipv6_dad $netif
Harald Hoyer 414eba
     else
Harald Hoyer 414eba
-        if ! arping -f -q -D -c 2 -I $netif $ip; then
Harald Hoyer 414eba
-            warn "Duplicate address detected for $ip for interface $netif."
Harald Hoyer 414eba
-            return 1
Harald Hoyer 414eba
+        if command -v arping2 >/dev/null; then
Harald Hoyer 414eba
+            if arping2 -q -C 1 -c 2 -I $netif $ip ; then
Harald Hoyer 414eba
+                warn "Duplicate address detected for $ip for interface $netif."
Harald Hoyer 414eba
+                return 1
Harald Hoyer 414eba
+            fi
Harald Hoyer 414eba
+        else
Harald Hoyer 414eba
+            if ! arping -f -q -D -c 2 -I $netif $ip ; then
Harald Hoyer 414eba
+                warn "Duplicate address detected for $ip for interface $netif."
Harald Hoyer 414eba
+                return 1
Harald Hoyer 414eba
+            fi
Harald Hoyer 414eba
         fi
Harald Hoyer 414eba
         ip addr flush dev $netif
Harald Hoyer 414eba
         ip addr add $ip/$mask ${srv:+peer $srv} brd + dev $netif
Harald Hoyer 414eba
diff --git a/modules.d/40network/module-setup.sh b/modules.d/40network/module-setup.sh
Harald Hoyer 414eba
index 53b4b60..0501ffe 100755
Harald Hoyer 414eba
--- a/modules.d/40network/module-setup.sh
Harald Hoyer 414eba
+++ b/modules.d/40network/module-setup.sh
Harald Hoyer 414eba
@@ -4,7 +4,8 @@
Harald Hoyer 414eba
 check() {
Harald Hoyer 414eba
     local _program
Harald Hoyer 414eba
 
Harald Hoyer 414eba
-    require_binaries ip arping dhclient || return 1
Harald Hoyer 414eba
+    require_binaries ip dhclient || return 1
Harald Hoyer 414eba
+    require_any_binaries arping arping2 || return 1
Harald Hoyer 414eba
 
Harald Hoyer 414eba
     return 255
Harald Hoyer 414eba
 }
Harald Hoyer 414eba
@@ -23,7 +24,7 @@ installkernel() {
Harald Hoyer 414eba
 # called by dracut
Harald Hoyer 414eba
 install() {
Harald Hoyer 414eba
     local _arch _i _dir
Harald Hoyer 414eba
-    inst_multiple ip arping dhclient sed awk
Harald Hoyer 414eba
+    inst_multiple ip arping arping2 dhclient sed awk
Harald Hoyer 414eba
     inst_multiple -o ping ping6
Harald Hoyer 414eba
     inst_multiple -o brctl
Harald Hoyer 414eba
     inst_multiple -o teamd teamdctl teamnl
Harald Hoyer 414eba
diff --git a/modules.d/40network/net-lib.sh b/modules.d/40network/net-lib.sh
Harald Hoyer 414eba
index 9c1448d..92225c5 100755
Harald Hoyer 414eba
--- a/modules.d/40network/net-lib.sh
Harald Hoyer 414eba
+++ b/modules.d/40network/net-lib.sh
Harald Hoyer 414eba
@@ -169,7 +169,11 @@ setup_net() {
Harald Hoyer 414eba
     fi
Harald Hoyer 414eba
 
Harald Hoyer 414eba
     if [ "$layer2" != "0" ] && [ -n "$dest" ] && ! strstr "$dest" ":"; then
Harald Hoyer 414eba
-        arping -q -f -w 60 -I $netif $dest || info "Resolving $dest via ARP on $netif failed"
Harald Hoyer 414eba
+        if command -v arping2 >/dev/null; then
Harald Hoyer 414eba
+            arping2 -q -C 1 -c 60 -I $netif $dest || info "Resolving $dest via ARP on $netif failed"
Harald Hoyer 414eba
+        else
Harald Hoyer 414eba
+            arping -q -f -w 60 -I $netif $dest || info "Resolving $dest via ARP on $netif failed"
Harald Hoyer 414eba
+        fi
Harald Hoyer 414eba
     fi
Harald Hoyer 414eba
     unset layer2
Harald Hoyer 414eba