#!/bin/bash # Check if jq is installed if ! command -v jq &> /dev/null then echo "jq is not installed. Please install it before running the script." exit 1 fi # Check if a JSON file is provided as an argument if [ -z "$1" ]; then echo "Please provide the JSON configuration file as an argument." exit 1 fi # Read the JSON file JSON_FILE=$1 # Apply rules for each network interface (eno1, wg0, etc.) for interface in $(jq -r 'keys[]' "$JSON_FILE"); do echo "Applying rules for interface $interface..." # Delete existing qdisc if it exists tc qdisc del dev "$interface" root 2>/dev/null # Set the prio queue for the interface tc qdisc add dev "$interface" root handle 1: prio # Set high priority ports high_ports=$(jq -r ".\"$interface\".high[]" "$JSON_FILE") for port in $high_ports; do echo " Setting port $port as high priority on $interface..." tc filter add dev "$interface" protocol ip parent 1: prio 0 u32 match ip dport "$port" 0xffff flowid 1:0 done # Set medium priority ports medium_ports=$(jq -r ".\"$interface\".medium[]" "$JSON_FILE") for port in $medium_ports; do echo " Setting port $port as medium priority on $interface..." tc filter add dev "$interface" protocol ip parent 1: prio 1 u32 match ip dport "$port" 0xffff flowid 1:1 done # Set low priority ports low_ports=$(jq -r ".\"$interface\".low[]" "$JSON_FILE") for port in $low_ports; do echo " Setting port $port as low priority on $interface..." tc filter add dev "$interface" protocol ip parent 1: prio 2 u32 match ip dport "$port" 0xffff flowid 1:2 done done echo "Rules have been successfully applied."