From eb071de23087ea19bfeb203c34479ea9f04e49fd Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Wed, 5 Aug 2020 22:38:49 -0400 Subject: [PATCH] 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 --- include/patty/ax25/sock.h | 5 +++++ include/patty/client.h | 5 +++++ src/server.c | 18 ++++++++++++++++++ src/sock.c | 8 ++++++++ 4 files changed, 36 insertions(+) diff --git a/include/patty/ax25/sock.h b/include/patty/ax25/sock.h index 08407cd..68bf94f 100644 --- a/include/patty/ax25/sock.h +++ b/include/patty/ax25/sock.h @@ -64,6 +64,7 @@ enum patty_ax25_sock_flow { }; enum patty_ax25_sock_opt { + PATTY_AX25_SOCK_PARAMS, PATTY_AX25_SOCK_IF }; @@ -127,6 +128,10 @@ void patty_ax25_sock_init(patty_ax25_sock *sock); void patty_ax25_sock_reset(patty_ax25_sock *sock); +void patty_ax25_sock_mtu_set(patty_ax25_sock *sock, size_t mtu); + +void patty_ax25_sock_window_set(patty_ax25_sock *sock, size_t window); + void patty_ax25_sock_params_upgrade(patty_ax25_sock *sock); void patty_ax25_sock_params_max(patty_ax25_sock *sock); diff --git a/include/patty/client.h b/include/patty/client.h index d5c34af..8a3d948 100644 --- a/include/patty/client.h +++ b/include/patty/client.h @@ -56,6 +56,11 @@ typedef struct _patty_client_setsockopt_request { size_t len; } patty_client_setsockopt_request; +typedef struct _patty_client_setsockopt_params { + size_t mtu, + window; +} patty_client_setsockopt_params; + typedef struct _patty_client_setsockopt_if { char name[8]; int status; diff --git a/src/server.c b/src/server.c index d2793ca..19ee9ac 100644 --- a/src/server.c +++ b/src/server.c @@ -590,6 +590,23 @@ static int server_setsockopt(patty_ax25_server *server, } switch (request.opt) { + case PATTY_AX25_SOCK_PARAMS: { + patty_client_setsockopt_params data; + + if (read(client, &data, request.len) < 0) { + goto error_read; + } + + if (data.mtu) patty_ax25_sock_mtu_set(sock, data.mtu); + if (data.window) patty_ax25_sock_window_set(sock, data.window); + + if (patty_ax25_sock_realloc_bufs(sock) < 0) { + goto error_realloc_bufs; + } + + break; + } + case PATTY_AX25_SOCK_IF: { patty_client_setsockopt_if data; patty_ax25_if *iface; @@ -639,6 +656,7 @@ error_invalid_type: error_invalid_opt: return write(client, &response, sizeof(response)); +error_realloc_bufs: error_read: return -1; } diff --git a/src/sock.c b/src/sock.c index 6c50e7d..0bf35c5 100644 --- a/src/sock.c +++ b/src/sock.c @@ -227,6 +227,14 @@ void patty_ax25_sock_reset(patty_ax25_sock *sock) { patty_timer_clear(&sock->timer_t3); } +void patty_ax25_sock_mtu_set(patty_ax25_sock *sock, size_t mtu) { + sock->n_maxlen_tx = mtu; +} + +void patty_ax25_sock_window_set(patty_ax25_sock *sock, size_t window) { + sock->n_window_tx = window; +} + void patty_ax25_sock_params_upgrade(patty_ax25_sock *sock) { if (sock->version >= PATTY_AX25_2_2) { return;