packet reordering and delay using libipq
When using libipq, is it possible to delay/reorder individual packets? In particular, I am curious whether the following pseudo code can be implemented using libipq. Situation is like this: Assume that this imaginary software is running on a router which forwards packets to other hosts. Packet 1 arrives at the router first and packet 2 arrives one second after packet 1 does. The goal is to send out packet 2 one second before packet 1 is sent out. In other words, packet 1 should be delayed by two seconds while packet 2 is immediately forwarded.
Very approximate code without all the bells and whistles follows.
main(){
int status;
unsigned char buf1[BUFSIZE]; // buffer for packet1
unsigned char buf2[BUFSIZE]; // buffer for packet2
struct ipq_handle *h;
h = ipq_create_handle(0, PF_INET);
status = ipq_set_mode(h, IPQ_COPY_PACKET, BUFSIZE);
do{
// get packet1
status = ipq_read(h, buf1, BUFSIZE, 0);
ipq_packet_msg_t *m1 = ipq_get_packet(buf1);
// get packet2
status = ipq_read(h, buf2, BUFSIZE, 0);
ipq_packet_msg_t *m2 = ipq_get_packet(buf2);
// set verdict on packet2
status = ipq_set_verdict(h, m1->packet_id, NF_ACCEPT, 0, NULL);
// delay
delay(2000); // I am not exactly sure about how to implement delay, but for
// the sake of the argument, this line should be clear enough
// set verdict on packet1
status = ipq_set_verdict(h, m2->packet_id, NF_ACCEPT, 0, NULL);
} while (1);
}
What worries me the most about my pseudo code is that the underlying ip_queue might hang waiting for the return value (such as NF_ACCEPT), which will prevent packet 2 from being forwarded before packet 1. I haven't actually implemented the code yet because it is not very easy for me to test it with just one lousy computer...I would like to know whether somebody has successfully reordered/applied delays to individual packets using libipq. Also, it would be great if somebody could point out what I am doing wrong if that is the case. Thanx in advance.
Last edited by shinkm; 09-08-2004 at 12:26 AM.
|