[ 61.240186] firewall: Initializing the firewall LKM
[ 61.240190] firewall: registered correctly with major number 244
[ 61.240197] firewall: device class registered correctly
[ 61.240268] firewall: device class created correctly
[ 61.240268] packet droper loaded
int main(){
int BUFFER_LENGTH =256;
FILE* filePointer;
char buffer[BUFFER_LENGTH];
char save[100][BUFFER_LENGTH];
filePointer = fopen("config.txt", "r");
int i = 0;
int j=0;
int ret, fd;
while(fgets(save[i], BUFFER_LENGTH, filePointer)) {
printf("%s", save[i]);
i++;
}
fclose(filePointer);
printf("\nStarting device test code example...\n");
fd = open("/dev/firewall", O_RDWR); // Open the device with read/write access
//printf("open\n");
if (fd < 0){
perror("Failed to open the device...");
return errno;
}
for(j=0; j < i; j++){
ret = write(fd, save[j], BUFFER_LENGTH); // Send the string to the LKM
if (ret < 0){
perror("Failed to write the message to the device.");
return errno;
}
}
printf("End of the program\n");
return 0;
}
[ 71.371035] firewall: Device has been opened
[ 71.371039] ips: blacklist
[ 71.380654] block list
[ 71.380663] ips: 216.58.208.238
[ 71.405081] block list
[ 71.405096] ips: 192.168.2.6
[ 71.421113] block list
[ 71.421297] firewall: Device successfully closed
[ 4871.536952] src_ip: 10.211.55.1 ** source port: 67
[ 4871.536956] dst_ip: 10.211.55.4 ** dest_port :68
[ 4871.536961] b_hook - OK
[ 4871.536966] Not in blacklist ,Not dropped.
[ 4871.536970] src_ip: 10.211.55.1 ** source port: 67
[ 4871.536975] dst_ip: 10.211.55.4 ** dest_port :68
[ 4871.536980] b_hook - OK
[ 4871.536984] Not in blacklist ,Not dropped.
static struct nf_hook_ops b_drop __read_mostly = {
.pf = NFPROTO_IPV4,
.priority = NF_IP_PRI_FIRST,
.hooknum =NF_INET_LOCAL_IN,
.hook = (nf_hookfn *) b_hook
};
static ssize_t mydev_write(struct file * filep, const char * buffer, size_t len, loff_t * offset) {
copy_from_user(ips[i], buffer, 256);
printk(KERN_INFO "ips: %s \n", ips[i]);
i++;
if (strncmp(ips[0], "wh", 2) == 0) {
BORW = 0;
if (nf_register_net_hook( & init_net, &w_drop) {
printk(KERN_ALERT "FAILED\n");
}
printk(KERN_INFO "white list\n");
return len;
}
if (strncmp(ips[0], "bl", 2) == 0) {
BORW = 1;
if (nf_register_net_hook( & init_net, &b_drop)) {
printk(KERN_ALERT "FAILED\n");
}
printk(KERN_INFO "block list\n");
return len;
}
BORW = 1;
if (nf_register_net_hook( & init_net, &b_drop)) {
printk(KERN_ALERT "FAILED\n");
}
printk(KERN_INFO "defult is block list\n");
return len;
}
}