Commit graph

152 commits

Author SHA1 Message Date
XANTRONIX Development
df9efb8b3a Start Timer T3 when starting Timer T1 after expiry
Start Timer T3 when starting Timer T1 after expiry, to avoid a situation
wherein two RR command polling frames may be sent within close proximity
of one another
2024-03-01 00:20:47 -05:00
XANTRONIX Development
99a48af087 Stop Timer T2 when sending RR on k/2 unacked
When handling I frames, stop Timer T2 if the number of unacknowledged
frames has reached k/2

Other changes:

    * Provide annotations from the AX.25 v2.2 standards document

    * Improve implementation of I frame reception P/F procedure
2024-03-01 00:20:47 -05:00
XANTRONIX Development
3b1e341851 Fix switch case fallthrough bugs in src/server.c
Fix switch case fallthrough bugs in src/server.c in the following
functions:

    * handle_rr()

    * handle_rnr()

    * handle_rej()
2024-03-01 00:20:47 -05:00
XANTRONIX Development
b619fffb32 Always send RR when Timer T3 runs out
Always send RR when Timer T3 runs out, as we are not likely (with modern
hardware with MMUs) to be unable to receive; furthermore, RNR would have
only been sent erroneously if the outward flow of traffic had been
stopped
2024-03-01 00:20:47 -05:00
XANTRONIX Development
609a7271e5 Minor formatting tweaks for searchability 2024-03-01 00:20:47 -05:00
XANTRONIX Development
d88e8512b8 Adhere to P/F procedure on I frames 2024-03-01 00:20:47 -05:00
XANTRONIX Development
bdbab9c5e7 Disregard TEST, UA and XID not addressed to iface 2024-03-01 00:20:47 -05:00
XANTRONIX Development
3db8c9cef3 Better handling, response to FRMR, SABM, and SABME
Changes:

    * Use patty_ax25_sock_reset() when receiving a FRMR, SABM, or SABME
      frame

    * Reply to an SABM or SABME frame with a UA when received by an
      ESTABLISHED socket
2024-03-01 00:20:47 -05:00
XANTRONIX Development
697ade0afa Reset socket retry counter for each frame acked 2024-03-01 00:20:47 -05:00
XANTRONIX Development
484981de34 Implement better frame ack strategy
Implement AX.25 v2.2, Section 6.4.6 "Receiving Acknowledgement"
semantics more consistently

Changes:

    * Add frame_ack() method in src/server.c to unify logic for
      acknowledging frames and handling I frame transmission flow
      control

    * Ensure that the Timer T1 retry counter is reset as appropriate
      when Timer T1 is restarted

    * Add excerpts from the AX.25 v2.2 documentation to accompanying
      code to better document the purpose of important aspects of the
      state machine and protocol

    * When receiving an S frame with N(R) acknowledgement of a frame
      sent earlier than indicated by V(S), set V(S) to that N(R) value

    * Implement patty_ax25_sock_resend_pending() as a means to resend
      one frame previously sent which remains unacknowledged; this
      uses V(S) to determine the frame to resend, and increments V(S) if
      there was indeed an unacknowledged frame

    * Call patty_ax25_sock_resend_pending() in src/server.c, method
      handle_sock() to send a single frame previously sent but pending
      acknowledgement
2024-03-01 00:20:47 -05:00
XANTRONIX Development
1fd1be2cb6 Improvements to patty_ax25_sock_ack()
Changes:

    * Make patty_ax25_sock_ack() take a N(R) argument directly, rather
      than having the caller specify N(R)-1

    * Only perform acknowledgement of frames within the range between
      V(A) and N(R)-1
2024-03-01 00:20:47 -05:00
XANTRONIX Development
1819b7fb34 Rename patty_ax25_sock 'pending' to 'rx_pending'
Rename patty_ax25_sock 'pending' to 'rx_pending' to better document its
purpose
2024-03-01 00:20:47 -05:00
XANTRONIX Development
0fb7d08872 Implement patty_timer_init()
Implement patty_timer_init() to allow the caller to specify a timer
value to use each time patty_timer_start() is called, obviating the need
to pass the same argument redundantly; if the timer value must be
changed, then another call to patty_timer_init() may be used
2024-03-01 00:20:47 -05:00
XANTRONIX Development
4577b5f223 More WIP; please kill me 2024-03-01 00:20:47 -05:00
XANTRONIX Development
e34713c766 Send the right rejection packets 2024-03-01 00:20:47 -05:00
XANTRONIX Development
f26e977bfc Implement patty_ax25_sock_ack()
Implement patty_ax25_sock_ack() to keep track of I frames sent which
have been successfully acknowledged by a peer
2024-03-01 00:20:47 -05:00
XANTRONIX Development
301e58c6e9 Send RR Response, not Command, on Timer T2 timeout 2024-03-01 00:20:47 -05:00
XANTRONIX Development
4d84ed183e Adhere better to P/F bit procedure for I frames 2024-03-01 00:20:47 -05:00
XANTRONIX Development
d43d24a934 Poll with RR when V(S) = V(A) + k 2024-03-01 00:20:47 -05:00
XANTRONIX Development
a5d74ecf2e Initial flow control improvements 2024-03-01 00:20:47 -05:00
XANTRONIX Development
776949b90c Implement frame segmentation/reassembly
Implement frame segmentation/reassembly state machine as per AX.25 v2.2
specifications, as per Section 6.6 "Disassembler/Reassembler" and
associated appendices
2024-03-01 00:20:47 -05:00
XANTRONIX Development
6d22d0286c Better adherence to flow control semantics 2024-03-01 00:20:47 -05:00
XANTRONIX Development
1e4329528c Use Timer T1 for timeouts on XID negotiations
When a remote station wishes to connect by sending an XID frame, use
Timer T1 to send an XID response up to the retry count before closing
the socket pending negotiation
2024-03-01 00:20:47 -05:00
XANTRONIX Development
893ddefd57 Use bit fields for setsockopt() SOCK_OPT_PARAMS 2024-03-01 00:20:47 -05:00
XANTRONIX Development
0cee9d1e17 Fix error when handling unexpected DM 2024-03-01 00:20:47 -05:00
XANTRONIX Development
20cacf4bed Improve accept(); allow select(2) on listeners
Changes:

    * Add validation to accept() to ensure file descriptors provided
      refer to SOCK_STREAM sockets in the SOCK_LISTENING state

    * Rather than writing a reply to the patty client socket when
      accepting a SABM or SABME request, write a message to the
      remote end of the listening socket; this avoids issues wherein
      a client receives an unexpected accept() response that may be
      unrelated to another pending request; this also allows client
      code to use select(2) on listening sockets

    * In patty_client_accept(), send the initial request to validate
      that the local socket can accept connections, and then wait for
      a connection to be made, reading a message written to the
      listening socket from the patty server

    * Allow select(2) to notify on accepted connections
2024-03-01 00:20:47 -05:00
XANTRONIX Development
0b8ce4f775 Gracefully close raw sockets on EOF
In src/server.c, handle_sock_raw(), gracefully close sockets upon
read()ing EOF
2024-03-01 00:20:47 -05:00
XANTRONIX Development
acaa5dee0f Don't change socket to SOCK_PROMISC for bad iface
In src/server.c, server_setsockopt(), do not change socket state to
SOCK_PROMISC if the requested interface cannot be found
2024-03-01 00:20:47 -05:00
XANTRONIX Development
3e51b48453 Fix various timer-related issues
Changes:

    * Replace usage of gettimeofday() with clock_gettime() in the main
      event loop, patty_ax25_server_run(), as gettimeofday() apparently
      goes backwards in time occasionally, as per:

        https://bugzilla.redhat.com/show_bug.cgi?id=174390

      Thanks Iain MM0ROR!

    * Fix patty_timer_expired() to properly return true if the
      remaining number of seconds is zero, but the remaining higher
      precision time is less than zero

    * Implement patty_timer_sub() to subtract two struct timespec
      values, as glibc lacks timespecsub()
2024-03-01 00:20:47 -05:00
XANTRONIX Development
40408060de Don't throw error on failure to decode frames
Fix src/server.c, handle_frame() to not throw an error when encountering
errors decoding invalid frames
2024-03-01 00:20:47 -05:00
XANTRONIX Development
08509999c4 Formatting tweaks 2024-03-01 00:20:47 -05:00
XANTRONIX Development
e558ccd57d Cleanup in src/server.c, handle_sock()
Changes:

    * Implement handle_sock_dgram() to specifically handle datagram
      (UI frame-only) sockets; this fixes issues wherein logic
      specific to SOCK_STREAM timers would be erroneously applied
      to datagram sockets

    * Always tick Timers T1, T2 and T3

    * Some slight code reorganization for improved readability of
      control flow
2024-03-01 00:20:47 -05:00
XANTRONIX Development
a3995c7e88 Stop Timer T1 upon receipt of DM during disconnect 2024-03-01 00:20:47 -05:00
XANTRONIX Development
82dd1d50a8 Start Timer T1 in src/server, sock_shutdown()
Start Timer T1 in src/server, sock_shutdown() after sending a DM frame
to the remote station
2024-03-01 00:20:47 -05:00
XANTRONIX Development
58a0025c59 Only handle clients and interfaces if select() >0
Only handle clients and interfaces if select() returns >0 in the main
event loop of patty_ax25_server_run(), to avoid unnecessary CPU
overhead
2024-03-01 00:20:47 -05:00
XANTRONIX Development
98490f79a7 Fix select() portability issues in src/server.c
Fix select() portability issues in src/server.c by using gettimeofday()
immediately prior to and after calling select() to calculate elapsed
time since blocking on select()
2024-03-01 00:20:47 -05:00
XANTRONIX Development
4899aa4796 Implement SOCK_DGRAM
Implement PATTY_AX25_SOCK_DGRAM type sockets as a means of exchanging UI
frames between stations without requiring calling code to encode and
decode UI frames explicitly
2024-03-01 00:20:47 -05:00
XANTRONIX Development
1d03b2883a Return ENOTSUP on connect() to raw sockets 2024-03-01 00:20:47 -05:00
XANTRONIX Development
b2d3d3e03f Fix strncpy() buffer size compiler warnings 2024-03-01 00:20:47 -05:00
XANTRONIX Development
ca06f34eed Rename patty_ax25_sock member 'status' to 'state' 2024-03-01 00:20:47 -05:00
XANTRONIX Development
b2182618ab Slight order change 2024-03-01 00:20:47 -05:00
XANTRONIX Development
512957dda1 Fix NULL dereference
Fix NULL dereference when handling REJ packets
2024-03-01 00:20:47 -05:00
XANTRONIX Development
ea68dc199b Reset retry counter on receipt of RR, RNR 2024-03-01 00:20:47 -05:00
XANTRONIX Development
2e56ae55eb Allow setting retry count with setsockopt()
Allow setting retry count with patty_client_setsockopt()
2024-03-01 00:20:47 -05:00
XANTRONIX Development
04176659ec Allow changing socket ack timer with setsockopt()
Allow changing socket ack timer with patty_client_setsockopt()
2024-03-01 00:20:47 -05:00
XANTRONIX Development
eb071de230 Add SOCK_PARAMS to patty_client_setsockopt()
Add SOCK_PARAMS to patty_client_setsockopt() to allow for setting
(presently) the MTU and TX window of a given socket to accommodate the
needs of specific remote stations
2024-03-01 00:20:47 -05:00
XANTRONIX Development
4d47b62f5f Implement additional socket flow control
Implement the SOCK_WAIT and SOCK_READY socket flow control states to
indicate a Receive Ready or Receive Not Ready state on the remote end

Other changes:

    * Fix issue wherein flow control was never halted when the remote
      end has received k (window) number of frames without the sending
      station asking for acknowledgment
2024-03-01 00:20:47 -05:00
XANTRONIX Development
36f98bf7f0 Improve SOCK_RAW facilities
Changes:

    * Reimplement patty_ax25_sock_send() to be geared specifically for
      sending raw frames; the function which formerly held this name is
      now a private method

    * Implement patty_ax25_sock_recv() to receive a frame from a raw
      socket

    * Implement patty_ax25_sock_recv_pending() to determine how many raw
      frames are pending receipt in the buffer

    * When handling raw sockets, use patty_ax25_sock_recv_pending() to
      ensure any raw pending frames read from a client intended for
      transmission on an interface are read completely
2024-03-01 00:20:47 -05:00
XANTRONIX Development
d0d17b58fb Implement support for sending frames with SOCK_RAW
Changes:

    * When associating a promiscuous socket with an interface, rather
      than creating a patty_kiss_tnc object, simply store the socket
      file descriptor and use patty_kiss_frame_send() to send incoming
      or outgoing frames for that interface to the promiscuous socket

    * Add special initialization code in src/sock.c for SOCK_RAW; don't
      allocate any buffers, but instead set a few flags and otherwise
      use 0-initialized defaults

    * Implement handle_sock_raw() in src/server.c to check to see if any
      raw frames are pending, and if so, send them to the associated
      interface if provided by setsockopt()

    * Make patty_ax25_sock_bind_if() only call the function
      patty_ax25_if_add_promisc() only if the socket status is PROMISC;
      this allows support for non-promiscuous sockets used for outbound
      purposes
2024-03-01 00:20:47 -05:00
XANTRONIX Development
f96017bc10 Implement handling/sending RNR frames
Changes:

    * When handling RR commands with the P/F flag set, check to see if
      the socket file descriptor is currently being monitored; if so,
      reply RR, otherwise reply RNR

    * When handling RNR commands with the P/F flag set, apply the same
      aforementioned logic as used for handling RR commands

    * When handling RNR responses, clear the socket file descriptor so
      as to avoid infinite loop polling and to indicate that the remote
      station cannot receive packets currently
2024-03-01 00:20:47 -05:00