0
votes

I'm trying to implement a security mechanism in RPL. For this, I need to log where did a packet come from. For example, if a packet is transmitted from A-->B-->C-->D, I want to find out at C that the packet came through B, and similarly for D.

I've added some code in uip6.c file to pull up the sender address from packetbuffer, but it is always null.

I'm storing the last node address and the time when the complete packet was received. These are the data structures.

struct packet_time_entry {
  linkaddr_t *source;
  uint32_t time;
};
MEMB(packet_time_mem, struct packet_time_entry, 16);
LIST(packet_time);

The main code I've written so far is this, in uip_process(), below line 1108 (master branch).

  struct packet_time_entry *p = memb_alloc(&packet_time_mem);
  p->time = clock_time();
  linkaddr_copy(p->source, packetbuf_addr(PACKETBUF_ADDR_SENDER));

  struct packet_time_entry *i;
  for (i = list_head(packet_time); i != NULL; i = list_item_next(i)) {
    if (linkaddr_cmp(i->source, p->source))
      list_remove(packet_time, i);
  }
  list_add(packet_time, p);
  PRINTF("Entry ");
  PRINTLLADDR((uip_lladdr_t*) p->source);  // always NULL 
  PRINTF("| %lu", p->time);
  PRINTF("\n");

I expect it to give me the address from packetbuf, but it's always NULL. Also, I suspect it is run only at the destination node, but not at the intermediate nodes.

1
You just want to log the sender of each packet if I understood your question correctly ? - desmaxi
@desmaxi Yes, on a per-hop level - Shubham Kumaram
did you try to use the callback functions? when a packet is received either over (r)unicast / broadcast / multicast / ... the appropriate callback function is called with the sender of the packet, the packet, and the retransmission . - desmaxi
Can you point me towards any documentation for callback functions? I couldn't find much help online - Shubham Kumaram
When you initialize you udp connection you can pass a callback function, here is an example of rpl-udp with an udp-client, github.com/contiki-ng/contiki-ng/blob/develop/examples/rpl-udp/…. It shows how to set the callback function for the udp connection. - desmaxi

1 Answers

0
votes

You can DEBUG the execution. For that just set DEBUG_NONE TO DEBUG_PRINT in uip6.c and then parse the serial log for finding the path taken by the packet.