net_helper.sh 514 B

12345678910111213141516171819202122232425
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Helper functions
  5. wait_local_port_listen()
  6. {
  7. local listener_ns="${1}"
  8. local port="${2}"
  9. local protocol="${3}"
  10. local pattern
  11. local i
  12. pattern=":$(printf "%04X" "${port}") "
  13. # for tcp protocol additionally check the socket state
  14. [ ${protocol} = "tcp" ] && pattern="${pattern}0A"
  15. for i in $(seq 10); do
  16. if ip netns exec "${listener_ns}" awk '{print $2" "$4}' \
  17. /proc/net/"${protocol}"* | grep -q "${pattern}"; then
  18. break
  19. fi
  20. sleep 0.1
  21. done
  22. }