Compare commits
2 commits
master
...
contrib/49
Author | SHA1 | Date | |
---|---|---|---|
df9c689cba | |||
a9b0d34bb2 |
1 changed files with 11 additions and 5 deletions
|
@ -144,9 +144,12 @@ CONTAINER_IFNAME=${CONTAINER_IFNAME:-eth1}
|
||||||
|
|
||||||
# Second step: find the guest (for now, we only support LXC containers)
|
# Second step: find the guest (for now, we only support LXC containers)
|
||||||
while read _ mnt fstype options _; do
|
while read _ mnt fstype options _; do
|
||||||
[ "$fstype" != "cgroup" ] && continue
|
[ "$fstype" != "cgroup2" ] && [ "$fstype" != "cgroup" ] && continue
|
||||||
|
if [ "$fstype" = "cgroup" ]; then
|
||||||
echo "$options" | grep -qw devices || continue
|
echo "$options" | grep -qw devices || continue
|
||||||
|
fi
|
||||||
CGROUPMNT=$mnt
|
CGROUPMNT=$mnt
|
||||||
|
CGROUPTYPE=$fstype
|
||||||
done < /proc/mounts
|
done < /proc/mounts
|
||||||
|
|
||||||
[ "$CGROUPMNT" ] || {
|
[ "$CGROUPMNT" ] || {
|
||||||
|
@ -154,7 +157,9 @@ done < /proc/mounts
|
||||||
}
|
}
|
||||||
|
|
||||||
# Try to find a cgroup matching exactly the provided name.
|
# Try to find a cgroup matching exactly the provided name.
|
||||||
N=$(find "$CGROUPMNT" -name "$GUESTNAME" | wc -l)
|
[ "$CGROUPTYPE" = "cgroup" ] && N=$(find "$CGROUPMNT" -name "$GUESTNAME" | wc -l)
|
||||||
|
[ "$CGROUPTYPE" = "cgroup2" ] && N=$(find "$CGROUPMNT" -name "lxc.payload.$GUESTNAME" | wc -l)
|
||||||
|
|
||||||
case "$N" in
|
case "$N" in
|
||||||
0)
|
0)
|
||||||
# If we didn't find anything, try to lookup the container with Docker.
|
# If we didn't find anything, try to lookup the container with Docker.
|
||||||
|
@ -235,7 +240,8 @@ fi
|
||||||
if [ "$DOCKERPID" ]; then
|
if [ "$DOCKERPID" ]; then
|
||||||
NSPID=$DOCKERPID
|
NSPID=$DOCKERPID
|
||||||
else
|
else
|
||||||
NSPID=$(head -n 1 "$(find "$CGROUPMNT" -name "$GUESTNAME" | head -n 1)/tasks")
|
NSPATH=$(find "$CGROUPMNT" -name "$GUESTNAME" | head -n 1)
|
||||||
|
[ -f "$NSPATH/tasks" ] && NSPID=$(head -n 1 "$NSPATH/tasks")
|
||||||
[ "$NSPID" ] || {
|
[ "$NSPID" ] || {
|
||||||
# it is an alternative way to get the pid
|
# it is an alternative way to get the pid
|
||||||
NSPID=$(lxc-info -n "$GUESTNAME" | grep PID | grep -Eo '[0-9]+')
|
NSPID=$(lxc-info -n "$GUESTNAME" | grep PID | grep -Eo '[0-9]+')
|
||||||
|
@ -390,7 +396,7 @@ else
|
||||||
;;
|
;;
|
||||||
"")
|
"")
|
||||||
if installed ipcalc; then
|
if installed ipcalc; then
|
||||||
eval $(ipcalc -b $IPADDR)
|
eval "$(ipcalc -b $IPADDR)"
|
||||||
ip netns exec "$NSPID" ip addr add "$IPADDR" brd "$BROADCAST" dev "$CONTAINER_IFNAME"
|
ip netns exec "$NSPID" ip addr add "$IPADDR" brd "$BROADCAST" dev "$CONTAINER_IFNAME"
|
||||||
else
|
else
|
||||||
ip netns exec "$NSPID" ip addr add "$IPADDR" dev "$CONTAINER_IFNAME"
|
ip netns exec "$NSPID" ip addr add "$IPADDR" dev "$CONTAINER_IFNAME"
|
||||||
|
|
Loading…
Reference in a new issue