summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoryangwei <[email protected]>2024-07-23 19:04:55 +0800
committeryangwei <[email protected]>2024-07-24 09:56:56 +0800
commitbba15d7ffdd3e9add76a2d1e287a0899369ac96b (patch)
treeade42e8e62a2f917d74bd3283f15e4d616369e2b /src
parenta91425ce46fdf3459924f6463af533ac8d2f3ce0 (diff)
✨ feat(packet api): support drop,printaddr,link_dir
Diffstat (limited to 'src')
-rw-r--r--src/stellar_on_sapp/stellar_on_sapp_api.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/stellar_on_sapp/stellar_on_sapp_api.c b/src/stellar_on_sapp/stellar_on_sapp_api.c
index 04a67e8..05b6e0a 100644
--- a/src/stellar_on_sapp/stellar_on_sapp_api.c
+++ b/src/stellar_on_sapp/stellar_on_sapp_api.c
@@ -26,6 +26,7 @@ struct packet
enum packet_type type;
unsigned char ip_proto;
const void *raw_pkt;
+ struct streaminfo *pstream;
struct session *sess;
struct stellar *st;
}__attribute__((aligned(sizeof(void*)))) ;
@@ -147,6 +148,7 @@ unsigned char session_state_update_on_sapp(struct streaminfo *stream, unsigned c
pkt->type=type;
pkt->sess=sess;
pkt->st=sess->st;
+ pkt->pstream=stream;
if(raw_pkt)plugin_manager_on_session_ingress(sess, pkt);
//check TCP topic active subscirber num, if 0, return APP_STATE_DROPME, to reduce tcp reassemble overhead
@@ -186,6 +188,7 @@ void packet_update_on_sapp(struct stellar *st, struct streaminfo *pstream, void
pkt.raw_pkt=get_current_rawpkt_from_streaminfo(pstream);
pkt.st=st;
pkt.sess=NULL;
+ pkt.pstream=pstream;
switch (type)
{
case IPv4:
@@ -292,6 +295,37 @@ inline unsigned char packet_get_ip_protocol(struct packet *pkt)
return pkt->ip_proto;
}
+int packet_get_route_direction(const struct packet *pkt)
+{
+ if(pkt == NULL || pkt->raw_pkt==NULL)return PACKET_DIRECTION_UNKNOWN;
+ int dir=PACKET_DIRECTION_UNKNOWN;
+ get_opt_from_rawpkt(pkt->raw_pkt, RAW_PKT_GET_ROUTE_DIR, &dir);
+ MESA_dir_link_to_human(dir);
+ if (dir == (int)'I')
+ {
+ return PACKET_DIRECTION_INCOMING;
+ }
+ if (dir == (int)'E')
+ {
+ return PACKET_DIRECTION_OUTGOING;
+ }
+ return PACKET_DIRECTION_UNKNOWN;
+}
+
+void packet_drop(const struct packet *pkt)
+{
+ if(pkt == NULL || pkt->pstream==NULL)return;
+ int value=1;
+ MESA_set_stream_opt(pkt->pstream, MSO_DROP_CURRENT_PKT, &value, sizeof(value));
+}
+
+const char *packet_get0_readable_addr(struct packet *pkt)
+{
+ if(pkt == NULL || pkt->pstream==NULL)return NULL;
+ struct streaminfo *pstream=pkt->pstream;
+ return printaddr(&pstream->addr, pstream->threadnum);
+}
+
/*********************************************
* SESSION INFO INTERFACE WRAPPER ON SAPP*
*********************************************/