1
0
This repository has been archived on 2025-01-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
alacn1_pace_v5471/squashfs-root/etc/bewan/lib/ipv6_routing_functions
Anderson Luiz Alves 0464e230c1 stock 103961
2017-07-30 16:48:04 -03:00

207 lines
6.2 KiB
Bash
Executable File

#!/bin/sh
# IPv6 routing functions, included by /etc/bewan/init.d/routes
# This file is largely shared by what's in ipv6_routing_functions.
# So when you fix something here, please take a look at the other.
[ ${IPV6_ROUTING_LIB:-0} = 1 ] && return
IPV6_ROUTING_LIB=1
check_routes_ipv6() {
base_check_arg "test -f $IP6ENABLE" "test -d $ROUTE6D"
}
stop_routes_ipv6() {
local i j
for i in `ls $ROUTE6D`; do
if [ "$i" != 'status' ]; then
local rtdir=$ROUTE6D/$i
for j in `ls $rtdir`; do
ip -6 route flush table $j 2>/dev/null
local rule
rule=`cat $rtdir/$j/rule 2>/dev/null`
[ "$rule" != '' ] && ip -6 rule del $rule 2>&1 | base_log - debug
done
fi
done
rm -rf $ROUTE6D
ip -6 route flush table default
rm -f $WAND/default6
}
init_routes_ipv6() {
# Change the priority of routing lookup
# We search in the main table first
# Then check the additional source routing rules
# We finally lookup the default table
ip -6 rule del pref 10 lookup main 2>/dev/null
ip -6 rule del pref 32766 lookup main 2>/dev/null
ip -6 rule add pref 10 lookup main
}
start_routes_ipv6() {
local i router
mkdir -p $ROUTE6D
# Brings-up the main default route
local defrte=$Layer3Forwarding_DefaultConnectionService6
local ifname=`cat $WAND/$defrte/ip6/ifname 2>/dev/null`
local ipaddr=`cat $WAND/$defrte/ip6/ipaddr 2>/dev/null`
local fakeip=`cat $WAND/$defrte/ip6/fakeip 2>/dev/null`
local routers=`cat $WAND/$defrte/ip6/routers 2>/dev/null`
echo "$defrte" >$WAND/default6
if [ "$routers" != '' ]; then
for router in $routers; do
ip -6 route add default metric 5 via $router dev $ifname table default 2>&1 | base_log - debug
done
elif [ "$ipaddr" != '' ] || [ "$fakeip" != '' ]; then
ip -6 route add default metric 5 dev $ifname table default 2>&1 | base_log - debug
fi
}
add_route_ipv6() {
local ext; eval ext=\${$l3f$i'_External'}
local intf; eval intf=\${$l3f$i'_Interface'}
local srcip; eval srcip=\${$l3f$i'_SourceIPAddress'}
local srcprefix; eval srcprefix=\${$l3f$i'_SourcePrefix'}
local dstip; eval dstip=\${$l3f$i'_DestIPAddress'}
local dstprefix; eval dstprefix=\${$l3f$i'_DestPrefix'}
local tos; eval tos=\${$l3f$i'_TOS'}
local mark; eval mark=\${$l3f$i'_Mark'}
local gateway; eval gateway=\${$l3f$i'_GatewayIPAddress'}
local metric; eval metric=\${$l3f$i'_ForwardingMetric'}
local mtu; eval mtu=\${$l3f$i'_MTU'}
local table; eval table=\${$l3f$i'_RoutingTable'}
local pref; eval pref=\${$l3f$i'_RoutingTablePref'}
# Not an ipv6 address, should we complain ?
if [ "$gateway" != '' ]; then isip6 $gateway || return; fi
if [ "$srcip" != '' ]; then isip6 $srcip || return; fi
if [ "$dstip" != '' ]; then isip6 $dstip || return; fi
local dst
if [ "$dstip" = '' ] || [ "$dstip" = '::' ]; then
dst='default'
else
[ "$dstprefix" = '' ] && dstprefix=128
dst="$dstip/$dstprefix"
fi
local dest="$dst"
if [ "$mtu" != '' ]; then
dest="$dest mtu $mtu"
fi
if [ "$metric" != '' ]; then
dest="$dest metric $metric"
fi
local ifname ipaddr fakeip routers rtdir
if [ "$intf" = 0 ]; then
ifname='' ipaddr='' fakeip='' routers=''
rtdir="$ROUTE6D/unreachable"
elif [ "$ext" = 1 ]; then
ifname=`cat $WAND/$intf/ip6/ifname 2>/dev/null`
ipaddr=`cat $WAND/$intf/ip6/ipaddr 2>/dev/null`
fakeip=`cat $WAND/$intf/ip6/fakeip 2>/dev/null`
routers=`cat $WAND/$intf/ip6/routers 2>/dev/null`
rtdir="$ROUTE6D/wan$intf"
else
ifname=`cat $LAND/$intf/ifname 2>/dev/null`
ipaddr=`cat $LAND/$intf/ip6/ipaddr 2>/dev/null`
routers=`cat $LAND/$intf/ip6/routers 2>/dev/null`
rtdir="$ROUTE6D/lan$intf"
fakeip=''
fi
local rule
if [ "$srcip" = '' ]; then
rule="to $dst"
else
[ "$srcprefix" = '' ] && srcprefix=128
rule="from $srcip/$srcprefix to $dst"
fi
if [ "$tos" != '' ]; then
rule="$rule tos $tos"
fi
if [ "$mark" != '' ]; then
rule="$rule fwmark $mark"
fi
mkdir -p $ROUTE6D/status
local tbl prf res=''
if [ "$srcip" = '' ] && [ "$tos" = '' ] && [ "$mark" = '' ] && [ "$dst" = 'default' ]; then
# Put the route in table named 'default'
# a rule to lookup in that table already exists
tbl='default'
prf=32767
mkdir -p $rtdir/$tbl
res=0
else
if [ "$table" != '' ]; then
# Put the route in the table given by config
tbl=$table
else
# Put the route in table $num and
# a rule to lookup in that table
tbl=$num
fi
if [ "$pref" != '' ]; then
prf=$pref
else
prf=$tbl
fi
mkdir -p $rtdir/$tbl
# Set rule priority
rule="$rule pref $prf"
echo $rule >$rtdir/$tbl/rule
local ret_log
ret_log="$(ip -6 rule add $rule table $tbl 2>&1)"
res=$?
[ "$ret_log" != '' ] && base_log "$ret_log" debug
fi
# Save route info to rebuild it in script update-routes
echo $i >$rtdir/$tbl/idx
echo $dest >$rtdir/$tbl/dest
echo $gateway >$rtdir/$tbl/gate
if [ "$intf" != 0 ] && ( [ "$ifname" = '' ] || ( [ "$ipaddr" = '' ] && [ "$fakeip" = '' ] )); then
# No interface
echo 'Disabled' >$ROUTE6D/status/$i
res=''
elif [ $res != 0 ]; then
# Error in ip rule add...
echo 'Error' >$ROUTE6D/status/$i
res=''
elif [ "$intf" = 0 ]; then
# Unreachable route
local ret_log
ret_log="$(ip -6 route add unreachable $dest table $tbl 2>&1)"
res=$?
[ "$ret_log" != '' ] && base_log "$ret_log" debug
elif [ "$gateway" != '' ]; then
local ret_log
ret_log="$(ip -6 route add $dest via $gateway dev $ifname table $tbl 2>&1)"
res=$?
[ "$ret_log" != '' ] && base_log "$ret_log" debug
elif [ "$routers" != '' ]; then
for router in $routers; do
local ret_log
ret_log="$(ip -6 route add $dest via $router dev $ifname table $tbl 2>&1)"
res=$?
[ "$ret_log" != '' ] && base_log "$ret_log" debug
[ $res != 0 ] && break
done
# No gateway found (ppp interface)
elif [ "$ipaddr" != '' ] || [ "$fakeip" != '' ]; then
local ret_log
ret_log="$(ip -6 route add $dest dev $ifname table $tbl 2>&1)"
res=$?
[ "$ret_log" != '' ] && base_log "$ret_log" debug
fi
if [ "$res" = 0 ]; then
# Success
echo 'Enabled' >$ROUTE6D/status/$i
elif [ "$res" != '' ]; then
# Error in ip route add...
echo 'Error' >$ROUTE6D/status/$i
fi
}