static void x25_heartbeat_expiry(unsigned long param) { struct sock *sk = (struct sock *)param; bh_lock_sock(sk); if (sock_owned_by_user(sk)) /* can currently only occur in state 3 */ goto restart_heartbeat; switch (x25_sk(sk)->state) { case X25_STATE_0: /* * Magic here: If we listen() and a new link dies * before it is accepted() it isn't 'dead' so doesn't * get removed. */ if (sock_flag(sk, SOCK_DESTROY) || (sk->sk_state == TCP_LISTEN && sock_flag(sk, SOCK_DEAD))) { x25_destroy_socket(sk); goto unlock; } break; case X25_STATE_3: /* * Check for the state of the receive buffer. */ x25_check_rbuf(sk); break; } restart_heartbeat: x25_start_heartbeat(sk); unlock: bh_unlock_sock(sk); }
/* * State machine for state 3, Connected State. * The handling of the timer(s) is in file x25_timer.c * Handling of state 0 and connection release is in af_x25.c. */ static int x25_state3_machine(struct sock *sk, struct sk_buff *skb, int frametype, int ns, int nr, int q, int d, int m) { int queued = 0; int modulus; struct x25_sock *x25 = x25_sk(sk); modulus = (x25->neighbour->extended) ? X25_EMODULUS : X25_SMODULUS; switch (frametype) { case X25_RESET_REQUEST: x25_write_internal(sk, X25_RESET_CONFIRMATION); x25_stop_timer(sk); x25->condition = 0x00; x25->vs = 0; x25->vr = 0; x25->va = 0; x25->vl = 0; x25_requeue_frames(sk); break; case X25_CLEAR_REQUEST: x25_write_internal(sk, X25_CLEAR_CONFIRMATION); x25_disconnect(sk, 0, skb->data[3], skb->data[4]); break; case X25_RR: case X25_RNR: if (!x25_validate_nr(sk, nr)) { x25_clear_queues(sk); x25_write_internal(sk, X25_RESET_REQUEST); x25_start_t22timer(sk); x25->condition = 0x00; x25->vs = 0; x25->vr = 0; x25->va = 0; x25->vl = 0; x25->state = X25_STATE_4; } else { x25_frames_acked(sk, nr); if (frametype == X25_RNR) { x25->condition |= X25_COND_PEER_RX_BUSY; } else { x25->condition &= ~X25_COND_PEER_RX_BUSY; } } break; case X25_DATA: /* XXX */ x25->condition &= ~X25_COND_PEER_RX_BUSY; if ((ns != x25->vr) || !x25_validate_nr(sk, nr)) { x25_clear_queues(sk); x25_write_internal(sk, X25_RESET_REQUEST); x25_start_t22timer(sk); x25->condition = 0x00; x25->vs = 0; x25->vr = 0; x25->va = 0; x25->vl = 0; x25->state = X25_STATE_4; break; } x25_frames_acked(sk, nr); if (ns == x25->vr) { if (x25_queue_rx_frame(sk, skb, m) == 0) { x25->vr = (x25->vr + 1) % modulus; queued = 1; } else { /* Should never happen */ x25_clear_queues(sk); x25_write_internal(sk, X25_RESET_REQUEST); x25_start_t22timer(sk); x25->condition = 0x00; x25->vs = 0; x25->vr = 0; x25->va = 0; x25->vl = 0; x25->state = X25_STATE_4; break; } if (atomic_read(&sk->sk_rmem_alloc) > (sk->sk_rcvbuf / 2)) x25->condition |= X25_COND_OWN_RX_BUSY; } /* * If the window is full Ack it immediately, else * start the holdback timer. */ if (((x25->vl + x25->facilities.winsize_in) % modulus) == x25->vr) { x25->condition &= ~X25_COND_ACK_PENDING; x25_stop_timer(sk); x25_enquiry_response(sk); } else { x25->condition |= X25_COND_ACK_PENDING; x25_start_t2timer(sk); } break; case X25_INTERRUPT_CONFIRMATION: x25->intflag = 0; break; case X25_INTERRUPT: if (sock_flag(sk, SOCK_URGINLINE)) queued = !sock_queue_rcv_skb(sk, skb); else { skb_set_owner_r(skb, sk); skb_queue_tail(&x25->interrupt_in_queue, skb); queued = 1; } sk_send_sigurg(sk); x25_write_internal(sk, X25_INTERRUPT_CONFIRMATION); break; default: printk(KERN_WARNING "x25: unknown %02X in state 3\n", frametype); break; } return queued; }
/* * This is where all X.25 information frames pass. * * Returns the amount of user data bytes sent on success * or a negative error code on failure. */ int x25_output(struct sock *sk, struct sk_buff *skb) { struct sk_buff *skbn; unsigned char header[X25_EXT_MIN_LEN]; int err, frontlen, len; int sent=0, noblock = X25_SKB_CB(skb)->flags & MSG_DONTWAIT; struct x25_opt *x25 = x25_sk(sk); int header_len = x25->neighbour->extended ? X25_EXT_MIN_LEN : X25_STD_MIN_LEN; int max_len = x25_pacsize_to_bytes(x25->facilities.pacsize_out); if (skb->len - header_len > max_len) { /* Save a copy of the Header */ memcpy(header, skb->data, header_len); skb_pull(skb, header_len); frontlen = skb_headroom(skb); while (skb->len > 0) { if ((skbn = sock_alloc_send_skb(sk, frontlen + max_len, noblock, &err)) == NULL){ if (err == -EWOULDBLOCK && noblock){ kfree_skb(skb); return sent; } SOCK_DEBUG(sk, "x25_output: fragment alloc" " failed, err=%d, %d bytes " "sent\n", err, sent); return err; } skb_reserve(skbn, frontlen); len = max_len > skb->len ? skb->len : max_len; /* Copy the user data */ memcpy(skb_put(skbn, len), skb->data, len); skb_pull(skb, len); /* Duplicate the Header */ skb_push(skbn, header_len); memcpy(skbn->data, header, header_len); if (skb->len > 0) { if (x25->neighbour->extended) skbn->data[3] |= X25_EXT_M_BIT; else skbn->data[2] |= X25_STD_M_BIT; } skb_queue_tail(&sk->sk_write_queue, skbn); sent += len; } kfree_skb(skb); } else { skb_queue_tail(&sk->sk_write_queue, skb); sent = skb->len - header_len; } return sent; }
void x25_kick(struct sock *sk) { struct sk_buff *skb, *skbn; unsigned short start, end; int modulus; struct x25_opt *x25 = x25_sk(sk); if (x25->state != X25_STATE_3) return; /* * Transmit interrupt data. */ if (!x25->intflag && skb_peek(&x25->interrupt_out_queue) != NULL) { x25->intflag = 1; skb = skb_dequeue(&x25->interrupt_out_queue); x25_transmit_link(skb, x25->neighbour); } if (x25->condition & X25_COND_PEER_RX_BUSY) return; if (!skb_peek(&sk->sk_write_queue)) return; modulus = x25->neighbour->extended ? X25_EMODULUS : X25_SMODULUS; start = skb_peek(&x25->ack_queue) ? x25->vs : x25->va; end = (x25->va + x25->facilities.winsize_out) % modulus; if (start == end) return; x25->vs = start; /* * Transmit data until either we're out of data to send or * the window is full. */ skb = skb_dequeue(&sk->sk_write_queue); do { if ((skbn = skb_clone(skb, GFP_ATOMIC)) == NULL) { skb_queue_head(&sk->sk_write_queue, skb); break; } skb_set_owner_w(skbn, sk); /* * Transmit the frame copy. */ x25_send_iframe(sk, skbn); x25->vs = (x25->vs + 1) % modulus; /* * Requeue the original data frame. */ skb_queue_tail(&x25->ack_queue, skb); } while (x25->vs != end && (skb = skb_dequeue(&sk->sk_write_queue)) != NULL); x25->vl = x25->vr; x25->condition &= ~X25_COND_ACK_PENDING; x25_stop_timer(sk); }
void x25_stop_timer(struct sock *sk) { del_timer(&x25_sk(sk)->timer); }
void x25_start_t23timer(struct sock *sk) { struct x25_opt *x25 = x25_sk(sk); mod_timer(&x25->timer, jiffies + x25->t23); }