Skip to content

Commit

Permalink
net: x25: Fix handling of Restart Request and Restart Confirmation
Browse files Browse the repository at this point in the history
1. When the x25 module gets loaded, layer 2 may already be running and
connected. In this case, although we are in X25_LINK_STATE_0, we still
need to handle the Restart Request received, rather than ignore it.

2. When we are in X25_LINK_STATE_2, we have already sent a Restart Request
and is waiting for the Restart Confirmation with t20timer. t20timer will
restart itself repeatedly forever so it will always be there, as long as we
are in State 2. So we don't need to check x25_t20timer_pending again.

Fixes: d023b2b ("net/x25: fix restart request/confirm handling")
Cc: Martin Schiller <[email protected]>
Signed-off-by: Xie He <[email protected]>
Acked-by: Martin Schiller <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Xie He authored and davem330 committed Dec 10, 2020
1 parent 0f86a5b commit 6b21c0b
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions net/x25/x25_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,29 +58,27 @@ static inline void x25_stop_t20timer(struct x25_neigh *nb)
del_timer(&nb->t20timer);
}

static inline int x25_t20timer_pending(struct x25_neigh *nb)
{
return timer_pending(&nb->t20timer);
}

/*
* This handles all restart and diagnostic frames.
*/
void x25_link_control(struct sk_buff *skb, struct x25_neigh *nb,
unsigned short frametype)
{
struct sk_buff *skbn;
int confirm;

switch (frametype) {
case X25_RESTART_REQUEST:
switch (nb->state) {
case X25_LINK_STATE_0:
/* This can happen when the x25 module just gets loaded
* and doesn't know layer 2 has already connected
*/
nb->state = X25_LINK_STATE_3;
x25_transmit_restart_confirmation(nb);
break;
case X25_LINK_STATE_2:
confirm = !x25_t20timer_pending(nb);
x25_stop_t20timer(nb);
nb->state = X25_LINK_STATE_3;
if (confirm)
x25_transmit_restart_confirmation(nb);
break;
case X25_LINK_STATE_3:
/* clear existing virtual calls */
Expand All @@ -94,13 +92,8 @@ void x25_link_control(struct sk_buff *skb, struct x25_neigh *nb,
case X25_RESTART_CONFIRMATION:
switch (nb->state) {
case X25_LINK_STATE_2:
if (x25_t20timer_pending(nb)) {
x25_stop_t20timer(nb);
nb->state = X25_LINK_STATE_3;
} else {
x25_transmit_restart_request(nb);
x25_start_t20timer(nb);
}
x25_stop_t20timer(nb);
nb->state = X25_LINK_STATE_3;
break;
case X25_LINK_STATE_3:
/* clear existing virtual calls */
Expand Down

0 comments on commit 6b21c0b

Please sign in to comment.