Commit 055e2825 authored by Alessandro Rubini's avatar Alessandro Rubini

general: refuse to process our own frames

This is accomplished by making msg_unpack_header return an error code
(and by warning users who ignore it).  We *really* don't need our
own frames back -- even if they come from a different port.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 1063b42b
......@@ -16,16 +16,19 @@
int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
{
struct pp_state_table_item *ip;
int state, err;
int state, err = 0;
if (plen > 0)
if (plen && plen < PP_HEADER_LENGTH)
err = -1;
if (plen >= PP_HEADER_LENGTH) {
PP_VPRINTF("RECV %02d %d.%09d %s\n", plen,
(int)ppi->last_rcv_time.seconds,
(int)ppi->last_rcv_time.nanoseconds,
pp_msg_names[packet[0] & 0x0f]);
if (packet)
msg_unpack_header(ppi, packet);
err = msg_unpack_header(ppi, packet);
}
if (err)
return ppi->next_delay;
state = ppi->state;
......
......@@ -195,7 +195,6 @@ struct pp_instance {
MsgHeader msg_tmp_header;
MsgHeader delay_req_hdr;
UInteger32
is_from_self:1,
is_from_cur_par:1,
waiting_for_follow:1;
};
......@@ -346,7 +345,8 @@ extern UInteger8 bmc(struct pp_instance *ppi,
/* msg.c */
extern void msg_pack_header(struct pp_instance *ppi, void *buf);
extern void msg_unpack_header(struct pp_instance *ppi, void *buf);
extern int __attribute__((warn_unused_result))
msg_unpack_header(struct pp_instance *ppi, void *buf);
void *msg_copy_header(MsgHeader *dest, MsgHeader *src);
extern void msg_pack_sync(struct pp_instance *ppi, Timestamp *orig_tstamp);
extern void msg_unpack_sync(void *buf, MsgSync *sync);
......
......@@ -149,9 +149,6 @@ int st_com_slave_handle_announce(struct pp_instance *ppi, unsigned char *buf,
if (len < PP_ANNOUNCE_LENGTH)
return -1;
if (ppi->is_from_self)
return 0;
/*
* Valid announce message is received : BMC algorithm
* will be executed
......@@ -186,9 +183,6 @@ int st_com_slave_handle_sync(struct pp_instance *ppi, unsigned char *buf,
if (len < PP_SYNC_LENGTH)
return -1;
if (ppi->is_from_self)
return 0;
time = &ppi->last_rcv_time;
if (ppi->is_from_cur_par) {
......@@ -298,11 +292,6 @@ int st_com_master_handle_announce(struct pp_instance *ppi, unsigned char *buf,
if (len < PP_ANNOUNCE_LENGTH)
return -1;
if (ppi->is_from_self) {
PP_VPRINTF("master handle_announce: ignore msg from self\n");
return 0;
}
PP_VPRINTF("Announce message from another foreign master\n");
st_com_add_foreign(ppi, buf);
......
......@@ -81,7 +81,7 @@ static void msg_display_announce(MsgAnnounce *announce)
}
/* Unpack header from in buffer to msg_tmp_header field */
void msg_unpack_header(struct pp_instance *ppi, void *buf)
int msg_unpack_header(struct pp_instance *ppi, void *buf)
{
MsgHeader *hdr = &ppi->msg_tmp_header;
......@@ -107,14 +107,17 @@ void msg_unpack_header(struct pp_instance *ppi, void *buf)
hdr->controlField = (*(UInteger8 *) (buf + 32));
hdr->logMessageInterval = (*(Integer8 *) (buf + 33));
if (DSPOR(ppi)->portIdentity.portNumber ==
ppi->msg_tmp_header.sourcePortIdentity.portNumber
&& !memcmp(ppi->msg_tmp_header.sourcePortIdentity.clockIdentity,
/*
* If the message is from us, we should discard it.
* The best way to do that is comparing the mac address,
* but it's easier to check the clock identity (we refuse
* any port, not only the same port, as we can't sync with
* ourself even when we'll run in multi-port mode.
*/
if (!memcmp(ppi->msg_tmp_header.sourcePortIdentity.clockIdentity,
DSPOR(ppi)->portIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH))
ppi->is_from_self = 1;
else
ppi->is_from_self = 0;
PP_CLOCK_IDENTITY_LENGTH))
return -1;
if (!memcmp(DSPAR(ppi)->parentPortIdentity.clockIdentity,
hdr->sourcePortIdentity.clockIdentity,
......@@ -126,6 +129,7 @@ void msg_unpack_header(struct pp_instance *ppi, void *buf)
ppi->is_from_cur_par = 0;
msg_display_header(hdr);
return 0;
}
/* Pack header message into out buffer of ppi */
......
......@@ -55,13 +55,7 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
break;
case PPM_DELAY_REQ:
e = (plen < PP_DELAY_REQ_LENGTH);
if (!e && ppi->is_from_self) {
/* No more used: delay_req_send_time was taken
* when sending it */
}
/* Being slave, we are not waiting for a delay request */
break;
case PPM_DELAY_RESP:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment