GithubHelp home page GithubHelp logo

hackman / linux-tcp-drop Goto Github PK

View Code? Open in Web Editor NEW

This project forked from arut/linux-tcp-drop

0.0 3.0 0.0 111 KB

Linux implementation of tcpdrop (dropping TCP sockets on working system)

Makefile 3.26% C 96.74%

linux-tcp-drop's Introduction

== Linux tcpdrop kernel module ==

(c) 2012 Roman Arutyunyan <[email protected]>


Module:
======
This module lets you drop TCP connections from 
working Linux system. It also supports unscheduling 
TIME_WAIT sockets.

The module creates pseudo-file /proc/net/tcp_drop
which expects input of the following format:

saddr:sport daddr:dport

Note: Spaces between the two can be of any type & size.

Requirements:
============

Linux kernel 3.0.0

Build & install:
===============

Untar/ungzip & cd to module directory & just run make.

Load module:

sudo insmod ./tcp_drop.ko

Unload module:

sudo rmmod tcp_drop

Note: remember you need root privileges to write to /proc/net/tcp_drop.

Example1:
========

We have 4 connected sockets by IMAP client (port 143). Let's drop the last one:

netstat -n|grep ESTABLISHED|grep 143

tcp        0      0 10.31.1.141:51292       192.168.0.1:143        ESTABLISHED
tcp        0      0 10.31.1.141:51293       192.168.0.1:143        ESTABLISHED
tcp        0      0 10.31.1.141:51436       192.168.0.1:143        ESTABLISHED
                    ^.............copy this...............^

Just copy the middle part of string (incl. tabs/spaces) to /proc/net/tcp_drop:


echo "10.31.1.141:51436       192.168.0.1:143" > /proc/net/tcp_drop


Now it'dead:

netstat -n|grep ESTABLISHED|grep 143
tcp        0      0 10.31.1.141:51292       192.168.0.1:143        ESTABLISHED
tcp        0      0 10.31.1.141:51293       192.168.0.1:143        ESTABLISHED


IMAP client has received a socket error & will reconnect when needed.

Example2:
========

Let's kill a TIME_WAIT socket.
I've just created a TIME_WAIT socket with a netcat connection to localhost:8080:

netstat -n|grep TIME_WAIT
tcp        0      0 127.0.0.1:34790         127.0.0.1:8080          TIME_WAIT
                    ^....................................^


Here's how to kill it (it's better to say 'unschedule'):

echo "127.0.0.1:34790         127.0.0.1:8080" > /proc/net/tcp_drop


Let's see:

netstat -n|grep TIME_WAIT

<nothing here>

IPv6 support:
============

If built for non-ancient (>2.6.19) kernel IPv6 is fully supported.
Dropping IPv6 connections is done the same way as IPv4:

echo "::1:34717               ::1:8080" > /proc/net/tcp_drop

Standard representation of IPv6 address with port ([ipv6addr]:port)
is also supported:

echo "[::1]:34717               [::1]:8080" > /proc/net/tcp_drop


What server/client code receives:
================================

All code which has been using the socket killed
receives network error (it's like receiving TCP RESET):

telnet localhost 8080
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.


linux-tcp-drop's People

Contributors

arut avatar

Watchers

Marian Marinov avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.