1 /* SCTP kernel implementation
2 * Copyright (c) 2003 International Business Machines, Corp.
4 * This file is part of the SCTP kernel implementation
6 * These functions manipulate sctp SSN tracker.
8 * This SCTP implementation is free software;
9 * you can redistribute it and/or modify it under the terms of
10 * the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
14 * This SCTP implementation is distributed in the hope that it
15 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
16 * ************************
17 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 * See the GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with GNU CC; see the file COPYING. If not, write to
22 * the Free Software Foundation, 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
25 * Please send any bug reports or fixes you make to the
27 * lksctp developers <linux-sctp@vger.kernel.org>
29 * Written or modified by:
30 * Jon Grimm <jgrimm@us.ibm.com>
33 #include <linux/types.h>
34 #include <linux/slab.h>
35 #include <net/sctp/sctp.h>
36 #include <net/sctp/sm.h>
38 static struct sctp_ssnmap
*sctp_ssnmap_init(struct sctp_ssnmap
*map
, __u16 in
,
41 /* Storage size needed for map includes 2 headers and then the
42 * specific needs of in or out streams.
44 static inline size_t sctp_ssnmap_size(__u16 in
, __u16 out
)
46 return sizeof(struct sctp_ssnmap
) + (in
+ out
) * sizeof(__u16
);
50 /* Create a new sctp_ssnmap.
51 * Allocate room to store at least 'len' contiguous TSNs.
53 struct sctp_ssnmap
*sctp_ssnmap_new(__u16 in
, __u16 out
,
56 struct sctp_ssnmap
*retval
;
59 size
= sctp_ssnmap_size(in
, out
);
60 if (size
<= KMALLOC_MAX_SIZE
)
61 retval
= kmalloc(size
, gfp
);
63 retval
= (struct sctp_ssnmap
*)
64 __get_free_pages(gfp
, get_order(size
));
68 if (!sctp_ssnmap_init(retval
, in
, out
))
71 SCTP_DBG_OBJCNT_INC(ssnmap
);
76 if (size
<= KMALLOC_MAX_SIZE
)
79 free_pages((unsigned long)retval
, get_order(size
));
85 /* Initialize a block of memory as a ssnmap. */
86 static struct sctp_ssnmap
*sctp_ssnmap_init(struct sctp_ssnmap
*map
, __u16 in
,
89 memset(map
, 0x00, sctp_ssnmap_size(in
, out
));
91 /* Start 'in' stream just after the map header. */
92 map
->in
.ssn
= (__u16
*)&map
[1];
95 /* Start 'out' stream just after 'in'. */
96 map
->out
.ssn
= &map
->in
.ssn
[in
];
102 /* Clear out the ssnmap streams. */
103 void sctp_ssnmap_clear(struct sctp_ssnmap
*map
)
107 size
= (map
->in
.len
+ map
->out
.len
) * sizeof(__u16
);
108 memset(map
->in
.ssn
, 0x00, size
);
111 /* Dispose of a ssnmap. */
112 void sctp_ssnmap_free(struct sctp_ssnmap
*map
)
119 size
= sctp_ssnmap_size(map
->in
.len
, map
->out
.len
);
120 if (size
<= KMALLOC_MAX_SIZE
)
123 free_pages((unsigned long)map
, get_order(size
));
125 SCTP_DBG_OBJCNT_DEC(ssnmap
);