Skip to content

Commit

Permalink
wg-quick: linux: use sed for trimming config lines
Browse files Browse the repository at this point in the history
Bash's longest matching operators combined with extended globs is
extremely slow for very large lines. There are probably very few people
for which this is noticable but in a file with 800 AllowIPs on a single
line it keeps wg-quick from stalling for 5s when performing operations.
  • Loading branch information
kkartaltepe committed Aug 18, 2021
1 parent b3aafa6 commit 043b591
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/wg-quick/linux.bash
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ parse_options() {
shopt -s nocasematch
while read -r line || [[ -n $line ]]; do
stripped="${line%%\#*}"
key="${stripped%%=*}"; key="${key##*([[:space:]])}"; key="${key%%*([[:space:]])}"
value="${stripped#*=}"; value="${value##*([[:space:]])}"; value="${value%%*([[:space:]])}"
key=$(sed -e 's/=.*$//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' <<< "$stripped")
value=$(sed -e 's/^[^=]*=//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' <<< "$stripped")
[[ $key == "["* ]] && interface_section=0
[[ $key == "[Interface]" ]] && interface_section=1
if [[ $interface_section -eq 1 ]]; then
Expand Down

0 comments on commit 043b591

Please sign in to comment.