/***************************************************************************** * Packet Queue * ***************************************************************************** * This module is designed to allow the creation of queues to store packages * * waiting for ARP requests to be replied. The queue are updated as packages * * expire or are sent to their destination. * *****************************************************************************/ #ifndef SR_PQ_H #define SR_PQ_H #include #include "sr_protocol.h" #include "sr_if.h" /** * This structure holds the individual packet queue element. **/ struct pq_element{ /** * The number of ARP requests left before packet drop. **/ unsigned int arp_count; /** * Pointer to the packet buffer. **/ uint8_t *packet; /** * Length of queued packet. **/ unsigned int len; /** * Next queue element. **/ struct pq_element *next; }; /** * Queue structure. **/ struct sr_pq{ /** * Reference to first element. **/ struct pq_element *head; /** * Reference to last element. **/ struct pq_element *tail; /** * Number of elements in the queue. **/ unsigned int length; /** * The time untill the next APR request can be sent. **/ time_t expires; }; /** * Queue up a packet. * Author: Nicholas **/ void sr_enqueue_packet(struct sr_pq*, uint8_t *, unsigned int); /** * Remove a packet from the queue. * Author: Nicholas **/ uint8_t *sr_dequeue_packet(struct sr_pq *, unsigned int*); /** * Print the packet queue entries. * Author: Nicholas **/ void sr_print_pq(struct sr_pq *); /** * Send all packets in the queue. * Author: Nicholas **/ void sr_send_packets(struct sr_instance*, struct sr_pq *, char*, unsigned char [ETHER_ADDR_LEN]); /** * Convert a MAC address to a nicely formated string. * Author: Nicholas **/ char *strmac(unsigned char [ETHER_ADDR_LEN]); /** * Convert an IP address to a buffered string. * Author: Nicholas **/ char *strip(uint32_t); /** * Send ARP requests and ICMP unreachable errors for queued packets. * Author: Nicholas **/ void sr_update_pq(struct sr_instance*, struct sr_pq*, char*, uint32_t); #endif