0004-alfred-not-only-wait-for-the-interface-but-also-a-link-local-address.patch 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Sun, 9 Aug 2015 18:03:28 +0200
  3. Subject: alfred: not only wait for the interface, but also a link-local address
  4. Changes between alfred 2015.0 and 2015.1 cause alfred to print an error
  5. and exit when the interface to bind to is not completely set up (has no
  6. non-tentative link-local address). As a workaround, wait for such an
  7. address by reading /proc/net/if_inet6 before alfred is started.
  8. In the long term, it would be nice to make alfred more robust against
  9. missing interfaces (allowing alfred to start without the interface
  10. existing, and keeping it working even when the interface is removed and
  11. re-added while alfred is running).
  12. Signed-off-by: Matthias Schiffer <mschiffer@universe-factory.net>
  13. diff --git a/alfred/files/alfred.init b/alfred/files/alfred.init
  14. index 5ce06c0..8e1f11d 100755
  15. --- a/alfred/files/alfred.init
  16. +++ b/alfred/files/alfred.init
  17. @@ -37,6 +37,32 @@ wait_for_dir()
  18. fi
  19. }
  20. +wait_for_ll_address()
  21. +{
  22. + local iface="$1"
  23. + local timeout
  24. +
  25. + timeout=30
  26. + echo "${initscript}: waiting $timeout secs for $iface address..."
  27. + for i in $(seq $timeout); do
  28. + # We look for
  29. + # - the link-local address (starts with fe80)
  30. + # - without tentative flag (bit 0x40 in the flags field; the first char of the flags field begins 38 columns after the fe80 prefix
  31. + # - on interface $iface
  32. + if awk '
  33. + BEGIN { RET=1 }
  34. + /^fe80.{37} [012389ab]/ { if ($6 == "'"$iface"'") RET=0 }
  35. + END { exit RET }
  36. + ' /proc/net/if_inet6; then
  37. + return
  38. + fi
  39. + sleep 1
  40. + done
  41. +
  42. + echo "${initscript}: $iface address not detected, alfred not starting."
  43. + exit 1
  44. +}
  45. +
  46. alfred_start()
  47. {
  48. local args=""
  49. @@ -62,7 +88,7 @@ alfred_start()
  50. wait_for_dir "$batmanif" "/sys/class/net/$batmanif/mesh"
  51. fi
  52. - wait_for_dir "$interface" "/sys/class/net/$interface/"
  53. + wait_for_ll_address "$interface"
  54. append alfred_args "$args"
  55. enable=1