1 /* SCTP kernel reference Implementation
2  *
3  * (C) Copyright IBM Corp. 2004
4  * Copyright (c) 2003 Hewlett-Packard Company
5  *
6  * This file is part of the SCTP kernel reference Implementation
7  *
8  * This header represents the structures and constants needed to backport
9  * lksctp from Linux kernel 2.5 to 2.4 This file also has some code that
10  * has been taken from the source base of Linux kernel 2.5
11  *
12  * The SCTP reference implementation is free software;
13  * you can redistribute it and/or modify it under the terms of
14  * the GNU General Public License as published by
15  * the Free Software Foundation; either version 2, or (at your option)
16  * any later version.
17  *
18  * The SCTP reference implementation is distributed in the hope that it
19  * will be useful, but WITHOUT ANY WARRANTY; without even the implied
20  *                 ************************
21  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22  * See the GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with GNU CC; see the file COPYING.  If not, write to
26  * the Free Software Foundation, 59 Temple Place - Suite 330,
27  * Boston, MA 02111-1307, USA.
28  *
29  */
30 
31 #ifndef __net_sctp_compat_h__
32 #define __net_sctp_compat_h__
33 
34 #include <linux/version.h>
35 #include <linux/module.h>
36 #include <linux/poll.h>
37 #include <linux/seq_file.h>
38 
39 /*
40  * The following defines are for compatibility with 2.6
41  */
42 /*
43  * container_of - cast a member of a structure out to the containing structure
44  * @ptr:	the pointer to the member.
45  * @type:	the type of the container struct this is embedded in.
46  * @member:	the name of the member within the struct.
47  */
48 #define container_of(ptr, type, member) ({			\
49 	const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
50 	(type *)( (char *)__mptr - offsetof(type,member) );})
51 
52 #define DEFINE_SNMP_STAT(type, name)	\
53 	type name[NR_CPUS * 2]
54 #define DECLARE_SNMP_STAT(type, name)	\
55 	extern type name[]
56 #define SNMP_DEC_STATS(mib, field) ((mib)[2*smp_processor_id()+!in_softirq()].field--)
57 
58 #define inet_sk(__sk) (&(((struct sock *)__sk)->protinfo.af_inet))
59 #define inet6_sk(__sk) (&(((struct sock *)__sk)->net_pinfo.af_inet6))
60 
61 #define virt_addr_valid(x)	VALID_PAGE(virt_to_page((x)))
62 #define sock_owned_by_user(sk)  ((sk)->lock.users)
63 #define sk_set_owner(x, y)
64 #define __unsafe(x)
65 #define dst_pmtu(x) ((x)->pmtu)
66 
67 /*
68  * find last bit set.
69  */
fls(int x)70 static __inline__ int fls(int x)
71 {
72 	int r = 32;
73 
74 	if (!x)
75 		return 0;
76 	if (!(x & 0xffff0000u)) {
77 		x <<= 16;
78 		r -= 16;
79 	}
80 	if (!(x & 0xff000000u)) {
81 		x <<= 8;
82 		r -= 8;
83 	}
84 	if (!(x & 0xf0000000u)) {
85 		x <<= 4;
86 		r -= 4;
87 	}
88 	if (!(x & 0xc0000000u)) {
89 		x <<= 2;
90 		r -= 2;
91 	}
92 	if (!(x & 0x80000000u)) {
93 		x <<= 1;
94 		r -= 1;
95 	}
96 	return r;
97 }
98 
99 #endif /* __net_sctp_compat_h__ */
100