GithubHelp home page GithubHelp logo

ccie18643 / pytcp Goto Github PK

View Code? Open in Web Editor NEW
330.0 15.0 35.0 32.7 MB

PyTCP is a fully functional TCP/IP stack written in Python. It supports TCP stream-based transport with reliable packet delivery based on a sliding window mechanism and basic congestion control. It also supports IPv6/ICMPv6 protocols with SLAAC address configuration. It operates as a user space program attached to the Linux TAP interface.

License: GNU General Public License v3.0

Python 99.79% Makefile 0.21%
network tcp python linux ip arp udp icmp ethernet ipv4

pytcp's People

Contributors

ccie18643 avatar nvelozsavino avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pytcp's Issues

Don't reapond to rst with rst

Currently, if a packet is sent to a port which is not in stack.sockets, then it is responded with rst.

The issue with such behaviour raises when a rst is received, instead of ignoring it, a rst is sent back (protocols/tcp/phrx.py:89).

This is especially problematic if you put two pytcp instances since they enter an infinite loop.

I'd love to fix that, just opening an issue to open it up for discussion.

Make it possible to import pytcp as a library

Currently, pytcp can be run as a script, using pytcp.py

It would have been nice to be able to import it as a library.

To do this a few things should be done -

  • add setup.py\pyproject.toml file.
  • either import relative or import including the root - pytcp.
  • encapsulate stack.py in an exposed class.
  • extract config.py to a configuration class, with the possibility of getting it from a file.

I'd love to do that, just opening an issue to open it up for discussion.

Typos discovered by codespell

% codespell --ignore-words-list="ect,ether,nd" --quiet-level=2

./rx_ring.py:84: comming ==> coming
./phrx_ether.py:62: droping ==> dropping
./tx_ring.py:70: avaiable ==> available
./tx_ring.py:93: priorty ==> priority
./ps_ip4.py:40: libary ==> library
./ps_ip6.py:40: libary ==> library
./pytcp.py:107: whch ==> which
./pytcp.py:142: addess ==> address
./pytcp.py:146: addess ==> address
./ps_udp.py:40: libary ==> library
./phrx_icmp6.py:63: droping ==> dropping
./phrx_icmp6.py:83: neccessary ==> necessary
./tcp_socket.py:92: incomming ==> incoming
./phrx_arp.py:79: maping ==> mapping
./phrx_arp.py:99: maping ==> mapping
./phrx_arp.py:105: maping ==> mapping
./phrx_udp.py:87: droping ==> dropping
./icmp6_nd_cache.py:60: fo ==> of, for
./icmp6_nd_cache.py:124: apropriate ==> appropriate
./tcp_session_alt.py:118: paramters ==> parameters
./tcp_session_alt.py:148: milisecond ==> millisecond
./tcp_session_alt.py:304: realeased ==> released
./tcp_session_alt.py:367: reseting ==> resetting
./tcp_session_alt.py:384: reseting ==> resetting
./tcp_session_alt.py:480: desn't ==> doesn't
./tcp_session_alt.py:511: desn't ==> doesn't
./tcp_session_alt.py:608: droping ==> dropping
./tcp_session_alt.py:630: notifiy ==> notify
./tcp_session_alt.py:635: Immidiately ==> Immediately
./tcp_session_alt.py:673: Immidiately ==> Immediately
./tcp_session_alt.py:717: Immidiately ==> Immediately
./tcp_session.py:110: lenght ==> length
./tcp_session.py:112: bellow ==> below
./tcp_session.py:150: milisecond ==> millisecond
./tcp_session.py:307: realeased ==> released
./tcp_session.py:372: reseting ==> resetting
./tcp_session.py:389: reseting ==> resetting
./tcp_session.py:495: desn't ==> doesn't
./tcp_session.py:531: desn't ==> doesn't
./tcp_session.py:653: notifiy ==> notify
./tcp_session.py:658: Immidiately ==> Immediately
./tcp_session.py:701: Immidiately ==> Immediately
./tcp_session.py:748: Immidiately ==> Immediately
./phtx_ether.py:76: destiantion ==> destination
./phtx_ether.py:84: droping ==> dropping
./phtx_ether.py:89: destiantion ==> destination
./phtx_ether.py:98: destiantion ==> destination
./phtx_ether.py:109: destiantion ==> destination
./phtx_ether.py:118: destiantion ==> destination
./phtx_ether.py:126: droping ==> dropping
./phtx_ether.py:131: destiantion ==> destination
./phtx_ether.py:140: destiantion ==> destination
./phtx_ether.py:145: droping ==> dropping
./config.py:50: potocol ==> protocol
./config.py:51: apropriate ==> appropriate
./config.py:51: lenght ==> length
./config.py:51: boundries ==> boundaries
./config.py:52: actuall ==> actually, actual
./config.py:52: lenghts ==> lengths
./config.py:52: lenghts ==> lengths
./config.py:79: defaut ==> default
./config.py:80: implmented ==> implemented
./config.py:99: defaut ==> default
./config.py:100: implmented ==> implemented
./config.py:131: configuation ==> configuration
./config.py:132: fro ==> for, from
./phtx_ip4.py:55: comunication ==> communication
./phtx_ip4.py:83: apropriate ==> appropriate
./ps_tcp.py:40: libary ==> library
./phtx_ip6.py:122: droping ==> dropping
./pylintrc:58: reenable ==> re-enable
./phrx_ip4.py:102: droping ==> dropping
./phrx_ip4.py:105: accrdingly ==> accordingly
./ps_dhcp.py:40: libary ==> library
./README.md:30: Listner ==> Listener
./README.md:32: Berkley ==> Berkeley
./README.md:39: Berkley ==> Berkeley
./README.md:45: debuging ==> debugging
./README.md:52: acoording ==> according
./README.md:54: ceratin ==> certain, keratin
./README.md:56: acoording ==> according
./README.md:58: Listner ==> Listener
./README.md:58: requied ==> required
./README.md:73: Berkley ==> Berkeley
./README.md:74: Berkley ==> Berkeley
./README.md:177: addesses ==> addresses
./ps_icmp4.py:40: libary ==> library
./timer.py:56: exponentialy ==> exponentially
./ph.py:92: accomodate ==> accommodate
./ph.py:144: brodcast ==> broadcast
./ph.py:153: brodcast ==> broadcast
./ph.py:206: skiping ==> skipping
./ph.py:209: skiping ==> skipping
./ph.py:212: skiping ==> skipping
./ph.py:218: skiping ==> skipping
./ph.py:221: skiping ==> skipping
./ph.py:224: skiping ==> skipping
./ph.py:238: Succesfully ==> Successfully
./ph.py:248: automaticaly ==> automatically
./ph.py:285: skiping ==> skipping
./ph.py:288: skiping ==> skipping
./ph.py:291: skiping ==> skipping
./ph.py:294: skiping ==> skipping
./ph.py:300: skiping ==> skipping
./ph.py:303: skiping ==> skipping
./ph.py:330: Succesfully ==> Successfully
./ph.py:384: neccessary ==> necessary
./ps_icmp6.py:40: libary ==> library
./ps_icmp6.py:774: lenght ==> length
./ps_icmp6.py:1108: constuctor ==> constructor
./ps_ether.py:40: libary ==> library
./ps_ether.py:147: frmat ==> format
./phrx_ip6.py:61: droping ==> dropping

Using tun interface (without ethernet layer)

I've got a situation where it would be very useful to use pytcp as a TCP stack on top of a tun interface, where the ethernet layer is not necessary. Was wondering how possible it would be to implement.

Add some basic exmaples or docs~

I'm so happy to have this project to study, but all parts are coupled under one app.
I can't run ICMP or IP alone, all source code file is not easy to read and refactor,
cound you consider adding some examples to run one protocol individually.

TCP keep alive

When I'm using the tun/tap interface on windows, I can connect a TCP socket through that interface, and watch the packets in Wireshark.

s=sequence number
a=acknowledge number

My Client sent a SYN (s=X, a=0) (With the SACK_PERM and timeouts options)
The server replies with the SYN,ACK (s=Y,a=X+1)
and my client ACK that messages (s=X+1,a=Y+1)

PyTCP does this as well without a problem, except it doesn't use the SACK_PERM or timeout options

The problem comes after that:

the server sends an empty TCP package with s=Y, a=X+1 (TCP Keep-Alive)
and my client responds with s=X+1,a=Y+1 (TCP Keep-Alive ACK)

Wireshark detects this messages as TCP Keep-Alive and TCP Keep-Alive ACK

this sequence keeps happens every 3 seconds until something is send, and the sequence and ack gets incremented on the response

On PyTCP the TCP Keep-Alive is ignored because it "doesn't fit into receive window" and there's no ACK to this keep alive

Eventually, the server sends a packet with the RESET bit set and the connection is dropped.

is this behaviour different because the SYN didn't have the SACK_PERM option or is something that's missing in the PyTCP stack?

Add nagle's algorithm

Add the possibility to use [https://en.wikipedia.org/wiki/Nagle%27s_algorithm?wprov=sfla1](nagle's algorithm).

This should come with the possibility of turning off the delayed ack due to collision between the two.

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.