Skip to content

Commit df9519d

Browse files
committed
T7965: invoke Python hooks from Bash scripts for better performance
1 parent c44dc99 commit df9519d

File tree

7 files changed

+181
-153
lines changed

7 files changed

+181
-153
lines changed
Lines changed: 8 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,10 @@
1-
#!/usr/bin/env python3
2-
#
3-
# Copyright VyOS maintainers and contributors <[email protected]>
4-
#
5-
# This program is free software; you can redistribute it and/or modify
6-
# it under the terms of the GNU General Public License version 2 or later as
7-
# published by the Free Software Foundation.
8-
#
9-
# This program is distributed in the hope that it will be useful,
10-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
# GNU General Public License for more details.
13-
#
14-
# You should have received a copy of the GNU General Public License
15-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1+
#!/bin/bash
162

17-
# This is a Python hook script which is invoked whenever a SSTP client session
18-
# goes "ip-up". It will call into our vyos.ifconfig library and will then
19-
# execute common tasks for the SSTP interface. The reason we have to "hook" this
20-
# is that we can not create a sstpcX interface in advance in linux and then
21-
# connect pppd to this already existing interface.
3+
interface=$6
4+
if [ -z "$interface" ]; then
5+
exit
6+
fi
227

23-
from sys import argv
24-
from sys import exit
25-
26-
from vyos.configquery import ConfigTreeQuery
27-
from vyos.configdict import get_interface_dict
28-
from vyos.ifconfig import SSTPCIf
29-
30-
# When the ppp link comes up, this script is called with the following
31-
# parameters
32-
# $1 the interface name used by pppd (e.g. ppp3)
33-
# $2 the tty device name
34-
# $3 the tty device speed
35-
# $4 the local IP address for the interface
36-
# $5 the remote IP address
37-
# $6 the parameter specified by the 'ipparam' option to pppd
38-
39-
if (len(argv) < 7):
40-
exit(1)
41-
42-
interface = argv[6]
43-
44-
conf = ConfigTreeQuery()
45-
_, sstpc = get_interface_dict(conf.config, ['interfaces', 'sstpc'], interface)
46-
47-
# Update the config
48-
p = SSTPCIf(interface)
49-
p.update(sstpc)
8+
if [[ "$interface" == sstpc* ]]; then
9+
/etc/ppp/ip-up.d/ppp-hook-scripts/96-vyos-sstpc-callback "$@"
10+
fi
Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,11 @@
1-
#!/usr/bin/env python3
2-
#
3-
# Copyright VyOS maintainers and contributors <[email protected]>
4-
#
5-
# This program is free software; you can redistribute it and/or modify
6-
# it under the terms of the GNU General Public License version 2 or later as
7-
# published by the Free Software Foundation.
8-
#
9-
# This program is distributed in the hope that it will be useful,
10-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
# GNU General Public License for more details.
13-
#
14-
# You should have received a copy of the GNU General Public License
15-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1+
#!/bin/bash
162

17-
# This is a Python hook script which is invoked whenever a PPPoE session goes
18-
# "ip-up". It will call into our vyos.ifconfig library and will then execute
19-
# common tasks for the PPPoE interface. The reason we have to "hook" this is
20-
# that we can not create a pppoeX interface in advance in linux and then connect
21-
# pppd to this already existing interface.
3+
interface=$6
4+
if [ -z "$interface" ]; then
5+
exit
6+
fi
227

23-
from sys import argv
24-
from sys import exit
25-
26-
from vyos.configquery import ConfigTreeQuery
27-
from vyos.configdict import get_interface_dict
28-
from vyos.ifconfig import PPPoEIf
29-
30-
# When the ppp link comes up, this script is called with the following
31-
# parameters
32-
# $1 the interface name used by pppd (e.g. ppp3)
33-
# $2 the tty device name
34-
# $3 the tty device speed
35-
# $4 the local IP address for the interface
36-
# $5 the remote IP address
37-
# $6 the parameter specified by the 'ipparam' option to pppd
38-
39-
if (len(argv) < 7):
40-
exit(1)
41-
42-
interface = argv[6]
43-
44-
conf = ConfigTreeQuery()
45-
_, pppoe = get_interface_dict(conf.config, ['interfaces', 'pppoe'], interface)
46-
47-
# Update the config
48-
p = PPPoEIf(interface)
49-
p.update(pppoe)
8+
if [[ "$interface" == pppoe* ]]; then
9+
/etc/ppp/ip-up.d/ppp-hook-scripts/99-vyos-pppoe-callback "$@"
10+
/etc/ppp/ip-up.d/ppp-hook-scripts/99-vyos-pppoe-qos "$@"
11+
fi
Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,7 @@
1-
#!/usr/bin/env python3
2-
#
3-
# Copyright VyOS maintainers and contributors <[email protected]>
4-
#
5-
# This program is free software; you can redistribute it and/or modify
6-
# it under the terms of the GNU General Public License version 2 or later as
7-
# published by the Free Software Foundation.
8-
#
9-
# This program is distributed in the hope that it will be useful,
10-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
# GNU General Public License for more details.
13-
#
14-
# You should have received a copy of the GNU General Public License
15-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1+
#!/bin/bash
162

17-
# This is a Python hook script which is invoked whenever a PPPoE session goes
18-
# "ip-up". It will call into our vyos.ifconfig library and will then execute
19-
# common tasks for the PPPoE interface. The reason we have to "hook" this is
20-
# that we can not create a pppoeX interface in advance in linux and then connect
21-
# pppd to this already existing interface.
3+
WLB_PID_FILE="/run/wlb_daemon.pid"
224

23-
import os
24-
import signal
25-
26-
from sys import argv
27-
from sys import exit
28-
29-
from vyos.defaults import directories
30-
31-
# When the ppp link comes up, this script is called with the following
32-
# parameters
33-
# $1 the interface name used by pppd (e.g. ppp3)
34-
# $2 the tty device name
35-
# $3 the tty device speed
36-
# $4 the local IP address for the interface
37-
# $5 the remote IP address
38-
# $6 the parameter specified by the 'ipparam' option to pppd
39-
40-
if (len(argv) < 7):
41-
exit(1)
42-
43-
wlb_pid_file = '/run/wlb_daemon.pid'
44-
45-
interface = argv[6]
46-
nexthop = argv[5]
47-
48-
if not os.path.exists(directories['ppp_nexthop_dir']):
49-
os.mkdir(directories['ppp_nexthop_dir'])
50-
51-
nexthop_file = os.path.join(directories['ppp_nexthop_dir'], interface)
52-
53-
with open(nexthop_file, 'w') as f:
54-
f.write(nexthop)
55-
56-
# Trigger WLB daemon update
57-
if os.path.exists(wlb_pid_file):
58-
with open(wlb_pid_file, 'r') as f:
59-
pid = int(f.read())
60-
61-
os.kill(pid, signal.SIGUSR2)
5+
if [ -f "$WLB_PID_FILE" ]; then
6+
/etc/ppp/ip-up.d/ppp-hook-scripts/99-vyos-pppoe-wlb "$@"
7+
fi
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright VyOS maintainers and contributors <[email protected]>
4+
#
5+
# This program is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License version 2 or later as
7+
# published by the Free Software Foundation.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
# This is a Python hook script which is invoked whenever a SSTP client session
18+
# goes "ip-up". It will call into our vyos.ifconfig library and will then
19+
# execute common tasks for the SSTP interface. The reason we have to "hook" this
20+
# is that we can not create a sstpcX interface in advance in linux and then
21+
# connect pppd to this already existing interface.
22+
23+
from sys import argv
24+
from sys import exit
25+
26+
from vyos.configquery import ConfigTreeQuery
27+
from vyos.configdict import get_interface_dict
28+
from vyos.ifconfig import SSTPCIf
29+
30+
# When the ppp link comes up, this script is called with the following
31+
# parameters
32+
# $1 the interface name used by pppd (e.g. ppp3)
33+
# $2 the tty device name
34+
# $3 the tty device speed
35+
# $4 the local IP address for the interface
36+
# $5 the remote IP address
37+
# $6 the parameter specified by the 'ipparam' option to pppd
38+
39+
if (len(argv) < 7):
40+
exit(1)
41+
42+
interface = argv[6]
43+
44+
conf = ConfigTreeQuery()
45+
_, sstpc = get_interface_dict(conf.config, ['interfaces', 'sstpc'], interface)
46+
47+
# Update the config
48+
p = SSTPCIf(interface)
49+
p.update(sstpc)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright VyOS maintainers and contributors <[email protected]>
4+
#
5+
# This program is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License version 2 or later as
7+
# published by the Free Software Foundation.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
# This is a Python hook script which is invoked whenever a PPPoE session goes
18+
# "ip-up". It will call into our vyos.ifconfig library and will then execute
19+
# common tasks for the PPPoE interface. The reason we have to "hook" this is
20+
# that we can not create a pppoeX interface in advance in linux and then connect
21+
# pppd to this already existing interface.
22+
23+
from sys import argv
24+
from sys import exit
25+
26+
from vyos.configquery import ConfigTreeQuery
27+
from vyos.configdict import get_interface_dict
28+
from vyos.ifconfig import PPPoEIf
29+
30+
# When the ppp link comes up, this script is called with the following
31+
# parameters
32+
# $1 the interface name used by pppd (e.g. ppp3)
33+
# $2 the tty device name
34+
# $3 the tty device speed
35+
# $4 the local IP address for the interface
36+
# $5 the remote IP address
37+
# $6 the parameter specified by the 'ipparam' option to pppd
38+
39+
if (len(argv) < 7):
40+
exit(1)
41+
42+
interface = argv[6]
43+
44+
conf = ConfigTreeQuery()
45+
_, pppoe = get_interface_dict(conf.config, ['interfaces', 'pppoe'], interface)
46+
47+
# Update the config
48+
p = PPPoEIf(interface)
49+
p.update(pppoe)
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Copyright VyOS maintainers and contributors <[email protected]>
4+
#
5+
# This program is free software; you can redistribute it and/or modify
6+
# it under the terms of the GNU General Public License version 2 or later as
7+
# published by the Free Software Foundation.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
17+
# This is a Python hook script which is invoked whenever a PPPoE session goes
18+
# "ip-up". It will call into our vyos.ifconfig library and will then execute
19+
# common tasks for the PPPoE interface. The reason we have to "hook" this is
20+
# that we can not create a pppoeX interface in advance in linux and then connect
21+
# pppd to this already existing interface.
22+
23+
import os
24+
import signal
25+
26+
from sys import argv
27+
from sys import exit
28+
29+
from vyos.defaults import directories
30+
31+
# When the ppp link comes up, this script is called with the following
32+
# parameters
33+
# $1 the interface name used by pppd (e.g. ppp3)
34+
# $2 the tty device name
35+
# $3 the tty device speed
36+
# $4 the local IP address for the interface
37+
# $5 the remote IP address
38+
# $6 the parameter specified by the 'ipparam' option to pppd
39+
40+
if (len(argv) < 7):
41+
exit(1)
42+
43+
wlb_pid_file = '/run/wlb_daemon.pid'
44+
45+
interface = argv[6]
46+
nexthop = argv[5]
47+
48+
if not os.path.exists(directories['ppp_nexthop_dir']):
49+
os.mkdir(directories['ppp_nexthop_dir'])
50+
51+
nexthop_file = os.path.join(directories['ppp_nexthop_dir'], interface)
52+
53+
with open(nexthop_file, 'w') as f:
54+
f.write(nexthop)
55+
56+
# Trigger WLB daemon update
57+
if os.path.exists(wlb_pid_file):
58+
with open(wlb_pid_file, 'r') as f:
59+
pid = int(f.read())
60+
61+
os.kill(pid, signal.SIGUSR2)

0 commit comments

Comments
 (0)