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 @@ ...@@ -16,16 +16,19 @@
int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen) int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
{ {
struct pp_state_table_item *ip; 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, PP_VPRINTF("RECV %02d %d.%09d %s\n", plen,
(int)ppi->last_rcv_time.seconds, (int)ppi->last_rcv_time.seconds,
(int)ppi->last_rcv_time.nanoseconds, (int)ppi->last_rcv_time.nanoseconds,
pp_msg_names[packet[0] & 0x0f]); pp_msg_names[packet[0] & 0x0f]);
err = msg_unpack_header(ppi, packet);
if (packet) }
msg_unpack_header(ppi, packet); if (err)
return ppi->next_delay;
state = ppi->state; state = ppi->state;
......
...@@ -195,7 +195,6 @@ struct pp_instance { ...@@ -195,7 +195,6 @@ struct pp_instance {
MsgHeader msg_tmp_header; MsgHeader msg_tmp_header;
MsgHeader delay_req_hdr; MsgHeader delay_req_hdr;
UInteger32 UInteger32
is_from_self:1,
is_from_cur_par:1, is_from_cur_par:1,
waiting_for_follow:1; waiting_for_follow:1;
}; };
...@@ -346,7 +345,8 @@ extern UInteger8 bmc(struct pp_instance *ppi, ...@@ -346,7 +345,8 @@ extern UInteger8 bmc(struct pp_instance *ppi,
/* msg.c */ /* msg.c */
extern void msg_pack_header(struct pp_instance *ppi, void *buf); 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); void *msg_copy_header(MsgHeader *dest, MsgHeader *src);
extern void msg_pack_sync(struct pp_instance *ppi, Timestamp *orig_tstamp); extern void msg_pack_sync(struct pp_instance *ppi, Timestamp *orig_tstamp);
extern void msg_unpack_sync(void *buf, MsgSync *sync); 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, ...@@ -149,9 +149,6 @@ int st_com_slave_handle_announce(struct pp_instance *ppi, unsigned char *buf,
if (len < PP_ANNOUNCE_LENGTH) if (len < PP_ANNOUNCE_LENGTH)
return -1; return -1;
if (ppi->is_from_self)
return 0;
/* /*
* Valid announce message is received : BMC algorithm * Valid announce message is received : BMC algorithm
* will be executed * will be executed
...@@ -186,9 +183,6 @@ int st_com_slave_handle_sync(struct pp_instance *ppi, unsigned char *buf, ...@@ -186,9 +183,6 @@ int st_com_slave_handle_sync(struct pp_instance *ppi, unsigned char *buf,
if (len < PP_SYNC_LENGTH) if (len < PP_SYNC_LENGTH)
return -1; return -1;
if (ppi->is_from_self)
return 0;
time = &ppi->last_rcv_time; time = &ppi->last_rcv_time;
if (ppi->is_from_cur_par) { if (ppi->is_from_cur_par) {
...@@ -298,11 +292,6 @@ int st_com_master_handle_announce(struct pp_instance *ppi, unsigned char *buf, ...@@ -298,11 +292,6 @@ int st_com_master_handle_announce(struct pp_instance *ppi, unsigned char *buf,
if (len < PP_ANNOUNCE_LENGTH) if (len < PP_ANNOUNCE_LENGTH)
return -1; 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"); PP_VPRINTF("Announce message from another foreign master\n");
st_com_add_foreign(ppi, buf); st_com_add_foreign(ppi, buf);
......
...@@ -81,7 +81,7 @@ static void msg_display_announce(MsgAnnounce *announce) ...@@ -81,7 +81,7 @@ static void msg_display_announce(MsgAnnounce *announce)
} }
/* Unpack header from in buffer to msg_tmp_header field */ /* 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; MsgHeader *hdr = &ppi->msg_tmp_header;
...@@ -107,14 +107,17 @@ void msg_unpack_header(struct pp_instance *ppi, void *buf) ...@@ -107,14 +107,17 @@ void msg_unpack_header(struct pp_instance *ppi, void *buf)
hdr->controlField = (*(UInteger8 *) (buf + 32)); hdr->controlField = (*(UInteger8 *) (buf + 32));
hdr->logMessageInterval = (*(Integer8 *) (buf + 33)); hdr->logMessageInterval = (*(Integer8 *) (buf + 33));
if (DSPOR(ppi)->portIdentity.portNumber == /*
ppi->msg_tmp_header.sourcePortIdentity.portNumber * If the message is from us, we should discard it.
&& !memcmp(ppi->msg_tmp_header.sourcePortIdentity.clockIdentity, * 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, DSPOR(ppi)->portIdentity.clockIdentity,
PP_CLOCK_IDENTITY_LENGTH)) PP_CLOCK_IDENTITY_LENGTH))
ppi->is_from_self = 1; return -1;
else
ppi->is_from_self = 0;
if (!memcmp(DSPAR(ppi)->parentPortIdentity.clockIdentity, if (!memcmp(DSPAR(ppi)->parentPortIdentity.clockIdentity,
hdr->sourcePortIdentity.clockIdentity, hdr->sourcePortIdentity.clockIdentity,
...@@ -126,6 +129,7 @@ void msg_unpack_header(struct pp_instance *ppi, void *buf) ...@@ -126,6 +129,7 @@ void msg_unpack_header(struct pp_instance *ppi, void *buf)
ppi->is_from_cur_par = 0; ppi->is_from_cur_par = 0;
msg_display_header(hdr); msg_display_header(hdr);
return 0;
} }
/* Pack header message into out buffer of ppi */ /* Pack header message into out buffer of ppi */
......
...@@ -55,13 +55,7 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -55,13 +55,7 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
break; break;
case PPM_DELAY_REQ: case PPM_DELAY_REQ:
/* Being slave, we are not waiting for a delay request */
e = (plen < PP_DELAY_REQ_LENGTH);
if (!e && ppi->is_from_self) {
/* No more used: delay_req_send_time was taken
* when sending it */
}
break; break;
case PPM_DELAY_RESP: 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