run_net_test: UML - fix insufficient entropy problems
This resolves IPv6 ping problems on recent (for example 4.17) kernels.
Change-Id: I5310bad2f3148d1195367aade10b9761995134a4
diff --git a/net/test/net_test.sh b/net/test/net_test.sh
index e2ed6b1..0c3a3ad 100755
--- a/net/test/net_test.sh
+++ b/net/test/net_test.sh
@@ -1,4 +1,21 @@
#!/bin/bash
+if [[ -n "${entropy}" ]]; then
+ echo "adding entropy from hex string [${entropy}]" 1>&2
+
+ # In kernel/include/uapi/linux/random.h RNDADDENTROPY is defined as
+ # _IOW('R', 0x03, int[2]) =(R is 0x52)= 0x40085203 = 1074287107
+ python 3>/dev/random <<EOF
+import fcntl, struct
+rnd = '${entropy}'.decode('hex')
+fcntl.ioctl(3, 0x40085203, struct.pack('ii', len(rnd) * 8, len(rnd)) + rnd)
+EOF
+
+ # This is probably not truly required, but let us give the system
+ # just a moment to catch up. Mostly this just makes sure that
+ # the 'random: crng init done' kernel message has a chance to print
+ # out before we continue...
+ sleep 0.2
+fi
# In case IPv6 is compiled as a module.
[ -f /proc/net/if_inet6 ] || insmod $DIR/kernel/net-next/net/ipv6/ipv6.ko
diff --git a/net/test/run_net_test.sh b/net/test/run_net_test.sh
index 4c089f9..1b5c9f6 100755
--- a/net/test/run_net_test.sh
+++ b/net/test/run_net_test.sh
@@ -273,6 +273,17 @@
# Use UML's /proc/exitcode feature to communicate errors on test failure
cmdline="$cmdline net_test_exitcode=/proc/exitcode"
+ # Experience shows we need at least 128 bits of entropy for the kernel's
+ # crng init to complete, hence net_test.sh needs at least 32 hex chars
+ # (which is the amount of hex in a single random UUID) provided to it on
+ # the kernel cmdline.
+ #
+ # We'll pass in 256 bits just to be safe, ie. a random 64 hex char seed.
+ # We do this by getting *two* random UUIDs and concatenating their hex
+ # digits into an even length hex encoded string.
+ entropy="$(cat /proc/sys/kernel/random{/,/}uuid | tr -d '\n-')"
+ cmdline="${cmdline} entropy=${entropy}"
+
# Map the --readonly flag to UML block device names
if ((nowrite == 0)); then
blockdevice=ubda