Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] LOCAL_IFNAME and GUEST_IFNAME max name size #205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions pipework
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
# (https://google-styleguide.googlecode.com/svn/trunk/shell.xml)
set -e

# default max size for interface names (cfr. IFNAMSIZ)
readonly IF_MAX_NAME_SIZE=15

# Random string used to compute interface names
readonly RAND_STRING=`for i in {0..16}; do rndval+=$(printf "%x" $(($RANDOM % 16)) ); done; echo $rndval`

case "$1" in
--wait)
WAIT=1
Expand Down Expand Up @@ -283,9 +289,9 @@ ln -s "/proc/$NSPID/ns/net" "/var/run/netns/$NSPID"
# If it's a bridge, we need to create a veth pair
[ "$IFTYPE" = bridge ] && {
if [ -z "$LOCAL_IFNAME" ]; then
LOCAL_IFNAME="v${CONTAINER_IFNAME}pl${NSPID}"
LOCAL_IFNAME="veth${NSPID}_"; LOCAL_IFNAME=$LOCAL_IFNAME${RAND_STRING:0:$IF_MAX_NAME_SIZE - ${#LOCAL_IFNAME}}
fi
GUEST_IFNAME="v${CONTAINER_IFNAME}pg${NSPID}"
GUEST_IFNAME="teth${NSPID}_"; GUEST_IFNAME=$GUEST_IFNAME${RAND_STRING:0:$IF_MAX_NAME_SIZE - ${#GUEST_IFNAME}}
# Does the link already exist?
if ip link show "$LOCAL_IFNAME" >/dev/null 2>&1; then
# link exists, is it in use?
Expand Down Expand Up @@ -323,7 +329,7 @@ ln -s "/proc/$NSPID/ns/net" "/var/run/netns/$NSPID"
if [ ! -z "$DIRECT_PHYS" ]; then
GUEST_IFNAME=$IFNAME
else
GUEST_IFNAME=ph$NSPID$CONTAINER_IFNAME
GUEST_IFNAME=ph$NSPID; GUEST_IFNAME=$GUEST_IFNAME${RAND_STRING:0:$IF_MAX_NAME_SIZE - ${#GUEST_IFNAME}}
ip link add link "$IFNAME" dev "$GUEST_IFNAME" mtu "$MTU" type macvlan mode bridge
fi

Expand Down Expand Up @@ -351,7 +357,7 @@ ln -s "/proc/$NSPID/ns/net" "/var/run/netns/$NSPID"

# If its a dummy interface, create a dummy interface.
[ "$IFTYPE" = dummy ] && {
GUEST_IFNAME=du$NSPID$CONTAINER_IFNAME
GUEST_IFNAME=du$NSPID; GUEST_IFNAME=$GUEST_IFNAME${RAND_STRING:0:$IF_MAX_NAME_SIZE - ${#GUEST_IFNAME}}
ip link add dev "$GUEST_IFNAME" type dummy
}

Expand Down