summaryrefslogtreecommitdiff
path: root/user/netifrc/switch-l2tp-gawk-to-perl.patch
diff options
context:
space:
mode:
authorLee Starnes <lee@canned-death.us>2020-09-13 20:55:31 +0000
committerA. Wilcox <awilcox@wilcox-tech.com>2020-09-13 20:55:31 +0000
commitcf7e1ee8ae9060afb6d124712cc740fc9485acdd (patch)
treea6bd5a4605ad6047eee562615a7a7cef57336c7f /user/netifrc/switch-l2tp-gawk-to-perl.patch
parent1a1558f77106adeb93d6bcd8eea552b678e93f89 (diff)
downloadpackages-cf7e1ee8ae9060afb6d124712cc740fc9485acdd.tar.gz
packages-cf7e1ee8ae9060afb6d124712cc740fc9485acdd.tar.bz2
packages-cf7e1ee8ae9060afb6d124712cc740fc9485acdd.tar.xz
packages-cf7e1ee8ae9060afb6d124712cc740fc9485acdd.zip
user/netifrc: bump to 0.7.1; replace gawk w/ perl
net/l2tp.sh depends on the 3-argument match() provided by GNU awk, which mawk doesn't implement. Rather than rewrite this in mawk, which would be very hard, instead translate it to perl, which is in system. Also upgrade to 0.7.1.
Diffstat (limited to 'user/netifrc/switch-l2tp-gawk-to-perl.patch')
-rw-r--r--user/netifrc/switch-l2tp-gawk-to-perl.patch92
1 files changed, 92 insertions, 0 deletions
diff --git a/user/netifrc/switch-l2tp-gawk-to-perl.patch b/user/netifrc/switch-l2tp-gawk-to-perl.patch
new file mode 100644
index 000000000..9c8bc7e0c
--- /dev/null
+++ b/user/netifrc/switch-l2tp-gawk-to-perl.patch
@@ -0,0 +1,92 @@
+diff --git a/net/l2tp.sh b/net/l2tp.sh
+index 9644e32..24b081c 100644
+--- a/net/l2tp.sh
++++ b/net/l2tp.sh
+@@ -37,9 +37,20 @@ _is_l2tp() {
+ ip l2tp show session &>/dev/null
+ [ $? -ne 0 ] && return 1
+
+- eval "$(ip l2tp show session | \
+- awk "match(\$0, /^Session ([0-9]+) in tunnel ([0-9]+)\$/, ret) {sid=ret[1]; tid=ret[2]}
+- match(\$0, /^[ ]*interface name: ${IFACE}\$/) {print \"session_id=\"sid\";tunnel_id=\"tid; exit}")"
++ eval "$(ip l2tp show session | perl -E '
++my $sid;
++my $tid;
++my $IFACE=$ARGV[0];
++while (<STDIN>) {
++ if($_ =~ /^Session ([0-9]+) in tunnel ([0-9+])\$/) {
++ $sid = $1;
++ $tid = $2;
++ }
++ if ($_ =~ /^[ ]*interface name: $IFACE$/) {
++ say "session_id=" . $sid . ";" . "tunnel_id=" . $tid;
++ exit;
++ }
++}' $IFACE)"
+ test -n "$session_id"
+ }
+
+@@ -49,33 +60,36 @@ _is_l2tp() {
+ _l2tp_get_tunnel_info() {
+ local found
+ eval "$(ip l2tp show tunnel | \
+- awk -v id=$2 -v prefix=$1 '
+- match($0, /^Tunnel ([0-9]+), encap (IP|UDP)$/, ret) {
+- if (found == "1") exit;
+- if (ret[1] == id) {
+- print "found=1;"
+- print prefix "tunnel_id=" ret[1] ";"
+- print prefix "encap=" ret[2] ";";
+- found="1"
+- }
+- }
+- match($0, /^[ ]*From ([^ ]+) to ([^ ]+)$/, ret) {
+- if (found == "1") {
+- print prefix "local=" ret[1] ";";
+- print prefix "remote=" ret[2] ";";
+- }
+- }
+- match($0, /^[ ]*Peer tunnel ([0-9]+)$/, ret) {
+- if (found == "1") {
+- print prefix "peer_tunnel_id=" ret[1] ";";
+- }
+- }
+- match($0, /^[ ]*UDP source \/ dest ports: ([0-9]+)\/([0-9]+)$/, ret) {
+- if (found == "1") {
+- print prefix "udp_sport=" ret[1] ";";
+- print prefix "udp_dport=" ret[2] ";";
+- }
+- }')"
++ perl -E '
++my ($prefix, $id) = @ARGV;
++my $found = 0;
++while(<STDIN>) {
++ if ($_ =~ /^Tunnel ([0-9]+), encap (IP|UDP)$/) {
++ if ($found) {
++ exit;
++ }
++ elsif ($1 == $id) {
++ say "found=1;";
++ say $prefix . "tunnel_id=" . $1 . ";";
++ say $prefix . "encap=" . $2 . ";";
++ $found = 1;
++ }
++ }
++ elsif ($found) {
++ if ($_ =~ /^[ ]*From ([^ ]+) to ([^ \n]+)$/) {
++ say $prefix . "local=" . $1 . ";";
++ say $prefix . "remote=" . $2 . ";";
++ }
++ elsif ($_ =~ /^[ ]*Peer tunnel ([0-9]+)$/) {
++ say $prefix . "peer_tunnel_id=" . $1 . ";";
++ }
++ elsif ($_ =~ /^[ ]*UDP source \/ dest ports: ([0-9]+)\/([0-9]+)$/) {
++ say $prefix . "udp_sport=" . $1 . ";";
++ say $prefix . "udp_dport=" . $2 . ";";
++ }
++ }
++}
++ ' "$1" "$2")"
+ test -n "$found"
+ }
+