summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangwei <[email protected]>2024-11-21 19:50:55 +0800
committeryangwei <[email protected]>2024-11-22 09:58:14 +0800
commit109ff3947fd966389ec166250deff564e56cdb89 (patch)
treef86fca50c7794d2f8ee855625caa680fa0eba76e
parentfdfa69d19be7cc82d2a76c000bf62f2392919406 (diff)
Saved-20241121Saved-20241121
-rw-r--r--include/stellar/module.h19
-rw-r--r--include/stellar/packet_tag.h39
-rw-r--r--infra/module_manager/module_manager.c6
-rw-r--r--infra/module_manager/module_manager_interna.h10
4 files changed, 59 insertions, 15 deletions
diff --git a/include/stellar/module.h b/include/stellar/module.h
index bc96b46..b0dc738 100644
--- a/include/stellar/module.h
+++ b/include/stellar/module.h
@@ -1,5 +1,6 @@
#pragma once
+#include <stdlib.h>
#ifdef __cplusplus
extern "C"
{
@@ -8,6 +9,10 @@ extern "C"
#include "stellar/mq.h"
#include "stellar/log.h"
+/*******************************************
+ * module API *
+ *******************************************/
+
struct module;
struct module *module_new(const char *name, void *ctx);
void module_free(struct module *mod);
@@ -18,6 +23,10 @@ void module_set_ctx(struct module *mod, void *ctx);
const char *module_get_name(struct module* mod);
void module_set_name(struct module* mod, const char *name);
+/*******************************************
+ * module API *
+ *******************************************/
+
struct module_manager;
typedef struct module *module_on_instance_init_func(struct module_manager *mod_mgr);
@@ -26,7 +35,15 @@ typedef void module_on_instance_exit_func(struct module_manager *mod_mgr, struct
typedef struct module *module_on_thread_init_func(struct module_manager *mod_mgr, int thread_id, struct module *mod);
typedef void module_on_thread_exit_func(struct module_manager *mod_mgr, int thread_id, struct module *mod);
-struct module_manager *module_manager_new(const char *module_spec_toml_path, int max_thread_num, struct mq_schema *mq_schema, struct logger *logger);
+struct module_specification
+{
+ module_on_instance_init_func *on_instance_init_cb;
+ module_on_instance_exit_func *on_instance_exit_cb;
+ module_on_thread_init_func *on_thread_init_cb;
+ module_on_thread_exit_func *on_thread_exit_cb;
+};
+
+struct module_manager *module_manager_new(struct module_specification mod_specs[], size_t n_mod, int max_thread_num, struct mq_schema *mq_schema, struct logger *logger);
void module_manager_free(struct module_manager *mod_mgr);
void module_manager_register_thread(struct module_manager *mod_mgr, int thread_id, struct mq_runtime *mq_rt);
diff --git a/include/stellar/packet_tag.h b/include/stellar/packet_tag.h
new file mode 100644
index 0000000..64319cd
--- /dev/null
+++ b/include/stellar/packet_tag.h
@@ -0,0 +1,39 @@
+
+// packet_tag.h
+
+//packet tag key
+#define PACKET_TAG_KEY_IP_PROTOCOL 1<<1
+#define PACKET_TAG_KEY_SESSION_STATE 1<<2
+#define PACKET_TAG_KEY_L7_PROTOCOL 1<<3
+#define PACKET_TAG_KEY_SESSION_FLAG 1<<4
+#define PACKET_TAG_KEY_CTRL_MESSAGE 1<<5
+
+//packet tag value
+#define PACKET_TAG_VALUE_IP_PROTO_TCP 1<<1
+#define PACKET_TAG_VALUE_IP_PROTO_UDP 1<<2
+#define PACKET_TAG_VALUE_IP_PROTO_ICMP 1<<3
+
+#define PACKET_TAG_VALUE_SESSION_STATE_NEW 1<<4
+#define PACKET_TAG_VALUE_SESSION_STATE_FREE 1<<5
+
+#define PACKET_TAG_VALUE_L7_PROTO_HTTP 1<<6
+#define PACKET_TAG_VALUE_L7_PROTO_SSL 1<<7
+#define PACKET_TAG_VALUE_L7_PROTO_DNS 1<<8
+
+
+//packet.h
+struct packet;
+
+int packet_tag_set(struct packet *pkt, unsigned long long key_bits, unsigned long long value_bits);
+void packet_tag_get(struct packet *pkt, unsigned long long *tag_key_bits, unsigned long long *tag_value_bits);
+
+struct packet_manager;
+struct module;
+
+typedef void on_packet_callback(struct packet *pkt, struct module *mod);
+
+int packet_manager_register_node(struct packet_manager *pkt_mgr, const char *node_name, int packet_stage,
+ unsigned long long interested_tag_key_bits,
+ unsigned long long interested_tag_value_bits,
+ on_packet_callback *node_entry,
+ struct module *mod);
diff --git a/infra/module_manager/module_manager.c b/infra/module_manager/module_manager.c
index 2574267..99b6fc6 100644
--- a/infra/module_manager/module_manager.c
+++ b/infra/module_manager/module_manager.c
@@ -13,17 +13,13 @@
#include "toml/toml.h"
-struct module_manager *module_manager_new(const char *module_spec_toml_path, int max_thread_num, struct mq_schema *mq_schema, struct logger *logger)
+struct module_manager *module_manager_new(struct module_specification mod_specs[], size_t n_mod, int max_thread_num, struct mq_schema *mq_schema, struct logger *logger)
{
struct module_manager *mod_mgr = CALLOC(struct module_manager, 1);
mod_mgr->schema.max_thread_num=max_thread_num;
mod_mgr->schema.mq_schema=mq_schema;
mod_mgr->schema.logger=logger;
- if(module_spec_toml_path==NULL)return mod_mgr;
- FILE *fp = fopen(module_spec_toml_path, "r");
- if (fp == NULL)return mod_mgr;
- mod_mgr->module_spec_toml_path = strdup(module_spec_toml_path);
int mod_num = 0;
toml_table_t *conf = toml_parse_file(fp, NULL, 0);
diff --git a/infra/module_manager/module_manager_interna.h b/infra/module_manager/module_manager_interna.h
index 120c12a..3e47bf0 100644
--- a/infra/module_manager/module_manager_interna.h
+++ b/infra/module_manager/module_manager_interna.h
@@ -22,15 +22,7 @@ struct module
struct module_spec_load
{
struct module *mod;
- module_on_instance_init_func *on_instance_init_cb;
- module_on_instance_exit_func *on_instance_exit_cb;
- module_on_thread_init_func *on_thread_init_cb;
- module_on_thread_exit_func *on_thread_exit_cb;
- char *path;
- char *instance_init_cb_name;
- char *instance_exit_cb_name;
- char *thread_init_cb_name;
- char *thread_exit_cb_name;
+ struct module_specification spec;
bool init_succ;
}__attribute__((aligned(sizeof(void*))));