diff options
| author | yangwei <[email protected]> | 2023-08-30 13:44:34 +0800 |
|---|---|---|
| committer | yangwei <[email protected]> | 2023-08-30 13:44:34 +0800 |
| commit | f74d035b9ecc745bd73db9cfd18cba8711e6d5f2 (patch) | |
| tree | 3ec93fb38d060b6666458af5feb536fc13fde379 | |
| parent | d7b6efe5a306a776efd8c39cb04ef8555f53df9e (diff) | |
✨ feat(session_is_outer_tunnel): return session tunnel info
| -rw-r--r-- | include/stellar/session.h | 16 | ||||
| -rw-r--r-- | src/adapter/adapter.c | 46 |
2 files changed, 59 insertions, 3 deletions
diff --git a/include/stellar/session.h b/include/stellar/session.h index 6188cb1..e1ec40b 100644 --- a/include/stellar/session.h +++ b/include/stellar/session.h @@ -28,6 +28,22 @@ struct session; #define SESSION_SEEN_S2C_FLOW (1 << 1) int session_is_symmetric(const struct session *sess, unsigned char *flag); + + +#define SESSION_IS_TUNNLE_NON (0) /* default is 0, not tunnel; */ +#define SESSION_IS_TUNNLE_6OVER4 (1 << 0) +#define SESSION_IS_TUNNLE_4OVER6 (1 << 1) +#define SESSION_IS_TUNNLE_GRE (1 << 2) +#define SESSION_IS_TUNNLE_IP_IN_IP (1 << 3) +#define SESSION_IS_TUNNLE_PPTP (1 << 4) +#define SESSION_IS_TUNNLE_L2TP (1 << 5) +#define SESSION_IS_TUNNLE_TEREDO (1 << 6) +#define SESSION_IS_TUNNLE_GTP (1 << 7) +#define SESSION_IS_TUNNLE_SOCKS (1 << 8) +#define SESSION_IS_TUNNLE_HTTP_PROXY (1 << 9) + +int session_is_outer_tunnel(struct session *sess, uint64_t *flag); + #define SESSION_DIRECTION_IN 0 #define SESSION_DIRECTION_OUT 1 int session_get_direction(const struct session *sess); diff --git a/src/adapter/adapter.c b/src/adapter/adapter.c index c0bc299..806f94e 100644 --- a/src/adapter/adapter.c +++ b/src/adapter/adapter.c @@ -307,16 +307,16 @@ int session_is_symmetric(const struct session *sess, unsigned char *flag) int is_symmetric=0; if(sess->cur_pkt && sess->cur_pkt->a_stream) { - if(sess->cur_pkt->a_stream->dir==DIR_DOUBLE) + if(sess->cur_pkt->a_stream->dir==DIR_DOUBLE && flag) { *flag=(SESSION_SEEN_C2S_FLOW|SESSION_SEEN_S2C_FLOW); is_symmetric=1; } - else if(sess->cur_pkt->a_stream->dir==DIR_C2S) + else if(sess->cur_pkt->a_stream->dir==DIR_C2S && flag) { *flag=SESSION_SEEN_C2S_FLOW; } - else if(sess->cur_pkt->a_stream->dir==DIR_S2C) + else if(sess->cur_pkt->a_stream->dir==DIR_S2C && flag) { *flag=SESSION_SEEN_S2C_FLOW; } @@ -324,6 +324,46 @@ int session_is_symmetric(const struct session *sess, unsigned char *flag) return is_symmetric; } +int session_is_outer_tunnel(struct session *sess, uint64_t *flag) +{ + if(sess==NULL||sess->cur_pkt==NULL||sess->cur_pkt->a_stream==NULL) + { + return 0; + } + struct streaminfo *t_stream = sess->cur_pkt->a_stream->pfather; + struct streaminfo *a_stream = sess->cur_pkt->a_stream; + if(flag)*flag=SESSION_IS_TUNNLE_NON; + + int ret=0; + unsigned short tunnel_type=0; + int tunnel_type_len=sizeof(unsigned short); + ret=MESA_get_stream_opt(a_stream, MSO_STREAM_UP_LAYER_TUNNEL_TYPE, (void *)&tunnel_type, &tunnel_type_len); + if(ret==0) + { + if(tunnel_type!=STREAM_TUNNLE_NON) + { + if(flag)*flag=(uint64_t)tunnel_type; + return 1; + } + } + + while (t_stream != NULL) + { + if (t_stream->type == STREAM_TYPE_HTTP_PROXY) + { + if(flag) (*flag)|= (uint64_t)SESSION_IS_TUNNLE_HTTP_PROXY; + return 1; + } + if(t_stream->type == STREAM_TYPE_SOCKS4 || t_stream->type == STREAM_TYPE_SOCKS5) + { + if(flag) (*flag)|= (uint64_t)SESSION_IS_TUNNLE_SOCKS; + return 1; + } + t_stream = t_stream->pfather; + } + return 0; +} + int stellar_get_worker_thread_num(struct stellar *st) { return get_thread_count(); |
