Skip to content

Instantly share code, notes, and snippets.

@iMasaruOki
Created February 28, 2020 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iMasaruOki/a4e4cf03f4b754cb5d5f17633276a381 to your computer and use it in GitHub Desktop.
Save iMasaruOki/a4e4cf03f4b754cb5d5f17633276a381 to your computer and use it in GitHub Desktop.
similar to "ip vrf exec" for linux kernel 4.9
#!/bin/sh
EXEC=
ARG="$@"
VRF=$1
if [ "x$USER" != "xroot" ]; then
echo "Root privileges are required for this operation"
exit 1
fi
ip link show $VRF > /dev/null 2>&1
if [ "$?" != 0 ]; then
echo "VRF $VRF does not exist."
exit 1
fi
ip link show $VRF | grep MASTER > /dev/null 2>&1
if [ "$?" != 0 ]; then
echo "$VRF is not VRF."
exit 1
fi
cgget -r l3mdev.master-device $VRF 2>&1 | grep cannot > /dev/null 2>&1
if [ "$?" = 0 ]; then
$EXEC cgcreate -g l3mdev:$VRF
fi
$EXEC cgset -r l3mdev.master-device=$VRF $VRF
$EXEC cgexec -g l3mdev:$ARG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment