route.bash: seperate route remove function
This commit is contained in:
parent
dd27333906
commit
d7fd882770
@ -1,35 +1,69 @@
|
|||||||
add_route4() {
|
remove_route4() {
|
||||||
local interface="$1"
|
local interface="$1"
|
||||||
local subnet="$2"
|
local subnet="$2"
|
||||||
local gateway="$3"
|
local netmask="$3"
|
||||||
local netmask="$4"
|
local gateway="$4"
|
||||||
local cidr="$(mask2cidr $netmask)"
|
local cidr="$(mask2cidr $netmask)"
|
||||||
|
|
||||||
if has ip; then
|
if has ip; then
|
||||||
ip route del "$subnet/$cidr" via "$gateway" dev "$interface" || true
|
ip route del "$subnet/$cidr" via "$gateway" dev "$interface"
|
||||||
|
elif has route; then
|
||||||
|
route -n del -net "$subnet/$prefixlen" "$gateway"
|
||||||
|
else
|
||||||
|
die "no suitable program found to set routes, need iproute2 or ifconfig"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
add_route4() {
|
||||||
|
local interface="$1"
|
||||||
|
local subnet="$2"
|
||||||
|
local netmask="$3"
|
||||||
|
local gateway="$4"
|
||||||
|
local cidr="$(mask2cidr $netmask)"
|
||||||
|
|
||||||
|
remove_route4 "$interface" "$subnet" "$netmask" "$gateway" || true
|
||||||
|
|
||||||
|
if has ip; then
|
||||||
ip route add "$subnet/$cidr" via "$gateway" dev "$interface"
|
ip route add "$subnet/$cidr" via "$gateway" dev "$interface"
|
||||||
elif has route; then
|
elif has route; then
|
||||||
route -n del -net "$subnet/$prefixlen" "$gateway" || true
|
|
||||||
route -n add -net "$subnet/$prefixlen" "$gateway"
|
route -n add -net "$subnet/$prefixlen" "$gateway"
|
||||||
else
|
else
|
||||||
die "no suitable program found to set routes, need iproute2 or ifconfig"
|
die "no suitable program found to set routes, need iproute2 or ifconfig"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remove_route6() {
|
||||||
|
local interface="$1"
|
||||||
|
local subnet="$2"
|
||||||
|
local prefixlen="$3"
|
||||||
|
local gateway="$4"
|
||||||
|
|
||||||
|
if has ip; then
|
||||||
|
ip route del "$subnet/$prefixlen" via "$gateway" dev "$interface"
|
||||||
|
elif has route; then
|
||||||
|
if [[ "$gateway" == fe80* ]]; then
|
||||||
|
gateway="$gateway%$interface"
|
||||||
|
fi
|
||||||
|
route -n add -inet6 "$network" "$gateway" -prefixlen "$prefixlen"
|
||||||
|
else
|
||||||
|
die "no suitable program found to set routes, need iproute2 or ifconfig"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
add_route6() {
|
add_route6() {
|
||||||
local interface="$1"
|
local interface="$1"
|
||||||
local subnet="$2"
|
local subnet="$2"
|
||||||
local gateway="$3"
|
local prefixlen="$3"
|
||||||
local prefixlen="$4"
|
local gateway="$4"
|
||||||
|
|
||||||
|
remove_route6 "$interface" "$subnet" "$prefixlen" "$gateway" || true
|
||||||
|
|
||||||
if has ip; then
|
if has ip; then
|
||||||
ip route del "$subnet/$prefixlen" via "$gateway" dev "$interface" || true
|
|
||||||
ip route add "$subnet/$prefixlen" via "$gateway" dev "$interface"
|
ip route add "$subnet/$prefixlen" via "$gateway" dev "$interface"
|
||||||
if has route; then
|
elif has route; then
|
||||||
if [[ "$gateway" == fe80* ]]; then
|
if [[ "$gateway" == fe80* ]]; then
|
||||||
gateway="$gateway%$interface"
|
gateway="$gateway%$interface"
|
||||||
fi
|
fi
|
||||||
route -n add -inet6 "$network" "$gateway" -prefixlen "$prefixlen" || true
|
|
||||||
route -n add -inet6 "$network" "$gateway" -prefixlen "$prefixlen"
|
route -n add -inet6 "$network" "$gateway" -prefixlen "$prefixlen"
|
||||||
else
|
else
|
||||||
die "no suitable program found to set routes, need iproute2 or ifconfig"
|
die "no suitable program found to set routes, need iproute2 or ifconfig"
|
||||||
|
Loading…
Reference in New Issue
Block a user