Browse Source

fastd: Pimp ff_fastd_con script to do simple cipher stats

  This has reached the complexity level of wanting to be a Python script now.

Signed-off-by: Maximilian Wilhelm <max@sdn.clinic>
Maximilian Wilhelm 3 years ago
parent
commit
c8c2e63e3e
1 changed files with 42 additions and 11 deletions
  1. 42 11
      fastd/ff_fastd_con

+ 42 - 11
fastd/ff_fastd_con

@@ -4,11 +4,18 @@
 #  --  Mon 31 Aug 2015 08:55:27 AM CEST
 #
 
-if [ $# != 1 ]; then
-	echo "Usage: $(basename $0) fastd_instance | -a" >&2
+if [ $# -lt 1 ]; then
+	echo "Usage: $(basename $0) [ -c ] fastd_instance | -a" >&2
 	exit 1
 fi
 
+fastd_ciphers () {
+	socket_path=$(grep "status socket" "/etc/fastd/${1}/fastd.conf" | grep -o '/[0-9a-z/_.-]\+')
+
+	echo -n "$1: "
+	socat - "UNIX-CONNECT:${socket_path}" | jq '.peers[] | select (.connection) | .connection | .method ' | sort | uniq -c
+}
+
 fastd_con () {
 	socket_path=$(grep "status socket" "/etc/fastd/${1}/fastd.conf" | grep -o '/[0-9a-z/_.-]\+')
 
@@ -16,15 +23,39 @@ fastd_con () {
 	socat - "UNIX-CONNECT:${socket_path}" | jq '.peers[] | select( .connection ) | .name' | wc -l
 }
 
-if [ "${1}" = '-a' ]; then
-	for fastd_instance in $(find /etc/fastd -mindepth 1 -maxdepth 1 -type d  -exec basename {} \; | sort); do
-		fastd_con ${fastd_instance}
-	done
-else
-	if [ ! -d "/etc/fastd/${1}" ]; then
-		echo "Invalid fastd instance \"$1\"." >&2
+mode="count"
+if [ "${1}" = "-c" ]; then
+	mode="ciphers"
+	shift
+fi
+
+instances="${@}"
+if [ "${1}" = "-a" ]; then
+	instances="all"
+fi
+
+
+# Verify existance of fastd instance
+if [ "$instances" != "all" -a ! -d "/etc/fastd/${instances}" ]; then
+	echo "Invalid fastd instance \"$instances\"." >&2
+	exit 1
+
+# Figure out all fastd instances
+elif [ "$instances" = "all" ]; then
+	instances=$(find /etc/fastd -mindepth 1 -maxdepth 1 -type d  -exec basename {} \; | sort)
+	
+	if [ ! "${instances}" ]; then
+		echo "Did not find any configured instances in /etc/fastd." >&2
 		exit 1
 	fi
-
-	fastd_con "${1}"
 fi
+
+
+for inst in ${instances}; do
+	if [ "${mode}" = "count" ]; then
+		fastd_con ${inst}
+
+	elif [ "$mode" = "ciphers" ]; then
+		fastd_ciphers ${inst}
+	fi
+done