Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion .github/workflows/dai-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
21 changes: 13 additions & 8 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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();
Expand All @@ -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
Expand Down
73 changes: 73 additions & 0 deletions tests/SettingDynamicParameters/Test_add_Trusted_Interface.sh
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions tests/SettingDynamicParameters/Test_add_Trusted_Interfaces.sh
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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!"
Expand Down
Original file line number Diff line number Diff line change
@@ -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
73 changes: 73 additions & 0 deletions tests/SettingDynamicParameters/Test_add_VLAN.sh
Original file line number Diff line number Diff line change
@@ -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
Loading