diff -r -U4 rp-l2tp-0.4/dgram.c rp-l2tp-0.4+pppcfgprio/dgram.c --- rp-l2tp-0.4/dgram.c 2003-01-11 05:29:03.000000000 +0000 +++ rp-l2tp-0.4+pppcfgprio/dgram.c 2009-11-08 15:34:31.000000000 +0000 @@ -1015,8 +1015,9 @@ { int r; unsigned char *real_buf = (unsigned char *) buf - 8; l2tp_tunnel *tunnel = ses->tunnel; + unsigned int protocol; /* Drop frame if tunnel and/or session in wrong state */ if (!tunnel || tunnel->state != TUNNEL_ESTABLISHED || @@ -1030,9 +1031,17 @@ tunnel->ack_handler = NULL; tunnel_send_ZLB(tunnel); } - real_buf[0] = 0; + /* Get protocol */ + if (buf[0] & 0x01) { + /* Compressed protcol field */ + protocol = buf[0]; + } else { + protocol = ((unsigned int) buf[0]) * 256 + buf[1]; + } + + real_buf[0] = (protocol < 0x8000) ? 0 : PRIORITY_BIT; real_buf[1] = 2; real_buf[2] = (tunnel->assigned_id >> 8); real_buf[3] = tunnel->assigned_id & 0xFF; real_buf[4] = ses->assigned_id >> 8; diff -r -U4 rp-l2tp-0.4/tunnel.c rp-l2tp-0.4+pppcfgprio/tunnel.c --- rp-l2tp-0.4/tunnel.c 2004-07-01 15:58:56.000000000 +0100 +++ rp-l2tp-0.4+pppcfgprio/tunnel.c 2009-11-08 15:35:26.000000000 +0000 @@ -196,26 +196,49 @@ static void tunnel_enqueue_dgram(l2tp_tunnel *tunnel, l2tp_dgram *dgram) { - dgram->next = NULL; - if (tunnel->xmit_queue_tail) { - tunnel->xmit_queue_tail->next = dgram; - tunnel->xmit_queue_tail = dgram; + if ((dgram->bits & (TYPE_BIT|PRIORITY_BIT)) == 0) { + dgram->next = NULL; + if (tunnel->xmit_queue_tail) { + tunnel->xmit_queue_tail->next = dgram; + tunnel->xmit_queue_tail = dgram; + } else { + tunnel->xmit_queue_head = dgram; + tunnel->xmit_queue_tail = dgram; + } } else { - tunnel->xmit_queue_head = dgram; - tunnel->xmit_queue_tail = dgram; + dgram->next = NULL; + if (tunnel->xmit_queue_head) { + l2tp_dgram *prev, *tmp; + + prev = NULL; + tmp = tunnel->xmit_queue_head; + while (tmp != NULL && (tmp->bits & (TYPE_BIT|PRIORITY_BIT)) != 0) { + prev = tmp; + tmp = tmp->next; + } + dgram->next = tmp; + if (prev == NULL) + tunnel->xmit_queue_head = dgram; + else + prev->next = dgram; + } else { + tunnel->xmit_queue_head = dgram; + tunnel->xmit_queue_tail = dgram; + } } if (!tunnel->xmit_new_dgrams) { tunnel->xmit_new_dgrams = dgram; } dgram->Ns = tunnel->Ns; tunnel->Ns++; - DBG(l2tp_db(DBG_FLOW, "tunnel_enqueue_dgram(%s, %s) %s\n", + DBG(l2tp_db(DBG_FLOW, "tunnel_enqueue_dgram(%s, %s) %s %d\n", l2tp_debug_tunnel_to_str(tunnel), l2tp_debug_message_type_to_str(dgram->msg_type), - tunnel_flow_control_stats(tunnel))); + tunnel_flow_control_stats(tunnel), + (dgram->bits & (TYPE_BIT|PRIORITY_BIT)) == 0 ? 0 : 1)); } /**********************************************************************