1*50b3ed57SPetar Penkov#!/bin/bash 2*50b3ed57SPetar Penkov# SPDX-License-Identifier: GPL-2.0 3*50b3ed57SPetar Penkov# 4*50b3ed57SPetar Penkov# add private ipv4 and ipv6 addresses to loopback 5*50b3ed57SPetar Penkov 6*50b3ed57SPetar Penkovreadonly V6_INNER='100::a/128' 7*50b3ed57SPetar Penkovreadonly V4_INNER='192.168.0.1/32' 8*50b3ed57SPetar Penkov 9*50b3ed57SPetar Penkovif getopts ":s" opt; then 10*50b3ed57SPetar Penkov readonly SIT_DEV_NAME='sixtofourtest0' 11*50b3ed57SPetar Penkov readonly V6_SIT='2::/64' 12*50b3ed57SPetar Penkov readonly V4_SIT='172.17.0.1/32' 13*50b3ed57SPetar Penkov shift 14*50b3ed57SPetar Penkovfi 15*50b3ed57SPetar Penkov 16*50b3ed57SPetar Penkovfail() { 17*50b3ed57SPetar Penkov echo "error: $*" 1>&2 18*50b3ed57SPetar Penkov exit 1 19*50b3ed57SPetar Penkov} 20*50b3ed57SPetar Penkov 21*50b3ed57SPetar Penkovsetup() { 22*50b3ed57SPetar Penkov ip -6 addr add "${V6_INNER}" dev lo || fail 'failed to setup v6 address' 23*50b3ed57SPetar Penkov ip -4 addr add "${V4_INNER}" dev lo || fail 'failed to setup v4 address' 24*50b3ed57SPetar Penkov 25*50b3ed57SPetar Penkov if [[ -n "${V6_SIT}" ]]; then 26*50b3ed57SPetar Penkov ip link add "${SIT_DEV_NAME}" type sit remote any local any \ 27*50b3ed57SPetar Penkov || fail 'failed to add sit' 28*50b3ed57SPetar Penkov ip link set dev "${SIT_DEV_NAME}" up \ 29*50b3ed57SPetar Penkov || fail 'failed to bring sit device up' 30*50b3ed57SPetar Penkov ip -6 addr add "${V6_SIT}" dev "${SIT_DEV_NAME}" \ 31*50b3ed57SPetar Penkov || fail 'failed to setup v6 SIT address' 32*50b3ed57SPetar Penkov ip -4 addr add "${V4_SIT}" dev "${SIT_DEV_NAME}" \ 33*50b3ed57SPetar Penkov || fail 'failed to setup v4 SIT address' 34*50b3ed57SPetar Penkov fi 35*50b3ed57SPetar Penkov 36*50b3ed57SPetar Penkov sleep 2 # avoid race causing bind to fail 37*50b3ed57SPetar Penkov} 38*50b3ed57SPetar Penkov 39*50b3ed57SPetar Penkovcleanup() { 40*50b3ed57SPetar Penkov if [[ -n "${V6_SIT}" ]]; then 41*50b3ed57SPetar Penkov ip -4 addr del "${V4_SIT}" dev "${SIT_DEV_NAME}" 42*50b3ed57SPetar Penkov ip -6 addr del "${V6_SIT}" dev "${SIT_DEV_NAME}" 43*50b3ed57SPetar Penkov ip link del "${SIT_DEV_NAME}" 44*50b3ed57SPetar Penkov fi 45*50b3ed57SPetar Penkov 46*50b3ed57SPetar Penkov ip -4 addr del "${V4_INNER}" dev lo 47*50b3ed57SPetar Penkov ip -6 addr del "${V6_INNER}" dev lo 48*50b3ed57SPetar Penkov} 49*50b3ed57SPetar Penkov 50*50b3ed57SPetar Penkovtrap cleanup EXIT 51*50b3ed57SPetar Penkov 52*50b3ed57SPetar Penkovsetup 53*50b3ed57SPetar Penkov"$@" 54*50b3ed57SPetar Penkovexit "$?" 55