Reduce packet_get_xxx() calls
This commit is contained in:
@@ -9,6 +9,8 @@
|
||||
#include "session_queue.h"
|
||||
#include "session_private.h"
|
||||
#include "packet_helpers.h"
|
||||
#include "tcp_helpers.h"
|
||||
#include "udp_helpers.h"
|
||||
|
||||
struct session_manager
|
||||
{
|
||||
@@ -291,8 +293,11 @@ static void update_session_base(struct session *sess, const struct packet *pkt,
|
||||
|
||||
static void update_tcp_ex_data(struct session *sess, const struct packet *pkt, enum session_dir curr_dir)
|
||||
{
|
||||
const struct layer_record *tcp_layer = packet_get_innermost_layer(pkt, LAYER_TYPE_TCP);
|
||||
const struct tcphdr *hdr = (const struct tcphdr *)tcp_layer->hdr_ptr;
|
||||
|
||||
uint64_t state = (uint64_t)session_get0_ex_data(sess, tcp_builtin_ex);
|
||||
if (packet_has_tcp_flag_rst(pkt))
|
||||
if (tcp_hdr_has_flag_rst(hdr))
|
||||
{
|
||||
if (curr_dir == SESSION_DIR_C2S)
|
||||
{
|
||||
@@ -306,7 +311,7 @@ static void update_tcp_ex_data(struct session *sess, const struct packet *pkt, e
|
||||
}
|
||||
}
|
||||
|
||||
if (packet_has_tcp_flag_fin(pkt))
|
||||
if (tcp_hdr_has_flag_fin(hdr))
|
||||
{
|
||||
if (curr_dir == SESSION_DIR_C2S)
|
||||
{
|
||||
@@ -320,9 +325,9 @@ static void update_tcp_ex_data(struct session *sess, const struct packet *pkt, e
|
||||
}
|
||||
}
|
||||
|
||||
if (packet_has_tcp_flag_syn(pkt))
|
||||
if (tcp_hdr_has_flag_syn(hdr))
|
||||
{
|
||||
if (packet_has_tcp_flag_ack(pkt))
|
||||
if (tcp_hdr_has_flag_ack(hdr))
|
||||
{
|
||||
state |= TCP_SYNACK_RECVED;
|
||||
session_set_ex_data(sess, tcp_builtin_ex, (void *)(state));
|
||||
@@ -334,7 +339,7 @@ static void update_tcp_ex_data(struct session *sess, const struct packet *pkt, e
|
||||
}
|
||||
}
|
||||
|
||||
if (packet_get_tcp_pld_len(pkt) > 0)
|
||||
if (tcp_layer->pld_len > 0)
|
||||
{
|
||||
if (curr_dir == SESSION_DIR_C2S)
|
||||
{
|
||||
@@ -370,7 +375,8 @@ static void update_udp_ex_data(struct session *sess, const struct packet *pkt, e
|
||||
// return -1: tcp not syn packet, discard
|
||||
static int handle_tcp_new_session(struct session_manager *mgr, struct tuple6 *key, struct session *sess, const struct packet *pkt)
|
||||
{
|
||||
if (!packet_has_tcp_flag_syn(pkt))
|
||||
const struct tcphdr *hdr = (const struct tcphdr *)packet_get_tcp_hdr_ptr(pkt);
|
||||
if (!tcp_hdr_has_flag_syn(hdr))
|
||||
{
|
||||
// not syn packet, discard
|
||||
return -1;
|
||||
@@ -380,7 +386,7 @@ static int handle_tcp_new_session(struct session_manager *mgr, struct tuple6 *ke
|
||||
|
||||
session_init(sess);
|
||||
// syn packet
|
||||
if (!packet_has_tcp_flag_ack(pkt))
|
||||
if (!tcp_hdr_has_flag_ack(hdr))
|
||||
{
|
||||
curr_dir = SESSION_DIR_C2S;
|
||||
session_set_ex_data(sess, tcp_builtin_ex, (void *)TCP_SYN_RECVED);
|
||||
@@ -483,7 +489,7 @@ static void handle_udp_old_session(struct session_manager *mgr, struct tuple6 *k
|
||||
// return -1: tcp not syn packet, discard
|
||||
static int handle_new_session(struct session_manager *mgr, struct tuple6 *key, struct session *sess, const struct packet *pkt)
|
||||
{
|
||||
if (packet_has_tcp(pkt))
|
||||
if (key->ip_proto == IPPROTO_TCP)
|
||||
{
|
||||
return handle_tcp_new_session(mgr, key, sess, pkt);
|
||||
}
|
||||
@@ -500,7 +506,7 @@ static void handle_old_session(struct session_manager *mgr, struct tuple6 *key,
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet_has_tcp(pkt))
|
||||
if (key->ip_proto == IPPROTO_TCP)
|
||||
{
|
||||
handle_tcp_old_session(mgr, key, sess, pkt);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user