Change spaces to tabs
This commit is contained in:
parent
43032964c3
commit
510a41cbb3
6 changed files with 80 additions and 78 deletions
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
|
@ -1,5 +1,7 @@
|
||||||
{
|
{
|
||||||
"files.associations": {
|
"files.associations": {
|
||||||
"*.h": "c"
|
"*.h": "c"
|
||||||
}
|
},
|
||||||
|
"editor.insertSpaces": false,
|
||||||
|
"editor.tabSize": 4
|
||||||
}
|
}
|
|
@ -3,12 +3,12 @@
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
|
|
||||||
static int __init basic_module_init(void) {
|
static int __init basic_module_init(void) {
|
||||||
pr_info("Bonjour! Le module est chargé.\n");
|
pr_info("Bonjour! Le module est chargé.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit basic_module_exit(void) {
|
static void __exit basic_module_exit(void) {
|
||||||
pr_info("Au revoir! Le module est déchargé.\n");
|
pr_info("Au revoir! Le module est déchargé.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(basic_module_init);
|
module_init(basic_module_init);
|
||||||
|
|
|
@ -24,24 +24,24 @@ module_param_array(myintarray, int, &arr_argc, 0000);
|
||||||
MODULE_PARM_DESC(myintarray, "An array of integers");
|
MODULE_PARM_DESC(myintarray, "An array of integers");
|
||||||
|
|
||||||
static int __init module_params_init(void) {
|
static int __init module_params_init(void) {
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
pr_info("myshort: %hd\n", myshort);
|
pr_info("myshort: %hd\n", myshort);
|
||||||
pr_info("myint: %d\n", myint);
|
pr_info("myint: %d\n", myint);
|
||||||
pr_info("mylong: %ld\n", mylong);
|
pr_info("mylong: %ld\n", mylong);
|
||||||
pr_info("mystring: %s\n", mystring);
|
pr_info("mystring: %s\n", mystring);
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(myintarray); i++)
|
for (i = 0; i < ARRAY_SIZE(myintarray); i++)
|
||||||
pr_info("myintarray[%d] = %d\n", i, myintarray[i]);
|
pr_info("myintarray[%d] = %d\n", i, myintarray[i]);
|
||||||
|
|
||||||
pr_info("%d arguments for myintarray.\n", arr_argc);
|
pr_info("%d arguments for myintarray.\n", arr_argc);
|
||||||
|
|
||||||
pr_info("Module avec paramètre chargé.\n");
|
pr_info("Module avec paramètre chargé.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit module_params_exit(void) {
|
static void __exit module_params_exit(void) {
|
||||||
pr_info("Module avec paramètre déchargé.\n");
|
pr_info("Module avec paramètre déchargé.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(module_params_init);
|
module_init(module_params_init);
|
||||||
|
|
|
@ -16,62 +16,62 @@ static ssize_t device_read(struct file *, char *, size_t, loff_t *);
|
||||||
static ssize_t device_write(struct file *, const char *, size_t, loff_t *);
|
static ssize_t device_write(struct file *, const char *, size_t, loff_t *);
|
||||||
|
|
||||||
static struct file_operations fops = {
|
static struct file_operations fops = {
|
||||||
.read = device_read,
|
.read = device_read,
|
||||||
.write = device_write,
|
.write = device_write,
|
||||||
.open = device_open,
|
.open = device_open,
|
||||||
.release = device_release,
|
.release = device_release,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int __init basic_module_init(void) {
|
static int __init basic_module_init(void) {
|
||||||
pr_info("Bonjour! Le module est chargé.\n");
|
pr_info("Bonjour! Le module est chargé.\n");
|
||||||
major_number = register_chrdev(0, DEVICE_NAME, &fops);
|
major_number = register_chrdev(0, DEVICE_NAME, &fops);
|
||||||
if (major_number < 0) {
|
if (major_number < 0) {
|
||||||
pr_info("Erreur lors de l'enregistrement du périphérique de caractère\n");
|
pr_info("Erreur lors de l'enregistrement du périphérique de caractère\n");
|
||||||
return major_number;
|
return major_number;
|
||||||
}
|
}
|
||||||
pr_info("Périphérique de caractère enregistré avec le numéro de majeur %d\n", major_number);
|
pr_info("Périphérique de caractère enregistré avec le numéro de majeur %d\n", major_number);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit basic_module_exit(void) {
|
static void __exit basic_module_exit(void) {
|
||||||
unregister_chrdev(major_number, DEVICE_NAME);
|
unregister_chrdev(major_number, DEVICE_NAME);
|
||||||
pr_info("Au revoir! Le module est déchargé.\n");
|
pr_info("Au revoir! Le module est déchargé.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int device_open(struct inode *inode, struct file *file) {
|
static int device_open(struct inode *inode, struct file *file) {
|
||||||
pr_info("flodev - Ouverture du périphérique\n");
|
pr_info("flodev - Ouverture du périphérique\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int device_release(struct inode *inode, struct file *file) {
|
static int device_release(struct inode *inode, struct file *file) {
|
||||||
pr_info("flodev - Fermeture du périphérique\n");
|
pr_info("flodev - Fermeture du périphérique\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t device_read(struct file *filp, char *buffer, size_t length, loff_t *offset) {
|
static ssize_t device_read(struct file *filp, char *buffer, size_t length, loff_t *offset) {
|
||||||
int bytes_read = 0;
|
int bytes_read = 0;
|
||||||
if (*offset >= size_of_msg) {
|
if (*offset >= size_of_msg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (*offset + length > size_of_msg) {
|
if (*offset + length > size_of_msg) {
|
||||||
length = size_of_msg - *offset;
|
length = size_of_msg - *offset;
|
||||||
}
|
}
|
||||||
if (copy_to_user(buffer, msg + *offset, length)) {
|
if (copy_to_user(buffer, msg + *offset, length)) {
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
*offset += length;
|
*offset += length;
|
||||||
bytes_read = length;
|
bytes_read = length;
|
||||||
pr_info("flodev - Lecture de %d bytes\n", bytes_read);
|
pr_info("flodev - Lecture de %d bytes\n", bytes_read);
|
||||||
return bytes_read;
|
return bytes_read;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ssize_t device_write(struct file *filp, const char *buff, size_t len, loff_t *off) {
|
static ssize_t device_write(struct file *filp, const char *buff, size_t len, loff_t *off) {
|
||||||
if (copy_from_user(msg, buff, len)) {
|
if (copy_from_user(msg, buff, len)) {
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
size_of_msg = len;
|
size_of_msg = len;
|
||||||
pr_info("flodev - Message reçu: %s\n", msg);
|
pr_info("flodev - Message reçu: %s\n", msg);
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(basic_module_init);
|
module_init(basic_module_init);
|
||||||
|
|
|
@ -7,22 +7,22 @@
|
||||||
static inline void print_processus_info(void);
|
static inline void print_processus_info(void);
|
||||||
|
|
||||||
static int __init basic_module_init(void) {
|
static int __init basic_module_init(void) {
|
||||||
pr_info("Bonjour! Le module est chargé.\n");
|
pr_info("Bonjour! Le module est chargé.\n");
|
||||||
|
|
||||||
print_processus_info();
|
print_processus_info();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit basic_module_exit(void) {
|
static void __exit basic_module_exit(void) {
|
||||||
pr_info("Au revoir! Le module est déchargé.\n");
|
pr_info("Au revoir! Le module est déchargé.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void print_processus_info(void) {
|
static inline void print_processus_info(void) {
|
||||||
struct task_struct *task;
|
struct task_struct *task;
|
||||||
|
|
||||||
for_each_process(task) {
|
for_each_process(task) {
|
||||||
pr_info("PID: %d, COMM: %s, ON CPU: %d\n", task->pid, task->comm, task->on_cpu);
|
pr_info("PID: %d, COMM: %s, ON CPU: %d\n", task->pid, task->comm, task->on_cpu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(basic_module_init);
|
module_init(basic_module_init);
|
||||||
|
|
|
@ -8,32 +8,32 @@
|
||||||
static struct nf_hook_ops nfho;
|
static struct nf_hook_ops nfho;
|
||||||
|
|
||||||
unsigned int hook_func(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) {
|
unsigned int hook_func(void *priv, struct sk_buff *skb, const struct nf_hook_state *state) {
|
||||||
const struct iphdr *iph = ip_hdr(skb);
|
const struct iphdr *iph = ip_hdr(skb);
|
||||||
const struct tcphdr *tcph = tcp_hdr(skb);
|
const struct tcphdr *tcph = tcp_hdr(skb);
|
||||||
|
|
||||||
// Filtrer les paquets TCP avec un port source spécifique
|
// Filtrer les paquets TCP avec un port source spécifique
|
||||||
if (iph->protocol == IPPROTO_TCP && tcph->source == htons(8080)) {
|
if (iph->protocol == IPPROTO_TCP && tcph->source == htons(8080)) {
|
||||||
pr_info("Paquets filtrés: TCP source port 8080\n");
|
pr_info("Paquets filtrés: TCP source port 8080\n");
|
||||||
return NF_DROP;
|
return NF_DROP;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NF_ACCEPT;
|
return NF_ACCEPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __init packet_filter_init(void) {
|
static int __init packet_filter_init(void) {
|
||||||
nfho.hook = hook_func;
|
nfho.hook = hook_func;
|
||||||
nfho.hooknum = NF_INET_PRE_ROUTING;
|
nfho.hooknum = NF_INET_PRE_ROUTING;
|
||||||
nfho.pf = PF_INET;
|
nfho.pf = PF_INET;
|
||||||
nfho.priority = NF_IP_PRI_FIRST;
|
nfho.priority = NF_IP_PRI_FIRST;
|
||||||
|
|
||||||
nf_register_net_hook(&init_net, &nfho);
|
nf_register_net_hook(&init_net, &nfho);
|
||||||
pr_info("Module de filtrage de paquets chargé.\n");
|
pr_info("Module de filtrage de paquets chargé.\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit packet_filter_exit(void) {
|
static void __exit packet_filter_exit(void) {
|
||||||
nf_unregister_net_hook(&init_net, &nfho);
|
nf_unregister_net_hook(&init_net, &nfho);
|
||||||
pr_info("Module de filtrage de paquets déchargé.\n");
|
pr_info("Module de filtrage de paquets déchargé.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(packet_filter_init);
|
module_init(packet_filter_init);
|
||||||
|
|
Loading…
Add table
Reference in a new issue