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