Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
multihome
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sysadmin
multihome
Commits
42cd8ba9
Commit
42cd8ba9
authored
Dec 15, 2015
by
Franco (nextime) Lanza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add primary script
parent
30311b5a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
151 additions
and
0 deletions
+151
-0
multihome
multihome
+151
-0
No files found.
multihome
0 → 100755
View file @
42cd8ba9
#!/bin/bash
# This script is called with the following arguments:
# Arg Name Example
# $1 Interface name ppp0
# $2 The tty ttyS1
# $3 The link speed 38400
# $4 Local IP number 12.34.56.78
# $5 Peer IP number 12.34.56.99
# $6 Optional ``ipparam'' value foo
# The environment is cleared before executing this script
# so the path must be reset
PATH
=
/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
export
PATH
# These variables are for the use of the scripts run by run-parts
PPP_IFACE
=
"
$1
"
PPP_TTY
=
"
$2
"
PPP_SPEED
=
"
$3
"
PPP_LOCAL
=
"
$4
"
PPP_REMOTE
=
"
$5
"
PPP_IPPARAM
=
"
$6
"
IP
=
/sbin/ip
IPT
=
/sbin/iptables
CNT
=
/usr/sbin/conntrack
EOLO
=
ppp0
ALICE1
=
ppp1
ALICEv6
=
ppp2
ALICE2
=
ppp3
DEFROUTES
=
"
$EOLO
$ALICE1
"
OVPN_CONFIG_DIR
=
"/etc/openvpn"
#CFILE=$(readlink -f $0)
CDIR
=
$(
dirname
$0
)
ACTIVEDEVS
=
$(
/sbin/ifconfig |
grep
ppp |
grep
-v
$ALICEv6
|
awk
'{print $1}'
)
UP
=
/etc/ppp/ip-up.d
DOWN
=
/etc/ppp/ip-down.d
echo
$ACTIVEDEVS
>
/tmp/active.devices
echo
${
CDIR
}
>
/tmp/mhome.cdir
case
${
PPP_IFACE
}
in
$EOLO
)
TABLE
=
"eolo"
MARK
=
1
;;
$ALICE1
)
TABLE
=
"alice"
MARK
=
2
;;
$ALICE2
)
TABLE
=
"alice2"
MARK
=
3
;;
$ALICEv6
)
TABLE
=
"alicev6"
MARK
=
"NO"
;;
*
)
TABLE
=
"eolo"
MARK
=
1
esac
if
[
$MARK
!=
"NO"
]
;
then
case
${
CDIR
}
in
$UP
)
$IP
route add default dev
$PPP_IFACE
table
$TABLE
$IP
rule add from
$PPP_LOCAL
table
$TABLE
$IP
rule add fwmark
$MARK
table
$TABLE
$IPT
-t
nat
-I
POSTROUTING
-s
192.168.0.0/16
-o
$PPP_IFACE
-j
MASQUERADE
$IPT
-t
mangle
-I
POSTROUTING
-o
$PPP_IFACE
-j
MARK
--set-mark
$MARK
echo
0
>
/proc/sys/net/ipv4/conf/
$PPP_IFACE
/rp_filter
# DISABLE MARTIANS FILTERING
echo
1
>
/proc/sys/net/ipv4/ip_forward
# ENABLE IP FORWARD
echo
10
>
/proc/sys/net/ipv4/route/gc_timeout
# FAST ROUTING TABLE CACHE TIMEOUT
logger
-t
"[PPP
$PPP_IFACE
-
$TABLE
]"
"Connection up (ip
$PPP_LOCAL
, activedevices
$ACTIVEDEVS
)"
for
VPN_CONFIG
in
`
cd
$OVPN_CONFIG_DIR
;
ls
*
.
$TABLE
.conf 2> /dev/null
`
;
do
VPN_NAME
=
${
VPN_CONFIG
%%.conf
}
cat
$OVPN_CONFIG_DIR
/
$VPN_CONFIG
|
grep
-v
"^local"
>
$OVPN_CONFIG_DIR
/
$VPN_CONFIG
.tmp
echo
"local
$PPP_LOCAL
"
>>
$OVPN_CONFIG_DIR
/
$VPN_CONFIG
.tmp
mv
$OVPN_CONFIG_DIR
/
$VPN_CONFIG
.tmp
$OVPN_CONFIG_DIR
/
$VPN_CONFIG
/etc/init.d/openvpn stop
$VPN_NAME
>
/dev/null 2>&1
/etc/init.d/openvpn start
$VPN_NAME
>
/dev/null 2>&1
logger
-t
"[PPP
$TABLE
- OpenVPN]"
"
$VPN_NAME
enabled on
$PPP_LOCAL
"
done
;;
$DOWN
)
$IPT
-t
nat
-D
POSTROUTING
-s
192.168.0.0/16
-o
$PPP_IFACE
-j
MASQUERADE
$IPT
-t
mangle
-D
POSTROUTING
-o
$PPP_IFACE
-j
MARK
--set-mark
$MARK
$IP
rule del fwmark
$MARK
table
$TABLE
$IP
rule del from
$PPP_LOCAL
table
$TABLE
# Remove already established connection from the conntrack table
$CNT
-D
-m
$MARK
logger
-t
"[PPP
$PPP_IFACE
-
$TABLE
]"
"Connection down (ex ip
$PPP_LOCAL
, activedevices
$ACTIVEDEVS
)"
for
VPN_CONFIG
in
`
cd
$OVPN_CONFIG_DIR
;
ls
*
.
$TABLE
.conf 2> /dev/null
`
;
do
VPN_NAME
=
${
VPN_CONFIG
%%.conf
}
/etc/init.d/openvpn stop
$VPN_NAME
>
/dev/null 2>&1
logger
-t
"[PPP
$TABLE
- OpenVPN]"
"
$VPN_NAME
disabled"
done
;;
esac
$IP
route del default 2>&1
>
/dev/null
if
[
x
"
$ACTIVEDEVS
"
!=
x
""
]
;
then
DEFR
=
""
for
iface
in
$ACTIVEDEVS
do
logger
-t
"[PPP
$iface
- nexhop]"
"
$DEFR
nexthop dev
$iface
weight 1"
DEFR
=
"
$DEFR
nexthop dev
$iface
weight 1"
done
$IP
route add default scope global
$DEFR
#$IP route add default equalize $DEFR
fi
$IP
route flush cache
else
case
${
CDIR
}
in
$UP
)
$IP
route add default dev
$PPP_IFACE
table
$TABLE
$IP
rule add from
$PPP_LOCAL
table
$TABLE
;;
$DOWN
)
$IP
rule del from
$PPP_LOCAL
table
$TABLE
;;
esac
$IP
route flush cache
fi
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment