diff --git a/.github/workflows/dai-testing.yml b/.github/workflows/dai-testing.yml index c3e9ad3..5bf84d7 100644 --- a/.github/workflows/dai-testing.yml +++ b/.github/workflows/dai-testing.yml @@ -35,10 +35,26 @@ jobs: run: ./Test_Insert_Kernel_Module.sh # Run Setting_Dynamic_Parameters Tests + - name: Run Test_add_Trusted_Interface + working-directory: ./tests/SettingDynamicParameters/ + run: ./Test_add_Trusted_Interface.sh + + - name: Run Test_add_Trusted_Interfaces_Malformed + working-directory: ./tests/SettingDynamicParameters/ + run: ./Test_add_Trusted_Interfaces_Malformed.sh + - name: Run Test_add_Trusted_Interfaces working-directory: ./tests/SettingDynamicParameters/ run: ./Test_add_Trusted_Interfaces.sh - + + - name: Run Test_add_VLAN + working-directory: ./tests/SettingDynamicParameters/ + run: ./Test_add_VLAN.sh + + - name: Run Test_add_VLANs_Malformed + working-directory: ./tests/SettingDynamicParameters/ + run: ./Test_add_VLANs_Malformed.sh + - name: Run Test_add_VLANs working-directory: ./tests/SettingDynamicParameters/ run: ./Test_add_VLANs.sh @@ -47,10 +63,17 @@ jobs: working-directory: ./tests/SettingDynamicParameters/ run: ./Test_set_globally_enabled_DAI.sh + - name: Run Test_set_globally_enabled_DAI_Malformed + working-directory: ./tests/SettingDynamicParameters/ + run: ./Test_set_globally_enabled_DAI_Malformed.sh + - name: Run Test_set_static_ACL_Enabled working-directory: ./tests/SettingDynamicParameters/ run: ./Test_set_static_ACL_Enabled.sh + - name: Run Test_set_static_ACL_Enabled_Malformed + working-directory: ./tests/SettingDynamicParameters/ + run: ./Test_set_static_ACL_Enabled_Malformed.sh # Run Using_Dynamic_Parameters Tests - name: Run Test_DAI_VLAN_Filtering diff --git a/main.c b/main.c index 71c6c25..ab9aa2e 100644 --- a/main.c +++ b/main.c @@ -75,7 +75,7 @@ static int set_vlans_to_inspect(const char *val, const struct kernel_param *kp){ printk(KERN_INFO "kdai: No VLANs to inspect (empty input).\n\n"); return 0; } - if (*val == '\0') { + if (strcmp(val,"clear") == 0) { printk(KERN_INFO "kdai: Clearing VLANs To Inspect list\n\n"); free_all_vlan_entries(); print_all_vlans_in_hash(); @@ -84,15 +84,18 @@ static int set_vlans_to_inspect(const char *val, const struct kernel_param *kp){ // Parse the incoming string of VLANs to_free = kstrdup(val, GFP_KERNEL); - if (!to_free) + if (!to_free) { + printk(KERN_INFO "kdai: Could not dup\n\n"); return -ENOMEM; // Memory allocation failed - + } str = to_free; //Remove all VLAN_ID entries from the list + printk(KERN_INFO "kdai: Clearing VLANs To Inspect list\n\n"); free_all_vlan_entries(); - //Add all entries that are specified in new val + //Add all entries that are specified in new val + printk(KERN_INFO "kdai: Parsing VLANs To Inspect\n\n"); parse_vlans(to_free); //Free allocate dmmemory @@ -109,19 +112,20 @@ static const struct kernel_param_ops vlans_to_inspect_ops = { module_param_cb(vlans_to_inspect, &vlans_to_inspect_ops, &vlans_to_inspect, 0644); -char * trusted_interfaces = NULL; //Default is None +char * trusted_interfaces; //Default is None //module_param(trusted_interfaces, charp, 0644); MODULE_PARM_DESC(trusted_interfaces, "Comma-separated list of Interfaces:VLAN_ID that are considered to be trusted"); static int set_trusted_interfaces(const char *val, const struct kernel_param *kp){ char *to_free; // Declare to_free for duplicating the string char *str; + printk(KERN_INFO "kdai: Changed Trusted Interface List\n"); // If the input string is empty, just return if (val == NULL) { printk(KERN_INFO "kdai: Empty input for Trusted Interfaces.\n\n"); return 0; } - if(*val == '\0') { + if(strcmp(val,"clear") == 0) { printk(KERN_INFO "kdai: Clearing Trusted list\n\n"); free_trusted_interface_list(); print_trusted_interface_list(); @@ -130,9 +134,10 @@ static int set_trusted_interfaces(const char *val, const struct kernel_param *kp // Parse the incoming string of VLANs to_free = kstrdup(val, GFP_KERNEL); - if (!to_free) + if (!to_free) { + printk(KERN_INFO "kdai: Could not dup\n\n"); return -ENOMEM; // Memory allocation failed - + } str = to_free; //Remove all trusted entries from the list diff --git a/tests/SettingDynamicParameters/Test_add_Trusted_Interface.sh b/tests/SettingDynamicParameters/Test_add_Trusted_Interface.sh new file mode 100644 index 0000000..311b247 --- /dev/null +++ b/tests/SettingDynamicParameters/Test_add_Trusted_Interface.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +# This script checks if the kernel module can add one Interface to the Trusted List + +set -euo pipefail #treat unset vars as errors + +# Track current command for debugging +last_command="" +current_command="" +trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG + +# Log which command caused exit +trap 'echo ""; echo "TEST FAILED - Script exited during: \"$last_command\"" >&2' ERR + +# Define the cleanup function +cleanup() { + echo + echo "=== Cleaning Up ===" + echo + make -C ../.. remove || true + + sudo ip netns exec ns1 ip link set lo down || true + sudo ip netns exec ns2 ip link set lo down || true + sudo ip netns exec ns1 ip link set veth0 down || true + sudo ip netns exec ns2 ip link set veth3 down || true + sudo ip link set veth1 down || true + sudo ip link set veth2 down || true + sudo ip link set br1 down || true + + sudo ip netns delete ns1 || true + sudo ip netns delete ns2 || true + sudo ip link delete br1 || true + + echo "=== Clean-up Complete ===" +} + +# Always run cleanup on exit (normal or error) +trap cleanup EXIT + +cleanup +sudo dmesg -C +sudo dmesg -n 3 + +sudo ../testenv/setup_test_env.sh + +echo +echo "=== Ensure Working Test Environment ===" +echo +sudo ip netns exec ns1 python3 ../helperPythonFilesForCustomPackets/ARP_Request_And_Response_Without_VLAN_ID.py +sudo dmesg -C + +echo +echo "=== Running make to build the module ===" +echo +make -C ../.. + +echo +echo "=== Running make load_with_params to insert the module ===" +echo +make -C ../.. install +echo "veth1:1" | sudo tee /sys/module/kdai/parameters/trusted_interfaces + +echo +echo "=== Testing DAI Adds Trusted Interface to Entries ===" +echo +sudo dmesg | grep -E "VLAN ID:\s*1\s*Interface:\s*veth1" + +echo +echo "Test Passed!" +sudo dmesg -n 7 +echo + +exit \ No newline at end of file diff --git a/tests/SettingDynamicParameters/Test_add_Trusted_Interfaces.sh b/tests/SettingDynamicParameters/Test_add_Trusted_Interfaces.sh index 8c99a85..1226a5e 100644 --- a/tests/SettingDynamicParameters/Test_add_Trusted_Interfaces.sh +++ b/tests/SettingDynamicParameters/Test_add_Trusted_Interfaces.sh @@ -1,6 +1,6 @@ #!/bin/bash -# This script checks if the kernel module can add Interfaces to the Trusted List +# This script checks if the kernel module can add more than one Interfaces to the Trusted List set -euo pipefail #treat unset vars as errors @@ -58,12 +58,13 @@ echo echo "=== Running make load_with_params to insert the module ===" echo make -C ../.. install -echo "veth1:1" | sudo tee /sys/module/kdai/parameters/trusted_interfaces +echo "veth2:20,veth1:10" | sudo tee /sys/module/kdai/parameters/trusted_interfaces echo echo "=== Testing DAI Adds Trusted Interface to Entries ===" echo -sudo dmesg | grep -E "VLAN ID:\s*1\s*Interface:\s*veth1" +sudo dmesg | grep -E "VLAN ID:\s*10\s*Interface:\s*veth1" +sudo dmesg | grep -E "VLAN ID:\s*20\s*Interface:\s*veth2" echo echo "Test Passed!" diff --git a/tests/SettingDynamicParameters/Test_add_Trusted_Interfaces_Malformed.sh b/tests/SettingDynamicParameters/Test_add_Trusted_Interfaces_Malformed.sh new file mode 100644 index 0000000..0412de5 --- /dev/null +++ b/tests/SettingDynamicParameters/Test_add_Trusted_Interfaces_Malformed.sh @@ -0,0 +1,91 @@ +#!/bin/bash + +# This script checks if the kernel module can handle malformed Trusted Interface Input + +set -euo pipefail #treat unset vars as errors + +# Track current command for debugging +last_command="" +current_command="" +trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG + +# Log which command caused exit +trap 'echo ""; echo "TEST FAILED - Script exited during: \"$last_command\"" >&2' ERR + +# Define the cleanup function +cleanup() { + echo + echo "=== Cleaning Up ===" + echo + make -C ../.. remove || true + + sudo ip netns exec ns1 ip link set lo down || true + sudo ip netns exec ns2 ip link set lo down || true + sudo ip netns exec ns1 ip link set veth0 down || true + sudo ip netns exec ns2 ip link set veth3 down || true + sudo ip link set veth1 down || true + sudo ip link set veth2 down || true + sudo ip link set br1 down || true + + sudo ip netns delete ns1 || true + sudo ip netns delete ns2 || true + sudo ip link delete br1 || true + + echo "=== Clean-up Complete ===" +} + +# Always run cleanup on exit (normal or error) +trap cleanup EXIT + +cleanup +sudo dmesg -C +sudo dmesg -n 3 + +sudo ../testenv/setup_test_env.sh + +echo +echo "=== Ensure Working Test Environment ===" +echo +#sudo ip netns exec ns1 python3 ../helperPythonFilesForCustomPackets/ARP_Request_And_Response_Without_VLAN_ID.py +sudo dmesg -C + +echo +echo "=== Running make to build the module ===" +echo +make -C ../.. + +echo +echo "=== Running make load_with_params to insert the module ===" +echo +make -C ../.. install +# Valid input for context +#echo "veth1:1" | sudo tee /sys/module/kdai/parameters/trusted_interfaces +#echo -n "0" | sudo tee /sys/module/kdai/parameters/trusted_interfaces # Empty input (remove the newline character) + +# Malformed / edge-case inputs +echo -n "veth1" | sudo tee /sys/module/kdai/parameters/trusted_interfaces # Missing colon + value +echo -n ":1" | sudo tee /sys/module/kdai/parameters/trusted_interfaces # Missing interface name +echo -n "veth1:" | sudo tee /sys/module/kdai/parameters/trusted_interfaces # Missing value +echo -n "veth1::1" | sudo tee /sys/module/kdai/parameters/trusted_interfaces # Extra colon +echo -n "veth1:abc" | sudo tee /sys/module/kdai/parameters/trusted_interfaces # Non-numeric value +echo -n "veth1:-1" | sudo tee /sys/module/kdai/parameters/trusted_interfaces # Negative value (if invalid) +echo -n "veth1:1:extra" | sudo tee /sys/module/kdai/parameters/trusted_interfaces # Too many fields +echo -n "veth1:1,veth2" | sudo tee /sys/module/kdai/parameters/trusted_interfaces # Mixed valid/invalid +echo "@!veth1:1" | sudo tee /sys/module/kdai/parameters/trusted_interfaces # Invalid interface characters +echo + +echo "=== Testing DAI Adds Trusted Interface to Entries ===" +echo +sudo dmesg | grep -E 'Invalid Format \(Expected: eth0:1\), Input Recieved: "veth1"' +sudo dmesg | grep -E 'Interface not found: ""' +sudo dmesg | grep -E 'Input Format Error for Trusted Interface \(Expected: eth0:1\)' #Check for "veth1:" "veth1::1" "veth1:abc" "veth1:-1" "veth1:1:extra" +sudo dmesg | grep -E 'Invalid Format \(Expected: eth0:1\), Input Recieved: "veth1:1,veth2"' +sudo dmesg | grep -E 'Interface not found: "@!veth1"' + + +echo +echo "Test Passed!" +sudo dmesg -n 7 +echo + +exit \ No newline at end of file diff --git a/tests/SettingDynamicParameters/Test_add_VLAN.sh b/tests/SettingDynamicParameters/Test_add_VLAN.sh new file mode 100644 index 0000000..9014f08 --- /dev/null +++ b/tests/SettingDynamicParameters/Test_add_VLAN.sh @@ -0,0 +1,73 @@ +#!/bin/bash + +# This script checks if DAI can add one VLAN to the inspection list + +set -euo pipefail #treat unset vars as errors + +# Track current command for debugging +last_command="" +current_command="" +trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG + +# Log which command caused exit +trap 'echo ""; echo "TEST FAILED - Script exited during: \"$last_command\"" >&2' ERR + +# Define the cleanup function +cleanup() { + echo + echo "=== Cleaning Up ===" + echo + make -C ../.. remove || true + + sudo ip netns exec ns1 ip link set lo down || true + sudo ip netns exec ns2 ip link set lo down || true + sudo ip netns exec ns1 ip link set veth0 down || true + sudo ip netns exec ns2 ip link set veth3 down || true + sudo ip link set veth1 down || true + sudo ip link set veth2 down || true + sudo ip link set br1 down || true + + sudo ip netns delete ns1 || true + sudo ip netns delete ns2 || true + sudo ip link delete br1 || true + + echo "=== Clean-up Complete ===" +} + +# Always run cleanup on exit (normal or error) +trap cleanup EXIT + +cleanup +sudo dmesg -C +sudo dmesg -n 3 + +sudo ../testenv/setup_test_env.sh + +echo +echo "=== Ensure Working Test Environment ===" +echo +sudo ip netns exec ns1 python3 ../helperPythonFilesForCustomPackets/ARP_Request_And_Response_Without_VLAN_ID.py +sudo dmesg -C + +echo +echo "=== Running make to build the module ===" +echo +make -C ../.. + +echo +echo "=== Running make load_with_params to insert the module ===" +echo +make -C ../.. install +echo "10" | sudo tee /sys/module/kdai/parameters/vlans_to_inspect + +echo +echo "=== Testing DAI Adds VLAN_IDs to Entries ===" +echo +sudo dmesg | grep -E "VLAN ID:\s*10" +echo + +echo "Test Passed!" +sudo dmesg -n 7 +echo + +exit diff --git a/tests/SettingDynamicParameters/Test_add_VLANs.sh b/tests/SettingDynamicParameters/Test_add_VLANs.sh index 2bed437..b0d0f50 100644 --- a/tests/SettingDynamicParameters/Test_add_VLANs.sh +++ b/tests/SettingDynamicParameters/Test_add_VLANs.sh @@ -1,6 +1,6 @@ #!/bin/bash -# This script checks if DAI can add VLANs to the inspection list +# This script checks if DAI can add more than one VLANs to the inspection list set -euo pipefail #treat unset vars as errors @@ -58,12 +58,13 @@ echo echo "=== Running make load_with_params to insert the module ===" echo make -C ../.. install -echo "10" | sudo tee /sys/module/kdai/parameters/vlans_to_inspect +echo "10,20" | sudo tee /sys/module/kdai/parameters/vlans_to_inspect echo echo "=== Testing DAI Adds VLAN_IDs to Entries ===" echo sudo dmesg | grep -E "VLAN ID:\s*10" +sudo dmesg | grep -E "VLAN ID:\s*20" echo echo "Test Passed!" diff --git a/tests/SettingDynamicParameters/Test_add_VLANs_Malformed.sh b/tests/SettingDynamicParameters/Test_add_VLANs_Malformed.sh new file mode 100644 index 0000000..3d66522 --- /dev/null +++ b/tests/SettingDynamicParameters/Test_add_VLANs_Malformed.sh @@ -0,0 +1,92 @@ +#!/bin/bash + +# This script checks if the kernel module can handle malformed Trusted Interface Input + +set -euo pipefail #treat unset vars as errors + +# Track current command for debugging +last_command="" +current_command="" +trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG + +# Log which command caused exit +trap 'echo ""; echo "TEST FAILED - Script exited during: \"$last_command\"" >&2' ERR + +# Define the cleanup function +cleanup() { + echo + echo "=== Cleaning Up ===" + echo + make -C ../.. remove || true + + sudo ip netns exec ns1 ip link set lo down || true + sudo ip netns exec ns2 ip link set lo down || true + sudo ip netns exec ns1 ip link set veth0 down || true + sudo ip netns exec ns2 ip link set veth3 down || true + sudo ip link set veth1 down || true + sudo ip link set veth2 down || true + sudo ip link set br1 down || true + + sudo ip netns delete ns1 || true + sudo ip netns delete ns2 || true + sudo ip link delete br1 || true + + echo "=== Clean-up Complete ===" +} + +# Always run cleanup on exit (normal or error) +trap cleanup EXIT + +cleanup +sudo dmesg -C +sudo dmesg -n 3 + +#sudo ../testenv/setup_test_env.sh + +echo +echo "=== Ensure Working Test Environment ===" +echo +#sudo ip netns exec ns1 python3 ../helperPythonFilesForCustomPackets/ARP_Request_And_Response_Without_VLAN_ID.py +sudo dmesg -C + +echo +echo "=== Running make to build the module ===" +echo +make -C ../.. + +echo +echo "=== Running make load_with_params to insert the module ===" +echo +make -C ../.. install +# Valid input for context +# echo "10,20" | sudo tee /sys/module/kdai/parameters/vlans_to_inspect +#echo -n "clear" | sudo tee /sys/module/kdai/parameters/vlans_to_inspect # Empty input (remove the newline character) + +# Malformed / edge-case inputs +echo -n "10,abc,30" | sudo tee /sys/module/kdai/parameters/vlans_to_inspect # VLAN ID with non-numeric characters +echo -n ",,," | sudo tee /sys/module/kdai/parameters/vlans_to_inspect # Multiple commas without values +echo -n " 10 , 20 " | sudo tee /sys/module/kdai/parameters/vlans_to_inspect # VLAN ID with leading or trailing spaces +echo -n "10,20," | sudo tee /sys/module/kdai/parameters/vlans_to_inspect # Trailing comma +echo -n "10 , 20" | sudo tee /sys/module/kdai/parameters/vlans_to_inspect # Excessive spaces around commas +echo -n "-10,20" | sudo tee /sys/module/kdai/parameters/vlans_to_inspect # Negative VLAN ID + +echo + +echo "=== Testing DAI Adds Trusted Interface to Entries ===" +echo +#sudo dmesg | grep -E 'Clearing VLANs To Inspect list' +sudo dmesg | grep -E 'Invalid VLAN_ID: "abc"' +sudo dmesg | grep -E 'Invalid VLAN_ID: ""' # VLAN ID with leading or trailing spaces, Multiple commas without values +sudo dmesg | grep -E 'Invalid VLAN_ID: " 10 "' +sudo dmesg | grep -E 'Invalid VLAN_ID: " 20 "' +sudo dmesg | grep -E 'Invalid VLAN_ID: "10 "' +sudo dmesg | grep -E 'Invalid VLAN_ID: " 20"' +sudo dmesg | grep -E 'Invalid VLAN_ID: "-10"' + + +echo +echo "Test Passed!" +sudo dmesg -n 7 +echo + +exit \ No newline at end of file diff --git a/tests/SettingDynamicParameters/Test_set_globally_enabled_DAI_Malformed.sh b/tests/SettingDynamicParameters/Test_set_globally_enabled_DAI_Malformed.sh new file mode 100644 index 0000000..47026fb --- /dev/null +++ b/tests/SettingDynamicParameters/Test_set_globally_enabled_DAI_Malformed.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +# This script checks if the kernel module can handle malformed Trusted Interface Input + +set -euo pipefail #treat unset vars as errors + +# Track current command for debugging +last_command="" +current_command="" +trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG + +# Log which command caused exit +trap 'echo ""; echo "TEST FAILED - Script exited during: \"$last_command\"" >&2' ERR + +# Define the cleanup function +cleanup() { + echo + echo "=== Cleaning Up ===" + echo + make -C ../.. remove || true + + sudo ip netns exec ns1 ip link set lo down || true + sudo ip netns exec ns2 ip link set lo down || true + sudo ip netns exec ns1 ip link set veth0 down || true + sudo ip netns exec ns2 ip link set veth3 down || true + sudo ip link set veth1 down || true + sudo ip link set veth2 down || true + sudo ip link set br1 down || true + + sudo ip netns delete ns1 || true + sudo ip netns delete ns2 || true + sudo ip link delete br1 || true + + echo "=== Clean-up Complete ===" +} + +# Always run cleanup on exit (normal or error) +trap cleanup EXIT + +cleanup +sudo dmesg -C +sudo dmesg -n 3 + +#sudo ../testenv/setup_test_env.sh + +echo +echo "=== Ensure Working Test Environment ===" +echo +#sudo ip netns exec ns1 python3 ../helperPythonFilesForCustomPackets/ARP_Request_And_Response_Without_VLAN_ID.py +sudo dmesg -C + +echo +echo "=== Running make to build the module ===" +echo +make -C ../.. + +echo +echo "=== Running make load_with_params to insert the module ===" +echo +make -C ../.. install +# Valid input for context +#echo 1 | sudo tee /sys/module/kdai/parameters/globally_enabled_DAI + +echo "=== Testing DAI globalldy_enabled_DAI Entries ===" +# Function to check that the command fails (i.e., invalid input is rejected) +expect_failure() { + input=$1 + echo "Testing malformed input: '$input'" + + set +e # Temporarily disable exit-on-error + echo "$input" | sudo tee /sys/module/kdai/parameters/globally_enabled_DAI >/dev/null + status=$? + set -e # Re-enable exit-on-error + + if [ $status -eq 0 ]; then + echo "Test failed: '$input' was accepted but should have been rejected" + exit 1 + else + echo "Test passed: '$input' correctly rejected" + fi +} + +# Run tests +expect_failure 2 +expect_failure z +expect_failure -1 \ No newline at end of file diff --git a/tests/SettingDynamicParameters/Test_set_static_ACL_Enabled_Malformed.sh b/tests/SettingDynamicParameters/Test_set_static_ACL_Enabled_Malformed.sh new file mode 100644 index 0000000..47026fb --- /dev/null +++ b/tests/SettingDynamicParameters/Test_set_static_ACL_Enabled_Malformed.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +# This script checks if the kernel module can handle malformed Trusted Interface Input + +set -euo pipefail #treat unset vars as errors + +# Track current command for debugging +last_command="" +current_command="" +trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG + +# Log which command caused exit +trap 'echo ""; echo "TEST FAILED - Script exited during: \"$last_command\"" >&2' ERR + +# Define the cleanup function +cleanup() { + echo + echo "=== Cleaning Up ===" + echo + make -C ../.. remove || true + + sudo ip netns exec ns1 ip link set lo down || true + sudo ip netns exec ns2 ip link set lo down || true + sudo ip netns exec ns1 ip link set veth0 down || true + sudo ip netns exec ns2 ip link set veth3 down || true + sudo ip link set veth1 down || true + sudo ip link set veth2 down || true + sudo ip link set br1 down || true + + sudo ip netns delete ns1 || true + sudo ip netns delete ns2 || true + sudo ip link delete br1 || true + + echo "=== Clean-up Complete ===" +} + +# Always run cleanup on exit (normal or error) +trap cleanup EXIT + +cleanup +sudo dmesg -C +sudo dmesg -n 3 + +#sudo ../testenv/setup_test_env.sh + +echo +echo "=== Ensure Working Test Environment ===" +echo +#sudo ip netns exec ns1 python3 ../helperPythonFilesForCustomPackets/ARP_Request_And_Response_Without_VLAN_ID.py +sudo dmesg -C + +echo +echo "=== Running make to build the module ===" +echo +make -C ../.. + +echo +echo "=== Running make load_with_params to insert the module ===" +echo +make -C ../.. install +# Valid input for context +#echo 1 | sudo tee /sys/module/kdai/parameters/globally_enabled_DAI + +echo "=== Testing DAI globalldy_enabled_DAI Entries ===" +# Function to check that the command fails (i.e., invalid input is rejected) +expect_failure() { + input=$1 + echo "Testing malformed input: '$input'" + + set +e # Temporarily disable exit-on-error + echo "$input" | sudo tee /sys/module/kdai/parameters/globally_enabled_DAI >/dev/null + status=$? + set -e # Re-enable exit-on-error + + if [ $status -eq 0 ]; then + echo "Test failed: '$input' was accepted but should have been rejected" + exit 1 + else + echo "Test passed: '$input' correctly rejected" + fi +} + +# Run tests +expect_failure 2 +expect_failure z +expect_failure -1 \ No newline at end of file diff --git a/trustedInterfaces.c b/trustedInterfaces.c index dda2a14..e3410c0 100644 --- a/trustedInterfaces.c +++ b/trustedInterfaces.c @@ -48,7 +48,7 @@ int insert_trusted_interface(const char *device_name, u16 vlan_id) { // Check if the interface exists dev = dev_get_by_name(&init_net, device_name); if (!dev) { - printk(KERN_INFO "Interface not found: %s\n", device_name); + printk(KERN_INFO "Interface not found: \"%s\"\n", device_name); return -2; } @@ -126,13 +126,13 @@ void print_trusted_interface_list(void) { struct interface_entry *entry; unsigned long flags; - printk(KERN_INFO "kdai: ---- List of trusted network interfaces ---\n"); + printk(KERN_INFO "kdai: ---- Trusted Network Interfaces List ---\n"); //If the list is empty notify the user if(trusted_list_size == 0) { printk(KERN_INFO "kdai: The list is currently empty!\n"); printk(KERN_INFO "kdai: All interfaces are Untrusted.\n"); - printk(KERN_INFO "kdai: ---- End of Trusted Network Interfaces List ---\n\n"); + printk(KERN_INFO "kdai: ---- Trusted Network Interfaces List ---\n\n"); return; } @@ -180,10 +180,6 @@ void parse_interfaces_and_vlan(char * interfaces_and_vlan) { char *to_free; u16 vlan_id; - if(interfaces_and_vlan==NULL || *interfaces_and_vlan=='\0'){ - return; - } - //Duplicate the string to safely modify it to_free = kstrdup(interfaces_and_vlan,GFP_KERNEL); str = to_free; @@ -197,7 +193,7 @@ void parse_interfaces_and_vlan(char * interfaces_and_vlan) { //Find the deliminator and null terminate the interface from the vlan; vlan_id_str = strstr(token, ":"); if (!vlan_id_str) { - printk(KERN_INFO "Invalid format (missing colon): %s\n", token); + printk(KERN_INFO "Invalid Format (Expected: eth0:1), Input Recieved: \"%s\"\n", interfaces_and_vlan); continue; } *vlan_id_str='\0'; @@ -209,7 +205,7 @@ void parse_interfaces_and_vlan(char * interfaces_and_vlan) { //After converting add the interface and vlan to the trusted list insert_trusted_interface(token, vlan_id); } else { - printk(KERN_INFO "Invalid VLAN_ID: %s\n", token); + printk(KERN_INFO "Input Format Error for Trusted Interface (Expected: eth0:1)\n"); } } //Free the allocated memory diff --git a/vlan.c b/vlan.c index f8e5f74..1bfb8b5 100644 --- a/vlan.c +++ b/vlan.c @@ -150,10 +150,6 @@ void parse_vlans(char * vlans) { char * str; char *to_free; - if(vlans==NULL || *vlans =='\0'){ - return; - } - //Duplicate the string to safely modify it to_free = kstrdup(vlans,GFP_KERNEL); str = to_free; @@ -170,7 +166,7 @@ void parse_vlans(char * vlans) { //After converting add the vlan to the inpsection list add_vlan_to_inspect(vlan_id); } else { - printk(KERN_INFO "Invalid VLAN_ID: %s\n", token); + printk(KERN_INFO "Invalid VLAN_ID: \"%s\"\n", token); } } //Free the allocated memory