Skip to content

Commit

Permalink
usnic: add some cagent verification checks
Browse files Browse the repository at this point in the history
Add primitive magic number and version checking in the connectivity
checker protocol.  These checks doesn't *guarantee* to we won't get
false PINGs and ACKs, but they do significantly reduce the possibility
of interpretating random incoming fragments as PINGs or ACKs.
  • Loading branch information
jsquyres committed Mar 9, 2016
1 parent c98e97a commit 9771471
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions opal/mca/btl/usnic/btl_usnic_cagent.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ typedef enum {
AGENT_MSG_TYPE_ACK
} agent_udp_message_type_t;

// Arbitrary 64 bit numbers
#define MAGIC_ORIGINATOR 0x9a9e2fbce63a11e5
#define MAGIC_TARGET 0x60735c68f368aace

/*
* Ping and ACK messages
*/
Expand All @@ -110,6 +114,11 @@ typedef struct {
uint32_t src_ipv4_addr;
uint32_t src_udp_port;

/* A magic number that helps determine that the sender was Open
MPI */
uint64_t magic_number;
uint32_t major_version, minor_version;

/* If this is a PING, the message should be this size.
If this is an ACK, we are ACKing a ping of this size. */
uint32_t size;
Expand Down Expand Up @@ -369,6 +378,21 @@ static void agent_thread_handle_ping(agent_udp_port_listener_t *listener,
return;
}

if (msg->magic_number != MAGIC_ORIGINATOR) {
opal_output_verbose(20, USNIC_OUT,
"usNIC connectivity got bad ping (magic number: %" PRIu64 ", discarded)",
msg->magic_number);
return;
}
if (msg->major_version != OPAL_MAJOR_VERSION ||
msg->minor_version != OPAL_MINOR_VERSION) {
opal_output_verbose(20, USNIC_OUT,
"usNIC connectivity got bad ping (originator version: %d.%d, expected %d.%d, discarded)",
msg->major_version, msg->minor_version,
OPAL_MAJOR_VERSION, OPAL_MINOR_VERSION);
return;
}

/* Ok, this is a good ping. Send the ACK back. The PING sender
will verify that the ACK came back from the IP address that it
expected. */
Expand All @@ -383,6 +407,7 @@ static void agent_thread_handle_ping(agent_udp_port_listener_t *listener,
in the msg (the sender will use the msg fields and the
recvfrom() src_addr to check for a match). */
msg->message_type = AGENT_MSG_TYPE_ACK;
msg->magic_number = MAGIC_TARGET;

agent_sendto(listener->fd, (char*) listener->buffer, sizeof(*msg), from);
}
Expand All @@ -406,6 +431,12 @@ static void agent_thread_handle_ack(agent_udp_port_listener_t *listener,
(int) numbytes, str, (int) sizeof(*msg));
return;
}
if (msg->magic_number != MAGIC_TARGET) {
opal_output_verbose(20, USNIC_OUT,
"usNIC connectivity got bad ACK (magic number: %" PRIu64 ", discarded)",
msg->magic_number);
return;
}

/* Find the pending ping request (on this interface) for this ACK.
If we don't find a match, we'll drop it. */
Expand Down Expand Up @@ -866,6 +897,9 @@ static void agent_thread_cmd_ping(agent_ipc_listener_t *ipc_listener)
msg->message_type = AGENT_MSG_TYPE_PING;
msg->src_ipv4_addr = ap->src_ipv4_addr;
msg->src_udp_port = ap->src_udp_port;
msg->magic_number = MAGIC_ORIGINATOR;
msg->major_version = OPAL_MAJOR_VERSION;
msg->minor_version = OPAL_MINOR_VERSION;
msg->size = ap->sizes[i];
}

Expand Down

0 comments on commit 9771471

Please sign in to comment.