Update kernel module arguments

This commit is contained in:
Vadim Vetrov 2024-09-15 22:02:04 +03:00
parent 5e28fe83c2
commit 49a48c33cf
No known key found for this signature in database
GPG Key ID: E8A308689D7A73A5

67
kargs.c
View File

@ -3,7 +3,7 @@
#include "types.h"
#include <linux/moduleparam.h>
#define STR_MAXLEN 1024
#define STR_MAXLEN 2048
struct config_t config = {
.frag_sni_reverse = 1,
@ -55,6 +55,7 @@ static int unumeric_set(const char *val, const struct kernel_param *kp) {
if (ret != 0 || n < 0)
return -EINVAL;
return param_set_int(val, kp);
}
@ -67,6 +68,30 @@ static int boolean_set(const char *val, const struct kernel_param *kp) {
return param_set_int(val, kp);
}
static int inverse_boolean_set(const char *val, const struct kernel_param *kp) {
int n = 0, ret;
ret = kstrtoint(val, 10, &n);
if (ret != 0 || (n != 0 && n != 1))
return -EINVAL;
n = !n;
if (kp->arg == NULL)
return -EINVAL;
*(int *)kp->arg = n;
return 0;
}
static int inverse_boolean_get(char *buffer, const struct kernel_param *kp) {
if (*(int *)kp->arg == 0) {
buffer[0] = '1';
} else {
buffer[0] = '0';
}
buffer[1] = '\0';
return 0;
}
static const struct kernel_param_ops unumeric_parameter_ops = {
.set = unumeric_set,
.get = param_get_int
@ -77,6 +102,11 @@ static const struct kernel_param_ops boolean_parameter_ops = {
.get = param_get_int
};
static const struct kernel_param_ops inverse_boolean_ops = {
.set = inverse_boolean_set,
.get = inverse_boolean_get,
};
module_param_cb(fake_sni, &boolean_parameter_ops, &config.fake_sni, 0664);
module_param_cb(fake_sni_seq_len, &unumeric_parameter_ops, &config.fake_sni_seq_len, 0664);
module_param_cb(faking_ttl, &unumeric_parameter_ops, &config.faking_ttl, 0664);
@ -100,14 +130,20 @@ static int sni_domains_set(const char *val, const struct kernel_param *kp) {
return -ENOSPC;
}
if (len >= 1 && val[len - 1] == '\n') {
len--;
}
ret = param_set_charp(val, kp);
if (ret < 0) {
config.domains_strlen = 0;
} else {
config.domains_strlen = len;
if (len == 3 && !strcmp(config.domains_str, "all")) {
if (len == 3 && !strncmp(val, "all", len)) {
config.all_domains = 1;
} else {
config.all_domains = 0;
}
}
@ -150,3 +186,30 @@ static const struct kernel_param_ops exclude_domains_ops = {
module_param_cb(exclude_domains, &exclude_domains_ops, &config.exclude_domains_str, 0664);
module_param_cb(no_ipv6, &inverse_boolean_ops, &config.use_ipv6, 0664);
module_param_cb(silent, &inverse_boolean_ops, &config.verbose, 0664);
module_param_cb(quic_drop, &boolean_parameter_ops, &config.quic_drop, 0664);
static int verbose_trace_set(const char *val, const struct kernel_param *kp) {
int n = 0, ret;
ret = kstrtoint(val, 10, &n);
if (ret != 0 || (n != 0 && n != 1))
return -EINVAL;
if (n) {
n = VERBOSE_TRACE;
} else {
n = VERBOSE_DEBUG;
}
if (kp->arg == NULL)
return -EINVAL;
*(int *)kp->arg = n;
return 0;
}
static const struct kernel_param_ops verbose_trace_ops = {
.set = verbose_trace_set,
.get = param_get_int,
};
module_param_cb(trace, &verbose_trace_ops, &config.verbose, 0664);