Defensive programming: make sure that we don't fail completely if we get a callback for a NULL pointer
This commit is contained in:
parent
82b755c017
commit
f2fbb4b49d
1 changed files with 135 additions and 134 deletions
|
@ -186,15 +186,19 @@ free_first_packet(struct neighbor_queue *n)
|
||||||
static void
|
static void
|
||||||
packet_sent(void *ptr, int status, int num_transmissions)
|
packet_sent(void *ptr, int status, int num_transmissions)
|
||||||
{
|
{
|
||||||
struct neighbor_queue *n = ptr;
|
struct neighbor_queue *n;
|
||||||
struct rdc_buf_list *q = list_head(n->queued_packet_list);
|
struct rdc_buf_list *q;
|
||||||
struct qbuf_metadata *metadata = (struct qbuf_metadata *)q->ptr;
|
struct qbuf_metadata *metadata;
|
||||||
clock_time_t time = 0;
|
clock_time_t time = 0;
|
||||||
mac_callback_t sent;
|
mac_callback_t sent;
|
||||||
void *cptr;
|
void *cptr;
|
||||||
int num_tx;
|
int num_tx;
|
||||||
int backoff_transmissions;
|
int backoff_transmissions;
|
||||||
|
|
||||||
|
n = ptr;
|
||||||
|
if(n == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
switch(status) {
|
switch(status) {
|
||||||
case MAC_TX_OK:
|
case MAC_TX_OK:
|
||||||
case MAC_TX_NOACK:
|
case MAC_TX_NOACK:
|
||||||
|
@ -208,15 +212,19 @@ packet_sent(void *ptr, int status, int num_transmissions)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
q = list_head(n->queued_packet_list);
|
||||||
|
if(q != NULL) {
|
||||||
|
metadata = (struct qbuf_metadata *)q->ptr;
|
||||||
|
|
||||||
|
if(metadata != NULL) {
|
||||||
sent = metadata->sent;
|
sent = metadata->sent;
|
||||||
cptr = metadata->cptr;
|
cptr = metadata->cptr;
|
||||||
num_tx = n->transmissions;
|
num_tx = n->transmissions;
|
||||||
|
|
||||||
if(status == MAC_TX_COLLISION ||
|
if(status == MAC_TX_COLLISION ||
|
||||||
status == MAC_TX_NOACK) {
|
status == MAC_TX_NOACK) {
|
||||||
|
|
||||||
/* If the transmission was not performed because of a collision or
|
/* If the transmission was not performed because of a
|
||||||
noack, we must retransmit the packet. */
|
collision or noack, we must retransmit the packet. */
|
||||||
|
|
||||||
switch(status) {
|
switch(status) {
|
||||||
case MAC_TX_COLLISION:
|
case MAC_TX_COLLISION:
|
||||||
|
@ -269,6 +277,8 @@ packet_sent(void *ptr, int status, int num_transmissions)
|
||||||
free_first_packet(n);
|
free_first_packet(n);
|
||||||
mac_call_sent_callback(sent, cptr, status, num_tx);
|
mac_call_sent_callback(sent, cptr, status, num_tx);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
|
@ -277,15 +287,10 @@ send_packet(mac_callback_t sent, void *ptr)
|
||||||
struct rdc_buf_list *q;
|
struct rdc_buf_list *q;
|
||||||
struct neighbor_queue *n;
|
struct neighbor_queue *n;
|
||||||
static uint16_t seqno;
|
static uint16_t seqno;
|
||||||
|
const rimeaddr_t *addr = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
|
||||||
|
|
||||||
packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, seqno++);
|
packetbuf_set_attr(PACKETBUF_ATTR_MAC_SEQNO, seqno++);
|
||||||
|
|
||||||
/* If the packet is a broadcast, do not allocate a queue
|
|
||||||
entry. Instead, just send it out. */
|
|
||||||
if(!rimeaddr_cmp(packetbuf_addr(PACKETBUF_ADDR_RECEIVER),
|
|
||||||
&rimeaddr_null)) {
|
|
||||||
const rimeaddr_t *addr = packetbuf_addr(PACKETBUF_ADDR_RECEIVER);
|
|
||||||
|
|
||||||
/* Look for the neighbor entry */
|
/* Look for the neighbor entry */
|
||||||
n = neighbor_queue_from_addr(addr);
|
n = neighbor_queue_from_addr(addr);
|
||||||
if(n == NULL) {
|
if(n == NULL) {
|
||||||
|
@ -353,10 +358,6 @@ send_packet(mac_callback_t sent, void *ptr)
|
||||||
PRINTF("csma: could not allocate neighbor, dropping packet\n");
|
PRINTF("csma: could not allocate neighbor, dropping packet\n");
|
||||||
}
|
}
|
||||||
mac_call_sent_callback(sent, ptr, MAC_TX_ERR, 1);
|
mac_call_sent_callback(sent, ptr, MAC_TX_ERR, 1);
|
||||||
} else {
|
|
||||||
PRINTF("csma: send broadcast\n");
|
|
||||||
NETSTACK_RDC.send(sent, ptr);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue