1*3bdd9fd2SLucas Karpinski#!/bin/bash 2*3bdd9fd2SLucas Karpinski# SPDX-License-Identifier: GPL-2.0 3*3bdd9fd2SLucas Karpinski# 4*3bdd9fd2SLucas Karpinski# Helper functions 5*3bdd9fd2SLucas Karpinski 6*3bdd9fd2SLucas Karpinskiwait_local_port_listen() 7*3bdd9fd2SLucas Karpinski{ 8*3bdd9fd2SLucas Karpinski local listener_ns="${1}" 9*3bdd9fd2SLucas Karpinski local port="${2}" 10*3bdd9fd2SLucas Karpinski local protocol="${3}" 11*3bdd9fd2SLucas Karpinski local port_hex 12*3bdd9fd2SLucas Karpinski local i 13*3bdd9fd2SLucas Karpinski 14*3bdd9fd2SLucas Karpinski port_hex="$(printf "%04X" "${port}")" 15*3bdd9fd2SLucas Karpinski for i in $(seq 10); do 16*3bdd9fd2SLucas Karpinski if ip netns exec "${listener_ns}" cat /proc/net/"${protocol}"* | \ 17*3bdd9fd2SLucas Karpinski grep -q "${port_hex}"; then 18*3bdd9fd2SLucas Karpinski break 19*3bdd9fd2SLucas Karpinski fi 20*3bdd9fd2SLucas Karpinski sleep 0.1 21*3bdd9fd2SLucas Karpinski done 22*3bdd9fd2SLucas Karpinski} 23