Add test case: inject IPv4 based (TCP payload & TCP FIN & TCP RST) packet after recv C2S first payload
This commit is contained in:
@@ -165,7 +165,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, uint16_t len)
|
||||
static inline void calc_tcp_seq_ack(const struct session *sess, enum flow_direction inject_dir, uint32_t *seq, uint32_t *ack, uint8_t flags, uint16_t len)
|
||||
{
|
||||
/*
|
||||
* +--------+ current packet +---------+ C2S RST +--------+
|
||||
@@ -196,6 +196,8 @@ static inline void calc_tcp_seq_ack(const struct session *sess, enum flow_direct
|
||||
*ack = tcp_curr_half->ack;
|
||||
|
||||
tcp_curr_half->inject_inc_seq_offset += len;
|
||||
// inject RST packer after FIN packer, seq should be increased by 1
|
||||
tcp_curr_half->inject_inc_seq_offset += (flags & TH_FIN) ? 1 : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -203,6 +205,8 @@ static inline void calc_tcp_seq_ack(const struct session *sess, enum flow_direct
|
||||
*ack = uint32_add(tcp_curr_half->seq, tcp_curr_half->len + (tcp_curr_half->flags & TH_SYN ? 1 : 0));
|
||||
|
||||
tcp_curr_half->inject_inc_ack_offset += len;
|
||||
// inject RST packer after FIN packer, ack should be increased by 1
|
||||
tcp_curr_half->inject_inc_ack_offset += (flags & TH_FIN) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -416,7 +420,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, len);
|
||||
calc_tcp_seq_ack(sess, inject_dir, &tcp_seq, &tcp_ack, tcp_flags, 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));
|
||||
|
||||
Reference in New Issue
Block a user