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.