Skip to content

Commit

Permalink
Fix race condition in rxbufstat (OpenEtherCATsociety#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wanga authored and nakarlsson committed Aug 23, 2018
1 parent 2e165be commit 0a67e6b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 16 deletions.
11 changes: 8 additions & 3 deletions oshw/intime/nicdrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,15 +363,16 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber)
}
log_RT_event('S',(WORD)3);

(*stack->rxbufstat)[idx] = EC_BUF_TX;
status = hpeStartTransmitter(port->handle);
if (status != E_OK)
{
(*stack->rxbufstat)[idx] = EC_BUF_EMPTY;
result = -3;
goto end;
}

log_RT_event('S',(WORD)4);
(*stack->rxbufstat)[idx] = EC_BUF_TX;
result = lp;

end:
Expand Down Expand Up @@ -408,9 +409,13 @@ int ecx_outframe_red(ecx_portt *port, int idx)
//send(sockhandle2, &ec_txbuf2, ec_txbuflength2 , 0);
// OBS! redundant not ACTIVE for BFIN, just added to compile
//ASSERT (0);
hpeAttachTransmitBufferSet(port->redport->handle, port->tx_buffers[idx]);
status = hpeStartTransmitter(port->redport->handle);
hpeAttachTransmitBufferSet(port->redport->handle, port->tx_buffers[idx]);
port->redport->rxbufstat[idx] = EC_BUF_TX;
status = hpeStartTransmitter(port->redport->handle);
if (status != E_OK)
{
(*stack->rxbufstat)[idx] = EC_BUF_EMPTY;
}
}

return rval;
Expand Down
13 changes: 10 additions & 3 deletions oshw/linux/nicdrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,12 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber)
stack = &(port->redport->stack);
}
lp = (*stack->txbuflength)[idx];
rval = send(*stack->sock, (*stack->txbuf)[idx], lp, 0);
(*stack->rxbufstat)[idx] = EC_BUF_TX;
rval = send(*stack->sock, (*stack->txbuf)[idx], lp, 0);
if (rval == -1)
{
(*stack->rxbufstat)[idx] = EC_BUF_EMPTY;
}

return rval;
}
Expand Down Expand Up @@ -314,9 +318,12 @@ int ecx_outframe_red(ecx_portt *port, int idx)
/* rewrite MAC source address 1 to secondary */
ehp->sa1 = htons(secMAC[1]);
/* transmit over secondary socket */
send(port->redport->sockhandle, &(port->txbuf2), port->txbuflength2 , 0);
pthread_mutex_unlock( &(port->tx_mutex) );
port->redport->rxbufstat[idx] = EC_BUF_TX;
if (send(port->redport->sockhandle, &(port->txbuf2), port->txbuflength2 , 0) == -1)
{
port->redport->rxbufstat[idx] = EC_BUF_EMPTY;
}
pthread_mutex_unlock( &(port->tx_mutex) );
}

return rval;
Expand Down
13 changes: 10 additions & 3 deletions oshw/rtems/nicdrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,12 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber)
}
lp = (*stack->txbuflength)[idx];
//rval = send(*stack->sock, (*stack->txbuf)[idx], lp, 0);
rval = write (*stack->sock,(*stack->txbuf)[idx], lp);
(*stack->rxbufstat)[idx] = EC_BUF_TX;
rval = write (*stack->sock,(*stack->txbuf)[idx], lp);
if (rval == -1)
{
(*stack->rxbufstat)[idx] = EC_BUF_EMPTY;
}

return rval;
}
Expand Down Expand Up @@ -361,9 +365,12 @@ int ecx_outframe_red(ecx_portt *port, int idx)
ehp->sa1 = htons(secMAC[1]);
/* transmit over secondary socket */
//send(port->redport->sockhandle, &(port->txbuf2), port->txbuflength2 , 0);
write(port->redport->sockhandle, &(port->txbuf2), port->txbuflength2);
pthread_mutex_unlock( &(port->tx_mutex) );
port->redport->rxbufstat[idx] = EC_BUF_TX;
if (write(port->redport->sockhandle, &(port->txbuf2), port->txbuflength2) == -1)
{
(*stack->rxbufstat)[idx] = EC_BUF_EMPTY;
}
pthread_mutex_unlock( &(port->tx_mutex) );
}

return rval;
Expand Down
4 changes: 2 additions & 2 deletions oshw/rtk/nicdrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber)
stack = &(port->redport->stack);
}
lp = (*stack->txbuflength)[idx];
rval = bfin_EMAC_send((*stack->txbuf)[idx], lp);
(*stack->rxbufstat)[idx] = EC_BUF_TX;
rval = bfin_EMAC_send((*stack->txbuf)[idx], lp);

return rval;
}
Expand Down Expand Up @@ -298,9 +298,9 @@ int ecx_outframe_red(ecx_portt *port, int idx)
//send(sockhandle2, &ec_txbuf2, ec_txbuflength2 , 0);
// OBS! redundant not ACTIVE for BFIN, just added to compile
ASSERT (0);
port->redport->rxbufstat[idx] = EC_BUF_TX;
bfin_EMAC_send(&(port->txbuf2), port->txbuflength2);
mtx_unlock (port->tx_mutex);
port->redport->rxbufstat[idx] = EC_BUF_TX;
}

return rval;
Expand Down
12 changes: 10 additions & 2 deletions oshw/vxworks/nicdrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,17 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber)
pPktDev = &(port->redport->pktDev);
}

(*stack->rxbufstat)[idx] = EC_BUF_TX;
rval = ec_outfram_send(pPktDev, (char*)(*stack->txbuf)[idx],
(*stack->txbuflength)[idx]);
if (rval > 0)
{
(*stack->rxbufstat)[idx] = EC_BUF_TX;
port->pktDev.tx_count++;
}
else
{
(*stack->rxbufstat)[idx] = EC_BUF_EMPTY;
}

return rval;
}
Expand Down Expand Up @@ -511,8 +515,12 @@ int ecx_outframe_red(ecx_portt *port, int idx)
/* rewrite MAC source address 1 to secondary */
ehp->sa1 = htons(secMAC[1]);
/* transmit over secondary interface */
rval = ec_outfram_send(&(port->redport->pktDev), &(port->txbuf2), port->txbuflength2);
port->redport->rxbufstat[idx] = EC_BUF_TX;
rval = ec_outfram_send(&(port->redport->pktDev), &(port->txbuf2), port->txbuflength2);
if (rval <= 0)
{
(*stack->rxbufstat)[idx] = EC_BUF_EMPTY;
}
}

return rval;
Expand Down
13 changes: 10 additions & 3 deletions oshw/win32/nicdrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,12 @@ int ecx_outframe(ecx_portt *port, int idx, int stacknumber)
stack = &(port->redport->stack);
}
lp = (*stack->txbuflength)[idx];
rval = pcap_sendpacket(*stack->sock, (*stack->txbuf)[idx], lp);
(*stack->rxbufstat)[idx] = EC_BUF_TX;
rval = pcap_sendpacket(*stack->sock, (*stack->txbuf)[idx], lp);
if (rval == PCAP_ERROR)
{
(*stack->rxbufstat)[idx] = EC_BUF_EMPTY;
}

return rval;
}
Expand Down Expand Up @@ -301,9 +305,12 @@ int ecx_outframe_red(ecx_portt *port, int idx)
/* rewrite MAC source address 1 to secondary */
ehp->sa1 = htons(secMAC[1]);
/* transmit over secondary socket */
pcap_sendpacket(port->redport->sockhandle, (u_char const *)&(port->txbuf2), port->txbuflength2);
LeaveCriticalSection( &(port->tx_mutex) );
port->redport->rxbufstat[idx] = EC_BUF_TX;
if (pcap_sendpacket(port->redport->sockhandle, (u_char const *)&(port->txbuf2), port->txbuflength2) == PCAP_ERROR)
{
port->redport->rxbufstat[idx] = EC_BUF_EMPTY;
}
LeaveCriticalSection( &(port->tx_mutex) );
}

return rval;
Expand Down

0 comments on commit 0a67e6b

Please sign in to comment.