summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-11-30 09:20:12 +0100
committerErich Eckner <git@eckner.net>2018-11-30 09:20:12 +0100
commit7af03170be553eb64372c0dc36c9334743a7059e (patch)
tree810fbbc70ba399696aa67abbc721e6c629fac9d8
parent6ada269f376786119cb4705461639ebe5caa30a5 (diff)
downloadnetwork-topology-scanner-7af03170be553eb64372c0dc36c9334743a7059e.tar.xz
network-topology-scanner: remove duplicate routing links
-rwxr-xr-xnetwork-topology-scanner28
1 files changed, 21 insertions, 7 deletions
diff --git a/network-topology-scanner b/network-topology-scanner
index 8db3315..a57c555 100755
--- a/network-topology-scanner
+++ b/network-topology-scanner
@@ -159,28 +159,42 @@ grep -vwF -- '-m conntrack' "${tmp_dir}/iptables" | \
sed '
s/^\(\S\+ \S\+\) \(\S\+\) \(\S\+\)$/f \1 \2 \3\nr \1 \3 \2/
' "${tmp_dir}/routes" \
- | sort -k2,5 -k1,1 \
+ | while read -r dir host ip from to; do
+ printf '%s %s %s %s %s %s\n' \
+ "${dir}" \
+ "${from}" \
+ "${to}" \
+ "${host}" \
+ "${ip}" \
+ "$(
+ printf '%s\n' "${from}" "${to}" | \
+ sort | \
+ sha512sum | \
+ awk '{print $1}'
+ )"
+ done \
+ | sort -k2,6 -k1,1 \
> "${tmp_dir}/routes.new"
uniq -uf1 "${tmp_dir}/routes.new" | tee /dev/stderr \
| grep '^f ' \
> "${tmp_dir}/routes"
-# todo : remove duplicates
-
uniq -df1 "${tmp_dir}/routes.new" \
| sed 's/^[fr] /b /' \
+ | sort -k4,6 -k1,3 \
+ | uniq -f3 \
>> "${tmp_dir}/routes"
rm "${tmp_dir}/routes.new"
sed '
- s/^f \(\S\+\) 4 \(\S\+\) \(\S\+\)$/"\1 \2" -> "\1 \3" [weight=0, color="#808080"];\n/
+ s/^f \(\S\+\) \(\S\+\) \(\S\+\) 4 \S\+$/"\3 \1" -> "\3 \2" [weight=0, color="#808080"];\n/
t
- s/^f \(\S\+\) 6 \(\S\+\) \(\S\+\)$/"\1 \2" -> "\1 \3" [weight=0, color="#000000"];\n/
+ s/^f \(\S\+\) \(\S\+\) \(\S\+\) 6 \S\+$/"\3 \1" -> "\3 \2" [weight=0, color="#000000"];\n/
t
- s/^b \(\S\+\) 4 \(\S\+\) \(\S\+\)$/"\1 \2" -> "\1 \3" [dir=both, weight=0, color="#808080"];\n/
+ s/^b \(\S\+\) \(\S\+\) \(\S\+\) 4 \S\+$/"\3 \1" -> "\3 \2" [dir=both, weight=0, color="#808080"];\n/
t
- s/^b \(\S\+\) 6 \(\S\+\) \(\S\+\)$/"\1 \2" -> "\1 \3" [dir=both, weight=0, color="#000000"];\n/
+ s/^b \(\S\+\) \(\S\+\) \(\S\+\) 6 \S\+$/"\3 \1" -> "\3 \2" [dir=both, weight=0, color="#000000"];\n/
t
d
' "${tmp_dir}/routes" \