Skip to content
Snippets Groups Projects
Commit 24614d0a authored by Julian Cordes's avatar Julian Cordes
Browse files

refactored handle_listen_for_script_packet method

parent 63d1d061
No related branches found
No related tags found
No related merge requests found
...@@ -209,6 +209,39 @@ static struct socket *setup_new_child_socket(struct state *state, const struct p ...@@ -209,6 +209,39 @@ static struct socket *setup_new_child_socket(struct state *state, const struct p
return socket; return socket;
} }
static inline bool sctp_is_init_packet(const struct packet *packet) {
struct sctp_chunk_list_item *item;
if (packet->chunk_list != NULL) {
item = packet->chunk_list->first;
if ((item != NULL) &&
(item->chunk->type == SCTP_INIT_CHUNK_TYPE)) {
return true;
}
} else {
if (packet->flags & FLAGS_SCTP_GENERIC_PACKET) {
u8 *sctp_chunk_start = (u8 *) (packet->sctp + 1);
if ((sctp_chunk_start != NULL) &&
(sctp_chunk_start[0] == SCTP_INIT_CHUNK_TYPE)) {
return true;
}
}
}
return false;
}
static inline void sctp_socket_set_initiate_tag(struct socket *socket, u32 initiate_tag) {
socket->script.remote_initiate_tag = initiate_tag;
socket->live.remote_initiate_tag = initiate_tag;
}
static inline void sctp_socket_set_initial_tsn(struct socket *socket, u32 initial_tsn) {
socket->script.remote_initial_tsn = initial_tsn;
socket->live.remote_initial_tsn = initial_tsn;
}
/* See if the socket under test is listening and is willing to receive /* See if the socket under test is listening and is willing to receive
* this incoming SYN packet. If so, create a new child socket, anoint * this incoming SYN packet. If so, create a new child socket, anoint
* it as the new socket under test, and return a pointer to * it as the new socket under test, and return a pointer to
...@@ -226,7 +259,6 @@ static struct socket *handle_listen_for_script_packet( ...@@ -226,7 +259,6 @@ static struct socket *handle_listen_for_script_packet(
*/ */
struct config *config = state->config; struct config *config = state->config;
struct socket *socket = state->socket_under_test; /* shortcut */ struct socket *socket = state->socket_under_test; /* shortcut */
u32 initiate_tag, initial_tsn;
struct sctp_chunk_list_item *item; struct sctp_chunk_list_item *item;
bool match = (direction == DIRECTION_INBOUND); bool match = (direction == DIRECTION_INBOUND);
...@@ -250,18 +282,16 @@ static struct socket *handle_listen_for_script_packet( ...@@ -250,18 +282,16 @@ static struct socket *handle_listen_for_script_packet(
socket = setup_new_child_socket(state, packet); socket = setup_new_child_socket(state, packet);
if (packet->sctp != NULL) { if (packet->sctp != NULL) {
if (packet->chunk_list != NULL) { if (sctp_is_init_packet(packet)) {
item = packet->chunk_list->first; if (packet->chunk_list != NULL) {
if ((item != NULL) && struct sctp_init_chunk *init;
(item->chunk->type == SCTP_INIT_CHUNK_TYPE)) { item = packet->chunk_list->first;
struct sctp_init_chunk *init = (struct sctp_init_chunk *)item->chunk; init = (struct sctp_init_chunk *) item->chunk;
initiate_tag = ntohl(init->initiate_tag);
initial_tsn = ntohl(init->initial_tsn); sctp_socket_set_initiate_tag(socket, ntohl(init->initiate_tag));
} else { sctp_socket_set_initial_tsn(socket, ntohl(init->initial_tsn));
return socket;
} }
} else { else {
if (packet->flags & FLAGS_SCTP_GENERIC_PACKET) {
struct header sctp_header; struct header sctp_header;
unsigned int i; unsigned int i;
bool found = false; bool found = false;
...@@ -284,30 +314,19 @@ static struct socket *handle_listen_for_script_packet( ...@@ -284,30 +314,19 @@ static struct socket *handle_listen_for_script_packet(
} }
u8 *sctp_chunk_start = (u8 *) (packet->sctp + 1); u8 *sctp_chunk_start = (u8 *) (packet->sctp + 1);
if (sctp_chunk_start[0] == SCTP_INIT_CHUNK_TYPE) { struct sctp_init_chunk *init = (struct sctp_init_chunk *) sctp_chunk_start;
struct sctp_init_chunk *init = (struct sctp_init_chunk *) sctp_chunk_start;
initiate_tag = ntohl(init->initiate_tag); sctp_socket_set_initiate_tag(socket, ntohl(init->initiate_tag));
initial_tsn = ntohl(init->initial_tsn); sctp_socket_set_initial_tsn(socket, ntohl(init->initial_tsn));
} else {
return socket;
}
} else {
return socket;
} }
} else {
return socket;
} }
} else {
DEBUGP("packet->sctp == NULL");
} }
if (packet->tcp != NULL) { if (packet->tcp != NULL) {
socket->script.remote_isn = ntohl(packet->tcp->seq); socket->script.remote_isn = ntohl(packet->tcp->seq);
socket->live.remote_isn = ntohl(packet->tcp->seq); socket->live.remote_isn = ntohl(packet->tcp->seq);
} else {
socket->script.remote_initiate_tag = initiate_tag;
socket->script.remote_initial_tsn = initial_tsn;
socket->live.remote_initiate_tag = initiate_tag;
socket->live.remote_initial_tsn = initial_tsn;
} }
if (DEBUG_LOGGING) { if (DEBUG_LOGGING) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment