-
-
Notifications
You must be signed in to change notification settings - Fork 197
Rfc9293 WIP #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ebrasca
wants to merge
61
commits into
froggey:master
Choose a base branch
from
ebrasca:rfc9293
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+673
−370
Open
Rfc9293 WIP #202
Changes from 6 commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
1113751
tcp: Remove redundant :ack-p t
ebrasca 3b0fe68
tcp: Update the protocol specification link to rfc9293
ebrasca ef54dfb
tcp: Do nothing to finish segments when in state :closed or :listen
ebrasca c140f05
tcp: Fix errata
ebrasca d2c3874
tcp: Refactor acceptable-segment-p
ebrasca 8c0a1c1
tcp: Add tcp4-send-ack
ebrasca e8b7f35
tcp: Add challenge-ack
ebrasca 0e6ca64
tcp: Check the sequence numbers before accepting RST in :syn-sent
ebrasca bce312d
tcp: Send RST when package is from old connection in :syn-sent state
ebrasca fb4e215
tcp: Refactor tcp4-connection-receive :syn-sent state
ebrasca e91e108
tcp: ACK non RST incoming unacceptable segments
ebrasca 5a6d095
tcp: Check incomming RST segments
ebrasca 53363c9
tcp: Don't abort connection when resiving segment in :syn-received state
ebrasca cc921f7
tcp: Remove connection from listener when getting SYN in state :syn-r…
ebrasca d602981
tcp: Challenge any SYN segment when not in :syn-sent state
ebrasca 352172c
tcp: Add :time-wait state
ebrasca 663c799
tcp: Add =<
ebrasca 9688f25
tcp: Deal with wrap around sequence numbers correctly
ebrasca 08e01fb
tcp: Small refactor
ebrasca f6fa477
tcp: Send RST to segments of old connections in :syn-received state
ebrasca 3278434
tcp: Handle FIN in :syn-received state
ebrasca 180b7b4
tcp: Chenck ACK sequence number in :last-ack state before ending it
ebrasca 3334d79
tcp: Hangle FIN in :last-ack state
ebrasca 0c28348
tcp: Ignore SYN or RST packets without ACK
ebrasca c9a2b0d
tcp: Allow sending data in half open connection
ebrasca d4bf137
tcp: Add rfc5961 mitigation
ebrasca 98af636
tcp: Send ACK to segments that acknowledges something not yet sent
ebrasca bfb920a
tcp: Hangle FIN in :closing state
ebrasca dd95347
tcp: Hangle FIN in :close-wait state
ebrasca 0d07fa7
tcp: Allow to resive data and control in the same segment
ebrasca 5a15692
tcp: Refactor tcp4-connection-receive :fin-wait-1 state
ebrasca 7cf7956
tcp: Update window size
ebrasca b365915
arp: Use correct function to get the time
ebrasca 4f2bd69
tcp: Report connection-closing in tcp-send when connetion is closing
ebrasca c229bc9
tcp: Implemented abort close
ebrasca 24ea270
tcp: Refactor tcp-send
ebrasca 94ebcb6
tcp: Add missing :closed case
ebrasca dc3eced
tcp: Implemented time-wait timeout
ebrasca 1690e24
tcp: Add :closed case to tcp4-connection-receive
ebrasca fe6ae64
tcp: Add close for :syn-sent and :syn-received cases
ebrasca eafa3eb
tcp: Default MSS for IPv4 is 536
ebrasca 8f75902
tcp: Support the mandatory option set
ebrasca 09b45ea
tcp: Set own MSS to 1460
ebrasca 966c557
tcp: Add checks for updating send window
ebrasca 0d6923b
tcp: Fix errata
ebrasca 55cf9d1
tcp: Handle retransmision and timeout in :syn-received state
ebrasca fb3d8ff
tcp: Add missing update-window
ebrasca dad5bfa
tcp: Better docstrings for acceptable-segment-p and acceptable-ack-p
ebrasca 5456851
tcp: Cancel retransmit after 3-Way Handshake
ebrasca 59f75a5
tcp: Cancel retransmit when getting FIN in :syn-received
ebrasca ab40c05
tcp: Update snd.nxt when sending FIN
ebrasca 0f28d52
tcp: Refactor implementation for clarity and configurability
ebrasca e825280
tcp: Fix simultaneous close handling in :fin-wait-1 state
ebrasca fdd7727
tcp: Rename max-seg-size to mss
ebrasca 0f947cd
tcp: Use MTU to calculate MSS
ebrasca 16081bf
tcp: Rename MSS parameters to clarify sender/receiver roles
ebrasca 53d7c1b
tcp: Refactor and add documentation
ebrasca ce491c8
tcp: Add missing rfc5961 mitigation in state :syn-sent
ebrasca c846c94
tcp: Use challenge-ack in places where ACKs are defensive
ebrasca 87c9ab6
tcp: Document the purpose of tcp4-send-ack and challenge-ack
ebrasca 35c2044
tcp: Add link to rfc5961
ebrasca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,8 @@ | ||
;;; TCP | ||
;;; | ||
;;; Transmission Control Protocol - Protocol Specification | ||
;;; https://tools.ietf.org/html/rfc793 | ||
;;; https://datatracker.ietf.org/doc/html/rfc9293 | ||
;;; | ||
;;; EFSM/SDL modeling of the original TCP standard (RFC793) and the | ||
;;; Congestion Control Mechanism of TCP Reno | ||
;;; http://www.medianet.kent.edu/techreports/TR2005-07-22-tcp-EFSM.pdf | ||
;;; | ||
;;; Computing TCP's Retransmission Timer | ||
;;; https://tools.ietf.org/html/rfc6298 | ||
|
||
(in-package :mezzano.network.tcp) | ||
|
||
|
@@ -383,8 +377,9 @@ Set to a value near 2^32 to test SND sequence number wrapping.") | |
(setf (tcp-connection-last-ack-time connection) | ||
(get-internal-run-time)) | ||
(when (not *netmangler-force-local-retransmit*) | ||
(tcp4-send-packet connection iss (+u32 irs 1) nil :ack-p t :syn-p t)))) | ||
(tcp4-send-packet connection iss (+u32 irs 1) nil :syn-p t)))) | ||
((logtest flags +tcp4-flag-rst+)) ; Do nothing for resets addressed to nobody. | ||
((logtest flags +tcp4-flag-fin+)) ; Do nothing for finish since the SEG.SEQ cannot be validated | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have a way to test this? |
||
(t | ||
(let* ((seq (if (logtest flags +tcp4-flag-ack+) | ||
(tcp-packet-acknowledgment-number packet start end) | ||
|
@@ -471,11 +466,7 @@ Set to a value near 2^32 to test SND sequence number wrapping.") | |
(when (<= seq (tcp-connection-rcv.nxt connection)) | ||
;; Don't check *netmangler-force-local-retransmit* here, | ||
;; or no acks will ever get through. | ||
(tcp4-send-packet connection | ||
(tcp-connection-snd.nxt connection) | ||
(tcp-connection-rcv.nxt connection) | ||
nil | ||
:ack-p t))) | ||
(tcp4-send-ack connection))) | ||
|
||
(defun tcp-packet-sequence-number (packet start end) | ||
(declare (ignore end)) | ||
|
@@ -496,16 +487,15 @@ Set to a value near 2^32 to test SND sequence number wrapping.") | |
(defun tcp-packet-data-length (packet start end) | ||
(- end (+ start (tcp-packet-header-length packet start end)))) | ||
|
||
(defun acceptable-segment-p (connection packet start end) | ||
(defun acceptable-segment-p (connection seg.seq seg.len) | ||
(let ((rcv.wnd (tcp-connection-rcv.wnd connection)) | ||
(rcv.nxt (tcp-connection-rcv.nxt connection)) | ||
(seg.seq (tcp-packet-sequence-number packet start end)) | ||
(seg.len (tcp-packet-data-length packet start end))) | ||
(rcv.nxt (tcp-connection-rcv.nxt connection))) | ||
(if (eql rcv.wnd 0) | ||
(and (eql seg.len 0) | ||
(eql seg.seq rcv.nxt)) | ||
;; Arithmetic here is not wrapping, so as to avoid wrap-around problems. | ||
(and (and (<= rcv.nxt seg.seq) (< seg.seq (+ rcv.nxt rcv.wnd))) | ||
(and (<= rcv.nxt seg.seq) | ||
fitzsim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(< seg.seq (+ rcv.nxt rcv.wnd)) | ||
(or (eql seg.len 0) | ||
(let ((seq-end (+ seg.seq seg.len -1))) | ||
(and (<= rcv.nxt seq-end) (< seq-end (+ rcv.nxt rcv.wnd))))))))) | ||
|
@@ -593,7 +583,7 @@ Set to a value near 2^32 to test SND sequence number wrapping.") | |
(tcp-connection-rcv.nxt connection) (+u32 seq 1)) | ||
(when (not *netmangler-force-local-retransmit*) | ||
(tcp4-send-packet connection ack (tcp-connection-rcv.nxt connection) nil | ||
:ack-p t :syn-p t)) | ||
:syn-p t)) | ||
;; Cancel retransmit | ||
(disarm-retransmit-timer connection) | ||
(disarm-timeout-timer connection)) | ||
|
@@ -632,13 +622,9 @@ Set to a value near 2^32 to test SND sequence number wrapping.") | |
(remhash connection (tcp-listener-pending-connections listener)) | ||
(decf (tcp-listener-n-pending-connections listener)))))) | ||
(:established | ||
(cond ((not (acceptable-segment-p connection packet start end)) | ||
(cond ((not (acceptable-segment-p connection seq data-length)) | ||
(when (not (logtest flags +tcp4-flag-rst+)) | ||
(tcp4-send-packet connection | ||
(tcp-connection-snd.nxt connection) | ||
(tcp-connection-rcv.nxt connection) | ||
nil | ||
:ack-p t))) | ||
(tcp4-send-ack connection))) | ||
((logtest flags +tcp4-flag-rst+) | ||
(setf (tcp-connection-pending-error connection) | ||
(make-condition 'connection-reset | ||
|
@@ -652,7 +638,7 @@ Set to a value near 2^32 to test SND sequence number wrapping.") | |
:port (tcp-connection-remote-port connection))) | ||
(detach-tcp-connection connection) | ||
(tcp4-send-packet connection | ||
(tcp-connection-snd.next connection) | ||
(tcp-connection-snd.nxt connection) | ||
fitzsim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
0 ; ??? | ||
nil | ||
:ack-p nil | ||
|
@@ -700,7 +686,7 @@ Set to a value near 2^32 to test SND sequence number wrapping.") | |
(setf (mezzano.supervisor:event-state | ||
(tcp-connection-receive-event connection)) | ||
t) | ||
(tcp4-send-packet connection ack (+u32 seq 1) nil :ack-p t)) | ||
(tcp4-send-packet connection ack (+u32 seq 1) nil)) | ||
fitzsim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
(tcp4-receive-data connection data-length end header-length packet seq start))) | ||
((eql (tcp-connection-snd.una connection) ack) | ||
;; TODO: slow start/duplicate ack detection/fast retransmit/etc. | ||
|
@@ -722,10 +708,7 @@ Set to a value near 2^32 to test SND sequence number wrapping.") | |
(cond ((logtest flags +tcp4-flag-fin+) | ||
(setf (tcp-connection-rcv.nxt connection) | ||
(+u32 (tcp-connection-rcv.nxt connection) 1)) | ||
(tcp4-send-packet connection | ||
(tcp-connection-snd.nxt connection) | ||
(tcp-connection-rcv.nxt connection) | ||
nil) | ||
(tcp4-send-ack connection) | ||
(if (logtest flags +tcp4-flag-ack+) | ||
;; Remote saw our FIN and closed as well. | ||
(detach-tcp-connection connection) | ||
|
@@ -743,10 +726,7 @@ Set to a value near 2^32 to test SND sequence number wrapping.") | |
;; Remote has sent FIN and waiting for ACK | ||
(setf (tcp-connection-rcv.nxt connection) | ||
(+u32 (tcp-connection-rcv.nxt connection) 1)) | ||
(tcp4-send-packet connection | ||
(tcp-connection-snd.nxt connection) | ||
(tcp-connection-rcv.nxt connection) | ||
nil) | ||
(tcp4-send-ack connection) | ||
(detach-tcp-connection connection)) | ||
(tcp4-receive-data connection data-length end header-length packet seq start))) | ||
(:closing | ||
|
@@ -787,6 +767,12 @@ Set to a value near 2^32 to test SND sequence number wrapping.") | |
(when errors-escape | ||
(error c)))))) | ||
|
||
(defun tcp4-send-ack (connection) | ||
fitzsim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(tcp4-send-packet connection | ||
(tcp-connection-snd.nxt connection) | ||
(tcp-connection-rcv.nxt connection) | ||
nil)) | ||
|
||
(defun compute-ip-pseudo-header-partial-checksum (src-ip dst-ip protocol length) | ||
(+ (logand src-ip #xFFFF) | ||
(logand (ash src-ip -16) #xFFFF) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.