rename session_direction to flow_direction
This commit is contained in:
@@ -155,7 +155,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_and_ack(const struct session *sess, enum session_direction inj_dir, uint32_t *seq, uint32_t *ack)
|
||||
static inline void calc_tcp_seq_and_ack(const struct session *sess, enum flow_direction inject_dir, uint32_t *seq, uint32_t *ack)
|
||||
{
|
||||
/*
|
||||
* +--------+ current packet +---------+ C2S RST +--------+
|
||||
@@ -175,9 +175,9 @@ static inline void calc_tcp_seq_and_ack(const struct session *sess, enum session
|
||||
* ack = current_packet_seq + current_packet_payload_len
|
||||
*/
|
||||
|
||||
enum session_direction curr_dir = session_get_current_direction(sess);
|
||||
enum flow_direction curr_dir = session_get_flow_direction(sess);
|
||||
const struct tcp_half *tcp_curr_half = &sess->tcp_halfs[curr_dir];
|
||||
if (inj_dir == curr_dir)
|
||||
if (inject_dir == curr_dir)
|
||||
{
|
||||
*seq = tcp_curr_half->seq;
|
||||
*ack = tcp_curr_half->ack;
|
||||
@@ -213,8 +213,8 @@ struct fingerprint
|
||||
};
|
||||
|
||||
// return packet length
|
||||
int build_tcp_packet(const struct packet *first, const struct fingerprint *finger,
|
||||
uint32_t tcp_seq, uint32_t tcp_ack, uint8_t tcp_flags, char *tcp_pld, int pld_len, char *pkt_buff, int buff_size)
|
||||
static int build_tcp_packet(const struct packet *first, const struct fingerprint *finger,
|
||||
uint32_t tcp_seq, uint32_t tcp_ack, uint8_t tcp_flags, char *tcp_pld, int pld_len, char *pkt_buff, int buff_size)
|
||||
{
|
||||
int trim = 0;
|
||||
struct tcphdr *tcphdr;
|
||||
@@ -224,7 +224,7 @@ int build_tcp_packet(const struct packet *first, const struct fingerprint *finge
|
||||
struct packet_layer *curr;
|
||||
struct packet_layer *last;
|
||||
int len = packet_get_len(first);
|
||||
int8_t layers = packet_get_layers(first);
|
||||
int8_t layers = packet_get_layers_number(first);
|
||||
|
||||
if ((tcp_pld == NULL && pld_len > 0) || (tcp_pld != NULL && pld_len <= 0))
|
||||
{
|
||||
@@ -302,50 +302,44 @@ int build_tcp_packet(const struct packet *first, const struct fingerprint *finge
|
||||
}
|
||||
|
||||
// return 0: success, -1: failed
|
||||
|
||||
int stellar_inject_icmp_unreach(const struct session *sess, enum session_direction inj_dir, uint16_t thr_idx)
|
||||
int stellar_inject_tcp_flags(const struct session *sess, enum flow_direction inject_dir, uint8_t flags)
|
||||
{
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
uint16_t thr_idx = stellar_get_current_thread_index();
|
||||
|
||||
int stellar_inject_tcp_rst(const struct session *sess, enum session_direction inj_dir, uint16_t thr_idx)
|
||||
{
|
||||
if (session_get_type(sess) != SESSION_TYPE_TCP)
|
||||
{
|
||||
session_inc_stat((struct session *)sess, inj_dir, STAT_INJ_PKTS_FAIL, 1);
|
||||
session_inc_stat((struct session *)sess, inject_dir, STAT_INJ_PKTS_FAIL, 1);
|
||||
INJECT_PACKET_LOG_ERROR("session %ld is not a TCP session, cannot inject TCP RST", session_get_id(sess));
|
||||
return -1;
|
||||
}
|
||||
|
||||
const struct packet *pkt = session_get_1st_packet(sess, inj_dir);
|
||||
const struct packet *pkt = session_get_first_packet(sess, inject_dir);
|
||||
if (pkt == NULL)
|
||||
{
|
||||
session_inc_stat((struct session *)sess, inj_dir, STAT_INJ_PKTS_FAIL, 1);
|
||||
INJECT_PACKET_LOG_ERROR("session %ld has no %s first packet, cannot inject TCP RST", session_get_id(sess), session_direction_to_str(inj_dir));
|
||||
session_inc_stat((struct session *)sess, inject_dir, STAT_INJ_PKTS_FAIL, 1);
|
||||
INJECT_PACKET_LOG_ERROR("session %ld has no %s first packet, cannot inject TCP RST", session_get_id(sess), flow_direction_to_str(inject_dir));
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct fingerprint finger = {0};
|
||||
uint32_t tcp_seq = 0;
|
||||
uint32_t tcp_ack = 0;
|
||||
uint8_t tcp_flags = TH_RST | TH_ACK;
|
||||
char buff[4096] = {0};
|
||||
calc_tcp_seq_and_ack(sess, inj_dir, &tcp_seq, &tcp_ack);
|
||||
calc_tcp_seq_and_ack(sess, inject_dir, &tcp_seq, &tcp_ack);
|
||||
calc_ipid_ttl_win(&finger.ipid, &finger.ttl, &finger.win);
|
||||
|
||||
int len = build_tcp_packet(pkt, &finger, tcp_seq, tcp_ack, tcp_flags, NULL, 0, buff, sizeof(buff));
|
||||
int len = build_tcp_packet(pkt, &finger, tcp_seq, tcp_ack, flags, NULL, 0, buff, sizeof(buff));
|
||||
if (len <= 0)
|
||||
{
|
||||
INJECT_PACKET_LOG_ERROR("session %ld build TCP %s RST packet failed, %s", session_get_id(sess), session_direction_to_str(inj_dir), strerror(len));
|
||||
session_inc_stat((struct session *)sess, inj_dir, STAT_INJ_PKTS_FAIL, 1);
|
||||
INJECT_PACKET_LOG_ERROR("session %ld build TCP %s RST packet failed, %s", session_get_id(sess), flow_direction_to_str(inject_dir), strerror(len));
|
||||
session_inc_stat((struct session *)sess, inject_dir, STAT_INJ_PKTS_FAIL, 1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct inject_packet_meta meta = {0};
|
||||
meta.session_id = session_get_id(sess);
|
||||
session_get_route_ctx(sess, inj_dir, &meta.route);
|
||||
session_get_sid_list(sess, inj_dir, &meta.sids);
|
||||
session_get_route_ctx(sess, inject_dir, &meta.route);
|
||||
session_get_sid_list(sess, inject_dir, &meta.sids);
|
||||
|
||||
struct packet inj_pkt;
|
||||
packet_parse(&inj_pkt, buff, len);
|
||||
@@ -353,37 +347,25 @@ int stellar_inject_tcp_rst(const struct session *sess, enum session_direction in
|
||||
packet_set_origin_ctx(&inj_pkt, &meta);
|
||||
if (packet_io_inject(runtime->packet_io, thr_idx, &inj_pkt, 1) == 1)
|
||||
{
|
||||
session_inc_stat((struct session *)sess, inj_dir, STAT_INJ_PKTS_SUSS, 1);
|
||||
session_inc_stat((struct session *)sess, inj_dir, STAT_INJ_BYTES_SUSS, len);
|
||||
session_inc_stat((struct session *)sess, inject_dir, STAT_INJ_PKTS_SUSS, 1);
|
||||
session_inc_stat((struct session *)sess, inject_dir, STAT_INJ_BYTES_SUSS, len);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
INJECT_PACKET_LOG_ERROR("session %ld inject TCP %s RST packet failed, packet I/O nospace", session_get_id(sess), session_direction_to_str(inj_dir));
|
||||
session_inc_stat((struct session *)sess, inj_dir, STAT_INJ_PKTS_FAIL, 1);
|
||||
INJECT_PACKET_LOG_ERROR("session %ld inject TCP %s RST packet failed, packet I/O nospace", session_get_id(sess), flow_direction_to_str(inject_dir));
|
||||
session_inc_stat((struct session *)sess, inject_dir, STAT_INJ_PKTS_FAIL, 1);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int stellar_inject_tcp_payload(const struct session *sess, enum session_direction inj_dir, uint16_t thr_idx, const char *payload, uint16_t len)
|
||||
int stellar_inject_payload(const struct session *sess, enum flow_direction inject_dir, const char *payload, uint16_t len)
|
||||
{
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
int stellar_inject_udp_payload(const struct session *sess, enum session_direction inj_dir, uint16_t thr_idx, const char *payload, uint16_t len)
|
||||
{
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
int stellar_inject_ctrl_msg(const struct session *sess, uint16_t *sids, int nr_sid, uint16_t thr_idx, const char *msg, uint16_t len)
|
||||
{
|
||||
// TODO
|
||||
return -1;
|
||||
}
|
||||
|
||||
int stellar_inject_stateless_pkt(uint16_t link_id, uint16_t thr_idx, const char *packet, uint16_t len)
|
||||
int stellar_inject_ctrl_msg(const struct session *sess, const struct sid_list *sids, const char *msg, uint16_t len)
|
||||
{
|
||||
// TODO
|
||||
return -1;
|
||||
|
||||
Reference in New Issue
Block a user