From b842ce11460bb2f181b33a8ee71af1277eb80567 Mon Sep 17 00:00:00 2001 From: kircher Date: Tue, 27 Jun 2023 14:50:06 +0800 Subject: [PATCH] add udp_enable to turn off udp in need --- src/lstack/api/lstack_wrap.c | 1 + src/lstack/core/lstack_cfg.c | 9 +++++++++ src/lstack/include/lstack_cfg.h | 1 + 3 files changed, 11 insertions(+) diff --git a/src/lstack/api/lstack_wrap.c b/src/lstack/api/lstack_wrap.c index 6ee0512..6a1a2c4 100644 --- a/src/lstack/api/lstack_wrap.c +++ b/src/lstack/api/lstack_wrap.c @@ -414,6 +414,7 @@ static inline int32_t do_setsockopt(int32_t s, int32_t level, int32_t optname, c static inline int32_t do_socket(int32_t domain, int32_t type, int32_t protocol) { if ((domain != AF_INET && domain != AF_UNSPEC) + || ((type & SOCK_DGRAM) && !get_global_cfg_params()->udp_enable) || posix_api->ues_posix) { return posix_api->socket_fn(domain, type, protocol); } diff --git a/src/lstack/core/lstack_cfg.c b/src/lstack/core/lstack_cfg.c index 8a627d5..32d63b9 100644 --- a/src/lstack/core/lstack_cfg.c +++ b/src/lstack/core/lstack_cfg.c @@ -73,6 +73,7 @@ static int32_t parse_tuple_filter(void); static int32_t parse_use_bond4(void); static int32_t parse_bond4_slave_mac(void); static int32_t parse_use_sockmap(void); +static int32_t parse_udp_enable(void); #define PARSE_ARG(_arg, _arg_string, _default_val, _min_val, _max_val, _ret) \ do { \ @@ -129,6 +130,7 @@ static struct config_vector_t g_config_tbl[] = { { "use_bond4", parse_use_bond4 }, { "bond4_slave_mac", parse_bond4_slave_mac }, { "use_sockmap", parse_use_sockmap }, + { "udp_enable", parse_udp_enable }, { NULL, NULL } }; @@ -1097,6 +1099,13 @@ static int parse_tuple_filter(void) return 0; } +static int32_t parse_udp_enable(void) +{ + int32_t ret; + PARSE_ARG(g_config_params.udp_enable, "udp_enable", 1, 0, 1, ret); + return ret; +} + static int32_t parse_use_bond4(void) { int32_t ret; diff --git a/src/lstack/include/lstack_cfg.h b/src/lstack/include/lstack_cfg.h index 6da18cf..9102fee 100644 --- a/src/lstack/include/lstack_cfg.h +++ b/src/lstack/include/lstack_cfg.h @@ -109,6 +109,7 @@ struct cfg_params { uint8_t bond4_slave1_mac_addr[ETHER_ADDR_LEN]; uint8_t bond4_slave2_mac_addr[ETHER_ADDR_LEN]; bool use_sockmap; + bool udp_enable; }; struct cfg_params *get_global_cfg_params(void); -- 2.27.0