File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -9,13 +9,33 @@ lower=$1
99shift
1010[ $# -gt 0 ] || set sh
1111
12+ # Detect if we're running inside the infamy container or on the host
13+ # Inside the container, we can directly access the interfaces
14+ # On the host, we need to use docker/podman exec
15+ if ip link show " $lower " > /dev/null 2>&1 ; then
16+ # We can see the lower interface directly, so we're in the right namespace
17+ lookup_ifname () {
18+ ip -j link show | jq -r " .[] | select(.ifindex == $1 ) | .ifname"
19+ }
20+ else
21+ # We're on the host, need to query the infamy container
22+ infamy=$( infamy 2> /dev/null) || {
23+ echo " ERROR: Cannot see interface '$lower ' and no infamy container found" >&2
24+ echo " Run this script from inside the infamy container or from the host with docker/podman available" >&2
25+ exit 1
26+ }
27+ lookup_ifname () {
28+ $( runner) exec $infamy ip -j link show | jq -r " .[] | select(.ifindex == $1 ) | .ifname"
29+ }
30+ fi
31+
1232for pid in $( pgrep -fx " sleep infinity" ) ; do
1333 ifidxs=$( nsenter -t $pid -U -n ip -j link show | \
1434 jq ' .[] | select(has("link_netnsid")) | .link_index' )
1535 for ifidx in $ifidxs ; do
16- ifname=$( ip -j link show | jq -r " .[] | select(.ifindex == $ifidx ) | .ifname " )
36+ ifname=$( lookup_ifname $ifidx )
1737 if [ " $ifname " = " $lower " ]; then
18- exec nsenter -t $pid -U -n env PS1=" $( build_ps1 " ( netns:$ifname )" ) " " $@ "
38+ exec nsenter -t $pid -U -n env PS1=" ( netns:$ifname ) # " " $@ "
1939 fi
2040 done
2141done
You can’t perform that action at this time.
0 commit comments