OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [net/] [sctp/] [inqueue.c] - Diff between revs 1275 and 1765

Only display areas with differences | Details | Blame | View Log

Rev 1275 Rev 1765
/* SCTP kernel reference Implementation
/* SCTP kernel reference Implementation
 * Copyright (c) 1999-2000 Cisco, Inc.
 * Copyright (c) 1999-2000 Cisco, Inc.
 * Copyright (c) 1999-2001 Motorola, Inc.
 * Copyright (c) 1999-2001 Motorola, Inc.
 * Copyright (c) 2002 International Business Machines, Corp.
 * Copyright (c) 2002 International Business Machines, Corp.
 *
 *
 * This file is part of the SCTP kernel reference Implementation
 * This file is part of the SCTP kernel reference Implementation
 *
 *
 * These functions are the methods for accessing the SCTP inqueue.
 * These functions are the methods for accessing the SCTP inqueue.
 *
 *
 * An SCTP inqueue is a queue into which you push SCTP packets
 * An SCTP inqueue is a queue into which you push SCTP packets
 * (which might be bundles or fragments of chunks) and out of which you
 * (which might be bundles or fragments of chunks) and out of which you
 * pop SCTP whole chunks.
 * pop SCTP whole chunks.
 *
 *
 * The SCTP reference implementation is free software;
 * The SCTP reference implementation is free software;
 * you can redistribute it and/or modify it under the terms of
 * you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by
 * the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 * any later version.
 *
 *
 * The SCTP reference implementation is distributed in the hope that it
 * The SCTP reference implementation is distributed in the hope that it
 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
 *                 ************************
 *                 ************************
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * See the GNU General Public License for more details.
 *
 *
 * You should have received a copy of the GNU General Public License
 * You should have received a copy of the GNU General Public License
 * along with GNU CC; see the file COPYING.  If not, write to
 * along with GNU CC; see the file COPYING.  If not, write to
 * the Free Software Foundation, 59 Temple Place - Suite 330,
 * the Free Software Foundation, 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 * Boston, MA 02111-1307, USA.
 *
 *
 * Please send any bug reports or fixes you make to the
 * Please send any bug reports or fixes you make to the
 * email address(es):
 * email address(es):
 *    lksctp developers <lksctp-developers@lists.sourceforge.net>
 *    lksctp developers <lksctp-developers@lists.sourceforge.net>
 *
 *
 * Or submit a bug report through the following website:
 * Or submit a bug report through the following website:
 *    http://www.sf.net/projects/lksctp
 *    http://www.sf.net/projects/lksctp
 *
 *
 * Written or modified by:
 * Written or modified by:
 *    La Monte H.P. Yarroll <piggy@acm.org>
 *    La Monte H.P. Yarroll <piggy@acm.org>
 *    Karl Knutson <karl@athena.chicago.il.us>
 *    Karl Knutson <karl@athena.chicago.il.us>
 *
 *
 * Any bugs reported given to us we will try to fix... any fixes shared will
 * Any bugs reported given to us we will try to fix... any fixes shared will
 * be incorporated into the next SCTP release.
 * be incorporated into the next SCTP release.
 */
 */
 
 
#include <net/sctp/sctp.h>
#include <net/sctp/sctp.h>
#include <net/sctp/sm.h>
#include <net/sctp/sm.h>
#include <linux/interrupt.h>
#include <linux/interrupt.h>
 
 
/* Initialize an SCTP inqueue.  */
/* Initialize an SCTP inqueue.  */
void sctp_inq_init(struct sctp_inq *queue)
void sctp_inq_init(struct sctp_inq *queue)
{
{
        skb_queue_head_init(&queue->in);
        skb_queue_head_init(&queue->in);
        queue->in_progress = NULL;
        queue->in_progress = NULL;
 
 
        /* Create a task for delivering data.  */
        /* Create a task for delivering data.  */
        INIT_LIST_HEAD(&queue->immediate.list);
        INIT_LIST_HEAD(&queue->immediate.list);
        queue->immediate.sync = 0;
        queue->immediate.sync = 0;
        queue->immediate.routine = NULL;
        queue->immediate.routine = NULL;
        queue->immediate.data = NULL;
        queue->immediate.data = NULL;
 
 
        queue->malloced = 0;
        queue->malloced = 0;
}
}
 
 
/* Create an initialized sctp_inq.  */
/* Create an initialized sctp_inq.  */
struct sctp_inq *sctp_inq_new(void)
struct sctp_inq *sctp_inq_new(void)
{
{
        struct sctp_inq *retval;
        struct sctp_inq *retval;
 
 
        retval = t_new(struct sctp_inq, GFP_ATOMIC);
        retval = t_new(struct sctp_inq, GFP_ATOMIC);
        if (retval) {
        if (retval) {
                sctp_inq_init(retval);
                sctp_inq_init(retval);
                retval->malloced = 1;
                retval->malloced = 1;
        }
        }
        return retval;
        return retval;
}
}
 
 
/* Release the memory associated with an SCTP inqueue.  */
/* Release the memory associated with an SCTP inqueue.  */
void sctp_inq_free(struct sctp_inq *queue)
void sctp_inq_free(struct sctp_inq *queue)
{
{
        struct sctp_chunk *chunk;
        struct sctp_chunk *chunk;
 
 
        /* Empty the queue.  */
        /* Empty the queue.  */
        while ((chunk = (struct sctp_chunk *) skb_dequeue(&queue->in)))
        while ((chunk = (struct sctp_chunk *) skb_dequeue(&queue->in)))
                sctp_chunk_free(chunk);
                sctp_chunk_free(chunk);
 
 
        /* If there is a packet which is currently being worked on,
        /* If there is a packet which is currently being worked on,
         * free it as well.
         * free it as well.
         */
         */
        if (queue->in_progress)
        if (queue->in_progress)
                sctp_chunk_free(queue->in_progress);
                sctp_chunk_free(queue->in_progress);
 
 
        if (queue->malloced) {
        if (queue->malloced) {
                /* Dump the master memory segment.  */
                /* Dump the master memory segment.  */
                kfree(queue);
                kfree(queue);
        }
        }
}
}
 
 
/* Put a new packet in an SCTP inqueue.
/* Put a new packet in an SCTP inqueue.
 * We assume that packet->sctp_hdr is set and in host byte order.
 * We assume that packet->sctp_hdr is set and in host byte order.
 */
 */
void sctp_inq_push(struct sctp_inq *q, struct sctp_chunk *packet)
void sctp_inq_push(struct sctp_inq *q, struct sctp_chunk *packet)
{
{
        /* Directly call the packet handling routine. */
        /* Directly call the packet handling routine. */
 
 
        /* We are now calling this either from the soft interrupt
        /* We are now calling this either from the soft interrupt
         * or from the backlog processing.
         * or from the backlog processing.
         * Eventually, we should clean up inqueue to not rely
         * Eventually, we should clean up inqueue to not rely
         * on the BH related data structures.
         * on the BH related data structures.
         */
         */
        skb_queue_tail(&(q->in), (struct sk_buff *) packet);
        skb_queue_tail(&(q->in), (struct sk_buff *) packet);
        q->immediate.routine(q->immediate.data);
        q->immediate.routine(q->immediate.data);
}
}
 
 
/* Extract a chunk from an SCTP inqueue.
/* Extract a chunk from an SCTP inqueue.
 *
 *
 * WARNING:  If you need to put the chunk on another queue, you need to
 * WARNING:  If you need to put the chunk on another queue, you need to
 * make a shallow copy (clone) of it.
 * make a shallow copy (clone) of it.
 */
 */
struct sctp_chunk *sctp_inq_pop(struct sctp_inq *queue)
struct sctp_chunk *sctp_inq_pop(struct sctp_inq *queue)
{
{
        struct sctp_chunk *chunk;
        struct sctp_chunk *chunk;
        sctp_chunkhdr_t *ch = NULL;
        sctp_chunkhdr_t *ch = NULL;
 
 
        /* The assumption is that we are safe to process the chunks
        /* The assumption is that we are safe to process the chunks
         * at this time.
         * at this time.
         */
         */
 
 
        if ((chunk = queue->in_progress)) {
        if ((chunk = queue->in_progress)) {
                /* There is a packet that we have been working on.
                /* There is a packet that we have been working on.
                 * Any post processing work to do before we move on?
                 * Any post processing work to do before we move on?
                 */
                 */
                if (chunk->singleton ||
                if (chunk->singleton ||
                    chunk->end_of_packet ||
                    chunk->end_of_packet ||
                    chunk->pdiscard) {
                    chunk->pdiscard) {
                        sctp_chunk_free(chunk);
                        sctp_chunk_free(chunk);
                        chunk = queue->in_progress = NULL;
                        chunk = queue->in_progress = NULL;
                } else {
                } else {
                        /* Nothing to do. Next chunk in the packet, please. */
                        /* Nothing to do. Next chunk in the packet, please. */
                        ch = (sctp_chunkhdr_t *) chunk->chunk_end;
                        ch = (sctp_chunkhdr_t *) chunk->chunk_end;
 
 
                        /* Force chunk->skb->data to chunk->chunk_end.  */
                        /* Force chunk->skb->data to chunk->chunk_end.  */
                        skb_pull(chunk->skb,
                        skb_pull(chunk->skb,
                                 chunk->chunk_end - chunk->skb->data);
                                 chunk->chunk_end - chunk->skb->data);
                }
                }
        }
        }
 
 
        /* Do we need to take the next packet out of the queue to process? */
        /* Do we need to take the next packet out of the queue to process? */
        if (!chunk) {
        if (!chunk) {
                /* Is the queue empty?  */
                /* Is the queue empty?  */
                if (skb_queue_empty(&queue->in))
                if (skb_queue_empty(&queue->in))
                        return NULL;
                        return NULL;
 
 
                chunk = queue->in_progress =
                chunk = queue->in_progress =
                        (struct sctp_chunk *) skb_dequeue(&queue->in);
                        (struct sctp_chunk *) skb_dequeue(&queue->in);
 
 
                /* This is the first chunk in the packet.  */
                /* This is the first chunk in the packet.  */
                chunk->singleton = 1;
                chunk->singleton = 1;
                ch = (sctp_chunkhdr_t *) chunk->skb->data;
                ch = (sctp_chunkhdr_t *) chunk->skb->data;
        }
        }
 
 
        chunk->chunk_hdr = ch;
        chunk->chunk_hdr = ch;
        chunk->chunk_end = ((__u8 *) ch)
        chunk->chunk_end = ((__u8 *) ch)
                + WORD_ROUND(ntohs(ch->length));
                + WORD_ROUND(ntohs(ch->length));
        skb_pull(chunk->skb, sizeof(sctp_chunkhdr_t));
        skb_pull(chunk->skb, sizeof(sctp_chunkhdr_t));
        chunk->subh.v = NULL; /* Subheader is no longer valid.  */
        chunk->subh.v = NULL; /* Subheader is no longer valid.  */
 
 
        if (chunk->chunk_end < chunk->skb->tail) {
        if (chunk->chunk_end < chunk->skb->tail) {
                /* This is not a singleton */
                /* This is not a singleton */
                chunk->singleton = 0;
                chunk->singleton = 0;
        } else {
        } else {
                /* We are at the end of the packet, so mark the chunk
                /* We are at the end of the packet, so mark the chunk
                 * in case we need to send a SACK.
                 * in case we need to send a SACK.
                 */
                 */
                chunk->end_of_packet = 1;
                chunk->end_of_packet = 1;
        }
        }
 
 
        SCTP_DEBUG_PRINTK("+++sctp_inq_pop+++ chunk %p[%s],"
        SCTP_DEBUG_PRINTK("+++sctp_inq_pop+++ chunk %p[%s],"
                          " length %d, skb->len %d\n",chunk,
                          " length %d, skb->len %d\n",chunk,
                          sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)),
                          sctp_cname(SCTP_ST_CHUNK(chunk->chunk_hdr->type)),
                          ntohs(chunk->chunk_hdr->length), chunk->skb->len);
                          ntohs(chunk->chunk_hdr->length), chunk->skb->len);
        return chunk;
        return chunk;
}
}
 
 
/* Set a top-half handler.
/* Set a top-half handler.
 *
 *
 * Originally, we the top-half handler was scheduled as a BH.  We now
 * Originally, we the top-half handler was scheduled as a BH.  We now
 * call the handler directly in sctp_inq_push() at a time that
 * call the handler directly in sctp_inq_push() at a time that
 * we know we are lock safe.
 * we know we are lock safe.
 * The intent is that this routine will pull stuff out of the
 * The intent is that this routine will pull stuff out of the
 * inqueue and process it.
 * inqueue and process it.
 */
 */
void sctp_inq_set_th_handler(struct sctp_inq *q,
void sctp_inq_set_th_handler(struct sctp_inq *q,
                                 void (*callback)(void *), void *arg)
                                 void (*callback)(void *), void *arg)
{
{
        q->immediate.routine = callback;
        q->immediate.routine = callback;
        q->immediate.data = arg;
        q->immediate.data = arg;
}
}
 
 
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.