support inject mutil packet base current packet

This commit is contained in:
luwenpeng
2024-05-17 19:10:28 +08:00
parent c22e4e5955
commit 31a4267e23
3 changed files with 16 additions and 7 deletions

View File

@@ -164,7 +164,7 @@ static void update_ip6_hdr(struct ip6_hdr *ip6hdr, int trim)
ipv6_hdr_set_payload_len(ip6hdr, len - trim);
}
static inline void calc_tcp_seq_ack(const struct session *sess, enum flow_direction inject_dir, uint32_t *seq, uint32_t *ack)
static inline void calc_tcp_seq_ack(const struct session *sess, enum flow_direction inject_dir, uint32_t *seq, uint32_t *ack, uint16_t len)
{
/*
* +--------+ current packet +---------+ C2S RST +--------+
@@ -188,16 +188,20 @@ static inline void calc_tcp_seq_ack(const struct session *sess, enum flow_direct
*/
enum flow_direction curr_dir = session_get_current_flow_direction(sess);
const struct tcp_half *tcp_curr_half = &sess->tcp_halfs[curr_dir];
struct tcp_half *tcp_curr_half = (struct tcp_half *)&sess->tcp_halfs[curr_dir];
if (inject_dir == curr_dir)
{
*seq = tcp_curr_half->seq;
*ack = tcp_curr_half->ack;
*seq = uint32_add(tcp_curr_half->seq, tcp_curr_half->inject_inc_seq_offset);
*ack = uint32_add(tcp_curr_half->ack, tcp_curr_half->inject_inc_ack_offset);
tcp_curr_half->inject_inc_seq_offset += len;
}
else
{
*seq = tcp_curr_half->ack;
*ack = tcp_curr_half->seq + tcp_curr_half->len + (tcp_curr_half->flags & TH_SYN ? 1 : 0);
*seq = uint32_add(tcp_curr_half->ack, tcp_curr_half->inject_inc_ack_offset);
*ack = uint32_add(tcp_curr_half->seq, tcp_curr_half->inject_inc_seq_offset + tcp_curr_half->len + (tcp_curr_half->flags & TH_SYN ? 1 : 0));
tcp_curr_half->inject_inc_ack_offset += len;
}
}
@@ -406,7 +410,7 @@ int inject_tcp_packet(const struct session *sess, enum flow_direction inject_dir
uint32_t tcp_seq = 0;
uint32_t tcp_ack = 0;
char buff[4096] = {0};
calc_tcp_seq_ack(sess, inject_dir, &tcp_seq, &tcp_ack);
calc_tcp_seq_ack(sess, inject_dir, &tcp_seq, &tcp_ack, len);
calc_tcp_fingerprint(&finger);
int pkt_len = build_tcp_packet(pkt, finger.ipid, finger.ttl, tcp_seq, tcp_ack, tcp_flags, finger.win, payload, len, buff, sizeof(buff));