]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - net/sctp/stream.c
Merge tag 'mac80211-next-for-davem-2017-01-13' of git://git.kernel.org/pub/scm/linux...
[mirror_ubuntu-artful-kernel.git] / net / sctp / stream.c
1 /* SCTP kernel implementation
2 * (C) Copyright IBM Corp. 2001, 2004
3 * Copyright (c) 1999-2000 Cisco, Inc.
4 * Copyright (c) 1999-2001 Motorola, Inc.
5 * Copyright (c) 2001 Intel Corp.
6 *
7 * This file is part of the SCTP kernel implementation
8 *
9 * These functions manipulate sctp tsn mapping array.
10 *
11 * This SCTP implementation is free software;
12 * you can redistribute it and/or modify it under the terms of
13 * the GNU General Public License as published by
14 * the Free Software Foundation; either version 2, or (at your option)
15 * any later version.
16 *
17 * This SCTP implementation is distributed in the hope that it
18 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
19 * ************************
20 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 * See the GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with GNU CC; see the file COPYING. If not, see
25 * <http://www.gnu.org/licenses/>.
26 *
27 * Please send any bug reports or fixes you make to the
28 * email address(es):
29 * lksctp developers <linux-sctp@vger.kernel.org>
30 *
31 * Written or modified by:
32 * Xin Long <lucien.xin@gmail.com>
33 */
34
35 #include <net/sctp/sctp.h>
36
37 struct sctp_stream *sctp_stream_new(__u16 incnt, __u16 outcnt, gfp_t gfp)
38 {
39 struct sctp_stream *stream;
40 int i;
41
42 stream = kzalloc(sizeof(*stream), gfp);
43 if (!stream)
44 return NULL;
45
46 stream->outcnt = outcnt;
47 stream->out = kcalloc(stream->outcnt, sizeof(*stream->out), gfp);
48 if (!stream->out) {
49 kfree(stream);
50 return NULL;
51 }
52 for (i = 0; i < stream->outcnt; i++)
53 stream->out[i].state = SCTP_STREAM_OPEN;
54
55 stream->incnt = incnt;
56 stream->in = kcalloc(stream->incnt, sizeof(*stream->in), gfp);
57 if (!stream->in) {
58 kfree(stream->out);
59 kfree(stream);
60 return NULL;
61 }
62
63 return stream;
64 }
65
66 void sctp_stream_free(struct sctp_stream *stream)
67 {
68 if (unlikely(!stream))
69 return;
70
71 kfree(stream->out);
72 kfree(stream->in);
73 kfree(stream);
74 }
75
76 void sctp_stream_clear(struct sctp_stream *stream)
77 {
78 int i;
79
80 for (i = 0; i < stream->outcnt; i++)
81 stream->out[i].ssn = 0;
82
83 for (i = 0; i < stream->incnt; i++)
84 stream->in[i].ssn = 0;
85 }