Commit graph

556 commits

Author SHA1 Message Date
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
7a76da651c Add comments to include/ax25/sock.h defaults 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
a1ec1e00d0 Improve patty_ax25_sock_destroy() for raw sockets
Changes:

    * Don't clear socket from an interface's promiscuous socket table if
      the socket state is not SOCK_PROMISC

    * Destroy socket TNC if socket type is SOCK_RAW

    * Only attempt to close socket file descriptors >0
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
4c427854da Portability fixes for ./configure
Fix portability of ./configure by defaulting to a more generic POSIX
setup for all values of `uname -s` apart from "Darwin"
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
f54db37a7e Always clear KISS frame decode state on FEND
Always completely discard KISS frame decode state when encountering an
FEND character
2024-03-01 00:20:47 -05:00
XANTRONIX Development
b5ec25eb6a Don't check errno on EOF in patty_kiss_tnc_recv() 2024-03-01 00:20:47 -05:00
XANTRONIX Development
63a1c2d56e Clear unwanted errno in patty_kiss_tnc_new_fd()
Clear unwanted errno in patty_kiss_tnc_new_fd() when isatty() returns
false on a file descriptor
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
b99a6607ba Use tcflush() in patty_kiss_tnc_new()
Use tcflush() to initialize TTY state in patty_kiss_tnc_new(), so that
no unexpected data causes KISS framing errors
2024-03-01 00:20:47 -05:00
XANTRONIX Development
08509999c4 Formatting tweaks 2024-03-01 00:20:47 -05:00
XANTRONIX Development
1493f913a7 Don't use tcdrain() in patty_kiss_frame_send()
Don't use tcdrain() in patty_kiss_frame_send(), as this may cause a
program to block indefinitely on BSD systems
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
c417461a0b Implement patty_kiss_frame_send()
Implement patty_kiss_frame_send() as a means of sending a KISS frame
without requiring a patty_kiss_tnc object
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
XANTRONIX Development
6b603b6048 Omit version field in patty_print_frame_header() 2024-03-01 00:20:47 -05:00
XANTRONIX Development
c7a51ff7f1 Use more standard formatting in src/print.c
Use a more standard formatting style when printing frame headers,
similar to that of MONITOR mode of a Kantronics TNC, or direwolf
2024-03-01 00:20:47 -05:00
XANTRONIX Development
967f2f6830 Rename patty_ax25_sock sequences per Section 4.2.4
Changes:

    * Rename seq_send to vs, ie, V(S)

    * Rename seq_recv to vr, ie, V(R)

    * Ensure handling RR responses updates V(S) with the N(R) value of
      the received frame
2024-03-01 00:20:47 -05:00
XANTRONIX Development
2db5a0d0b9 Fix issues with TX slots in src/sock.c
Fix issues with TX slots in src/sock.c wherein packets saved for resend
would not be able to be resent, as their total length was not encoded
properly into the slot structure
2024-03-01 00:20:46 -05:00
XANTRONIX Development
10432c9709 Fix swapped command/response bits in reply packets 2024-03-01 00:20:46 -05:00
XANTRONIX Development
4c00c441bb Remove localcall arg from examples/ax25dump.c 2024-03-01 00:20:46 -05:00
XANTRONIX Development
575adc5d31 Fix numerous XID negotiation bugs
Changes:

    * Fix Classes of Operations and HDLC parameter bit flags in
      include/patty/ax25.h to match the documentation after more careful
      analysis; resolve issues with byte order

    * Add support for previously missing HDLC parameters to function
      patty_print_params()

    * Fix Info TX/RX field encodings to be in bits, rather than bytes

    * Implement patty_ax25_sock_realloc_bufs() to reallocate buffers
      based on current window and I frame sizes

    * Implement patty_ax25_sock_params_upgrade() to upgrade a socket's
      parameters to the AX.25 v2.2 documented defaults; this will not
      change parameters if the socket is already set to v2.2

    * Implement patty_ax25_sock_params_max() to upgrade a socket's
      parameters to the highest values supported by patty

    * Reimplement patty_ax25_sock_send_xid() to send highest desired
      parameters, rather than the values currently set on the socket

    * When receiving XID frames destined to listening sockets, use
      patty_ax25_sock_params_max() to negotiate from high to low
      parameters

    * When receiving SABME flags, use patty_ax25_sock_params_upgrade()
      to ensure at least base AX.25 v2.2 parameter defaults are set

    * Fix issue where outbound connections initiated with XID were
      unable to time out after N retries
2024-03-01 00:20:46 -05:00
XANTRONIX Development
c287eb7a61 Fix dropped packets to promisc interfaces 2024-03-01 00:20:46 -05:00
XANTRONIX Development
16179894d2 Add tcdrain() at end of patty_kiss_tnc_send() 2024-03-01 00:20:46 -05:00
XANTRONIX Development
eb04bc4bb5 Fix XID I field size TX, RX parameter encoding
Fix XID I field size TX, RX parameter encoding to indicate the I frame
size in bits, rather than octets
2024-03-01 00:20:46 -05:00
XANTRONIX Development
671d4ef337 Don't tcsetattr() ptmx in patty_kiss_tnc_destroy()
Avoid tcsetattr() on a ptmx in patty_kiss_tnc_destroy(), as the old
attributes are not saved when opening a Unix98 PTY master
2024-03-01 00:20:46 -05:00
XANTRONIX Development
1f4ffc98ac Implement new patty client code
Implement new patty client code, replacing src/call.c with src/client.c
providing clients with an interface dealing with file descriptors valid
in their process space; this also obviates the need to open a Unix
domain socket to a patty server explicitly, and helps keep track of
sockets opened on the server, locally

Changes:

    * Implement patty_client_new() to handle opening the server Unix
      domain socket, and to allocate a dict for mapping server-side
      sockets with current process file descriptors

    * Reimplement all server calls in src/call.c around the new
      patty_client type; calls which result in the creation of a
      Unix98 PTY by the patty server now handle opening the local PTY
      and setting the file descriptor to raw mode.  Furthermore, these
      calls deal exclusively in terms of current process file
      descriptors

    * Refactor src/server.c to use the new patty_client type and calls

    * Refactor examples/client.c, examples/server.c, examples/ax25dump.c
      to use the new patty_client type and calls

    * Fix a bug in src/server.c, respond_accept() wherein a 0, rather
      than the file descriptor of the socket, is sent to the client as a
      return value
2024-03-01 00:20:46 -05:00
XANTRONIX Development
81d063cb68 Skip tcgetattr() in patty_kiss_tnc_new_fd() w/ptmx
Modify patty_kiss_tnc_new_fd() to avoid tcgetattr()/tcsetattr() when
passed a file descriptor for a PTY master, to address incompatibility
with BSD kernelspace Unix98 PTY implementations
2024-03-01 00:20:46 -05:00