ppp : Unnumbered support
Adds PPP unnumbered support via the parameter unnumbered which points to a logical OpenWRT interface. The PPP proto shell handler will "borrow" an IP address from the unnumbered interface (if multiple IP addresses are present the longest prefix different from 32 will be "borrowed") for which a host interface dependency will be created. Due to the host interface dependency the PPP unnumbered interface will only "borrow" an IP address from an interface which is up. The borrowed IP address will be shared as local IP address by the PPP daemon and no other local IP will be accepted from the peer in the IPCP negotiation. A typical use case is the usage of a public IP subnet on the Lan interface which will be shared by the PPP interface as local IP address. Signed-off-by: Hans Dedecker <dedeckeh@gmail.com> SVN-Revision: 45948
This commit is contained in:
parent
085a75aec2
commit
48a95eff38
1 changed files with 39 additions and 1 deletions
|
@ -4,10 +4,35 @@
|
||||||
|
|
||||||
[ -n "$INCLUDE_ONLY" ] || {
|
[ -n "$INCLUDE_ONLY" ] || {
|
||||||
. /lib/functions.sh
|
. /lib/functions.sh
|
||||||
|
. /lib/functions/network.sh
|
||||||
. ../netifd-proto.sh
|
. ../netifd-proto.sh
|
||||||
init_proto "$@"
|
init_proto "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ppp_select_ipaddr()
|
||||||
|
{
|
||||||
|
local subnets=$1
|
||||||
|
local res
|
||||||
|
local res_mask
|
||||||
|
|
||||||
|
for subnet in $subnets; do
|
||||||
|
local addr="${subnet%%/*}"
|
||||||
|
local mask="${subnet#*/}"
|
||||||
|
|
||||||
|
if [ -n "$res_mask" -a "$mask" != 32 ]; then
|
||||||
|
[ "$mask" -gt "$res_mask" ] || [ "$res_mask" = 32 ] && {
|
||||||
|
res="$addr"
|
||||||
|
res_mask="$mask"
|
||||||
|
}
|
||||||
|
elif [ -z "$res_mask" ]; then
|
||||||
|
res="$addr"
|
||||||
|
res_mask="$mask"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "$res"
|
||||||
|
}
|
||||||
|
|
||||||
ppp_exitcode_tostring()
|
ppp_exitcode_tostring()
|
||||||
{
|
{
|
||||||
local errorcode=$1
|
local errorcode=$1
|
||||||
|
@ -53,12 +78,14 @@ ppp_generic_init_config() {
|
||||||
proto_config_add_boolean authfail
|
proto_config_add_boolean authfail
|
||||||
proto_config_add_int mtu
|
proto_config_add_int mtu
|
||||||
proto_config_add_string pppname
|
proto_config_add_string pppname
|
||||||
|
proto_config_add_string unnumbered
|
||||||
}
|
}
|
||||||
|
|
||||||
ppp_generic_setup() {
|
ppp_generic_setup() {
|
||||||
local config="$1"; shift
|
local config="$1"; shift
|
||||||
|
local localip
|
||||||
|
|
||||||
json_get_vars ipv6 demand keepalive keepalive_adaptive username password pppd_options pppname
|
json_get_vars ipv6 demand keepalive keepalive_adaptive username password pppd_options pppname unnumbered
|
||||||
if [ "$ipv6" = 0 ]; then
|
if [ "$ipv6" = 0 ]; then
|
||||||
ipv6=""
|
ipv6=""
|
||||||
elif [ -z "$ipv6" -o "$ipv6" = auto ]; then
|
elif [ -z "$ipv6" -o "$ipv6" = auto ]; then
|
||||||
|
@ -73,6 +100,16 @@ ppp_generic_setup() {
|
||||||
fi
|
fi
|
||||||
[ -n "$mtu" ] || json_get_var mtu mtu
|
[ -n "$mtu" ] || json_get_var mtu mtu
|
||||||
[ -n "$pppname" ] || pppname="${proto:-ppp}-$config"
|
[ -n "$pppname" ] || pppname="${proto:-ppp}-$config"
|
||||||
|
[ -n "$unnumbered" ] && {
|
||||||
|
local subnets
|
||||||
|
( proto_add_host_dependency "$config" "" "$unnumbered" )
|
||||||
|
network_get_subnets subnets "$unnumbered"
|
||||||
|
localip=$(ppp_select_ipaddr "$subnets")
|
||||||
|
[ -n "$localip" ] || {
|
||||||
|
proto_block_restart "$config"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
local lcp_failure="${keepalive%%[, ]*}"
|
local lcp_failure="${keepalive%%[, ]*}"
|
||||||
local lcp_interval="${keepalive##*[, ]}"
|
local lcp_interval="${keepalive##*[, ]}"
|
||||||
|
@ -86,6 +123,7 @@ ppp_generic_setup() {
|
||||||
proto_run_command "$config" /usr/sbin/pppd \
|
proto_run_command "$config" /usr/sbin/pppd \
|
||||||
nodetach ipparam "$config" \
|
nodetach ipparam "$config" \
|
||||||
ifname "$pppname" \
|
ifname "$pppname" \
|
||||||
|
${localip:+$localip:} \
|
||||||
${lcp_failure:+lcp-echo-interval $lcp_interval lcp-echo-failure $lcp_failure $lcp_adaptive} \
|
${lcp_failure:+lcp-echo-interval $lcp_interval lcp-echo-failure $lcp_failure $lcp_adaptive} \
|
||||||
${ipv6:++ipv6} \
|
${ipv6:++ipv6} \
|
||||||
nodefaultroute \
|
nodefaultroute \
|
||||||
|
|
Loading…
Reference in a new issue