Factor out code for handling SABM frames
This commit is contained in:
parent
17b2313edc
commit
a60e562fdb
1 changed files with 35 additions and 25 deletions
60
src/server.c
60
src/server.c
|
@ -1115,6 +1115,40 @@ static int reply_ua(patty_ax25_if *iface,
|
|||
return reply_to(iface, frame, &reply, PATTY_AX25_FRAME_NORMAL);
|
||||
}
|
||||
|
||||
static int handle_sabm(patty_ax25_server *server,
|
||||
patty_ax25_if *iface,
|
||||
patty_ax25_frame *frame) {
|
||||
patty_ax25_sock *sock;
|
||||
|
||||
if ((sock = sock_by_addr(server->socks_pending_accept,
|
||||
&frame->dest)) == NULL) {
|
||||
return reply_dm(iface, frame, PATTY_AX25_FRAME_U_FINAL);
|
||||
}
|
||||
|
||||
sock->status = PATTY_AX25_SOCK_ESTABLISHED;
|
||||
sock->mode = PATTY_AX25_SOCK_SABM;
|
||||
|
||||
save_reply_addr(sock, frame);
|
||||
|
||||
if (sock_save_by_addrpair(server->socks_established,
|
||||
sock,
|
||||
&sock->local,
|
||||
&sock->remote) < 0) {
|
||||
goto error_save_by_addrpair;
|
||||
}
|
||||
|
||||
if (sock_delete_by_addr(server->socks_pending_accept,
|
||||
&frame->dest) < 0) {
|
||||
goto error_delete_by_addr;
|
||||
}
|
||||
|
||||
return reply_ua(iface, frame, PATTY_AX25_FRAME_U_FINAL);
|
||||
|
||||
error_delete_by_addr:
|
||||
error_save_by_addrpair:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int handle_frame(patty_ax25_server *server,
|
||||
patty_ax25_if *iface,
|
||||
void *buf,
|
||||
|
@ -1131,31 +1165,7 @@ static int handle_frame(patty_ax25_server *server,
|
|||
}
|
||||
|
||||
if (PATTY_AX25_CONTROL_UNNUMBERED_SABM(frame.control)) {
|
||||
patty_ax25_sock *sock;
|
||||
|
||||
if ((sock = sock_by_addr(server->socks_pending_accept,
|
||||
&frame.dest)) == NULL) {
|
||||
if (reply_dm(iface, &frame, PATTY_AX25_FRAME_U_FINAL) < 0) {
|
||||
goto error_io;
|
||||
}
|
||||
}
|
||||
|
||||
sock->status = PATTY_AX25_SOCK_ESTABLISHED;
|
||||
sock->mode = PATTY_AX25_SOCK_SABM;
|
||||
|
||||
save_reply_addr(sock, &frame);
|
||||
|
||||
if (sock_save_by_addrpair(server->socks_established,
|
||||
sock,
|
||||
&sock->local,
|
||||
&sock->remote) < 0) {
|
||||
goto error_io;
|
||||
}
|
||||
|
||||
if (sock_delete_by_addr(server->socks_pending_accept,
|
||||
&frame.dest) < 0) {
|
||||
goto error_io;
|
||||
}
|
||||
return handle_sabm(server, iface, &frame);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue