summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryangwei <[email protected]>2024-02-28 19:13:35 +0800
committeryangwei <[email protected]>2024-02-28 19:14:21 +0800
commitdba8ffef7b3b69db106d75c86e784c57b88b92b8 (patch)
tree476b336216bb0bd2a2ce93d04136fafa1dec843b
parent41d9fa5e80726a00c9ca3b66b7619f834dc66377 (diff)
✨ feat(polling plugin): support register polling plugin
-rw-r--r--examples/stellar_plugin/simple_stellar_plugin.c20
-rw-r--r--include/stellar/stellar.h3
-rw-r--r--src/plugin_manager/plugin_manager.c47
-rw-r--r--src/plugin_manager/plugin_manager.h2
-rw-r--r--src/stellar_on_sapp/start_loader.inf6
-rw-r--r--src/stellar_on_sapp/stellar_on_sapp.h2
-rw-r--r--src/stellar_on_sapp/stellar_on_sapp_api.c8
-rw-r--r--src/stellar_on_sapp/stellar_on_sapp_loader.c6
8 files changed, 83 insertions, 11 deletions
diff --git a/examples/stellar_plugin/simple_stellar_plugin.c b/examples/stellar_plugin/simple_stellar_plugin.c
index 990aee9..eb7dd48 100644
--- a/examples/stellar_plugin/simple_stellar_plugin.c
+++ b/examples/stellar_plugin/simple_stellar_plugin.c
@@ -21,6 +21,7 @@ struct simple_stellar_plugin_env
long long udp_packet_count;
long long icmp_packet_count;
long long icmp6_packet_count;
+ long long polling_times;
};
struct mq_message_stat
@@ -149,6 +150,12 @@ void simple_stellar_event_on_packet_func(struct packet *pkt, unsigned char ip_p
return;
}
+void simple_stellar_plugin_on_polling_func(void *plugin_env)
+{
+ struct simple_stellar_plugin_env *env = (struct simple_stellar_plugin_env *)plugin_env;
+ env->polling_times++;
+ return;
+}
void *simple_stellar_event_plugin_init(struct stellar *st)
{
@@ -166,7 +173,14 @@ void *simple_stellar_event_plugin_init(struct stellar *st)
if(tcp_plugin_id <= 0x10000 || udp_plugin_id <= 0x10000 || icmp_plugin_id <= 0x10000 || icmp6_plugin_id <= 0x10000)
{
- perror("register packet plugin failed\n");
+ perror("register packet plugin return invalid plugin id\n");
+ exit(-1);
+ }
+
+ int polling_plugin_id=stellar_polling_plugin_register(st, simple_stellar_plugin_on_polling_func, env);
+ if(polling_plugin_id <= 0x20000)
+ {
+ perror("register polling plugin return invalid plugin id \n");
exit(-1);
}
@@ -197,14 +211,12 @@ void simple_stellar_event_plugin_exit(void *plugin_env)
if(plugin_env)
{
struct simple_stellar_plugin_env *env = (struct simple_stellar_plugin_env *)plugin_env;
- printf("(%s):tcp_packet_num:%lld, udp_packet_num:%lld, icmp_packet_num:%lld, icmp6_packet_num:%lld \n", __FUNCTION__, env->tcp_packet_count, env->udp_packet_count, env->icmp_packet_count, env->icmp6_packet_count);
+ printf("(%s):tcp_packet_num:%lld, udp_packet_num:%lld, icmp_packet_num:%lld, icmp6_packet_num:%lld, polling_times:%lld\n", __FUNCTION__, env->tcp_packet_count, env->udp_packet_count, env->icmp_packet_count, env->icmp6_packet_count, env->polling_times);
FREE(plugin_env);
}
return;
}
-// TODO: add polling entry
-
/*******************************
* mq plugin *
*******************************/
diff --git a/include/stellar/stellar.h b/include/stellar/stellar.h
index 96b5394..3f11734 100644
--- a/include/stellar/stellar.h
+++ b/include/stellar/stellar.h
@@ -33,4 +33,7 @@ typedef void plugin_on_packet_func(struct packet *pkt, unsigned char ip_protoco
//return packet plugin_id
int stellar_packet_plugin_register(struct stellar *st, unsigned char ip_protocol, plugin_on_packet_func on_packet, void *plugin_env);
+typedef void plugin_on_polling_func(void *plugin_env);
+//return polling plugin_id
+int stellar_polling_plugin_register(struct stellar *st, plugin_on_polling_func on_polling, void *plugin_env); \ No newline at end of file
diff --git a/src/plugin_manager/plugin_manager.c b/src/plugin_manager/plugin_manager.c
index 13e0f2a..dc0939b 100644
--- a/src/plugin_manager/plugin_manager.c
+++ b/src/plugin_manager/plugin_manager.c
@@ -17,6 +17,7 @@ struct plugin_manager_schema
UT_array *session_mq_schema_array;
UT_array *registered_session_plugin_array;
UT_array *registered_packet_plugin_array;
+ UT_array *registered_polling_plugin_array;
int topic_num;
int subscriber_num;
int tcp_topic_id;
@@ -88,12 +89,16 @@ struct plugin_manager_runtime
struct registered_packet_plugin_schema
{
- int plugin_spec_idx;
char ip_protocol;
plugin_on_packet_func *on_packet;
void *plugin_env;
};
+struct registered_polling_plugin_schema
+{
+ plugin_on_polling_func *on_polling;
+ void *plugin_env;
+};
struct session_mq_subscriber_info
{
@@ -103,7 +108,6 @@ struct session_mq_subscriber_info
struct registered_session_plugin_schema
{
- int plugin_spec_idx;
session_ctx_new_func *on_ctx_new;
session_ctx_free_func *on_ctx_free;
void *plugin_env;
@@ -111,6 +115,7 @@ struct registered_session_plugin_schema
};
#define PACKET_PULGIN_ID_BASE 0x10000
+#define POLLING_PULGIN_ID_BASE 0x20000
/*******************************
* PLUGIN MANAGER INIT & EXIT *
@@ -246,6 +251,7 @@ void plugin_manager_exit(struct plugin_manager_schema *plug_mgr)
}
if(plug_mgr->session_exdata_schema_array)utarray_free(plug_mgr->session_exdata_schema_array);
if(plug_mgr->registered_packet_plugin_array)utarray_free(plug_mgr->registered_packet_plugin_array);
+ if(plug_mgr->registered_polling_plugin_array)utarray_free(plug_mgr->registered_polling_plugin_array);
if(plug_mgr->registered_session_plugin_array)
{
struct registered_session_plugin_schema *s = NULL;
@@ -723,6 +729,43 @@ void plugin_manager_on_packet(struct plugin_manager_schema *plug_mgr, struct pac
}
/*********************************************
+ * PLUGIN MANAGER POLLING PLUGIN *
+ *********************************************/
+
+
+UT_icd registered_polling_plugin_array_icd = {sizeof(struct registered_polling_plugin_schema), NULL, NULL, NULL};
+
+int stellar_polling_plugin_register(struct stellar *st, plugin_on_polling_func on_polling, void *plugin_env)
+{
+ struct plugin_manager_schema *plug_mgr = stellar_plugin_manager_schema_get(st);
+ if(plug_mgr->registered_polling_plugin_array == NULL)
+ {
+ utarray_new(plug_mgr->registered_polling_plugin_array, &registered_polling_plugin_array_icd);
+ }
+ struct registered_polling_plugin_schema polling_plugin_schema;
+ memset(&polling_plugin_schema, 0, sizeof(polling_plugin_schema));
+ polling_plugin_schema.on_polling = on_polling;
+ polling_plugin_schema.plugin_env = plugin_env;
+ utarray_push_back(plug_mgr->registered_polling_plugin_array, &polling_plugin_schema);
+ return (POLLING_PULGIN_ID_BASE+utarray_len(plug_mgr->registered_polling_plugin_array));// return polling plugin_id
+}
+
+// FIXME: scheduler with return value
+void plugin_manager_on_polling(struct plugin_manager_schema *plug_mgr)
+{
+ if(plug_mgr->registered_polling_plugin_array == NULL)return;
+ struct registered_polling_plugin_schema *p=NULL;
+ while ((p = (struct registered_polling_plugin_schema *)utarray_next(plug_mgr->registered_polling_plugin_array, p)))
+ {
+ if(p->on_polling)
+ {
+ p->on_polling(p->plugin_env);
+ }
+ }
+ return;
+}
+
+/*********************************************
* PLUGIN MANAGER SESSION PLUGIN *
*********************************************/
diff --git a/src/plugin_manager/plugin_manager.h b/src/plugin_manager/plugin_manager.h
index 7d19323..c967e9e 100644
--- a/src/plugin_manager/plugin_manager.h
+++ b/src/plugin_manager/plugin_manager.h
@@ -10,6 +10,8 @@ void plugin_manager_exit(struct plugin_manager_schema *plug_mgr);
void plugin_manager_on_packet(struct plugin_manager_schema *plug_mgr, struct packet *pkt);
+void plugin_manager_on_polling(struct plugin_manager_schema *plug_mgr);
+
//publish and dispatch session msg(msg, pkt) on session_mq
void plugin_manager_on_session_ingress(struct session *sess,const struct packet *pkt);
void plugin_manager_on_session_egress(struct session *sess,const struct packet *pkt);
diff --git a/src/stellar_on_sapp/start_loader.inf b/src/stellar_on_sapp/start_loader.inf
index 0327912..0b029b8 100644
--- a/src/stellar_on_sapp/start_loader.inf
+++ b/src/stellar_on_sapp/start_loader.inf
@@ -28,6 +28,6 @@ FUNC_NAME=stellar_on_sapp_ip4_entry
FUNC_FLAG=ALL
FUNC_NAME=stellar_on_sapp_ip6_entry
-#[POLLING]
-#FUNC_FLAG=ALL
-#FUNC_NAME=stellar_on_sapp_polling_entry \ No newline at end of file
+[POLLING]
+FUNC_FLAG=ALL
+FUNC_NAME=stellar_on_sapp_polling_entry \ No newline at end of file
diff --git a/src/stellar_on_sapp/stellar_on_sapp.h b/src/stellar_on_sapp/stellar_on_sapp.h
index 593f40b..0784458 100644
--- a/src/stellar_on_sapp/stellar_on_sapp.h
+++ b/src/stellar_on_sapp/stellar_on_sapp.h
@@ -17,3 +17,5 @@ unsigned char session_state_update_on_sapp(struct streaminfo *stream, struct ses
void session_poll_on_sapp(struct session *sess);
void packet_update_on_sapp(struct stellar *st, struct streaminfo *pstream, void *a_packet, enum packet_type type);
+
+void polling_on_sapp(struct stellar *st); \ No newline at end of file
diff --git a/src/stellar_on_sapp/stellar_on_sapp_api.c b/src/stellar_on_sapp/stellar_on_sapp_api.c
index 54651b1..e0706c0 100644
--- a/src/stellar_on_sapp/stellar_on_sapp_api.c
+++ b/src/stellar_on_sapp/stellar_on_sapp_api.c
@@ -178,8 +178,14 @@ void packet_update_on_sapp(struct stellar *st, struct streaminfo *pstream, void
}
plugin_manager_on_packet(st->plug_mgr, &pkt);
}
+
+void polling_on_sapp(struct stellar *st)
+{
+ plugin_manager_on_polling(st->plug_mgr);
+}
+
/*********************************************
- * STELLAR INFO INTERFACE WRAPPER ON SAPP*
+ * STELLAR INFO INTERFACE WRAPPER ON SAPP
*********************************************/
int stellar_get_worker_thread_num(struct stellar *st)
diff --git a/src/stellar_on_sapp/stellar_on_sapp_loader.c b/src/stellar_on_sapp/stellar_on_sapp_loader.c
index df864f2..c8a4306 100644
--- a/src/stellar_on_sapp/stellar_on_sapp_loader.c
+++ b/src/stellar_on_sapp/stellar_on_sapp_loader.c
@@ -223,4 +223,8 @@ char stellar_on_sapp_ip6_entry( struct streaminfo *pstream,unsigned char routedi
return APP_STATE_GIVEME;
}
-// TODO: add polling entry and call plugin_manager_on_polling \ No newline at end of file
+char stellar_on_sapp_polling_entry(struct streaminfo *stream, void **pme, int thread_seq,void *a_packet)
+{
+ polling_on_sapp(g_stellar);
+ return APP_STATE_GIVEME;
+} \ No newline at end of file