mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
unify message validation across S2SS server and OPAL and GTFPGA PPC clients
This commit is contained in:
parent
b17bd51236
commit
8490d289fb
3 changed files with 27 additions and 9 deletions
|
@ -11,5 +11,15 @@
|
|||
|
||||
void msg_swap(struct msg *m);
|
||||
|
||||
/** Check the consistency of a message.
|
||||
*
|
||||
* The functions checks the header fields of a message.
|
||||
*
|
||||
* @param m A pointer to the message
|
||||
* @retval 0 The message header is valid.
|
||||
* @retval <0 The message header is invalid.
|
||||
*/
|
||||
int msg_verify(struct msg *m);
|
||||
|
||||
#endif /* _MSG_H_ */
|
||||
|
||||
|
|
|
@ -22,3 +22,16 @@ void msg_swap(struct msg *m)
|
|||
m->endian ^= 1;
|
||||
}
|
||||
|
||||
int msg_verify(struct msg *m)
|
||||
{
|
||||
if (m->version != MSG_VERSION)
|
||||
return -1;
|
||||
else if (m->type != MSG_TYPE_DATA)
|
||||
return -2;
|
||||
else if ((m->length <= 0) || (m->length > MSG_VALUES))
|
||||
return -3;
|
||||
else if ((m->rsvd1 != 0) || (m->rsvd2 != 0))
|
||||
return -4;
|
||||
else
|
||||
return 0;
|
||||
}
|
|
@ -187,15 +187,10 @@ static void *RecvFromIPPort(void *arg)
|
|||
/******* FORMAT TO SPECIFIC PROTOCOL HERE ******************************/
|
||||
n = RecvPacket((char *) &msg, sizeof(msg), 1.0);
|
||||
|
||||
/** @todo: Check and ntohs() sequence number! */
|
||||
|
||||
if (msg.version != MSG_VERSION) {
|
||||
OpalPrint("%s: Received message with unknown version. Skipping..\n", PROGNAME);
|
||||
continue;
|
||||
}
|
||||
else if (msg.type != MSG_TYPE_DATA) {
|
||||
OpalPrint("%s: Received no data. Skipping..\n", PROGNAME);
|
||||
continue;
|
||||
int ret = msg_verify(m);
|
||||
if (ret) {
|
||||
printf("Dropping invalid message (reason=%d)\r\n", ret);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/** @todo: We may check the sequence number here. */
|
||||
|
|
Loading…
Add table
Reference in a new issue