update 2025-02-12 00:27:05

This commit is contained in:
kenzok8
2025-02-12 00:27:05 +08:00
parent a6ff95d63c
commit dc1bbf8e9a
36 changed files with 1837 additions and 1144 deletions

View File

@@ -49,6 +49,7 @@ define Package/appfilter/install
$(INSTALL_BIN) ./files/appfilter.config $(1)/etc/config/appfilter
$(INSTALL_BIN) ./files/user_info.config $(1)/etc/config/user_info
$(INSTALL_BIN) $(PKG_BUILD_DIR)/oafd $(1)/usr/bin
$(INSTALL_BIN) ./files/hnat.sh $(1)/usr/bin
endef

View File

@@ -2,6 +2,9 @@ config global global
option enable '0'
option work_mode '0'
option record_enable '1'
option disable_hnat '1'
option tcp_rst '1'
option lan_ifname 'br-lan'
config appfilter appfilter

View File

@@ -0,0 +1,33 @@
. /usr/share/libubox/jshn.sh
. /lib/functions.sh
disable_hnat=`uci get appfilter.global.disable_hnat`
if [ x"1" != x"$disable_hnat" ];then
return
fi
# mt798x
test -d /sys/kernel/debug/hnat && {
echo 0 >/sys/kernel/debug/hnat/hook_toggle
}
# qca ecm
test -d /sys/kernel/debug/ecm/ && {
echo "1000000" > /sys/kernel/debug/ecm/ecm_classifier_default/accel_delay_pkts
}
# turbo acc
test -f /etc/config/turboacc && {
uci -q set "turboacc.config.fastpath_fo_hw"="0"
uci -q set "turboacc.config.fastpath_fc_ipv6"="0"
uci -q set "turboacc.config.fastpath"="none"
uci -q set "turboacc.config.fullcone"="0"
/etc/init.d/turboacc restart &
}
uci -q set "firewall.@defaults[0].flow_offloading_hw"='0'
uci -q set "firewall.@defaults[0].flow_offloading"='0'
uci -q set "firewall.@defaults[0].fullcone"='0'
fw3 reload &

View File

@@ -73,11 +73,16 @@ reload_rule(){
load_mac_list
}
reload_base_config(){
config_load appfilter
reload_base_config(){
config_load appfilter
config_get work_mode "global" "work_mode"
config_get lan_ifname "global" "lan_ifname"
echo "$work_mode" >/proc/sys/oaf/work_mode
}
if [ x"" != x"$lan_ifname" ];then
echo "$lan_ifname" >/proc/sys/oaf/lan_ifname
fi
}
case $1 in
"reload")

View File

@@ -72,6 +72,9 @@ typedef struct af_global_config_t{
int user_mode;
int work_mode;
int record_enable;
int disable_hnat;
int tcp_rst;
char lan_ifname[16];
}af_global_config_t;
typedef struct time_config{

View File

@@ -820,6 +820,81 @@ static int handle_set_app_filter_base(struct ubus_context *ctx, struct ubus_obje
}
static int handle_get_app_filter_adv(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg) {
struct json_object *response = json_object_new_object();
struct json_object *data_obj = json_object_new_object();
int i;
struct uci_context *uci_ctx = uci_alloc_context();
if (!uci_ctx) {
printf("Failed to allocate UCI context\n");
return 0;
}
char lan_ifname[16];
int tcp_rst = af_uci_get_int_value(uci_ctx, "appfilter.global.tcp_rst");
af_uci_get_value(uci_ctx, "appfilter.global.lan_ifname", lan_ifname, sizeof(lan_ifname));
int disable_hnat = af_uci_get_int_value(uci_ctx, "appfilter.global.disable_hnat");
json_object_object_add(data_obj, "tcp_rst", json_object_new_int(tcp_rst));
json_object_object_add(data_obj, "lan_ifname", json_object_new_string(lan_ifname));
json_object_object_add(data_obj, "disable_hnat", json_object_new_int(disable_hnat));
json_object_object_add(response, "data", data_obj);
uci_free_context(uci_ctx);
struct blob_buf b = {};
blob_buf_init(&b, 0);
blobmsg_add_object(&b, response);
ubus_send_reply(ctx, req, b.head);
blob_buf_free(&b);
json_object_put(response);
return 0;
}
static int handle_set_app_filter_adv(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg) {
struct json_object *response = json_object_new_object();
int i;
char *msg_obj_str = blobmsg_format_json(msg, true);
if (!msg_obj_str) {
printf("format json failed\n");
return 0;
}
printf("msg_obj_str: %s\n", msg_obj_str);
struct json_object *req_obj = json_tokener_parse(msg_obj_str);
struct json_object *tcp_rst_obj = json_object_object_get(req_obj, "tcp_rst");
struct json_object *lan_ifname_obj = json_object_object_get(req_obj, "lan_ifname");
struct json_object *disable_hnat_obj = json_object_object_get(req_obj, "disable_hnat");
struct uci_context *uci_ctx = uci_alloc_context();
if (!uci_ctx) {
printf("Failed to allocate UCI context\n");
return 0;
}
if (tcp_rst_obj)
af_uci_set_int_value(uci_ctx, "appfilter.global.tcp_rst", json_object_get_int(tcp_rst_obj));
if (lan_ifname_obj)
af_uci_set_value(uci_ctx, "appfilter.global.lan_ifname", json_object_get_string(lan_ifname_obj));
if (disable_hnat_obj)
af_uci_set_int_value(uci_ctx, "appfilter.global.disable_hnat", json_object_get_int(disable_hnat_obj));
af_uci_commit(uci_ctx, "appfilter");
g_oaf_config_change = 1;
reload_oaf_rule();
system("/usr/bin/hnat.sh &");
uci_free_context(uci_ctx);
struct blob_buf b = {};
blob_buf_init(&b, 0);
blobmsg_add_object(&b, response);
ubus_send_reply(ctx, req, b.head);
blob_buf_free(&b);
json_object_put(response);
return 0;
}
static int handle_get_app_filter_time(struct ubus_context *ctx, struct ubus_object *obj,
struct ubus_request_data *req, const char *method,
struct blob_attr *msg) {
@@ -1463,9 +1538,10 @@ static struct ubus_method appfilter_object_methods[] = {
UBUS_METHOD("class_list", handle_get_class_list, empty_policy),
UBUS_METHOD("set_app_filter", handle_set_app_filter, empty_policy),
UBUS_METHOD("get_app_filter", handle_get_app_filter, empty_policy),
UBUS_METHOD("set_app_filter_base", handle_set_app_filter_base, empty_policy),
UBUS_METHOD("get_app_filter_base", handle_get_app_filter_base, empty_policy),
UBUS_METHOD("set_app_filter_adv", handle_set_app_filter_adv, empty_policy),
UBUS_METHOD("get_app_filter_adv", handle_get_app_filter_adv, empty_policy),
UBUS_METHOD("set_app_filter_time", handle_set_app_filter_time, empty_policy),
UBUS_METHOD("get_app_filter_time", handle_get_app_filter_time, empty_policy),
UBUS_METHOD("get_all_users", handle_get_all_users, empty_policy),

View File

@@ -38,6 +38,7 @@ int current_log_level = LOG_LEVEL_INFO;
af_run_time_status_t g_af_status;
int g_oaf_config_change = 1;
af_config_t g_af_config;
int g_hnat_init = 0;
void af_init_time_status(void){
g_af_status.filter = 0;
@@ -117,6 +118,7 @@ EXIT:
void af_load_global_config(af_global_config_t *config){
int ret = 0;
char lan_ifname[32] = {0};
struct uci_context *ctx = uci_alloc_context();
if (!ctx)
return;
@@ -143,6 +145,24 @@ void af_load_global_config(af_global_config_t *config){
config->work_mode = 0;
else
config->work_mode = ret;
ret = af_uci_get_int_value(ctx, "appfilter.global.tcp_rst");
if (ret < 0)
config->tcp_rst = 1;
else
config->tcp_rst = ret;
ret = af_uci_get_int_value(ctx, "appfilter.global.disable_hnat");
if (ret < 0)
config->disable_hnat = 1;
else
config->disable_hnat = ret;
ret = af_uci_get_value(ctx, "appfilter.global.disable_hnat", lan_ifname, sizeof(lan_ifname));
if (ret < 0)
strncpy(config->lan_ifname, "br-lan", sizeof(config->lan_ifname) - 1);
else
strncpy(config->lan_ifname, lan_ifname, sizeof(config->lan_ifname) - 1);
uci_free_context(ctx);
LOG_INFO("enable=%d, user_mode=%d, work_mode=%d", config->enable, config->user_mode, config->work_mode);
}
@@ -290,6 +310,13 @@ void update_oaf_record_status(void){
}
}
void af_hnat_init(void){
if (g_hnat_init == 0){
system("/usr/bin/hnat.sh");
g_hnat_init = 1;
}
}
void dev_list_timeout_handler(struct uloop_timeout *t)
{
@@ -315,6 +342,9 @@ void dev_list_timeout_handler(struct uloop_timeout *t)
update_oaf_record_status();
g_oaf_config_change = 0;
}
if (count > 60){ // delay init
af_hnat_init();
}
uloop_timeout_set(t, 1000);
}