Created
February 15, 2016 16:50
-
-
Save ym/994b5e9e39a613009cff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ip_rule_add () { | |
if ip rule list | grep -Fq $1 | |
then | |
ip rule list | grep -F $1 | awk -F\: -f <(cat - <<-'EOD' | |
function ltrim(s) { sub(/^[ \t\r\n]+/, "", s); return s } | |
function rtrim(s) { sub(/[ \t\r\n]+$/, "", s); return s } | |
function trim(s) { return rtrim(ltrim(s)); } | |
BEGIN {} | |
{ | |
rule = trim(trim($2)); | |
if (rule == "") { | |
next; | |
} | |
split(rule, conditions, " "); | |
if (conditions[2] == "all") { | |
next; | |
} | |
print "ip rule del " $2 | |
} | |
EOD | |
) | bash | |
fi | |
if [ "$3" != "del" ]; then | |
ip rule add from $1 table $2 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment