-if [ $basename = "ath" -o $basename = "wlan" ]; then
- match="$match, ATTR{type}==\"1\"" # do not match the wifi* interfaces
+
+if [ -z "$match" ]; then
+ echo "missing valid match" >&2
+ unlock_rules_file
+ exit 1
+fi
+
+if [ "$INTERFACE_NAME" ]; then
+ # external tools may request a custom name
+ COMMENT="$COMMENT (custom name provided by external tool)"
+ if [ "$INTERFACE_NAME" != "$INTERFACE" ]; then
+ INTERFACE=$INTERFACE_NAME;
+ echo "INTERFACE_NEW=$INTERFACE"
+ fi
+else
+ # if a rule using the current name already exists, find a new name
+ basename=${INTERFACE%%[0-9]*}
+ match="$match, KERNEL==\"$basename*\""
+ if interface_name_taken; then
+ INTERFACE="$basename$(find_next_available "$basename[0-9]*")"
+ echo "INTERFACE_NEW=$INTERFACE"
+ fi