You are not logged in.

#1 2012-04-26 09:16:21

XaverOz
Member
Registered: 2012-02-24
Posts: 18

Simulate dropped packets on UDP protocol

I want to simulate packet loss (in both directions).
I use iptables as follows:
iptables -A INPUT -m statistic -p udp --mode random --probability 0.5 -j DROP
all OK. But when i try:
iptables -A OUTPUT -m statistic -p udp --mode random --probability 0.5 -j DROP
my code on Python2.7 return to me:
socket.error: [Errno 1] Operation not permitted

Last edited by XaverOz (2012-04-27 02:12:31)

Offline

#2 2012-04-26 11:05:01

pedromj
Member
Registered: 2010-10-27
Posts: 51

Re: Simulate dropped packets on UDP protocol

You say UDP in the title but the iptables commands refer to TCP. We need to know what is the exact Python code (just the socket/connection part) you are using.


Entia non sunt multiplicanda praeter necessitatem

Offline

#3 2012-04-27 02:17:41

XaverOz
Member
Registered: 2012-02-24
Posts: 18

Re: Simulate dropped packets on UDP protocol

sorry form my error smile. i mean udp flag.
my code for output:
import socket, time

def main():
    sckm = socket.socket( socket.AF_INET, socket.SOCK_DGRAM )
    while True:
        sckm.sendto( 'package', ("192.168.0.102", 10025) )
        time.sleep(3)

if __name__ == "__main__":
    main()

Last edited by XaverOz (2012-04-27 02:38:27)

Offline

#4 2012-04-27 08:31:28

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,224
Website

Re: Simulate dropped packets on UDP protocol

Kernel appears to be telling the python process that it's not allowed to send that packet...

Perhaps redirect it to somewhere else instead:

iptables -t nat -I PREROUTING -m statistic -p udp --mode random --probability 0.5 -j DNAT --to 1.2.3.4

Offline

Board footer

Powered by FluxBB