Уже написал полгода назад ;-)
Работает совместно с iptables.
Выкладываю.EN:
In order to run this software you have to build your kernel with
ip_queue support and packet iptables-dev installed with libipq lib.
To compile:
./mk
To add filter:
iptables -I OUTPUT -d 10.0.0.1 -p icmp --icmp-type ping -j QUEUE
To view filter:
iptables -L -v -n -x
RU:
Для запуска этого ПО необходима поддержка ядром функции ip_queue и пакетом iptables-dev
с библиотекой libipq;
Для компиляции:
./mk
Для добавления фильтра:
iptables -I OUTPUT -d 10.0.0.1 -p icmp --icmp-type ping -j QUEUE
Для просмотра фильтра:
iptables -L -v -n -x
/*
Packet delayer.
(c) Volodymyr Skrypka. vmskrypkaATyandexDOTruREMOVETHIS
Based on libpq example code and code from book "Advanced Linux Programming" ( Mark Mitchel, ...)
*/
#include <linux/netfilter.h>
#include <libipq.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define TIME 10000
#define BUFSIZE 2048
int nsleep (double sleep_time)
{
struct timespec tv;
tv.tv_sec = (time_t) sleep_time;
tv.tv_nsec= (long) ((sleep_time -tv.tv_sec)*1e+9);
printf("\nDelaying packet for %d sec %d nsec\n", tv.tv_sec,tv.tv_nsec);
while(1)
{
int rval = nanosleep(&tv,&tv);
if(rval == 0)
return 0; //sleep ok
else
if (errno=EINTR)
continue;
else
return rval; //unknown error
}
return 0;
/*
tv.tv_sec = 0;
tv.tv_nsec= TIME;
printf("\nDelaying packet for %d sec %d nsec\n", tv.tv_sec,tv.tv_nsec);
nanosleep(&tv,&tv);
*/
}
static void die(struct ipq_handle *h)
{
ipq_perror("passer");
ipq_destroy_handle(h);
exit(1);
}
int main(int argc, char **argv)
{
int status;
unsigned char buf[BUFSIZE];
double delay=0;
struct ipq_handle *h;
if(argc<2)
{
printf("\nUsage: \n%s DELAY_VALUE_IN_SECONDS\nExample:\n%s 0.1\n",argv[0],argv[0]);
exit(0);
}
delay = atof(argv[1]);
if(delay==0.0)
{
printf("\nConversion error\n");
exit(1);
}
h = ipq_create_handle(0, PF_INET);
if (!h)
die(h);
status = ipq_set_mode(h, IPQ_COPY_PACKET, BUFSIZE);
if (status < 0)
die(h);
do{
status = ipq_read(h, buf, BUFSIZE, 0);
if (status < 0)
die(h);
switch (ipq_message_type(buf)) {
case NLMSG_ERROR:
fprintf(stderr, "Received error message %d\n",
ipq_get_msgerr(buf));
break;
case IPQM_PACKET: {
ipq_packet_msg_t *m = ipq_get_packet(buf);
nsleep(delay);
status = ipq_set_verdict(h, m->packet_id,
NF_ACCEPT, 0, NULL);
if (status < 0)
die(h);
break;
}
default:
fprintf(stderr, "Unknown message type!\n");
break;
}
} while (1);
ipq_destroy_handle(h);
return 0;
}