Commit 161643660129dd7d98f0b12418c0a2710ffa7db6
Committed by
David S. Miller
1 parent
7198f8cec1
Exists in
master
and in
7 other branches
[SCTP]: Cleanups
This patch contains the following cleanups: - make the following needlessly global function static: - socket.c: sctp_apply_peer_addr_params() - add proper prototypes for the several global functions in include/net/sctp/sctp.h Note that this fixes wrong prototypes for the following functions: - sctp_snmp_proc_exit() - sctp_eps_proc_exit() - sctp_assocs_proc_exit() The latter was spotted by the GNU C compiler and reported by David Woodhouse. Signed-off-by: Adrian Bunk <bunk@stusta.de> Acked-by: Sridhar Samudrala <sri@us.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Showing 4 changed files with 20 additions and 15 deletions Inline Diff
include/net/sctp/sctp.h
1 | /* SCTP kernel reference Implementation | 1 | /* SCTP kernel reference Implementation |
2 | * (C) Copyright IBM Corp. 2001, 2004 | 2 | * (C) Copyright IBM Corp. 2001, 2004 |
3 | * Copyright (c) 1999-2000 Cisco, Inc. | 3 | * Copyright (c) 1999-2000 Cisco, Inc. |
4 | * Copyright (c) 1999-2001 Motorola, Inc. | 4 | * Copyright (c) 1999-2001 Motorola, Inc. |
5 | * Copyright (c) 2001-2003 Intel Corp. | 5 | * Copyright (c) 2001-2003 Intel Corp. |
6 | * | 6 | * |
7 | * This file is part of the SCTP kernel reference Implementation | 7 | * This file is part of the SCTP kernel reference Implementation |
8 | * | 8 | * |
9 | * The base lksctp header. | 9 | * The base lksctp header. |
10 | * | 10 | * |
11 | * The SCTP reference implementation is free software; | 11 | * The SCTP reference implementation is free software; |
12 | * you can redistribute it and/or modify it under the terms of | 12 | * you can redistribute it and/or modify it under the terms of |
13 | * the GNU General Public License as published by | 13 | * the GNU General Public License as published by |
14 | * the Free Software Foundation; either version 2, or (at your option) | 14 | * the Free Software Foundation; either version 2, or (at your option) |
15 | * any later version. | 15 | * any later version. |
16 | * | 16 | * |
17 | * The SCTP reference implementation is distributed in the hope that it | 17 | * The SCTP reference implementation is distributed in the hope that it |
18 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied | 18 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied |
19 | * ************************ | 19 | * ************************ |
20 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 20 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
21 | * See the GNU General Public License for more details. | 21 | * See the GNU General Public License for more details. |
22 | * | 22 | * |
23 | * You should have received a copy of the GNU General Public License | 23 | * You should have received a copy of the GNU General Public License |
24 | * along with GNU CC; see the file COPYING. If not, write to | 24 | * along with GNU CC; see the file COPYING. If not, write to |
25 | * the Free Software Foundation, 59 Temple Place - Suite 330, | 25 | * the Free Software Foundation, 59 Temple Place - Suite 330, |
26 | * Boston, MA 02111-1307, USA. | 26 | * Boston, MA 02111-1307, USA. |
27 | * | 27 | * |
28 | * Please send any bug reports or fixes you make to the | 28 | * Please send any bug reports or fixes you make to the |
29 | * email address(es): | 29 | * email address(es): |
30 | * lksctp developers <lksctp-developers@lists.sourceforge.net> | 30 | * lksctp developers <lksctp-developers@lists.sourceforge.net> |
31 | * | 31 | * |
32 | * Or submit a bug report through the following website: | 32 | * Or submit a bug report through the following website: |
33 | * http://www.sf.net/projects/lksctp | 33 | * http://www.sf.net/projects/lksctp |
34 | * | 34 | * |
35 | * Written or modified by: | 35 | * Written or modified by: |
36 | * La Monte H.P. Yarroll <piggy@acm.org> | 36 | * La Monte H.P. Yarroll <piggy@acm.org> |
37 | * Xingang Guo <xingang.guo@intel.com> | 37 | * Xingang Guo <xingang.guo@intel.com> |
38 | * Jon Grimm <jgrimm@us.ibm.com> | 38 | * Jon Grimm <jgrimm@us.ibm.com> |
39 | * Daisy Chang <daisyc@us.ibm.com> | 39 | * Daisy Chang <daisyc@us.ibm.com> |
40 | * Sridhar Samudrala <sri@us.ibm.com> | 40 | * Sridhar Samudrala <sri@us.ibm.com> |
41 | * Ardelle Fan <ardelle.fan@intel.com> | 41 | * Ardelle Fan <ardelle.fan@intel.com> |
42 | * Ryan Layer <rmlayer@us.ibm.com> | 42 | * Ryan Layer <rmlayer@us.ibm.com> |
43 | * Kevin Gao <kevin.gao@intel.com> | 43 | * Kevin Gao <kevin.gao@intel.com> |
44 | * | 44 | * |
45 | * Any bugs reported given to us we will try to fix... any fixes shared will | 45 | * Any bugs reported given to us we will try to fix... any fixes shared will |
46 | * be incorporated into the next SCTP release. | 46 | * be incorporated into the next SCTP release. |
47 | */ | 47 | */ |
48 | 48 | ||
49 | #ifndef __net_sctp_h__ | 49 | #ifndef __net_sctp_h__ |
50 | #define __net_sctp_h__ | 50 | #define __net_sctp_h__ |
51 | 51 | ||
52 | /* Header Strategy. | 52 | /* Header Strategy. |
53 | * Start getting some control over the header file depencies: | 53 | * Start getting some control over the header file depencies: |
54 | * includes | 54 | * includes |
55 | * constants | 55 | * constants |
56 | * structs | 56 | * structs |
57 | * prototypes | 57 | * prototypes |
58 | * macros, externs, and inlines | 58 | * macros, externs, and inlines |
59 | * | 59 | * |
60 | * Move test_frame specific items out of the kernel headers | 60 | * Move test_frame specific items out of the kernel headers |
61 | * and into the test frame headers. This is not perfect in any sense | 61 | * and into the test frame headers. This is not perfect in any sense |
62 | * and will continue to evolve. | 62 | * and will continue to evolve. |
63 | */ | 63 | */ |
64 | 64 | ||
65 | 65 | ||
66 | 66 | ||
67 | #ifdef TEST_FRAME | 67 | #ifdef TEST_FRAME |
68 | #undef CONFIG_PROC_FS | 68 | #undef CONFIG_PROC_FS |
69 | #undef CONFIG_SCTP_DBG_OBJCNT | 69 | #undef CONFIG_SCTP_DBG_OBJCNT |
70 | #undef CONFIG_SYSCTL | 70 | #undef CONFIG_SYSCTL |
71 | #endif /* TEST_FRAME */ | 71 | #endif /* TEST_FRAME */ |
72 | 72 | ||
73 | #include <linux/types.h> | 73 | #include <linux/types.h> |
74 | #include <linux/slab.h> | 74 | #include <linux/slab.h> |
75 | #include <linux/in.h> | 75 | #include <linux/in.h> |
76 | #include <linux/tty.h> | 76 | #include <linux/tty.h> |
77 | #include <linux/proc_fs.h> | 77 | #include <linux/proc_fs.h> |
78 | #include <linux/spinlock.h> | 78 | #include <linux/spinlock.h> |
79 | #include <linux/jiffies.h> | 79 | #include <linux/jiffies.h> |
80 | #include <linux/idr.h> | 80 | #include <linux/idr.h> |
81 | 81 | ||
82 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | 82 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
83 | #include <net/ipv6.h> | 83 | #include <net/ipv6.h> |
84 | #include <net/ip6_route.h> | 84 | #include <net/ip6_route.h> |
85 | #endif | 85 | #endif |
86 | 86 | ||
87 | #include <asm/uaccess.h> | 87 | #include <asm/uaccess.h> |
88 | #include <asm/page.h> | 88 | #include <asm/page.h> |
89 | #include <net/sock.h> | 89 | #include <net/sock.h> |
90 | #include <net/snmp.h> | 90 | #include <net/snmp.h> |
91 | #include <net/sctp/structs.h> | 91 | #include <net/sctp/structs.h> |
92 | #include <net/sctp/constants.h> | 92 | #include <net/sctp/constants.h> |
93 | 93 | ||
94 | 94 | ||
95 | /* Set SCTP_DEBUG flag via config if not already set. */ | 95 | /* Set SCTP_DEBUG flag via config if not already set. */ |
96 | #ifndef SCTP_DEBUG | 96 | #ifndef SCTP_DEBUG |
97 | #ifdef CONFIG_SCTP_DBG_MSG | 97 | #ifdef CONFIG_SCTP_DBG_MSG |
98 | #define SCTP_DEBUG 1 | 98 | #define SCTP_DEBUG 1 |
99 | #else | 99 | #else |
100 | #define SCTP_DEBUG 0 | 100 | #define SCTP_DEBUG 0 |
101 | #endif /* CONFIG_SCTP_DBG */ | 101 | #endif /* CONFIG_SCTP_DBG */ |
102 | #endif /* SCTP_DEBUG */ | 102 | #endif /* SCTP_DEBUG */ |
103 | 103 | ||
104 | #ifdef CONFIG_IP_SCTP_MODULE | 104 | #ifdef CONFIG_IP_SCTP_MODULE |
105 | #define SCTP_PROTOSW_FLAG 0 | 105 | #define SCTP_PROTOSW_FLAG 0 |
106 | #else /* static! */ | 106 | #else /* static! */ |
107 | #define SCTP_PROTOSW_FLAG INET_PROTOSW_PERMANENT | 107 | #define SCTP_PROTOSW_FLAG INET_PROTOSW_PERMANENT |
108 | #endif | 108 | #endif |
109 | 109 | ||
110 | 110 | ||
111 | /* Certain internal static functions need to be exported when | 111 | /* Certain internal static functions need to be exported when |
112 | * compiled into the test frame. | 112 | * compiled into the test frame. |
113 | */ | 113 | */ |
114 | #ifndef SCTP_STATIC | 114 | #ifndef SCTP_STATIC |
115 | #define SCTP_STATIC static | 115 | #define SCTP_STATIC static |
116 | #endif | 116 | #endif |
117 | 117 | ||
118 | /* | 118 | /* |
119 | * Function declarations. | 119 | * Function declarations. |
120 | */ | 120 | */ |
121 | 121 | ||
122 | /* | 122 | /* |
123 | * sctp/protocol.c | 123 | * sctp/protocol.c |
124 | */ | 124 | */ |
125 | extern struct sock *sctp_get_ctl_sock(void); | 125 | extern struct sock *sctp_get_ctl_sock(void); |
126 | extern int sctp_copy_local_addr_list(struct sctp_bind_addr *, | 126 | extern int sctp_copy_local_addr_list(struct sctp_bind_addr *, |
127 | sctp_scope_t, gfp_t gfp, | 127 | sctp_scope_t, gfp_t gfp, |
128 | int flags); | 128 | int flags); |
129 | extern struct sctp_pf *sctp_get_pf_specific(sa_family_t family); | 129 | extern struct sctp_pf *sctp_get_pf_specific(sa_family_t family); |
130 | extern int sctp_register_pf(struct sctp_pf *, sa_family_t); | 130 | extern int sctp_register_pf(struct sctp_pf *, sa_family_t); |
131 | int sctp_inetaddr_event(struct notifier_block *this, unsigned long ev, | ||
132 | void *ptr); | ||
131 | 133 | ||
132 | /* | 134 | /* |
133 | * sctp/socket.c | 135 | * sctp/socket.c |
134 | */ | 136 | */ |
135 | int sctp_backlog_rcv(struct sock *sk, struct sk_buff *skb); | 137 | int sctp_backlog_rcv(struct sock *sk, struct sk_buff *skb); |
136 | int sctp_inet_listen(struct socket *sock, int backlog); | 138 | int sctp_inet_listen(struct socket *sock, int backlog); |
137 | void sctp_write_space(struct sock *sk); | 139 | void sctp_write_space(struct sock *sk); |
138 | unsigned int sctp_poll(struct file *file, struct socket *sock, | 140 | unsigned int sctp_poll(struct file *file, struct socket *sock, |
139 | poll_table *wait); | 141 | poll_table *wait); |
140 | 142 | ||
141 | /* | 143 | /* |
142 | * sctp/primitive.c | 144 | * sctp/primitive.c |
143 | */ | 145 | */ |
144 | int sctp_primitive_ASSOCIATE(struct sctp_association *, void *arg); | 146 | int sctp_primitive_ASSOCIATE(struct sctp_association *, void *arg); |
145 | int sctp_primitive_SHUTDOWN(struct sctp_association *, void *arg); | 147 | int sctp_primitive_SHUTDOWN(struct sctp_association *, void *arg); |
146 | int sctp_primitive_ABORT(struct sctp_association *, void *arg); | 148 | int sctp_primitive_ABORT(struct sctp_association *, void *arg); |
147 | int sctp_primitive_SEND(struct sctp_association *, void *arg); | 149 | int sctp_primitive_SEND(struct sctp_association *, void *arg); |
148 | int sctp_primitive_REQUESTHEARTBEAT(struct sctp_association *, void *arg); | 150 | int sctp_primitive_REQUESTHEARTBEAT(struct sctp_association *, void *arg); |
149 | int sctp_primitive_ASCONF(struct sctp_association *, void *arg); | 151 | int sctp_primitive_ASCONF(struct sctp_association *, void *arg); |
150 | 152 | ||
151 | /* | 153 | /* |
152 | * sctp/crc32c.c | 154 | * sctp/crc32c.c |
153 | */ | 155 | */ |
154 | __u32 sctp_start_cksum(__u8 *ptr, __u16 count); | 156 | __u32 sctp_start_cksum(__u8 *ptr, __u16 count); |
155 | __u32 sctp_update_cksum(__u8 *ptr, __u16 count, __u32 cksum); | 157 | __u32 sctp_update_cksum(__u8 *ptr, __u16 count, __u32 cksum); |
156 | __u32 sctp_end_cksum(__u32 cksum); | 158 | __u32 sctp_end_cksum(__u32 cksum); |
157 | __u32 sctp_update_copy_cksum(__u8 *, __u8 *, __u16 count, __u32 cksum); | 159 | __u32 sctp_update_copy_cksum(__u8 *, __u8 *, __u16 count, __u32 cksum); |
158 | 160 | ||
159 | /* | 161 | /* |
160 | * sctp/input.c | 162 | * sctp/input.c |
161 | */ | 163 | */ |
162 | int sctp_rcv(struct sk_buff *skb); | 164 | int sctp_rcv(struct sk_buff *skb); |
163 | void sctp_v4_err(struct sk_buff *skb, u32 info); | 165 | void sctp_v4_err(struct sk_buff *skb, u32 info); |
164 | void sctp_hash_established(struct sctp_association *); | 166 | void sctp_hash_established(struct sctp_association *); |
165 | void sctp_unhash_established(struct sctp_association *); | 167 | void sctp_unhash_established(struct sctp_association *); |
166 | void sctp_hash_endpoint(struct sctp_endpoint *); | 168 | void sctp_hash_endpoint(struct sctp_endpoint *); |
167 | void sctp_unhash_endpoint(struct sctp_endpoint *); | 169 | void sctp_unhash_endpoint(struct sctp_endpoint *); |
168 | struct sock *sctp_err_lookup(int family, struct sk_buff *, | 170 | struct sock *sctp_err_lookup(int family, struct sk_buff *, |
169 | struct sctphdr *, struct sctp_association **, | 171 | struct sctphdr *, struct sctp_association **, |
170 | struct sctp_transport **); | 172 | struct sctp_transport **); |
171 | void sctp_err_finish(struct sock *, struct sctp_association *); | 173 | void sctp_err_finish(struct sock *, struct sctp_association *); |
172 | void sctp_icmp_frag_needed(struct sock *, struct sctp_association *, | 174 | void sctp_icmp_frag_needed(struct sock *, struct sctp_association *, |
173 | struct sctp_transport *t, __u32 pmtu); | 175 | struct sctp_transport *t, __u32 pmtu); |
174 | void sctp_icmp_proto_unreachable(struct sock *sk, | 176 | void sctp_icmp_proto_unreachable(struct sock *sk, |
175 | struct sctp_association *asoc, | 177 | struct sctp_association *asoc, |
176 | struct sctp_transport *t); | 178 | struct sctp_transport *t); |
177 | void sctp_backlog_migrate(struct sctp_association *assoc, | 179 | void sctp_backlog_migrate(struct sctp_association *assoc, |
178 | struct sock *oldsk, struct sock *newsk); | 180 | struct sock *oldsk, struct sock *newsk); |
181 | |||
182 | /* | ||
183 | * sctp/proc.c | ||
184 | */ | ||
185 | int sctp_snmp_proc_init(void); | ||
186 | void sctp_snmp_proc_exit(void); | ||
187 | int sctp_eps_proc_init(void); | ||
188 | void sctp_eps_proc_exit(void); | ||
189 | int sctp_assocs_proc_init(void); | ||
190 | void sctp_assocs_proc_exit(void); | ||
191 | |||
179 | 192 | ||
180 | /* | 193 | /* |
181 | * Section: Macros, externs, and inlines | 194 | * Section: Macros, externs, and inlines |
182 | */ | 195 | */ |
183 | 196 | ||
184 | 197 | ||
185 | #ifdef TEST_FRAME | 198 | #ifdef TEST_FRAME |
186 | #include <test_frame.h> | 199 | #include <test_frame.h> |
187 | #else | 200 | #else |
188 | 201 | ||
189 | /* spin lock wrappers. */ | 202 | /* spin lock wrappers. */ |
190 | #define sctp_spin_lock_irqsave(lock, flags) spin_lock_irqsave(lock, flags) | 203 | #define sctp_spin_lock_irqsave(lock, flags) spin_lock_irqsave(lock, flags) |
191 | #define sctp_spin_unlock_irqrestore(lock, flags) \ | 204 | #define sctp_spin_unlock_irqrestore(lock, flags) \ |
192 | spin_unlock_irqrestore(lock, flags) | 205 | spin_unlock_irqrestore(lock, flags) |
193 | #define sctp_local_bh_disable() local_bh_disable() | 206 | #define sctp_local_bh_disable() local_bh_disable() |
194 | #define sctp_local_bh_enable() local_bh_enable() | 207 | #define sctp_local_bh_enable() local_bh_enable() |
195 | #define sctp_spin_lock(lock) spin_lock(lock) | 208 | #define sctp_spin_lock(lock) spin_lock(lock) |
196 | #define sctp_spin_unlock(lock) spin_unlock(lock) | 209 | #define sctp_spin_unlock(lock) spin_unlock(lock) |
197 | #define sctp_write_lock(lock) write_lock(lock) | 210 | #define sctp_write_lock(lock) write_lock(lock) |
198 | #define sctp_write_unlock(lock) write_unlock(lock) | 211 | #define sctp_write_unlock(lock) write_unlock(lock) |
199 | #define sctp_read_lock(lock) read_lock(lock) | 212 | #define sctp_read_lock(lock) read_lock(lock) |
200 | #define sctp_read_unlock(lock) read_unlock(lock) | 213 | #define sctp_read_unlock(lock) read_unlock(lock) |
201 | 214 | ||
202 | /* sock lock wrappers. */ | 215 | /* sock lock wrappers. */ |
203 | #define sctp_lock_sock(sk) lock_sock(sk) | 216 | #define sctp_lock_sock(sk) lock_sock(sk) |
204 | #define sctp_release_sock(sk) release_sock(sk) | 217 | #define sctp_release_sock(sk) release_sock(sk) |
205 | #define sctp_bh_lock_sock(sk) bh_lock_sock(sk) | 218 | #define sctp_bh_lock_sock(sk) bh_lock_sock(sk) |
206 | #define sctp_bh_unlock_sock(sk) bh_unlock_sock(sk) | 219 | #define sctp_bh_unlock_sock(sk) bh_unlock_sock(sk) |
207 | #define SCTP_SOCK_SLEEP_PRE(sk) SOCK_SLEEP_PRE(sk) | 220 | #define SCTP_SOCK_SLEEP_PRE(sk) SOCK_SLEEP_PRE(sk) |
208 | #define SCTP_SOCK_SLEEP_POST(sk) SOCK_SLEEP_POST(sk) | 221 | #define SCTP_SOCK_SLEEP_POST(sk) SOCK_SLEEP_POST(sk) |
209 | 222 | ||
210 | /* SCTP SNMP MIB stats handlers */ | 223 | /* SCTP SNMP MIB stats handlers */ |
211 | DECLARE_SNMP_STAT(struct sctp_mib, sctp_statistics); | 224 | DECLARE_SNMP_STAT(struct sctp_mib, sctp_statistics); |
212 | #define SCTP_INC_STATS(field) SNMP_INC_STATS(sctp_statistics, field) | 225 | #define SCTP_INC_STATS(field) SNMP_INC_STATS(sctp_statistics, field) |
213 | #define SCTP_INC_STATS_BH(field) SNMP_INC_STATS_BH(sctp_statistics, field) | 226 | #define SCTP_INC_STATS_BH(field) SNMP_INC_STATS_BH(sctp_statistics, field) |
214 | #define SCTP_INC_STATS_USER(field) SNMP_INC_STATS_USER(sctp_statistics, field) | 227 | #define SCTP_INC_STATS_USER(field) SNMP_INC_STATS_USER(sctp_statistics, field) |
215 | #define SCTP_DEC_STATS(field) SNMP_DEC_STATS(sctp_statistics, field) | 228 | #define SCTP_DEC_STATS(field) SNMP_DEC_STATS(sctp_statistics, field) |
216 | 229 | ||
217 | #endif /* !TEST_FRAME */ | 230 | #endif /* !TEST_FRAME */ |
218 | 231 | ||
219 | /* sctp mib definitions */ | 232 | /* sctp mib definitions */ |
220 | enum | 233 | enum |
221 | { | 234 | { |
222 | SCTP_MIB_NUM = 0, | 235 | SCTP_MIB_NUM = 0, |
223 | SCTP_MIB_CURRESTAB, /* CurrEstab */ | 236 | SCTP_MIB_CURRESTAB, /* CurrEstab */ |
224 | SCTP_MIB_ACTIVEESTABS, /* ActiveEstabs */ | 237 | SCTP_MIB_ACTIVEESTABS, /* ActiveEstabs */ |
225 | SCTP_MIB_PASSIVEESTABS, /* PassiveEstabs */ | 238 | SCTP_MIB_PASSIVEESTABS, /* PassiveEstabs */ |
226 | SCTP_MIB_ABORTEDS, /* Aborteds */ | 239 | SCTP_MIB_ABORTEDS, /* Aborteds */ |
227 | SCTP_MIB_SHUTDOWNS, /* Shutdowns */ | 240 | SCTP_MIB_SHUTDOWNS, /* Shutdowns */ |
228 | SCTP_MIB_OUTOFBLUES, /* OutOfBlues */ | 241 | SCTP_MIB_OUTOFBLUES, /* OutOfBlues */ |
229 | SCTP_MIB_CHECKSUMERRORS, /* ChecksumErrors */ | 242 | SCTP_MIB_CHECKSUMERRORS, /* ChecksumErrors */ |
230 | SCTP_MIB_OUTCTRLCHUNKS, /* OutCtrlChunks */ | 243 | SCTP_MIB_OUTCTRLCHUNKS, /* OutCtrlChunks */ |
231 | SCTP_MIB_OUTORDERCHUNKS, /* OutOrderChunks */ | 244 | SCTP_MIB_OUTORDERCHUNKS, /* OutOrderChunks */ |
232 | SCTP_MIB_OUTUNORDERCHUNKS, /* OutUnorderChunks */ | 245 | SCTP_MIB_OUTUNORDERCHUNKS, /* OutUnorderChunks */ |
233 | SCTP_MIB_INCTRLCHUNKS, /* InCtrlChunks */ | 246 | SCTP_MIB_INCTRLCHUNKS, /* InCtrlChunks */ |
234 | SCTP_MIB_INORDERCHUNKS, /* InOrderChunks */ | 247 | SCTP_MIB_INORDERCHUNKS, /* InOrderChunks */ |
235 | SCTP_MIB_INUNORDERCHUNKS, /* InUnorderChunks */ | 248 | SCTP_MIB_INUNORDERCHUNKS, /* InUnorderChunks */ |
236 | SCTP_MIB_FRAGUSRMSGS, /* FragUsrMsgs */ | 249 | SCTP_MIB_FRAGUSRMSGS, /* FragUsrMsgs */ |
237 | SCTP_MIB_REASMUSRMSGS, /* ReasmUsrMsgs */ | 250 | SCTP_MIB_REASMUSRMSGS, /* ReasmUsrMsgs */ |
238 | SCTP_MIB_OUTSCTPPACKS, /* OutSCTPPacks */ | 251 | SCTP_MIB_OUTSCTPPACKS, /* OutSCTPPacks */ |
239 | SCTP_MIB_INSCTPPACKS, /* InSCTPPacks */ | 252 | SCTP_MIB_INSCTPPACKS, /* InSCTPPacks */ |
240 | SCTP_MIB_T1_INIT_EXPIREDS, | 253 | SCTP_MIB_T1_INIT_EXPIREDS, |
241 | SCTP_MIB_T1_COOKIE_EXPIREDS, | 254 | SCTP_MIB_T1_COOKIE_EXPIREDS, |
242 | SCTP_MIB_T2_SHUTDOWN_EXPIREDS, | 255 | SCTP_MIB_T2_SHUTDOWN_EXPIREDS, |
243 | SCTP_MIB_T3_RTX_EXPIREDS, | 256 | SCTP_MIB_T3_RTX_EXPIREDS, |
244 | SCTP_MIB_T4_RTO_EXPIREDS, | 257 | SCTP_MIB_T4_RTO_EXPIREDS, |
245 | SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS, | 258 | SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS, |
246 | SCTP_MIB_DELAY_SACK_EXPIREDS, | 259 | SCTP_MIB_DELAY_SACK_EXPIREDS, |
247 | SCTP_MIB_AUTOCLOSE_EXPIREDS, | 260 | SCTP_MIB_AUTOCLOSE_EXPIREDS, |
248 | SCTP_MIB_T3_RETRANSMITS, | 261 | SCTP_MIB_T3_RETRANSMITS, |
249 | SCTP_MIB_PMTUD_RETRANSMITS, | 262 | SCTP_MIB_PMTUD_RETRANSMITS, |
250 | SCTP_MIB_FAST_RETRANSMITS, | 263 | SCTP_MIB_FAST_RETRANSMITS, |
251 | SCTP_MIB_IN_PKT_SOFTIRQ, | 264 | SCTP_MIB_IN_PKT_SOFTIRQ, |
252 | SCTP_MIB_IN_PKT_BACKLOG, | 265 | SCTP_MIB_IN_PKT_BACKLOG, |
253 | SCTP_MIB_IN_PKT_DISCARDS, | 266 | SCTP_MIB_IN_PKT_DISCARDS, |
254 | SCTP_MIB_IN_DATA_CHUNK_DISCARDS, | 267 | SCTP_MIB_IN_DATA_CHUNK_DISCARDS, |
255 | __SCTP_MIB_MAX | 268 | __SCTP_MIB_MAX |
256 | }; | 269 | }; |
257 | 270 | ||
258 | #define SCTP_MIB_MAX __SCTP_MIB_MAX | 271 | #define SCTP_MIB_MAX __SCTP_MIB_MAX |
259 | struct sctp_mib { | 272 | struct sctp_mib { |
260 | unsigned long mibs[SCTP_MIB_MAX]; | 273 | unsigned long mibs[SCTP_MIB_MAX]; |
261 | } __SNMP_MIB_ALIGN__; | 274 | } __SNMP_MIB_ALIGN__; |
262 | 275 | ||
263 | 276 | ||
264 | /* Print debugging messages. */ | 277 | /* Print debugging messages. */ |
265 | #if SCTP_DEBUG | 278 | #if SCTP_DEBUG |
266 | extern int sctp_debug_flag; | 279 | extern int sctp_debug_flag; |
267 | #define SCTP_DEBUG_PRINTK(whatever...) \ | 280 | #define SCTP_DEBUG_PRINTK(whatever...) \ |
268 | ((void) (sctp_debug_flag && printk(KERN_DEBUG whatever))) | 281 | ((void) (sctp_debug_flag && printk(KERN_DEBUG whatever))) |
269 | #define SCTP_DEBUG_PRINTK_IPADDR(lead, trail, leadparm, saddr, otherparms...) \ | 282 | #define SCTP_DEBUG_PRINTK_IPADDR(lead, trail, leadparm, saddr, otherparms...) \ |
270 | if (sctp_debug_flag) { \ | 283 | if (sctp_debug_flag) { \ |
271 | if (saddr->sa.sa_family == AF_INET6) { \ | 284 | if (saddr->sa.sa_family == AF_INET6) { \ |
272 | printk(KERN_DEBUG \ | 285 | printk(KERN_DEBUG \ |
273 | lead NIP6_FMT trail, \ | 286 | lead NIP6_FMT trail, \ |
274 | leadparm, \ | 287 | leadparm, \ |
275 | NIP6(saddr->v6.sin6_addr), \ | 288 | NIP6(saddr->v6.sin6_addr), \ |
276 | otherparms); \ | 289 | otherparms); \ |
277 | } else { \ | 290 | } else { \ |
278 | printk(KERN_DEBUG \ | 291 | printk(KERN_DEBUG \ |
279 | lead NIPQUAD_FMT trail, \ | 292 | lead NIPQUAD_FMT trail, \ |
280 | leadparm, \ | 293 | leadparm, \ |
281 | NIPQUAD(saddr->v4.sin_addr.s_addr), \ | 294 | NIPQUAD(saddr->v4.sin_addr.s_addr), \ |
282 | otherparms); \ | 295 | otherparms); \ |
283 | } \ | 296 | } \ |
284 | } | 297 | } |
285 | #define SCTP_ENABLE_DEBUG { sctp_debug_flag = 1; } | 298 | #define SCTP_ENABLE_DEBUG { sctp_debug_flag = 1; } |
286 | #define SCTP_DISABLE_DEBUG { sctp_debug_flag = 0; } | 299 | #define SCTP_DISABLE_DEBUG { sctp_debug_flag = 0; } |
287 | 300 | ||
288 | #define SCTP_ASSERT(expr, str, func) \ | 301 | #define SCTP_ASSERT(expr, str, func) \ |
289 | if (!(expr)) { \ | 302 | if (!(expr)) { \ |
290 | SCTP_DEBUG_PRINTK("Assertion Failed: %s(%s) at %s:%s:%d\n", \ | 303 | SCTP_DEBUG_PRINTK("Assertion Failed: %s(%s) at %s:%s:%d\n", \ |
291 | str, (#expr), __FILE__, __FUNCTION__, __LINE__); \ | 304 | str, (#expr), __FILE__, __FUNCTION__, __LINE__); \ |
292 | func; \ | 305 | func; \ |
293 | } | 306 | } |
294 | 307 | ||
295 | #else /* SCTP_DEBUG */ | 308 | #else /* SCTP_DEBUG */ |
296 | 309 | ||
297 | #define SCTP_DEBUG_PRINTK(whatever...) | 310 | #define SCTP_DEBUG_PRINTK(whatever...) |
298 | #define SCTP_DEBUG_PRINTK_IPADDR(whatever...) | 311 | #define SCTP_DEBUG_PRINTK_IPADDR(whatever...) |
299 | #define SCTP_ENABLE_DEBUG | 312 | #define SCTP_ENABLE_DEBUG |
300 | #define SCTP_DISABLE_DEBUG | 313 | #define SCTP_DISABLE_DEBUG |
301 | #define SCTP_ASSERT(expr, str, func) | 314 | #define SCTP_ASSERT(expr, str, func) |
302 | 315 | ||
303 | #endif /* SCTP_DEBUG */ | 316 | #endif /* SCTP_DEBUG */ |
304 | 317 | ||
305 | 318 | ||
306 | /* | 319 | /* |
307 | * Macros for keeping a global reference of object allocations. | 320 | * Macros for keeping a global reference of object allocations. |
308 | */ | 321 | */ |
309 | #ifdef CONFIG_SCTP_DBG_OBJCNT | 322 | #ifdef CONFIG_SCTP_DBG_OBJCNT |
310 | 323 | ||
311 | extern atomic_t sctp_dbg_objcnt_sock; | 324 | extern atomic_t sctp_dbg_objcnt_sock; |
312 | extern atomic_t sctp_dbg_objcnt_ep; | 325 | extern atomic_t sctp_dbg_objcnt_ep; |
313 | extern atomic_t sctp_dbg_objcnt_assoc; | 326 | extern atomic_t sctp_dbg_objcnt_assoc; |
314 | extern atomic_t sctp_dbg_objcnt_transport; | 327 | extern atomic_t sctp_dbg_objcnt_transport; |
315 | extern atomic_t sctp_dbg_objcnt_chunk; | 328 | extern atomic_t sctp_dbg_objcnt_chunk; |
316 | extern atomic_t sctp_dbg_objcnt_bind_addr; | 329 | extern atomic_t sctp_dbg_objcnt_bind_addr; |
317 | extern atomic_t sctp_dbg_objcnt_bind_bucket; | 330 | extern atomic_t sctp_dbg_objcnt_bind_bucket; |
318 | extern atomic_t sctp_dbg_objcnt_addr; | 331 | extern atomic_t sctp_dbg_objcnt_addr; |
319 | extern atomic_t sctp_dbg_objcnt_ssnmap; | 332 | extern atomic_t sctp_dbg_objcnt_ssnmap; |
320 | extern atomic_t sctp_dbg_objcnt_datamsg; | 333 | extern atomic_t sctp_dbg_objcnt_datamsg; |
321 | 334 | ||
322 | /* Macros to atomically increment/decrement objcnt counters. */ | 335 | /* Macros to atomically increment/decrement objcnt counters. */ |
323 | #define SCTP_DBG_OBJCNT_INC(name) \ | 336 | #define SCTP_DBG_OBJCNT_INC(name) \ |
324 | atomic_inc(&sctp_dbg_objcnt_## name) | 337 | atomic_inc(&sctp_dbg_objcnt_## name) |
325 | #define SCTP_DBG_OBJCNT_DEC(name) \ | 338 | #define SCTP_DBG_OBJCNT_DEC(name) \ |
326 | atomic_dec(&sctp_dbg_objcnt_## name) | 339 | atomic_dec(&sctp_dbg_objcnt_## name) |
327 | #define SCTP_DBG_OBJCNT(name) \ | 340 | #define SCTP_DBG_OBJCNT(name) \ |
328 | atomic_t sctp_dbg_objcnt_## name = ATOMIC_INIT(0) | 341 | atomic_t sctp_dbg_objcnt_## name = ATOMIC_INIT(0) |
329 | 342 | ||
330 | /* Macro to help create new entries in in the global array of | 343 | /* Macro to help create new entries in in the global array of |
331 | * objcnt counters. | 344 | * objcnt counters. |
332 | */ | 345 | */ |
333 | #define SCTP_DBG_OBJCNT_ENTRY(name) \ | 346 | #define SCTP_DBG_OBJCNT_ENTRY(name) \ |
334 | {.label= #name, .counter= &sctp_dbg_objcnt_## name} | 347 | {.label= #name, .counter= &sctp_dbg_objcnt_## name} |
335 | 348 | ||
336 | void sctp_dbg_objcnt_init(void); | 349 | void sctp_dbg_objcnt_init(void); |
337 | void sctp_dbg_objcnt_exit(void); | 350 | void sctp_dbg_objcnt_exit(void); |
338 | 351 | ||
339 | #else | 352 | #else |
340 | 353 | ||
341 | #define SCTP_DBG_OBJCNT_INC(name) | 354 | #define SCTP_DBG_OBJCNT_INC(name) |
342 | #define SCTP_DBG_OBJCNT_DEC(name) | 355 | #define SCTP_DBG_OBJCNT_DEC(name) |
343 | 356 | ||
344 | static inline void sctp_dbg_objcnt_init(void) { return; } | 357 | static inline void sctp_dbg_objcnt_init(void) { return; } |
345 | static inline void sctp_dbg_objcnt_exit(void) { return; } | 358 | static inline void sctp_dbg_objcnt_exit(void) { return; } |
346 | 359 | ||
347 | #endif /* CONFIG_SCTP_DBG_OBJCOUNT */ | 360 | #endif /* CONFIG_SCTP_DBG_OBJCOUNT */ |
348 | 361 | ||
349 | #if defined CONFIG_SYSCTL | 362 | #if defined CONFIG_SYSCTL |
350 | void sctp_sysctl_register(void); | 363 | void sctp_sysctl_register(void); |
351 | void sctp_sysctl_unregister(void); | 364 | void sctp_sysctl_unregister(void); |
352 | #else | 365 | #else |
353 | static inline void sctp_sysctl_register(void) { return; } | 366 | static inline void sctp_sysctl_register(void) { return; } |
354 | static inline void sctp_sysctl_unregister(void) { return; } | 367 | static inline void sctp_sysctl_unregister(void) { return; } |
355 | static inline int sctp_sysctl_jiffies_ms(ctl_table *table, int __user *name, int nlen, | 368 | static inline int sctp_sysctl_jiffies_ms(ctl_table *table, int __user *name, int nlen, |
356 | void __user *oldval, size_t __user *oldlenp, | 369 | void __user *oldval, size_t __user *oldlenp, |
357 | void __user *newval, size_t newlen, void **context) { | 370 | void __user *newval, size_t newlen, void **context) { |
358 | return -ENOSYS; | 371 | return -ENOSYS; |
359 | } | 372 | } |
360 | #endif | 373 | #endif |
361 | 374 | ||
362 | /* Size of Supported Address Parameter for 'x' address types. */ | 375 | /* Size of Supported Address Parameter for 'x' address types. */ |
363 | #define SCTP_SAT_LEN(x) (sizeof(struct sctp_paramhdr) + (x) * sizeof(__u16)) | 376 | #define SCTP_SAT_LEN(x) (sizeof(struct sctp_paramhdr) + (x) * sizeof(__u16)) |
364 | 377 | ||
365 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | 378 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
366 | 379 | ||
367 | int sctp_v6_init(void); | 380 | int sctp_v6_init(void); |
368 | void sctp_v6_exit(void); | 381 | void sctp_v6_exit(void); |
369 | 382 | ||
370 | #else /* #ifdef defined(CONFIG_IPV6) */ | 383 | #else /* #ifdef defined(CONFIG_IPV6) */ |
371 | 384 | ||
372 | static inline int sctp_v6_init(void) { return 0; } | 385 | static inline int sctp_v6_init(void) { return 0; } |
373 | static inline void sctp_v6_exit(void) { return; } | 386 | static inline void sctp_v6_exit(void) { return; } |
374 | 387 | ||
375 | #endif /* #if defined(CONFIG_IPV6) */ | 388 | #endif /* #if defined(CONFIG_IPV6) */ |
376 | 389 | ||
377 | 390 | ||
378 | /* Map an association to an assoc_id. */ | 391 | /* Map an association to an assoc_id. */ |
379 | static inline sctp_assoc_t sctp_assoc2id(const struct sctp_association *asoc) | 392 | static inline sctp_assoc_t sctp_assoc2id(const struct sctp_association *asoc) |
380 | { | 393 | { |
381 | return (asoc?asoc->assoc_id:0); | 394 | return (asoc?asoc->assoc_id:0); |
382 | } | 395 | } |
383 | 396 | ||
384 | /* Look up the association by its id. */ | 397 | /* Look up the association by its id. */ |
385 | struct sctp_association *sctp_id2assoc(struct sock *sk, sctp_assoc_t id); | 398 | struct sctp_association *sctp_id2assoc(struct sock *sk, sctp_assoc_t id); |
386 | 399 | ||
387 | 400 | ||
388 | /* A macro to walk a list of skbs. */ | 401 | /* A macro to walk a list of skbs. */ |
389 | #define sctp_skb_for_each(pos, head, tmp) \ | 402 | #define sctp_skb_for_each(pos, head, tmp) \ |
390 | for (pos = (head)->next;\ | 403 | for (pos = (head)->next;\ |
391 | tmp = (pos)->next, pos != ((struct sk_buff *)(head));\ | 404 | tmp = (pos)->next, pos != ((struct sk_buff *)(head));\ |
392 | pos = tmp) | 405 | pos = tmp) |
393 | 406 | ||
394 | 407 | ||
395 | /* A helper to append an entire skb list (list) to another (head). */ | 408 | /* A helper to append an entire skb list (list) to another (head). */ |
396 | static inline void sctp_skb_list_tail(struct sk_buff_head *list, | 409 | static inline void sctp_skb_list_tail(struct sk_buff_head *list, |
397 | struct sk_buff_head *head) | 410 | struct sk_buff_head *head) |
398 | { | 411 | { |
399 | unsigned long flags; | 412 | unsigned long flags; |
400 | 413 | ||
401 | sctp_spin_lock_irqsave(&head->lock, flags); | 414 | sctp_spin_lock_irqsave(&head->lock, flags); |
402 | sctp_spin_lock(&list->lock); | 415 | sctp_spin_lock(&list->lock); |
403 | 416 | ||
404 | list_splice((struct list_head *)list, (struct list_head *)head->prev); | 417 | list_splice((struct list_head *)list, (struct list_head *)head->prev); |
405 | 418 | ||
406 | head->qlen += list->qlen; | 419 | head->qlen += list->qlen; |
407 | list->qlen = 0; | 420 | list->qlen = 0; |
408 | 421 | ||
409 | sctp_spin_unlock(&list->lock); | 422 | sctp_spin_unlock(&list->lock); |
410 | sctp_spin_unlock_irqrestore(&head->lock, flags); | 423 | sctp_spin_unlock_irqrestore(&head->lock, flags); |
411 | } | 424 | } |
412 | 425 | ||
413 | /** | 426 | /** |
414 | * sctp_list_dequeue - remove from the head of the queue | 427 | * sctp_list_dequeue - remove from the head of the queue |
415 | * @list: list to dequeue from | 428 | * @list: list to dequeue from |
416 | * | 429 | * |
417 | * Remove the head of the list. The head item is | 430 | * Remove the head of the list. The head item is |
418 | * returned or %NULL if the list is empty. | 431 | * returned or %NULL if the list is empty. |
419 | */ | 432 | */ |
420 | 433 | ||
421 | static inline struct list_head *sctp_list_dequeue(struct list_head *list) | 434 | static inline struct list_head *sctp_list_dequeue(struct list_head *list) |
422 | { | 435 | { |
423 | struct list_head *result = NULL; | 436 | struct list_head *result = NULL; |
424 | 437 | ||
425 | if (list->next != list) { | 438 | if (list->next != list) { |
426 | result = list->next; | 439 | result = list->next; |
427 | list->next = result->next; | 440 | list->next = result->next; |
428 | list->next->prev = list; | 441 | list->next->prev = list; |
429 | INIT_LIST_HEAD(result); | 442 | INIT_LIST_HEAD(result); |
430 | } | 443 | } |
431 | return result; | 444 | return result; |
432 | } | 445 | } |
433 | 446 | ||
434 | /* Tests if the list has one and only one entry. */ | 447 | /* Tests if the list has one and only one entry. */ |
435 | static inline int sctp_list_single_entry(struct list_head *head) | 448 | static inline int sctp_list_single_entry(struct list_head *head) |
436 | { | 449 | { |
437 | return ((head->next != head) && (head->next == head->prev)); | 450 | return ((head->next != head) && (head->next == head->prev)); |
438 | } | 451 | } |
439 | 452 | ||
440 | /* Generate a random jitter in the range of -50% ~ +50% of input RTO. */ | 453 | /* Generate a random jitter in the range of -50% ~ +50% of input RTO. */ |
441 | static inline __s32 sctp_jitter(__u32 rto) | 454 | static inline __s32 sctp_jitter(__u32 rto) |
442 | { | 455 | { |
443 | static __u32 sctp_rand; | 456 | static __u32 sctp_rand; |
444 | __s32 ret; | 457 | __s32 ret; |
445 | 458 | ||
446 | /* Avoid divide by zero. */ | 459 | /* Avoid divide by zero. */ |
447 | if (!rto) | 460 | if (!rto) |
448 | rto = 1; | 461 | rto = 1; |
449 | 462 | ||
450 | sctp_rand += jiffies; | 463 | sctp_rand += jiffies; |
451 | sctp_rand ^= (sctp_rand << 12); | 464 | sctp_rand ^= (sctp_rand << 12); |
452 | sctp_rand ^= (sctp_rand >> 20); | 465 | sctp_rand ^= (sctp_rand >> 20); |
453 | 466 | ||
454 | /* Choose random number from 0 to rto, then move to -50% ~ +50% | 467 | /* Choose random number from 0 to rto, then move to -50% ~ +50% |
455 | * of rto. | 468 | * of rto. |
456 | */ | 469 | */ |
457 | ret = sctp_rand % rto - (rto >> 1); | 470 | ret = sctp_rand % rto - (rto >> 1); |
458 | return ret; | 471 | return ret; |
459 | } | 472 | } |
460 | 473 | ||
461 | /* Break down data chunks at this point. */ | 474 | /* Break down data chunks at this point. */ |
462 | static inline int sctp_frag_point(const struct sctp_sock *sp, int pmtu) | 475 | static inline int sctp_frag_point(const struct sctp_sock *sp, int pmtu) |
463 | { | 476 | { |
464 | int frag = pmtu; | 477 | int frag = pmtu; |
465 | 478 | ||
466 | frag -= sp->pf->af->net_header_len; | 479 | frag -= sp->pf->af->net_header_len; |
467 | frag -= sizeof(struct sctphdr) + sizeof(struct sctp_data_chunk); | 480 | frag -= sizeof(struct sctphdr) + sizeof(struct sctp_data_chunk); |
468 | 481 | ||
469 | if (sp->user_frag) | 482 | if (sp->user_frag) |
470 | frag = min_t(int, frag, sp->user_frag); | 483 | frag = min_t(int, frag, sp->user_frag); |
471 | 484 | ||
472 | frag = min_t(int, frag, SCTP_MAX_CHUNK_LEN); | 485 | frag = min_t(int, frag, SCTP_MAX_CHUNK_LEN); |
473 | 486 | ||
474 | return frag; | 487 | return frag; |
475 | } | 488 | } |
476 | 489 | ||
477 | /* Walk through a list of TLV parameters. Don't trust the | 490 | /* Walk through a list of TLV parameters. Don't trust the |
478 | * individual parameter lengths and instead depend on | 491 | * individual parameter lengths and instead depend on |
479 | * the chunk length to indicate when to stop. Make sure | 492 | * the chunk length to indicate when to stop. Make sure |
480 | * there is room for a param header too. | 493 | * there is room for a param header too. |
481 | */ | 494 | */ |
482 | #define sctp_walk_params(pos, chunk, member)\ | 495 | #define sctp_walk_params(pos, chunk, member)\ |
483 | _sctp_walk_params((pos), (chunk), ntohs((chunk)->chunk_hdr.length), member) | 496 | _sctp_walk_params((pos), (chunk), ntohs((chunk)->chunk_hdr.length), member) |
484 | 497 | ||
485 | #define _sctp_walk_params(pos, chunk, end, member)\ | 498 | #define _sctp_walk_params(pos, chunk, end, member)\ |
486 | for (pos.v = chunk->member;\ | 499 | for (pos.v = chunk->member;\ |
487 | pos.v <= (void *)chunk + end - sizeof(sctp_paramhdr_t) &&\ | 500 | pos.v <= (void *)chunk + end - sizeof(sctp_paramhdr_t) &&\ |
488 | pos.v <= (void *)chunk + end - ntohs(pos.p->length) &&\ | 501 | pos.v <= (void *)chunk + end - ntohs(pos.p->length) &&\ |
489 | ntohs(pos.p->length) >= sizeof(sctp_paramhdr_t);\ | 502 | ntohs(pos.p->length) >= sizeof(sctp_paramhdr_t);\ |
490 | pos.v += WORD_ROUND(ntohs(pos.p->length))) | 503 | pos.v += WORD_ROUND(ntohs(pos.p->length))) |
491 | 504 | ||
492 | #define sctp_walk_errors(err, chunk_hdr)\ | 505 | #define sctp_walk_errors(err, chunk_hdr)\ |
493 | _sctp_walk_errors((err), (chunk_hdr), ntohs((chunk_hdr)->length)) | 506 | _sctp_walk_errors((err), (chunk_hdr), ntohs((chunk_hdr)->length)) |
494 | 507 | ||
495 | #define _sctp_walk_errors(err, chunk_hdr, end)\ | 508 | #define _sctp_walk_errors(err, chunk_hdr, end)\ |
496 | for (err = (sctp_errhdr_t *)((void *)chunk_hdr + \ | 509 | for (err = (sctp_errhdr_t *)((void *)chunk_hdr + \ |
497 | sizeof(sctp_chunkhdr_t));\ | 510 | sizeof(sctp_chunkhdr_t));\ |
498 | (void *)err <= (void *)chunk_hdr + end - sizeof(sctp_errhdr_t) &&\ | 511 | (void *)err <= (void *)chunk_hdr + end - sizeof(sctp_errhdr_t) &&\ |
499 | (void *)err <= (void *)chunk_hdr + end - ntohs(err->length) &&\ | 512 | (void *)err <= (void *)chunk_hdr + end - ntohs(err->length) &&\ |
500 | ntohs(err->length) >= sizeof(sctp_errhdr_t); \ | 513 | ntohs(err->length) >= sizeof(sctp_errhdr_t); \ |
501 | err = (sctp_errhdr_t *)((void *)err + WORD_ROUND(ntohs(err->length)))) | 514 | err = (sctp_errhdr_t *)((void *)err + WORD_ROUND(ntohs(err->length)))) |
502 | 515 | ||
503 | #define sctp_walk_fwdtsn(pos, chunk)\ | 516 | #define sctp_walk_fwdtsn(pos, chunk)\ |
504 | _sctp_walk_fwdtsn((pos), (chunk), ntohs((chunk)->chunk_hdr->length) - sizeof(struct sctp_fwdtsn_chunk)) | 517 | _sctp_walk_fwdtsn((pos), (chunk), ntohs((chunk)->chunk_hdr->length) - sizeof(struct sctp_fwdtsn_chunk)) |
505 | 518 | ||
506 | #define _sctp_walk_fwdtsn(pos, chunk, end)\ | 519 | #define _sctp_walk_fwdtsn(pos, chunk, end)\ |
507 | for (pos = chunk->subh.fwdtsn_hdr->skip;\ | 520 | for (pos = chunk->subh.fwdtsn_hdr->skip;\ |
508 | (void *)pos <= (void *)chunk->subh.fwdtsn_hdr->skip + end - sizeof(struct sctp_fwdtsn_skip);\ | 521 | (void *)pos <= (void *)chunk->subh.fwdtsn_hdr->skip + end - sizeof(struct sctp_fwdtsn_skip);\ |
509 | pos++) | 522 | pos++) |
510 | 523 | ||
511 | /* Round an int up to the next multiple of 4. */ | 524 | /* Round an int up to the next multiple of 4. */ |
512 | #define WORD_ROUND(s) (((s)+3)&~3) | 525 | #define WORD_ROUND(s) (((s)+3)&~3) |
513 | 526 | ||
514 | /* Make a new instance of type. */ | 527 | /* Make a new instance of type. */ |
515 | #define t_new(type, flags) (type *)kmalloc(sizeof(type), flags) | 528 | #define t_new(type, flags) (type *)kmalloc(sizeof(type), flags) |
516 | 529 | ||
517 | /* Compare two timevals. */ | 530 | /* Compare two timevals. */ |
518 | #define tv_lt(s, t) \ | 531 | #define tv_lt(s, t) \ |
519 | (s.tv_sec < t.tv_sec || (s.tv_sec == t.tv_sec && s.tv_usec < t.tv_usec)) | 532 | (s.tv_sec < t.tv_sec || (s.tv_sec == t.tv_sec && s.tv_usec < t.tv_usec)) |
520 | 533 | ||
521 | /* Add tv1 to tv2. */ | 534 | /* Add tv1 to tv2. */ |
522 | #define TIMEVAL_ADD(tv1, tv2) \ | 535 | #define TIMEVAL_ADD(tv1, tv2) \ |
523 | ({ \ | 536 | ({ \ |
524 | suseconds_t usecs = (tv2).tv_usec + (tv1).tv_usec; \ | 537 | suseconds_t usecs = (tv2).tv_usec + (tv1).tv_usec; \ |
525 | time_t secs = (tv2).tv_sec + (tv1).tv_sec; \ | 538 | time_t secs = (tv2).tv_sec + (tv1).tv_sec; \ |
526 | \ | 539 | \ |
527 | if (usecs >= 1000000) { \ | 540 | if (usecs >= 1000000) { \ |
528 | usecs -= 1000000; \ | 541 | usecs -= 1000000; \ |
529 | secs++; \ | 542 | secs++; \ |
530 | } \ | 543 | } \ |
531 | (tv2).tv_sec = secs; \ | 544 | (tv2).tv_sec = secs; \ |
532 | (tv2).tv_usec = usecs; \ | 545 | (tv2).tv_usec = usecs; \ |
533 | }) | 546 | }) |
534 | 547 | ||
535 | /* External references. */ | 548 | /* External references. */ |
536 | 549 | ||
537 | extern struct proto sctp_prot; | 550 | extern struct proto sctp_prot; |
538 | extern struct proto sctpv6_prot; | 551 | extern struct proto sctpv6_prot; |
539 | extern struct proc_dir_entry *proc_net_sctp; | 552 | extern struct proc_dir_entry *proc_net_sctp; |
540 | void sctp_put_port(struct sock *sk); | 553 | void sctp_put_port(struct sock *sk); |
541 | 554 | ||
542 | extern struct idr sctp_assocs_id; | 555 | extern struct idr sctp_assocs_id; |
543 | extern spinlock_t sctp_assocs_id_lock; | 556 | extern spinlock_t sctp_assocs_id_lock; |
544 | 557 | ||
545 | /* Static inline functions. */ | 558 | /* Static inline functions. */ |
546 | 559 | ||
547 | /* Convert from an IP version number to an Address Family symbol. */ | 560 | /* Convert from an IP version number to an Address Family symbol. */ |
548 | static inline int ipver2af(__u8 ipver) | 561 | static inline int ipver2af(__u8 ipver) |
549 | { | 562 | { |
550 | switch (ipver) { | 563 | switch (ipver) { |
551 | case 4: | 564 | case 4: |
552 | return AF_INET; | 565 | return AF_INET; |
553 | case 6: | 566 | case 6: |
554 | return AF_INET6; | 567 | return AF_INET6; |
555 | default: | 568 | default: |
556 | return 0; | 569 | return 0; |
557 | }; | 570 | }; |
558 | } | 571 | } |
559 | 572 | ||
560 | /* Convert from an address parameter type to an address family. */ | 573 | /* Convert from an address parameter type to an address family. */ |
561 | static inline int param_type2af(__u16 type) | 574 | static inline int param_type2af(__u16 type) |
562 | { | 575 | { |
563 | switch (type) { | 576 | switch (type) { |
564 | case SCTP_PARAM_IPV4_ADDRESS: | 577 | case SCTP_PARAM_IPV4_ADDRESS: |
565 | return AF_INET; | 578 | return AF_INET; |
566 | case SCTP_PARAM_IPV6_ADDRESS: | 579 | case SCTP_PARAM_IPV6_ADDRESS: |
567 | return AF_INET6; | 580 | return AF_INET6; |
568 | default: | 581 | default: |
569 | return 0; | 582 | return 0; |
570 | }; | 583 | }; |
571 | } | 584 | } |
572 | 585 | ||
573 | /* Perform some sanity checks. */ | 586 | /* Perform some sanity checks. */ |
574 | static inline int sctp_sanity_check(void) | 587 | static inline int sctp_sanity_check(void) |
575 | { | 588 | { |
576 | SCTP_ASSERT(sizeof(struct sctp_ulpevent) <= | 589 | SCTP_ASSERT(sizeof(struct sctp_ulpevent) <= |
577 | sizeof(((struct sk_buff *)0)->cb), | 590 | sizeof(((struct sk_buff *)0)->cb), |
578 | "SCTP: ulpevent does not fit in skb!\n", return 0); | 591 | "SCTP: ulpevent does not fit in skb!\n", return 0); |
579 | 592 | ||
580 | return 1; | 593 | return 1; |
581 | } | 594 | } |
582 | 595 | ||
583 | /* Warning: The following hash functions assume a power of two 'size'. */ | 596 | /* Warning: The following hash functions assume a power of two 'size'. */ |
584 | /* This is the hash function for the SCTP port hash table. */ | 597 | /* This is the hash function for the SCTP port hash table. */ |
585 | static inline int sctp_phashfn(__u16 lport) | 598 | static inline int sctp_phashfn(__u16 lport) |
586 | { | 599 | { |
587 | return (lport & (sctp_port_hashsize - 1)); | 600 | return (lport & (sctp_port_hashsize - 1)); |
588 | } | 601 | } |
589 | 602 | ||
590 | /* This is the hash function for the endpoint hash table. */ | 603 | /* This is the hash function for the endpoint hash table. */ |
591 | static inline int sctp_ep_hashfn(__u16 lport) | 604 | static inline int sctp_ep_hashfn(__u16 lport) |
592 | { | 605 | { |
593 | return (lport & (sctp_ep_hashsize - 1)); | 606 | return (lport & (sctp_ep_hashsize - 1)); |
594 | } | 607 | } |
595 | 608 | ||
596 | /* This is the hash function for the association hash table. */ | 609 | /* This is the hash function for the association hash table. */ |
597 | static inline int sctp_assoc_hashfn(__u16 lport, __u16 rport) | 610 | static inline int sctp_assoc_hashfn(__u16 lport, __u16 rport) |
598 | { | 611 | { |
599 | int h = (lport << 16) + rport; | 612 | int h = (lport << 16) + rport; |
600 | h ^= h>>8; | 613 | h ^= h>>8; |
601 | return (h & (sctp_assoc_hashsize - 1)); | 614 | return (h & (sctp_assoc_hashsize - 1)); |
602 | } | 615 | } |
603 | 616 | ||
604 | /* This is the hash function for the association hash table. This is | 617 | /* This is the hash function for the association hash table. This is |
605 | * not used yet, but could be used as a better hash function when | 618 | * not used yet, but could be used as a better hash function when |
606 | * we have a vtag. | 619 | * we have a vtag. |
607 | */ | 620 | */ |
608 | static inline int sctp_vtag_hashfn(__u16 lport, __u16 rport, __u32 vtag) | 621 | static inline int sctp_vtag_hashfn(__u16 lport, __u16 rport, __u32 vtag) |
609 | { | 622 | { |
610 | int h = (lport << 16) + rport; | 623 | int h = (lport << 16) + rport; |
611 | h ^= vtag; | 624 | h ^= vtag; |
612 | return (h & (sctp_assoc_hashsize-1)); | 625 | return (h & (sctp_assoc_hashsize-1)); |
613 | } | 626 | } |
614 | 627 | ||
615 | /* Is a socket of this style? */ | 628 | /* Is a socket of this style? */ |
616 | #define sctp_style(sk, style) __sctp_style((sk), (SCTP_SOCKET_##style)) | 629 | #define sctp_style(sk, style) __sctp_style((sk), (SCTP_SOCKET_##style)) |
617 | static inline int __sctp_style(const struct sock *sk, sctp_socket_type_t style) | 630 | static inline int __sctp_style(const struct sock *sk, sctp_socket_type_t style) |
618 | { | 631 | { |
619 | return sctp_sk(sk)->type == style; | 632 | return sctp_sk(sk)->type == style; |
620 | } | 633 | } |
621 | 634 | ||
622 | /* Is the association in this state? */ | 635 | /* Is the association in this state? */ |
623 | #define sctp_state(asoc, state) __sctp_state((asoc), (SCTP_STATE_##state)) | 636 | #define sctp_state(asoc, state) __sctp_state((asoc), (SCTP_STATE_##state)) |
624 | static inline int __sctp_state(const struct sctp_association *asoc, | 637 | static inline int __sctp_state(const struct sctp_association *asoc, |
625 | sctp_state_t state) | 638 | sctp_state_t state) |
626 | { | 639 | { |
627 | return asoc->state == state; | 640 | return asoc->state == state; |
628 | } | 641 | } |
629 | 642 | ||
630 | /* Is the socket in this state? */ | 643 | /* Is the socket in this state? */ |
631 | #define sctp_sstate(sk, state) __sctp_sstate((sk), (SCTP_SS_##state)) | 644 | #define sctp_sstate(sk, state) __sctp_sstate((sk), (SCTP_SS_##state)) |
632 | static inline int __sctp_sstate(const struct sock *sk, sctp_sock_state_t state) | 645 | static inline int __sctp_sstate(const struct sock *sk, sctp_sock_state_t state) |
633 | { | 646 | { |
634 | return sk->sk_state == state; | 647 | return sk->sk_state == state; |
635 | } | 648 | } |
636 | 649 | ||
637 | /* Map v4-mapped v6 address back to v4 address */ | 650 | /* Map v4-mapped v6 address back to v4 address */ |
638 | static inline void sctp_v6_map_v4(union sctp_addr *addr) | 651 | static inline void sctp_v6_map_v4(union sctp_addr *addr) |
639 | { | 652 | { |
640 | addr->v4.sin_family = AF_INET; | 653 | addr->v4.sin_family = AF_INET; |
641 | addr->v4.sin_port = addr->v6.sin6_port; | 654 | addr->v4.sin_port = addr->v6.sin6_port; |
642 | addr->v4.sin_addr.s_addr = addr->v6.sin6_addr.s6_addr32[3]; | 655 | addr->v4.sin_addr.s_addr = addr->v6.sin6_addr.s6_addr32[3]; |
643 | } | 656 | } |
644 | 657 | ||
645 | /* Map v4 address to v4-mapped v6 address */ | 658 | /* Map v4 address to v4-mapped v6 address */ |
646 | static inline void sctp_v4_map_v6(union sctp_addr *addr) | 659 | static inline void sctp_v4_map_v6(union sctp_addr *addr) |
647 | { | 660 | { |
648 | addr->v6.sin6_family = AF_INET6; | 661 | addr->v6.sin6_family = AF_INET6; |
649 | addr->v6.sin6_port = addr->v4.sin_port; | 662 | addr->v6.sin6_port = addr->v4.sin_port; |
650 | addr->v6.sin6_addr.s6_addr32[3] = addr->v4.sin_addr.s_addr; | 663 | addr->v6.sin6_addr.s6_addr32[3] = addr->v4.sin_addr.s_addr; |
651 | addr->v6.sin6_addr.s6_addr32[0] = 0; | 664 | addr->v6.sin6_addr.s6_addr32[0] = 0; |
652 | addr->v6.sin6_addr.s6_addr32[1] = 0; | 665 | addr->v6.sin6_addr.s6_addr32[1] = 0; |
653 | addr->v6.sin6_addr.s6_addr32[2] = htonl(0x0000ffff); | 666 | addr->v6.sin6_addr.s6_addr32[2] = htonl(0x0000ffff); |
654 | } | 667 | } |
655 | 668 | ||
656 | #endif /* __net_sctp_h__ */ | 669 | #endif /* __net_sctp_h__ */ |
657 | 670 |
net/sctp/ipv6.c
1 | /* SCTP kernel reference Implementation | 1 | /* SCTP kernel reference Implementation |
2 | * (C) Copyright IBM Corp. 2002, 2004 | 2 | * (C) Copyright IBM Corp. 2002, 2004 |
3 | * Copyright (c) 2001 Nokia, Inc. | 3 | * Copyright (c) 2001 Nokia, Inc. |
4 | * Copyright (c) 2001 La Monte H.P. Yarroll | 4 | * Copyright (c) 2001 La Monte H.P. Yarroll |
5 | * Copyright (c) 2002-2003 Intel Corp. | 5 | * Copyright (c) 2002-2003 Intel Corp. |
6 | * | 6 | * |
7 | * This file is part of the SCTP kernel reference Implementation | 7 | * This file is part of the SCTP kernel reference Implementation |
8 | * | 8 | * |
9 | * SCTP over IPv6. | 9 | * SCTP over IPv6. |
10 | * | 10 | * |
11 | * The SCTP reference implementation is free software; | 11 | * The SCTP reference implementation is free software; |
12 | * you can redistribute it and/or modify it under the terms of | 12 | * you can redistribute it and/or modify it under the terms of |
13 | * the GNU General Public License as published by | 13 | * the GNU General Public License as published by |
14 | * the Free Software Foundation; either version 2, or (at your option) | 14 | * the Free Software Foundation; either version 2, or (at your option) |
15 | * any later version. | 15 | * any later version. |
16 | * | 16 | * |
17 | * The SCTP reference implementation is distributed in the hope that it | 17 | * The SCTP reference implementation is distributed in the hope that it |
18 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied | 18 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied |
19 | * ************************ | 19 | * ************************ |
20 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 20 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
21 | * See the GNU General Public License for more details. | 21 | * See the GNU General Public License for more details. |
22 | * | 22 | * |
23 | * You should have received a copy of the GNU General Public License | 23 | * You should have received a copy of the GNU General Public License |
24 | * along with GNU CC; see the file COPYING. If not, write to | 24 | * along with GNU CC; see the file COPYING. If not, write to |
25 | * the Free Software Foundation, 59 Temple Place - Suite 330, | 25 | * the Free Software Foundation, 59 Temple Place - Suite 330, |
26 | * Boston, MA 02111-1307, USA. | 26 | * Boston, MA 02111-1307, USA. |
27 | * | 27 | * |
28 | * Please send any bug reports or fixes you make to the | 28 | * Please send any bug reports or fixes you make to the |
29 | * email address(es): | 29 | * email address(es): |
30 | * lksctp developers <lksctp-developers@lists.sourceforge.net> | 30 | * lksctp developers <lksctp-developers@lists.sourceforge.net> |
31 | * | 31 | * |
32 | * Or submit a bug report through the following website: | 32 | * Or submit a bug report through the following website: |
33 | * http://www.sf.net/projects/lksctp | 33 | * http://www.sf.net/projects/lksctp |
34 | * | 34 | * |
35 | * Written or modified by: | 35 | * Written or modified by: |
36 | * Le Yanqun <yanqun.le@nokia.com> | 36 | * Le Yanqun <yanqun.le@nokia.com> |
37 | * Hui Huang <hui.huang@nokia.com> | 37 | * Hui Huang <hui.huang@nokia.com> |
38 | * La Monte H.P. Yarroll <piggy@acm.org> | 38 | * La Monte H.P. Yarroll <piggy@acm.org> |
39 | * Sridhar Samudrala <sri@us.ibm.com> | 39 | * Sridhar Samudrala <sri@us.ibm.com> |
40 | * Jon Grimm <jgrimm@us.ibm.com> | 40 | * Jon Grimm <jgrimm@us.ibm.com> |
41 | * Ardelle Fan <ardelle.fan@intel.com> | 41 | * Ardelle Fan <ardelle.fan@intel.com> |
42 | * | 42 | * |
43 | * Based on: | 43 | * Based on: |
44 | * linux/net/ipv6/tcp_ipv6.c | 44 | * linux/net/ipv6/tcp_ipv6.c |
45 | * | 45 | * |
46 | * Any bugs reported given to us we will try to fix... any fixes shared will | 46 | * Any bugs reported given to us we will try to fix... any fixes shared will |
47 | * be incorporated into the next SCTP release. | 47 | * be incorporated into the next SCTP release. |
48 | */ | 48 | */ |
49 | 49 | ||
50 | #include <linux/module.h> | 50 | #include <linux/module.h> |
51 | #include <linux/errno.h> | 51 | #include <linux/errno.h> |
52 | #include <linux/types.h> | 52 | #include <linux/types.h> |
53 | #include <linux/socket.h> | 53 | #include <linux/socket.h> |
54 | #include <linux/sockios.h> | 54 | #include <linux/sockios.h> |
55 | #include <linux/net.h> | 55 | #include <linux/net.h> |
56 | #include <linux/sched.h> | 56 | #include <linux/sched.h> |
57 | #include <linux/in.h> | 57 | #include <linux/in.h> |
58 | #include <linux/in6.h> | 58 | #include <linux/in6.h> |
59 | #include <linux/netdevice.h> | 59 | #include <linux/netdevice.h> |
60 | #include <linux/init.h> | 60 | #include <linux/init.h> |
61 | #include <linux/ipsec.h> | 61 | #include <linux/ipsec.h> |
62 | 62 | ||
63 | #include <linux/ipv6.h> | 63 | #include <linux/ipv6.h> |
64 | #include <linux/icmpv6.h> | 64 | #include <linux/icmpv6.h> |
65 | #include <linux/random.h> | 65 | #include <linux/random.h> |
66 | #include <linux/seq_file.h> | 66 | #include <linux/seq_file.h> |
67 | 67 | ||
68 | #include <net/protocol.h> | 68 | #include <net/protocol.h> |
69 | #include <net/ndisc.h> | 69 | #include <net/ndisc.h> |
70 | #include <net/ip.h> | 70 | #include <net/ip.h> |
71 | #include <net/ipv6.h> | 71 | #include <net/ipv6.h> |
72 | #include <net/transp_v6.h> | 72 | #include <net/transp_v6.h> |
73 | #include <net/addrconf.h> | 73 | #include <net/addrconf.h> |
74 | #include <net/ip6_route.h> | 74 | #include <net/ip6_route.h> |
75 | #include <net/inet_common.h> | 75 | #include <net/inet_common.h> |
76 | #include <net/inet_ecn.h> | 76 | #include <net/inet_ecn.h> |
77 | #include <net/sctp/sctp.h> | 77 | #include <net/sctp/sctp.h> |
78 | 78 | ||
79 | #include <asm/uaccess.h> | 79 | #include <asm/uaccess.h> |
80 | 80 | ||
81 | extern int sctp_inetaddr_event(struct notifier_block *, unsigned long, void *); | ||
82 | static struct notifier_block sctp_inet6addr_notifier = { | 81 | static struct notifier_block sctp_inet6addr_notifier = { |
83 | .notifier_call = sctp_inetaddr_event, | 82 | .notifier_call = sctp_inetaddr_event, |
84 | }; | 83 | }; |
85 | 84 | ||
86 | /* ICMP error handler. */ | 85 | /* ICMP error handler. */ |
87 | SCTP_STATIC void sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, | 86 | SCTP_STATIC void sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, |
88 | int type, int code, int offset, __u32 info) | 87 | int type, int code, int offset, __u32 info) |
89 | { | 88 | { |
90 | struct inet6_dev *idev; | 89 | struct inet6_dev *idev; |
91 | struct ipv6hdr *iph = (struct ipv6hdr *)skb->data; | 90 | struct ipv6hdr *iph = (struct ipv6hdr *)skb->data; |
92 | struct sctphdr *sh = (struct sctphdr *)(skb->data + offset); | 91 | struct sctphdr *sh = (struct sctphdr *)(skb->data + offset); |
93 | struct sock *sk; | 92 | struct sock *sk; |
94 | struct sctp_association *asoc; | 93 | struct sctp_association *asoc; |
95 | struct sctp_transport *transport; | 94 | struct sctp_transport *transport; |
96 | struct ipv6_pinfo *np; | 95 | struct ipv6_pinfo *np; |
97 | char *saveip, *savesctp; | 96 | char *saveip, *savesctp; |
98 | int err; | 97 | int err; |
99 | 98 | ||
100 | idev = in6_dev_get(skb->dev); | 99 | idev = in6_dev_get(skb->dev); |
101 | 100 | ||
102 | /* Fix up skb to look at the embedded net header. */ | 101 | /* Fix up skb to look at the embedded net header. */ |
103 | saveip = skb->nh.raw; | 102 | saveip = skb->nh.raw; |
104 | savesctp = skb->h.raw; | 103 | savesctp = skb->h.raw; |
105 | skb->nh.ipv6h = iph; | 104 | skb->nh.ipv6h = iph; |
106 | skb->h.raw = (char *)sh; | 105 | skb->h.raw = (char *)sh; |
107 | sk = sctp_err_lookup(AF_INET6, skb, sh, &asoc, &transport); | 106 | sk = sctp_err_lookup(AF_INET6, skb, sh, &asoc, &transport); |
108 | /* Put back, the original pointers. */ | 107 | /* Put back, the original pointers. */ |
109 | skb->nh.raw = saveip; | 108 | skb->nh.raw = saveip; |
110 | skb->h.raw = savesctp; | 109 | skb->h.raw = savesctp; |
111 | if (!sk) { | 110 | if (!sk) { |
112 | ICMP6_INC_STATS_BH(idev, ICMP6_MIB_INERRORS); | 111 | ICMP6_INC_STATS_BH(idev, ICMP6_MIB_INERRORS); |
113 | goto out; | 112 | goto out; |
114 | } | 113 | } |
115 | 114 | ||
116 | /* Warning: The sock lock is held. Remember to call | 115 | /* Warning: The sock lock is held. Remember to call |
117 | * sctp_err_finish! | 116 | * sctp_err_finish! |
118 | */ | 117 | */ |
119 | 118 | ||
120 | switch (type) { | 119 | switch (type) { |
121 | case ICMPV6_PKT_TOOBIG: | 120 | case ICMPV6_PKT_TOOBIG: |
122 | sctp_icmp_frag_needed(sk, asoc, transport, ntohl(info)); | 121 | sctp_icmp_frag_needed(sk, asoc, transport, ntohl(info)); |
123 | goto out_unlock; | 122 | goto out_unlock; |
124 | case ICMPV6_PARAMPROB: | 123 | case ICMPV6_PARAMPROB: |
125 | if (ICMPV6_UNK_NEXTHDR == code) { | 124 | if (ICMPV6_UNK_NEXTHDR == code) { |
126 | sctp_icmp_proto_unreachable(sk, asoc, transport); | 125 | sctp_icmp_proto_unreachable(sk, asoc, transport); |
127 | goto out_unlock; | 126 | goto out_unlock; |
128 | } | 127 | } |
129 | break; | 128 | break; |
130 | default: | 129 | default: |
131 | break; | 130 | break; |
132 | } | 131 | } |
133 | 132 | ||
134 | np = inet6_sk(sk); | 133 | np = inet6_sk(sk); |
135 | icmpv6_err_convert(type, code, &err); | 134 | icmpv6_err_convert(type, code, &err); |
136 | if (!sock_owned_by_user(sk) && np->recverr) { | 135 | if (!sock_owned_by_user(sk) && np->recverr) { |
137 | sk->sk_err = err; | 136 | sk->sk_err = err; |
138 | sk->sk_error_report(sk); | 137 | sk->sk_error_report(sk); |
139 | } else { /* Only an error on timeout */ | 138 | } else { /* Only an error on timeout */ |
140 | sk->sk_err_soft = err; | 139 | sk->sk_err_soft = err; |
141 | } | 140 | } |
142 | 141 | ||
143 | out_unlock: | 142 | out_unlock: |
144 | sctp_err_finish(sk, asoc); | 143 | sctp_err_finish(sk, asoc); |
145 | out: | 144 | out: |
146 | if (likely(idev != NULL)) | 145 | if (likely(idev != NULL)) |
147 | in6_dev_put(idev); | 146 | in6_dev_put(idev); |
148 | } | 147 | } |
149 | 148 | ||
150 | /* Based on tcp_v6_xmit() in tcp_ipv6.c. */ | 149 | /* Based on tcp_v6_xmit() in tcp_ipv6.c. */ |
151 | static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport, | 150 | static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport, |
152 | int ipfragok) | 151 | int ipfragok) |
153 | { | 152 | { |
154 | struct sock *sk = skb->sk; | 153 | struct sock *sk = skb->sk; |
155 | struct ipv6_pinfo *np = inet6_sk(sk); | 154 | struct ipv6_pinfo *np = inet6_sk(sk); |
156 | struct flowi fl; | 155 | struct flowi fl; |
157 | 156 | ||
158 | memset(&fl, 0, sizeof(fl)); | 157 | memset(&fl, 0, sizeof(fl)); |
159 | 158 | ||
160 | fl.proto = sk->sk_protocol; | 159 | fl.proto = sk->sk_protocol; |
161 | 160 | ||
162 | /* Fill in the dest address from the route entry passed with the skb | 161 | /* Fill in the dest address from the route entry passed with the skb |
163 | * and the source address from the transport. | 162 | * and the source address from the transport. |
164 | */ | 163 | */ |
165 | ipv6_addr_copy(&fl.fl6_dst, &transport->ipaddr.v6.sin6_addr); | 164 | ipv6_addr_copy(&fl.fl6_dst, &transport->ipaddr.v6.sin6_addr); |
166 | ipv6_addr_copy(&fl.fl6_src, &transport->saddr.v6.sin6_addr); | 165 | ipv6_addr_copy(&fl.fl6_src, &transport->saddr.v6.sin6_addr); |
167 | 166 | ||
168 | fl.fl6_flowlabel = np->flow_label; | 167 | fl.fl6_flowlabel = np->flow_label; |
169 | IP6_ECN_flow_xmit(sk, fl.fl6_flowlabel); | 168 | IP6_ECN_flow_xmit(sk, fl.fl6_flowlabel); |
170 | if (ipv6_addr_type(&fl.fl6_src) & IPV6_ADDR_LINKLOCAL) | 169 | if (ipv6_addr_type(&fl.fl6_src) & IPV6_ADDR_LINKLOCAL) |
171 | fl.oif = transport->saddr.v6.sin6_scope_id; | 170 | fl.oif = transport->saddr.v6.sin6_scope_id; |
172 | else | 171 | else |
173 | fl.oif = sk->sk_bound_dev_if; | 172 | fl.oif = sk->sk_bound_dev_if; |
174 | fl.fl_ip_sport = inet_sk(sk)->sport; | 173 | fl.fl_ip_sport = inet_sk(sk)->sport; |
175 | fl.fl_ip_dport = transport->ipaddr.v6.sin6_port; | 174 | fl.fl_ip_dport = transport->ipaddr.v6.sin6_port; |
176 | 175 | ||
177 | if (np->opt && np->opt->srcrt) { | 176 | if (np->opt && np->opt->srcrt) { |
178 | struct rt0_hdr *rt0 = (struct rt0_hdr *) np->opt->srcrt; | 177 | struct rt0_hdr *rt0 = (struct rt0_hdr *) np->opt->srcrt; |
179 | ipv6_addr_copy(&fl.fl6_dst, rt0->addr); | 178 | ipv6_addr_copy(&fl.fl6_dst, rt0->addr); |
180 | } | 179 | } |
181 | 180 | ||
182 | SCTP_DEBUG_PRINTK("%s: skb:%p, len:%d, " | 181 | SCTP_DEBUG_PRINTK("%s: skb:%p, len:%d, " |
183 | "src:" NIP6_FMT " dst:" NIP6_FMT "\n", | 182 | "src:" NIP6_FMT " dst:" NIP6_FMT "\n", |
184 | __FUNCTION__, skb, skb->len, | 183 | __FUNCTION__, skb, skb->len, |
185 | NIP6(fl.fl6_src), NIP6(fl.fl6_dst)); | 184 | NIP6(fl.fl6_src), NIP6(fl.fl6_dst)); |
186 | 185 | ||
187 | SCTP_INC_STATS(SCTP_MIB_OUTSCTPPACKS); | 186 | SCTP_INC_STATS(SCTP_MIB_OUTSCTPPACKS); |
188 | 187 | ||
189 | return ip6_xmit(sk, skb, &fl, np->opt, ipfragok); | 188 | return ip6_xmit(sk, skb, &fl, np->opt, ipfragok); |
190 | } | 189 | } |
191 | 190 | ||
192 | /* Returns the dst cache entry for the given source and destination ip | 191 | /* Returns the dst cache entry for the given source and destination ip |
193 | * addresses. | 192 | * addresses. |
194 | */ | 193 | */ |
195 | static struct dst_entry *sctp_v6_get_dst(struct sctp_association *asoc, | 194 | static struct dst_entry *sctp_v6_get_dst(struct sctp_association *asoc, |
196 | union sctp_addr *daddr, | 195 | union sctp_addr *daddr, |
197 | union sctp_addr *saddr) | 196 | union sctp_addr *saddr) |
198 | { | 197 | { |
199 | struct dst_entry *dst; | 198 | struct dst_entry *dst; |
200 | struct flowi fl; | 199 | struct flowi fl; |
201 | 200 | ||
202 | memset(&fl, 0, sizeof(fl)); | 201 | memset(&fl, 0, sizeof(fl)); |
203 | ipv6_addr_copy(&fl.fl6_dst, &daddr->v6.sin6_addr); | 202 | ipv6_addr_copy(&fl.fl6_dst, &daddr->v6.sin6_addr); |
204 | if (ipv6_addr_type(&daddr->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL) | 203 | if (ipv6_addr_type(&daddr->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL) |
205 | fl.oif = daddr->v6.sin6_scope_id; | 204 | fl.oif = daddr->v6.sin6_scope_id; |
206 | 205 | ||
207 | 206 | ||
208 | SCTP_DEBUG_PRINTK("%s: DST=" NIP6_FMT " ", | 207 | SCTP_DEBUG_PRINTK("%s: DST=" NIP6_FMT " ", |
209 | __FUNCTION__, NIP6(fl.fl6_dst)); | 208 | __FUNCTION__, NIP6(fl.fl6_dst)); |
210 | 209 | ||
211 | if (saddr) { | 210 | if (saddr) { |
212 | ipv6_addr_copy(&fl.fl6_src, &saddr->v6.sin6_addr); | 211 | ipv6_addr_copy(&fl.fl6_src, &saddr->v6.sin6_addr); |
213 | SCTP_DEBUG_PRINTK( | 212 | SCTP_DEBUG_PRINTK( |
214 | "SRC=" NIP6_FMT " - ", | 213 | "SRC=" NIP6_FMT " - ", |
215 | NIP6(fl.fl6_src)); | 214 | NIP6(fl.fl6_src)); |
216 | } | 215 | } |
217 | 216 | ||
218 | dst = ip6_route_output(NULL, &fl); | 217 | dst = ip6_route_output(NULL, &fl); |
219 | if (dst) { | 218 | if (dst) { |
220 | struct rt6_info *rt; | 219 | struct rt6_info *rt; |
221 | rt = (struct rt6_info *)dst; | 220 | rt = (struct rt6_info *)dst; |
222 | SCTP_DEBUG_PRINTK( | 221 | SCTP_DEBUG_PRINTK( |
223 | "rt6_dst:" NIP6_FMT " rt6_src:" NIP6_FMT "\n", | 222 | "rt6_dst:" NIP6_FMT " rt6_src:" NIP6_FMT "\n", |
224 | NIP6(rt->rt6i_dst.addr), NIP6(rt->rt6i_src.addr)); | 223 | NIP6(rt->rt6i_dst.addr), NIP6(rt->rt6i_src.addr)); |
225 | } else { | 224 | } else { |
226 | SCTP_DEBUG_PRINTK("NO ROUTE\n"); | 225 | SCTP_DEBUG_PRINTK("NO ROUTE\n"); |
227 | } | 226 | } |
228 | 227 | ||
229 | return dst; | 228 | return dst; |
230 | } | 229 | } |
231 | 230 | ||
232 | /* Returns the number of consecutive initial bits that match in the 2 ipv6 | 231 | /* Returns the number of consecutive initial bits that match in the 2 ipv6 |
233 | * addresses. | 232 | * addresses. |
234 | */ | 233 | */ |
235 | static inline int sctp_v6_addr_match_len(union sctp_addr *s1, | 234 | static inline int sctp_v6_addr_match_len(union sctp_addr *s1, |
236 | union sctp_addr *s2) | 235 | union sctp_addr *s2) |
237 | { | 236 | { |
238 | struct in6_addr *a1 = &s1->v6.sin6_addr; | 237 | struct in6_addr *a1 = &s1->v6.sin6_addr; |
239 | struct in6_addr *a2 = &s2->v6.sin6_addr; | 238 | struct in6_addr *a2 = &s2->v6.sin6_addr; |
240 | int i, j; | 239 | int i, j; |
241 | 240 | ||
242 | for (i = 0; i < 4 ; i++) { | 241 | for (i = 0; i < 4 ; i++) { |
243 | __u32 a1xora2; | 242 | __u32 a1xora2; |
244 | 243 | ||
245 | a1xora2 = a1->s6_addr32[i] ^ a2->s6_addr32[i]; | 244 | a1xora2 = a1->s6_addr32[i] ^ a2->s6_addr32[i]; |
246 | 245 | ||
247 | if ((j = fls(ntohl(a1xora2)))) | 246 | if ((j = fls(ntohl(a1xora2)))) |
248 | return (i * 32 + 32 - j); | 247 | return (i * 32 + 32 - j); |
249 | } | 248 | } |
250 | 249 | ||
251 | return (i*32); | 250 | return (i*32); |
252 | } | 251 | } |
253 | 252 | ||
254 | /* Fills in the source address(saddr) based on the destination address(daddr) | 253 | /* Fills in the source address(saddr) based on the destination address(daddr) |
255 | * and asoc's bind address list. | 254 | * and asoc's bind address list. |
256 | */ | 255 | */ |
257 | static void sctp_v6_get_saddr(struct sctp_association *asoc, | 256 | static void sctp_v6_get_saddr(struct sctp_association *asoc, |
258 | struct dst_entry *dst, | 257 | struct dst_entry *dst, |
259 | union sctp_addr *daddr, | 258 | union sctp_addr *daddr, |
260 | union sctp_addr *saddr) | 259 | union sctp_addr *saddr) |
261 | { | 260 | { |
262 | struct sctp_bind_addr *bp; | 261 | struct sctp_bind_addr *bp; |
263 | rwlock_t *addr_lock; | 262 | rwlock_t *addr_lock; |
264 | struct sctp_sockaddr_entry *laddr; | 263 | struct sctp_sockaddr_entry *laddr; |
265 | struct list_head *pos; | 264 | struct list_head *pos; |
266 | sctp_scope_t scope; | 265 | sctp_scope_t scope; |
267 | union sctp_addr *baddr = NULL; | 266 | union sctp_addr *baddr = NULL; |
268 | __u8 matchlen = 0; | 267 | __u8 matchlen = 0; |
269 | __u8 bmatchlen; | 268 | __u8 bmatchlen; |
270 | 269 | ||
271 | SCTP_DEBUG_PRINTK("%s: asoc:%p dst:%p " | 270 | SCTP_DEBUG_PRINTK("%s: asoc:%p dst:%p " |
272 | "daddr:" NIP6_FMT " ", | 271 | "daddr:" NIP6_FMT " ", |
273 | __FUNCTION__, asoc, dst, NIP6(daddr->v6.sin6_addr)); | 272 | __FUNCTION__, asoc, dst, NIP6(daddr->v6.sin6_addr)); |
274 | 273 | ||
275 | if (!asoc) { | 274 | if (!asoc) { |
276 | ipv6_get_saddr(dst, &daddr->v6.sin6_addr,&saddr->v6.sin6_addr); | 275 | ipv6_get_saddr(dst, &daddr->v6.sin6_addr,&saddr->v6.sin6_addr); |
277 | SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: " NIP6_FMT "\n", | 276 | SCTP_DEBUG_PRINTK("saddr from ipv6_get_saddr: " NIP6_FMT "\n", |
278 | NIP6(saddr->v6.sin6_addr)); | 277 | NIP6(saddr->v6.sin6_addr)); |
279 | return; | 278 | return; |
280 | } | 279 | } |
281 | 280 | ||
282 | scope = sctp_scope(daddr); | 281 | scope = sctp_scope(daddr); |
283 | 282 | ||
284 | bp = &asoc->base.bind_addr; | 283 | bp = &asoc->base.bind_addr; |
285 | addr_lock = &asoc->base.addr_lock; | 284 | addr_lock = &asoc->base.addr_lock; |
286 | 285 | ||
287 | /* Go through the bind address list and find the best source address | 286 | /* Go through the bind address list and find the best source address |
288 | * that matches the scope of the destination address. | 287 | * that matches the scope of the destination address. |
289 | */ | 288 | */ |
290 | sctp_read_lock(addr_lock); | 289 | sctp_read_lock(addr_lock); |
291 | list_for_each(pos, &bp->address_list) { | 290 | list_for_each(pos, &bp->address_list) { |
292 | laddr = list_entry(pos, struct sctp_sockaddr_entry, list); | 291 | laddr = list_entry(pos, struct sctp_sockaddr_entry, list); |
293 | if ((laddr->use_as_src) && | 292 | if ((laddr->use_as_src) && |
294 | (laddr->a.sa.sa_family == AF_INET6) && | 293 | (laddr->a.sa.sa_family == AF_INET6) && |
295 | (scope <= sctp_scope(&laddr->a))) { | 294 | (scope <= sctp_scope(&laddr->a))) { |
296 | bmatchlen = sctp_v6_addr_match_len(daddr, &laddr->a); | 295 | bmatchlen = sctp_v6_addr_match_len(daddr, &laddr->a); |
297 | if (!baddr || (matchlen < bmatchlen)) { | 296 | if (!baddr || (matchlen < bmatchlen)) { |
298 | baddr = &laddr->a; | 297 | baddr = &laddr->a; |
299 | matchlen = bmatchlen; | 298 | matchlen = bmatchlen; |
300 | } | 299 | } |
301 | } | 300 | } |
302 | } | 301 | } |
303 | 302 | ||
304 | if (baddr) { | 303 | if (baddr) { |
305 | memcpy(saddr, baddr, sizeof(union sctp_addr)); | 304 | memcpy(saddr, baddr, sizeof(union sctp_addr)); |
306 | SCTP_DEBUG_PRINTK("saddr: " NIP6_FMT "\n", | 305 | SCTP_DEBUG_PRINTK("saddr: " NIP6_FMT "\n", |
307 | NIP6(saddr->v6.sin6_addr)); | 306 | NIP6(saddr->v6.sin6_addr)); |
308 | } else { | 307 | } else { |
309 | printk(KERN_ERR "%s: asoc:%p Could not find a valid source " | 308 | printk(KERN_ERR "%s: asoc:%p Could not find a valid source " |
310 | "address for the dest:" NIP6_FMT "\n", | 309 | "address for the dest:" NIP6_FMT "\n", |
311 | __FUNCTION__, asoc, NIP6(daddr->v6.sin6_addr)); | 310 | __FUNCTION__, asoc, NIP6(daddr->v6.sin6_addr)); |
312 | } | 311 | } |
313 | 312 | ||
314 | sctp_read_unlock(addr_lock); | 313 | sctp_read_unlock(addr_lock); |
315 | } | 314 | } |
316 | 315 | ||
317 | /* Make a copy of all potential local addresses. */ | 316 | /* Make a copy of all potential local addresses. */ |
318 | static void sctp_v6_copy_addrlist(struct list_head *addrlist, | 317 | static void sctp_v6_copy_addrlist(struct list_head *addrlist, |
319 | struct net_device *dev) | 318 | struct net_device *dev) |
320 | { | 319 | { |
321 | struct inet6_dev *in6_dev; | 320 | struct inet6_dev *in6_dev; |
322 | struct inet6_ifaddr *ifp; | 321 | struct inet6_ifaddr *ifp; |
323 | struct sctp_sockaddr_entry *addr; | 322 | struct sctp_sockaddr_entry *addr; |
324 | 323 | ||
325 | read_lock(&addrconf_lock); | 324 | read_lock(&addrconf_lock); |
326 | if ((in6_dev = __in6_dev_get(dev)) == NULL) { | 325 | if ((in6_dev = __in6_dev_get(dev)) == NULL) { |
327 | read_unlock(&addrconf_lock); | 326 | read_unlock(&addrconf_lock); |
328 | return; | 327 | return; |
329 | } | 328 | } |
330 | 329 | ||
331 | read_lock(&in6_dev->lock); | 330 | read_lock(&in6_dev->lock); |
332 | for (ifp = in6_dev->addr_list; ifp; ifp = ifp->if_next) { | 331 | for (ifp = in6_dev->addr_list; ifp; ifp = ifp->if_next) { |
333 | /* Add the address to the local list. */ | 332 | /* Add the address to the local list. */ |
334 | addr = t_new(struct sctp_sockaddr_entry, GFP_ATOMIC); | 333 | addr = t_new(struct sctp_sockaddr_entry, GFP_ATOMIC); |
335 | if (addr) { | 334 | if (addr) { |
336 | addr->a.v6.sin6_family = AF_INET6; | 335 | addr->a.v6.sin6_family = AF_INET6; |
337 | addr->a.v6.sin6_port = 0; | 336 | addr->a.v6.sin6_port = 0; |
338 | addr->a.v6.sin6_addr = ifp->addr; | 337 | addr->a.v6.sin6_addr = ifp->addr; |
339 | addr->a.v6.sin6_scope_id = dev->ifindex; | 338 | addr->a.v6.sin6_scope_id = dev->ifindex; |
340 | INIT_LIST_HEAD(&addr->list); | 339 | INIT_LIST_HEAD(&addr->list); |
341 | list_add_tail(&addr->list, addrlist); | 340 | list_add_tail(&addr->list, addrlist); |
342 | } | 341 | } |
343 | } | 342 | } |
344 | 343 | ||
345 | read_unlock(&in6_dev->lock); | 344 | read_unlock(&in6_dev->lock); |
346 | read_unlock(&addrconf_lock); | 345 | read_unlock(&addrconf_lock); |
347 | } | 346 | } |
348 | 347 | ||
349 | /* Initialize a sockaddr_storage from in incoming skb. */ | 348 | /* Initialize a sockaddr_storage from in incoming skb. */ |
350 | static void sctp_v6_from_skb(union sctp_addr *addr,struct sk_buff *skb, | 349 | static void sctp_v6_from_skb(union sctp_addr *addr,struct sk_buff *skb, |
351 | int is_saddr) | 350 | int is_saddr) |
352 | { | 351 | { |
353 | void *from; | 352 | void *from; |
354 | __u16 *port; | 353 | __u16 *port; |
355 | struct sctphdr *sh; | 354 | struct sctphdr *sh; |
356 | 355 | ||
357 | port = &addr->v6.sin6_port; | 356 | port = &addr->v6.sin6_port; |
358 | addr->v6.sin6_family = AF_INET6; | 357 | addr->v6.sin6_family = AF_INET6; |
359 | addr->v6.sin6_flowinfo = 0; /* FIXME */ | 358 | addr->v6.sin6_flowinfo = 0; /* FIXME */ |
360 | addr->v6.sin6_scope_id = ((struct inet6_skb_parm *)skb->cb)->iif; | 359 | addr->v6.sin6_scope_id = ((struct inet6_skb_parm *)skb->cb)->iif; |
361 | 360 | ||
362 | sh = (struct sctphdr *) skb->h.raw; | 361 | sh = (struct sctphdr *) skb->h.raw; |
363 | if (is_saddr) { | 362 | if (is_saddr) { |
364 | *port = ntohs(sh->source); | 363 | *port = ntohs(sh->source); |
365 | from = &skb->nh.ipv6h->saddr; | 364 | from = &skb->nh.ipv6h->saddr; |
366 | } else { | 365 | } else { |
367 | *port = ntohs(sh->dest); | 366 | *port = ntohs(sh->dest); |
368 | from = &skb->nh.ipv6h->daddr; | 367 | from = &skb->nh.ipv6h->daddr; |
369 | } | 368 | } |
370 | ipv6_addr_copy(&addr->v6.sin6_addr, from); | 369 | ipv6_addr_copy(&addr->v6.sin6_addr, from); |
371 | } | 370 | } |
372 | 371 | ||
373 | /* Initialize an sctp_addr from a socket. */ | 372 | /* Initialize an sctp_addr from a socket. */ |
374 | static void sctp_v6_from_sk(union sctp_addr *addr, struct sock *sk) | 373 | static void sctp_v6_from_sk(union sctp_addr *addr, struct sock *sk) |
375 | { | 374 | { |
376 | addr->v6.sin6_family = AF_INET6; | 375 | addr->v6.sin6_family = AF_INET6; |
377 | addr->v6.sin6_port = inet_sk(sk)->num; | 376 | addr->v6.sin6_port = inet_sk(sk)->num; |
378 | addr->v6.sin6_addr = inet6_sk(sk)->rcv_saddr; | 377 | addr->v6.sin6_addr = inet6_sk(sk)->rcv_saddr; |
379 | } | 378 | } |
380 | 379 | ||
381 | /* Initialize sk->sk_rcv_saddr from sctp_addr. */ | 380 | /* Initialize sk->sk_rcv_saddr from sctp_addr. */ |
382 | static void sctp_v6_to_sk_saddr(union sctp_addr *addr, struct sock *sk) | 381 | static void sctp_v6_to_sk_saddr(union sctp_addr *addr, struct sock *sk) |
383 | { | 382 | { |
384 | if (addr->sa.sa_family == AF_INET && sctp_sk(sk)->v4mapped) { | 383 | if (addr->sa.sa_family == AF_INET && sctp_sk(sk)->v4mapped) { |
385 | inet6_sk(sk)->rcv_saddr.s6_addr32[0] = 0; | 384 | inet6_sk(sk)->rcv_saddr.s6_addr32[0] = 0; |
386 | inet6_sk(sk)->rcv_saddr.s6_addr32[1] = 0; | 385 | inet6_sk(sk)->rcv_saddr.s6_addr32[1] = 0; |
387 | inet6_sk(sk)->rcv_saddr.s6_addr32[2] = htonl(0x0000ffff); | 386 | inet6_sk(sk)->rcv_saddr.s6_addr32[2] = htonl(0x0000ffff); |
388 | inet6_sk(sk)->rcv_saddr.s6_addr32[3] = | 387 | inet6_sk(sk)->rcv_saddr.s6_addr32[3] = |
389 | addr->v4.sin_addr.s_addr; | 388 | addr->v4.sin_addr.s_addr; |
390 | } else { | 389 | } else { |
391 | inet6_sk(sk)->rcv_saddr = addr->v6.sin6_addr; | 390 | inet6_sk(sk)->rcv_saddr = addr->v6.sin6_addr; |
392 | } | 391 | } |
393 | } | 392 | } |
394 | 393 | ||
395 | /* Initialize sk->sk_daddr from sctp_addr. */ | 394 | /* Initialize sk->sk_daddr from sctp_addr. */ |
396 | static void sctp_v6_to_sk_daddr(union sctp_addr *addr, struct sock *sk) | 395 | static void sctp_v6_to_sk_daddr(union sctp_addr *addr, struct sock *sk) |
397 | { | 396 | { |
398 | if (addr->sa.sa_family == AF_INET && sctp_sk(sk)->v4mapped) { | 397 | if (addr->sa.sa_family == AF_INET && sctp_sk(sk)->v4mapped) { |
399 | inet6_sk(sk)->daddr.s6_addr32[0] = 0; | 398 | inet6_sk(sk)->daddr.s6_addr32[0] = 0; |
400 | inet6_sk(sk)->daddr.s6_addr32[1] = 0; | 399 | inet6_sk(sk)->daddr.s6_addr32[1] = 0; |
401 | inet6_sk(sk)->daddr.s6_addr32[2] = htonl(0x0000ffff); | 400 | inet6_sk(sk)->daddr.s6_addr32[2] = htonl(0x0000ffff); |
402 | inet6_sk(sk)->daddr.s6_addr32[3] = addr->v4.sin_addr.s_addr; | 401 | inet6_sk(sk)->daddr.s6_addr32[3] = addr->v4.sin_addr.s_addr; |
403 | } else { | 402 | } else { |
404 | inet6_sk(sk)->daddr = addr->v6.sin6_addr; | 403 | inet6_sk(sk)->daddr = addr->v6.sin6_addr; |
405 | } | 404 | } |
406 | } | 405 | } |
407 | 406 | ||
408 | /* Initialize a sctp_addr from an address parameter. */ | 407 | /* Initialize a sctp_addr from an address parameter. */ |
409 | static void sctp_v6_from_addr_param(union sctp_addr *addr, | 408 | static void sctp_v6_from_addr_param(union sctp_addr *addr, |
410 | union sctp_addr_param *param, | 409 | union sctp_addr_param *param, |
411 | __u16 port, int iif) | 410 | __u16 port, int iif) |
412 | { | 411 | { |
413 | addr->v6.sin6_family = AF_INET6; | 412 | addr->v6.sin6_family = AF_INET6; |
414 | addr->v6.sin6_port = port; | 413 | addr->v6.sin6_port = port; |
415 | addr->v6.sin6_flowinfo = 0; /* BUG */ | 414 | addr->v6.sin6_flowinfo = 0; /* BUG */ |
416 | ipv6_addr_copy(&addr->v6.sin6_addr, ¶m->v6.addr); | 415 | ipv6_addr_copy(&addr->v6.sin6_addr, ¶m->v6.addr); |
417 | addr->v6.sin6_scope_id = iif; | 416 | addr->v6.sin6_scope_id = iif; |
418 | } | 417 | } |
419 | 418 | ||
420 | /* Initialize an address parameter from a sctp_addr and return the length | 419 | /* Initialize an address parameter from a sctp_addr and return the length |
421 | * of the address parameter. | 420 | * of the address parameter. |
422 | */ | 421 | */ |
423 | static int sctp_v6_to_addr_param(const union sctp_addr *addr, | 422 | static int sctp_v6_to_addr_param(const union sctp_addr *addr, |
424 | union sctp_addr_param *param) | 423 | union sctp_addr_param *param) |
425 | { | 424 | { |
426 | int length = sizeof(sctp_ipv6addr_param_t); | 425 | int length = sizeof(sctp_ipv6addr_param_t); |
427 | 426 | ||
428 | param->v6.param_hdr.type = SCTP_PARAM_IPV6_ADDRESS; | 427 | param->v6.param_hdr.type = SCTP_PARAM_IPV6_ADDRESS; |
429 | param->v6.param_hdr.length = ntohs(length); | 428 | param->v6.param_hdr.length = ntohs(length); |
430 | ipv6_addr_copy(¶m->v6.addr, &addr->v6.sin6_addr); | 429 | ipv6_addr_copy(¶m->v6.addr, &addr->v6.sin6_addr); |
431 | 430 | ||
432 | return length; | 431 | return length; |
433 | } | 432 | } |
434 | 433 | ||
435 | /* Initialize a sctp_addr from a dst_entry. */ | 434 | /* Initialize a sctp_addr from a dst_entry. */ |
436 | static void sctp_v6_dst_saddr(union sctp_addr *addr, struct dst_entry *dst, | 435 | static void sctp_v6_dst_saddr(union sctp_addr *addr, struct dst_entry *dst, |
437 | unsigned short port) | 436 | unsigned short port) |
438 | { | 437 | { |
439 | struct rt6_info *rt = (struct rt6_info *)dst; | 438 | struct rt6_info *rt = (struct rt6_info *)dst; |
440 | addr->sa.sa_family = AF_INET6; | 439 | addr->sa.sa_family = AF_INET6; |
441 | addr->v6.sin6_port = port; | 440 | addr->v6.sin6_port = port; |
442 | ipv6_addr_copy(&addr->v6.sin6_addr, &rt->rt6i_src.addr); | 441 | ipv6_addr_copy(&addr->v6.sin6_addr, &rt->rt6i_src.addr); |
443 | } | 442 | } |
444 | 443 | ||
445 | /* Compare addresses exactly. | 444 | /* Compare addresses exactly. |
446 | * v4-mapped-v6 is also in consideration. | 445 | * v4-mapped-v6 is also in consideration. |
447 | */ | 446 | */ |
448 | static int sctp_v6_cmp_addr(const union sctp_addr *addr1, | 447 | static int sctp_v6_cmp_addr(const union sctp_addr *addr1, |
449 | const union sctp_addr *addr2) | 448 | const union sctp_addr *addr2) |
450 | { | 449 | { |
451 | if (addr1->sa.sa_family != addr2->sa.sa_family) { | 450 | if (addr1->sa.sa_family != addr2->sa.sa_family) { |
452 | if (addr1->sa.sa_family == AF_INET && | 451 | if (addr1->sa.sa_family == AF_INET && |
453 | addr2->sa.sa_family == AF_INET6 && | 452 | addr2->sa.sa_family == AF_INET6 && |
454 | IPV6_ADDR_MAPPED == ipv6_addr_type(&addr2->v6.sin6_addr)) { | 453 | IPV6_ADDR_MAPPED == ipv6_addr_type(&addr2->v6.sin6_addr)) { |
455 | if (addr2->v6.sin6_port == addr1->v4.sin_port && | 454 | if (addr2->v6.sin6_port == addr1->v4.sin_port && |
456 | addr2->v6.sin6_addr.s6_addr32[3] == | 455 | addr2->v6.sin6_addr.s6_addr32[3] == |
457 | addr1->v4.sin_addr.s_addr) | 456 | addr1->v4.sin_addr.s_addr) |
458 | return 1; | 457 | return 1; |
459 | } | 458 | } |
460 | if (addr2->sa.sa_family == AF_INET && | 459 | if (addr2->sa.sa_family == AF_INET && |
461 | addr1->sa.sa_family == AF_INET6 && | 460 | addr1->sa.sa_family == AF_INET6 && |
462 | IPV6_ADDR_MAPPED == ipv6_addr_type(&addr1->v6.sin6_addr)) { | 461 | IPV6_ADDR_MAPPED == ipv6_addr_type(&addr1->v6.sin6_addr)) { |
463 | if (addr1->v6.sin6_port == addr2->v4.sin_port && | 462 | if (addr1->v6.sin6_port == addr2->v4.sin_port && |
464 | addr1->v6.sin6_addr.s6_addr32[3] == | 463 | addr1->v6.sin6_addr.s6_addr32[3] == |
465 | addr2->v4.sin_addr.s_addr) | 464 | addr2->v4.sin_addr.s_addr) |
466 | return 1; | 465 | return 1; |
467 | } | 466 | } |
468 | return 0; | 467 | return 0; |
469 | } | 468 | } |
470 | if (!ipv6_addr_equal(&addr1->v6.sin6_addr, &addr2->v6.sin6_addr)) | 469 | if (!ipv6_addr_equal(&addr1->v6.sin6_addr, &addr2->v6.sin6_addr)) |
471 | return 0; | 470 | return 0; |
472 | /* If this is a linklocal address, compare the scope_id. */ | 471 | /* If this is a linklocal address, compare the scope_id. */ |
473 | if (ipv6_addr_type(&addr1->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL) { | 472 | if (ipv6_addr_type(&addr1->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL) { |
474 | if (addr1->v6.sin6_scope_id && addr2->v6.sin6_scope_id && | 473 | if (addr1->v6.sin6_scope_id && addr2->v6.sin6_scope_id && |
475 | (addr1->v6.sin6_scope_id != addr2->v6.sin6_scope_id)) { | 474 | (addr1->v6.sin6_scope_id != addr2->v6.sin6_scope_id)) { |
476 | return 0; | 475 | return 0; |
477 | } | 476 | } |
478 | } | 477 | } |
479 | 478 | ||
480 | return 1; | 479 | return 1; |
481 | } | 480 | } |
482 | 481 | ||
483 | /* Initialize addr struct to INADDR_ANY. */ | 482 | /* Initialize addr struct to INADDR_ANY. */ |
484 | static void sctp_v6_inaddr_any(union sctp_addr *addr, unsigned short port) | 483 | static void sctp_v6_inaddr_any(union sctp_addr *addr, unsigned short port) |
485 | { | 484 | { |
486 | memset(addr, 0x00, sizeof(union sctp_addr)); | 485 | memset(addr, 0x00, sizeof(union sctp_addr)); |
487 | addr->v6.sin6_family = AF_INET6; | 486 | addr->v6.sin6_family = AF_INET6; |
488 | addr->v6.sin6_port = port; | 487 | addr->v6.sin6_port = port; |
489 | } | 488 | } |
490 | 489 | ||
491 | /* Is this a wildcard address? */ | 490 | /* Is this a wildcard address? */ |
492 | static int sctp_v6_is_any(const union sctp_addr *addr) | 491 | static int sctp_v6_is_any(const union sctp_addr *addr) |
493 | { | 492 | { |
494 | return ipv6_addr_any(&addr->v6.sin6_addr); | 493 | return ipv6_addr_any(&addr->v6.sin6_addr); |
495 | } | 494 | } |
496 | 495 | ||
497 | /* Should this be available for binding? */ | 496 | /* Should this be available for binding? */ |
498 | static int sctp_v6_available(union sctp_addr *addr, struct sctp_sock *sp) | 497 | static int sctp_v6_available(union sctp_addr *addr, struct sctp_sock *sp) |
499 | { | 498 | { |
500 | int type; | 499 | int type; |
501 | struct in6_addr *in6 = (struct in6_addr *)&addr->v6.sin6_addr; | 500 | struct in6_addr *in6 = (struct in6_addr *)&addr->v6.sin6_addr; |
502 | 501 | ||
503 | type = ipv6_addr_type(in6); | 502 | type = ipv6_addr_type(in6); |
504 | if (IPV6_ADDR_ANY == type) | 503 | if (IPV6_ADDR_ANY == type) |
505 | return 1; | 504 | return 1; |
506 | if (type == IPV6_ADDR_MAPPED) { | 505 | if (type == IPV6_ADDR_MAPPED) { |
507 | if (sp && !sp->v4mapped) | 506 | if (sp && !sp->v4mapped) |
508 | return 0; | 507 | return 0; |
509 | if (sp && ipv6_only_sock(sctp_opt2sk(sp))) | 508 | if (sp && ipv6_only_sock(sctp_opt2sk(sp))) |
510 | return 0; | 509 | return 0; |
511 | sctp_v6_map_v4(addr); | 510 | sctp_v6_map_v4(addr); |
512 | return sctp_get_af_specific(AF_INET)->available(addr, sp); | 511 | return sctp_get_af_specific(AF_INET)->available(addr, sp); |
513 | } | 512 | } |
514 | if (!(type & IPV6_ADDR_UNICAST)) | 513 | if (!(type & IPV6_ADDR_UNICAST)) |
515 | return 0; | 514 | return 0; |
516 | 515 | ||
517 | return ipv6_chk_addr(in6, NULL, 0); | 516 | return ipv6_chk_addr(in6, NULL, 0); |
518 | } | 517 | } |
519 | 518 | ||
520 | /* This function checks if the address is a valid address to be used for | 519 | /* This function checks if the address is a valid address to be used for |
521 | * SCTP. | 520 | * SCTP. |
522 | * | 521 | * |
523 | * Output: | 522 | * Output: |
524 | * Return 0 - If the address is a non-unicast or an illegal address. | 523 | * Return 0 - If the address is a non-unicast or an illegal address. |
525 | * Return 1 - If the address is a unicast. | 524 | * Return 1 - If the address is a unicast. |
526 | */ | 525 | */ |
527 | static int sctp_v6_addr_valid(union sctp_addr *addr, | 526 | static int sctp_v6_addr_valid(union sctp_addr *addr, |
528 | struct sctp_sock *sp, | 527 | struct sctp_sock *sp, |
529 | const struct sk_buff *skb) | 528 | const struct sk_buff *skb) |
530 | { | 529 | { |
531 | int ret = ipv6_addr_type(&addr->v6.sin6_addr); | 530 | int ret = ipv6_addr_type(&addr->v6.sin6_addr); |
532 | 531 | ||
533 | /* Support v4-mapped-v6 address. */ | 532 | /* Support v4-mapped-v6 address. */ |
534 | if (ret == IPV6_ADDR_MAPPED) { | 533 | if (ret == IPV6_ADDR_MAPPED) { |
535 | /* Note: This routine is used in input, so v4-mapped-v6 | 534 | /* Note: This routine is used in input, so v4-mapped-v6 |
536 | * are disallowed here when there is no sctp_sock. | 535 | * are disallowed here when there is no sctp_sock. |
537 | */ | 536 | */ |
538 | if (!sp || !sp->v4mapped) | 537 | if (!sp || !sp->v4mapped) |
539 | return 0; | 538 | return 0; |
540 | if (sp && ipv6_only_sock(sctp_opt2sk(sp))) | 539 | if (sp && ipv6_only_sock(sctp_opt2sk(sp))) |
541 | return 0; | 540 | return 0; |
542 | sctp_v6_map_v4(addr); | 541 | sctp_v6_map_v4(addr); |
543 | return sctp_get_af_specific(AF_INET)->addr_valid(addr, sp, skb); | 542 | return sctp_get_af_specific(AF_INET)->addr_valid(addr, sp, skb); |
544 | } | 543 | } |
545 | 544 | ||
546 | /* Is this a non-unicast address */ | 545 | /* Is this a non-unicast address */ |
547 | if (!(ret & IPV6_ADDR_UNICAST)) | 546 | if (!(ret & IPV6_ADDR_UNICAST)) |
548 | return 0; | 547 | return 0; |
549 | 548 | ||
550 | return 1; | 549 | return 1; |
551 | } | 550 | } |
552 | 551 | ||
553 | /* What is the scope of 'addr'? */ | 552 | /* What is the scope of 'addr'? */ |
554 | static sctp_scope_t sctp_v6_scope(union sctp_addr *addr) | 553 | static sctp_scope_t sctp_v6_scope(union sctp_addr *addr) |
555 | { | 554 | { |
556 | int v6scope; | 555 | int v6scope; |
557 | sctp_scope_t retval; | 556 | sctp_scope_t retval; |
558 | 557 | ||
559 | /* The IPv6 scope is really a set of bit fields. | 558 | /* The IPv6 scope is really a set of bit fields. |
560 | * See IFA_* in <net/if_inet6.h>. Map to a generic SCTP scope. | 559 | * See IFA_* in <net/if_inet6.h>. Map to a generic SCTP scope. |
561 | */ | 560 | */ |
562 | 561 | ||
563 | v6scope = ipv6_addr_scope(&addr->v6.sin6_addr); | 562 | v6scope = ipv6_addr_scope(&addr->v6.sin6_addr); |
564 | switch (v6scope) { | 563 | switch (v6scope) { |
565 | case IFA_HOST: | 564 | case IFA_HOST: |
566 | retval = SCTP_SCOPE_LOOPBACK; | 565 | retval = SCTP_SCOPE_LOOPBACK; |
567 | break; | 566 | break; |
568 | case IFA_LINK: | 567 | case IFA_LINK: |
569 | retval = SCTP_SCOPE_LINK; | 568 | retval = SCTP_SCOPE_LINK; |
570 | break; | 569 | break; |
571 | case IFA_SITE: | 570 | case IFA_SITE: |
572 | retval = SCTP_SCOPE_PRIVATE; | 571 | retval = SCTP_SCOPE_PRIVATE; |
573 | break; | 572 | break; |
574 | default: | 573 | default: |
575 | retval = SCTP_SCOPE_GLOBAL; | 574 | retval = SCTP_SCOPE_GLOBAL; |
576 | break; | 575 | break; |
577 | }; | 576 | }; |
578 | 577 | ||
579 | return retval; | 578 | return retval; |
580 | } | 579 | } |
581 | 580 | ||
582 | /* Create and initialize a new sk for the socket to be returned by accept(). */ | 581 | /* Create and initialize a new sk for the socket to be returned by accept(). */ |
583 | static struct sock *sctp_v6_create_accept_sk(struct sock *sk, | 582 | static struct sock *sctp_v6_create_accept_sk(struct sock *sk, |
584 | struct sctp_association *asoc) | 583 | struct sctp_association *asoc) |
585 | { | 584 | { |
586 | struct inet_sock *inet = inet_sk(sk); | 585 | struct inet_sock *inet = inet_sk(sk); |
587 | struct sock *newsk; | 586 | struct sock *newsk; |
588 | struct inet_sock *newinet; | 587 | struct inet_sock *newinet; |
589 | struct ipv6_pinfo *newnp, *np = inet6_sk(sk); | 588 | struct ipv6_pinfo *newnp, *np = inet6_sk(sk); |
590 | struct sctp6_sock *newsctp6sk; | 589 | struct sctp6_sock *newsctp6sk; |
591 | 590 | ||
592 | newsk = sk_alloc(PF_INET6, GFP_KERNEL, sk->sk_prot, 1); | 591 | newsk = sk_alloc(PF_INET6, GFP_KERNEL, sk->sk_prot, 1); |
593 | if (!newsk) | 592 | if (!newsk) |
594 | goto out; | 593 | goto out; |
595 | 594 | ||
596 | sock_init_data(NULL, newsk); | 595 | sock_init_data(NULL, newsk); |
597 | 596 | ||
598 | newsk->sk_type = SOCK_STREAM; | 597 | newsk->sk_type = SOCK_STREAM; |
599 | 598 | ||
600 | newsk->sk_prot = sk->sk_prot; | 599 | newsk->sk_prot = sk->sk_prot; |
601 | newsk->sk_no_check = sk->sk_no_check; | 600 | newsk->sk_no_check = sk->sk_no_check; |
602 | newsk->sk_reuse = sk->sk_reuse; | 601 | newsk->sk_reuse = sk->sk_reuse; |
603 | 602 | ||
604 | newsk->sk_destruct = inet_sock_destruct; | 603 | newsk->sk_destruct = inet_sock_destruct; |
605 | newsk->sk_family = PF_INET6; | 604 | newsk->sk_family = PF_INET6; |
606 | newsk->sk_protocol = IPPROTO_SCTP; | 605 | newsk->sk_protocol = IPPROTO_SCTP; |
607 | newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv; | 606 | newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv; |
608 | newsk->sk_shutdown = sk->sk_shutdown; | 607 | newsk->sk_shutdown = sk->sk_shutdown; |
609 | sock_reset_flag(sk, SOCK_ZAPPED); | 608 | sock_reset_flag(sk, SOCK_ZAPPED); |
610 | 609 | ||
611 | newsctp6sk = (struct sctp6_sock *)newsk; | 610 | newsctp6sk = (struct sctp6_sock *)newsk; |
612 | inet_sk(newsk)->pinet6 = &newsctp6sk->inet6; | 611 | inet_sk(newsk)->pinet6 = &newsctp6sk->inet6; |
613 | 612 | ||
614 | newinet = inet_sk(newsk); | 613 | newinet = inet_sk(newsk); |
615 | newnp = inet6_sk(newsk); | 614 | newnp = inet6_sk(newsk); |
616 | 615 | ||
617 | memcpy(newnp, np, sizeof(struct ipv6_pinfo)); | 616 | memcpy(newnp, np, sizeof(struct ipv6_pinfo)); |
618 | 617 | ||
619 | /* Initialize sk's sport, dport, rcv_saddr and daddr for getsockname() | 618 | /* Initialize sk's sport, dport, rcv_saddr and daddr for getsockname() |
620 | * and getpeername(). | 619 | * and getpeername(). |
621 | */ | 620 | */ |
622 | newinet->sport = inet->sport; | 621 | newinet->sport = inet->sport; |
623 | newnp->saddr = np->saddr; | 622 | newnp->saddr = np->saddr; |
624 | newnp->rcv_saddr = np->rcv_saddr; | 623 | newnp->rcv_saddr = np->rcv_saddr; |
625 | newinet->dport = htons(asoc->peer.port); | 624 | newinet->dport = htons(asoc->peer.port); |
626 | sctp_v6_to_sk_daddr(&asoc->peer.primary_addr, newsk); | 625 | sctp_v6_to_sk_daddr(&asoc->peer.primary_addr, newsk); |
627 | 626 | ||
628 | /* Init the ipv4 part of the socket since we can have sockets | 627 | /* Init the ipv4 part of the socket since we can have sockets |
629 | * using v6 API for ipv4. | 628 | * using v6 API for ipv4. |
630 | */ | 629 | */ |
631 | newinet->uc_ttl = -1; | 630 | newinet->uc_ttl = -1; |
632 | newinet->mc_loop = 1; | 631 | newinet->mc_loop = 1; |
633 | newinet->mc_ttl = 1; | 632 | newinet->mc_ttl = 1; |
634 | newinet->mc_index = 0; | 633 | newinet->mc_index = 0; |
635 | newinet->mc_list = NULL; | 634 | newinet->mc_list = NULL; |
636 | 635 | ||
637 | if (ipv4_config.no_pmtu_disc) | 636 | if (ipv4_config.no_pmtu_disc) |
638 | newinet->pmtudisc = IP_PMTUDISC_DONT; | 637 | newinet->pmtudisc = IP_PMTUDISC_DONT; |
639 | else | 638 | else |
640 | newinet->pmtudisc = IP_PMTUDISC_WANT; | 639 | newinet->pmtudisc = IP_PMTUDISC_WANT; |
641 | 640 | ||
642 | sk_refcnt_debug_inc(newsk); | 641 | sk_refcnt_debug_inc(newsk); |
643 | 642 | ||
644 | if (newsk->sk_prot->init(newsk)) { | 643 | if (newsk->sk_prot->init(newsk)) { |
645 | sk_common_release(newsk); | 644 | sk_common_release(newsk); |
646 | newsk = NULL; | 645 | newsk = NULL; |
647 | } | 646 | } |
648 | 647 | ||
649 | out: | 648 | out: |
650 | return newsk; | 649 | return newsk; |
651 | } | 650 | } |
652 | 651 | ||
653 | /* Map v4 address to mapped v6 address */ | 652 | /* Map v4 address to mapped v6 address */ |
654 | static void sctp_v6_addr_v4map(struct sctp_sock *sp, union sctp_addr *addr) | 653 | static void sctp_v6_addr_v4map(struct sctp_sock *sp, union sctp_addr *addr) |
655 | { | 654 | { |
656 | if (sp->v4mapped && AF_INET == addr->sa.sa_family) | 655 | if (sp->v4mapped && AF_INET == addr->sa.sa_family) |
657 | sctp_v4_map_v6(addr); | 656 | sctp_v4_map_v6(addr); |
658 | } | 657 | } |
659 | 658 | ||
660 | /* Where did this skb come from? */ | 659 | /* Where did this skb come from? */ |
661 | static int sctp_v6_skb_iif(const struct sk_buff *skb) | 660 | static int sctp_v6_skb_iif(const struct sk_buff *skb) |
662 | { | 661 | { |
663 | struct inet6_skb_parm *opt = (struct inet6_skb_parm *) skb->cb; | 662 | struct inet6_skb_parm *opt = (struct inet6_skb_parm *) skb->cb; |
664 | return opt->iif; | 663 | return opt->iif; |
665 | } | 664 | } |
666 | 665 | ||
667 | /* Was this packet marked by Explicit Congestion Notification? */ | 666 | /* Was this packet marked by Explicit Congestion Notification? */ |
668 | static int sctp_v6_is_ce(const struct sk_buff *skb) | 667 | static int sctp_v6_is_ce(const struct sk_buff *skb) |
669 | { | 668 | { |
670 | return *((__u32 *)(skb->nh.ipv6h)) & htonl(1<<20); | 669 | return *((__u32 *)(skb->nh.ipv6h)) & htonl(1<<20); |
671 | } | 670 | } |
672 | 671 | ||
673 | /* Dump the v6 addr to the seq file. */ | 672 | /* Dump the v6 addr to the seq file. */ |
674 | static void sctp_v6_seq_dump_addr(struct seq_file *seq, union sctp_addr *addr) | 673 | static void sctp_v6_seq_dump_addr(struct seq_file *seq, union sctp_addr *addr) |
675 | { | 674 | { |
676 | seq_printf(seq, NIP6_FMT " ", NIP6(addr->v6.sin6_addr)); | 675 | seq_printf(seq, NIP6_FMT " ", NIP6(addr->v6.sin6_addr)); |
677 | } | 676 | } |
678 | 677 | ||
679 | /* Initialize a PF_INET6 socket msg_name. */ | 678 | /* Initialize a PF_INET6 socket msg_name. */ |
680 | static void sctp_inet6_msgname(char *msgname, int *addr_len) | 679 | static void sctp_inet6_msgname(char *msgname, int *addr_len) |
681 | { | 680 | { |
682 | struct sockaddr_in6 *sin6; | 681 | struct sockaddr_in6 *sin6; |
683 | 682 | ||
684 | sin6 = (struct sockaddr_in6 *)msgname; | 683 | sin6 = (struct sockaddr_in6 *)msgname; |
685 | sin6->sin6_family = AF_INET6; | 684 | sin6->sin6_family = AF_INET6; |
686 | sin6->sin6_flowinfo = 0; | 685 | sin6->sin6_flowinfo = 0; |
687 | sin6->sin6_scope_id = 0; /*FIXME */ | 686 | sin6->sin6_scope_id = 0; /*FIXME */ |
688 | *addr_len = sizeof(struct sockaddr_in6); | 687 | *addr_len = sizeof(struct sockaddr_in6); |
689 | } | 688 | } |
690 | 689 | ||
691 | /* Initialize a PF_INET msgname from a ulpevent. */ | 690 | /* Initialize a PF_INET msgname from a ulpevent. */ |
692 | static void sctp_inet6_event_msgname(struct sctp_ulpevent *event, | 691 | static void sctp_inet6_event_msgname(struct sctp_ulpevent *event, |
693 | char *msgname, int *addrlen) | 692 | char *msgname, int *addrlen) |
694 | { | 693 | { |
695 | struct sockaddr_in6 *sin6, *sin6from; | 694 | struct sockaddr_in6 *sin6, *sin6from; |
696 | 695 | ||
697 | if (msgname) { | 696 | if (msgname) { |
698 | union sctp_addr *addr; | 697 | union sctp_addr *addr; |
699 | struct sctp_association *asoc; | 698 | struct sctp_association *asoc; |
700 | 699 | ||
701 | asoc = event->asoc; | 700 | asoc = event->asoc; |
702 | sctp_inet6_msgname(msgname, addrlen); | 701 | sctp_inet6_msgname(msgname, addrlen); |
703 | sin6 = (struct sockaddr_in6 *)msgname; | 702 | sin6 = (struct sockaddr_in6 *)msgname; |
704 | sin6->sin6_port = htons(asoc->peer.port); | 703 | sin6->sin6_port = htons(asoc->peer.port); |
705 | addr = &asoc->peer.primary_addr; | 704 | addr = &asoc->peer.primary_addr; |
706 | 705 | ||
707 | /* Note: If we go to a common v6 format, this code | 706 | /* Note: If we go to a common v6 format, this code |
708 | * will change. | 707 | * will change. |
709 | */ | 708 | */ |
710 | 709 | ||
711 | /* Map ipv4 address into v4-mapped-on-v6 address. */ | 710 | /* Map ipv4 address into v4-mapped-on-v6 address. */ |
712 | if (sctp_sk(asoc->base.sk)->v4mapped && | 711 | if (sctp_sk(asoc->base.sk)->v4mapped && |
713 | AF_INET == addr->sa.sa_family) { | 712 | AF_INET == addr->sa.sa_family) { |
714 | sctp_v4_map_v6((union sctp_addr *)sin6); | 713 | sctp_v4_map_v6((union sctp_addr *)sin6); |
715 | sin6->sin6_addr.s6_addr32[3] = | 714 | sin6->sin6_addr.s6_addr32[3] = |
716 | addr->v4.sin_addr.s_addr; | 715 | addr->v4.sin_addr.s_addr; |
717 | return; | 716 | return; |
718 | } | 717 | } |
719 | 718 | ||
720 | sin6from = &asoc->peer.primary_addr.v6; | 719 | sin6from = &asoc->peer.primary_addr.v6; |
721 | ipv6_addr_copy(&sin6->sin6_addr, &sin6from->sin6_addr); | 720 | ipv6_addr_copy(&sin6->sin6_addr, &sin6from->sin6_addr); |
722 | if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) | 721 | if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) |
723 | sin6->sin6_scope_id = sin6from->sin6_scope_id; | 722 | sin6->sin6_scope_id = sin6from->sin6_scope_id; |
724 | } | 723 | } |
725 | } | 724 | } |
726 | 725 | ||
727 | /* Initialize a msg_name from an inbound skb. */ | 726 | /* Initialize a msg_name from an inbound skb. */ |
728 | static void sctp_inet6_skb_msgname(struct sk_buff *skb, char *msgname, | 727 | static void sctp_inet6_skb_msgname(struct sk_buff *skb, char *msgname, |
729 | int *addr_len) | 728 | int *addr_len) |
730 | { | 729 | { |
731 | struct sctphdr *sh; | 730 | struct sctphdr *sh; |
732 | struct sockaddr_in6 *sin6; | 731 | struct sockaddr_in6 *sin6; |
733 | 732 | ||
734 | if (msgname) { | 733 | if (msgname) { |
735 | sctp_inet6_msgname(msgname, addr_len); | 734 | sctp_inet6_msgname(msgname, addr_len); |
736 | sin6 = (struct sockaddr_in6 *)msgname; | 735 | sin6 = (struct sockaddr_in6 *)msgname; |
737 | sh = (struct sctphdr *)skb->h.raw; | 736 | sh = (struct sctphdr *)skb->h.raw; |
738 | sin6->sin6_port = sh->source; | 737 | sin6->sin6_port = sh->source; |
739 | 738 | ||
740 | /* Map ipv4 address into v4-mapped-on-v6 address. */ | 739 | /* Map ipv4 address into v4-mapped-on-v6 address. */ |
741 | if (sctp_sk(skb->sk)->v4mapped && | 740 | if (sctp_sk(skb->sk)->v4mapped && |
742 | skb->nh.iph->version == 4) { | 741 | skb->nh.iph->version == 4) { |
743 | sctp_v4_map_v6((union sctp_addr *)sin6); | 742 | sctp_v4_map_v6((union sctp_addr *)sin6); |
744 | sin6->sin6_addr.s6_addr32[3] = skb->nh.iph->saddr; | 743 | sin6->sin6_addr.s6_addr32[3] = skb->nh.iph->saddr; |
745 | return; | 744 | return; |
746 | } | 745 | } |
747 | 746 | ||
748 | /* Otherwise, just copy the v6 address. */ | 747 | /* Otherwise, just copy the v6 address. */ |
749 | ipv6_addr_copy(&sin6->sin6_addr, &skb->nh.ipv6h->saddr); | 748 | ipv6_addr_copy(&sin6->sin6_addr, &skb->nh.ipv6h->saddr); |
750 | if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) { | 749 | if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) { |
751 | struct sctp_ulpevent *ev = sctp_skb2event(skb); | 750 | struct sctp_ulpevent *ev = sctp_skb2event(skb); |
752 | sin6->sin6_scope_id = ev->iif; | 751 | sin6->sin6_scope_id = ev->iif; |
753 | } | 752 | } |
754 | } | 753 | } |
755 | } | 754 | } |
756 | 755 | ||
757 | /* Do we support this AF? */ | 756 | /* Do we support this AF? */ |
758 | static int sctp_inet6_af_supported(sa_family_t family, struct sctp_sock *sp) | 757 | static int sctp_inet6_af_supported(sa_family_t family, struct sctp_sock *sp) |
759 | { | 758 | { |
760 | switch (family) { | 759 | switch (family) { |
761 | case AF_INET6: | 760 | case AF_INET6: |
762 | return 1; | 761 | return 1; |
763 | /* v4-mapped-v6 addresses */ | 762 | /* v4-mapped-v6 addresses */ |
764 | case AF_INET: | 763 | case AF_INET: |
765 | if (!__ipv6_only_sock(sctp_opt2sk(sp)) && sp->v4mapped) | 764 | if (!__ipv6_only_sock(sctp_opt2sk(sp)) && sp->v4mapped) |
766 | return 1; | 765 | return 1; |
767 | default: | 766 | default: |
768 | return 0; | 767 | return 0; |
769 | } | 768 | } |
770 | } | 769 | } |
771 | 770 | ||
772 | /* Address matching with wildcards allowed. This extra level | 771 | /* Address matching with wildcards allowed. This extra level |
773 | * of indirection lets us choose whether a PF_INET6 should | 772 | * of indirection lets us choose whether a PF_INET6 should |
774 | * disallow any v4 addresses if we so choose. | 773 | * disallow any v4 addresses if we so choose. |
775 | */ | 774 | */ |
776 | static int sctp_inet6_cmp_addr(const union sctp_addr *addr1, | 775 | static int sctp_inet6_cmp_addr(const union sctp_addr *addr1, |
777 | const union sctp_addr *addr2, | 776 | const union sctp_addr *addr2, |
778 | struct sctp_sock *opt) | 777 | struct sctp_sock *opt) |
779 | { | 778 | { |
780 | struct sctp_af *af1, *af2; | 779 | struct sctp_af *af1, *af2; |
781 | 780 | ||
782 | af1 = sctp_get_af_specific(addr1->sa.sa_family); | 781 | af1 = sctp_get_af_specific(addr1->sa.sa_family); |
783 | af2 = sctp_get_af_specific(addr2->sa.sa_family); | 782 | af2 = sctp_get_af_specific(addr2->sa.sa_family); |
784 | 783 | ||
785 | if (!af1 || !af2) | 784 | if (!af1 || !af2) |
786 | return 0; | 785 | return 0; |
787 | /* Today, wildcard AF_INET/AF_INET6. */ | 786 | /* Today, wildcard AF_INET/AF_INET6. */ |
788 | if (sctp_is_any(addr1) || sctp_is_any(addr2)) | 787 | if (sctp_is_any(addr1) || sctp_is_any(addr2)) |
789 | return 1; | 788 | return 1; |
790 | 789 | ||
791 | if (addr1->sa.sa_family != addr2->sa.sa_family) | 790 | if (addr1->sa.sa_family != addr2->sa.sa_family) |
792 | return 0; | 791 | return 0; |
793 | 792 | ||
794 | return af1->cmp_addr(addr1, addr2); | 793 | return af1->cmp_addr(addr1, addr2); |
795 | } | 794 | } |
796 | 795 | ||
797 | /* Verify that the provided sockaddr looks bindable. Common verification, | 796 | /* Verify that the provided sockaddr looks bindable. Common verification, |
798 | * has already been taken care of. | 797 | * has already been taken care of. |
799 | */ | 798 | */ |
800 | static int sctp_inet6_bind_verify(struct sctp_sock *opt, union sctp_addr *addr) | 799 | static int sctp_inet6_bind_verify(struct sctp_sock *opt, union sctp_addr *addr) |
801 | { | 800 | { |
802 | struct sctp_af *af; | 801 | struct sctp_af *af; |
803 | 802 | ||
804 | /* ASSERT: address family has already been verified. */ | 803 | /* ASSERT: address family has already been verified. */ |
805 | if (addr->sa.sa_family != AF_INET6) | 804 | if (addr->sa.sa_family != AF_INET6) |
806 | af = sctp_get_af_specific(addr->sa.sa_family); | 805 | af = sctp_get_af_specific(addr->sa.sa_family); |
807 | else { | 806 | else { |
808 | int type = ipv6_addr_type(&addr->v6.sin6_addr); | 807 | int type = ipv6_addr_type(&addr->v6.sin6_addr); |
809 | struct net_device *dev; | 808 | struct net_device *dev; |
810 | 809 | ||
811 | if (type & IPV6_ADDR_LINKLOCAL) { | 810 | if (type & IPV6_ADDR_LINKLOCAL) { |
812 | if (!addr->v6.sin6_scope_id) | 811 | if (!addr->v6.sin6_scope_id) |
813 | return 0; | 812 | return 0; |
814 | dev = dev_get_by_index(addr->v6.sin6_scope_id); | 813 | dev = dev_get_by_index(addr->v6.sin6_scope_id); |
815 | if (!dev) | 814 | if (!dev) |
816 | return 0; | 815 | return 0; |
817 | dev_put(dev); | 816 | dev_put(dev); |
818 | } | 817 | } |
819 | af = opt->pf->af; | 818 | af = opt->pf->af; |
820 | } | 819 | } |
821 | return af->available(addr, opt); | 820 | return af->available(addr, opt); |
822 | } | 821 | } |
823 | 822 | ||
824 | /* Verify that the provided sockaddr looks sendable. Common verification, | 823 | /* Verify that the provided sockaddr looks sendable. Common verification, |
825 | * has already been taken care of. | 824 | * has already been taken care of. |
826 | */ | 825 | */ |
827 | static int sctp_inet6_send_verify(struct sctp_sock *opt, union sctp_addr *addr) | 826 | static int sctp_inet6_send_verify(struct sctp_sock *opt, union sctp_addr *addr) |
828 | { | 827 | { |
829 | struct sctp_af *af = NULL; | 828 | struct sctp_af *af = NULL; |
830 | 829 | ||
831 | /* ASSERT: address family has already been verified. */ | 830 | /* ASSERT: address family has already been verified. */ |
832 | if (addr->sa.sa_family != AF_INET6) | 831 | if (addr->sa.sa_family != AF_INET6) |
833 | af = sctp_get_af_specific(addr->sa.sa_family); | 832 | af = sctp_get_af_specific(addr->sa.sa_family); |
834 | else { | 833 | else { |
835 | int type = ipv6_addr_type(&addr->v6.sin6_addr); | 834 | int type = ipv6_addr_type(&addr->v6.sin6_addr); |
836 | struct net_device *dev; | 835 | struct net_device *dev; |
837 | 836 | ||
838 | if (type & IPV6_ADDR_LINKLOCAL) { | 837 | if (type & IPV6_ADDR_LINKLOCAL) { |
839 | if (!addr->v6.sin6_scope_id) | 838 | if (!addr->v6.sin6_scope_id) |
840 | return 0; | 839 | return 0; |
841 | dev = dev_get_by_index(addr->v6.sin6_scope_id); | 840 | dev = dev_get_by_index(addr->v6.sin6_scope_id); |
842 | if (!dev) | 841 | if (!dev) |
843 | return 0; | 842 | return 0; |
844 | dev_put(dev); | 843 | dev_put(dev); |
845 | } | 844 | } |
846 | af = opt->pf->af; | 845 | af = opt->pf->af; |
847 | } | 846 | } |
848 | 847 | ||
849 | return af != NULL; | 848 | return af != NULL; |
850 | } | 849 | } |
851 | 850 | ||
852 | /* Fill in Supported Address Type information for INIT and INIT-ACK | 851 | /* Fill in Supported Address Type information for INIT and INIT-ACK |
853 | * chunks. Note: In the future, we may want to look at sock options | 852 | * chunks. Note: In the future, we may want to look at sock options |
854 | * to determine whether a PF_INET6 socket really wants to have IPV4 | 853 | * to determine whether a PF_INET6 socket really wants to have IPV4 |
855 | * addresses. | 854 | * addresses. |
856 | * Returns number of addresses supported. | 855 | * Returns number of addresses supported. |
857 | */ | 856 | */ |
858 | static int sctp_inet6_supported_addrs(const struct sctp_sock *opt, | 857 | static int sctp_inet6_supported_addrs(const struct sctp_sock *opt, |
859 | __u16 *types) | 858 | __u16 *types) |
860 | { | 859 | { |
861 | types[0] = SCTP_PARAM_IPV4_ADDRESS; | 860 | types[0] = SCTP_PARAM_IPV4_ADDRESS; |
862 | types[1] = SCTP_PARAM_IPV6_ADDRESS; | 861 | types[1] = SCTP_PARAM_IPV6_ADDRESS; |
863 | return 2; | 862 | return 2; |
864 | } | 863 | } |
865 | 864 | ||
866 | static const struct proto_ops inet6_seqpacket_ops = { | 865 | static const struct proto_ops inet6_seqpacket_ops = { |
867 | .family = PF_INET6, | 866 | .family = PF_INET6, |
868 | .owner = THIS_MODULE, | 867 | .owner = THIS_MODULE, |
869 | .release = inet6_release, | 868 | .release = inet6_release, |
870 | .bind = inet6_bind, | 869 | .bind = inet6_bind, |
871 | .connect = inet_dgram_connect, | 870 | .connect = inet_dgram_connect, |
872 | .socketpair = sock_no_socketpair, | 871 | .socketpair = sock_no_socketpair, |
873 | .accept = inet_accept, | 872 | .accept = inet_accept, |
874 | .getname = inet6_getname, | 873 | .getname = inet6_getname, |
875 | .poll = sctp_poll, | 874 | .poll = sctp_poll, |
876 | .ioctl = inet6_ioctl, | 875 | .ioctl = inet6_ioctl, |
877 | .listen = sctp_inet_listen, | 876 | .listen = sctp_inet_listen, |
878 | .shutdown = inet_shutdown, | 877 | .shutdown = inet_shutdown, |
879 | .setsockopt = sock_common_setsockopt, | 878 | .setsockopt = sock_common_setsockopt, |
880 | .getsockopt = sock_common_getsockopt, | 879 | .getsockopt = sock_common_getsockopt, |
881 | .sendmsg = inet_sendmsg, | 880 | .sendmsg = inet_sendmsg, |
882 | .recvmsg = sock_common_recvmsg, | 881 | .recvmsg = sock_common_recvmsg, |
883 | .mmap = sock_no_mmap, | 882 | .mmap = sock_no_mmap, |
884 | #ifdef CONFIG_COMPAT | 883 | #ifdef CONFIG_COMPAT |
885 | .compat_setsockopt = compat_sock_common_setsockopt, | 884 | .compat_setsockopt = compat_sock_common_setsockopt, |
886 | .compat_getsockopt = compat_sock_common_getsockopt, | 885 | .compat_getsockopt = compat_sock_common_getsockopt, |
887 | #endif | 886 | #endif |
888 | }; | 887 | }; |
889 | 888 | ||
890 | static struct inet_protosw sctpv6_seqpacket_protosw = { | 889 | static struct inet_protosw sctpv6_seqpacket_protosw = { |
891 | .type = SOCK_SEQPACKET, | 890 | .type = SOCK_SEQPACKET, |
892 | .protocol = IPPROTO_SCTP, | 891 | .protocol = IPPROTO_SCTP, |
893 | .prot = &sctpv6_prot, | 892 | .prot = &sctpv6_prot, |
894 | .ops = &inet6_seqpacket_ops, | 893 | .ops = &inet6_seqpacket_ops, |
895 | .capability = -1, | 894 | .capability = -1, |
896 | .no_check = 0, | 895 | .no_check = 0, |
897 | .flags = SCTP_PROTOSW_FLAG | 896 | .flags = SCTP_PROTOSW_FLAG |
898 | }; | 897 | }; |
899 | static struct inet_protosw sctpv6_stream_protosw = { | 898 | static struct inet_protosw sctpv6_stream_protosw = { |
900 | .type = SOCK_STREAM, | 899 | .type = SOCK_STREAM, |
901 | .protocol = IPPROTO_SCTP, | 900 | .protocol = IPPROTO_SCTP, |
902 | .prot = &sctpv6_prot, | 901 | .prot = &sctpv6_prot, |
903 | .ops = &inet6_seqpacket_ops, | 902 | .ops = &inet6_seqpacket_ops, |
904 | .capability = -1, | 903 | .capability = -1, |
905 | .no_check = 0, | 904 | .no_check = 0, |
906 | .flags = SCTP_PROTOSW_FLAG, | 905 | .flags = SCTP_PROTOSW_FLAG, |
907 | }; | 906 | }; |
908 | 907 | ||
909 | static int sctp6_rcv(struct sk_buff **pskb) | 908 | static int sctp6_rcv(struct sk_buff **pskb) |
910 | { | 909 | { |
911 | return sctp_rcv(*pskb) ? -1 : 0; | 910 | return sctp_rcv(*pskb) ? -1 : 0; |
912 | } | 911 | } |
913 | 912 | ||
914 | static struct inet6_protocol sctpv6_protocol = { | 913 | static struct inet6_protocol sctpv6_protocol = { |
915 | .handler = sctp6_rcv, | 914 | .handler = sctp6_rcv, |
916 | .err_handler = sctp_v6_err, | 915 | .err_handler = sctp_v6_err, |
917 | .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL, | 916 | .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL, |
918 | }; | 917 | }; |
919 | 918 | ||
920 | static struct sctp_af sctp_ipv6_specific = { | 919 | static struct sctp_af sctp_ipv6_specific = { |
921 | .sa_family = AF_INET6, | 920 | .sa_family = AF_INET6, |
922 | .sctp_xmit = sctp_v6_xmit, | 921 | .sctp_xmit = sctp_v6_xmit, |
923 | .setsockopt = ipv6_setsockopt, | 922 | .setsockopt = ipv6_setsockopt, |
924 | .getsockopt = ipv6_getsockopt, | 923 | .getsockopt = ipv6_getsockopt, |
925 | .get_dst = sctp_v6_get_dst, | 924 | .get_dst = sctp_v6_get_dst, |
926 | .get_saddr = sctp_v6_get_saddr, | 925 | .get_saddr = sctp_v6_get_saddr, |
927 | .copy_addrlist = sctp_v6_copy_addrlist, | 926 | .copy_addrlist = sctp_v6_copy_addrlist, |
928 | .from_skb = sctp_v6_from_skb, | 927 | .from_skb = sctp_v6_from_skb, |
929 | .from_sk = sctp_v6_from_sk, | 928 | .from_sk = sctp_v6_from_sk, |
930 | .to_sk_saddr = sctp_v6_to_sk_saddr, | 929 | .to_sk_saddr = sctp_v6_to_sk_saddr, |
931 | .to_sk_daddr = sctp_v6_to_sk_daddr, | 930 | .to_sk_daddr = sctp_v6_to_sk_daddr, |
932 | .from_addr_param = sctp_v6_from_addr_param, | 931 | .from_addr_param = sctp_v6_from_addr_param, |
933 | .to_addr_param = sctp_v6_to_addr_param, | 932 | .to_addr_param = sctp_v6_to_addr_param, |
934 | .dst_saddr = sctp_v6_dst_saddr, | 933 | .dst_saddr = sctp_v6_dst_saddr, |
935 | .cmp_addr = sctp_v6_cmp_addr, | 934 | .cmp_addr = sctp_v6_cmp_addr, |
936 | .scope = sctp_v6_scope, | 935 | .scope = sctp_v6_scope, |
937 | .addr_valid = sctp_v6_addr_valid, | 936 | .addr_valid = sctp_v6_addr_valid, |
938 | .inaddr_any = sctp_v6_inaddr_any, | 937 | .inaddr_any = sctp_v6_inaddr_any, |
939 | .is_any = sctp_v6_is_any, | 938 | .is_any = sctp_v6_is_any, |
940 | .available = sctp_v6_available, | 939 | .available = sctp_v6_available, |
941 | .skb_iif = sctp_v6_skb_iif, | 940 | .skb_iif = sctp_v6_skb_iif, |
942 | .is_ce = sctp_v6_is_ce, | 941 | .is_ce = sctp_v6_is_ce, |
943 | .seq_dump_addr = sctp_v6_seq_dump_addr, | 942 | .seq_dump_addr = sctp_v6_seq_dump_addr, |
944 | .net_header_len = sizeof(struct ipv6hdr), | 943 | .net_header_len = sizeof(struct ipv6hdr), |
945 | .sockaddr_len = sizeof(struct sockaddr_in6), | 944 | .sockaddr_len = sizeof(struct sockaddr_in6), |
946 | #ifdef CONFIG_COMPAT | 945 | #ifdef CONFIG_COMPAT |
947 | .compat_setsockopt = compat_ipv6_setsockopt, | 946 | .compat_setsockopt = compat_ipv6_setsockopt, |
948 | .compat_getsockopt = compat_ipv6_getsockopt, | 947 | .compat_getsockopt = compat_ipv6_getsockopt, |
949 | #endif | 948 | #endif |
950 | }; | 949 | }; |
951 | 950 | ||
952 | static struct sctp_pf sctp_pf_inet6_specific = { | 951 | static struct sctp_pf sctp_pf_inet6_specific = { |
953 | .event_msgname = sctp_inet6_event_msgname, | 952 | .event_msgname = sctp_inet6_event_msgname, |
954 | .skb_msgname = sctp_inet6_skb_msgname, | 953 | .skb_msgname = sctp_inet6_skb_msgname, |
955 | .af_supported = sctp_inet6_af_supported, | 954 | .af_supported = sctp_inet6_af_supported, |
956 | .cmp_addr = sctp_inet6_cmp_addr, | 955 | .cmp_addr = sctp_inet6_cmp_addr, |
957 | .bind_verify = sctp_inet6_bind_verify, | 956 | .bind_verify = sctp_inet6_bind_verify, |
958 | .send_verify = sctp_inet6_send_verify, | 957 | .send_verify = sctp_inet6_send_verify, |
959 | .supported_addrs = sctp_inet6_supported_addrs, | 958 | .supported_addrs = sctp_inet6_supported_addrs, |
960 | .create_accept_sk = sctp_v6_create_accept_sk, | 959 | .create_accept_sk = sctp_v6_create_accept_sk, |
961 | .addr_v4map = sctp_v6_addr_v4map, | 960 | .addr_v4map = sctp_v6_addr_v4map, |
962 | .af = &sctp_ipv6_specific, | 961 | .af = &sctp_ipv6_specific, |
963 | }; | 962 | }; |
964 | 963 | ||
965 | /* Initialize IPv6 support and register with inet6 stack. */ | 964 | /* Initialize IPv6 support and register with inet6 stack. */ |
966 | int sctp_v6_init(void) | 965 | int sctp_v6_init(void) |
967 | { | 966 | { |
968 | int rc = proto_register(&sctpv6_prot, 1); | 967 | int rc = proto_register(&sctpv6_prot, 1); |
969 | 968 | ||
970 | if (rc) | 969 | if (rc) |
971 | goto out; | 970 | goto out; |
972 | /* Register inet6 protocol. */ | 971 | /* Register inet6 protocol. */ |
973 | rc = -EAGAIN; | 972 | rc = -EAGAIN; |
974 | if (inet6_add_protocol(&sctpv6_protocol, IPPROTO_SCTP) < 0) | 973 | if (inet6_add_protocol(&sctpv6_protocol, IPPROTO_SCTP) < 0) |
975 | goto out_unregister_sctp_proto; | 974 | goto out_unregister_sctp_proto; |
976 | 975 | ||
977 | /* Add SCTPv6(UDP and TCP style) to inetsw6 linked list. */ | 976 | /* Add SCTPv6(UDP and TCP style) to inetsw6 linked list. */ |
978 | inet6_register_protosw(&sctpv6_seqpacket_protosw); | 977 | inet6_register_protosw(&sctpv6_seqpacket_protosw); |
979 | inet6_register_protosw(&sctpv6_stream_protosw); | 978 | inet6_register_protosw(&sctpv6_stream_protosw); |
980 | 979 | ||
981 | /* Register the SCTP specific PF_INET6 functions. */ | 980 | /* Register the SCTP specific PF_INET6 functions. */ |
982 | sctp_register_pf(&sctp_pf_inet6_specific, PF_INET6); | 981 | sctp_register_pf(&sctp_pf_inet6_specific, PF_INET6); |
983 | 982 | ||
984 | /* Register the SCTP specific AF_INET6 functions. */ | 983 | /* Register the SCTP specific AF_INET6 functions. */ |
985 | sctp_register_af(&sctp_ipv6_specific); | 984 | sctp_register_af(&sctp_ipv6_specific); |
986 | 985 | ||
987 | /* Register notifier for inet6 address additions/deletions. */ | 986 | /* Register notifier for inet6 address additions/deletions. */ |
988 | register_inet6addr_notifier(&sctp_inet6addr_notifier); | 987 | register_inet6addr_notifier(&sctp_inet6addr_notifier); |
989 | rc = 0; | 988 | rc = 0; |
990 | out: | 989 | out: |
991 | return rc; | 990 | return rc; |
992 | out_unregister_sctp_proto: | 991 | out_unregister_sctp_proto: |
993 | proto_unregister(&sctpv6_prot); | 992 | proto_unregister(&sctpv6_prot); |
994 | goto out; | 993 | goto out; |
995 | } | 994 | } |
996 | 995 | ||
997 | /* IPv6 specific exit support. */ | 996 | /* IPv6 specific exit support. */ |
998 | void sctp_v6_exit(void) | 997 | void sctp_v6_exit(void) |
999 | { | 998 | { |
1000 | list_del(&sctp_ipv6_specific.list); | 999 | list_del(&sctp_ipv6_specific.list); |
1001 | inet6_del_protocol(&sctpv6_protocol, IPPROTO_SCTP); | 1000 | inet6_del_protocol(&sctpv6_protocol, IPPROTO_SCTP); |
1002 | inet6_unregister_protosw(&sctpv6_seqpacket_protosw); | 1001 | inet6_unregister_protosw(&sctpv6_seqpacket_protosw); |
1003 | inet6_unregister_protosw(&sctpv6_stream_protosw); | 1002 | inet6_unregister_protosw(&sctpv6_stream_protosw); |
1004 | unregister_inet6addr_notifier(&sctp_inet6addr_notifier); | 1003 | unregister_inet6addr_notifier(&sctp_inet6addr_notifier); |
1005 | proto_unregister(&sctpv6_prot); | 1004 | proto_unregister(&sctpv6_prot); |
1006 | } | 1005 | } |
1007 | 1006 |
net/sctp/protocol.c
1 | /* SCTP kernel reference Implementation | 1 | /* SCTP kernel reference Implementation |
2 | * (C) Copyright IBM Corp. 2001, 2004 | 2 | * (C) Copyright IBM Corp. 2001, 2004 |
3 | * Copyright (c) 1999-2000 Cisco, Inc. | 3 | * Copyright (c) 1999-2000 Cisco, Inc. |
4 | * Copyright (c) 1999-2001 Motorola, Inc. | 4 | * Copyright (c) 1999-2001 Motorola, Inc. |
5 | * Copyright (c) 2001 Intel Corp. | 5 | * Copyright (c) 2001 Intel Corp. |
6 | * Copyright (c) 2001 Nokia, Inc. | 6 | * Copyright (c) 2001 Nokia, Inc. |
7 | * Copyright (c) 2001 La Monte H.P. Yarroll | 7 | * Copyright (c) 2001 La Monte H.P. Yarroll |
8 | * | 8 | * |
9 | * This file is part of the SCTP kernel reference Implementation | 9 | * This file is part of the SCTP kernel reference Implementation |
10 | * | 10 | * |
11 | * Initialization/cleanup for SCTP protocol support. | 11 | * Initialization/cleanup for SCTP protocol support. |
12 | * | 12 | * |
13 | * The SCTP reference implementation is free software; | 13 | * The SCTP reference implementation is free software; |
14 | * you can redistribute it and/or modify it under the terms of | 14 | * you can redistribute it and/or modify it under the terms of |
15 | * the GNU General Public License as published by | 15 | * the GNU General Public License as published by |
16 | * the Free Software Foundation; either version 2, or (at your option) | 16 | * the Free Software Foundation; either version 2, or (at your option) |
17 | * any later version. | 17 | * any later version. |
18 | * | 18 | * |
19 | * The SCTP reference implementation is distributed in the hope that it | 19 | * The SCTP reference implementation is distributed in the hope that it |
20 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied | 20 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied |
21 | * ************************ | 21 | * ************************ |
22 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 22 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
23 | * See the GNU General Public License for more details. | 23 | * See the GNU General Public License for more details. |
24 | * | 24 | * |
25 | * You should have received a copy of the GNU General Public License | 25 | * You should have received a copy of the GNU General Public License |
26 | * along with GNU CC; see the file COPYING. If not, write to | 26 | * along with GNU CC; see the file COPYING. If not, write to |
27 | * the Free Software Foundation, 59 Temple Place - Suite 330, | 27 | * the Free Software Foundation, 59 Temple Place - Suite 330, |
28 | * Boston, MA 02111-1307, USA. | 28 | * Boston, MA 02111-1307, USA. |
29 | * | 29 | * |
30 | * Please send any bug reports or fixes you make to the | 30 | * Please send any bug reports or fixes you make to the |
31 | * email address(es): | 31 | * email address(es): |
32 | * lksctp developers <lksctp-developers@lists.sourceforge.net> | 32 | * lksctp developers <lksctp-developers@lists.sourceforge.net> |
33 | * | 33 | * |
34 | * Or submit a bug report through the following website: | 34 | * Or submit a bug report through the following website: |
35 | * http://www.sf.net/projects/lksctp | 35 | * http://www.sf.net/projects/lksctp |
36 | * | 36 | * |
37 | * Written or modified by: | 37 | * Written or modified by: |
38 | * La Monte H.P. Yarroll <piggy@acm.org> | 38 | * La Monte H.P. Yarroll <piggy@acm.org> |
39 | * Karl Knutson <karl@athena.chicago.il.us> | 39 | * Karl Knutson <karl@athena.chicago.il.us> |
40 | * Jon Grimm <jgrimm@us.ibm.com> | 40 | * Jon Grimm <jgrimm@us.ibm.com> |
41 | * Sridhar Samudrala <sri@us.ibm.com> | 41 | * Sridhar Samudrala <sri@us.ibm.com> |
42 | * Daisy Chang <daisyc@us.ibm.com> | 42 | * Daisy Chang <daisyc@us.ibm.com> |
43 | * Ardelle Fan <ardelle.fan@intel.com> | 43 | * Ardelle Fan <ardelle.fan@intel.com> |
44 | * | 44 | * |
45 | * Any bugs reported given to us we will try to fix... any fixes shared will | 45 | * Any bugs reported given to us we will try to fix... any fixes shared will |
46 | * be incorporated into the next SCTP release. | 46 | * be incorporated into the next SCTP release. |
47 | */ | 47 | */ |
48 | 48 | ||
49 | #include <linux/module.h> | 49 | #include <linux/module.h> |
50 | #include <linux/init.h> | 50 | #include <linux/init.h> |
51 | #include <linux/netdevice.h> | 51 | #include <linux/netdevice.h> |
52 | #include <linux/inetdevice.h> | 52 | #include <linux/inetdevice.h> |
53 | #include <linux/seq_file.h> | 53 | #include <linux/seq_file.h> |
54 | #include <net/protocol.h> | 54 | #include <net/protocol.h> |
55 | #include <net/ip.h> | 55 | #include <net/ip.h> |
56 | #include <net/ipv6.h> | 56 | #include <net/ipv6.h> |
57 | #include <net/route.h> | 57 | #include <net/route.h> |
58 | #include <net/sctp/sctp.h> | 58 | #include <net/sctp/sctp.h> |
59 | #include <net/addrconf.h> | 59 | #include <net/addrconf.h> |
60 | #include <net/inet_common.h> | 60 | #include <net/inet_common.h> |
61 | #include <net/inet_ecn.h> | 61 | #include <net/inet_ecn.h> |
62 | 62 | ||
63 | /* Global data structures. */ | 63 | /* Global data structures. */ |
64 | struct sctp_globals sctp_globals __read_mostly; | 64 | struct sctp_globals sctp_globals __read_mostly; |
65 | struct proc_dir_entry *proc_net_sctp; | 65 | struct proc_dir_entry *proc_net_sctp; |
66 | DEFINE_SNMP_STAT(struct sctp_mib, sctp_statistics) __read_mostly; | 66 | DEFINE_SNMP_STAT(struct sctp_mib, sctp_statistics) __read_mostly; |
67 | 67 | ||
68 | struct idr sctp_assocs_id; | 68 | struct idr sctp_assocs_id; |
69 | DEFINE_SPINLOCK(sctp_assocs_id_lock); | 69 | DEFINE_SPINLOCK(sctp_assocs_id_lock); |
70 | 70 | ||
71 | /* This is the global socket data structure used for responding to | 71 | /* This is the global socket data structure used for responding to |
72 | * the Out-of-the-blue (OOTB) packets. A control sock will be created | 72 | * the Out-of-the-blue (OOTB) packets. A control sock will be created |
73 | * for this socket at the initialization time. | 73 | * for this socket at the initialization time. |
74 | */ | 74 | */ |
75 | static struct socket *sctp_ctl_socket; | 75 | static struct socket *sctp_ctl_socket; |
76 | 76 | ||
77 | static struct sctp_pf *sctp_pf_inet6_specific; | 77 | static struct sctp_pf *sctp_pf_inet6_specific; |
78 | static struct sctp_pf *sctp_pf_inet_specific; | 78 | static struct sctp_pf *sctp_pf_inet_specific; |
79 | static struct sctp_af *sctp_af_v4_specific; | 79 | static struct sctp_af *sctp_af_v4_specific; |
80 | static struct sctp_af *sctp_af_v6_specific; | 80 | static struct sctp_af *sctp_af_v6_specific; |
81 | 81 | ||
82 | kmem_cache_t *sctp_chunk_cachep __read_mostly; | 82 | kmem_cache_t *sctp_chunk_cachep __read_mostly; |
83 | kmem_cache_t *sctp_bucket_cachep __read_mostly; | 83 | kmem_cache_t *sctp_bucket_cachep __read_mostly; |
84 | 84 | ||
85 | extern int sctp_snmp_proc_init(void); | ||
86 | extern int sctp_snmp_proc_exit(void); | ||
87 | extern int sctp_eps_proc_init(void); | ||
88 | extern int sctp_eps_proc_exit(void); | ||
89 | extern int sctp_assocs_proc_init(void); | ||
90 | extern int sctp_assocs_proc_exit(void); | ||
91 | |||
92 | /* Return the address of the control sock. */ | 85 | /* Return the address of the control sock. */ |
93 | struct sock *sctp_get_ctl_sock(void) | 86 | struct sock *sctp_get_ctl_sock(void) |
94 | { | 87 | { |
95 | return sctp_ctl_socket->sk; | 88 | return sctp_ctl_socket->sk; |
96 | } | 89 | } |
97 | 90 | ||
98 | /* Set up the proc fs entry for the SCTP protocol. */ | 91 | /* Set up the proc fs entry for the SCTP protocol. */ |
99 | static __init int sctp_proc_init(void) | 92 | static __init int sctp_proc_init(void) |
100 | { | 93 | { |
101 | if (!proc_net_sctp) { | 94 | if (!proc_net_sctp) { |
102 | struct proc_dir_entry *ent; | 95 | struct proc_dir_entry *ent; |
103 | ent = proc_mkdir("net/sctp", NULL); | 96 | ent = proc_mkdir("net/sctp", NULL); |
104 | if (ent) { | 97 | if (ent) { |
105 | ent->owner = THIS_MODULE; | 98 | ent->owner = THIS_MODULE; |
106 | proc_net_sctp = ent; | 99 | proc_net_sctp = ent; |
107 | } else | 100 | } else |
108 | goto out_nomem; | 101 | goto out_nomem; |
109 | } | 102 | } |
110 | 103 | ||
111 | if (sctp_snmp_proc_init()) | 104 | if (sctp_snmp_proc_init()) |
112 | goto out_nomem; | 105 | goto out_nomem; |
113 | if (sctp_eps_proc_init()) | 106 | if (sctp_eps_proc_init()) |
114 | goto out_nomem; | 107 | goto out_nomem; |
115 | if (sctp_assocs_proc_init()) | 108 | if (sctp_assocs_proc_init()) |
116 | goto out_nomem; | 109 | goto out_nomem; |
117 | 110 | ||
118 | return 0; | 111 | return 0; |
119 | 112 | ||
120 | out_nomem: | 113 | out_nomem: |
121 | return -ENOMEM; | 114 | return -ENOMEM; |
122 | } | 115 | } |
123 | 116 | ||
124 | /* Clean up the proc fs entry for the SCTP protocol. | 117 | /* Clean up the proc fs entry for the SCTP protocol. |
125 | * Note: Do not make this __exit as it is used in the init error | 118 | * Note: Do not make this __exit as it is used in the init error |
126 | * path. | 119 | * path. |
127 | */ | 120 | */ |
128 | static void sctp_proc_exit(void) | 121 | static void sctp_proc_exit(void) |
129 | { | 122 | { |
130 | sctp_snmp_proc_exit(); | 123 | sctp_snmp_proc_exit(); |
131 | sctp_eps_proc_exit(); | 124 | sctp_eps_proc_exit(); |
132 | sctp_assocs_proc_exit(); | 125 | sctp_assocs_proc_exit(); |
133 | 126 | ||
134 | if (proc_net_sctp) { | 127 | if (proc_net_sctp) { |
135 | proc_net_sctp = NULL; | 128 | proc_net_sctp = NULL; |
136 | remove_proc_entry("net/sctp", NULL); | 129 | remove_proc_entry("net/sctp", NULL); |
137 | } | 130 | } |
138 | } | 131 | } |
139 | 132 | ||
140 | /* Private helper to extract ipv4 address and stash them in | 133 | /* Private helper to extract ipv4 address and stash them in |
141 | * the protocol structure. | 134 | * the protocol structure. |
142 | */ | 135 | */ |
143 | static void sctp_v4_copy_addrlist(struct list_head *addrlist, | 136 | static void sctp_v4_copy_addrlist(struct list_head *addrlist, |
144 | struct net_device *dev) | 137 | struct net_device *dev) |
145 | { | 138 | { |
146 | struct in_device *in_dev; | 139 | struct in_device *in_dev; |
147 | struct in_ifaddr *ifa; | 140 | struct in_ifaddr *ifa; |
148 | struct sctp_sockaddr_entry *addr; | 141 | struct sctp_sockaddr_entry *addr; |
149 | 142 | ||
150 | rcu_read_lock(); | 143 | rcu_read_lock(); |
151 | if ((in_dev = __in_dev_get_rcu(dev)) == NULL) { | 144 | if ((in_dev = __in_dev_get_rcu(dev)) == NULL) { |
152 | rcu_read_unlock(); | 145 | rcu_read_unlock(); |
153 | return; | 146 | return; |
154 | } | 147 | } |
155 | 148 | ||
156 | for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) { | 149 | for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) { |
157 | /* Add the address to the local list. */ | 150 | /* Add the address to the local list. */ |
158 | addr = t_new(struct sctp_sockaddr_entry, GFP_ATOMIC); | 151 | addr = t_new(struct sctp_sockaddr_entry, GFP_ATOMIC); |
159 | if (addr) { | 152 | if (addr) { |
160 | addr->a.v4.sin_family = AF_INET; | 153 | addr->a.v4.sin_family = AF_INET; |
161 | addr->a.v4.sin_port = 0; | 154 | addr->a.v4.sin_port = 0; |
162 | addr->a.v4.sin_addr.s_addr = ifa->ifa_local; | 155 | addr->a.v4.sin_addr.s_addr = ifa->ifa_local; |
163 | list_add_tail(&addr->list, addrlist); | 156 | list_add_tail(&addr->list, addrlist); |
164 | } | 157 | } |
165 | } | 158 | } |
166 | 159 | ||
167 | rcu_read_unlock(); | 160 | rcu_read_unlock(); |
168 | } | 161 | } |
169 | 162 | ||
170 | /* Extract our IP addresses from the system and stash them in the | 163 | /* Extract our IP addresses from the system and stash them in the |
171 | * protocol structure. | 164 | * protocol structure. |
172 | */ | 165 | */ |
173 | static void __sctp_get_local_addr_list(void) | 166 | static void __sctp_get_local_addr_list(void) |
174 | { | 167 | { |
175 | struct net_device *dev; | 168 | struct net_device *dev; |
176 | struct list_head *pos; | 169 | struct list_head *pos; |
177 | struct sctp_af *af; | 170 | struct sctp_af *af; |
178 | 171 | ||
179 | read_lock(&dev_base_lock); | 172 | read_lock(&dev_base_lock); |
180 | for (dev = dev_base; dev; dev = dev->next) { | 173 | for (dev = dev_base; dev; dev = dev->next) { |
181 | __list_for_each(pos, &sctp_address_families) { | 174 | __list_for_each(pos, &sctp_address_families) { |
182 | af = list_entry(pos, struct sctp_af, list); | 175 | af = list_entry(pos, struct sctp_af, list); |
183 | af->copy_addrlist(&sctp_local_addr_list, dev); | 176 | af->copy_addrlist(&sctp_local_addr_list, dev); |
184 | } | 177 | } |
185 | } | 178 | } |
186 | read_unlock(&dev_base_lock); | 179 | read_unlock(&dev_base_lock); |
187 | } | 180 | } |
188 | 181 | ||
189 | static void sctp_get_local_addr_list(void) | 182 | static void sctp_get_local_addr_list(void) |
190 | { | 183 | { |
191 | unsigned long flags; | 184 | unsigned long flags; |
192 | 185 | ||
193 | sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags); | 186 | sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags); |
194 | __sctp_get_local_addr_list(); | 187 | __sctp_get_local_addr_list(); |
195 | sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags); | 188 | sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags); |
196 | } | 189 | } |
197 | 190 | ||
198 | /* Free the existing local addresses. */ | 191 | /* Free the existing local addresses. */ |
199 | static void __sctp_free_local_addr_list(void) | 192 | static void __sctp_free_local_addr_list(void) |
200 | { | 193 | { |
201 | struct sctp_sockaddr_entry *addr; | 194 | struct sctp_sockaddr_entry *addr; |
202 | struct list_head *pos, *temp; | 195 | struct list_head *pos, *temp; |
203 | 196 | ||
204 | list_for_each_safe(pos, temp, &sctp_local_addr_list) { | 197 | list_for_each_safe(pos, temp, &sctp_local_addr_list) { |
205 | addr = list_entry(pos, struct sctp_sockaddr_entry, list); | 198 | addr = list_entry(pos, struct sctp_sockaddr_entry, list); |
206 | list_del(pos); | 199 | list_del(pos); |
207 | kfree(addr); | 200 | kfree(addr); |
208 | } | 201 | } |
209 | } | 202 | } |
210 | 203 | ||
211 | /* Free the existing local addresses. */ | 204 | /* Free the existing local addresses. */ |
212 | static void sctp_free_local_addr_list(void) | 205 | static void sctp_free_local_addr_list(void) |
213 | { | 206 | { |
214 | unsigned long flags; | 207 | unsigned long flags; |
215 | 208 | ||
216 | sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags); | 209 | sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags); |
217 | __sctp_free_local_addr_list(); | 210 | __sctp_free_local_addr_list(); |
218 | sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags); | 211 | sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags); |
219 | } | 212 | } |
220 | 213 | ||
221 | /* Copy the local addresses which are valid for 'scope' into 'bp'. */ | 214 | /* Copy the local addresses which are valid for 'scope' into 'bp'. */ |
222 | int sctp_copy_local_addr_list(struct sctp_bind_addr *bp, sctp_scope_t scope, | 215 | int sctp_copy_local_addr_list(struct sctp_bind_addr *bp, sctp_scope_t scope, |
223 | gfp_t gfp, int copy_flags) | 216 | gfp_t gfp, int copy_flags) |
224 | { | 217 | { |
225 | struct sctp_sockaddr_entry *addr; | 218 | struct sctp_sockaddr_entry *addr; |
226 | int error = 0; | 219 | int error = 0; |
227 | struct list_head *pos; | 220 | struct list_head *pos; |
228 | unsigned long flags; | 221 | unsigned long flags; |
229 | 222 | ||
230 | sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags); | 223 | sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags); |
231 | list_for_each(pos, &sctp_local_addr_list) { | 224 | list_for_each(pos, &sctp_local_addr_list) { |
232 | addr = list_entry(pos, struct sctp_sockaddr_entry, list); | 225 | addr = list_entry(pos, struct sctp_sockaddr_entry, list); |
233 | if (sctp_in_scope(&addr->a, scope)) { | 226 | if (sctp_in_scope(&addr->a, scope)) { |
234 | /* Now that the address is in scope, check to see if | 227 | /* Now that the address is in scope, check to see if |
235 | * the address type is really supported by the local | 228 | * the address type is really supported by the local |
236 | * sock as well as the remote peer. | 229 | * sock as well as the remote peer. |
237 | */ | 230 | */ |
238 | if ((((AF_INET == addr->a.sa.sa_family) && | 231 | if ((((AF_INET == addr->a.sa.sa_family) && |
239 | (copy_flags & SCTP_ADDR4_PEERSUPP))) || | 232 | (copy_flags & SCTP_ADDR4_PEERSUPP))) || |
240 | (((AF_INET6 == addr->a.sa.sa_family) && | 233 | (((AF_INET6 == addr->a.sa.sa_family) && |
241 | (copy_flags & SCTP_ADDR6_ALLOWED) && | 234 | (copy_flags & SCTP_ADDR6_ALLOWED) && |
242 | (copy_flags & SCTP_ADDR6_PEERSUPP)))) { | 235 | (copy_flags & SCTP_ADDR6_PEERSUPP)))) { |
243 | error = sctp_add_bind_addr(bp, &addr->a, 1, | 236 | error = sctp_add_bind_addr(bp, &addr->a, 1, |
244 | GFP_ATOMIC); | 237 | GFP_ATOMIC); |
245 | if (error) | 238 | if (error) |
246 | goto end_copy; | 239 | goto end_copy; |
247 | } | 240 | } |
248 | } | 241 | } |
249 | } | 242 | } |
250 | 243 | ||
251 | end_copy: | 244 | end_copy: |
252 | sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags); | 245 | sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags); |
253 | return error; | 246 | return error; |
254 | } | 247 | } |
255 | 248 | ||
256 | /* Initialize a sctp_addr from in incoming skb. */ | 249 | /* Initialize a sctp_addr from in incoming skb. */ |
257 | static void sctp_v4_from_skb(union sctp_addr *addr, struct sk_buff *skb, | 250 | static void sctp_v4_from_skb(union sctp_addr *addr, struct sk_buff *skb, |
258 | int is_saddr) | 251 | int is_saddr) |
259 | { | 252 | { |
260 | void *from; | 253 | void *from; |
261 | __u16 *port; | 254 | __u16 *port; |
262 | struct sctphdr *sh; | 255 | struct sctphdr *sh; |
263 | 256 | ||
264 | port = &addr->v4.sin_port; | 257 | port = &addr->v4.sin_port; |
265 | addr->v4.sin_family = AF_INET; | 258 | addr->v4.sin_family = AF_INET; |
266 | 259 | ||
267 | sh = (struct sctphdr *) skb->h.raw; | 260 | sh = (struct sctphdr *) skb->h.raw; |
268 | if (is_saddr) { | 261 | if (is_saddr) { |
269 | *port = ntohs(sh->source); | 262 | *port = ntohs(sh->source); |
270 | from = &skb->nh.iph->saddr; | 263 | from = &skb->nh.iph->saddr; |
271 | } else { | 264 | } else { |
272 | *port = ntohs(sh->dest); | 265 | *port = ntohs(sh->dest); |
273 | from = &skb->nh.iph->daddr; | 266 | from = &skb->nh.iph->daddr; |
274 | } | 267 | } |
275 | memcpy(&addr->v4.sin_addr.s_addr, from, sizeof(struct in_addr)); | 268 | memcpy(&addr->v4.sin_addr.s_addr, from, sizeof(struct in_addr)); |
276 | } | 269 | } |
277 | 270 | ||
278 | /* Initialize an sctp_addr from a socket. */ | 271 | /* Initialize an sctp_addr from a socket. */ |
279 | static void sctp_v4_from_sk(union sctp_addr *addr, struct sock *sk) | 272 | static void sctp_v4_from_sk(union sctp_addr *addr, struct sock *sk) |
280 | { | 273 | { |
281 | addr->v4.sin_family = AF_INET; | 274 | addr->v4.sin_family = AF_INET; |
282 | addr->v4.sin_port = inet_sk(sk)->num; | 275 | addr->v4.sin_port = inet_sk(sk)->num; |
283 | addr->v4.sin_addr.s_addr = inet_sk(sk)->rcv_saddr; | 276 | addr->v4.sin_addr.s_addr = inet_sk(sk)->rcv_saddr; |
284 | } | 277 | } |
285 | 278 | ||
286 | /* Initialize sk->sk_rcv_saddr from sctp_addr. */ | 279 | /* Initialize sk->sk_rcv_saddr from sctp_addr. */ |
287 | static void sctp_v4_to_sk_saddr(union sctp_addr *addr, struct sock *sk) | 280 | static void sctp_v4_to_sk_saddr(union sctp_addr *addr, struct sock *sk) |
288 | { | 281 | { |
289 | inet_sk(sk)->rcv_saddr = addr->v4.sin_addr.s_addr; | 282 | inet_sk(sk)->rcv_saddr = addr->v4.sin_addr.s_addr; |
290 | } | 283 | } |
291 | 284 | ||
292 | /* Initialize sk->sk_daddr from sctp_addr. */ | 285 | /* Initialize sk->sk_daddr from sctp_addr. */ |
293 | static void sctp_v4_to_sk_daddr(union sctp_addr *addr, struct sock *sk) | 286 | static void sctp_v4_to_sk_daddr(union sctp_addr *addr, struct sock *sk) |
294 | { | 287 | { |
295 | inet_sk(sk)->daddr = addr->v4.sin_addr.s_addr; | 288 | inet_sk(sk)->daddr = addr->v4.sin_addr.s_addr; |
296 | } | 289 | } |
297 | 290 | ||
298 | /* Initialize a sctp_addr from an address parameter. */ | 291 | /* Initialize a sctp_addr from an address parameter. */ |
299 | static void sctp_v4_from_addr_param(union sctp_addr *addr, | 292 | static void sctp_v4_from_addr_param(union sctp_addr *addr, |
300 | union sctp_addr_param *param, | 293 | union sctp_addr_param *param, |
301 | __u16 port, int iif) | 294 | __u16 port, int iif) |
302 | { | 295 | { |
303 | addr->v4.sin_family = AF_INET; | 296 | addr->v4.sin_family = AF_INET; |
304 | addr->v4.sin_port = port; | 297 | addr->v4.sin_port = port; |
305 | addr->v4.sin_addr.s_addr = param->v4.addr.s_addr; | 298 | addr->v4.sin_addr.s_addr = param->v4.addr.s_addr; |
306 | } | 299 | } |
307 | 300 | ||
308 | /* Initialize an address parameter from a sctp_addr and return the length | 301 | /* Initialize an address parameter from a sctp_addr and return the length |
309 | * of the address parameter. | 302 | * of the address parameter. |
310 | */ | 303 | */ |
311 | static int sctp_v4_to_addr_param(const union sctp_addr *addr, | 304 | static int sctp_v4_to_addr_param(const union sctp_addr *addr, |
312 | union sctp_addr_param *param) | 305 | union sctp_addr_param *param) |
313 | { | 306 | { |
314 | int length = sizeof(sctp_ipv4addr_param_t); | 307 | int length = sizeof(sctp_ipv4addr_param_t); |
315 | 308 | ||
316 | param->v4.param_hdr.type = SCTP_PARAM_IPV4_ADDRESS; | 309 | param->v4.param_hdr.type = SCTP_PARAM_IPV4_ADDRESS; |
317 | param->v4.param_hdr.length = ntohs(length); | 310 | param->v4.param_hdr.length = ntohs(length); |
318 | param->v4.addr.s_addr = addr->v4.sin_addr.s_addr; | 311 | param->v4.addr.s_addr = addr->v4.sin_addr.s_addr; |
319 | 312 | ||
320 | return length; | 313 | return length; |
321 | } | 314 | } |
322 | 315 | ||
323 | /* Initialize a sctp_addr from a dst_entry. */ | 316 | /* Initialize a sctp_addr from a dst_entry. */ |
324 | static void sctp_v4_dst_saddr(union sctp_addr *saddr, struct dst_entry *dst, | 317 | static void sctp_v4_dst_saddr(union sctp_addr *saddr, struct dst_entry *dst, |
325 | unsigned short port) | 318 | unsigned short port) |
326 | { | 319 | { |
327 | struct rtable *rt = (struct rtable *)dst; | 320 | struct rtable *rt = (struct rtable *)dst; |
328 | saddr->v4.sin_family = AF_INET; | 321 | saddr->v4.sin_family = AF_INET; |
329 | saddr->v4.sin_port = port; | 322 | saddr->v4.sin_port = port; |
330 | saddr->v4.sin_addr.s_addr = rt->rt_src; | 323 | saddr->v4.sin_addr.s_addr = rt->rt_src; |
331 | } | 324 | } |
332 | 325 | ||
333 | /* Compare two addresses exactly. */ | 326 | /* Compare two addresses exactly. */ |
334 | static int sctp_v4_cmp_addr(const union sctp_addr *addr1, | 327 | static int sctp_v4_cmp_addr(const union sctp_addr *addr1, |
335 | const union sctp_addr *addr2) | 328 | const union sctp_addr *addr2) |
336 | { | 329 | { |
337 | if (addr1->sa.sa_family != addr2->sa.sa_family) | 330 | if (addr1->sa.sa_family != addr2->sa.sa_family) |
338 | return 0; | 331 | return 0; |
339 | if (addr1->v4.sin_port != addr2->v4.sin_port) | 332 | if (addr1->v4.sin_port != addr2->v4.sin_port) |
340 | return 0; | 333 | return 0; |
341 | if (addr1->v4.sin_addr.s_addr != addr2->v4.sin_addr.s_addr) | 334 | if (addr1->v4.sin_addr.s_addr != addr2->v4.sin_addr.s_addr) |
342 | return 0; | 335 | return 0; |
343 | 336 | ||
344 | return 1; | 337 | return 1; |
345 | } | 338 | } |
346 | 339 | ||
347 | /* Initialize addr struct to INADDR_ANY. */ | 340 | /* Initialize addr struct to INADDR_ANY. */ |
348 | static void sctp_v4_inaddr_any(union sctp_addr *addr, unsigned short port) | 341 | static void sctp_v4_inaddr_any(union sctp_addr *addr, unsigned short port) |
349 | { | 342 | { |
350 | addr->v4.sin_family = AF_INET; | 343 | addr->v4.sin_family = AF_INET; |
351 | addr->v4.sin_addr.s_addr = INADDR_ANY; | 344 | addr->v4.sin_addr.s_addr = INADDR_ANY; |
352 | addr->v4.sin_port = port; | 345 | addr->v4.sin_port = port; |
353 | } | 346 | } |
354 | 347 | ||
355 | /* Is this a wildcard address? */ | 348 | /* Is this a wildcard address? */ |
356 | static int sctp_v4_is_any(const union sctp_addr *addr) | 349 | static int sctp_v4_is_any(const union sctp_addr *addr) |
357 | { | 350 | { |
358 | return INADDR_ANY == addr->v4.sin_addr.s_addr; | 351 | return INADDR_ANY == addr->v4.sin_addr.s_addr; |
359 | } | 352 | } |
360 | 353 | ||
361 | /* This function checks if the address is a valid address to be used for | 354 | /* This function checks if the address is a valid address to be used for |
362 | * SCTP binding. | 355 | * SCTP binding. |
363 | * | 356 | * |
364 | * Output: | 357 | * Output: |
365 | * Return 0 - If the address is a non-unicast or an illegal address. | 358 | * Return 0 - If the address is a non-unicast or an illegal address. |
366 | * Return 1 - If the address is a unicast. | 359 | * Return 1 - If the address is a unicast. |
367 | */ | 360 | */ |
368 | static int sctp_v4_addr_valid(union sctp_addr *addr, | 361 | static int sctp_v4_addr_valid(union sctp_addr *addr, |
369 | struct sctp_sock *sp, | 362 | struct sctp_sock *sp, |
370 | const struct sk_buff *skb) | 363 | const struct sk_buff *skb) |
371 | { | 364 | { |
372 | /* Is this a non-unicast address or a unusable SCTP address? */ | 365 | /* Is this a non-unicast address or a unusable SCTP address? */ |
373 | if (IS_IPV4_UNUSABLE_ADDRESS(&addr->v4.sin_addr.s_addr)) | 366 | if (IS_IPV4_UNUSABLE_ADDRESS(&addr->v4.sin_addr.s_addr)) |
374 | return 0; | 367 | return 0; |
375 | 368 | ||
376 | /* Is this a broadcast address? */ | 369 | /* Is this a broadcast address? */ |
377 | if (skb && ((struct rtable *)skb->dst)->rt_flags & RTCF_BROADCAST) | 370 | if (skb && ((struct rtable *)skb->dst)->rt_flags & RTCF_BROADCAST) |
378 | return 0; | 371 | return 0; |
379 | 372 | ||
380 | return 1; | 373 | return 1; |
381 | } | 374 | } |
382 | 375 | ||
383 | /* Should this be available for binding? */ | 376 | /* Should this be available for binding? */ |
384 | static int sctp_v4_available(union sctp_addr *addr, struct sctp_sock *sp) | 377 | static int sctp_v4_available(union sctp_addr *addr, struct sctp_sock *sp) |
385 | { | 378 | { |
386 | int ret = inet_addr_type(addr->v4.sin_addr.s_addr); | 379 | int ret = inet_addr_type(addr->v4.sin_addr.s_addr); |
387 | 380 | ||
388 | 381 | ||
389 | if (addr->v4.sin_addr.s_addr != INADDR_ANY && | 382 | if (addr->v4.sin_addr.s_addr != INADDR_ANY && |
390 | ret != RTN_LOCAL && | 383 | ret != RTN_LOCAL && |
391 | !sp->inet.freebind && | 384 | !sp->inet.freebind && |
392 | !sysctl_ip_nonlocal_bind) | 385 | !sysctl_ip_nonlocal_bind) |
393 | return 0; | 386 | return 0; |
394 | 387 | ||
395 | return 1; | 388 | return 1; |
396 | } | 389 | } |
397 | 390 | ||
398 | /* Checking the loopback, private and other address scopes as defined in | 391 | /* Checking the loopback, private and other address scopes as defined in |
399 | * RFC 1918. The IPv4 scoping is based on the draft for SCTP IPv4 | 392 | * RFC 1918. The IPv4 scoping is based on the draft for SCTP IPv4 |
400 | * scoping <draft-stewart-tsvwg-sctp-ipv4-00.txt>. | 393 | * scoping <draft-stewart-tsvwg-sctp-ipv4-00.txt>. |
401 | * | 394 | * |
402 | * Level 0 - unusable SCTP addresses | 395 | * Level 0 - unusable SCTP addresses |
403 | * Level 1 - loopback address | 396 | * Level 1 - loopback address |
404 | * Level 2 - link-local addresses | 397 | * Level 2 - link-local addresses |
405 | * Level 3 - private addresses. | 398 | * Level 3 - private addresses. |
406 | * Level 4 - global addresses | 399 | * Level 4 - global addresses |
407 | * For INIT and INIT-ACK address list, let L be the level of | 400 | * For INIT and INIT-ACK address list, let L be the level of |
408 | * of requested destination address, sender and receiver | 401 | * of requested destination address, sender and receiver |
409 | * SHOULD include all of its addresses with level greater | 402 | * SHOULD include all of its addresses with level greater |
410 | * than or equal to L. | 403 | * than or equal to L. |
411 | */ | 404 | */ |
412 | static sctp_scope_t sctp_v4_scope(union sctp_addr *addr) | 405 | static sctp_scope_t sctp_v4_scope(union sctp_addr *addr) |
413 | { | 406 | { |
414 | sctp_scope_t retval; | 407 | sctp_scope_t retval; |
415 | 408 | ||
416 | /* Should IPv4 scoping be a sysctl configurable option | 409 | /* Should IPv4 scoping be a sysctl configurable option |
417 | * so users can turn it off (default on) for certain | 410 | * so users can turn it off (default on) for certain |
418 | * unconventional networking environments? | 411 | * unconventional networking environments? |
419 | */ | 412 | */ |
420 | 413 | ||
421 | /* Check for unusable SCTP addresses. */ | 414 | /* Check for unusable SCTP addresses. */ |
422 | if (IS_IPV4_UNUSABLE_ADDRESS(&addr->v4.sin_addr.s_addr)) { | 415 | if (IS_IPV4_UNUSABLE_ADDRESS(&addr->v4.sin_addr.s_addr)) { |
423 | retval = SCTP_SCOPE_UNUSABLE; | 416 | retval = SCTP_SCOPE_UNUSABLE; |
424 | } else if (LOOPBACK(addr->v4.sin_addr.s_addr)) { | 417 | } else if (LOOPBACK(addr->v4.sin_addr.s_addr)) { |
425 | retval = SCTP_SCOPE_LOOPBACK; | 418 | retval = SCTP_SCOPE_LOOPBACK; |
426 | } else if (IS_IPV4_LINK_ADDRESS(&addr->v4.sin_addr.s_addr)) { | 419 | } else if (IS_IPV4_LINK_ADDRESS(&addr->v4.sin_addr.s_addr)) { |
427 | retval = SCTP_SCOPE_LINK; | 420 | retval = SCTP_SCOPE_LINK; |
428 | } else if (IS_IPV4_PRIVATE_ADDRESS(&addr->v4.sin_addr.s_addr)) { | 421 | } else if (IS_IPV4_PRIVATE_ADDRESS(&addr->v4.sin_addr.s_addr)) { |
429 | retval = SCTP_SCOPE_PRIVATE; | 422 | retval = SCTP_SCOPE_PRIVATE; |
430 | } else { | 423 | } else { |
431 | retval = SCTP_SCOPE_GLOBAL; | 424 | retval = SCTP_SCOPE_GLOBAL; |
432 | } | 425 | } |
433 | 426 | ||
434 | return retval; | 427 | return retval; |
435 | } | 428 | } |
436 | 429 | ||
437 | /* Returns a valid dst cache entry for the given source and destination ip | 430 | /* Returns a valid dst cache entry for the given source and destination ip |
438 | * addresses. If an association is passed, trys to get a dst entry with a | 431 | * addresses. If an association is passed, trys to get a dst entry with a |
439 | * source address that matches an address in the bind address list. | 432 | * source address that matches an address in the bind address list. |
440 | */ | 433 | */ |
441 | static struct dst_entry *sctp_v4_get_dst(struct sctp_association *asoc, | 434 | static struct dst_entry *sctp_v4_get_dst(struct sctp_association *asoc, |
442 | union sctp_addr *daddr, | 435 | union sctp_addr *daddr, |
443 | union sctp_addr *saddr) | 436 | union sctp_addr *saddr) |
444 | { | 437 | { |
445 | struct rtable *rt; | 438 | struct rtable *rt; |
446 | struct flowi fl; | 439 | struct flowi fl; |
447 | struct sctp_bind_addr *bp; | 440 | struct sctp_bind_addr *bp; |
448 | rwlock_t *addr_lock; | 441 | rwlock_t *addr_lock; |
449 | struct sctp_sockaddr_entry *laddr; | 442 | struct sctp_sockaddr_entry *laddr; |
450 | struct list_head *pos; | 443 | struct list_head *pos; |
451 | struct dst_entry *dst = NULL; | 444 | struct dst_entry *dst = NULL; |
452 | union sctp_addr dst_saddr; | 445 | union sctp_addr dst_saddr; |
453 | 446 | ||
454 | memset(&fl, 0x0, sizeof(struct flowi)); | 447 | memset(&fl, 0x0, sizeof(struct flowi)); |
455 | fl.fl4_dst = daddr->v4.sin_addr.s_addr; | 448 | fl.fl4_dst = daddr->v4.sin_addr.s_addr; |
456 | fl.proto = IPPROTO_SCTP; | 449 | fl.proto = IPPROTO_SCTP; |
457 | if (asoc) { | 450 | if (asoc) { |
458 | fl.fl4_tos = RT_CONN_FLAGS(asoc->base.sk); | 451 | fl.fl4_tos = RT_CONN_FLAGS(asoc->base.sk); |
459 | fl.oif = asoc->base.sk->sk_bound_dev_if; | 452 | fl.oif = asoc->base.sk->sk_bound_dev_if; |
460 | } | 453 | } |
461 | if (saddr) | 454 | if (saddr) |
462 | fl.fl4_src = saddr->v4.sin_addr.s_addr; | 455 | fl.fl4_src = saddr->v4.sin_addr.s_addr; |
463 | 456 | ||
464 | SCTP_DEBUG_PRINTK("%s: DST:%u.%u.%u.%u, SRC:%u.%u.%u.%u - ", | 457 | SCTP_DEBUG_PRINTK("%s: DST:%u.%u.%u.%u, SRC:%u.%u.%u.%u - ", |
465 | __FUNCTION__, NIPQUAD(fl.fl4_dst), | 458 | __FUNCTION__, NIPQUAD(fl.fl4_dst), |
466 | NIPQUAD(fl.fl4_src)); | 459 | NIPQUAD(fl.fl4_src)); |
467 | 460 | ||
468 | if (!ip_route_output_key(&rt, &fl)) { | 461 | if (!ip_route_output_key(&rt, &fl)) { |
469 | dst = &rt->u.dst; | 462 | dst = &rt->u.dst; |
470 | } | 463 | } |
471 | 464 | ||
472 | /* If there is no association or if a source address is passed, no | 465 | /* If there is no association or if a source address is passed, no |
473 | * more validation is required. | 466 | * more validation is required. |
474 | */ | 467 | */ |
475 | if (!asoc || saddr) | 468 | if (!asoc || saddr) |
476 | goto out; | 469 | goto out; |
477 | 470 | ||
478 | bp = &asoc->base.bind_addr; | 471 | bp = &asoc->base.bind_addr; |
479 | addr_lock = &asoc->base.addr_lock; | 472 | addr_lock = &asoc->base.addr_lock; |
480 | 473 | ||
481 | if (dst) { | 474 | if (dst) { |
482 | /* Walk through the bind address list and look for a bind | 475 | /* Walk through the bind address list and look for a bind |
483 | * address that matches the source address of the returned dst. | 476 | * address that matches the source address of the returned dst. |
484 | */ | 477 | */ |
485 | sctp_read_lock(addr_lock); | 478 | sctp_read_lock(addr_lock); |
486 | list_for_each(pos, &bp->address_list) { | 479 | list_for_each(pos, &bp->address_list) { |
487 | laddr = list_entry(pos, struct sctp_sockaddr_entry, | 480 | laddr = list_entry(pos, struct sctp_sockaddr_entry, |
488 | list); | 481 | list); |
489 | if (!laddr->use_as_src) | 482 | if (!laddr->use_as_src) |
490 | continue; | 483 | continue; |
491 | sctp_v4_dst_saddr(&dst_saddr, dst, bp->port); | 484 | sctp_v4_dst_saddr(&dst_saddr, dst, bp->port); |
492 | if (sctp_v4_cmp_addr(&dst_saddr, &laddr->a)) | 485 | if (sctp_v4_cmp_addr(&dst_saddr, &laddr->a)) |
493 | goto out_unlock; | 486 | goto out_unlock; |
494 | } | 487 | } |
495 | sctp_read_unlock(addr_lock); | 488 | sctp_read_unlock(addr_lock); |
496 | 489 | ||
497 | /* None of the bound addresses match the source address of the | 490 | /* None of the bound addresses match the source address of the |
498 | * dst. So release it. | 491 | * dst. So release it. |
499 | */ | 492 | */ |
500 | dst_release(dst); | 493 | dst_release(dst); |
501 | dst = NULL; | 494 | dst = NULL; |
502 | } | 495 | } |
503 | 496 | ||
504 | /* Walk through the bind address list and try to get a dst that | 497 | /* Walk through the bind address list and try to get a dst that |
505 | * matches a bind address as the source address. | 498 | * matches a bind address as the source address. |
506 | */ | 499 | */ |
507 | sctp_read_lock(addr_lock); | 500 | sctp_read_lock(addr_lock); |
508 | list_for_each(pos, &bp->address_list) { | 501 | list_for_each(pos, &bp->address_list) { |
509 | laddr = list_entry(pos, struct sctp_sockaddr_entry, list); | 502 | laddr = list_entry(pos, struct sctp_sockaddr_entry, list); |
510 | 503 | ||
511 | if ((laddr->use_as_src) && | 504 | if ((laddr->use_as_src) && |
512 | (AF_INET == laddr->a.sa.sa_family)) { | 505 | (AF_INET == laddr->a.sa.sa_family)) { |
513 | fl.fl4_src = laddr->a.v4.sin_addr.s_addr; | 506 | fl.fl4_src = laddr->a.v4.sin_addr.s_addr; |
514 | if (!ip_route_output_key(&rt, &fl)) { | 507 | if (!ip_route_output_key(&rt, &fl)) { |
515 | dst = &rt->u.dst; | 508 | dst = &rt->u.dst; |
516 | goto out_unlock; | 509 | goto out_unlock; |
517 | } | 510 | } |
518 | } | 511 | } |
519 | } | 512 | } |
520 | 513 | ||
521 | out_unlock: | 514 | out_unlock: |
522 | sctp_read_unlock(addr_lock); | 515 | sctp_read_unlock(addr_lock); |
523 | out: | 516 | out: |
524 | if (dst) | 517 | if (dst) |
525 | SCTP_DEBUG_PRINTK("rt_dst:%u.%u.%u.%u, rt_src:%u.%u.%u.%u\n", | 518 | SCTP_DEBUG_PRINTK("rt_dst:%u.%u.%u.%u, rt_src:%u.%u.%u.%u\n", |
526 | NIPQUAD(rt->rt_dst), NIPQUAD(rt->rt_src)); | 519 | NIPQUAD(rt->rt_dst), NIPQUAD(rt->rt_src)); |
527 | else | 520 | else |
528 | SCTP_DEBUG_PRINTK("NO ROUTE\n"); | 521 | SCTP_DEBUG_PRINTK("NO ROUTE\n"); |
529 | 522 | ||
530 | return dst; | 523 | return dst; |
531 | } | 524 | } |
532 | 525 | ||
533 | /* For v4, the source address is cached in the route entry(dst). So no need | 526 | /* For v4, the source address is cached in the route entry(dst). So no need |
534 | * to cache it separately and hence this is an empty routine. | 527 | * to cache it separately and hence this is an empty routine. |
535 | */ | 528 | */ |
536 | static void sctp_v4_get_saddr(struct sctp_association *asoc, | 529 | static void sctp_v4_get_saddr(struct sctp_association *asoc, |
537 | struct dst_entry *dst, | 530 | struct dst_entry *dst, |
538 | union sctp_addr *daddr, | 531 | union sctp_addr *daddr, |
539 | union sctp_addr *saddr) | 532 | union sctp_addr *saddr) |
540 | { | 533 | { |
541 | struct rtable *rt = (struct rtable *)dst; | 534 | struct rtable *rt = (struct rtable *)dst; |
542 | 535 | ||
543 | if (!asoc) | 536 | if (!asoc) |
544 | return; | 537 | return; |
545 | 538 | ||
546 | if (rt) { | 539 | if (rt) { |
547 | saddr->v4.sin_family = AF_INET; | 540 | saddr->v4.sin_family = AF_INET; |
548 | saddr->v4.sin_port = asoc->base.bind_addr.port; | 541 | saddr->v4.sin_port = asoc->base.bind_addr.port; |
549 | saddr->v4.sin_addr.s_addr = rt->rt_src; | 542 | saddr->v4.sin_addr.s_addr = rt->rt_src; |
550 | } | 543 | } |
551 | } | 544 | } |
552 | 545 | ||
553 | /* What interface did this skb arrive on? */ | 546 | /* What interface did this skb arrive on? */ |
554 | static int sctp_v4_skb_iif(const struct sk_buff *skb) | 547 | static int sctp_v4_skb_iif(const struct sk_buff *skb) |
555 | { | 548 | { |
556 | return ((struct rtable *)skb->dst)->rt_iif; | 549 | return ((struct rtable *)skb->dst)->rt_iif; |
557 | } | 550 | } |
558 | 551 | ||
559 | /* Was this packet marked by Explicit Congestion Notification? */ | 552 | /* Was this packet marked by Explicit Congestion Notification? */ |
560 | static int sctp_v4_is_ce(const struct sk_buff *skb) | 553 | static int sctp_v4_is_ce(const struct sk_buff *skb) |
561 | { | 554 | { |
562 | return INET_ECN_is_ce(skb->nh.iph->tos); | 555 | return INET_ECN_is_ce(skb->nh.iph->tos); |
563 | } | 556 | } |
564 | 557 | ||
565 | /* Create and initialize a new sk for the socket returned by accept(). */ | 558 | /* Create and initialize a new sk for the socket returned by accept(). */ |
566 | static struct sock *sctp_v4_create_accept_sk(struct sock *sk, | 559 | static struct sock *sctp_v4_create_accept_sk(struct sock *sk, |
567 | struct sctp_association *asoc) | 560 | struct sctp_association *asoc) |
568 | { | 561 | { |
569 | struct inet_sock *inet = inet_sk(sk); | 562 | struct inet_sock *inet = inet_sk(sk); |
570 | struct inet_sock *newinet; | 563 | struct inet_sock *newinet; |
571 | struct sock *newsk = sk_alloc(PF_INET, GFP_KERNEL, sk->sk_prot, 1); | 564 | struct sock *newsk = sk_alloc(PF_INET, GFP_KERNEL, sk->sk_prot, 1); |
572 | 565 | ||
573 | if (!newsk) | 566 | if (!newsk) |
574 | goto out; | 567 | goto out; |
575 | 568 | ||
576 | sock_init_data(NULL, newsk); | 569 | sock_init_data(NULL, newsk); |
577 | 570 | ||
578 | newsk->sk_type = SOCK_STREAM; | 571 | newsk->sk_type = SOCK_STREAM; |
579 | 572 | ||
580 | newsk->sk_no_check = sk->sk_no_check; | 573 | newsk->sk_no_check = sk->sk_no_check; |
581 | newsk->sk_reuse = sk->sk_reuse; | 574 | newsk->sk_reuse = sk->sk_reuse; |
582 | newsk->sk_shutdown = sk->sk_shutdown; | 575 | newsk->sk_shutdown = sk->sk_shutdown; |
583 | 576 | ||
584 | newsk->sk_destruct = inet_sock_destruct; | 577 | newsk->sk_destruct = inet_sock_destruct; |
585 | newsk->sk_family = PF_INET; | 578 | newsk->sk_family = PF_INET; |
586 | newsk->sk_protocol = IPPROTO_SCTP; | 579 | newsk->sk_protocol = IPPROTO_SCTP; |
587 | newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv; | 580 | newsk->sk_backlog_rcv = sk->sk_prot->backlog_rcv; |
588 | sock_reset_flag(newsk, SOCK_ZAPPED); | 581 | sock_reset_flag(newsk, SOCK_ZAPPED); |
589 | 582 | ||
590 | newinet = inet_sk(newsk); | 583 | newinet = inet_sk(newsk); |
591 | 584 | ||
592 | /* Initialize sk's sport, dport, rcv_saddr and daddr for | 585 | /* Initialize sk's sport, dport, rcv_saddr and daddr for |
593 | * getsockname() and getpeername() | 586 | * getsockname() and getpeername() |
594 | */ | 587 | */ |
595 | newinet->sport = inet->sport; | 588 | newinet->sport = inet->sport; |
596 | newinet->saddr = inet->saddr; | 589 | newinet->saddr = inet->saddr; |
597 | newinet->rcv_saddr = inet->rcv_saddr; | 590 | newinet->rcv_saddr = inet->rcv_saddr; |
598 | newinet->dport = htons(asoc->peer.port); | 591 | newinet->dport = htons(asoc->peer.port); |
599 | newinet->daddr = asoc->peer.primary_addr.v4.sin_addr.s_addr; | 592 | newinet->daddr = asoc->peer.primary_addr.v4.sin_addr.s_addr; |
600 | newinet->pmtudisc = inet->pmtudisc; | 593 | newinet->pmtudisc = inet->pmtudisc; |
601 | newinet->id = 0; | 594 | newinet->id = 0; |
602 | 595 | ||
603 | newinet->uc_ttl = -1; | 596 | newinet->uc_ttl = -1; |
604 | newinet->mc_loop = 1; | 597 | newinet->mc_loop = 1; |
605 | newinet->mc_ttl = 1; | 598 | newinet->mc_ttl = 1; |
606 | newinet->mc_index = 0; | 599 | newinet->mc_index = 0; |
607 | newinet->mc_list = NULL; | 600 | newinet->mc_list = NULL; |
608 | 601 | ||
609 | sk_refcnt_debug_inc(newsk); | 602 | sk_refcnt_debug_inc(newsk); |
610 | 603 | ||
611 | if (newsk->sk_prot->init(newsk)) { | 604 | if (newsk->sk_prot->init(newsk)) { |
612 | sk_common_release(newsk); | 605 | sk_common_release(newsk); |
613 | newsk = NULL; | 606 | newsk = NULL; |
614 | } | 607 | } |
615 | 608 | ||
616 | out: | 609 | out: |
617 | return newsk; | 610 | return newsk; |
618 | } | 611 | } |
619 | 612 | ||
620 | /* Map address, empty for v4 family */ | 613 | /* Map address, empty for v4 family */ |
621 | static void sctp_v4_addr_v4map(struct sctp_sock *sp, union sctp_addr *addr) | 614 | static void sctp_v4_addr_v4map(struct sctp_sock *sp, union sctp_addr *addr) |
622 | { | 615 | { |
623 | /* Empty */ | 616 | /* Empty */ |
624 | } | 617 | } |
625 | 618 | ||
626 | /* Dump the v4 addr to the seq file. */ | 619 | /* Dump the v4 addr to the seq file. */ |
627 | static void sctp_v4_seq_dump_addr(struct seq_file *seq, union sctp_addr *addr) | 620 | static void sctp_v4_seq_dump_addr(struct seq_file *seq, union sctp_addr *addr) |
628 | { | 621 | { |
629 | seq_printf(seq, "%d.%d.%d.%d ", NIPQUAD(addr->v4.sin_addr)); | 622 | seq_printf(seq, "%d.%d.%d.%d ", NIPQUAD(addr->v4.sin_addr)); |
630 | } | 623 | } |
631 | 624 | ||
632 | /* Event handler for inet address addition/deletion events. | 625 | /* Event handler for inet address addition/deletion events. |
633 | * Basically, whenever there is an event, we re-build our local address list. | 626 | * Basically, whenever there is an event, we re-build our local address list. |
634 | */ | 627 | */ |
635 | int sctp_inetaddr_event(struct notifier_block *this, unsigned long ev, | 628 | int sctp_inetaddr_event(struct notifier_block *this, unsigned long ev, |
636 | void *ptr) | 629 | void *ptr) |
637 | { | 630 | { |
638 | unsigned long flags; | 631 | unsigned long flags; |
639 | 632 | ||
640 | sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags); | 633 | sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags); |
641 | __sctp_free_local_addr_list(); | 634 | __sctp_free_local_addr_list(); |
642 | __sctp_get_local_addr_list(); | 635 | __sctp_get_local_addr_list(); |
643 | sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags); | 636 | sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags); |
644 | 637 | ||
645 | return NOTIFY_DONE; | 638 | return NOTIFY_DONE; |
646 | } | 639 | } |
647 | 640 | ||
648 | /* | 641 | /* |
649 | * Initialize the control inode/socket with a control endpoint data | 642 | * Initialize the control inode/socket with a control endpoint data |
650 | * structure. This endpoint is reserved exclusively for the OOTB processing. | 643 | * structure. This endpoint is reserved exclusively for the OOTB processing. |
651 | */ | 644 | */ |
652 | static int sctp_ctl_sock_init(void) | 645 | static int sctp_ctl_sock_init(void) |
653 | { | 646 | { |
654 | int err; | 647 | int err; |
655 | sa_family_t family; | 648 | sa_family_t family; |
656 | 649 | ||
657 | if (sctp_get_pf_specific(PF_INET6)) | 650 | if (sctp_get_pf_specific(PF_INET6)) |
658 | family = PF_INET6; | 651 | family = PF_INET6; |
659 | else | 652 | else |
660 | family = PF_INET; | 653 | family = PF_INET; |
661 | 654 | ||
662 | err = sock_create_kern(family, SOCK_SEQPACKET, IPPROTO_SCTP, | 655 | err = sock_create_kern(family, SOCK_SEQPACKET, IPPROTO_SCTP, |
663 | &sctp_ctl_socket); | 656 | &sctp_ctl_socket); |
664 | if (err < 0) { | 657 | if (err < 0) { |
665 | printk(KERN_ERR | 658 | printk(KERN_ERR |
666 | "SCTP: Failed to create the SCTP control socket.\n"); | 659 | "SCTP: Failed to create the SCTP control socket.\n"); |
667 | return err; | 660 | return err; |
668 | } | 661 | } |
669 | sctp_ctl_socket->sk->sk_allocation = GFP_ATOMIC; | 662 | sctp_ctl_socket->sk->sk_allocation = GFP_ATOMIC; |
670 | inet_sk(sctp_ctl_socket->sk)->uc_ttl = -1; | 663 | inet_sk(sctp_ctl_socket->sk)->uc_ttl = -1; |
671 | 664 | ||
672 | return 0; | 665 | return 0; |
673 | } | 666 | } |
674 | 667 | ||
675 | /* Register address family specific functions. */ | 668 | /* Register address family specific functions. */ |
676 | int sctp_register_af(struct sctp_af *af) | 669 | int sctp_register_af(struct sctp_af *af) |
677 | { | 670 | { |
678 | switch (af->sa_family) { | 671 | switch (af->sa_family) { |
679 | case AF_INET: | 672 | case AF_INET: |
680 | if (sctp_af_v4_specific) | 673 | if (sctp_af_v4_specific) |
681 | return 0; | 674 | return 0; |
682 | sctp_af_v4_specific = af; | 675 | sctp_af_v4_specific = af; |
683 | break; | 676 | break; |
684 | case AF_INET6: | 677 | case AF_INET6: |
685 | if (sctp_af_v6_specific) | 678 | if (sctp_af_v6_specific) |
686 | return 0; | 679 | return 0; |
687 | sctp_af_v6_specific = af; | 680 | sctp_af_v6_specific = af; |
688 | break; | 681 | break; |
689 | default: | 682 | default: |
690 | return 0; | 683 | return 0; |
691 | } | 684 | } |
692 | 685 | ||
693 | INIT_LIST_HEAD(&af->list); | 686 | INIT_LIST_HEAD(&af->list); |
694 | list_add_tail(&af->list, &sctp_address_families); | 687 | list_add_tail(&af->list, &sctp_address_families); |
695 | return 1; | 688 | return 1; |
696 | } | 689 | } |
697 | 690 | ||
698 | /* Get the table of functions for manipulating a particular address | 691 | /* Get the table of functions for manipulating a particular address |
699 | * family. | 692 | * family. |
700 | */ | 693 | */ |
701 | struct sctp_af *sctp_get_af_specific(sa_family_t family) | 694 | struct sctp_af *sctp_get_af_specific(sa_family_t family) |
702 | { | 695 | { |
703 | switch (family) { | 696 | switch (family) { |
704 | case AF_INET: | 697 | case AF_INET: |
705 | return sctp_af_v4_specific; | 698 | return sctp_af_v4_specific; |
706 | case AF_INET6: | 699 | case AF_INET6: |
707 | return sctp_af_v6_specific; | 700 | return sctp_af_v6_specific; |
708 | default: | 701 | default: |
709 | return NULL; | 702 | return NULL; |
710 | } | 703 | } |
711 | } | 704 | } |
712 | 705 | ||
713 | /* Common code to initialize a AF_INET msg_name. */ | 706 | /* Common code to initialize a AF_INET msg_name. */ |
714 | static void sctp_inet_msgname(char *msgname, int *addr_len) | 707 | static void sctp_inet_msgname(char *msgname, int *addr_len) |
715 | { | 708 | { |
716 | struct sockaddr_in *sin; | 709 | struct sockaddr_in *sin; |
717 | 710 | ||
718 | sin = (struct sockaddr_in *)msgname; | 711 | sin = (struct sockaddr_in *)msgname; |
719 | *addr_len = sizeof(struct sockaddr_in); | 712 | *addr_len = sizeof(struct sockaddr_in); |
720 | sin->sin_family = AF_INET; | 713 | sin->sin_family = AF_INET; |
721 | memset(sin->sin_zero, 0, sizeof(sin->sin_zero)); | 714 | memset(sin->sin_zero, 0, sizeof(sin->sin_zero)); |
722 | } | 715 | } |
723 | 716 | ||
724 | /* Copy the primary address of the peer primary address as the msg_name. */ | 717 | /* Copy the primary address of the peer primary address as the msg_name. */ |
725 | static void sctp_inet_event_msgname(struct sctp_ulpevent *event, char *msgname, | 718 | static void sctp_inet_event_msgname(struct sctp_ulpevent *event, char *msgname, |
726 | int *addr_len) | 719 | int *addr_len) |
727 | { | 720 | { |
728 | struct sockaddr_in *sin, *sinfrom; | 721 | struct sockaddr_in *sin, *sinfrom; |
729 | 722 | ||
730 | if (msgname) { | 723 | if (msgname) { |
731 | struct sctp_association *asoc; | 724 | struct sctp_association *asoc; |
732 | 725 | ||
733 | asoc = event->asoc; | 726 | asoc = event->asoc; |
734 | sctp_inet_msgname(msgname, addr_len); | 727 | sctp_inet_msgname(msgname, addr_len); |
735 | sin = (struct sockaddr_in *)msgname; | 728 | sin = (struct sockaddr_in *)msgname; |
736 | sinfrom = &asoc->peer.primary_addr.v4; | 729 | sinfrom = &asoc->peer.primary_addr.v4; |
737 | sin->sin_port = htons(asoc->peer.port); | 730 | sin->sin_port = htons(asoc->peer.port); |
738 | sin->sin_addr.s_addr = sinfrom->sin_addr.s_addr; | 731 | sin->sin_addr.s_addr = sinfrom->sin_addr.s_addr; |
739 | } | 732 | } |
740 | } | 733 | } |
741 | 734 | ||
742 | /* Initialize and copy out a msgname from an inbound skb. */ | 735 | /* Initialize and copy out a msgname from an inbound skb. */ |
743 | static void sctp_inet_skb_msgname(struct sk_buff *skb, char *msgname, int *len) | 736 | static void sctp_inet_skb_msgname(struct sk_buff *skb, char *msgname, int *len) |
744 | { | 737 | { |
745 | struct sctphdr *sh; | 738 | struct sctphdr *sh; |
746 | struct sockaddr_in *sin; | 739 | struct sockaddr_in *sin; |
747 | 740 | ||
748 | if (msgname) { | 741 | if (msgname) { |
749 | sctp_inet_msgname(msgname, len); | 742 | sctp_inet_msgname(msgname, len); |
750 | sin = (struct sockaddr_in *)msgname; | 743 | sin = (struct sockaddr_in *)msgname; |
751 | sh = (struct sctphdr *)skb->h.raw; | 744 | sh = (struct sctphdr *)skb->h.raw; |
752 | sin->sin_port = sh->source; | 745 | sin->sin_port = sh->source; |
753 | sin->sin_addr.s_addr = skb->nh.iph->saddr; | 746 | sin->sin_addr.s_addr = skb->nh.iph->saddr; |
754 | } | 747 | } |
755 | } | 748 | } |
756 | 749 | ||
757 | /* Do we support this AF? */ | 750 | /* Do we support this AF? */ |
758 | static int sctp_inet_af_supported(sa_family_t family, struct sctp_sock *sp) | 751 | static int sctp_inet_af_supported(sa_family_t family, struct sctp_sock *sp) |
759 | { | 752 | { |
760 | /* PF_INET only supports AF_INET addresses. */ | 753 | /* PF_INET only supports AF_INET addresses. */ |
761 | return (AF_INET == family); | 754 | return (AF_INET == family); |
762 | } | 755 | } |
763 | 756 | ||
764 | /* Address matching with wildcards allowed. */ | 757 | /* Address matching with wildcards allowed. */ |
765 | static int sctp_inet_cmp_addr(const union sctp_addr *addr1, | 758 | static int sctp_inet_cmp_addr(const union sctp_addr *addr1, |
766 | const union sctp_addr *addr2, | 759 | const union sctp_addr *addr2, |
767 | struct sctp_sock *opt) | 760 | struct sctp_sock *opt) |
768 | { | 761 | { |
769 | /* PF_INET only supports AF_INET addresses. */ | 762 | /* PF_INET only supports AF_INET addresses. */ |
770 | if (addr1->sa.sa_family != addr2->sa.sa_family) | 763 | if (addr1->sa.sa_family != addr2->sa.sa_family) |
771 | return 0; | 764 | return 0; |
772 | if (INADDR_ANY == addr1->v4.sin_addr.s_addr || | 765 | if (INADDR_ANY == addr1->v4.sin_addr.s_addr || |
773 | INADDR_ANY == addr2->v4.sin_addr.s_addr) | 766 | INADDR_ANY == addr2->v4.sin_addr.s_addr) |
774 | return 1; | 767 | return 1; |
775 | if (addr1->v4.sin_addr.s_addr == addr2->v4.sin_addr.s_addr) | 768 | if (addr1->v4.sin_addr.s_addr == addr2->v4.sin_addr.s_addr) |
776 | return 1; | 769 | return 1; |
777 | 770 | ||
778 | return 0; | 771 | return 0; |
779 | } | 772 | } |
780 | 773 | ||
781 | /* Verify that provided sockaddr looks bindable. Common verification has | 774 | /* Verify that provided sockaddr looks bindable. Common verification has |
782 | * already been taken care of. | 775 | * already been taken care of. |
783 | */ | 776 | */ |
784 | static int sctp_inet_bind_verify(struct sctp_sock *opt, union sctp_addr *addr) | 777 | static int sctp_inet_bind_verify(struct sctp_sock *opt, union sctp_addr *addr) |
785 | { | 778 | { |
786 | return sctp_v4_available(addr, opt); | 779 | return sctp_v4_available(addr, opt); |
787 | } | 780 | } |
788 | 781 | ||
789 | /* Verify that sockaddr looks sendable. Common verification has already | 782 | /* Verify that sockaddr looks sendable. Common verification has already |
790 | * been taken care of. | 783 | * been taken care of. |
791 | */ | 784 | */ |
792 | static int sctp_inet_send_verify(struct sctp_sock *opt, union sctp_addr *addr) | 785 | static int sctp_inet_send_verify(struct sctp_sock *opt, union sctp_addr *addr) |
793 | { | 786 | { |
794 | return 1; | 787 | return 1; |
795 | } | 788 | } |
796 | 789 | ||
797 | /* Fill in Supported Address Type information for INIT and INIT-ACK | 790 | /* Fill in Supported Address Type information for INIT and INIT-ACK |
798 | * chunks. Returns number of addresses supported. | 791 | * chunks. Returns number of addresses supported. |
799 | */ | 792 | */ |
800 | static int sctp_inet_supported_addrs(const struct sctp_sock *opt, | 793 | static int sctp_inet_supported_addrs(const struct sctp_sock *opt, |
801 | __u16 *types) | 794 | __u16 *types) |
802 | { | 795 | { |
803 | types[0] = SCTP_PARAM_IPV4_ADDRESS; | 796 | types[0] = SCTP_PARAM_IPV4_ADDRESS; |
804 | return 1; | 797 | return 1; |
805 | } | 798 | } |
806 | 799 | ||
807 | /* Wrapper routine that calls the ip transmit routine. */ | 800 | /* Wrapper routine that calls the ip transmit routine. */ |
808 | static inline int sctp_v4_xmit(struct sk_buff *skb, | 801 | static inline int sctp_v4_xmit(struct sk_buff *skb, |
809 | struct sctp_transport *transport, int ipfragok) | 802 | struct sctp_transport *transport, int ipfragok) |
810 | { | 803 | { |
811 | SCTP_DEBUG_PRINTK("%s: skb:%p, len:%d, " | 804 | SCTP_DEBUG_PRINTK("%s: skb:%p, len:%d, " |
812 | "src:%u.%u.%u.%u, dst:%u.%u.%u.%u\n", | 805 | "src:%u.%u.%u.%u, dst:%u.%u.%u.%u\n", |
813 | __FUNCTION__, skb, skb->len, | 806 | __FUNCTION__, skb, skb->len, |
814 | NIPQUAD(((struct rtable *)skb->dst)->rt_src), | 807 | NIPQUAD(((struct rtable *)skb->dst)->rt_src), |
815 | NIPQUAD(((struct rtable *)skb->dst)->rt_dst)); | 808 | NIPQUAD(((struct rtable *)skb->dst)->rt_dst)); |
816 | 809 | ||
817 | SCTP_INC_STATS(SCTP_MIB_OUTSCTPPACKS); | 810 | SCTP_INC_STATS(SCTP_MIB_OUTSCTPPACKS); |
818 | return ip_queue_xmit(skb, ipfragok); | 811 | return ip_queue_xmit(skb, ipfragok); |
819 | } | 812 | } |
820 | 813 | ||
821 | static struct sctp_af sctp_ipv4_specific; | 814 | static struct sctp_af sctp_ipv4_specific; |
822 | 815 | ||
823 | static struct sctp_pf sctp_pf_inet = { | 816 | static struct sctp_pf sctp_pf_inet = { |
824 | .event_msgname = sctp_inet_event_msgname, | 817 | .event_msgname = sctp_inet_event_msgname, |
825 | .skb_msgname = sctp_inet_skb_msgname, | 818 | .skb_msgname = sctp_inet_skb_msgname, |
826 | .af_supported = sctp_inet_af_supported, | 819 | .af_supported = sctp_inet_af_supported, |
827 | .cmp_addr = sctp_inet_cmp_addr, | 820 | .cmp_addr = sctp_inet_cmp_addr, |
828 | .bind_verify = sctp_inet_bind_verify, | 821 | .bind_verify = sctp_inet_bind_verify, |
829 | .send_verify = sctp_inet_send_verify, | 822 | .send_verify = sctp_inet_send_verify, |
830 | .supported_addrs = sctp_inet_supported_addrs, | 823 | .supported_addrs = sctp_inet_supported_addrs, |
831 | .create_accept_sk = sctp_v4_create_accept_sk, | 824 | .create_accept_sk = sctp_v4_create_accept_sk, |
832 | .addr_v4map = sctp_v4_addr_v4map, | 825 | .addr_v4map = sctp_v4_addr_v4map, |
833 | .af = &sctp_ipv4_specific, | 826 | .af = &sctp_ipv4_specific, |
834 | }; | 827 | }; |
835 | 828 | ||
836 | /* Notifier for inetaddr addition/deletion events. */ | 829 | /* Notifier for inetaddr addition/deletion events. */ |
837 | static struct notifier_block sctp_inetaddr_notifier = { | 830 | static struct notifier_block sctp_inetaddr_notifier = { |
838 | .notifier_call = sctp_inetaddr_event, | 831 | .notifier_call = sctp_inetaddr_event, |
839 | }; | 832 | }; |
840 | 833 | ||
841 | /* Socket operations. */ | 834 | /* Socket operations. */ |
842 | static const struct proto_ops inet_seqpacket_ops = { | 835 | static const struct proto_ops inet_seqpacket_ops = { |
843 | .family = PF_INET, | 836 | .family = PF_INET, |
844 | .owner = THIS_MODULE, | 837 | .owner = THIS_MODULE, |
845 | .release = inet_release, /* Needs to be wrapped... */ | 838 | .release = inet_release, /* Needs to be wrapped... */ |
846 | .bind = inet_bind, | 839 | .bind = inet_bind, |
847 | .connect = inet_dgram_connect, | 840 | .connect = inet_dgram_connect, |
848 | .socketpair = sock_no_socketpair, | 841 | .socketpair = sock_no_socketpair, |
849 | .accept = inet_accept, | 842 | .accept = inet_accept, |
850 | .getname = inet_getname, /* Semantics are different. */ | 843 | .getname = inet_getname, /* Semantics are different. */ |
851 | .poll = sctp_poll, | 844 | .poll = sctp_poll, |
852 | .ioctl = inet_ioctl, | 845 | .ioctl = inet_ioctl, |
853 | .listen = sctp_inet_listen, | 846 | .listen = sctp_inet_listen, |
854 | .shutdown = inet_shutdown, /* Looks harmless. */ | 847 | .shutdown = inet_shutdown, /* Looks harmless. */ |
855 | .setsockopt = sock_common_setsockopt, /* IP_SOL IP_OPTION is a problem */ | 848 | .setsockopt = sock_common_setsockopt, /* IP_SOL IP_OPTION is a problem */ |
856 | .getsockopt = sock_common_getsockopt, | 849 | .getsockopt = sock_common_getsockopt, |
857 | .sendmsg = inet_sendmsg, | 850 | .sendmsg = inet_sendmsg, |
858 | .recvmsg = sock_common_recvmsg, | 851 | .recvmsg = sock_common_recvmsg, |
859 | .mmap = sock_no_mmap, | 852 | .mmap = sock_no_mmap, |
860 | .sendpage = sock_no_sendpage, | 853 | .sendpage = sock_no_sendpage, |
861 | #ifdef CONFIG_COMPAT | 854 | #ifdef CONFIG_COMPAT |
862 | .compat_setsockopt = compat_sock_common_setsockopt, | 855 | .compat_setsockopt = compat_sock_common_setsockopt, |
863 | .compat_getsockopt = compat_sock_common_getsockopt, | 856 | .compat_getsockopt = compat_sock_common_getsockopt, |
864 | #endif | 857 | #endif |
865 | }; | 858 | }; |
866 | 859 | ||
867 | /* Registration with AF_INET family. */ | 860 | /* Registration with AF_INET family. */ |
868 | static struct inet_protosw sctp_seqpacket_protosw = { | 861 | static struct inet_protosw sctp_seqpacket_protosw = { |
869 | .type = SOCK_SEQPACKET, | 862 | .type = SOCK_SEQPACKET, |
870 | .protocol = IPPROTO_SCTP, | 863 | .protocol = IPPROTO_SCTP, |
871 | .prot = &sctp_prot, | 864 | .prot = &sctp_prot, |
872 | .ops = &inet_seqpacket_ops, | 865 | .ops = &inet_seqpacket_ops, |
873 | .capability = -1, | 866 | .capability = -1, |
874 | .no_check = 0, | 867 | .no_check = 0, |
875 | .flags = SCTP_PROTOSW_FLAG | 868 | .flags = SCTP_PROTOSW_FLAG |
876 | }; | 869 | }; |
877 | static struct inet_protosw sctp_stream_protosw = { | 870 | static struct inet_protosw sctp_stream_protosw = { |
878 | .type = SOCK_STREAM, | 871 | .type = SOCK_STREAM, |
879 | .protocol = IPPROTO_SCTP, | 872 | .protocol = IPPROTO_SCTP, |
880 | .prot = &sctp_prot, | 873 | .prot = &sctp_prot, |
881 | .ops = &inet_seqpacket_ops, | 874 | .ops = &inet_seqpacket_ops, |
882 | .capability = -1, | 875 | .capability = -1, |
883 | .no_check = 0, | 876 | .no_check = 0, |
884 | .flags = SCTP_PROTOSW_FLAG | 877 | .flags = SCTP_PROTOSW_FLAG |
885 | }; | 878 | }; |
886 | 879 | ||
887 | /* Register with IP layer. */ | 880 | /* Register with IP layer. */ |
888 | static struct net_protocol sctp_protocol = { | 881 | static struct net_protocol sctp_protocol = { |
889 | .handler = sctp_rcv, | 882 | .handler = sctp_rcv, |
890 | .err_handler = sctp_v4_err, | 883 | .err_handler = sctp_v4_err, |
891 | .no_policy = 1, | 884 | .no_policy = 1, |
892 | }; | 885 | }; |
893 | 886 | ||
894 | /* IPv4 address related functions. */ | 887 | /* IPv4 address related functions. */ |
895 | static struct sctp_af sctp_ipv4_specific = { | 888 | static struct sctp_af sctp_ipv4_specific = { |
896 | .sa_family = AF_INET, | 889 | .sa_family = AF_INET, |
897 | .sctp_xmit = sctp_v4_xmit, | 890 | .sctp_xmit = sctp_v4_xmit, |
898 | .setsockopt = ip_setsockopt, | 891 | .setsockopt = ip_setsockopt, |
899 | .getsockopt = ip_getsockopt, | 892 | .getsockopt = ip_getsockopt, |
900 | .get_dst = sctp_v4_get_dst, | 893 | .get_dst = sctp_v4_get_dst, |
901 | .get_saddr = sctp_v4_get_saddr, | 894 | .get_saddr = sctp_v4_get_saddr, |
902 | .copy_addrlist = sctp_v4_copy_addrlist, | 895 | .copy_addrlist = sctp_v4_copy_addrlist, |
903 | .from_skb = sctp_v4_from_skb, | 896 | .from_skb = sctp_v4_from_skb, |
904 | .from_sk = sctp_v4_from_sk, | 897 | .from_sk = sctp_v4_from_sk, |
905 | .to_sk_saddr = sctp_v4_to_sk_saddr, | 898 | .to_sk_saddr = sctp_v4_to_sk_saddr, |
906 | .to_sk_daddr = sctp_v4_to_sk_daddr, | 899 | .to_sk_daddr = sctp_v4_to_sk_daddr, |
907 | .from_addr_param = sctp_v4_from_addr_param, | 900 | .from_addr_param = sctp_v4_from_addr_param, |
908 | .to_addr_param = sctp_v4_to_addr_param, | 901 | .to_addr_param = sctp_v4_to_addr_param, |
909 | .dst_saddr = sctp_v4_dst_saddr, | 902 | .dst_saddr = sctp_v4_dst_saddr, |
910 | .cmp_addr = sctp_v4_cmp_addr, | 903 | .cmp_addr = sctp_v4_cmp_addr, |
911 | .addr_valid = sctp_v4_addr_valid, | 904 | .addr_valid = sctp_v4_addr_valid, |
912 | .inaddr_any = sctp_v4_inaddr_any, | 905 | .inaddr_any = sctp_v4_inaddr_any, |
913 | .is_any = sctp_v4_is_any, | 906 | .is_any = sctp_v4_is_any, |
914 | .available = sctp_v4_available, | 907 | .available = sctp_v4_available, |
915 | .scope = sctp_v4_scope, | 908 | .scope = sctp_v4_scope, |
916 | .skb_iif = sctp_v4_skb_iif, | 909 | .skb_iif = sctp_v4_skb_iif, |
917 | .is_ce = sctp_v4_is_ce, | 910 | .is_ce = sctp_v4_is_ce, |
918 | .seq_dump_addr = sctp_v4_seq_dump_addr, | 911 | .seq_dump_addr = sctp_v4_seq_dump_addr, |
919 | .net_header_len = sizeof(struct iphdr), | 912 | .net_header_len = sizeof(struct iphdr), |
920 | .sockaddr_len = sizeof(struct sockaddr_in), | 913 | .sockaddr_len = sizeof(struct sockaddr_in), |
921 | #ifdef CONFIG_COMPAT | 914 | #ifdef CONFIG_COMPAT |
922 | .compat_setsockopt = compat_ip_setsockopt, | 915 | .compat_setsockopt = compat_ip_setsockopt, |
923 | .compat_getsockopt = compat_ip_getsockopt, | 916 | .compat_getsockopt = compat_ip_getsockopt, |
924 | #endif | 917 | #endif |
925 | }; | 918 | }; |
926 | 919 | ||
927 | struct sctp_pf *sctp_get_pf_specific(sa_family_t family) { | 920 | struct sctp_pf *sctp_get_pf_specific(sa_family_t family) { |
928 | 921 | ||
929 | switch (family) { | 922 | switch (family) { |
930 | case PF_INET: | 923 | case PF_INET: |
931 | return sctp_pf_inet_specific; | 924 | return sctp_pf_inet_specific; |
932 | case PF_INET6: | 925 | case PF_INET6: |
933 | return sctp_pf_inet6_specific; | 926 | return sctp_pf_inet6_specific; |
934 | default: | 927 | default: |
935 | return NULL; | 928 | return NULL; |
936 | } | 929 | } |
937 | } | 930 | } |
938 | 931 | ||
939 | /* Register the PF specific function table. */ | 932 | /* Register the PF specific function table. */ |
940 | int sctp_register_pf(struct sctp_pf *pf, sa_family_t family) | 933 | int sctp_register_pf(struct sctp_pf *pf, sa_family_t family) |
941 | { | 934 | { |
942 | switch (family) { | 935 | switch (family) { |
943 | case PF_INET: | 936 | case PF_INET: |
944 | if (sctp_pf_inet_specific) | 937 | if (sctp_pf_inet_specific) |
945 | return 0; | 938 | return 0; |
946 | sctp_pf_inet_specific = pf; | 939 | sctp_pf_inet_specific = pf; |
947 | break; | 940 | break; |
948 | case PF_INET6: | 941 | case PF_INET6: |
949 | if (sctp_pf_inet6_specific) | 942 | if (sctp_pf_inet6_specific) |
950 | return 0; | 943 | return 0; |
951 | sctp_pf_inet6_specific = pf; | 944 | sctp_pf_inet6_specific = pf; |
952 | break; | 945 | break; |
953 | default: | 946 | default: |
954 | return 0; | 947 | return 0; |
955 | } | 948 | } |
956 | return 1; | 949 | return 1; |
957 | } | 950 | } |
958 | 951 | ||
959 | static int __init init_sctp_mibs(void) | 952 | static int __init init_sctp_mibs(void) |
960 | { | 953 | { |
961 | sctp_statistics[0] = alloc_percpu(struct sctp_mib); | 954 | sctp_statistics[0] = alloc_percpu(struct sctp_mib); |
962 | if (!sctp_statistics[0]) | 955 | if (!sctp_statistics[0]) |
963 | return -ENOMEM; | 956 | return -ENOMEM; |
964 | sctp_statistics[1] = alloc_percpu(struct sctp_mib); | 957 | sctp_statistics[1] = alloc_percpu(struct sctp_mib); |
965 | if (!sctp_statistics[1]) { | 958 | if (!sctp_statistics[1]) { |
966 | free_percpu(sctp_statistics[0]); | 959 | free_percpu(sctp_statistics[0]); |
967 | return -ENOMEM; | 960 | return -ENOMEM; |
968 | } | 961 | } |
969 | return 0; | 962 | return 0; |
970 | 963 | ||
971 | } | 964 | } |
972 | 965 | ||
973 | static void cleanup_sctp_mibs(void) | 966 | static void cleanup_sctp_mibs(void) |
974 | { | 967 | { |
975 | free_percpu(sctp_statistics[0]); | 968 | free_percpu(sctp_statistics[0]); |
976 | free_percpu(sctp_statistics[1]); | 969 | free_percpu(sctp_statistics[1]); |
977 | } | 970 | } |
978 | 971 | ||
979 | /* Initialize the universe into something sensible. */ | 972 | /* Initialize the universe into something sensible. */ |
980 | SCTP_STATIC __init int sctp_init(void) | 973 | SCTP_STATIC __init int sctp_init(void) |
981 | { | 974 | { |
982 | int i; | 975 | int i; |
983 | int status = -EINVAL; | 976 | int status = -EINVAL; |
984 | unsigned long goal; | 977 | unsigned long goal; |
985 | int order; | 978 | int order; |
986 | 979 | ||
987 | /* SCTP_DEBUG sanity check. */ | 980 | /* SCTP_DEBUG sanity check. */ |
988 | if (!sctp_sanity_check()) | 981 | if (!sctp_sanity_check()) |
989 | goto out; | 982 | goto out; |
990 | 983 | ||
991 | status = proto_register(&sctp_prot, 1); | 984 | status = proto_register(&sctp_prot, 1); |
992 | if (status) | 985 | if (status) |
993 | goto out; | 986 | goto out; |
994 | 987 | ||
995 | /* Add SCTP to inet_protos hash table. */ | 988 | /* Add SCTP to inet_protos hash table. */ |
996 | status = -EAGAIN; | 989 | status = -EAGAIN; |
997 | if (inet_add_protocol(&sctp_protocol, IPPROTO_SCTP) < 0) | 990 | if (inet_add_protocol(&sctp_protocol, IPPROTO_SCTP) < 0) |
998 | goto err_add_protocol; | 991 | goto err_add_protocol; |
999 | 992 | ||
1000 | /* Add SCTP(TCP and UDP style) to inetsw linked list. */ | 993 | /* Add SCTP(TCP and UDP style) to inetsw linked list. */ |
1001 | inet_register_protosw(&sctp_seqpacket_protosw); | 994 | inet_register_protosw(&sctp_seqpacket_protosw); |
1002 | inet_register_protosw(&sctp_stream_protosw); | 995 | inet_register_protosw(&sctp_stream_protosw); |
1003 | 996 | ||
1004 | /* Allocate a cache pools. */ | 997 | /* Allocate a cache pools. */ |
1005 | status = -ENOBUFS; | 998 | status = -ENOBUFS; |
1006 | sctp_bucket_cachep = kmem_cache_create("sctp_bind_bucket", | 999 | sctp_bucket_cachep = kmem_cache_create("sctp_bind_bucket", |
1007 | sizeof(struct sctp_bind_bucket), | 1000 | sizeof(struct sctp_bind_bucket), |
1008 | 0, SLAB_HWCACHE_ALIGN, | 1001 | 0, SLAB_HWCACHE_ALIGN, |
1009 | NULL, NULL); | 1002 | NULL, NULL); |
1010 | 1003 | ||
1011 | if (!sctp_bucket_cachep) | 1004 | if (!sctp_bucket_cachep) |
1012 | goto err_bucket_cachep; | 1005 | goto err_bucket_cachep; |
1013 | 1006 | ||
1014 | sctp_chunk_cachep = kmem_cache_create("sctp_chunk", | 1007 | sctp_chunk_cachep = kmem_cache_create("sctp_chunk", |
1015 | sizeof(struct sctp_chunk), | 1008 | sizeof(struct sctp_chunk), |
1016 | 0, SLAB_HWCACHE_ALIGN, | 1009 | 0, SLAB_HWCACHE_ALIGN, |
1017 | NULL, NULL); | 1010 | NULL, NULL); |
1018 | if (!sctp_chunk_cachep) | 1011 | if (!sctp_chunk_cachep) |
1019 | goto err_chunk_cachep; | 1012 | goto err_chunk_cachep; |
1020 | 1013 | ||
1021 | /* Allocate and initialise sctp mibs. */ | 1014 | /* Allocate and initialise sctp mibs. */ |
1022 | status = init_sctp_mibs(); | 1015 | status = init_sctp_mibs(); |
1023 | if (status) | 1016 | if (status) |
1024 | goto err_init_mibs; | 1017 | goto err_init_mibs; |
1025 | 1018 | ||
1026 | /* Initialize proc fs directory. */ | 1019 | /* Initialize proc fs directory. */ |
1027 | status = sctp_proc_init(); | 1020 | status = sctp_proc_init(); |
1028 | if (status) | 1021 | if (status) |
1029 | goto err_init_proc; | 1022 | goto err_init_proc; |
1030 | 1023 | ||
1031 | /* Initialize object count debugging. */ | 1024 | /* Initialize object count debugging. */ |
1032 | sctp_dbg_objcnt_init(); | 1025 | sctp_dbg_objcnt_init(); |
1033 | 1026 | ||
1034 | /* Initialize the SCTP specific PF functions. */ | 1027 | /* Initialize the SCTP specific PF functions. */ |
1035 | sctp_register_pf(&sctp_pf_inet, PF_INET); | 1028 | sctp_register_pf(&sctp_pf_inet, PF_INET); |
1036 | /* | 1029 | /* |
1037 | * 14. Suggested SCTP Protocol Parameter Values | 1030 | * 14. Suggested SCTP Protocol Parameter Values |
1038 | */ | 1031 | */ |
1039 | /* The following protocol parameters are RECOMMENDED: */ | 1032 | /* The following protocol parameters are RECOMMENDED: */ |
1040 | /* RTO.Initial - 3 seconds */ | 1033 | /* RTO.Initial - 3 seconds */ |
1041 | sctp_rto_initial = SCTP_RTO_INITIAL; | 1034 | sctp_rto_initial = SCTP_RTO_INITIAL; |
1042 | /* RTO.Min - 1 second */ | 1035 | /* RTO.Min - 1 second */ |
1043 | sctp_rto_min = SCTP_RTO_MIN; | 1036 | sctp_rto_min = SCTP_RTO_MIN; |
1044 | /* RTO.Max - 60 seconds */ | 1037 | /* RTO.Max - 60 seconds */ |
1045 | sctp_rto_max = SCTP_RTO_MAX; | 1038 | sctp_rto_max = SCTP_RTO_MAX; |
1046 | /* RTO.Alpha - 1/8 */ | 1039 | /* RTO.Alpha - 1/8 */ |
1047 | sctp_rto_alpha = SCTP_RTO_ALPHA; | 1040 | sctp_rto_alpha = SCTP_RTO_ALPHA; |
1048 | /* RTO.Beta - 1/4 */ | 1041 | /* RTO.Beta - 1/4 */ |
1049 | sctp_rto_beta = SCTP_RTO_BETA; | 1042 | sctp_rto_beta = SCTP_RTO_BETA; |
1050 | 1043 | ||
1051 | /* Valid.Cookie.Life - 60 seconds */ | 1044 | /* Valid.Cookie.Life - 60 seconds */ |
1052 | sctp_valid_cookie_life = SCTP_DEFAULT_COOKIE_LIFE; | 1045 | sctp_valid_cookie_life = SCTP_DEFAULT_COOKIE_LIFE; |
1053 | 1046 | ||
1054 | /* Whether Cookie Preservative is enabled(1) or not(0) */ | 1047 | /* Whether Cookie Preservative is enabled(1) or not(0) */ |
1055 | sctp_cookie_preserve_enable = 1; | 1048 | sctp_cookie_preserve_enable = 1; |
1056 | 1049 | ||
1057 | /* Max.Burst - 4 */ | 1050 | /* Max.Burst - 4 */ |
1058 | sctp_max_burst = SCTP_MAX_BURST; | 1051 | sctp_max_burst = SCTP_MAX_BURST; |
1059 | 1052 | ||
1060 | /* Association.Max.Retrans - 10 attempts | 1053 | /* Association.Max.Retrans - 10 attempts |
1061 | * Path.Max.Retrans - 5 attempts (per destination address) | 1054 | * Path.Max.Retrans - 5 attempts (per destination address) |
1062 | * Max.Init.Retransmits - 8 attempts | 1055 | * Max.Init.Retransmits - 8 attempts |
1063 | */ | 1056 | */ |
1064 | sctp_max_retrans_association = 10; | 1057 | sctp_max_retrans_association = 10; |
1065 | sctp_max_retrans_path = 5; | 1058 | sctp_max_retrans_path = 5; |
1066 | sctp_max_retrans_init = 8; | 1059 | sctp_max_retrans_init = 8; |
1067 | 1060 | ||
1068 | /* Sendbuffer growth - do per-socket accounting */ | 1061 | /* Sendbuffer growth - do per-socket accounting */ |
1069 | sctp_sndbuf_policy = 0; | 1062 | sctp_sndbuf_policy = 0; |
1070 | 1063 | ||
1071 | /* Rcvbuffer growth - do per-socket accounting */ | 1064 | /* Rcvbuffer growth - do per-socket accounting */ |
1072 | sctp_rcvbuf_policy = 0; | 1065 | sctp_rcvbuf_policy = 0; |
1073 | 1066 | ||
1074 | /* HB.interval - 30 seconds */ | 1067 | /* HB.interval - 30 seconds */ |
1075 | sctp_hb_interval = SCTP_DEFAULT_TIMEOUT_HEARTBEAT; | 1068 | sctp_hb_interval = SCTP_DEFAULT_TIMEOUT_HEARTBEAT; |
1076 | 1069 | ||
1077 | /* delayed SACK timeout */ | 1070 | /* delayed SACK timeout */ |
1078 | sctp_sack_timeout = SCTP_DEFAULT_TIMEOUT_SACK; | 1071 | sctp_sack_timeout = SCTP_DEFAULT_TIMEOUT_SACK; |
1079 | 1072 | ||
1080 | /* Implementation specific variables. */ | 1073 | /* Implementation specific variables. */ |
1081 | 1074 | ||
1082 | /* Initialize default stream count setup information. */ | 1075 | /* Initialize default stream count setup information. */ |
1083 | sctp_max_instreams = SCTP_DEFAULT_INSTREAMS; | 1076 | sctp_max_instreams = SCTP_DEFAULT_INSTREAMS; |
1084 | sctp_max_outstreams = SCTP_DEFAULT_OUTSTREAMS; | 1077 | sctp_max_outstreams = SCTP_DEFAULT_OUTSTREAMS; |
1085 | 1078 | ||
1086 | /* Initialize handle used for association ids. */ | 1079 | /* Initialize handle used for association ids. */ |
1087 | idr_init(&sctp_assocs_id); | 1080 | idr_init(&sctp_assocs_id); |
1088 | 1081 | ||
1089 | /* Size and allocate the association hash table. | 1082 | /* Size and allocate the association hash table. |
1090 | * The methodology is similar to that of the tcp hash tables. | 1083 | * The methodology is similar to that of the tcp hash tables. |
1091 | */ | 1084 | */ |
1092 | if (num_physpages >= (128 * 1024)) | 1085 | if (num_physpages >= (128 * 1024)) |
1093 | goal = num_physpages >> (22 - PAGE_SHIFT); | 1086 | goal = num_physpages >> (22 - PAGE_SHIFT); |
1094 | else | 1087 | else |
1095 | goal = num_physpages >> (24 - PAGE_SHIFT); | 1088 | goal = num_physpages >> (24 - PAGE_SHIFT); |
1096 | 1089 | ||
1097 | for (order = 0; (1UL << order) < goal; order++) | 1090 | for (order = 0; (1UL << order) < goal; order++) |
1098 | ; | 1091 | ; |
1099 | 1092 | ||
1100 | do { | 1093 | do { |
1101 | sctp_assoc_hashsize = (1UL << order) * PAGE_SIZE / | 1094 | sctp_assoc_hashsize = (1UL << order) * PAGE_SIZE / |
1102 | sizeof(struct sctp_hashbucket); | 1095 | sizeof(struct sctp_hashbucket); |
1103 | if ((sctp_assoc_hashsize > (64 * 1024)) && order > 0) | 1096 | if ((sctp_assoc_hashsize > (64 * 1024)) && order > 0) |
1104 | continue; | 1097 | continue; |
1105 | sctp_assoc_hashtable = (struct sctp_hashbucket *) | 1098 | sctp_assoc_hashtable = (struct sctp_hashbucket *) |
1106 | __get_free_pages(GFP_ATOMIC, order); | 1099 | __get_free_pages(GFP_ATOMIC, order); |
1107 | } while (!sctp_assoc_hashtable && --order > 0); | 1100 | } while (!sctp_assoc_hashtable && --order > 0); |
1108 | if (!sctp_assoc_hashtable) { | 1101 | if (!sctp_assoc_hashtable) { |
1109 | printk(KERN_ERR "SCTP: Failed association hash alloc.\n"); | 1102 | printk(KERN_ERR "SCTP: Failed association hash alloc.\n"); |
1110 | status = -ENOMEM; | 1103 | status = -ENOMEM; |
1111 | goto err_ahash_alloc; | 1104 | goto err_ahash_alloc; |
1112 | } | 1105 | } |
1113 | for (i = 0; i < sctp_assoc_hashsize; i++) { | 1106 | for (i = 0; i < sctp_assoc_hashsize; i++) { |
1114 | rwlock_init(&sctp_assoc_hashtable[i].lock); | 1107 | rwlock_init(&sctp_assoc_hashtable[i].lock); |
1115 | sctp_assoc_hashtable[i].chain = NULL; | 1108 | sctp_assoc_hashtable[i].chain = NULL; |
1116 | } | 1109 | } |
1117 | 1110 | ||
1118 | /* Allocate and initialize the endpoint hash table. */ | 1111 | /* Allocate and initialize the endpoint hash table. */ |
1119 | sctp_ep_hashsize = 64; | 1112 | sctp_ep_hashsize = 64; |
1120 | sctp_ep_hashtable = (struct sctp_hashbucket *) | 1113 | sctp_ep_hashtable = (struct sctp_hashbucket *) |
1121 | kmalloc(64 * sizeof(struct sctp_hashbucket), GFP_KERNEL); | 1114 | kmalloc(64 * sizeof(struct sctp_hashbucket), GFP_KERNEL); |
1122 | if (!sctp_ep_hashtable) { | 1115 | if (!sctp_ep_hashtable) { |
1123 | printk(KERN_ERR "SCTP: Failed endpoint_hash alloc.\n"); | 1116 | printk(KERN_ERR "SCTP: Failed endpoint_hash alloc.\n"); |
1124 | status = -ENOMEM; | 1117 | status = -ENOMEM; |
1125 | goto err_ehash_alloc; | 1118 | goto err_ehash_alloc; |
1126 | } | 1119 | } |
1127 | for (i = 0; i < sctp_ep_hashsize; i++) { | 1120 | for (i = 0; i < sctp_ep_hashsize; i++) { |
1128 | rwlock_init(&sctp_ep_hashtable[i].lock); | 1121 | rwlock_init(&sctp_ep_hashtable[i].lock); |
1129 | sctp_ep_hashtable[i].chain = NULL; | 1122 | sctp_ep_hashtable[i].chain = NULL; |
1130 | } | 1123 | } |
1131 | 1124 | ||
1132 | /* Allocate and initialize the SCTP port hash table. */ | 1125 | /* Allocate and initialize the SCTP port hash table. */ |
1133 | do { | 1126 | do { |
1134 | sctp_port_hashsize = (1UL << order) * PAGE_SIZE / | 1127 | sctp_port_hashsize = (1UL << order) * PAGE_SIZE / |
1135 | sizeof(struct sctp_bind_hashbucket); | 1128 | sizeof(struct sctp_bind_hashbucket); |
1136 | if ((sctp_port_hashsize > (64 * 1024)) && order > 0) | 1129 | if ((sctp_port_hashsize > (64 * 1024)) && order > 0) |
1137 | continue; | 1130 | continue; |
1138 | sctp_port_hashtable = (struct sctp_bind_hashbucket *) | 1131 | sctp_port_hashtable = (struct sctp_bind_hashbucket *) |
1139 | __get_free_pages(GFP_ATOMIC, order); | 1132 | __get_free_pages(GFP_ATOMIC, order); |
1140 | } while (!sctp_port_hashtable && --order > 0); | 1133 | } while (!sctp_port_hashtable && --order > 0); |
1141 | if (!sctp_port_hashtable) { | 1134 | if (!sctp_port_hashtable) { |
1142 | printk(KERN_ERR "SCTP: Failed bind hash alloc."); | 1135 | printk(KERN_ERR "SCTP: Failed bind hash alloc."); |
1143 | status = -ENOMEM; | 1136 | status = -ENOMEM; |
1144 | goto err_bhash_alloc; | 1137 | goto err_bhash_alloc; |
1145 | } | 1138 | } |
1146 | for (i = 0; i < sctp_port_hashsize; i++) { | 1139 | for (i = 0; i < sctp_port_hashsize; i++) { |
1147 | spin_lock_init(&sctp_port_hashtable[i].lock); | 1140 | spin_lock_init(&sctp_port_hashtable[i].lock); |
1148 | sctp_port_hashtable[i].chain = NULL; | 1141 | sctp_port_hashtable[i].chain = NULL; |
1149 | } | 1142 | } |
1150 | 1143 | ||
1151 | spin_lock_init(&sctp_port_alloc_lock); | 1144 | spin_lock_init(&sctp_port_alloc_lock); |
1152 | sctp_port_rover = sysctl_local_port_range[0] - 1; | 1145 | sctp_port_rover = sysctl_local_port_range[0] - 1; |
1153 | 1146 | ||
1154 | printk(KERN_INFO "SCTP: Hash tables configured " | 1147 | printk(KERN_INFO "SCTP: Hash tables configured " |
1155 | "(established %d bind %d)\n", | 1148 | "(established %d bind %d)\n", |
1156 | sctp_assoc_hashsize, sctp_port_hashsize); | 1149 | sctp_assoc_hashsize, sctp_port_hashsize); |
1157 | 1150 | ||
1158 | /* Disable ADDIP by default. */ | 1151 | /* Disable ADDIP by default. */ |
1159 | sctp_addip_enable = 0; | 1152 | sctp_addip_enable = 0; |
1160 | 1153 | ||
1161 | /* Enable PR-SCTP by default. */ | 1154 | /* Enable PR-SCTP by default. */ |
1162 | sctp_prsctp_enable = 1; | 1155 | sctp_prsctp_enable = 1; |
1163 | 1156 | ||
1164 | sctp_sysctl_register(); | 1157 | sctp_sysctl_register(); |
1165 | 1158 | ||
1166 | INIT_LIST_HEAD(&sctp_address_families); | 1159 | INIT_LIST_HEAD(&sctp_address_families); |
1167 | sctp_register_af(&sctp_ipv4_specific); | 1160 | sctp_register_af(&sctp_ipv4_specific); |
1168 | 1161 | ||
1169 | status = sctp_v6_init(); | 1162 | status = sctp_v6_init(); |
1170 | if (status) | 1163 | if (status) |
1171 | goto err_v6_init; | 1164 | goto err_v6_init; |
1172 | 1165 | ||
1173 | /* Initialize the control inode/socket for handling OOTB packets. */ | 1166 | /* Initialize the control inode/socket for handling OOTB packets. */ |
1174 | if ((status = sctp_ctl_sock_init())) { | 1167 | if ((status = sctp_ctl_sock_init())) { |
1175 | printk (KERN_ERR | 1168 | printk (KERN_ERR |
1176 | "SCTP: Failed to initialize the SCTP control sock.\n"); | 1169 | "SCTP: Failed to initialize the SCTP control sock.\n"); |
1177 | goto err_ctl_sock_init; | 1170 | goto err_ctl_sock_init; |
1178 | } | 1171 | } |
1179 | 1172 | ||
1180 | /* Initialize the local address list. */ | 1173 | /* Initialize the local address list. */ |
1181 | INIT_LIST_HEAD(&sctp_local_addr_list); | 1174 | INIT_LIST_HEAD(&sctp_local_addr_list); |
1182 | spin_lock_init(&sctp_local_addr_lock); | 1175 | spin_lock_init(&sctp_local_addr_lock); |
1183 | 1176 | ||
1184 | /* Register notifier for inet address additions/deletions. */ | 1177 | /* Register notifier for inet address additions/deletions. */ |
1185 | register_inetaddr_notifier(&sctp_inetaddr_notifier); | 1178 | register_inetaddr_notifier(&sctp_inetaddr_notifier); |
1186 | 1179 | ||
1187 | sctp_get_local_addr_list(); | 1180 | sctp_get_local_addr_list(); |
1188 | 1181 | ||
1189 | __unsafe(THIS_MODULE); | 1182 | __unsafe(THIS_MODULE); |
1190 | status = 0; | 1183 | status = 0; |
1191 | out: | 1184 | out: |
1192 | return status; | 1185 | return status; |
1193 | err_ctl_sock_init: | 1186 | err_ctl_sock_init: |
1194 | sctp_v6_exit(); | 1187 | sctp_v6_exit(); |
1195 | err_v6_init: | 1188 | err_v6_init: |
1196 | sctp_sysctl_unregister(); | 1189 | sctp_sysctl_unregister(); |
1197 | list_del(&sctp_ipv4_specific.list); | 1190 | list_del(&sctp_ipv4_specific.list); |
1198 | free_pages((unsigned long)sctp_port_hashtable, | 1191 | free_pages((unsigned long)sctp_port_hashtable, |
1199 | get_order(sctp_port_hashsize * | 1192 | get_order(sctp_port_hashsize * |
1200 | sizeof(struct sctp_bind_hashbucket))); | 1193 | sizeof(struct sctp_bind_hashbucket))); |
1201 | err_bhash_alloc: | 1194 | err_bhash_alloc: |
1202 | kfree(sctp_ep_hashtable); | 1195 | kfree(sctp_ep_hashtable); |
1203 | err_ehash_alloc: | 1196 | err_ehash_alloc: |
1204 | free_pages((unsigned long)sctp_assoc_hashtable, | 1197 | free_pages((unsigned long)sctp_assoc_hashtable, |
1205 | get_order(sctp_assoc_hashsize * | 1198 | get_order(sctp_assoc_hashsize * |
1206 | sizeof(struct sctp_hashbucket))); | 1199 | sizeof(struct sctp_hashbucket))); |
1207 | err_ahash_alloc: | 1200 | err_ahash_alloc: |
1208 | sctp_dbg_objcnt_exit(); | 1201 | sctp_dbg_objcnt_exit(); |
1209 | err_init_proc: | 1202 | err_init_proc: |
1210 | sctp_proc_exit(); | 1203 | sctp_proc_exit(); |
1211 | cleanup_sctp_mibs(); | 1204 | cleanup_sctp_mibs(); |
1212 | err_init_mibs: | 1205 | err_init_mibs: |
1213 | kmem_cache_destroy(sctp_chunk_cachep); | 1206 | kmem_cache_destroy(sctp_chunk_cachep); |
1214 | err_chunk_cachep: | 1207 | err_chunk_cachep: |
1215 | kmem_cache_destroy(sctp_bucket_cachep); | 1208 | kmem_cache_destroy(sctp_bucket_cachep); |
1216 | err_bucket_cachep: | 1209 | err_bucket_cachep: |
1217 | inet_del_protocol(&sctp_protocol, IPPROTO_SCTP); | 1210 | inet_del_protocol(&sctp_protocol, IPPROTO_SCTP); |
1218 | inet_unregister_protosw(&sctp_seqpacket_protosw); | 1211 | inet_unregister_protosw(&sctp_seqpacket_protosw); |
1219 | inet_unregister_protosw(&sctp_stream_protosw); | 1212 | inet_unregister_protosw(&sctp_stream_protosw); |
1220 | err_add_protocol: | 1213 | err_add_protocol: |
1221 | proto_unregister(&sctp_prot); | 1214 | proto_unregister(&sctp_prot); |
1222 | goto out; | 1215 | goto out; |
1223 | } | 1216 | } |
1224 | 1217 | ||
1225 | /* Exit handler for the SCTP protocol. */ | 1218 | /* Exit handler for the SCTP protocol. */ |
1226 | SCTP_STATIC __exit void sctp_exit(void) | 1219 | SCTP_STATIC __exit void sctp_exit(void) |
1227 | { | 1220 | { |
1228 | /* BUG. This should probably do something useful like clean | 1221 | /* BUG. This should probably do something useful like clean |
1229 | * up all the remaining associations and all that memory. | 1222 | * up all the remaining associations and all that memory. |
1230 | */ | 1223 | */ |
1231 | 1224 | ||
1232 | /* Unregister notifier for inet address additions/deletions. */ | 1225 | /* Unregister notifier for inet address additions/deletions. */ |
1233 | unregister_inetaddr_notifier(&sctp_inetaddr_notifier); | 1226 | unregister_inetaddr_notifier(&sctp_inetaddr_notifier); |
1234 | 1227 | ||
1235 | /* Free the local address list. */ | 1228 | /* Free the local address list. */ |
1236 | sctp_free_local_addr_list(); | 1229 | sctp_free_local_addr_list(); |
1237 | 1230 | ||
1238 | /* Free the control endpoint. */ | 1231 | /* Free the control endpoint. */ |
1239 | sock_release(sctp_ctl_socket); | 1232 | sock_release(sctp_ctl_socket); |
1240 | 1233 | ||
1241 | sctp_v6_exit(); | 1234 | sctp_v6_exit(); |
1242 | sctp_sysctl_unregister(); | 1235 | sctp_sysctl_unregister(); |
1243 | list_del(&sctp_ipv4_specific.list); | 1236 | list_del(&sctp_ipv4_specific.list); |
1244 | 1237 | ||
1245 | free_pages((unsigned long)sctp_assoc_hashtable, | 1238 | free_pages((unsigned long)sctp_assoc_hashtable, |
1246 | get_order(sctp_assoc_hashsize * | 1239 | get_order(sctp_assoc_hashsize * |
1247 | sizeof(struct sctp_hashbucket))); | 1240 | sizeof(struct sctp_hashbucket))); |
1248 | kfree(sctp_ep_hashtable); | 1241 | kfree(sctp_ep_hashtable); |
1249 | free_pages((unsigned long)sctp_port_hashtable, | 1242 | free_pages((unsigned long)sctp_port_hashtable, |
1250 | get_order(sctp_port_hashsize * | 1243 | get_order(sctp_port_hashsize * |
1251 | sizeof(struct sctp_bind_hashbucket))); | 1244 | sizeof(struct sctp_bind_hashbucket))); |
1252 | 1245 | ||
1253 | kmem_cache_destroy(sctp_chunk_cachep); | 1246 | kmem_cache_destroy(sctp_chunk_cachep); |
1254 | kmem_cache_destroy(sctp_bucket_cachep); | 1247 | kmem_cache_destroy(sctp_bucket_cachep); |
1255 | 1248 | ||
1256 | sctp_dbg_objcnt_exit(); | 1249 | sctp_dbg_objcnt_exit(); |
1257 | sctp_proc_exit(); | 1250 | sctp_proc_exit(); |
1258 | cleanup_sctp_mibs(); | 1251 | cleanup_sctp_mibs(); |
1259 | 1252 | ||
1260 | inet_del_protocol(&sctp_protocol, IPPROTO_SCTP); | 1253 | inet_del_protocol(&sctp_protocol, IPPROTO_SCTP); |
1261 | inet_unregister_protosw(&sctp_seqpacket_protosw); | 1254 | inet_unregister_protosw(&sctp_seqpacket_protosw); |
1262 | inet_unregister_protosw(&sctp_stream_protosw); | 1255 | inet_unregister_protosw(&sctp_stream_protosw); |
1263 | proto_unregister(&sctp_prot); | 1256 | proto_unregister(&sctp_prot); |
1264 | } | 1257 | } |
1265 | 1258 | ||
1266 | module_init(sctp_init); | 1259 | module_init(sctp_init); |
1267 | module_exit(sctp_exit); | 1260 | module_exit(sctp_exit); |
1268 | 1261 | ||
1269 | /* | 1262 | /* |
1270 | * __stringify doesn't likes enums, so use IPPROTO_SCTP value (132) directly. | 1263 | * __stringify doesn't likes enums, so use IPPROTO_SCTP value (132) directly. |
1271 | */ | 1264 | */ |
1272 | MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-132"); | 1265 | MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-132"); |
1273 | MODULE_AUTHOR("Linux Kernel SCTP developers <lksctp-developers@lists.sourceforge.net>"); | 1266 | MODULE_AUTHOR("Linux Kernel SCTP developers <lksctp-developers@lists.sourceforge.net>"); |
1274 | MODULE_DESCRIPTION("Support for the SCTP protocol (RFC2960)"); | 1267 | MODULE_DESCRIPTION("Support for the SCTP protocol (RFC2960)"); |
1275 | MODULE_LICENSE("GPL"); | 1268 | MODULE_LICENSE("GPL"); |
1276 | 1269 |
net/sctp/socket.c
1 | /* SCTP kernel reference Implementation | 1 | /* SCTP kernel reference Implementation |
2 | * (C) Copyright IBM Corp. 2001, 2004 | 2 | * (C) Copyright IBM Corp. 2001, 2004 |
3 | * Copyright (c) 1999-2000 Cisco, Inc. | 3 | * Copyright (c) 1999-2000 Cisco, Inc. |
4 | * Copyright (c) 1999-2001 Motorola, Inc. | 4 | * Copyright (c) 1999-2001 Motorola, Inc. |
5 | * Copyright (c) 2001-2003 Intel Corp. | 5 | * Copyright (c) 2001-2003 Intel Corp. |
6 | * Copyright (c) 2001-2002 Nokia, Inc. | 6 | * Copyright (c) 2001-2002 Nokia, Inc. |
7 | * Copyright (c) 2001 La Monte H.P. Yarroll | 7 | * Copyright (c) 2001 La Monte H.P. Yarroll |
8 | * | 8 | * |
9 | * This file is part of the SCTP kernel reference Implementation | 9 | * This file is part of the SCTP kernel reference Implementation |
10 | * | 10 | * |
11 | * These functions interface with the sockets layer to implement the | 11 | * These functions interface with the sockets layer to implement the |
12 | * SCTP Extensions for the Sockets API. | 12 | * SCTP Extensions for the Sockets API. |
13 | * | 13 | * |
14 | * Note that the descriptions from the specification are USER level | 14 | * Note that the descriptions from the specification are USER level |
15 | * functions--this file is the functions which populate the struct proto | 15 | * functions--this file is the functions which populate the struct proto |
16 | * for SCTP which is the BOTTOM of the sockets interface. | 16 | * for SCTP which is the BOTTOM of the sockets interface. |
17 | * | 17 | * |
18 | * The SCTP reference implementation is free software; | 18 | * The SCTP reference implementation is free software; |
19 | * you can redistribute it and/or modify it under the terms of | 19 | * you can redistribute it and/or modify it under the terms of |
20 | * the GNU General Public License as published by | 20 | * the GNU General Public License as published by |
21 | * the Free Software Foundation; either version 2, or (at your option) | 21 | * the Free Software Foundation; either version 2, or (at your option) |
22 | * any later version. | 22 | * any later version. |
23 | * | 23 | * |
24 | * The SCTP reference implementation is distributed in the hope that it | 24 | * The SCTP reference implementation is distributed in the hope that it |
25 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied | 25 | * will be useful, but WITHOUT ANY WARRANTY; without even the implied |
26 | * ************************ | 26 | * ************************ |
27 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 27 | * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
28 | * See the GNU General Public License for more details. | 28 | * See the GNU General Public License for more details. |
29 | * | 29 | * |
30 | * You should have received a copy of the GNU General Public License | 30 | * You should have received a copy of the GNU General Public License |
31 | * along with GNU CC; see the file COPYING. If not, write to | 31 | * along with GNU CC; see the file COPYING. If not, write to |
32 | * the Free Software Foundation, 59 Temple Place - Suite 330, | 32 | * the Free Software Foundation, 59 Temple Place - Suite 330, |
33 | * Boston, MA 02111-1307, USA. | 33 | * Boston, MA 02111-1307, USA. |
34 | * | 34 | * |
35 | * Please send any bug reports or fixes you make to the | 35 | * Please send any bug reports or fixes you make to the |
36 | * email address(es): | 36 | * email address(es): |
37 | * lksctp developers <lksctp-developers@lists.sourceforge.net> | 37 | * lksctp developers <lksctp-developers@lists.sourceforge.net> |
38 | * | 38 | * |
39 | * Or submit a bug report through the following website: | 39 | * Or submit a bug report through the following website: |
40 | * http://www.sf.net/projects/lksctp | 40 | * http://www.sf.net/projects/lksctp |
41 | * | 41 | * |
42 | * Written or modified by: | 42 | * Written or modified by: |
43 | * La Monte H.P. Yarroll <piggy@acm.org> | 43 | * La Monte H.P. Yarroll <piggy@acm.org> |
44 | * Narasimha Budihal <narsi@refcode.org> | 44 | * Narasimha Budihal <narsi@refcode.org> |
45 | * Karl Knutson <karl@athena.chicago.il.us> | 45 | * Karl Knutson <karl@athena.chicago.il.us> |
46 | * Jon Grimm <jgrimm@us.ibm.com> | 46 | * Jon Grimm <jgrimm@us.ibm.com> |
47 | * Xingang Guo <xingang.guo@intel.com> | 47 | * Xingang Guo <xingang.guo@intel.com> |
48 | * Daisy Chang <daisyc@us.ibm.com> | 48 | * Daisy Chang <daisyc@us.ibm.com> |
49 | * Sridhar Samudrala <samudrala@us.ibm.com> | 49 | * Sridhar Samudrala <samudrala@us.ibm.com> |
50 | * Inaky Perez-Gonzalez <inaky.gonzalez@intel.com> | 50 | * Inaky Perez-Gonzalez <inaky.gonzalez@intel.com> |
51 | * Ardelle Fan <ardelle.fan@intel.com> | 51 | * Ardelle Fan <ardelle.fan@intel.com> |
52 | * Ryan Layer <rmlayer@us.ibm.com> | 52 | * Ryan Layer <rmlayer@us.ibm.com> |
53 | * Anup Pemmaiah <pemmaiah@cc.usu.edu> | 53 | * Anup Pemmaiah <pemmaiah@cc.usu.edu> |
54 | * Kevin Gao <kevin.gao@intel.com> | 54 | * Kevin Gao <kevin.gao@intel.com> |
55 | * | 55 | * |
56 | * Any bugs reported given to us we will try to fix... any fixes shared will | 56 | * Any bugs reported given to us we will try to fix... any fixes shared will |
57 | * be incorporated into the next SCTP release. | 57 | * be incorporated into the next SCTP release. |
58 | */ | 58 | */ |
59 | 59 | ||
60 | #include <linux/types.h> | 60 | #include <linux/types.h> |
61 | #include <linux/kernel.h> | 61 | #include <linux/kernel.h> |
62 | #include <linux/wait.h> | 62 | #include <linux/wait.h> |
63 | #include <linux/time.h> | 63 | #include <linux/time.h> |
64 | #include <linux/ip.h> | 64 | #include <linux/ip.h> |
65 | #include <linux/capability.h> | 65 | #include <linux/capability.h> |
66 | #include <linux/fcntl.h> | 66 | #include <linux/fcntl.h> |
67 | #include <linux/poll.h> | 67 | #include <linux/poll.h> |
68 | #include <linux/init.h> | 68 | #include <linux/init.h> |
69 | #include <linux/crypto.h> | 69 | #include <linux/crypto.h> |
70 | 70 | ||
71 | #include <net/ip.h> | 71 | #include <net/ip.h> |
72 | #include <net/icmp.h> | 72 | #include <net/icmp.h> |
73 | #include <net/route.h> | 73 | #include <net/route.h> |
74 | #include <net/ipv6.h> | 74 | #include <net/ipv6.h> |
75 | #include <net/inet_common.h> | 75 | #include <net/inet_common.h> |
76 | 76 | ||
77 | #include <linux/socket.h> /* for sa_family_t */ | 77 | #include <linux/socket.h> /* for sa_family_t */ |
78 | #include <net/sock.h> | 78 | #include <net/sock.h> |
79 | #include <net/sctp/sctp.h> | 79 | #include <net/sctp/sctp.h> |
80 | #include <net/sctp/sm.h> | 80 | #include <net/sctp/sm.h> |
81 | 81 | ||
82 | /* WARNING: Please do not remove the SCTP_STATIC attribute to | 82 | /* WARNING: Please do not remove the SCTP_STATIC attribute to |
83 | * any of the functions below as they are used to export functions | 83 | * any of the functions below as they are used to export functions |
84 | * used by a project regression testsuite. | 84 | * used by a project regression testsuite. |
85 | */ | 85 | */ |
86 | 86 | ||
87 | /* Forward declarations for internal helper functions. */ | 87 | /* Forward declarations for internal helper functions. */ |
88 | static int sctp_writeable(struct sock *sk); | 88 | static int sctp_writeable(struct sock *sk); |
89 | static void sctp_wfree(struct sk_buff *skb); | 89 | static void sctp_wfree(struct sk_buff *skb); |
90 | static int sctp_wait_for_sndbuf(struct sctp_association *, long *timeo_p, | 90 | static int sctp_wait_for_sndbuf(struct sctp_association *, long *timeo_p, |
91 | size_t msg_len); | 91 | size_t msg_len); |
92 | static int sctp_wait_for_packet(struct sock * sk, int *err, long *timeo_p); | 92 | static int sctp_wait_for_packet(struct sock * sk, int *err, long *timeo_p); |
93 | static int sctp_wait_for_connect(struct sctp_association *, long *timeo_p); | 93 | static int sctp_wait_for_connect(struct sctp_association *, long *timeo_p); |
94 | static int sctp_wait_for_accept(struct sock *sk, long timeo); | 94 | static int sctp_wait_for_accept(struct sock *sk, long timeo); |
95 | static void sctp_wait_for_close(struct sock *sk, long timeo); | 95 | static void sctp_wait_for_close(struct sock *sk, long timeo); |
96 | static struct sctp_af *sctp_sockaddr_af(struct sctp_sock *opt, | 96 | static struct sctp_af *sctp_sockaddr_af(struct sctp_sock *opt, |
97 | union sctp_addr *addr, int len); | 97 | union sctp_addr *addr, int len); |
98 | static int sctp_bindx_add(struct sock *, struct sockaddr *, int); | 98 | static int sctp_bindx_add(struct sock *, struct sockaddr *, int); |
99 | static int sctp_bindx_rem(struct sock *, struct sockaddr *, int); | 99 | static int sctp_bindx_rem(struct sock *, struct sockaddr *, int); |
100 | static int sctp_send_asconf_add_ip(struct sock *, struct sockaddr *, int); | 100 | static int sctp_send_asconf_add_ip(struct sock *, struct sockaddr *, int); |
101 | static int sctp_send_asconf_del_ip(struct sock *, struct sockaddr *, int); | 101 | static int sctp_send_asconf_del_ip(struct sock *, struct sockaddr *, int); |
102 | static int sctp_send_asconf(struct sctp_association *asoc, | 102 | static int sctp_send_asconf(struct sctp_association *asoc, |
103 | struct sctp_chunk *chunk); | 103 | struct sctp_chunk *chunk); |
104 | static int sctp_do_bind(struct sock *, union sctp_addr *, int); | 104 | static int sctp_do_bind(struct sock *, union sctp_addr *, int); |
105 | static int sctp_autobind(struct sock *sk); | 105 | static int sctp_autobind(struct sock *sk); |
106 | static void sctp_sock_migrate(struct sock *, struct sock *, | 106 | static void sctp_sock_migrate(struct sock *, struct sock *, |
107 | struct sctp_association *, sctp_socket_type_t); | 107 | struct sctp_association *, sctp_socket_type_t); |
108 | static char *sctp_hmac_alg = SCTP_COOKIE_HMAC_ALG; | 108 | static char *sctp_hmac_alg = SCTP_COOKIE_HMAC_ALG; |
109 | 109 | ||
110 | extern kmem_cache_t *sctp_bucket_cachep; | 110 | extern kmem_cache_t *sctp_bucket_cachep; |
111 | 111 | ||
112 | /* Get the sndbuf space available at the time on the association. */ | 112 | /* Get the sndbuf space available at the time on the association. */ |
113 | static inline int sctp_wspace(struct sctp_association *asoc) | 113 | static inline int sctp_wspace(struct sctp_association *asoc) |
114 | { | 114 | { |
115 | struct sock *sk = asoc->base.sk; | 115 | struct sock *sk = asoc->base.sk; |
116 | int amt = 0; | 116 | int amt = 0; |
117 | 117 | ||
118 | if (asoc->ep->sndbuf_policy) { | 118 | if (asoc->ep->sndbuf_policy) { |
119 | /* make sure that no association uses more than sk_sndbuf */ | 119 | /* make sure that no association uses more than sk_sndbuf */ |
120 | amt = sk->sk_sndbuf - asoc->sndbuf_used; | 120 | amt = sk->sk_sndbuf - asoc->sndbuf_used; |
121 | } else { | 121 | } else { |
122 | /* do socket level accounting */ | 122 | /* do socket level accounting */ |
123 | amt = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc); | 123 | amt = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc); |
124 | } | 124 | } |
125 | 125 | ||
126 | if (amt < 0) | 126 | if (amt < 0) |
127 | amt = 0; | 127 | amt = 0; |
128 | 128 | ||
129 | return amt; | 129 | return amt; |
130 | } | 130 | } |
131 | 131 | ||
132 | /* Increment the used sndbuf space count of the corresponding association by | 132 | /* Increment the used sndbuf space count of the corresponding association by |
133 | * the size of the outgoing data chunk. | 133 | * the size of the outgoing data chunk. |
134 | * Also, set the skb destructor for sndbuf accounting later. | 134 | * Also, set the skb destructor for sndbuf accounting later. |
135 | * | 135 | * |
136 | * Since it is always 1-1 between chunk and skb, and also a new skb is always | 136 | * Since it is always 1-1 between chunk and skb, and also a new skb is always |
137 | * allocated for chunk bundling in sctp_packet_transmit(), we can use the | 137 | * allocated for chunk bundling in sctp_packet_transmit(), we can use the |
138 | * destructor in the data chunk skb for the purpose of the sndbuf space | 138 | * destructor in the data chunk skb for the purpose of the sndbuf space |
139 | * tracking. | 139 | * tracking. |
140 | */ | 140 | */ |
141 | static inline void sctp_set_owner_w(struct sctp_chunk *chunk) | 141 | static inline void sctp_set_owner_w(struct sctp_chunk *chunk) |
142 | { | 142 | { |
143 | struct sctp_association *asoc = chunk->asoc; | 143 | struct sctp_association *asoc = chunk->asoc; |
144 | struct sock *sk = asoc->base.sk; | 144 | struct sock *sk = asoc->base.sk; |
145 | 145 | ||
146 | /* The sndbuf space is tracked per association. */ | 146 | /* The sndbuf space is tracked per association. */ |
147 | sctp_association_hold(asoc); | 147 | sctp_association_hold(asoc); |
148 | 148 | ||
149 | skb_set_owner_w(chunk->skb, sk); | 149 | skb_set_owner_w(chunk->skb, sk); |
150 | 150 | ||
151 | chunk->skb->destructor = sctp_wfree; | 151 | chunk->skb->destructor = sctp_wfree; |
152 | /* Save the chunk pointer in skb for sctp_wfree to use later. */ | 152 | /* Save the chunk pointer in skb for sctp_wfree to use later. */ |
153 | *((struct sctp_chunk **)(chunk->skb->cb)) = chunk; | 153 | *((struct sctp_chunk **)(chunk->skb->cb)) = chunk; |
154 | 154 | ||
155 | asoc->sndbuf_used += SCTP_DATA_SNDSIZE(chunk) + | 155 | asoc->sndbuf_used += SCTP_DATA_SNDSIZE(chunk) + |
156 | sizeof(struct sk_buff) + | 156 | sizeof(struct sk_buff) + |
157 | sizeof(struct sctp_chunk); | 157 | sizeof(struct sctp_chunk); |
158 | 158 | ||
159 | atomic_add(sizeof(struct sctp_chunk), &sk->sk_wmem_alloc); | 159 | atomic_add(sizeof(struct sctp_chunk), &sk->sk_wmem_alloc); |
160 | } | 160 | } |
161 | 161 | ||
162 | /* Verify that this is a valid address. */ | 162 | /* Verify that this is a valid address. */ |
163 | static inline int sctp_verify_addr(struct sock *sk, union sctp_addr *addr, | 163 | static inline int sctp_verify_addr(struct sock *sk, union sctp_addr *addr, |
164 | int len) | 164 | int len) |
165 | { | 165 | { |
166 | struct sctp_af *af; | 166 | struct sctp_af *af; |
167 | 167 | ||
168 | /* Verify basic sockaddr. */ | 168 | /* Verify basic sockaddr. */ |
169 | af = sctp_sockaddr_af(sctp_sk(sk), addr, len); | 169 | af = sctp_sockaddr_af(sctp_sk(sk), addr, len); |
170 | if (!af) | 170 | if (!af) |
171 | return -EINVAL; | 171 | return -EINVAL; |
172 | 172 | ||
173 | /* Is this a valid SCTP address? */ | 173 | /* Is this a valid SCTP address? */ |
174 | if (!af->addr_valid(addr, sctp_sk(sk), NULL)) | 174 | if (!af->addr_valid(addr, sctp_sk(sk), NULL)) |
175 | return -EINVAL; | 175 | return -EINVAL; |
176 | 176 | ||
177 | if (!sctp_sk(sk)->pf->send_verify(sctp_sk(sk), (addr))) | 177 | if (!sctp_sk(sk)->pf->send_verify(sctp_sk(sk), (addr))) |
178 | return -EINVAL; | 178 | return -EINVAL; |
179 | 179 | ||
180 | return 0; | 180 | return 0; |
181 | } | 181 | } |
182 | 182 | ||
183 | /* Look up the association by its id. If this is not a UDP-style | 183 | /* Look up the association by its id. If this is not a UDP-style |
184 | * socket, the ID field is always ignored. | 184 | * socket, the ID field is always ignored. |
185 | */ | 185 | */ |
186 | struct sctp_association *sctp_id2assoc(struct sock *sk, sctp_assoc_t id) | 186 | struct sctp_association *sctp_id2assoc(struct sock *sk, sctp_assoc_t id) |
187 | { | 187 | { |
188 | struct sctp_association *asoc = NULL; | 188 | struct sctp_association *asoc = NULL; |
189 | 189 | ||
190 | /* If this is not a UDP-style socket, assoc id should be ignored. */ | 190 | /* If this is not a UDP-style socket, assoc id should be ignored. */ |
191 | if (!sctp_style(sk, UDP)) { | 191 | if (!sctp_style(sk, UDP)) { |
192 | /* Return NULL if the socket state is not ESTABLISHED. It | 192 | /* Return NULL if the socket state is not ESTABLISHED. It |
193 | * could be a TCP-style listening socket or a socket which | 193 | * could be a TCP-style listening socket or a socket which |
194 | * hasn't yet called connect() to establish an association. | 194 | * hasn't yet called connect() to establish an association. |
195 | */ | 195 | */ |
196 | if (!sctp_sstate(sk, ESTABLISHED)) | 196 | if (!sctp_sstate(sk, ESTABLISHED)) |
197 | return NULL; | 197 | return NULL; |
198 | 198 | ||
199 | /* Get the first and the only association from the list. */ | 199 | /* Get the first and the only association from the list. */ |
200 | if (!list_empty(&sctp_sk(sk)->ep->asocs)) | 200 | if (!list_empty(&sctp_sk(sk)->ep->asocs)) |
201 | asoc = list_entry(sctp_sk(sk)->ep->asocs.next, | 201 | asoc = list_entry(sctp_sk(sk)->ep->asocs.next, |
202 | struct sctp_association, asocs); | 202 | struct sctp_association, asocs); |
203 | return asoc; | 203 | return asoc; |
204 | } | 204 | } |
205 | 205 | ||
206 | /* Otherwise this is a UDP-style socket. */ | 206 | /* Otherwise this is a UDP-style socket. */ |
207 | if (!id || (id == (sctp_assoc_t)-1)) | 207 | if (!id || (id == (sctp_assoc_t)-1)) |
208 | return NULL; | 208 | return NULL; |
209 | 209 | ||
210 | spin_lock_bh(&sctp_assocs_id_lock); | 210 | spin_lock_bh(&sctp_assocs_id_lock); |
211 | asoc = (struct sctp_association *)idr_find(&sctp_assocs_id, (int)id); | 211 | asoc = (struct sctp_association *)idr_find(&sctp_assocs_id, (int)id); |
212 | spin_unlock_bh(&sctp_assocs_id_lock); | 212 | spin_unlock_bh(&sctp_assocs_id_lock); |
213 | 213 | ||
214 | if (!asoc || (asoc->base.sk != sk) || asoc->base.dead) | 214 | if (!asoc || (asoc->base.sk != sk) || asoc->base.dead) |
215 | return NULL; | 215 | return NULL; |
216 | 216 | ||
217 | return asoc; | 217 | return asoc; |
218 | } | 218 | } |
219 | 219 | ||
220 | /* Look up the transport from an address and an assoc id. If both address and | 220 | /* Look up the transport from an address and an assoc id. If both address and |
221 | * id are specified, the associations matching the address and the id should be | 221 | * id are specified, the associations matching the address and the id should be |
222 | * the same. | 222 | * the same. |
223 | */ | 223 | */ |
224 | static struct sctp_transport *sctp_addr_id2transport(struct sock *sk, | 224 | static struct sctp_transport *sctp_addr_id2transport(struct sock *sk, |
225 | struct sockaddr_storage *addr, | 225 | struct sockaddr_storage *addr, |
226 | sctp_assoc_t id) | 226 | sctp_assoc_t id) |
227 | { | 227 | { |
228 | struct sctp_association *addr_asoc = NULL, *id_asoc = NULL; | 228 | struct sctp_association *addr_asoc = NULL, *id_asoc = NULL; |
229 | struct sctp_transport *transport; | 229 | struct sctp_transport *transport; |
230 | union sctp_addr *laddr = (union sctp_addr *)addr; | 230 | union sctp_addr *laddr = (union sctp_addr *)addr; |
231 | 231 | ||
232 | laddr->v4.sin_port = ntohs(laddr->v4.sin_port); | 232 | laddr->v4.sin_port = ntohs(laddr->v4.sin_port); |
233 | addr_asoc = sctp_endpoint_lookup_assoc(sctp_sk(sk)->ep, | 233 | addr_asoc = sctp_endpoint_lookup_assoc(sctp_sk(sk)->ep, |
234 | (union sctp_addr *)addr, | 234 | (union sctp_addr *)addr, |
235 | &transport); | 235 | &transport); |
236 | laddr->v4.sin_port = htons(laddr->v4.sin_port); | 236 | laddr->v4.sin_port = htons(laddr->v4.sin_port); |
237 | 237 | ||
238 | if (!addr_asoc) | 238 | if (!addr_asoc) |
239 | return NULL; | 239 | return NULL; |
240 | 240 | ||
241 | id_asoc = sctp_id2assoc(sk, id); | 241 | id_asoc = sctp_id2assoc(sk, id); |
242 | if (id_asoc && (id_asoc != addr_asoc)) | 242 | if (id_asoc && (id_asoc != addr_asoc)) |
243 | return NULL; | 243 | return NULL; |
244 | 244 | ||
245 | sctp_get_pf_specific(sk->sk_family)->addr_v4map(sctp_sk(sk), | 245 | sctp_get_pf_specific(sk->sk_family)->addr_v4map(sctp_sk(sk), |
246 | (union sctp_addr *)addr); | 246 | (union sctp_addr *)addr); |
247 | 247 | ||
248 | return transport; | 248 | return transport; |
249 | } | 249 | } |
250 | 250 | ||
251 | /* API 3.1.2 bind() - UDP Style Syntax | 251 | /* API 3.1.2 bind() - UDP Style Syntax |
252 | * The syntax of bind() is, | 252 | * The syntax of bind() is, |
253 | * | 253 | * |
254 | * ret = bind(int sd, struct sockaddr *addr, int addrlen); | 254 | * ret = bind(int sd, struct sockaddr *addr, int addrlen); |
255 | * | 255 | * |
256 | * sd - the socket descriptor returned by socket(). | 256 | * sd - the socket descriptor returned by socket(). |
257 | * addr - the address structure (struct sockaddr_in or struct | 257 | * addr - the address structure (struct sockaddr_in or struct |
258 | * sockaddr_in6 [RFC 2553]), | 258 | * sockaddr_in6 [RFC 2553]), |
259 | * addr_len - the size of the address structure. | 259 | * addr_len - the size of the address structure. |
260 | */ | 260 | */ |
261 | SCTP_STATIC int sctp_bind(struct sock *sk, struct sockaddr *addr, int addr_len) | 261 | SCTP_STATIC int sctp_bind(struct sock *sk, struct sockaddr *addr, int addr_len) |
262 | { | 262 | { |
263 | int retval = 0; | 263 | int retval = 0; |
264 | 264 | ||
265 | sctp_lock_sock(sk); | 265 | sctp_lock_sock(sk); |
266 | 266 | ||
267 | SCTP_DEBUG_PRINTK("sctp_bind(sk: %p, addr: %p, addr_len: %d)\n", | 267 | SCTP_DEBUG_PRINTK("sctp_bind(sk: %p, addr: %p, addr_len: %d)\n", |
268 | sk, addr, addr_len); | 268 | sk, addr, addr_len); |
269 | 269 | ||
270 | /* Disallow binding twice. */ | 270 | /* Disallow binding twice. */ |
271 | if (!sctp_sk(sk)->ep->base.bind_addr.port) | 271 | if (!sctp_sk(sk)->ep->base.bind_addr.port) |
272 | retval = sctp_do_bind(sk, (union sctp_addr *)addr, | 272 | retval = sctp_do_bind(sk, (union sctp_addr *)addr, |
273 | addr_len); | 273 | addr_len); |
274 | else | 274 | else |
275 | retval = -EINVAL; | 275 | retval = -EINVAL; |
276 | 276 | ||
277 | sctp_release_sock(sk); | 277 | sctp_release_sock(sk); |
278 | 278 | ||
279 | return retval; | 279 | return retval; |
280 | } | 280 | } |
281 | 281 | ||
282 | static long sctp_get_port_local(struct sock *, union sctp_addr *); | 282 | static long sctp_get_port_local(struct sock *, union sctp_addr *); |
283 | 283 | ||
284 | /* Verify this is a valid sockaddr. */ | 284 | /* Verify this is a valid sockaddr. */ |
285 | static struct sctp_af *sctp_sockaddr_af(struct sctp_sock *opt, | 285 | static struct sctp_af *sctp_sockaddr_af(struct sctp_sock *opt, |
286 | union sctp_addr *addr, int len) | 286 | union sctp_addr *addr, int len) |
287 | { | 287 | { |
288 | struct sctp_af *af; | 288 | struct sctp_af *af; |
289 | 289 | ||
290 | /* Check minimum size. */ | 290 | /* Check minimum size. */ |
291 | if (len < sizeof (struct sockaddr)) | 291 | if (len < sizeof (struct sockaddr)) |
292 | return NULL; | 292 | return NULL; |
293 | 293 | ||
294 | /* Does this PF support this AF? */ | 294 | /* Does this PF support this AF? */ |
295 | if (!opt->pf->af_supported(addr->sa.sa_family, opt)) | 295 | if (!opt->pf->af_supported(addr->sa.sa_family, opt)) |
296 | return NULL; | 296 | return NULL; |
297 | 297 | ||
298 | /* If we get this far, af is valid. */ | 298 | /* If we get this far, af is valid. */ |
299 | af = sctp_get_af_specific(addr->sa.sa_family); | 299 | af = sctp_get_af_specific(addr->sa.sa_family); |
300 | 300 | ||
301 | if (len < af->sockaddr_len) | 301 | if (len < af->sockaddr_len) |
302 | return NULL; | 302 | return NULL; |
303 | 303 | ||
304 | return af; | 304 | return af; |
305 | } | 305 | } |
306 | 306 | ||
307 | /* Bind a local address either to an endpoint or to an association. */ | 307 | /* Bind a local address either to an endpoint or to an association. */ |
308 | SCTP_STATIC int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len) | 308 | SCTP_STATIC int sctp_do_bind(struct sock *sk, union sctp_addr *addr, int len) |
309 | { | 309 | { |
310 | struct sctp_sock *sp = sctp_sk(sk); | 310 | struct sctp_sock *sp = sctp_sk(sk); |
311 | struct sctp_endpoint *ep = sp->ep; | 311 | struct sctp_endpoint *ep = sp->ep; |
312 | struct sctp_bind_addr *bp = &ep->base.bind_addr; | 312 | struct sctp_bind_addr *bp = &ep->base.bind_addr; |
313 | struct sctp_af *af; | 313 | struct sctp_af *af; |
314 | unsigned short snum; | 314 | unsigned short snum; |
315 | int ret = 0; | 315 | int ret = 0; |
316 | 316 | ||
317 | /* Common sockaddr verification. */ | 317 | /* Common sockaddr verification. */ |
318 | af = sctp_sockaddr_af(sp, addr, len); | 318 | af = sctp_sockaddr_af(sp, addr, len); |
319 | if (!af) { | 319 | if (!af) { |
320 | SCTP_DEBUG_PRINTK("sctp_do_bind(sk: %p, newaddr: %p, len: %d) EINVAL\n", | 320 | SCTP_DEBUG_PRINTK("sctp_do_bind(sk: %p, newaddr: %p, len: %d) EINVAL\n", |
321 | sk, addr, len); | 321 | sk, addr, len); |
322 | return -EINVAL; | 322 | return -EINVAL; |
323 | } | 323 | } |
324 | 324 | ||
325 | snum = ntohs(addr->v4.sin_port); | 325 | snum = ntohs(addr->v4.sin_port); |
326 | 326 | ||
327 | SCTP_DEBUG_PRINTK_IPADDR("sctp_do_bind(sk: %p, new addr: ", | 327 | SCTP_DEBUG_PRINTK_IPADDR("sctp_do_bind(sk: %p, new addr: ", |
328 | ", port: %d, new port: %d, len: %d)\n", | 328 | ", port: %d, new port: %d, len: %d)\n", |
329 | sk, | 329 | sk, |
330 | addr, | 330 | addr, |
331 | bp->port, snum, | 331 | bp->port, snum, |
332 | len); | 332 | len); |
333 | 333 | ||
334 | /* PF specific bind() address verification. */ | 334 | /* PF specific bind() address verification. */ |
335 | if (!sp->pf->bind_verify(sp, addr)) | 335 | if (!sp->pf->bind_verify(sp, addr)) |
336 | return -EADDRNOTAVAIL; | 336 | return -EADDRNOTAVAIL; |
337 | 337 | ||
338 | /* We must either be unbound, or bind to the same port. */ | 338 | /* We must either be unbound, or bind to the same port. */ |
339 | if (bp->port && (snum != bp->port)) { | 339 | if (bp->port && (snum != bp->port)) { |
340 | SCTP_DEBUG_PRINTK("sctp_do_bind:" | 340 | SCTP_DEBUG_PRINTK("sctp_do_bind:" |
341 | " New port %d does not match existing port " | 341 | " New port %d does not match existing port " |
342 | "%d.\n", snum, bp->port); | 342 | "%d.\n", snum, bp->port); |
343 | return -EINVAL; | 343 | return -EINVAL; |
344 | } | 344 | } |
345 | 345 | ||
346 | if (snum && snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE)) | 346 | if (snum && snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE)) |
347 | return -EACCES; | 347 | return -EACCES; |
348 | 348 | ||
349 | /* Make sure we are allowed to bind here. | 349 | /* Make sure we are allowed to bind here. |
350 | * The function sctp_get_port_local() does duplicate address | 350 | * The function sctp_get_port_local() does duplicate address |
351 | * detection. | 351 | * detection. |
352 | */ | 352 | */ |
353 | if ((ret = sctp_get_port_local(sk, addr))) { | 353 | if ((ret = sctp_get_port_local(sk, addr))) { |
354 | if (ret == (long) sk) { | 354 | if (ret == (long) sk) { |
355 | /* This endpoint has a conflicting address. */ | 355 | /* This endpoint has a conflicting address. */ |
356 | return -EINVAL; | 356 | return -EINVAL; |
357 | } else { | 357 | } else { |
358 | return -EADDRINUSE; | 358 | return -EADDRINUSE; |
359 | } | 359 | } |
360 | } | 360 | } |
361 | 361 | ||
362 | /* Refresh ephemeral port. */ | 362 | /* Refresh ephemeral port. */ |
363 | if (!bp->port) | 363 | if (!bp->port) |
364 | bp->port = inet_sk(sk)->num; | 364 | bp->port = inet_sk(sk)->num; |
365 | 365 | ||
366 | /* Add the address to the bind address list. */ | 366 | /* Add the address to the bind address list. */ |
367 | sctp_local_bh_disable(); | 367 | sctp_local_bh_disable(); |
368 | sctp_write_lock(&ep->base.addr_lock); | 368 | sctp_write_lock(&ep->base.addr_lock); |
369 | 369 | ||
370 | /* Use GFP_ATOMIC since BHs are disabled. */ | 370 | /* Use GFP_ATOMIC since BHs are disabled. */ |
371 | addr->v4.sin_port = ntohs(addr->v4.sin_port); | 371 | addr->v4.sin_port = ntohs(addr->v4.sin_port); |
372 | ret = sctp_add_bind_addr(bp, addr, 1, GFP_ATOMIC); | 372 | ret = sctp_add_bind_addr(bp, addr, 1, GFP_ATOMIC); |
373 | addr->v4.sin_port = htons(addr->v4.sin_port); | 373 | addr->v4.sin_port = htons(addr->v4.sin_port); |
374 | sctp_write_unlock(&ep->base.addr_lock); | 374 | sctp_write_unlock(&ep->base.addr_lock); |
375 | sctp_local_bh_enable(); | 375 | sctp_local_bh_enable(); |
376 | 376 | ||
377 | /* Copy back into socket for getsockname() use. */ | 377 | /* Copy back into socket for getsockname() use. */ |
378 | if (!ret) { | 378 | if (!ret) { |
379 | inet_sk(sk)->sport = htons(inet_sk(sk)->num); | 379 | inet_sk(sk)->sport = htons(inet_sk(sk)->num); |
380 | af->to_sk_saddr(addr, sk); | 380 | af->to_sk_saddr(addr, sk); |
381 | } | 381 | } |
382 | 382 | ||
383 | return ret; | 383 | return ret; |
384 | } | 384 | } |
385 | 385 | ||
386 | /* ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks | 386 | /* ADDIP Section 4.1.1 Congestion Control of ASCONF Chunks |
387 | * | 387 | * |
388 | * R1) One and only one ASCONF Chunk MAY be in transit and unacknowledged | 388 | * R1) One and only one ASCONF Chunk MAY be in transit and unacknowledged |
389 | * at any one time. If a sender, after sending an ASCONF chunk, decides | 389 | * at any one time. If a sender, after sending an ASCONF chunk, decides |
390 | * it needs to transfer another ASCONF Chunk, it MUST wait until the | 390 | * it needs to transfer another ASCONF Chunk, it MUST wait until the |
391 | * ASCONF-ACK Chunk returns from the previous ASCONF Chunk before sending a | 391 | * ASCONF-ACK Chunk returns from the previous ASCONF Chunk before sending a |
392 | * subsequent ASCONF. Note this restriction binds each side, so at any | 392 | * subsequent ASCONF. Note this restriction binds each side, so at any |
393 | * time two ASCONF may be in-transit on any given association (one sent | 393 | * time two ASCONF may be in-transit on any given association (one sent |
394 | * from each endpoint). | 394 | * from each endpoint). |
395 | */ | 395 | */ |
396 | static int sctp_send_asconf(struct sctp_association *asoc, | 396 | static int sctp_send_asconf(struct sctp_association *asoc, |
397 | struct sctp_chunk *chunk) | 397 | struct sctp_chunk *chunk) |
398 | { | 398 | { |
399 | int retval = 0; | 399 | int retval = 0; |
400 | 400 | ||
401 | /* If there is an outstanding ASCONF chunk, queue it for later | 401 | /* If there is an outstanding ASCONF chunk, queue it for later |
402 | * transmission. | 402 | * transmission. |
403 | */ | 403 | */ |
404 | if (asoc->addip_last_asconf) { | 404 | if (asoc->addip_last_asconf) { |
405 | list_add_tail(&chunk->list, &asoc->addip_chunk_list); | 405 | list_add_tail(&chunk->list, &asoc->addip_chunk_list); |
406 | goto out; | 406 | goto out; |
407 | } | 407 | } |
408 | 408 | ||
409 | /* Hold the chunk until an ASCONF_ACK is received. */ | 409 | /* Hold the chunk until an ASCONF_ACK is received. */ |
410 | sctp_chunk_hold(chunk); | 410 | sctp_chunk_hold(chunk); |
411 | retval = sctp_primitive_ASCONF(asoc, chunk); | 411 | retval = sctp_primitive_ASCONF(asoc, chunk); |
412 | if (retval) | 412 | if (retval) |
413 | sctp_chunk_free(chunk); | 413 | sctp_chunk_free(chunk); |
414 | else | 414 | else |
415 | asoc->addip_last_asconf = chunk; | 415 | asoc->addip_last_asconf = chunk; |
416 | 416 | ||
417 | out: | 417 | out: |
418 | return retval; | 418 | return retval; |
419 | } | 419 | } |
420 | 420 | ||
421 | /* Add a list of addresses as bind addresses to local endpoint or | 421 | /* Add a list of addresses as bind addresses to local endpoint or |
422 | * association. | 422 | * association. |
423 | * | 423 | * |
424 | * Basically run through each address specified in the addrs/addrcnt | 424 | * Basically run through each address specified in the addrs/addrcnt |
425 | * array/length pair, determine if it is IPv6 or IPv4 and call | 425 | * array/length pair, determine if it is IPv6 or IPv4 and call |
426 | * sctp_do_bind() on it. | 426 | * sctp_do_bind() on it. |
427 | * | 427 | * |
428 | * If any of them fails, then the operation will be reversed and the | 428 | * If any of them fails, then the operation will be reversed and the |
429 | * ones that were added will be removed. | 429 | * ones that were added will be removed. |
430 | * | 430 | * |
431 | * Only sctp_setsockopt_bindx() is supposed to call this function. | 431 | * Only sctp_setsockopt_bindx() is supposed to call this function. |
432 | */ | 432 | */ |
433 | int sctp_bindx_add(struct sock *sk, struct sockaddr *addrs, int addrcnt) | 433 | int sctp_bindx_add(struct sock *sk, struct sockaddr *addrs, int addrcnt) |
434 | { | 434 | { |
435 | int cnt; | 435 | int cnt; |
436 | int retval = 0; | 436 | int retval = 0; |
437 | void *addr_buf; | 437 | void *addr_buf; |
438 | struct sockaddr *sa_addr; | 438 | struct sockaddr *sa_addr; |
439 | struct sctp_af *af; | 439 | struct sctp_af *af; |
440 | 440 | ||
441 | SCTP_DEBUG_PRINTK("sctp_bindx_add (sk: %p, addrs: %p, addrcnt: %d)\n", | 441 | SCTP_DEBUG_PRINTK("sctp_bindx_add (sk: %p, addrs: %p, addrcnt: %d)\n", |
442 | sk, addrs, addrcnt); | 442 | sk, addrs, addrcnt); |
443 | 443 | ||
444 | addr_buf = addrs; | 444 | addr_buf = addrs; |
445 | for (cnt = 0; cnt < addrcnt; cnt++) { | 445 | for (cnt = 0; cnt < addrcnt; cnt++) { |
446 | /* The list may contain either IPv4 or IPv6 address; | 446 | /* The list may contain either IPv4 or IPv6 address; |
447 | * determine the address length for walking thru the list. | 447 | * determine the address length for walking thru the list. |
448 | */ | 448 | */ |
449 | sa_addr = (struct sockaddr *)addr_buf; | 449 | sa_addr = (struct sockaddr *)addr_buf; |
450 | af = sctp_get_af_specific(sa_addr->sa_family); | 450 | af = sctp_get_af_specific(sa_addr->sa_family); |
451 | if (!af) { | 451 | if (!af) { |
452 | retval = -EINVAL; | 452 | retval = -EINVAL; |
453 | goto err_bindx_add; | 453 | goto err_bindx_add; |
454 | } | 454 | } |
455 | 455 | ||
456 | retval = sctp_do_bind(sk, (union sctp_addr *)sa_addr, | 456 | retval = sctp_do_bind(sk, (union sctp_addr *)sa_addr, |
457 | af->sockaddr_len); | 457 | af->sockaddr_len); |
458 | 458 | ||
459 | addr_buf += af->sockaddr_len; | 459 | addr_buf += af->sockaddr_len; |
460 | 460 | ||
461 | err_bindx_add: | 461 | err_bindx_add: |
462 | if (retval < 0) { | 462 | if (retval < 0) { |
463 | /* Failed. Cleanup the ones that have been added */ | 463 | /* Failed. Cleanup the ones that have been added */ |
464 | if (cnt > 0) | 464 | if (cnt > 0) |
465 | sctp_bindx_rem(sk, addrs, cnt); | 465 | sctp_bindx_rem(sk, addrs, cnt); |
466 | return retval; | 466 | return retval; |
467 | } | 467 | } |
468 | } | 468 | } |
469 | 469 | ||
470 | return retval; | 470 | return retval; |
471 | } | 471 | } |
472 | 472 | ||
473 | /* Send an ASCONF chunk with Add IP address parameters to all the peers of the | 473 | /* Send an ASCONF chunk with Add IP address parameters to all the peers of the |
474 | * associations that are part of the endpoint indicating that a list of local | 474 | * associations that are part of the endpoint indicating that a list of local |
475 | * addresses are added to the endpoint. | 475 | * addresses are added to the endpoint. |
476 | * | 476 | * |
477 | * If any of the addresses is already in the bind address list of the | 477 | * If any of the addresses is already in the bind address list of the |
478 | * association, we do not send the chunk for that association. But it will not | 478 | * association, we do not send the chunk for that association. But it will not |
479 | * affect other associations. | 479 | * affect other associations. |
480 | * | 480 | * |
481 | * Only sctp_setsockopt_bindx() is supposed to call this function. | 481 | * Only sctp_setsockopt_bindx() is supposed to call this function. |
482 | */ | 482 | */ |
483 | static int sctp_send_asconf_add_ip(struct sock *sk, | 483 | static int sctp_send_asconf_add_ip(struct sock *sk, |
484 | struct sockaddr *addrs, | 484 | struct sockaddr *addrs, |
485 | int addrcnt) | 485 | int addrcnt) |
486 | { | 486 | { |
487 | struct sctp_sock *sp; | 487 | struct sctp_sock *sp; |
488 | struct sctp_endpoint *ep; | 488 | struct sctp_endpoint *ep; |
489 | struct sctp_association *asoc; | 489 | struct sctp_association *asoc; |
490 | struct sctp_bind_addr *bp; | 490 | struct sctp_bind_addr *bp; |
491 | struct sctp_chunk *chunk; | 491 | struct sctp_chunk *chunk; |
492 | struct sctp_sockaddr_entry *laddr; | 492 | struct sctp_sockaddr_entry *laddr; |
493 | union sctp_addr *addr; | 493 | union sctp_addr *addr; |
494 | union sctp_addr saveaddr; | 494 | union sctp_addr saveaddr; |
495 | void *addr_buf; | 495 | void *addr_buf; |
496 | struct sctp_af *af; | 496 | struct sctp_af *af; |
497 | struct list_head *pos; | 497 | struct list_head *pos; |
498 | struct list_head *p; | 498 | struct list_head *p; |
499 | int i; | 499 | int i; |
500 | int retval = 0; | 500 | int retval = 0; |
501 | 501 | ||
502 | if (!sctp_addip_enable) | 502 | if (!sctp_addip_enable) |
503 | return retval; | 503 | return retval; |
504 | 504 | ||
505 | sp = sctp_sk(sk); | 505 | sp = sctp_sk(sk); |
506 | ep = sp->ep; | 506 | ep = sp->ep; |
507 | 507 | ||
508 | SCTP_DEBUG_PRINTK("%s: (sk: %p, addrs: %p, addrcnt: %d)\n", | 508 | SCTP_DEBUG_PRINTK("%s: (sk: %p, addrs: %p, addrcnt: %d)\n", |
509 | __FUNCTION__, sk, addrs, addrcnt); | 509 | __FUNCTION__, sk, addrs, addrcnt); |
510 | 510 | ||
511 | list_for_each(pos, &ep->asocs) { | 511 | list_for_each(pos, &ep->asocs) { |
512 | asoc = list_entry(pos, struct sctp_association, asocs); | 512 | asoc = list_entry(pos, struct sctp_association, asocs); |
513 | 513 | ||
514 | if (!asoc->peer.asconf_capable) | 514 | if (!asoc->peer.asconf_capable) |
515 | continue; | 515 | continue; |
516 | 516 | ||
517 | if (asoc->peer.addip_disabled_mask & SCTP_PARAM_ADD_IP) | 517 | if (asoc->peer.addip_disabled_mask & SCTP_PARAM_ADD_IP) |
518 | continue; | 518 | continue; |
519 | 519 | ||
520 | if (!sctp_state(asoc, ESTABLISHED)) | 520 | if (!sctp_state(asoc, ESTABLISHED)) |
521 | continue; | 521 | continue; |
522 | 522 | ||
523 | /* Check if any address in the packed array of addresses is | 523 | /* Check if any address in the packed array of addresses is |
524 | * in the bind address list of the association. If so, | 524 | * in the bind address list of the association. If so, |
525 | * do not send the asconf chunk to its peer, but continue with | 525 | * do not send the asconf chunk to its peer, but continue with |
526 | * other associations. | 526 | * other associations. |
527 | */ | 527 | */ |
528 | addr_buf = addrs; | 528 | addr_buf = addrs; |
529 | for (i = 0; i < addrcnt; i++) { | 529 | for (i = 0; i < addrcnt; i++) { |
530 | addr = (union sctp_addr *)addr_buf; | 530 | addr = (union sctp_addr *)addr_buf; |
531 | af = sctp_get_af_specific(addr->v4.sin_family); | 531 | af = sctp_get_af_specific(addr->v4.sin_family); |
532 | if (!af) { | 532 | if (!af) { |
533 | retval = -EINVAL; | 533 | retval = -EINVAL; |
534 | goto out; | 534 | goto out; |
535 | } | 535 | } |
536 | 536 | ||
537 | if (sctp_assoc_lookup_laddr(asoc, addr)) | 537 | if (sctp_assoc_lookup_laddr(asoc, addr)) |
538 | break; | 538 | break; |
539 | 539 | ||
540 | addr_buf += af->sockaddr_len; | 540 | addr_buf += af->sockaddr_len; |
541 | } | 541 | } |
542 | if (i < addrcnt) | 542 | if (i < addrcnt) |
543 | continue; | 543 | continue; |
544 | 544 | ||
545 | /* Use the first address in bind addr list of association as | 545 | /* Use the first address in bind addr list of association as |
546 | * Address Parameter of ASCONF CHUNK. | 546 | * Address Parameter of ASCONF CHUNK. |
547 | */ | 547 | */ |
548 | sctp_read_lock(&asoc->base.addr_lock); | 548 | sctp_read_lock(&asoc->base.addr_lock); |
549 | bp = &asoc->base.bind_addr; | 549 | bp = &asoc->base.bind_addr; |
550 | p = bp->address_list.next; | 550 | p = bp->address_list.next; |
551 | laddr = list_entry(p, struct sctp_sockaddr_entry, list); | 551 | laddr = list_entry(p, struct sctp_sockaddr_entry, list); |
552 | sctp_read_unlock(&asoc->base.addr_lock); | 552 | sctp_read_unlock(&asoc->base.addr_lock); |
553 | 553 | ||
554 | chunk = sctp_make_asconf_update_ip(asoc, &laddr->a, addrs, | 554 | chunk = sctp_make_asconf_update_ip(asoc, &laddr->a, addrs, |
555 | addrcnt, SCTP_PARAM_ADD_IP); | 555 | addrcnt, SCTP_PARAM_ADD_IP); |
556 | if (!chunk) { | 556 | if (!chunk) { |
557 | retval = -ENOMEM; | 557 | retval = -ENOMEM; |
558 | goto out; | 558 | goto out; |
559 | } | 559 | } |
560 | 560 | ||
561 | retval = sctp_send_asconf(asoc, chunk); | 561 | retval = sctp_send_asconf(asoc, chunk); |
562 | if (retval) | 562 | if (retval) |
563 | goto out; | 563 | goto out; |
564 | 564 | ||
565 | /* Add the new addresses to the bind address list with | 565 | /* Add the new addresses to the bind address list with |
566 | * use_as_src set to 0. | 566 | * use_as_src set to 0. |
567 | */ | 567 | */ |
568 | sctp_local_bh_disable(); | 568 | sctp_local_bh_disable(); |
569 | sctp_write_lock(&asoc->base.addr_lock); | 569 | sctp_write_lock(&asoc->base.addr_lock); |
570 | addr_buf = addrs; | 570 | addr_buf = addrs; |
571 | for (i = 0; i < addrcnt; i++) { | 571 | for (i = 0; i < addrcnt; i++) { |
572 | addr = (union sctp_addr *)addr_buf; | 572 | addr = (union sctp_addr *)addr_buf; |
573 | af = sctp_get_af_specific(addr->v4.sin_family); | 573 | af = sctp_get_af_specific(addr->v4.sin_family); |
574 | memcpy(&saveaddr, addr, af->sockaddr_len); | 574 | memcpy(&saveaddr, addr, af->sockaddr_len); |
575 | saveaddr.v4.sin_port = ntohs(saveaddr.v4.sin_port); | 575 | saveaddr.v4.sin_port = ntohs(saveaddr.v4.sin_port); |
576 | retval = sctp_add_bind_addr(bp, &saveaddr, 0, | 576 | retval = sctp_add_bind_addr(bp, &saveaddr, 0, |
577 | GFP_ATOMIC); | 577 | GFP_ATOMIC); |
578 | addr_buf += af->sockaddr_len; | 578 | addr_buf += af->sockaddr_len; |
579 | } | 579 | } |
580 | sctp_write_unlock(&asoc->base.addr_lock); | 580 | sctp_write_unlock(&asoc->base.addr_lock); |
581 | sctp_local_bh_enable(); | 581 | sctp_local_bh_enable(); |
582 | } | 582 | } |
583 | 583 | ||
584 | out: | 584 | out: |
585 | return retval; | 585 | return retval; |
586 | } | 586 | } |
587 | 587 | ||
588 | /* Remove a list of addresses from bind addresses list. Do not remove the | 588 | /* Remove a list of addresses from bind addresses list. Do not remove the |
589 | * last address. | 589 | * last address. |
590 | * | 590 | * |
591 | * Basically run through each address specified in the addrs/addrcnt | 591 | * Basically run through each address specified in the addrs/addrcnt |
592 | * array/length pair, determine if it is IPv6 or IPv4 and call | 592 | * array/length pair, determine if it is IPv6 or IPv4 and call |
593 | * sctp_del_bind() on it. | 593 | * sctp_del_bind() on it. |
594 | * | 594 | * |
595 | * If any of them fails, then the operation will be reversed and the | 595 | * If any of them fails, then the operation will be reversed and the |
596 | * ones that were removed will be added back. | 596 | * ones that were removed will be added back. |
597 | * | 597 | * |
598 | * At least one address has to be left; if only one address is | 598 | * At least one address has to be left; if only one address is |
599 | * available, the operation will return -EBUSY. | 599 | * available, the operation will return -EBUSY. |
600 | * | 600 | * |
601 | * Only sctp_setsockopt_bindx() is supposed to call this function. | 601 | * Only sctp_setsockopt_bindx() is supposed to call this function. |
602 | */ | 602 | */ |
603 | int sctp_bindx_rem(struct sock *sk, struct sockaddr *addrs, int addrcnt) | 603 | int sctp_bindx_rem(struct sock *sk, struct sockaddr *addrs, int addrcnt) |
604 | { | 604 | { |
605 | struct sctp_sock *sp = sctp_sk(sk); | 605 | struct sctp_sock *sp = sctp_sk(sk); |
606 | struct sctp_endpoint *ep = sp->ep; | 606 | struct sctp_endpoint *ep = sp->ep; |
607 | int cnt; | 607 | int cnt; |
608 | struct sctp_bind_addr *bp = &ep->base.bind_addr; | 608 | struct sctp_bind_addr *bp = &ep->base.bind_addr; |
609 | int retval = 0; | 609 | int retval = 0; |
610 | union sctp_addr saveaddr; | 610 | union sctp_addr saveaddr; |
611 | void *addr_buf; | 611 | void *addr_buf; |
612 | struct sockaddr *sa_addr; | 612 | struct sockaddr *sa_addr; |
613 | struct sctp_af *af; | 613 | struct sctp_af *af; |
614 | 614 | ||
615 | SCTP_DEBUG_PRINTK("sctp_bindx_rem (sk: %p, addrs: %p, addrcnt: %d)\n", | 615 | SCTP_DEBUG_PRINTK("sctp_bindx_rem (sk: %p, addrs: %p, addrcnt: %d)\n", |
616 | sk, addrs, addrcnt); | 616 | sk, addrs, addrcnt); |
617 | 617 | ||
618 | addr_buf = addrs; | 618 | addr_buf = addrs; |
619 | for (cnt = 0; cnt < addrcnt; cnt++) { | 619 | for (cnt = 0; cnt < addrcnt; cnt++) { |
620 | /* If the bind address list is empty or if there is only one | 620 | /* If the bind address list is empty or if there is only one |
621 | * bind address, there is nothing more to be removed (we need | 621 | * bind address, there is nothing more to be removed (we need |
622 | * at least one address here). | 622 | * at least one address here). |
623 | */ | 623 | */ |
624 | if (list_empty(&bp->address_list) || | 624 | if (list_empty(&bp->address_list) || |
625 | (sctp_list_single_entry(&bp->address_list))) { | 625 | (sctp_list_single_entry(&bp->address_list))) { |
626 | retval = -EBUSY; | 626 | retval = -EBUSY; |
627 | goto err_bindx_rem; | 627 | goto err_bindx_rem; |
628 | } | 628 | } |
629 | 629 | ||
630 | /* The list may contain either IPv4 or IPv6 address; | 630 | /* The list may contain either IPv4 or IPv6 address; |
631 | * determine the address length to copy the address to | 631 | * determine the address length to copy the address to |
632 | * saveaddr. | 632 | * saveaddr. |
633 | */ | 633 | */ |
634 | sa_addr = (struct sockaddr *)addr_buf; | 634 | sa_addr = (struct sockaddr *)addr_buf; |
635 | af = sctp_get_af_specific(sa_addr->sa_family); | 635 | af = sctp_get_af_specific(sa_addr->sa_family); |
636 | if (!af) { | 636 | if (!af) { |
637 | retval = -EINVAL; | 637 | retval = -EINVAL; |
638 | goto err_bindx_rem; | 638 | goto err_bindx_rem; |
639 | } | 639 | } |
640 | memcpy(&saveaddr, sa_addr, af->sockaddr_len); | 640 | memcpy(&saveaddr, sa_addr, af->sockaddr_len); |
641 | saveaddr.v4.sin_port = ntohs(saveaddr.v4.sin_port); | 641 | saveaddr.v4.sin_port = ntohs(saveaddr.v4.sin_port); |
642 | if (saveaddr.v4.sin_port != bp->port) { | 642 | if (saveaddr.v4.sin_port != bp->port) { |
643 | retval = -EINVAL; | 643 | retval = -EINVAL; |
644 | goto err_bindx_rem; | 644 | goto err_bindx_rem; |
645 | } | 645 | } |
646 | 646 | ||
647 | /* FIXME - There is probably a need to check if sk->sk_saddr and | 647 | /* FIXME - There is probably a need to check if sk->sk_saddr and |
648 | * sk->sk_rcv_addr are currently set to one of the addresses to | 648 | * sk->sk_rcv_addr are currently set to one of the addresses to |
649 | * be removed. This is something which needs to be looked into | 649 | * be removed. This is something which needs to be looked into |
650 | * when we are fixing the outstanding issues with multi-homing | 650 | * when we are fixing the outstanding issues with multi-homing |
651 | * socket routing and failover schemes. Refer to comments in | 651 | * socket routing and failover schemes. Refer to comments in |
652 | * sctp_do_bind(). -daisy | 652 | * sctp_do_bind(). -daisy |
653 | */ | 653 | */ |
654 | sctp_local_bh_disable(); | 654 | sctp_local_bh_disable(); |
655 | sctp_write_lock(&ep->base.addr_lock); | 655 | sctp_write_lock(&ep->base.addr_lock); |
656 | 656 | ||
657 | retval = sctp_del_bind_addr(bp, &saveaddr); | 657 | retval = sctp_del_bind_addr(bp, &saveaddr); |
658 | 658 | ||
659 | sctp_write_unlock(&ep->base.addr_lock); | 659 | sctp_write_unlock(&ep->base.addr_lock); |
660 | sctp_local_bh_enable(); | 660 | sctp_local_bh_enable(); |
661 | 661 | ||
662 | addr_buf += af->sockaddr_len; | 662 | addr_buf += af->sockaddr_len; |
663 | err_bindx_rem: | 663 | err_bindx_rem: |
664 | if (retval < 0) { | 664 | if (retval < 0) { |
665 | /* Failed. Add the ones that has been removed back */ | 665 | /* Failed. Add the ones that has been removed back */ |
666 | if (cnt > 0) | 666 | if (cnt > 0) |
667 | sctp_bindx_add(sk, addrs, cnt); | 667 | sctp_bindx_add(sk, addrs, cnt); |
668 | return retval; | 668 | return retval; |
669 | } | 669 | } |
670 | } | 670 | } |
671 | 671 | ||
672 | return retval; | 672 | return retval; |
673 | } | 673 | } |
674 | 674 | ||
675 | /* Send an ASCONF chunk with Delete IP address parameters to all the peers of | 675 | /* Send an ASCONF chunk with Delete IP address parameters to all the peers of |
676 | * the associations that are part of the endpoint indicating that a list of | 676 | * the associations that are part of the endpoint indicating that a list of |
677 | * local addresses are removed from the endpoint. | 677 | * local addresses are removed from the endpoint. |
678 | * | 678 | * |
679 | * If any of the addresses is already in the bind address list of the | 679 | * If any of the addresses is already in the bind address list of the |
680 | * association, we do not send the chunk for that association. But it will not | 680 | * association, we do not send the chunk for that association. But it will not |
681 | * affect other associations. | 681 | * affect other associations. |
682 | * | 682 | * |
683 | * Only sctp_setsockopt_bindx() is supposed to call this function. | 683 | * Only sctp_setsockopt_bindx() is supposed to call this function. |
684 | */ | 684 | */ |
685 | static int sctp_send_asconf_del_ip(struct sock *sk, | 685 | static int sctp_send_asconf_del_ip(struct sock *sk, |
686 | struct sockaddr *addrs, | 686 | struct sockaddr *addrs, |
687 | int addrcnt) | 687 | int addrcnt) |
688 | { | 688 | { |
689 | struct sctp_sock *sp; | 689 | struct sctp_sock *sp; |
690 | struct sctp_endpoint *ep; | 690 | struct sctp_endpoint *ep; |
691 | struct sctp_association *asoc; | 691 | struct sctp_association *asoc; |
692 | struct sctp_transport *transport; | 692 | struct sctp_transport *transport; |
693 | struct sctp_bind_addr *bp; | 693 | struct sctp_bind_addr *bp; |
694 | struct sctp_chunk *chunk; | 694 | struct sctp_chunk *chunk; |
695 | union sctp_addr *laddr; | 695 | union sctp_addr *laddr; |
696 | union sctp_addr saveaddr; | 696 | union sctp_addr saveaddr; |
697 | void *addr_buf; | 697 | void *addr_buf; |
698 | struct sctp_af *af; | 698 | struct sctp_af *af; |
699 | struct list_head *pos, *pos1; | 699 | struct list_head *pos, *pos1; |
700 | struct sctp_sockaddr_entry *saddr; | 700 | struct sctp_sockaddr_entry *saddr; |
701 | int i; | 701 | int i; |
702 | int retval = 0; | 702 | int retval = 0; |
703 | 703 | ||
704 | if (!sctp_addip_enable) | 704 | if (!sctp_addip_enable) |
705 | return retval; | 705 | return retval; |
706 | 706 | ||
707 | sp = sctp_sk(sk); | 707 | sp = sctp_sk(sk); |
708 | ep = sp->ep; | 708 | ep = sp->ep; |
709 | 709 | ||
710 | SCTP_DEBUG_PRINTK("%s: (sk: %p, addrs: %p, addrcnt: %d)\n", | 710 | SCTP_DEBUG_PRINTK("%s: (sk: %p, addrs: %p, addrcnt: %d)\n", |
711 | __FUNCTION__, sk, addrs, addrcnt); | 711 | __FUNCTION__, sk, addrs, addrcnt); |
712 | 712 | ||
713 | list_for_each(pos, &ep->asocs) { | 713 | list_for_each(pos, &ep->asocs) { |
714 | asoc = list_entry(pos, struct sctp_association, asocs); | 714 | asoc = list_entry(pos, struct sctp_association, asocs); |
715 | 715 | ||
716 | if (!asoc->peer.asconf_capable) | 716 | if (!asoc->peer.asconf_capable) |
717 | continue; | 717 | continue; |
718 | 718 | ||
719 | if (asoc->peer.addip_disabled_mask & SCTP_PARAM_DEL_IP) | 719 | if (asoc->peer.addip_disabled_mask & SCTP_PARAM_DEL_IP) |
720 | continue; | 720 | continue; |
721 | 721 | ||
722 | if (!sctp_state(asoc, ESTABLISHED)) | 722 | if (!sctp_state(asoc, ESTABLISHED)) |
723 | continue; | 723 | continue; |
724 | 724 | ||
725 | /* Check if any address in the packed array of addresses is | 725 | /* Check if any address in the packed array of addresses is |
726 | * not present in the bind address list of the association. | 726 | * not present in the bind address list of the association. |
727 | * If so, do not send the asconf chunk to its peer, but | 727 | * If so, do not send the asconf chunk to its peer, but |
728 | * continue with other associations. | 728 | * continue with other associations. |
729 | */ | 729 | */ |
730 | addr_buf = addrs; | 730 | addr_buf = addrs; |
731 | for (i = 0; i < addrcnt; i++) { | 731 | for (i = 0; i < addrcnt; i++) { |
732 | laddr = (union sctp_addr *)addr_buf; | 732 | laddr = (union sctp_addr *)addr_buf; |
733 | af = sctp_get_af_specific(laddr->v4.sin_family); | 733 | af = sctp_get_af_specific(laddr->v4.sin_family); |
734 | if (!af) { | 734 | if (!af) { |
735 | retval = -EINVAL; | 735 | retval = -EINVAL; |
736 | goto out; | 736 | goto out; |
737 | } | 737 | } |
738 | 738 | ||
739 | if (!sctp_assoc_lookup_laddr(asoc, laddr)) | 739 | if (!sctp_assoc_lookup_laddr(asoc, laddr)) |
740 | break; | 740 | break; |
741 | 741 | ||
742 | addr_buf += af->sockaddr_len; | 742 | addr_buf += af->sockaddr_len; |
743 | } | 743 | } |
744 | if (i < addrcnt) | 744 | if (i < addrcnt) |
745 | continue; | 745 | continue; |
746 | 746 | ||
747 | /* Find one address in the association's bind address list | 747 | /* Find one address in the association's bind address list |
748 | * that is not in the packed array of addresses. This is to | 748 | * that is not in the packed array of addresses. This is to |
749 | * make sure that we do not delete all the addresses in the | 749 | * make sure that we do not delete all the addresses in the |
750 | * association. | 750 | * association. |
751 | */ | 751 | */ |
752 | sctp_read_lock(&asoc->base.addr_lock); | 752 | sctp_read_lock(&asoc->base.addr_lock); |
753 | bp = &asoc->base.bind_addr; | 753 | bp = &asoc->base.bind_addr; |
754 | laddr = sctp_find_unmatch_addr(bp, (union sctp_addr *)addrs, | 754 | laddr = sctp_find_unmatch_addr(bp, (union sctp_addr *)addrs, |
755 | addrcnt, sp); | 755 | addrcnt, sp); |
756 | sctp_read_unlock(&asoc->base.addr_lock); | 756 | sctp_read_unlock(&asoc->base.addr_lock); |
757 | if (!laddr) | 757 | if (!laddr) |
758 | continue; | 758 | continue; |
759 | 759 | ||
760 | chunk = sctp_make_asconf_update_ip(asoc, laddr, addrs, addrcnt, | 760 | chunk = sctp_make_asconf_update_ip(asoc, laddr, addrs, addrcnt, |
761 | SCTP_PARAM_DEL_IP); | 761 | SCTP_PARAM_DEL_IP); |
762 | if (!chunk) { | 762 | if (!chunk) { |
763 | retval = -ENOMEM; | 763 | retval = -ENOMEM; |
764 | goto out; | 764 | goto out; |
765 | } | 765 | } |
766 | 766 | ||
767 | /* Reset use_as_src flag for the addresses in the bind address | 767 | /* Reset use_as_src flag for the addresses in the bind address |
768 | * list that are to be deleted. | 768 | * list that are to be deleted. |
769 | */ | 769 | */ |
770 | sctp_local_bh_disable(); | 770 | sctp_local_bh_disable(); |
771 | sctp_write_lock(&asoc->base.addr_lock); | 771 | sctp_write_lock(&asoc->base.addr_lock); |
772 | addr_buf = addrs; | 772 | addr_buf = addrs; |
773 | for (i = 0; i < addrcnt; i++) { | 773 | for (i = 0; i < addrcnt; i++) { |
774 | laddr = (union sctp_addr *)addr_buf; | 774 | laddr = (union sctp_addr *)addr_buf; |
775 | af = sctp_get_af_specific(laddr->v4.sin_family); | 775 | af = sctp_get_af_specific(laddr->v4.sin_family); |
776 | memcpy(&saveaddr, laddr, af->sockaddr_len); | 776 | memcpy(&saveaddr, laddr, af->sockaddr_len); |
777 | saveaddr.v4.sin_port = ntohs(saveaddr.v4.sin_port); | 777 | saveaddr.v4.sin_port = ntohs(saveaddr.v4.sin_port); |
778 | list_for_each(pos1, &bp->address_list) { | 778 | list_for_each(pos1, &bp->address_list) { |
779 | saddr = list_entry(pos1, | 779 | saddr = list_entry(pos1, |
780 | struct sctp_sockaddr_entry, | 780 | struct sctp_sockaddr_entry, |
781 | list); | 781 | list); |
782 | if (sctp_cmp_addr_exact(&saddr->a, &saveaddr)) | 782 | if (sctp_cmp_addr_exact(&saddr->a, &saveaddr)) |
783 | saddr->use_as_src = 0; | 783 | saddr->use_as_src = 0; |
784 | } | 784 | } |
785 | addr_buf += af->sockaddr_len; | 785 | addr_buf += af->sockaddr_len; |
786 | } | 786 | } |
787 | sctp_write_unlock(&asoc->base.addr_lock); | 787 | sctp_write_unlock(&asoc->base.addr_lock); |
788 | sctp_local_bh_enable(); | 788 | sctp_local_bh_enable(); |
789 | 789 | ||
790 | /* Update the route and saddr entries for all the transports | 790 | /* Update the route and saddr entries for all the transports |
791 | * as some of the addresses in the bind address list are | 791 | * as some of the addresses in the bind address list are |
792 | * about to be deleted and cannot be used as source addresses. | 792 | * about to be deleted and cannot be used as source addresses. |
793 | */ | 793 | */ |
794 | list_for_each(pos1, &asoc->peer.transport_addr_list) { | 794 | list_for_each(pos1, &asoc->peer.transport_addr_list) { |
795 | transport = list_entry(pos1, struct sctp_transport, | 795 | transport = list_entry(pos1, struct sctp_transport, |
796 | transports); | 796 | transports); |
797 | dst_release(transport->dst); | 797 | dst_release(transport->dst); |
798 | sctp_transport_route(transport, NULL, | 798 | sctp_transport_route(transport, NULL, |
799 | sctp_sk(asoc->base.sk)); | 799 | sctp_sk(asoc->base.sk)); |
800 | } | 800 | } |
801 | 801 | ||
802 | retval = sctp_send_asconf(asoc, chunk); | 802 | retval = sctp_send_asconf(asoc, chunk); |
803 | } | 803 | } |
804 | out: | 804 | out: |
805 | return retval; | 805 | return retval; |
806 | } | 806 | } |
807 | 807 | ||
808 | /* Helper for tunneling sctp_bindx() requests through sctp_setsockopt() | 808 | /* Helper for tunneling sctp_bindx() requests through sctp_setsockopt() |
809 | * | 809 | * |
810 | * API 8.1 | 810 | * API 8.1 |
811 | * int sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt, | 811 | * int sctp_bindx(int sd, struct sockaddr *addrs, int addrcnt, |
812 | * int flags); | 812 | * int flags); |
813 | * | 813 | * |
814 | * If sd is an IPv4 socket, the addresses passed must be IPv4 addresses. | 814 | * If sd is an IPv4 socket, the addresses passed must be IPv4 addresses. |
815 | * If the sd is an IPv6 socket, the addresses passed can either be IPv4 | 815 | * If the sd is an IPv6 socket, the addresses passed can either be IPv4 |
816 | * or IPv6 addresses. | 816 | * or IPv6 addresses. |
817 | * | 817 | * |
818 | * A single address may be specified as INADDR_ANY or IN6ADDR_ANY, see | 818 | * A single address may be specified as INADDR_ANY or IN6ADDR_ANY, see |
819 | * Section 3.1.2 for this usage. | 819 | * Section 3.1.2 for this usage. |
820 | * | 820 | * |
821 | * addrs is a pointer to an array of one or more socket addresses. Each | 821 | * addrs is a pointer to an array of one or more socket addresses. Each |
822 | * address is contained in its appropriate structure (i.e. struct | 822 | * address is contained in its appropriate structure (i.e. struct |
823 | * sockaddr_in or struct sockaddr_in6) the family of the address type | 823 | * sockaddr_in or struct sockaddr_in6) the family of the address type |
824 | * must be used to distengish the address length (note that this | 824 | * must be used to distengish the address length (note that this |
825 | * representation is termed a "packed array" of addresses). The caller | 825 | * representation is termed a "packed array" of addresses). The caller |
826 | * specifies the number of addresses in the array with addrcnt. | 826 | * specifies the number of addresses in the array with addrcnt. |
827 | * | 827 | * |
828 | * On success, sctp_bindx() returns 0. On failure, sctp_bindx() returns | 828 | * On success, sctp_bindx() returns 0. On failure, sctp_bindx() returns |
829 | * -1, and sets errno to the appropriate error code. | 829 | * -1, and sets errno to the appropriate error code. |
830 | * | 830 | * |
831 | * For SCTP, the port given in each socket address must be the same, or | 831 | * For SCTP, the port given in each socket address must be the same, or |
832 | * sctp_bindx() will fail, setting errno to EINVAL. | 832 | * sctp_bindx() will fail, setting errno to EINVAL. |
833 | * | 833 | * |
834 | * The flags parameter is formed from the bitwise OR of zero or more of | 834 | * The flags parameter is formed from the bitwise OR of zero or more of |
835 | * the following currently defined flags: | 835 | * the following currently defined flags: |
836 | * | 836 | * |
837 | * SCTP_BINDX_ADD_ADDR | 837 | * SCTP_BINDX_ADD_ADDR |
838 | * | 838 | * |
839 | * SCTP_BINDX_REM_ADDR | 839 | * SCTP_BINDX_REM_ADDR |
840 | * | 840 | * |
841 | * SCTP_BINDX_ADD_ADDR directs SCTP to add the given addresses to the | 841 | * SCTP_BINDX_ADD_ADDR directs SCTP to add the given addresses to the |
842 | * association, and SCTP_BINDX_REM_ADDR directs SCTP to remove the given | 842 | * association, and SCTP_BINDX_REM_ADDR directs SCTP to remove the given |
843 | * addresses from the association. The two flags are mutually exclusive; | 843 | * addresses from the association. The two flags are mutually exclusive; |
844 | * if both are given, sctp_bindx() will fail with EINVAL. A caller may | 844 | * if both are given, sctp_bindx() will fail with EINVAL. A caller may |
845 | * not remove all addresses from an association; sctp_bindx() will | 845 | * not remove all addresses from an association; sctp_bindx() will |
846 | * reject such an attempt with EINVAL. | 846 | * reject such an attempt with EINVAL. |
847 | * | 847 | * |
848 | * An application can use sctp_bindx(SCTP_BINDX_ADD_ADDR) to associate | 848 | * An application can use sctp_bindx(SCTP_BINDX_ADD_ADDR) to associate |
849 | * additional addresses with an endpoint after calling bind(). Or use | 849 | * additional addresses with an endpoint after calling bind(). Or use |
850 | * sctp_bindx(SCTP_BINDX_REM_ADDR) to remove some addresses a listening | 850 | * sctp_bindx(SCTP_BINDX_REM_ADDR) to remove some addresses a listening |
851 | * socket is associated with so that no new association accepted will be | 851 | * socket is associated with so that no new association accepted will be |
852 | * associated with those addresses. If the endpoint supports dynamic | 852 | * associated with those addresses. If the endpoint supports dynamic |
853 | * address a SCTP_BINDX_REM_ADDR or SCTP_BINDX_ADD_ADDR may cause a | 853 | * address a SCTP_BINDX_REM_ADDR or SCTP_BINDX_ADD_ADDR may cause a |
854 | * endpoint to send the appropriate message to the peer to change the | 854 | * endpoint to send the appropriate message to the peer to change the |
855 | * peers address lists. | 855 | * peers address lists. |
856 | * | 856 | * |
857 | * Adding and removing addresses from a connected association is | 857 | * Adding and removing addresses from a connected association is |
858 | * optional functionality. Implementations that do not support this | 858 | * optional functionality. Implementations that do not support this |
859 | * functionality should return EOPNOTSUPP. | 859 | * functionality should return EOPNOTSUPP. |
860 | * | 860 | * |
861 | * Basically do nothing but copying the addresses from user to kernel | 861 | * Basically do nothing but copying the addresses from user to kernel |
862 | * land and invoking either sctp_bindx_add() or sctp_bindx_rem() on the sk. | 862 | * land and invoking either sctp_bindx_add() or sctp_bindx_rem() on the sk. |
863 | * This is used for tunneling the sctp_bindx() request through sctp_setsockopt() | 863 | * This is used for tunneling the sctp_bindx() request through sctp_setsockopt() |
864 | * from userspace. | 864 | * from userspace. |
865 | * | 865 | * |
866 | * We don't use copy_from_user() for optimization: we first do the | 866 | * We don't use copy_from_user() for optimization: we first do the |
867 | * sanity checks (buffer size -fast- and access check-healthy | 867 | * sanity checks (buffer size -fast- and access check-healthy |
868 | * pointer); if all of those succeed, then we can alloc the memory | 868 | * pointer); if all of those succeed, then we can alloc the memory |
869 | * (expensive operation) needed to copy the data to kernel. Then we do | 869 | * (expensive operation) needed to copy the data to kernel. Then we do |
870 | * the copying without checking the user space area | 870 | * the copying without checking the user space area |
871 | * (__copy_from_user()). | 871 | * (__copy_from_user()). |
872 | * | 872 | * |
873 | * On exit there is no need to do sockfd_put(), sys_setsockopt() does | 873 | * On exit there is no need to do sockfd_put(), sys_setsockopt() does |
874 | * it. | 874 | * it. |
875 | * | 875 | * |
876 | * sk The sk of the socket | 876 | * sk The sk of the socket |
877 | * addrs The pointer to the addresses in user land | 877 | * addrs The pointer to the addresses in user land |
878 | * addrssize Size of the addrs buffer | 878 | * addrssize Size of the addrs buffer |
879 | * op Operation to perform (add or remove, see the flags of | 879 | * op Operation to perform (add or remove, see the flags of |
880 | * sctp_bindx) | 880 | * sctp_bindx) |
881 | * | 881 | * |
882 | * Returns 0 if ok, <0 errno code on error. | 882 | * Returns 0 if ok, <0 errno code on error. |
883 | */ | 883 | */ |
884 | SCTP_STATIC int sctp_setsockopt_bindx(struct sock* sk, | 884 | SCTP_STATIC int sctp_setsockopt_bindx(struct sock* sk, |
885 | struct sockaddr __user *addrs, | 885 | struct sockaddr __user *addrs, |
886 | int addrs_size, int op) | 886 | int addrs_size, int op) |
887 | { | 887 | { |
888 | struct sockaddr *kaddrs; | 888 | struct sockaddr *kaddrs; |
889 | int err; | 889 | int err; |
890 | int addrcnt = 0; | 890 | int addrcnt = 0; |
891 | int walk_size = 0; | 891 | int walk_size = 0; |
892 | struct sockaddr *sa_addr; | 892 | struct sockaddr *sa_addr; |
893 | void *addr_buf; | 893 | void *addr_buf; |
894 | struct sctp_af *af; | 894 | struct sctp_af *af; |
895 | 895 | ||
896 | SCTP_DEBUG_PRINTK("sctp_setsocktopt_bindx: sk %p addrs %p" | 896 | SCTP_DEBUG_PRINTK("sctp_setsocktopt_bindx: sk %p addrs %p" |
897 | " addrs_size %d opt %d\n", sk, addrs, addrs_size, op); | 897 | " addrs_size %d opt %d\n", sk, addrs, addrs_size, op); |
898 | 898 | ||
899 | if (unlikely(addrs_size <= 0)) | 899 | if (unlikely(addrs_size <= 0)) |
900 | return -EINVAL; | 900 | return -EINVAL; |
901 | 901 | ||
902 | /* Check the user passed a healthy pointer. */ | 902 | /* Check the user passed a healthy pointer. */ |
903 | if (unlikely(!access_ok(VERIFY_READ, addrs, addrs_size))) | 903 | if (unlikely(!access_ok(VERIFY_READ, addrs, addrs_size))) |
904 | return -EFAULT; | 904 | return -EFAULT; |
905 | 905 | ||
906 | /* Alloc space for the address array in kernel memory. */ | 906 | /* Alloc space for the address array in kernel memory. */ |
907 | kaddrs = kmalloc(addrs_size, GFP_KERNEL); | 907 | kaddrs = kmalloc(addrs_size, GFP_KERNEL); |
908 | if (unlikely(!kaddrs)) | 908 | if (unlikely(!kaddrs)) |
909 | return -ENOMEM; | 909 | return -ENOMEM; |
910 | 910 | ||
911 | if (__copy_from_user(kaddrs, addrs, addrs_size)) { | 911 | if (__copy_from_user(kaddrs, addrs, addrs_size)) { |
912 | kfree(kaddrs); | 912 | kfree(kaddrs); |
913 | return -EFAULT; | 913 | return -EFAULT; |
914 | } | 914 | } |
915 | 915 | ||
916 | /* Walk through the addrs buffer and count the number of addresses. */ | 916 | /* Walk through the addrs buffer and count the number of addresses. */ |
917 | addr_buf = kaddrs; | 917 | addr_buf = kaddrs; |
918 | while (walk_size < addrs_size) { | 918 | while (walk_size < addrs_size) { |
919 | sa_addr = (struct sockaddr *)addr_buf; | 919 | sa_addr = (struct sockaddr *)addr_buf; |
920 | af = sctp_get_af_specific(sa_addr->sa_family); | 920 | af = sctp_get_af_specific(sa_addr->sa_family); |
921 | 921 | ||
922 | /* If the address family is not supported or if this address | 922 | /* If the address family is not supported or if this address |
923 | * causes the address buffer to overflow return EINVAL. | 923 | * causes the address buffer to overflow return EINVAL. |
924 | */ | 924 | */ |
925 | if (!af || (walk_size + af->sockaddr_len) > addrs_size) { | 925 | if (!af || (walk_size + af->sockaddr_len) > addrs_size) { |
926 | kfree(kaddrs); | 926 | kfree(kaddrs); |
927 | return -EINVAL; | 927 | return -EINVAL; |
928 | } | 928 | } |
929 | addrcnt++; | 929 | addrcnt++; |
930 | addr_buf += af->sockaddr_len; | 930 | addr_buf += af->sockaddr_len; |
931 | walk_size += af->sockaddr_len; | 931 | walk_size += af->sockaddr_len; |
932 | } | 932 | } |
933 | 933 | ||
934 | /* Do the work. */ | 934 | /* Do the work. */ |
935 | switch (op) { | 935 | switch (op) { |
936 | case SCTP_BINDX_ADD_ADDR: | 936 | case SCTP_BINDX_ADD_ADDR: |
937 | err = sctp_bindx_add(sk, kaddrs, addrcnt); | 937 | err = sctp_bindx_add(sk, kaddrs, addrcnt); |
938 | if (err) | 938 | if (err) |
939 | goto out; | 939 | goto out; |
940 | err = sctp_send_asconf_add_ip(sk, kaddrs, addrcnt); | 940 | err = sctp_send_asconf_add_ip(sk, kaddrs, addrcnt); |
941 | break; | 941 | break; |
942 | 942 | ||
943 | case SCTP_BINDX_REM_ADDR: | 943 | case SCTP_BINDX_REM_ADDR: |
944 | err = sctp_bindx_rem(sk, kaddrs, addrcnt); | 944 | err = sctp_bindx_rem(sk, kaddrs, addrcnt); |
945 | if (err) | 945 | if (err) |
946 | goto out; | 946 | goto out; |
947 | err = sctp_send_asconf_del_ip(sk, kaddrs, addrcnt); | 947 | err = sctp_send_asconf_del_ip(sk, kaddrs, addrcnt); |
948 | break; | 948 | break; |
949 | 949 | ||
950 | default: | 950 | default: |
951 | err = -EINVAL; | 951 | err = -EINVAL; |
952 | break; | 952 | break; |
953 | }; | 953 | }; |
954 | 954 | ||
955 | out: | 955 | out: |
956 | kfree(kaddrs); | 956 | kfree(kaddrs); |
957 | 957 | ||
958 | return err; | 958 | return err; |
959 | } | 959 | } |
960 | 960 | ||
961 | /* __sctp_connect(struct sock* sk, struct sockaddr *kaddrs, int addrs_size) | 961 | /* __sctp_connect(struct sock* sk, struct sockaddr *kaddrs, int addrs_size) |
962 | * | 962 | * |
963 | * Common routine for handling connect() and sctp_connectx(). | 963 | * Common routine for handling connect() and sctp_connectx(). |
964 | * Connect will come in with just a single address. | 964 | * Connect will come in with just a single address. |
965 | */ | 965 | */ |
966 | static int __sctp_connect(struct sock* sk, | 966 | static int __sctp_connect(struct sock* sk, |
967 | struct sockaddr *kaddrs, | 967 | struct sockaddr *kaddrs, |
968 | int addrs_size) | 968 | int addrs_size) |
969 | { | 969 | { |
970 | struct sctp_sock *sp; | 970 | struct sctp_sock *sp; |
971 | struct sctp_endpoint *ep; | 971 | struct sctp_endpoint *ep; |
972 | struct sctp_association *asoc = NULL; | 972 | struct sctp_association *asoc = NULL; |
973 | struct sctp_association *asoc2; | 973 | struct sctp_association *asoc2; |
974 | struct sctp_transport *transport; | 974 | struct sctp_transport *transport; |
975 | union sctp_addr to; | 975 | union sctp_addr to; |
976 | struct sctp_af *af; | 976 | struct sctp_af *af; |
977 | sctp_scope_t scope; | 977 | sctp_scope_t scope; |
978 | long timeo; | 978 | long timeo; |
979 | int err = 0; | 979 | int err = 0; |
980 | int addrcnt = 0; | 980 | int addrcnt = 0; |
981 | int walk_size = 0; | 981 | int walk_size = 0; |
982 | struct sockaddr *sa_addr; | 982 | struct sockaddr *sa_addr; |
983 | void *addr_buf; | 983 | void *addr_buf; |
984 | 984 | ||
985 | sp = sctp_sk(sk); | 985 | sp = sctp_sk(sk); |
986 | ep = sp->ep; | 986 | ep = sp->ep; |
987 | 987 | ||
988 | /* connect() cannot be done on a socket that is already in ESTABLISHED | 988 | /* connect() cannot be done on a socket that is already in ESTABLISHED |
989 | * state - UDP-style peeled off socket or a TCP-style socket that | 989 | * state - UDP-style peeled off socket or a TCP-style socket that |
990 | * is already connected. | 990 | * is already connected. |
991 | * It cannot be done even on a TCP-style listening socket. | 991 | * It cannot be done even on a TCP-style listening socket. |
992 | */ | 992 | */ |
993 | if (sctp_sstate(sk, ESTABLISHED) || | 993 | if (sctp_sstate(sk, ESTABLISHED) || |
994 | (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING))) { | 994 | (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING))) { |
995 | err = -EISCONN; | 995 | err = -EISCONN; |
996 | goto out_free; | 996 | goto out_free; |
997 | } | 997 | } |
998 | 998 | ||
999 | /* Walk through the addrs buffer and count the number of addresses. */ | 999 | /* Walk through the addrs buffer and count the number of addresses. */ |
1000 | addr_buf = kaddrs; | 1000 | addr_buf = kaddrs; |
1001 | while (walk_size < addrs_size) { | 1001 | while (walk_size < addrs_size) { |
1002 | sa_addr = (struct sockaddr *)addr_buf; | 1002 | sa_addr = (struct sockaddr *)addr_buf; |
1003 | af = sctp_get_af_specific(sa_addr->sa_family); | 1003 | af = sctp_get_af_specific(sa_addr->sa_family); |
1004 | 1004 | ||
1005 | /* If the address family is not supported or if this address | 1005 | /* If the address family is not supported or if this address |
1006 | * causes the address buffer to overflow return EINVAL. | 1006 | * causes the address buffer to overflow return EINVAL. |
1007 | */ | 1007 | */ |
1008 | if (!af || (walk_size + af->sockaddr_len) > addrs_size) { | 1008 | if (!af || (walk_size + af->sockaddr_len) > addrs_size) { |
1009 | err = -EINVAL; | 1009 | err = -EINVAL; |
1010 | goto out_free; | 1010 | goto out_free; |
1011 | } | 1011 | } |
1012 | 1012 | ||
1013 | err = sctp_verify_addr(sk, (union sctp_addr *)sa_addr, | 1013 | err = sctp_verify_addr(sk, (union sctp_addr *)sa_addr, |
1014 | af->sockaddr_len); | 1014 | af->sockaddr_len); |
1015 | if (err) | 1015 | if (err) |
1016 | goto out_free; | 1016 | goto out_free; |
1017 | 1017 | ||
1018 | memcpy(&to, sa_addr, af->sockaddr_len); | 1018 | memcpy(&to, sa_addr, af->sockaddr_len); |
1019 | to.v4.sin_port = ntohs(to.v4.sin_port); | 1019 | to.v4.sin_port = ntohs(to.v4.sin_port); |
1020 | 1020 | ||
1021 | /* Check if there already is a matching association on the | 1021 | /* Check if there already is a matching association on the |
1022 | * endpoint (other than the one created here). | 1022 | * endpoint (other than the one created here). |
1023 | */ | 1023 | */ |
1024 | asoc2 = sctp_endpoint_lookup_assoc(ep, &to, &transport); | 1024 | asoc2 = sctp_endpoint_lookup_assoc(ep, &to, &transport); |
1025 | if (asoc2 && asoc2 != asoc) { | 1025 | if (asoc2 && asoc2 != asoc) { |
1026 | if (asoc2->state >= SCTP_STATE_ESTABLISHED) | 1026 | if (asoc2->state >= SCTP_STATE_ESTABLISHED) |
1027 | err = -EISCONN; | 1027 | err = -EISCONN; |
1028 | else | 1028 | else |
1029 | err = -EALREADY; | 1029 | err = -EALREADY; |
1030 | goto out_free; | 1030 | goto out_free; |
1031 | } | 1031 | } |
1032 | 1032 | ||
1033 | /* If we could not find a matching association on the endpoint, | 1033 | /* If we could not find a matching association on the endpoint, |
1034 | * make sure that there is no peeled-off association matching | 1034 | * make sure that there is no peeled-off association matching |
1035 | * the peer address even on another socket. | 1035 | * the peer address even on another socket. |
1036 | */ | 1036 | */ |
1037 | if (sctp_endpoint_is_peeled_off(ep, &to)) { | 1037 | if (sctp_endpoint_is_peeled_off(ep, &to)) { |
1038 | err = -EADDRNOTAVAIL; | 1038 | err = -EADDRNOTAVAIL; |
1039 | goto out_free; | 1039 | goto out_free; |
1040 | } | 1040 | } |
1041 | 1041 | ||
1042 | if (!asoc) { | 1042 | if (!asoc) { |
1043 | /* If a bind() or sctp_bindx() is not called prior to | 1043 | /* If a bind() or sctp_bindx() is not called prior to |
1044 | * an sctp_connectx() call, the system picks an | 1044 | * an sctp_connectx() call, the system picks an |
1045 | * ephemeral port and will choose an address set | 1045 | * ephemeral port and will choose an address set |
1046 | * equivalent to binding with a wildcard address. | 1046 | * equivalent to binding with a wildcard address. |
1047 | */ | 1047 | */ |
1048 | if (!ep->base.bind_addr.port) { | 1048 | if (!ep->base.bind_addr.port) { |
1049 | if (sctp_autobind(sk)) { | 1049 | if (sctp_autobind(sk)) { |
1050 | err = -EAGAIN; | 1050 | err = -EAGAIN; |
1051 | goto out_free; | 1051 | goto out_free; |
1052 | } | 1052 | } |
1053 | } else { | 1053 | } else { |
1054 | /* | 1054 | /* |
1055 | * If an unprivileged user inherits a 1-many | 1055 | * If an unprivileged user inherits a 1-many |
1056 | * style socket with open associations on a | 1056 | * style socket with open associations on a |
1057 | * privileged port, it MAY be permitted to | 1057 | * privileged port, it MAY be permitted to |
1058 | * accept new associations, but it SHOULD NOT | 1058 | * accept new associations, but it SHOULD NOT |
1059 | * be permitted to open new associations. | 1059 | * be permitted to open new associations. |
1060 | */ | 1060 | */ |
1061 | if (ep->base.bind_addr.port < PROT_SOCK && | 1061 | if (ep->base.bind_addr.port < PROT_SOCK && |
1062 | !capable(CAP_NET_BIND_SERVICE)) { | 1062 | !capable(CAP_NET_BIND_SERVICE)) { |
1063 | err = -EACCES; | 1063 | err = -EACCES; |
1064 | goto out_free; | 1064 | goto out_free; |
1065 | } | 1065 | } |
1066 | } | 1066 | } |
1067 | 1067 | ||
1068 | scope = sctp_scope(&to); | 1068 | scope = sctp_scope(&to); |
1069 | asoc = sctp_association_new(ep, sk, scope, GFP_KERNEL); | 1069 | asoc = sctp_association_new(ep, sk, scope, GFP_KERNEL); |
1070 | if (!asoc) { | 1070 | if (!asoc) { |
1071 | err = -ENOMEM; | 1071 | err = -ENOMEM; |
1072 | goto out_free; | 1072 | goto out_free; |
1073 | } | 1073 | } |
1074 | } | 1074 | } |
1075 | 1075 | ||
1076 | /* Prime the peer's transport structures. */ | 1076 | /* Prime the peer's transport structures. */ |
1077 | transport = sctp_assoc_add_peer(asoc, &to, GFP_KERNEL, | 1077 | transport = sctp_assoc_add_peer(asoc, &to, GFP_KERNEL, |
1078 | SCTP_UNKNOWN); | 1078 | SCTP_UNKNOWN); |
1079 | if (!transport) { | 1079 | if (!transport) { |
1080 | err = -ENOMEM; | 1080 | err = -ENOMEM; |
1081 | goto out_free; | 1081 | goto out_free; |
1082 | } | 1082 | } |
1083 | 1083 | ||
1084 | addrcnt++; | 1084 | addrcnt++; |
1085 | addr_buf += af->sockaddr_len; | 1085 | addr_buf += af->sockaddr_len; |
1086 | walk_size += af->sockaddr_len; | 1086 | walk_size += af->sockaddr_len; |
1087 | } | 1087 | } |
1088 | 1088 | ||
1089 | err = sctp_assoc_set_bind_addr_from_ep(asoc, GFP_KERNEL); | 1089 | err = sctp_assoc_set_bind_addr_from_ep(asoc, GFP_KERNEL); |
1090 | if (err < 0) { | 1090 | if (err < 0) { |
1091 | goto out_free; | 1091 | goto out_free; |
1092 | } | 1092 | } |
1093 | 1093 | ||
1094 | err = sctp_primitive_ASSOCIATE(asoc, NULL); | 1094 | err = sctp_primitive_ASSOCIATE(asoc, NULL); |
1095 | if (err < 0) { | 1095 | if (err < 0) { |
1096 | goto out_free; | 1096 | goto out_free; |
1097 | } | 1097 | } |
1098 | 1098 | ||
1099 | /* Initialize sk's dport and daddr for getpeername() */ | 1099 | /* Initialize sk's dport and daddr for getpeername() */ |
1100 | inet_sk(sk)->dport = htons(asoc->peer.port); | 1100 | inet_sk(sk)->dport = htons(asoc->peer.port); |
1101 | af = sctp_get_af_specific(to.sa.sa_family); | 1101 | af = sctp_get_af_specific(to.sa.sa_family); |
1102 | af->to_sk_daddr(&to, sk); | 1102 | af->to_sk_daddr(&to, sk); |
1103 | sk->sk_err = 0; | 1103 | sk->sk_err = 0; |
1104 | 1104 | ||
1105 | timeo = sock_sndtimeo(sk, sk->sk_socket->file->f_flags & O_NONBLOCK); | 1105 | timeo = sock_sndtimeo(sk, sk->sk_socket->file->f_flags & O_NONBLOCK); |
1106 | err = sctp_wait_for_connect(asoc, &timeo); | 1106 | err = sctp_wait_for_connect(asoc, &timeo); |
1107 | 1107 | ||
1108 | /* Don't free association on exit. */ | 1108 | /* Don't free association on exit. */ |
1109 | asoc = NULL; | 1109 | asoc = NULL; |
1110 | 1110 | ||
1111 | out_free: | 1111 | out_free: |
1112 | 1112 | ||
1113 | SCTP_DEBUG_PRINTK("About to exit __sctp_connect() free asoc: %p" | 1113 | SCTP_DEBUG_PRINTK("About to exit __sctp_connect() free asoc: %p" |
1114 | " kaddrs: %p err: %d\n", | 1114 | " kaddrs: %p err: %d\n", |
1115 | asoc, kaddrs, err); | 1115 | asoc, kaddrs, err); |
1116 | if (asoc) | 1116 | if (asoc) |
1117 | sctp_association_free(asoc); | 1117 | sctp_association_free(asoc); |
1118 | return err; | 1118 | return err; |
1119 | } | 1119 | } |
1120 | 1120 | ||
1121 | /* Helper for tunneling sctp_connectx() requests through sctp_setsockopt() | 1121 | /* Helper for tunneling sctp_connectx() requests through sctp_setsockopt() |
1122 | * | 1122 | * |
1123 | * API 8.9 | 1123 | * API 8.9 |
1124 | * int sctp_connectx(int sd, struct sockaddr *addrs, int addrcnt); | 1124 | * int sctp_connectx(int sd, struct sockaddr *addrs, int addrcnt); |
1125 | * | 1125 | * |
1126 | * If sd is an IPv4 socket, the addresses passed must be IPv4 addresses. | 1126 | * If sd is an IPv4 socket, the addresses passed must be IPv4 addresses. |
1127 | * If the sd is an IPv6 socket, the addresses passed can either be IPv4 | 1127 | * If the sd is an IPv6 socket, the addresses passed can either be IPv4 |
1128 | * or IPv6 addresses. | 1128 | * or IPv6 addresses. |
1129 | * | 1129 | * |
1130 | * A single address may be specified as INADDR_ANY or IN6ADDR_ANY, see | 1130 | * A single address may be specified as INADDR_ANY or IN6ADDR_ANY, see |
1131 | * Section 3.1.2 for this usage. | 1131 | * Section 3.1.2 for this usage. |
1132 | * | 1132 | * |
1133 | * addrs is a pointer to an array of one or more socket addresses. Each | 1133 | * addrs is a pointer to an array of one or more socket addresses. Each |
1134 | * address is contained in its appropriate structure (i.e. struct | 1134 | * address is contained in its appropriate structure (i.e. struct |
1135 | * sockaddr_in or struct sockaddr_in6) the family of the address type | 1135 | * sockaddr_in or struct sockaddr_in6) the family of the address type |
1136 | * must be used to distengish the address length (note that this | 1136 | * must be used to distengish the address length (note that this |
1137 | * representation is termed a "packed array" of addresses). The caller | 1137 | * representation is termed a "packed array" of addresses). The caller |
1138 | * specifies the number of addresses in the array with addrcnt. | 1138 | * specifies the number of addresses in the array with addrcnt. |
1139 | * | 1139 | * |
1140 | * On success, sctp_connectx() returns 0. On failure, sctp_connectx() returns | 1140 | * On success, sctp_connectx() returns 0. On failure, sctp_connectx() returns |
1141 | * -1, and sets errno to the appropriate error code. | 1141 | * -1, and sets errno to the appropriate error code. |
1142 | * | 1142 | * |
1143 | * For SCTP, the port given in each socket address must be the same, or | 1143 | * For SCTP, the port given in each socket address must be the same, or |
1144 | * sctp_connectx() will fail, setting errno to EINVAL. | 1144 | * sctp_connectx() will fail, setting errno to EINVAL. |
1145 | * | 1145 | * |
1146 | * An application can use sctp_connectx to initiate an association with | 1146 | * An application can use sctp_connectx to initiate an association with |
1147 | * an endpoint that is multi-homed. Much like sctp_bindx() this call | 1147 | * an endpoint that is multi-homed. Much like sctp_bindx() this call |
1148 | * allows a caller to specify multiple addresses at which a peer can be | 1148 | * allows a caller to specify multiple addresses at which a peer can be |
1149 | * reached. The way the SCTP stack uses the list of addresses to set up | 1149 | * reached. The way the SCTP stack uses the list of addresses to set up |
1150 | * the association is implementation dependant. This function only | 1150 | * the association is implementation dependant. This function only |
1151 | * specifies that the stack will try to make use of all the addresses in | 1151 | * specifies that the stack will try to make use of all the addresses in |
1152 | * the list when needed. | 1152 | * the list when needed. |
1153 | * | 1153 | * |
1154 | * Note that the list of addresses passed in is only used for setting up | 1154 | * Note that the list of addresses passed in is only used for setting up |
1155 | * the association. It does not necessarily equal the set of addresses | 1155 | * the association. It does not necessarily equal the set of addresses |
1156 | * the peer uses for the resulting association. If the caller wants to | 1156 | * the peer uses for the resulting association. If the caller wants to |
1157 | * find out the set of peer addresses, it must use sctp_getpaddrs() to | 1157 | * find out the set of peer addresses, it must use sctp_getpaddrs() to |
1158 | * retrieve them after the association has been set up. | 1158 | * retrieve them after the association has been set up. |
1159 | * | 1159 | * |
1160 | * Basically do nothing but copying the addresses from user to kernel | 1160 | * Basically do nothing but copying the addresses from user to kernel |
1161 | * land and invoking either sctp_connectx(). This is used for tunneling | 1161 | * land and invoking either sctp_connectx(). This is used for tunneling |
1162 | * the sctp_connectx() request through sctp_setsockopt() from userspace. | 1162 | * the sctp_connectx() request through sctp_setsockopt() from userspace. |
1163 | * | 1163 | * |
1164 | * We don't use copy_from_user() for optimization: we first do the | 1164 | * We don't use copy_from_user() for optimization: we first do the |
1165 | * sanity checks (buffer size -fast- and access check-healthy | 1165 | * sanity checks (buffer size -fast- and access check-healthy |
1166 | * pointer); if all of those succeed, then we can alloc the memory | 1166 | * pointer); if all of those succeed, then we can alloc the memory |
1167 | * (expensive operation) needed to copy the data to kernel. Then we do | 1167 | * (expensive operation) needed to copy the data to kernel. Then we do |
1168 | * the copying without checking the user space area | 1168 | * the copying without checking the user space area |
1169 | * (__copy_from_user()). | 1169 | * (__copy_from_user()). |
1170 | * | 1170 | * |
1171 | * On exit there is no need to do sockfd_put(), sys_setsockopt() does | 1171 | * On exit there is no need to do sockfd_put(), sys_setsockopt() does |
1172 | * it. | 1172 | * it. |
1173 | * | 1173 | * |
1174 | * sk The sk of the socket | 1174 | * sk The sk of the socket |
1175 | * addrs The pointer to the addresses in user land | 1175 | * addrs The pointer to the addresses in user land |
1176 | * addrssize Size of the addrs buffer | 1176 | * addrssize Size of the addrs buffer |
1177 | * | 1177 | * |
1178 | * Returns 0 if ok, <0 errno code on error. | 1178 | * Returns 0 if ok, <0 errno code on error. |
1179 | */ | 1179 | */ |
1180 | SCTP_STATIC int sctp_setsockopt_connectx(struct sock* sk, | 1180 | SCTP_STATIC int sctp_setsockopt_connectx(struct sock* sk, |
1181 | struct sockaddr __user *addrs, | 1181 | struct sockaddr __user *addrs, |
1182 | int addrs_size) | 1182 | int addrs_size) |
1183 | { | 1183 | { |
1184 | int err = 0; | 1184 | int err = 0; |
1185 | struct sockaddr *kaddrs; | 1185 | struct sockaddr *kaddrs; |
1186 | 1186 | ||
1187 | SCTP_DEBUG_PRINTK("%s - sk %p addrs %p addrs_size %d\n", | 1187 | SCTP_DEBUG_PRINTK("%s - sk %p addrs %p addrs_size %d\n", |
1188 | __FUNCTION__, sk, addrs, addrs_size); | 1188 | __FUNCTION__, sk, addrs, addrs_size); |
1189 | 1189 | ||
1190 | if (unlikely(addrs_size <= 0)) | 1190 | if (unlikely(addrs_size <= 0)) |
1191 | return -EINVAL; | 1191 | return -EINVAL; |
1192 | 1192 | ||
1193 | /* Check the user passed a healthy pointer. */ | 1193 | /* Check the user passed a healthy pointer. */ |
1194 | if (unlikely(!access_ok(VERIFY_READ, addrs, addrs_size))) | 1194 | if (unlikely(!access_ok(VERIFY_READ, addrs, addrs_size))) |
1195 | return -EFAULT; | 1195 | return -EFAULT; |
1196 | 1196 | ||
1197 | /* Alloc space for the address array in kernel memory. */ | 1197 | /* Alloc space for the address array in kernel memory. */ |
1198 | kaddrs = kmalloc(addrs_size, GFP_KERNEL); | 1198 | kaddrs = kmalloc(addrs_size, GFP_KERNEL); |
1199 | if (unlikely(!kaddrs)) | 1199 | if (unlikely(!kaddrs)) |
1200 | return -ENOMEM; | 1200 | return -ENOMEM; |
1201 | 1201 | ||
1202 | if (__copy_from_user(kaddrs, addrs, addrs_size)) { | 1202 | if (__copy_from_user(kaddrs, addrs, addrs_size)) { |
1203 | err = -EFAULT; | 1203 | err = -EFAULT; |
1204 | } else { | 1204 | } else { |
1205 | err = __sctp_connect(sk, kaddrs, addrs_size); | 1205 | err = __sctp_connect(sk, kaddrs, addrs_size); |
1206 | } | 1206 | } |
1207 | 1207 | ||
1208 | kfree(kaddrs); | 1208 | kfree(kaddrs); |
1209 | return err; | 1209 | return err; |
1210 | } | 1210 | } |
1211 | 1211 | ||
1212 | /* API 3.1.4 close() - UDP Style Syntax | 1212 | /* API 3.1.4 close() - UDP Style Syntax |
1213 | * Applications use close() to perform graceful shutdown (as described in | 1213 | * Applications use close() to perform graceful shutdown (as described in |
1214 | * Section 10.1 of [SCTP]) on ALL the associations currently represented | 1214 | * Section 10.1 of [SCTP]) on ALL the associations currently represented |
1215 | * by a UDP-style socket. | 1215 | * by a UDP-style socket. |
1216 | * | 1216 | * |
1217 | * The syntax is | 1217 | * The syntax is |
1218 | * | 1218 | * |
1219 | * ret = close(int sd); | 1219 | * ret = close(int sd); |
1220 | * | 1220 | * |
1221 | * sd - the socket descriptor of the associations to be closed. | 1221 | * sd - the socket descriptor of the associations to be closed. |
1222 | * | 1222 | * |
1223 | * To gracefully shutdown a specific association represented by the | 1223 | * To gracefully shutdown a specific association represented by the |
1224 | * UDP-style socket, an application should use the sendmsg() call, | 1224 | * UDP-style socket, an application should use the sendmsg() call, |
1225 | * passing no user data, but including the appropriate flag in the | 1225 | * passing no user data, but including the appropriate flag in the |
1226 | * ancillary data (see Section xxxx). | 1226 | * ancillary data (see Section xxxx). |
1227 | * | 1227 | * |
1228 | * If sd in the close() call is a branched-off socket representing only | 1228 | * If sd in the close() call is a branched-off socket representing only |
1229 | * one association, the shutdown is performed on that association only. | 1229 | * one association, the shutdown is performed on that association only. |
1230 | * | 1230 | * |
1231 | * 4.1.6 close() - TCP Style Syntax | 1231 | * 4.1.6 close() - TCP Style Syntax |
1232 | * | 1232 | * |
1233 | * Applications use close() to gracefully close down an association. | 1233 | * Applications use close() to gracefully close down an association. |
1234 | * | 1234 | * |
1235 | * The syntax is: | 1235 | * The syntax is: |
1236 | * | 1236 | * |
1237 | * int close(int sd); | 1237 | * int close(int sd); |
1238 | * | 1238 | * |
1239 | * sd - the socket descriptor of the association to be closed. | 1239 | * sd - the socket descriptor of the association to be closed. |
1240 | * | 1240 | * |
1241 | * After an application calls close() on a socket descriptor, no further | 1241 | * After an application calls close() on a socket descriptor, no further |
1242 | * socket operations will succeed on that descriptor. | 1242 | * socket operations will succeed on that descriptor. |
1243 | * | 1243 | * |
1244 | * API 7.1.4 SO_LINGER | 1244 | * API 7.1.4 SO_LINGER |
1245 | * | 1245 | * |
1246 | * An application using the TCP-style socket can use this option to | 1246 | * An application using the TCP-style socket can use this option to |
1247 | * perform the SCTP ABORT primitive. The linger option structure is: | 1247 | * perform the SCTP ABORT primitive. The linger option structure is: |
1248 | * | 1248 | * |
1249 | * struct linger { | 1249 | * struct linger { |
1250 | * int l_onoff; // option on/off | 1250 | * int l_onoff; // option on/off |
1251 | * int l_linger; // linger time | 1251 | * int l_linger; // linger time |
1252 | * }; | 1252 | * }; |
1253 | * | 1253 | * |
1254 | * To enable the option, set l_onoff to 1. If the l_linger value is set | 1254 | * To enable the option, set l_onoff to 1. If the l_linger value is set |
1255 | * to 0, calling close() is the same as the ABORT primitive. If the | 1255 | * to 0, calling close() is the same as the ABORT primitive. If the |
1256 | * value is set to a negative value, the setsockopt() call will return | 1256 | * value is set to a negative value, the setsockopt() call will return |
1257 | * an error. If the value is set to a positive value linger_time, the | 1257 | * an error. If the value is set to a positive value linger_time, the |
1258 | * close() can be blocked for at most linger_time ms. If the graceful | 1258 | * close() can be blocked for at most linger_time ms. If the graceful |
1259 | * shutdown phase does not finish during this period, close() will | 1259 | * shutdown phase does not finish during this period, close() will |
1260 | * return but the graceful shutdown phase continues in the system. | 1260 | * return but the graceful shutdown phase continues in the system. |
1261 | */ | 1261 | */ |
1262 | SCTP_STATIC void sctp_close(struct sock *sk, long timeout) | 1262 | SCTP_STATIC void sctp_close(struct sock *sk, long timeout) |
1263 | { | 1263 | { |
1264 | struct sctp_endpoint *ep; | 1264 | struct sctp_endpoint *ep; |
1265 | struct sctp_association *asoc; | 1265 | struct sctp_association *asoc; |
1266 | struct list_head *pos, *temp; | 1266 | struct list_head *pos, *temp; |
1267 | 1267 | ||
1268 | SCTP_DEBUG_PRINTK("sctp_close(sk: 0x%p, timeout:%ld)\n", sk, timeout); | 1268 | SCTP_DEBUG_PRINTK("sctp_close(sk: 0x%p, timeout:%ld)\n", sk, timeout); |
1269 | 1269 | ||
1270 | sctp_lock_sock(sk); | 1270 | sctp_lock_sock(sk); |
1271 | sk->sk_shutdown = SHUTDOWN_MASK; | 1271 | sk->sk_shutdown = SHUTDOWN_MASK; |
1272 | 1272 | ||
1273 | ep = sctp_sk(sk)->ep; | 1273 | ep = sctp_sk(sk)->ep; |
1274 | 1274 | ||
1275 | /* Walk all associations on an endpoint. */ | 1275 | /* Walk all associations on an endpoint. */ |
1276 | list_for_each_safe(pos, temp, &ep->asocs) { | 1276 | list_for_each_safe(pos, temp, &ep->asocs) { |
1277 | asoc = list_entry(pos, struct sctp_association, asocs); | 1277 | asoc = list_entry(pos, struct sctp_association, asocs); |
1278 | 1278 | ||
1279 | if (sctp_style(sk, TCP)) { | 1279 | if (sctp_style(sk, TCP)) { |
1280 | /* A closed association can still be in the list if | 1280 | /* A closed association can still be in the list if |
1281 | * it belongs to a TCP-style listening socket that is | 1281 | * it belongs to a TCP-style listening socket that is |
1282 | * not yet accepted. If so, free it. If not, send an | 1282 | * not yet accepted. If so, free it. If not, send an |
1283 | * ABORT or SHUTDOWN based on the linger options. | 1283 | * ABORT or SHUTDOWN based on the linger options. |
1284 | */ | 1284 | */ |
1285 | if (sctp_state(asoc, CLOSED)) { | 1285 | if (sctp_state(asoc, CLOSED)) { |
1286 | sctp_unhash_established(asoc); | 1286 | sctp_unhash_established(asoc); |
1287 | sctp_association_free(asoc); | 1287 | sctp_association_free(asoc); |
1288 | continue; | 1288 | continue; |
1289 | } | 1289 | } |
1290 | } | 1290 | } |
1291 | 1291 | ||
1292 | if (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime) { | 1292 | if (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime) { |
1293 | struct sctp_chunk *chunk; | 1293 | struct sctp_chunk *chunk; |
1294 | 1294 | ||
1295 | chunk = sctp_make_abort_user(asoc, NULL, 0); | 1295 | chunk = sctp_make_abort_user(asoc, NULL, 0); |
1296 | if (chunk) | 1296 | if (chunk) |
1297 | sctp_primitive_ABORT(asoc, chunk); | 1297 | sctp_primitive_ABORT(asoc, chunk); |
1298 | } else | 1298 | } else |
1299 | sctp_primitive_SHUTDOWN(asoc, NULL); | 1299 | sctp_primitive_SHUTDOWN(asoc, NULL); |
1300 | } | 1300 | } |
1301 | 1301 | ||
1302 | /* Clean up any skbs sitting on the receive queue. */ | 1302 | /* Clean up any skbs sitting on the receive queue. */ |
1303 | sctp_queue_purge_ulpevents(&sk->sk_receive_queue); | 1303 | sctp_queue_purge_ulpevents(&sk->sk_receive_queue); |
1304 | sctp_queue_purge_ulpevents(&sctp_sk(sk)->pd_lobby); | 1304 | sctp_queue_purge_ulpevents(&sctp_sk(sk)->pd_lobby); |
1305 | 1305 | ||
1306 | /* On a TCP-style socket, block for at most linger_time if set. */ | 1306 | /* On a TCP-style socket, block for at most linger_time if set. */ |
1307 | if (sctp_style(sk, TCP) && timeout) | 1307 | if (sctp_style(sk, TCP) && timeout) |
1308 | sctp_wait_for_close(sk, timeout); | 1308 | sctp_wait_for_close(sk, timeout); |
1309 | 1309 | ||
1310 | /* This will run the backlog queue. */ | 1310 | /* This will run the backlog queue. */ |
1311 | sctp_release_sock(sk); | 1311 | sctp_release_sock(sk); |
1312 | 1312 | ||
1313 | /* Supposedly, no process has access to the socket, but | 1313 | /* Supposedly, no process has access to the socket, but |
1314 | * the net layers still may. | 1314 | * the net layers still may. |
1315 | */ | 1315 | */ |
1316 | sctp_local_bh_disable(); | 1316 | sctp_local_bh_disable(); |
1317 | sctp_bh_lock_sock(sk); | 1317 | sctp_bh_lock_sock(sk); |
1318 | 1318 | ||
1319 | /* Hold the sock, since sk_common_release() will put sock_put() | 1319 | /* Hold the sock, since sk_common_release() will put sock_put() |
1320 | * and we have just a little more cleanup. | 1320 | * and we have just a little more cleanup. |
1321 | */ | 1321 | */ |
1322 | sock_hold(sk); | 1322 | sock_hold(sk); |
1323 | sk_common_release(sk); | 1323 | sk_common_release(sk); |
1324 | 1324 | ||
1325 | sctp_bh_unlock_sock(sk); | 1325 | sctp_bh_unlock_sock(sk); |
1326 | sctp_local_bh_enable(); | 1326 | sctp_local_bh_enable(); |
1327 | 1327 | ||
1328 | sock_put(sk); | 1328 | sock_put(sk); |
1329 | 1329 | ||
1330 | SCTP_DBG_OBJCNT_DEC(sock); | 1330 | SCTP_DBG_OBJCNT_DEC(sock); |
1331 | } | 1331 | } |
1332 | 1332 | ||
1333 | /* Handle EPIPE error. */ | 1333 | /* Handle EPIPE error. */ |
1334 | static int sctp_error(struct sock *sk, int flags, int err) | 1334 | static int sctp_error(struct sock *sk, int flags, int err) |
1335 | { | 1335 | { |
1336 | if (err == -EPIPE) | 1336 | if (err == -EPIPE) |
1337 | err = sock_error(sk) ? : -EPIPE; | 1337 | err = sock_error(sk) ? : -EPIPE; |
1338 | if (err == -EPIPE && !(flags & MSG_NOSIGNAL)) | 1338 | if (err == -EPIPE && !(flags & MSG_NOSIGNAL)) |
1339 | send_sig(SIGPIPE, current, 0); | 1339 | send_sig(SIGPIPE, current, 0); |
1340 | return err; | 1340 | return err; |
1341 | } | 1341 | } |
1342 | 1342 | ||
1343 | /* API 3.1.3 sendmsg() - UDP Style Syntax | 1343 | /* API 3.1.3 sendmsg() - UDP Style Syntax |
1344 | * | 1344 | * |
1345 | * An application uses sendmsg() and recvmsg() calls to transmit data to | 1345 | * An application uses sendmsg() and recvmsg() calls to transmit data to |
1346 | * and receive data from its peer. | 1346 | * and receive data from its peer. |
1347 | * | 1347 | * |
1348 | * ssize_t sendmsg(int socket, const struct msghdr *message, | 1348 | * ssize_t sendmsg(int socket, const struct msghdr *message, |
1349 | * int flags); | 1349 | * int flags); |
1350 | * | 1350 | * |
1351 | * socket - the socket descriptor of the endpoint. | 1351 | * socket - the socket descriptor of the endpoint. |
1352 | * message - pointer to the msghdr structure which contains a single | 1352 | * message - pointer to the msghdr structure which contains a single |
1353 | * user message and possibly some ancillary data. | 1353 | * user message and possibly some ancillary data. |
1354 | * | 1354 | * |
1355 | * See Section 5 for complete description of the data | 1355 | * See Section 5 for complete description of the data |
1356 | * structures. | 1356 | * structures. |
1357 | * | 1357 | * |
1358 | * flags - flags sent or received with the user message, see Section | 1358 | * flags - flags sent or received with the user message, see Section |
1359 | * 5 for complete description of the flags. | 1359 | * 5 for complete description of the flags. |
1360 | * | 1360 | * |
1361 | * Note: This function could use a rewrite especially when explicit | 1361 | * Note: This function could use a rewrite especially when explicit |
1362 | * connect support comes in. | 1362 | * connect support comes in. |
1363 | */ | 1363 | */ |
1364 | /* BUG: We do not implement the equivalent of sk_stream_wait_memory(). */ | 1364 | /* BUG: We do not implement the equivalent of sk_stream_wait_memory(). */ |
1365 | 1365 | ||
1366 | SCTP_STATIC int sctp_msghdr_parse(const struct msghdr *, sctp_cmsgs_t *); | 1366 | SCTP_STATIC int sctp_msghdr_parse(const struct msghdr *, sctp_cmsgs_t *); |
1367 | 1367 | ||
1368 | SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk, | 1368 | SCTP_STATIC int sctp_sendmsg(struct kiocb *iocb, struct sock *sk, |
1369 | struct msghdr *msg, size_t msg_len) | 1369 | struct msghdr *msg, size_t msg_len) |
1370 | { | 1370 | { |
1371 | struct sctp_sock *sp; | 1371 | struct sctp_sock *sp; |
1372 | struct sctp_endpoint *ep; | 1372 | struct sctp_endpoint *ep; |
1373 | struct sctp_association *new_asoc=NULL, *asoc=NULL; | 1373 | struct sctp_association *new_asoc=NULL, *asoc=NULL; |
1374 | struct sctp_transport *transport, *chunk_tp; | 1374 | struct sctp_transport *transport, *chunk_tp; |
1375 | struct sctp_chunk *chunk; | 1375 | struct sctp_chunk *chunk; |
1376 | union sctp_addr to; | 1376 | union sctp_addr to; |
1377 | struct sockaddr *msg_name = NULL; | 1377 | struct sockaddr *msg_name = NULL; |
1378 | struct sctp_sndrcvinfo default_sinfo = { 0 }; | 1378 | struct sctp_sndrcvinfo default_sinfo = { 0 }; |
1379 | struct sctp_sndrcvinfo *sinfo; | 1379 | struct sctp_sndrcvinfo *sinfo; |
1380 | struct sctp_initmsg *sinit; | 1380 | struct sctp_initmsg *sinit; |
1381 | sctp_assoc_t associd = 0; | 1381 | sctp_assoc_t associd = 0; |
1382 | sctp_cmsgs_t cmsgs = { NULL }; | 1382 | sctp_cmsgs_t cmsgs = { NULL }; |
1383 | int err; | 1383 | int err; |
1384 | sctp_scope_t scope; | 1384 | sctp_scope_t scope; |
1385 | long timeo; | 1385 | long timeo; |
1386 | __u16 sinfo_flags = 0; | 1386 | __u16 sinfo_flags = 0; |
1387 | struct sctp_datamsg *datamsg; | 1387 | struct sctp_datamsg *datamsg; |
1388 | struct list_head *pos; | 1388 | struct list_head *pos; |
1389 | int msg_flags = msg->msg_flags; | 1389 | int msg_flags = msg->msg_flags; |
1390 | 1390 | ||
1391 | SCTP_DEBUG_PRINTK("sctp_sendmsg(sk: %p, msg: %p, msg_len: %zu)\n", | 1391 | SCTP_DEBUG_PRINTK("sctp_sendmsg(sk: %p, msg: %p, msg_len: %zu)\n", |
1392 | sk, msg, msg_len); | 1392 | sk, msg, msg_len); |
1393 | 1393 | ||
1394 | err = 0; | 1394 | err = 0; |
1395 | sp = sctp_sk(sk); | 1395 | sp = sctp_sk(sk); |
1396 | ep = sp->ep; | 1396 | ep = sp->ep; |
1397 | 1397 | ||
1398 | SCTP_DEBUG_PRINTK("Using endpoint: %p.\n", ep); | 1398 | SCTP_DEBUG_PRINTK("Using endpoint: %p.\n", ep); |
1399 | 1399 | ||
1400 | /* We cannot send a message over a TCP-style listening socket. */ | 1400 | /* We cannot send a message over a TCP-style listening socket. */ |
1401 | if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING)) { | 1401 | if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING)) { |
1402 | err = -EPIPE; | 1402 | err = -EPIPE; |
1403 | goto out_nounlock; | 1403 | goto out_nounlock; |
1404 | } | 1404 | } |
1405 | 1405 | ||
1406 | /* Parse out the SCTP CMSGs. */ | 1406 | /* Parse out the SCTP CMSGs. */ |
1407 | err = sctp_msghdr_parse(msg, &cmsgs); | 1407 | err = sctp_msghdr_parse(msg, &cmsgs); |
1408 | 1408 | ||
1409 | if (err) { | 1409 | if (err) { |
1410 | SCTP_DEBUG_PRINTK("msghdr parse err = %x\n", err); | 1410 | SCTP_DEBUG_PRINTK("msghdr parse err = %x\n", err); |
1411 | goto out_nounlock; | 1411 | goto out_nounlock; |
1412 | } | 1412 | } |
1413 | 1413 | ||
1414 | /* Fetch the destination address for this packet. This | 1414 | /* Fetch the destination address for this packet. This |
1415 | * address only selects the association--it is not necessarily | 1415 | * address only selects the association--it is not necessarily |
1416 | * the address we will send to. | 1416 | * the address we will send to. |
1417 | * For a peeled-off socket, msg_name is ignored. | 1417 | * For a peeled-off socket, msg_name is ignored. |
1418 | */ | 1418 | */ |
1419 | if (!sctp_style(sk, UDP_HIGH_BANDWIDTH) && msg->msg_name) { | 1419 | if (!sctp_style(sk, UDP_HIGH_BANDWIDTH) && msg->msg_name) { |
1420 | int msg_namelen = msg->msg_namelen; | 1420 | int msg_namelen = msg->msg_namelen; |
1421 | 1421 | ||
1422 | err = sctp_verify_addr(sk, (union sctp_addr *)msg->msg_name, | 1422 | err = sctp_verify_addr(sk, (union sctp_addr *)msg->msg_name, |
1423 | msg_namelen); | 1423 | msg_namelen); |
1424 | if (err) | 1424 | if (err) |
1425 | return err; | 1425 | return err; |
1426 | 1426 | ||
1427 | if (msg_namelen > sizeof(to)) | 1427 | if (msg_namelen > sizeof(to)) |
1428 | msg_namelen = sizeof(to); | 1428 | msg_namelen = sizeof(to); |
1429 | memcpy(&to, msg->msg_name, msg_namelen); | 1429 | memcpy(&to, msg->msg_name, msg_namelen); |
1430 | SCTP_DEBUG_PRINTK("Just memcpy'd. msg_name is " | 1430 | SCTP_DEBUG_PRINTK("Just memcpy'd. msg_name is " |
1431 | "0x%x:%u.\n", | 1431 | "0x%x:%u.\n", |
1432 | to.v4.sin_addr.s_addr, to.v4.sin_port); | 1432 | to.v4.sin_addr.s_addr, to.v4.sin_port); |
1433 | 1433 | ||
1434 | to.v4.sin_port = ntohs(to.v4.sin_port); | 1434 | to.v4.sin_port = ntohs(to.v4.sin_port); |
1435 | msg_name = msg->msg_name; | 1435 | msg_name = msg->msg_name; |
1436 | } | 1436 | } |
1437 | 1437 | ||
1438 | sinfo = cmsgs.info; | 1438 | sinfo = cmsgs.info; |
1439 | sinit = cmsgs.init; | 1439 | sinit = cmsgs.init; |
1440 | 1440 | ||
1441 | /* Did the user specify SNDRCVINFO? */ | 1441 | /* Did the user specify SNDRCVINFO? */ |
1442 | if (sinfo) { | 1442 | if (sinfo) { |
1443 | sinfo_flags = sinfo->sinfo_flags; | 1443 | sinfo_flags = sinfo->sinfo_flags; |
1444 | associd = sinfo->sinfo_assoc_id; | 1444 | associd = sinfo->sinfo_assoc_id; |
1445 | } | 1445 | } |
1446 | 1446 | ||
1447 | SCTP_DEBUG_PRINTK("msg_len: %zu, sinfo_flags: 0x%x\n", | 1447 | SCTP_DEBUG_PRINTK("msg_len: %zu, sinfo_flags: 0x%x\n", |
1448 | msg_len, sinfo_flags); | 1448 | msg_len, sinfo_flags); |
1449 | 1449 | ||
1450 | /* SCTP_EOF or SCTP_ABORT cannot be set on a TCP-style socket. */ | 1450 | /* SCTP_EOF or SCTP_ABORT cannot be set on a TCP-style socket. */ |
1451 | if (sctp_style(sk, TCP) && (sinfo_flags & (SCTP_EOF | SCTP_ABORT))) { | 1451 | if (sctp_style(sk, TCP) && (sinfo_flags & (SCTP_EOF | SCTP_ABORT))) { |
1452 | err = -EINVAL; | 1452 | err = -EINVAL; |
1453 | goto out_nounlock; | 1453 | goto out_nounlock; |
1454 | } | 1454 | } |
1455 | 1455 | ||
1456 | /* If SCTP_EOF is set, no data can be sent. Disallow sending zero | 1456 | /* If SCTP_EOF is set, no data can be sent. Disallow sending zero |
1457 | * length messages when SCTP_EOF|SCTP_ABORT is not set. | 1457 | * length messages when SCTP_EOF|SCTP_ABORT is not set. |
1458 | * If SCTP_ABORT is set, the message length could be non zero with | 1458 | * If SCTP_ABORT is set, the message length could be non zero with |
1459 | * the msg_iov set to the user abort reason. | 1459 | * the msg_iov set to the user abort reason. |
1460 | */ | 1460 | */ |
1461 | if (((sinfo_flags & SCTP_EOF) && (msg_len > 0)) || | 1461 | if (((sinfo_flags & SCTP_EOF) && (msg_len > 0)) || |
1462 | (!(sinfo_flags & (SCTP_EOF|SCTP_ABORT)) && (msg_len == 0))) { | 1462 | (!(sinfo_flags & (SCTP_EOF|SCTP_ABORT)) && (msg_len == 0))) { |
1463 | err = -EINVAL; | 1463 | err = -EINVAL; |
1464 | goto out_nounlock; | 1464 | goto out_nounlock; |
1465 | } | 1465 | } |
1466 | 1466 | ||
1467 | /* If SCTP_ADDR_OVER is set, there must be an address | 1467 | /* If SCTP_ADDR_OVER is set, there must be an address |
1468 | * specified in msg_name. | 1468 | * specified in msg_name. |
1469 | */ | 1469 | */ |
1470 | if ((sinfo_flags & SCTP_ADDR_OVER) && (!msg->msg_name)) { | 1470 | if ((sinfo_flags & SCTP_ADDR_OVER) && (!msg->msg_name)) { |
1471 | err = -EINVAL; | 1471 | err = -EINVAL; |
1472 | goto out_nounlock; | 1472 | goto out_nounlock; |
1473 | } | 1473 | } |
1474 | 1474 | ||
1475 | transport = NULL; | 1475 | transport = NULL; |
1476 | 1476 | ||
1477 | SCTP_DEBUG_PRINTK("About to look up association.\n"); | 1477 | SCTP_DEBUG_PRINTK("About to look up association.\n"); |
1478 | 1478 | ||
1479 | sctp_lock_sock(sk); | 1479 | sctp_lock_sock(sk); |
1480 | 1480 | ||
1481 | /* If a msg_name has been specified, assume this is to be used. */ | 1481 | /* If a msg_name has been specified, assume this is to be used. */ |
1482 | if (msg_name) { | 1482 | if (msg_name) { |
1483 | /* Look for a matching association on the endpoint. */ | 1483 | /* Look for a matching association on the endpoint. */ |
1484 | asoc = sctp_endpoint_lookup_assoc(ep, &to, &transport); | 1484 | asoc = sctp_endpoint_lookup_assoc(ep, &to, &transport); |
1485 | if (!asoc) { | 1485 | if (!asoc) { |
1486 | /* If we could not find a matching association on the | 1486 | /* If we could not find a matching association on the |
1487 | * endpoint, make sure that it is not a TCP-style | 1487 | * endpoint, make sure that it is not a TCP-style |
1488 | * socket that already has an association or there is | 1488 | * socket that already has an association or there is |
1489 | * no peeled-off association on another socket. | 1489 | * no peeled-off association on another socket. |
1490 | */ | 1490 | */ |
1491 | if ((sctp_style(sk, TCP) && | 1491 | if ((sctp_style(sk, TCP) && |
1492 | sctp_sstate(sk, ESTABLISHED)) || | 1492 | sctp_sstate(sk, ESTABLISHED)) || |
1493 | sctp_endpoint_is_peeled_off(ep, &to)) { | 1493 | sctp_endpoint_is_peeled_off(ep, &to)) { |
1494 | err = -EADDRNOTAVAIL; | 1494 | err = -EADDRNOTAVAIL; |
1495 | goto out_unlock; | 1495 | goto out_unlock; |
1496 | } | 1496 | } |
1497 | } | 1497 | } |
1498 | } else { | 1498 | } else { |
1499 | asoc = sctp_id2assoc(sk, associd); | 1499 | asoc = sctp_id2assoc(sk, associd); |
1500 | if (!asoc) { | 1500 | if (!asoc) { |
1501 | err = -EPIPE; | 1501 | err = -EPIPE; |
1502 | goto out_unlock; | 1502 | goto out_unlock; |
1503 | } | 1503 | } |
1504 | } | 1504 | } |
1505 | 1505 | ||
1506 | if (asoc) { | 1506 | if (asoc) { |
1507 | SCTP_DEBUG_PRINTK("Just looked up association: %p.\n", asoc); | 1507 | SCTP_DEBUG_PRINTK("Just looked up association: %p.\n", asoc); |
1508 | 1508 | ||
1509 | /* We cannot send a message on a TCP-style SCTP_SS_ESTABLISHED | 1509 | /* We cannot send a message on a TCP-style SCTP_SS_ESTABLISHED |
1510 | * socket that has an association in CLOSED state. This can | 1510 | * socket that has an association in CLOSED state. This can |
1511 | * happen when an accepted socket has an association that is | 1511 | * happen when an accepted socket has an association that is |
1512 | * already CLOSED. | 1512 | * already CLOSED. |
1513 | */ | 1513 | */ |
1514 | if (sctp_state(asoc, CLOSED) && sctp_style(sk, TCP)) { | 1514 | if (sctp_state(asoc, CLOSED) && sctp_style(sk, TCP)) { |
1515 | err = -EPIPE; | 1515 | err = -EPIPE; |
1516 | goto out_unlock; | 1516 | goto out_unlock; |
1517 | } | 1517 | } |
1518 | 1518 | ||
1519 | if (sinfo_flags & SCTP_EOF) { | 1519 | if (sinfo_flags & SCTP_EOF) { |
1520 | SCTP_DEBUG_PRINTK("Shutting down association: %p\n", | 1520 | SCTP_DEBUG_PRINTK("Shutting down association: %p\n", |
1521 | asoc); | 1521 | asoc); |
1522 | sctp_primitive_SHUTDOWN(asoc, NULL); | 1522 | sctp_primitive_SHUTDOWN(asoc, NULL); |
1523 | err = 0; | 1523 | err = 0; |
1524 | goto out_unlock; | 1524 | goto out_unlock; |
1525 | } | 1525 | } |
1526 | if (sinfo_flags & SCTP_ABORT) { | 1526 | if (sinfo_flags & SCTP_ABORT) { |
1527 | struct sctp_chunk *chunk; | 1527 | struct sctp_chunk *chunk; |
1528 | 1528 | ||
1529 | chunk = sctp_make_abort_user(asoc, msg, msg_len); | 1529 | chunk = sctp_make_abort_user(asoc, msg, msg_len); |
1530 | if (!chunk) { | 1530 | if (!chunk) { |
1531 | err = -ENOMEM; | 1531 | err = -ENOMEM; |
1532 | goto out_unlock; | 1532 | goto out_unlock; |
1533 | } | 1533 | } |
1534 | 1534 | ||
1535 | SCTP_DEBUG_PRINTK("Aborting association: %p\n", asoc); | 1535 | SCTP_DEBUG_PRINTK("Aborting association: %p\n", asoc); |
1536 | sctp_primitive_ABORT(asoc, chunk); | 1536 | sctp_primitive_ABORT(asoc, chunk); |
1537 | err = 0; | 1537 | err = 0; |
1538 | goto out_unlock; | 1538 | goto out_unlock; |
1539 | } | 1539 | } |
1540 | } | 1540 | } |
1541 | 1541 | ||
1542 | /* Do we need to create the association? */ | 1542 | /* Do we need to create the association? */ |
1543 | if (!asoc) { | 1543 | if (!asoc) { |
1544 | SCTP_DEBUG_PRINTK("There is no association yet.\n"); | 1544 | SCTP_DEBUG_PRINTK("There is no association yet.\n"); |
1545 | 1545 | ||
1546 | if (sinfo_flags & (SCTP_EOF | SCTP_ABORT)) { | 1546 | if (sinfo_flags & (SCTP_EOF | SCTP_ABORT)) { |
1547 | err = -EINVAL; | 1547 | err = -EINVAL; |
1548 | goto out_unlock; | 1548 | goto out_unlock; |
1549 | } | 1549 | } |
1550 | 1550 | ||
1551 | /* Check for invalid stream against the stream counts, | 1551 | /* Check for invalid stream against the stream counts, |
1552 | * either the default or the user specified stream counts. | 1552 | * either the default or the user specified stream counts. |
1553 | */ | 1553 | */ |
1554 | if (sinfo) { | 1554 | if (sinfo) { |
1555 | if (!sinit || (sinit && !sinit->sinit_num_ostreams)) { | 1555 | if (!sinit || (sinit && !sinit->sinit_num_ostreams)) { |
1556 | /* Check against the defaults. */ | 1556 | /* Check against the defaults. */ |
1557 | if (sinfo->sinfo_stream >= | 1557 | if (sinfo->sinfo_stream >= |
1558 | sp->initmsg.sinit_num_ostreams) { | 1558 | sp->initmsg.sinit_num_ostreams) { |
1559 | err = -EINVAL; | 1559 | err = -EINVAL; |
1560 | goto out_unlock; | 1560 | goto out_unlock; |
1561 | } | 1561 | } |
1562 | } else { | 1562 | } else { |
1563 | /* Check against the requested. */ | 1563 | /* Check against the requested. */ |
1564 | if (sinfo->sinfo_stream >= | 1564 | if (sinfo->sinfo_stream >= |
1565 | sinit->sinit_num_ostreams) { | 1565 | sinit->sinit_num_ostreams) { |
1566 | err = -EINVAL; | 1566 | err = -EINVAL; |
1567 | goto out_unlock; | 1567 | goto out_unlock; |
1568 | } | 1568 | } |
1569 | } | 1569 | } |
1570 | } | 1570 | } |
1571 | 1571 | ||
1572 | /* | 1572 | /* |
1573 | * API 3.1.2 bind() - UDP Style Syntax | 1573 | * API 3.1.2 bind() - UDP Style Syntax |
1574 | * If a bind() or sctp_bindx() is not called prior to a | 1574 | * If a bind() or sctp_bindx() is not called prior to a |
1575 | * sendmsg() call that initiates a new association, the | 1575 | * sendmsg() call that initiates a new association, the |
1576 | * system picks an ephemeral port and will choose an address | 1576 | * system picks an ephemeral port and will choose an address |
1577 | * set equivalent to binding with a wildcard address. | 1577 | * set equivalent to binding with a wildcard address. |
1578 | */ | 1578 | */ |
1579 | if (!ep->base.bind_addr.port) { | 1579 | if (!ep->base.bind_addr.port) { |
1580 | if (sctp_autobind(sk)) { | 1580 | if (sctp_autobind(sk)) { |
1581 | err = -EAGAIN; | 1581 | err = -EAGAIN; |
1582 | goto out_unlock; | 1582 | goto out_unlock; |
1583 | } | 1583 | } |
1584 | } else { | 1584 | } else { |
1585 | /* | 1585 | /* |
1586 | * If an unprivileged user inherits a one-to-many | 1586 | * If an unprivileged user inherits a one-to-many |
1587 | * style socket with open associations on a privileged | 1587 | * style socket with open associations on a privileged |
1588 | * port, it MAY be permitted to accept new associations, | 1588 | * port, it MAY be permitted to accept new associations, |
1589 | * but it SHOULD NOT be permitted to open new | 1589 | * but it SHOULD NOT be permitted to open new |
1590 | * associations. | 1590 | * associations. |
1591 | */ | 1591 | */ |
1592 | if (ep->base.bind_addr.port < PROT_SOCK && | 1592 | if (ep->base.bind_addr.port < PROT_SOCK && |
1593 | !capable(CAP_NET_BIND_SERVICE)) { | 1593 | !capable(CAP_NET_BIND_SERVICE)) { |
1594 | err = -EACCES; | 1594 | err = -EACCES; |
1595 | goto out_unlock; | 1595 | goto out_unlock; |
1596 | } | 1596 | } |
1597 | } | 1597 | } |
1598 | 1598 | ||
1599 | scope = sctp_scope(&to); | 1599 | scope = sctp_scope(&to); |
1600 | new_asoc = sctp_association_new(ep, sk, scope, GFP_KERNEL); | 1600 | new_asoc = sctp_association_new(ep, sk, scope, GFP_KERNEL); |
1601 | if (!new_asoc) { | 1601 | if (!new_asoc) { |
1602 | err = -ENOMEM; | 1602 | err = -ENOMEM; |
1603 | goto out_unlock; | 1603 | goto out_unlock; |
1604 | } | 1604 | } |
1605 | asoc = new_asoc; | 1605 | asoc = new_asoc; |
1606 | 1606 | ||
1607 | /* If the SCTP_INIT ancillary data is specified, set all | 1607 | /* If the SCTP_INIT ancillary data is specified, set all |
1608 | * the association init values accordingly. | 1608 | * the association init values accordingly. |
1609 | */ | 1609 | */ |
1610 | if (sinit) { | 1610 | if (sinit) { |
1611 | if (sinit->sinit_num_ostreams) { | 1611 | if (sinit->sinit_num_ostreams) { |
1612 | asoc->c.sinit_num_ostreams = | 1612 | asoc->c.sinit_num_ostreams = |
1613 | sinit->sinit_num_ostreams; | 1613 | sinit->sinit_num_ostreams; |
1614 | } | 1614 | } |
1615 | if (sinit->sinit_max_instreams) { | 1615 | if (sinit->sinit_max_instreams) { |
1616 | asoc->c.sinit_max_instreams = | 1616 | asoc->c.sinit_max_instreams = |
1617 | sinit->sinit_max_instreams; | 1617 | sinit->sinit_max_instreams; |
1618 | } | 1618 | } |
1619 | if (sinit->sinit_max_attempts) { | 1619 | if (sinit->sinit_max_attempts) { |
1620 | asoc->max_init_attempts | 1620 | asoc->max_init_attempts |
1621 | = sinit->sinit_max_attempts; | 1621 | = sinit->sinit_max_attempts; |
1622 | } | 1622 | } |
1623 | if (sinit->sinit_max_init_timeo) { | 1623 | if (sinit->sinit_max_init_timeo) { |
1624 | asoc->max_init_timeo = | 1624 | asoc->max_init_timeo = |
1625 | msecs_to_jiffies(sinit->sinit_max_init_timeo); | 1625 | msecs_to_jiffies(sinit->sinit_max_init_timeo); |
1626 | } | 1626 | } |
1627 | } | 1627 | } |
1628 | 1628 | ||
1629 | /* Prime the peer's transport structures. */ | 1629 | /* Prime the peer's transport structures. */ |
1630 | transport = sctp_assoc_add_peer(asoc, &to, GFP_KERNEL, SCTP_UNKNOWN); | 1630 | transport = sctp_assoc_add_peer(asoc, &to, GFP_KERNEL, SCTP_UNKNOWN); |
1631 | if (!transport) { | 1631 | if (!transport) { |
1632 | err = -ENOMEM; | 1632 | err = -ENOMEM; |
1633 | goto out_free; | 1633 | goto out_free; |
1634 | } | 1634 | } |
1635 | err = sctp_assoc_set_bind_addr_from_ep(asoc, GFP_KERNEL); | 1635 | err = sctp_assoc_set_bind_addr_from_ep(asoc, GFP_KERNEL); |
1636 | if (err < 0) { | 1636 | if (err < 0) { |
1637 | err = -ENOMEM; | 1637 | err = -ENOMEM; |
1638 | goto out_free; | 1638 | goto out_free; |
1639 | } | 1639 | } |
1640 | } | 1640 | } |
1641 | 1641 | ||
1642 | /* ASSERT: we have a valid association at this point. */ | 1642 | /* ASSERT: we have a valid association at this point. */ |
1643 | SCTP_DEBUG_PRINTK("We have a valid association.\n"); | 1643 | SCTP_DEBUG_PRINTK("We have a valid association.\n"); |
1644 | 1644 | ||
1645 | if (!sinfo) { | 1645 | if (!sinfo) { |
1646 | /* If the user didn't specify SNDRCVINFO, make up one with | 1646 | /* If the user didn't specify SNDRCVINFO, make up one with |
1647 | * some defaults. | 1647 | * some defaults. |
1648 | */ | 1648 | */ |
1649 | default_sinfo.sinfo_stream = asoc->default_stream; | 1649 | default_sinfo.sinfo_stream = asoc->default_stream; |
1650 | default_sinfo.sinfo_flags = asoc->default_flags; | 1650 | default_sinfo.sinfo_flags = asoc->default_flags; |
1651 | default_sinfo.sinfo_ppid = asoc->default_ppid; | 1651 | default_sinfo.sinfo_ppid = asoc->default_ppid; |
1652 | default_sinfo.sinfo_context = asoc->default_context; | 1652 | default_sinfo.sinfo_context = asoc->default_context; |
1653 | default_sinfo.sinfo_timetolive = asoc->default_timetolive; | 1653 | default_sinfo.sinfo_timetolive = asoc->default_timetolive; |
1654 | default_sinfo.sinfo_assoc_id = sctp_assoc2id(asoc); | 1654 | default_sinfo.sinfo_assoc_id = sctp_assoc2id(asoc); |
1655 | sinfo = &default_sinfo; | 1655 | sinfo = &default_sinfo; |
1656 | } | 1656 | } |
1657 | 1657 | ||
1658 | /* API 7.1.7, the sndbuf size per association bounds the | 1658 | /* API 7.1.7, the sndbuf size per association bounds the |
1659 | * maximum size of data that can be sent in a single send call. | 1659 | * maximum size of data that can be sent in a single send call. |
1660 | */ | 1660 | */ |
1661 | if (msg_len > sk->sk_sndbuf) { | 1661 | if (msg_len > sk->sk_sndbuf) { |
1662 | err = -EMSGSIZE; | 1662 | err = -EMSGSIZE; |
1663 | goto out_free; | 1663 | goto out_free; |
1664 | } | 1664 | } |
1665 | 1665 | ||
1666 | /* If fragmentation is disabled and the message length exceeds the | 1666 | /* If fragmentation is disabled and the message length exceeds the |
1667 | * association fragmentation point, return EMSGSIZE. The I-D | 1667 | * association fragmentation point, return EMSGSIZE. The I-D |
1668 | * does not specify what this error is, but this looks like | 1668 | * does not specify what this error is, but this looks like |
1669 | * a great fit. | 1669 | * a great fit. |
1670 | */ | 1670 | */ |
1671 | if (sctp_sk(sk)->disable_fragments && (msg_len > asoc->frag_point)) { | 1671 | if (sctp_sk(sk)->disable_fragments && (msg_len > asoc->frag_point)) { |
1672 | err = -EMSGSIZE; | 1672 | err = -EMSGSIZE; |
1673 | goto out_free; | 1673 | goto out_free; |
1674 | } | 1674 | } |
1675 | 1675 | ||
1676 | if (sinfo) { | 1676 | if (sinfo) { |
1677 | /* Check for invalid stream. */ | 1677 | /* Check for invalid stream. */ |
1678 | if (sinfo->sinfo_stream >= asoc->c.sinit_num_ostreams) { | 1678 | if (sinfo->sinfo_stream >= asoc->c.sinit_num_ostreams) { |
1679 | err = -EINVAL; | 1679 | err = -EINVAL; |
1680 | goto out_free; | 1680 | goto out_free; |
1681 | } | 1681 | } |
1682 | } | 1682 | } |
1683 | 1683 | ||
1684 | timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); | 1684 | timeo = sock_sndtimeo(sk, msg->msg_flags & MSG_DONTWAIT); |
1685 | if (!sctp_wspace(asoc)) { | 1685 | if (!sctp_wspace(asoc)) { |
1686 | err = sctp_wait_for_sndbuf(asoc, &timeo, msg_len); | 1686 | err = sctp_wait_for_sndbuf(asoc, &timeo, msg_len); |
1687 | if (err) | 1687 | if (err) |
1688 | goto out_free; | 1688 | goto out_free; |
1689 | } | 1689 | } |
1690 | 1690 | ||
1691 | /* If an address is passed with the sendto/sendmsg call, it is used | 1691 | /* If an address is passed with the sendto/sendmsg call, it is used |
1692 | * to override the primary destination address in the TCP model, or | 1692 | * to override the primary destination address in the TCP model, or |
1693 | * when SCTP_ADDR_OVER flag is set in the UDP model. | 1693 | * when SCTP_ADDR_OVER flag is set in the UDP model. |
1694 | */ | 1694 | */ |
1695 | if ((sctp_style(sk, TCP) && msg_name) || | 1695 | if ((sctp_style(sk, TCP) && msg_name) || |
1696 | (sinfo_flags & SCTP_ADDR_OVER)) { | 1696 | (sinfo_flags & SCTP_ADDR_OVER)) { |
1697 | chunk_tp = sctp_assoc_lookup_paddr(asoc, &to); | 1697 | chunk_tp = sctp_assoc_lookup_paddr(asoc, &to); |
1698 | if (!chunk_tp) { | 1698 | if (!chunk_tp) { |
1699 | err = -EINVAL; | 1699 | err = -EINVAL; |
1700 | goto out_free; | 1700 | goto out_free; |
1701 | } | 1701 | } |
1702 | } else | 1702 | } else |
1703 | chunk_tp = NULL; | 1703 | chunk_tp = NULL; |
1704 | 1704 | ||
1705 | /* Auto-connect, if we aren't connected already. */ | 1705 | /* Auto-connect, if we aren't connected already. */ |
1706 | if (sctp_state(asoc, CLOSED)) { | 1706 | if (sctp_state(asoc, CLOSED)) { |
1707 | err = sctp_primitive_ASSOCIATE(asoc, NULL); | 1707 | err = sctp_primitive_ASSOCIATE(asoc, NULL); |
1708 | if (err < 0) | 1708 | if (err < 0) |
1709 | goto out_free; | 1709 | goto out_free; |
1710 | SCTP_DEBUG_PRINTK("We associated primitively.\n"); | 1710 | SCTP_DEBUG_PRINTK("We associated primitively.\n"); |
1711 | } | 1711 | } |
1712 | 1712 | ||
1713 | /* Break the message into multiple chunks of maximum size. */ | 1713 | /* Break the message into multiple chunks of maximum size. */ |
1714 | datamsg = sctp_datamsg_from_user(asoc, sinfo, msg, msg_len); | 1714 | datamsg = sctp_datamsg_from_user(asoc, sinfo, msg, msg_len); |
1715 | if (!datamsg) { | 1715 | if (!datamsg) { |
1716 | err = -ENOMEM; | 1716 | err = -ENOMEM; |
1717 | goto out_free; | 1717 | goto out_free; |
1718 | } | 1718 | } |
1719 | 1719 | ||
1720 | /* Now send the (possibly) fragmented message. */ | 1720 | /* Now send the (possibly) fragmented message. */ |
1721 | list_for_each(pos, &datamsg->chunks) { | 1721 | list_for_each(pos, &datamsg->chunks) { |
1722 | chunk = list_entry(pos, struct sctp_chunk, frag_list); | 1722 | chunk = list_entry(pos, struct sctp_chunk, frag_list); |
1723 | sctp_datamsg_track(chunk); | 1723 | sctp_datamsg_track(chunk); |
1724 | 1724 | ||
1725 | /* Do accounting for the write space. */ | 1725 | /* Do accounting for the write space. */ |
1726 | sctp_set_owner_w(chunk); | 1726 | sctp_set_owner_w(chunk); |
1727 | 1727 | ||
1728 | chunk->transport = chunk_tp; | 1728 | chunk->transport = chunk_tp; |
1729 | 1729 | ||
1730 | /* Send it to the lower layers. Note: all chunks | 1730 | /* Send it to the lower layers. Note: all chunks |
1731 | * must either fail or succeed. The lower layer | 1731 | * must either fail or succeed. The lower layer |
1732 | * works that way today. Keep it that way or this | 1732 | * works that way today. Keep it that way or this |
1733 | * breaks. | 1733 | * breaks. |
1734 | */ | 1734 | */ |
1735 | err = sctp_primitive_SEND(asoc, chunk); | 1735 | err = sctp_primitive_SEND(asoc, chunk); |
1736 | /* Did the lower layer accept the chunk? */ | 1736 | /* Did the lower layer accept the chunk? */ |
1737 | if (err) | 1737 | if (err) |
1738 | sctp_chunk_free(chunk); | 1738 | sctp_chunk_free(chunk); |
1739 | SCTP_DEBUG_PRINTK("We sent primitively.\n"); | 1739 | SCTP_DEBUG_PRINTK("We sent primitively.\n"); |
1740 | } | 1740 | } |
1741 | 1741 | ||
1742 | sctp_datamsg_free(datamsg); | 1742 | sctp_datamsg_free(datamsg); |
1743 | if (err) | 1743 | if (err) |
1744 | goto out_free; | 1744 | goto out_free; |
1745 | else | 1745 | else |
1746 | err = msg_len; | 1746 | err = msg_len; |
1747 | 1747 | ||
1748 | /* If we are already past ASSOCIATE, the lower | 1748 | /* If we are already past ASSOCIATE, the lower |
1749 | * layers are responsible for association cleanup. | 1749 | * layers are responsible for association cleanup. |
1750 | */ | 1750 | */ |
1751 | goto out_unlock; | 1751 | goto out_unlock; |
1752 | 1752 | ||
1753 | out_free: | 1753 | out_free: |
1754 | if (new_asoc) | 1754 | if (new_asoc) |
1755 | sctp_association_free(asoc); | 1755 | sctp_association_free(asoc); |
1756 | out_unlock: | 1756 | out_unlock: |
1757 | sctp_release_sock(sk); | 1757 | sctp_release_sock(sk); |
1758 | 1758 | ||
1759 | out_nounlock: | 1759 | out_nounlock: |
1760 | return sctp_error(sk, msg_flags, err); | 1760 | return sctp_error(sk, msg_flags, err); |
1761 | 1761 | ||
1762 | #if 0 | 1762 | #if 0 |
1763 | do_sock_err: | 1763 | do_sock_err: |
1764 | if (msg_len) | 1764 | if (msg_len) |
1765 | err = msg_len; | 1765 | err = msg_len; |
1766 | else | 1766 | else |
1767 | err = sock_error(sk); | 1767 | err = sock_error(sk); |
1768 | goto out; | 1768 | goto out; |
1769 | 1769 | ||
1770 | do_interrupted: | 1770 | do_interrupted: |
1771 | if (msg_len) | 1771 | if (msg_len) |
1772 | err = msg_len; | 1772 | err = msg_len; |
1773 | goto out; | 1773 | goto out; |
1774 | #endif /* 0 */ | 1774 | #endif /* 0 */ |
1775 | } | 1775 | } |
1776 | 1776 | ||
1777 | /* This is an extended version of skb_pull() that removes the data from the | 1777 | /* This is an extended version of skb_pull() that removes the data from the |
1778 | * start of a skb even when data is spread across the list of skb's in the | 1778 | * start of a skb even when data is spread across the list of skb's in the |
1779 | * frag_list. len specifies the total amount of data that needs to be removed. | 1779 | * frag_list. len specifies the total amount of data that needs to be removed. |
1780 | * when 'len' bytes could be removed from the skb, it returns 0. | 1780 | * when 'len' bytes could be removed from the skb, it returns 0. |
1781 | * If 'len' exceeds the total skb length, it returns the no. of bytes that | 1781 | * If 'len' exceeds the total skb length, it returns the no. of bytes that |
1782 | * could not be removed. | 1782 | * could not be removed. |
1783 | */ | 1783 | */ |
1784 | static int sctp_skb_pull(struct sk_buff *skb, int len) | 1784 | static int sctp_skb_pull(struct sk_buff *skb, int len) |
1785 | { | 1785 | { |
1786 | struct sk_buff *list; | 1786 | struct sk_buff *list; |
1787 | int skb_len = skb_headlen(skb); | 1787 | int skb_len = skb_headlen(skb); |
1788 | int rlen; | 1788 | int rlen; |
1789 | 1789 | ||
1790 | if (len <= skb_len) { | 1790 | if (len <= skb_len) { |
1791 | __skb_pull(skb, len); | 1791 | __skb_pull(skb, len); |
1792 | return 0; | 1792 | return 0; |
1793 | } | 1793 | } |
1794 | len -= skb_len; | 1794 | len -= skb_len; |
1795 | __skb_pull(skb, skb_len); | 1795 | __skb_pull(skb, skb_len); |
1796 | 1796 | ||
1797 | for (list = skb_shinfo(skb)->frag_list; list; list = list->next) { | 1797 | for (list = skb_shinfo(skb)->frag_list; list; list = list->next) { |
1798 | rlen = sctp_skb_pull(list, len); | 1798 | rlen = sctp_skb_pull(list, len); |
1799 | skb->len -= (len-rlen); | 1799 | skb->len -= (len-rlen); |
1800 | skb->data_len -= (len-rlen); | 1800 | skb->data_len -= (len-rlen); |
1801 | 1801 | ||
1802 | if (!rlen) | 1802 | if (!rlen) |
1803 | return 0; | 1803 | return 0; |
1804 | 1804 | ||
1805 | len = rlen; | 1805 | len = rlen; |
1806 | } | 1806 | } |
1807 | 1807 | ||
1808 | return len; | 1808 | return len; |
1809 | } | 1809 | } |
1810 | 1810 | ||
1811 | /* API 3.1.3 recvmsg() - UDP Style Syntax | 1811 | /* API 3.1.3 recvmsg() - UDP Style Syntax |
1812 | * | 1812 | * |
1813 | * ssize_t recvmsg(int socket, struct msghdr *message, | 1813 | * ssize_t recvmsg(int socket, struct msghdr *message, |
1814 | * int flags); | 1814 | * int flags); |
1815 | * | 1815 | * |
1816 | * socket - the socket descriptor of the endpoint. | 1816 | * socket - the socket descriptor of the endpoint. |
1817 | * message - pointer to the msghdr structure which contains a single | 1817 | * message - pointer to the msghdr structure which contains a single |
1818 | * user message and possibly some ancillary data. | 1818 | * user message and possibly some ancillary data. |
1819 | * | 1819 | * |
1820 | * See Section 5 for complete description of the data | 1820 | * See Section 5 for complete description of the data |
1821 | * structures. | 1821 | * structures. |
1822 | * | 1822 | * |
1823 | * flags - flags sent or received with the user message, see Section | 1823 | * flags - flags sent or received with the user message, see Section |
1824 | * 5 for complete description of the flags. | 1824 | * 5 for complete description of the flags. |
1825 | */ | 1825 | */ |
1826 | static struct sk_buff *sctp_skb_recv_datagram(struct sock *, int, int, int *); | 1826 | static struct sk_buff *sctp_skb_recv_datagram(struct sock *, int, int, int *); |
1827 | 1827 | ||
1828 | SCTP_STATIC int sctp_recvmsg(struct kiocb *iocb, struct sock *sk, | 1828 | SCTP_STATIC int sctp_recvmsg(struct kiocb *iocb, struct sock *sk, |
1829 | struct msghdr *msg, size_t len, int noblock, | 1829 | struct msghdr *msg, size_t len, int noblock, |
1830 | int flags, int *addr_len) | 1830 | int flags, int *addr_len) |
1831 | { | 1831 | { |
1832 | struct sctp_ulpevent *event = NULL; | 1832 | struct sctp_ulpevent *event = NULL; |
1833 | struct sctp_sock *sp = sctp_sk(sk); | 1833 | struct sctp_sock *sp = sctp_sk(sk); |
1834 | struct sk_buff *skb; | 1834 | struct sk_buff *skb; |
1835 | int copied; | 1835 | int copied; |
1836 | int err = 0; | 1836 | int err = 0; |
1837 | int skb_len; | 1837 | int skb_len; |
1838 | 1838 | ||
1839 | SCTP_DEBUG_PRINTK("sctp_recvmsg(%s: %p, %s: %p, %s: %zd, %s: %d, %s: " | 1839 | SCTP_DEBUG_PRINTK("sctp_recvmsg(%s: %p, %s: %p, %s: %zd, %s: %d, %s: " |
1840 | "0x%x, %s: %p)\n", "sk", sk, "msghdr", msg, | 1840 | "0x%x, %s: %p)\n", "sk", sk, "msghdr", msg, |
1841 | "len", len, "knoblauch", noblock, | 1841 | "len", len, "knoblauch", noblock, |
1842 | "flags", flags, "addr_len", addr_len); | 1842 | "flags", flags, "addr_len", addr_len); |
1843 | 1843 | ||
1844 | sctp_lock_sock(sk); | 1844 | sctp_lock_sock(sk); |
1845 | 1845 | ||
1846 | if (sctp_style(sk, TCP) && !sctp_sstate(sk, ESTABLISHED)) { | 1846 | if (sctp_style(sk, TCP) && !sctp_sstate(sk, ESTABLISHED)) { |
1847 | err = -ENOTCONN; | 1847 | err = -ENOTCONN; |
1848 | goto out; | 1848 | goto out; |
1849 | } | 1849 | } |
1850 | 1850 | ||
1851 | skb = sctp_skb_recv_datagram(sk, flags, noblock, &err); | 1851 | skb = sctp_skb_recv_datagram(sk, flags, noblock, &err); |
1852 | if (!skb) | 1852 | if (!skb) |
1853 | goto out; | 1853 | goto out; |
1854 | 1854 | ||
1855 | /* Get the total length of the skb including any skb's in the | 1855 | /* Get the total length of the skb including any skb's in the |
1856 | * frag_list. | 1856 | * frag_list. |
1857 | */ | 1857 | */ |
1858 | skb_len = skb->len; | 1858 | skb_len = skb->len; |
1859 | 1859 | ||
1860 | copied = skb_len; | 1860 | copied = skb_len; |
1861 | if (copied > len) | 1861 | if (copied > len) |
1862 | copied = len; | 1862 | copied = len; |
1863 | 1863 | ||
1864 | err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); | 1864 | err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); |
1865 | 1865 | ||
1866 | event = sctp_skb2event(skb); | 1866 | event = sctp_skb2event(skb); |
1867 | 1867 | ||
1868 | if (err) | 1868 | if (err) |
1869 | goto out_free; | 1869 | goto out_free; |
1870 | 1870 | ||
1871 | sock_recv_timestamp(msg, sk, skb); | 1871 | sock_recv_timestamp(msg, sk, skb); |
1872 | if (sctp_ulpevent_is_notification(event)) { | 1872 | if (sctp_ulpevent_is_notification(event)) { |
1873 | msg->msg_flags |= MSG_NOTIFICATION; | 1873 | msg->msg_flags |= MSG_NOTIFICATION; |
1874 | sp->pf->event_msgname(event, msg->msg_name, addr_len); | 1874 | sp->pf->event_msgname(event, msg->msg_name, addr_len); |
1875 | } else { | 1875 | } else { |
1876 | sp->pf->skb_msgname(skb, msg->msg_name, addr_len); | 1876 | sp->pf->skb_msgname(skb, msg->msg_name, addr_len); |
1877 | } | 1877 | } |
1878 | 1878 | ||
1879 | /* Check if we allow SCTP_SNDRCVINFO. */ | 1879 | /* Check if we allow SCTP_SNDRCVINFO. */ |
1880 | if (sp->subscribe.sctp_data_io_event) | 1880 | if (sp->subscribe.sctp_data_io_event) |
1881 | sctp_ulpevent_read_sndrcvinfo(event, msg); | 1881 | sctp_ulpevent_read_sndrcvinfo(event, msg); |
1882 | #if 0 | 1882 | #if 0 |
1883 | /* FIXME: we should be calling IP/IPv6 layers. */ | 1883 | /* FIXME: we should be calling IP/IPv6 layers. */ |
1884 | if (sk->sk_protinfo.af_inet.cmsg_flags) | 1884 | if (sk->sk_protinfo.af_inet.cmsg_flags) |
1885 | ip_cmsg_recv(msg, skb); | 1885 | ip_cmsg_recv(msg, skb); |
1886 | #endif | 1886 | #endif |
1887 | 1887 | ||
1888 | err = copied; | 1888 | err = copied; |
1889 | 1889 | ||
1890 | /* If skb's length exceeds the user's buffer, update the skb and | 1890 | /* If skb's length exceeds the user's buffer, update the skb and |
1891 | * push it back to the receive_queue so that the next call to | 1891 | * push it back to the receive_queue so that the next call to |
1892 | * recvmsg() will return the remaining data. Don't set MSG_EOR. | 1892 | * recvmsg() will return the remaining data. Don't set MSG_EOR. |
1893 | */ | 1893 | */ |
1894 | if (skb_len > copied) { | 1894 | if (skb_len > copied) { |
1895 | msg->msg_flags &= ~MSG_EOR; | 1895 | msg->msg_flags &= ~MSG_EOR; |
1896 | if (flags & MSG_PEEK) | 1896 | if (flags & MSG_PEEK) |
1897 | goto out_free; | 1897 | goto out_free; |
1898 | sctp_skb_pull(skb, copied); | 1898 | sctp_skb_pull(skb, copied); |
1899 | skb_queue_head(&sk->sk_receive_queue, skb); | 1899 | skb_queue_head(&sk->sk_receive_queue, skb); |
1900 | 1900 | ||
1901 | /* When only partial message is copied to the user, increase | 1901 | /* When only partial message is copied to the user, increase |
1902 | * rwnd by that amount. If all the data in the skb is read, | 1902 | * rwnd by that amount. If all the data in the skb is read, |
1903 | * rwnd is updated when the event is freed. | 1903 | * rwnd is updated when the event is freed. |
1904 | */ | 1904 | */ |
1905 | sctp_assoc_rwnd_increase(event->asoc, copied); | 1905 | sctp_assoc_rwnd_increase(event->asoc, copied); |
1906 | goto out; | 1906 | goto out; |
1907 | } else if ((event->msg_flags & MSG_NOTIFICATION) || | 1907 | } else if ((event->msg_flags & MSG_NOTIFICATION) || |
1908 | (event->msg_flags & MSG_EOR)) | 1908 | (event->msg_flags & MSG_EOR)) |
1909 | msg->msg_flags |= MSG_EOR; | 1909 | msg->msg_flags |= MSG_EOR; |
1910 | else | 1910 | else |
1911 | msg->msg_flags &= ~MSG_EOR; | 1911 | msg->msg_flags &= ~MSG_EOR; |
1912 | 1912 | ||
1913 | out_free: | 1913 | out_free: |
1914 | if (flags & MSG_PEEK) { | 1914 | if (flags & MSG_PEEK) { |
1915 | /* Release the skb reference acquired after peeking the skb in | 1915 | /* Release the skb reference acquired after peeking the skb in |
1916 | * sctp_skb_recv_datagram(). | 1916 | * sctp_skb_recv_datagram(). |
1917 | */ | 1917 | */ |
1918 | kfree_skb(skb); | 1918 | kfree_skb(skb); |
1919 | } else { | 1919 | } else { |
1920 | /* Free the event which includes releasing the reference to | 1920 | /* Free the event which includes releasing the reference to |
1921 | * the owner of the skb, freeing the skb and updating the | 1921 | * the owner of the skb, freeing the skb and updating the |
1922 | * rwnd. | 1922 | * rwnd. |
1923 | */ | 1923 | */ |
1924 | sctp_ulpevent_free(event); | 1924 | sctp_ulpevent_free(event); |
1925 | } | 1925 | } |
1926 | out: | 1926 | out: |
1927 | sctp_release_sock(sk); | 1927 | sctp_release_sock(sk); |
1928 | return err; | 1928 | return err; |
1929 | } | 1929 | } |
1930 | 1930 | ||
1931 | /* 7.1.12 Enable/Disable message fragmentation (SCTP_DISABLE_FRAGMENTS) | 1931 | /* 7.1.12 Enable/Disable message fragmentation (SCTP_DISABLE_FRAGMENTS) |
1932 | * | 1932 | * |
1933 | * This option is a on/off flag. If enabled no SCTP message | 1933 | * This option is a on/off flag. If enabled no SCTP message |
1934 | * fragmentation will be performed. Instead if a message being sent | 1934 | * fragmentation will be performed. Instead if a message being sent |
1935 | * exceeds the current PMTU size, the message will NOT be sent and | 1935 | * exceeds the current PMTU size, the message will NOT be sent and |
1936 | * instead a error will be indicated to the user. | 1936 | * instead a error will be indicated to the user. |
1937 | */ | 1937 | */ |
1938 | static int sctp_setsockopt_disable_fragments(struct sock *sk, | 1938 | static int sctp_setsockopt_disable_fragments(struct sock *sk, |
1939 | char __user *optval, int optlen) | 1939 | char __user *optval, int optlen) |
1940 | { | 1940 | { |
1941 | int val; | 1941 | int val; |
1942 | 1942 | ||
1943 | if (optlen < sizeof(int)) | 1943 | if (optlen < sizeof(int)) |
1944 | return -EINVAL; | 1944 | return -EINVAL; |
1945 | 1945 | ||
1946 | if (get_user(val, (int __user *)optval)) | 1946 | if (get_user(val, (int __user *)optval)) |
1947 | return -EFAULT; | 1947 | return -EFAULT; |
1948 | 1948 | ||
1949 | sctp_sk(sk)->disable_fragments = (val == 0) ? 0 : 1; | 1949 | sctp_sk(sk)->disable_fragments = (val == 0) ? 0 : 1; |
1950 | 1950 | ||
1951 | return 0; | 1951 | return 0; |
1952 | } | 1952 | } |
1953 | 1953 | ||
1954 | static int sctp_setsockopt_events(struct sock *sk, char __user *optval, | 1954 | static int sctp_setsockopt_events(struct sock *sk, char __user *optval, |
1955 | int optlen) | 1955 | int optlen) |
1956 | { | 1956 | { |
1957 | if (optlen != sizeof(struct sctp_event_subscribe)) | 1957 | if (optlen != sizeof(struct sctp_event_subscribe)) |
1958 | return -EINVAL; | 1958 | return -EINVAL; |
1959 | if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen)) | 1959 | if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen)) |
1960 | return -EFAULT; | 1960 | return -EFAULT; |
1961 | return 0; | 1961 | return 0; |
1962 | } | 1962 | } |
1963 | 1963 | ||
1964 | /* 7.1.8 Automatic Close of associations (SCTP_AUTOCLOSE) | 1964 | /* 7.1.8 Automatic Close of associations (SCTP_AUTOCLOSE) |
1965 | * | 1965 | * |
1966 | * This socket option is applicable to the UDP-style socket only. When | 1966 | * This socket option is applicable to the UDP-style socket only. When |
1967 | * set it will cause associations that are idle for more than the | 1967 | * set it will cause associations that are idle for more than the |
1968 | * specified number of seconds to automatically close. An association | 1968 | * specified number of seconds to automatically close. An association |
1969 | * being idle is defined an association that has NOT sent or received | 1969 | * being idle is defined an association that has NOT sent or received |
1970 | * user data. The special value of '0' indicates that no automatic | 1970 | * user data. The special value of '0' indicates that no automatic |
1971 | * close of any associations should be performed. The option expects an | 1971 | * close of any associations should be performed. The option expects an |
1972 | * integer defining the number of seconds of idle time before an | 1972 | * integer defining the number of seconds of idle time before an |
1973 | * association is closed. | 1973 | * association is closed. |
1974 | */ | 1974 | */ |
1975 | static int sctp_setsockopt_autoclose(struct sock *sk, char __user *optval, | 1975 | static int sctp_setsockopt_autoclose(struct sock *sk, char __user *optval, |
1976 | int optlen) | 1976 | int optlen) |
1977 | { | 1977 | { |
1978 | struct sctp_sock *sp = sctp_sk(sk); | 1978 | struct sctp_sock *sp = sctp_sk(sk); |
1979 | 1979 | ||
1980 | /* Applicable to UDP-style socket only */ | 1980 | /* Applicable to UDP-style socket only */ |
1981 | if (sctp_style(sk, TCP)) | 1981 | if (sctp_style(sk, TCP)) |
1982 | return -EOPNOTSUPP; | 1982 | return -EOPNOTSUPP; |
1983 | if (optlen != sizeof(int)) | 1983 | if (optlen != sizeof(int)) |
1984 | return -EINVAL; | 1984 | return -EINVAL; |
1985 | if (copy_from_user(&sp->autoclose, optval, optlen)) | 1985 | if (copy_from_user(&sp->autoclose, optval, optlen)) |
1986 | return -EFAULT; | 1986 | return -EFAULT; |
1987 | 1987 | ||
1988 | return 0; | 1988 | return 0; |
1989 | } | 1989 | } |
1990 | 1990 | ||
1991 | /* 7.1.13 Peer Address Parameters (SCTP_PEER_ADDR_PARAMS) | 1991 | /* 7.1.13 Peer Address Parameters (SCTP_PEER_ADDR_PARAMS) |
1992 | * | 1992 | * |
1993 | * Applications can enable or disable heartbeats for any peer address of | 1993 | * Applications can enable or disable heartbeats for any peer address of |
1994 | * an association, modify an address's heartbeat interval, force a | 1994 | * an association, modify an address's heartbeat interval, force a |
1995 | * heartbeat to be sent immediately, and adjust the address's maximum | 1995 | * heartbeat to be sent immediately, and adjust the address's maximum |
1996 | * number of retransmissions sent before an address is considered | 1996 | * number of retransmissions sent before an address is considered |
1997 | * unreachable. The following structure is used to access and modify an | 1997 | * unreachable. The following structure is used to access and modify an |
1998 | * address's parameters: | 1998 | * address's parameters: |
1999 | * | 1999 | * |
2000 | * struct sctp_paddrparams { | 2000 | * struct sctp_paddrparams { |
2001 | * sctp_assoc_t spp_assoc_id; | 2001 | * sctp_assoc_t spp_assoc_id; |
2002 | * struct sockaddr_storage spp_address; | 2002 | * struct sockaddr_storage spp_address; |
2003 | * uint32_t spp_hbinterval; | 2003 | * uint32_t spp_hbinterval; |
2004 | * uint16_t spp_pathmaxrxt; | 2004 | * uint16_t spp_pathmaxrxt; |
2005 | * uint32_t spp_pathmtu; | 2005 | * uint32_t spp_pathmtu; |
2006 | * uint32_t spp_sackdelay; | 2006 | * uint32_t spp_sackdelay; |
2007 | * uint32_t spp_flags; | 2007 | * uint32_t spp_flags; |
2008 | * }; | 2008 | * }; |
2009 | * | 2009 | * |
2010 | * spp_assoc_id - (one-to-many style socket) This is filled in the | 2010 | * spp_assoc_id - (one-to-many style socket) This is filled in the |
2011 | * application, and identifies the association for | 2011 | * application, and identifies the association for |
2012 | * this query. | 2012 | * this query. |
2013 | * spp_address - This specifies which address is of interest. | 2013 | * spp_address - This specifies which address is of interest. |
2014 | * spp_hbinterval - This contains the value of the heartbeat interval, | 2014 | * spp_hbinterval - This contains the value of the heartbeat interval, |
2015 | * in milliseconds. If a value of zero | 2015 | * in milliseconds. If a value of zero |
2016 | * is present in this field then no changes are to | 2016 | * is present in this field then no changes are to |
2017 | * be made to this parameter. | 2017 | * be made to this parameter. |
2018 | * spp_pathmaxrxt - This contains the maximum number of | 2018 | * spp_pathmaxrxt - This contains the maximum number of |
2019 | * retransmissions before this address shall be | 2019 | * retransmissions before this address shall be |
2020 | * considered unreachable. If a value of zero | 2020 | * considered unreachable. If a value of zero |
2021 | * is present in this field then no changes are to | 2021 | * is present in this field then no changes are to |
2022 | * be made to this parameter. | 2022 | * be made to this parameter. |
2023 | * spp_pathmtu - When Path MTU discovery is disabled the value | 2023 | * spp_pathmtu - When Path MTU discovery is disabled the value |
2024 | * specified here will be the "fixed" path mtu. | 2024 | * specified here will be the "fixed" path mtu. |
2025 | * Note that if the spp_address field is empty | 2025 | * Note that if the spp_address field is empty |
2026 | * then all associations on this address will | 2026 | * then all associations on this address will |
2027 | * have this fixed path mtu set upon them. | 2027 | * have this fixed path mtu set upon them. |
2028 | * | 2028 | * |
2029 | * spp_sackdelay - When delayed sack is enabled, this value specifies | 2029 | * spp_sackdelay - When delayed sack is enabled, this value specifies |
2030 | * the number of milliseconds that sacks will be delayed | 2030 | * the number of milliseconds that sacks will be delayed |
2031 | * for. This value will apply to all addresses of an | 2031 | * for. This value will apply to all addresses of an |
2032 | * association if the spp_address field is empty. Note | 2032 | * association if the spp_address field is empty. Note |
2033 | * also, that if delayed sack is enabled and this | 2033 | * also, that if delayed sack is enabled and this |
2034 | * value is set to 0, no change is made to the last | 2034 | * value is set to 0, no change is made to the last |
2035 | * recorded delayed sack timer value. | 2035 | * recorded delayed sack timer value. |
2036 | * | 2036 | * |
2037 | * spp_flags - These flags are used to control various features | 2037 | * spp_flags - These flags are used to control various features |
2038 | * on an association. The flag field may contain | 2038 | * on an association. The flag field may contain |
2039 | * zero or more of the following options. | 2039 | * zero or more of the following options. |
2040 | * | 2040 | * |
2041 | * SPP_HB_ENABLE - Enable heartbeats on the | 2041 | * SPP_HB_ENABLE - Enable heartbeats on the |
2042 | * specified address. Note that if the address | 2042 | * specified address. Note that if the address |
2043 | * field is empty all addresses for the association | 2043 | * field is empty all addresses for the association |
2044 | * have heartbeats enabled upon them. | 2044 | * have heartbeats enabled upon them. |
2045 | * | 2045 | * |
2046 | * SPP_HB_DISABLE - Disable heartbeats on the | 2046 | * SPP_HB_DISABLE - Disable heartbeats on the |
2047 | * speicifed address. Note that if the address | 2047 | * speicifed address. Note that if the address |
2048 | * field is empty all addresses for the association | 2048 | * field is empty all addresses for the association |
2049 | * will have their heartbeats disabled. Note also | 2049 | * will have their heartbeats disabled. Note also |
2050 | * that SPP_HB_ENABLE and SPP_HB_DISABLE are | 2050 | * that SPP_HB_ENABLE and SPP_HB_DISABLE are |
2051 | * mutually exclusive, only one of these two should | 2051 | * mutually exclusive, only one of these two should |
2052 | * be specified. Enabling both fields will have | 2052 | * be specified. Enabling both fields will have |
2053 | * undetermined results. | 2053 | * undetermined results. |
2054 | * | 2054 | * |
2055 | * SPP_HB_DEMAND - Request a user initiated heartbeat | 2055 | * SPP_HB_DEMAND - Request a user initiated heartbeat |
2056 | * to be made immediately. | 2056 | * to be made immediately. |
2057 | * | 2057 | * |
2058 | * SPP_PMTUD_ENABLE - This field will enable PMTU | 2058 | * SPP_PMTUD_ENABLE - This field will enable PMTU |
2059 | * discovery upon the specified address. Note that | 2059 | * discovery upon the specified address. Note that |
2060 | * if the address feild is empty then all addresses | 2060 | * if the address feild is empty then all addresses |
2061 | * on the association are effected. | 2061 | * on the association are effected. |
2062 | * | 2062 | * |
2063 | * SPP_PMTUD_DISABLE - This field will disable PMTU | 2063 | * SPP_PMTUD_DISABLE - This field will disable PMTU |
2064 | * discovery upon the specified address. Note that | 2064 | * discovery upon the specified address. Note that |
2065 | * if the address feild is empty then all addresses | 2065 | * if the address feild is empty then all addresses |
2066 | * on the association are effected. Not also that | 2066 | * on the association are effected. Not also that |
2067 | * SPP_PMTUD_ENABLE and SPP_PMTUD_DISABLE are mutually | 2067 | * SPP_PMTUD_ENABLE and SPP_PMTUD_DISABLE are mutually |
2068 | * exclusive. Enabling both will have undetermined | 2068 | * exclusive. Enabling both will have undetermined |
2069 | * results. | 2069 | * results. |
2070 | * | 2070 | * |
2071 | * SPP_SACKDELAY_ENABLE - Setting this flag turns | 2071 | * SPP_SACKDELAY_ENABLE - Setting this flag turns |
2072 | * on delayed sack. The time specified in spp_sackdelay | 2072 | * on delayed sack. The time specified in spp_sackdelay |
2073 | * is used to specify the sack delay for this address. Note | 2073 | * is used to specify the sack delay for this address. Note |
2074 | * that if spp_address is empty then all addresses will | 2074 | * that if spp_address is empty then all addresses will |
2075 | * enable delayed sack and take on the sack delay | 2075 | * enable delayed sack and take on the sack delay |
2076 | * value specified in spp_sackdelay. | 2076 | * value specified in spp_sackdelay. |
2077 | * SPP_SACKDELAY_DISABLE - Setting this flag turns | 2077 | * SPP_SACKDELAY_DISABLE - Setting this flag turns |
2078 | * off delayed sack. If the spp_address field is blank then | 2078 | * off delayed sack. If the spp_address field is blank then |
2079 | * delayed sack is disabled for the entire association. Note | 2079 | * delayed sack is disabled for the entire association. Note |
2080 | * also that this field is mutually exclusive to | 2080 | * also that this field is mutually exclusive to |
2081 | * SPP_SACKDELAY_ENABLE, setting both will have undefined | 2081 | * SPP_SACKDELAY_ENABLE, setting both will have undefined |
2082 | * results. | 2082 | * results. |
2083 | */ | 2083 | */ |
2084 | int sctp_apply_peer_addr_params(struct sctp_paddrparams *params, | 2084 | static int sctp_apply_peer_addr_params(struct sctp_paddrparams *params, |
2085 | struct sctp_transport *trans, | 2085 | struct sctp_transport *trans, |
2086 | struct sctp_association *asoc, | 2086 | struct sctp_association *asoc, |
2087 | struct sctp_sock *sp, | 2087 | struct sctp_sock *sp, |
2088 | int hb_change, | 2088 | int hb_change, |
2089 | int pmtud_change, | 2089 | int pmtud_change, |
2090 | int sackdelay_change) | 2090 | int sackdelay_change) |
2091 | { | 2091 | { |
2092 | int error; | 2092 | int error; |
2093 | 2093 | ||
2094 | if (params->spp_flags & SPP_HB_DEMAND && trans) { | 2094 | if (params->spp_flags & SPP_HB_DEMAND && trans) { |
2095 | error = sctp_primitive_REQUESTHEARTBEAT (trans->asoc, trans); | 2095 | error = sctp_primitive_REQUESTHEARTBEAT (trans->asoc, trans); |
2096 | if (error) | 2096 | if (error) |
2097 | return error; | 2097 | return error; |
2098 | } | 2098 | } |
2099 | 2099 | ||
2100 | if (params->spp_hbinterval) { | 2100 | if (params->spp_hbinterval) { |
2101 | if (trans) { | 2101 | if (trans) { |
2102 | trans->hbinterval = msecs_to_jiffies(params->spp_hbinterval); | 2102 | trans->hbinterval = msecs_to_jiffies(params->spp_hbinterval); |
2103 | } else if (asoc) { | 2103 | } else if (asoc) { |
2104 | asoc->hbinterval = msecs_to_jiffies(params->spp_hbinterval); | 2104 | asoc->hbinterval = msecs_to_jiffies(params->spp_hbinterval); |
2105 | } else { | 2105 | } else { |
2106 | sp->hbinterval = params->spp_hbinterval; | 2106 | sp->hbinterval = params->spp_hbinterval; |
2107 | } | 2107 | } |
2108 | } | 2108 | } |
2109 | 2109 | ||
2110 | if (hb_change) { | 2110 | if (hb_change) { |
2111 | if (trans) { | 2111 | if (trans) { |
2112 | trans->param_flags = | 2112 | trans->param_flags = |
2113 | (trans->param_flags & ~SPP_HB) | hb_change; | 2113 | (trans->param_flags & ~SPP_HB) | hb_change; |
2114 | } else if (asoc) { | 2114 | } else if (asoc) { |
2115 | asoc->param_flags = | 2115 | asoc->param_flags = |
2116 | (asoc->param_flags & ~SPP_HB) | hb_change; | 2116 | (asoc->param_flags & ~SPP_HB) | hb_change; |
2117 | } else { | 2117 | } else { |
2118 | sp->param_flags = | 2118 | sp->param_flags = |
2119 | (sp->param_flags & ~SPP_HB) | hb_change; | 2119 | (sp->param_flags & ~SPP_HB) | hb_change; |
2120 | } | 2120 | } |
2121 | } | 2121 | } |
2122 | 2122 | ||
2123 | if (params->spp_pathmtu) { | 2123 | if (params->spp_pathmtu) { |
2124 | if (trans) { | 2124 | if (trans) { |
2125 | trans->pathmtu = params->spp_pathmtu; | 2125 | trans->pathmtu = params->spp_pathmtu; |
2126 | sctp_assoc_sync_pmtu(asoc); | 2126 | sctp_assoc_sync_pmtu(asoc); |
2127 | } else if (asoc) { | 2127 | } else if (asoc) { |
2128 | asoc->pathmtu = params->spp_pathmtu; | 2128 | asoc->pathmtu = params->spp_pathmtu; |
2129 | sctp_frag_point(sp, params->spp_pathmtu); | 2129 | sctp_frag_point(sp, params->spp_pathmtu); |
2130 | } else { | 2130 | } else { |
2131 | sp->pathmtu = params->spp_pathmtu; | 2131 | sp->pathmtu = params->spp_pathmtu; |
2132 | } | 2132 | } |
2133 | } | 2133 | } |
2134 | 2134 | ||
2135 | if (pmtud_change) { | 2135 | if (pmtud_change) { |
2136 | if (trans) { | 2136 | if (trans) { |
2137 | int update = (trans->param_flags & SPP_PMTUD_DISABLE) && | 2137 | int update = (trans->param_flags & SPP_PMTUD_DISABLE) && |
2138 | (params->spp_flags & SPP_PMTUD_ENABLE); | 2138 | (params->spp_flags & SPP_PMTUD_ENABLE); |
2139 | trans->param_flags = | 2139 | trans->param_flags = |
2140 | (trans->param_flags & ~SPP_PMTUD) | pmtud_change; | 2140 | (trans->param_flags & ~SPP_PMTUD) | pmtud_change; |
2141 | if (update) { | 2141 | if (update) { |
2142 | sctp_transport_pmtu(trans); | 2142 | sctp_transport_pmtu(trans); |
2143 | sctp_assoc_sync_pmtu(asoc); | 2143 | sctp_assoc_sync_pmtu(asoc); |
2144 | } | 2144 | } |
2145 | } else if (asoc) { | 2145 | } else if (asoc) { |
2146 | asoc->param_flags = | 2146 | asoc->param_flags = |
2147 | (asoc->param_flags & ~SPP_PMTUD) | pmtud_change; | 2147 | (asoc->param_flags & ~SPP_PMTUD) | pmtud_change; |
2148 | } else { | 2148 | } else { |
2149 | sp->param_flags = | 2149 | sp->param_flags = |
2150 | (sp->param_flags & ~SPP_PMTUD) | pmtud_change; | 2150 | (sp->param_flags & ~SPP_PMTUD) | pmtud_change; |
2151 | } | 2151 | } |
2152 | } | 2152 | } |
2153 | 2153 | ||
2154 | if (params->spp_sackdelay) { | 2154 | if (params->spp_sackdelay) { |
2155 | if (trans) { | 2155 | if (trans) { |
2156 | trans->sackdelay = | 2156 | trans->sackdelay = |
2157 | msecs_to_jiffies(params->spp_sackdelay); | 2157 | msecs_to_jiffies(params->spp_sackdelay); |
2158 | } else if (asoc) { | 2158 | } else if (asoc) { |
2159 | asoc->sackdelay = | 2159 | asoc->sackdelay = |
2160 | msecs_to_jiffies(params->spp_sackdelay); | 2160 | msecs_to_jiffies(params->spp_sackdelay); |
2161 | } else { | 2161 | } else { |
2162 | sp->sackdelay = params->spp_sackdelay; | 2162 | sp->sackdelay = params->spp_sackdelay; |
2163 | } | 2163 | } |
2164 | } | 2164 | } |
2165 | 2165 | ||
2166 | if (sackdelay_change) { | 2166 | if (sackdelay_change) { |
2167 | if (trans) { | 2167 | if (trans) { |
2168 | trans->param_flags = | 2168 | trans->param_flags = |
2169 | (trans->param_flags & ~SPP_SACKDELAY) | | 2169 | (trans->param_flags & ~SPP_SACKDELAY) | |
2170 | sackdelay_change; | 2170 | sackdelay_change; |
2171 | } else if (asoc) { | 2171 | } else if (asoc) { |
2172 | asoc->param_flags = | 2172 | asoc->param_flags = |
2173 | (asoc->param_flags & ~SPP_SACKDELAY) | | 2173 | (asoc->param_flags & ~SPP_SACKDELAY) | |
2174 | sackdelay_change; | 2174 | sackdelay_change; |
2175 | } else { | 2175 | } else { |
2176 | sp->param_flags = | 2176 | sp->param_flags = |
2177 | (sp->param_flags & ~SPP_SACKDELAY) | | 2177 | (sp->param_flags & ~SPP_SACKDELAY) | |
2178 | sackdelay_change; | 2178 | sackdelay_change; |
2179 | } | 2179 | } |
2180 | } | 2180 | } |
2181 | 2181 | ||
2182 | if (params->spp_pathmaxrxt) { | 2182 | if (params->spp_pathmaxrxt) { |
2183 | if (trans) { | 2183 | if (trans) { |
2184 | trans->pathmaxrxt = params->spp_pathmaxrxt; | 2184 | trans->pathmaxrxt = params->spp_pathmaxrxt; |
2185 | } else if (asoc) { | 2185 | } else if (asoc) { |
2186 | asoc->pathmaxrxt = params->spp_pathmaxrxt; | 2186 | asoc->pathmaxrxt = params->spp_pathmaxrxt; |
2187 | } else { | 2187 | } else { |
2188 | sp->pathmaxrxt = params->spp_pathmaxrxt; | 2188 | sp->pathmaxrxt = params->spp_pathmaxrxt; |
2189 | } | 2189 | } |
2190 | } | 2190 | } |
2191 | 2191 | ||
2192 | return 0; | 2192 | return 0; |
2193 | } | 2193 | } |
2194 | 2194 | ||
2195 | static int sctp_setsockopt_peer_addr_params(struct sock *sk, | 2195 | static int sctp_setsockopt_peer_addr_params(struct sock *sk, |
2196 | char __user *optval, int optlen) | 2196 | char __user *optval, int optlen) |
2197 | { | 2197 | { |
2198 | struct sctp_paddrparams params; | 2198 | struct sctp_paddrparams params; |
2199 | struct sctp_transport *trans = NULL; | 2199 | struct sctp_transport *trans = NULL; |
2200 | struct sctp_association *asoc = NULL; | 2200 | struct sctp_association *asoc = NULL; |
2201 | struct sctp_sock *sp = sctp_sk(sk); | 2201 | struct sctp_sock *sp = sctp_sk(sk); |
2202 | int error; | 2202 | int error; |
2203 | int hb_change, pmtud_change, sackdelay_change; | 2203 | int hb_change, pmtud_change, sackdelay_change; |
2204 | 2204 | ||
2205 | if (optlen != sizeof(struct sctp_paddrparams)) | 2205 | if (optlen != sizeof(struct sctp_paddrparams)) |
2206 | return - EINVAL; | 2206 | return - EINVAL; |
2207 | 2207 | ||
2208 | if (copy_from_user(¶ms, optval, optlen)) | 2208 | if (copy_from_user(¶ms, optval, optlen)) |
2209 | return -EFAULT; | 2209 | return -EFAULT; |
2210 | 2210 | ||
2211 | /* Validate flags and value parameters. */ | 2211 | /* Validate flags and value parameters. */ |
2212 | hb_change = params.spp_flags & SPP_HB; | 2212 | hb_change = params.spp_flags & SPP_HB; |
2213 | pmtud_change = params.spp_flags & SPP_PMTUD; | 2213 | pmtud_change = params.spp_flags & SPP_PMTUD; |
2214 | sackdelay_change = params.spp_flags & SPP_SACKDELAY; | 2214 | sackdelay_change = params.spp_flags & SPP_SACKDELAY; |
2215 | 2215 | ||
2216 | if (hb_change == SPP_HB || | 2216 | if (hb_change == SPP_HB || |
2217 | pmtud_change == SPP_PMTUD || | 2217 | pmtud_change == SPP_PMTUD || |
2218 | sackdelay_change == SPP_SACKDELAY || | 2218 | sackdelay_change == SPP_SACKDELAY || |
2219 | params.spp_sackdelay > 500 || | 2219 | params.spp_sackdelay > 500 || |
2220 | (params.spp_pathmtu | 2220 | (params.spp_pathmtu |
2221 | && params.spp_pathmtu < SCTP_DEFAULT_MINSEGMENT)) | 2221 | && params.spp_pathmtu < SCTP_DEFAULT_MINSEGMENT)) |
2222 | return -EINVAL; | 2222 | return -EINVAL; |
2223 | 2223 | ||
2224 | /* If an address other than INADDR_ANY is specified, and | 2224 | /* If an address other than INADDR_ANY is specified, and |
2225 | * no transport is found, then the request is invalid. | 2225 | * no transport is found, then the request is invalid. |
2226 | */ | 2226 | */ |
2227 | if (!sctp_is_any(( union sctp_addr *)¶ms.spp_address)) { | 2227 | if (!sctp_is_any(( union sctp_addr *)¶ms.spp_address)) { |
2228 | trans = sctp_addr_id2transport(sk, ¶ms.spp_address, | 2228 | trans = sctp_addr_id2transport(sk, ¶ms.spp_address, |
2229 | params.spp_assoc_id); | 2229 | params.spp_assoc_id); |
2230 | if (!trans) | 2230 | if (!trans) |
2231 | return -EINVAL; | 2231 | return -EINVAL; |
2232 | } | 2232 | } |
2233 | 2233 | ||
2234 | /* Get association, if assoc_id != 0 and the socket is a one | 2234 | /* Get association, if assoc_id != 0 and the socket is a one |
2235 | * to many style socket, and an association was not found, then | 2235 | * to many style socket, and an association was not found, then |
2236 | * the id was invalid. | 2236 | * the id was invalid. |
2237 | */ | 2237 | */ |
2238 | asoc = sctp_id2assoc(sk, params.spp_assoc_id); | 2238 | asoc = sctp_id2assoc(sk, params.spp_assoc_id); |
2239 | if (!asoc && params.spp_assoc_id && sctp_style(sk, UDP)) | 2239 | if (!asoc && params.spp_assoc_id && sctp_style(sk, UDP)) |
2240 | return -EINVAL; | 2240 | return -EINVAL; |
2241 | 2241 | ||
2242 | /* Heartbeat demand can only be sent on a transport or | 2242 | /* Heartbeat demand can only be sent on a transport or |
2243 | * association, but not a socket. | 2243 | * association, but not a socket. |
2244 | */ | 2244 | */ |
2245 | if (params.spp_flags & SPP_HB_DEMAND && !trans && !asoc) | 2245 | if (params.spp_flags & SPP_HB_DEMAND && !trans && !asoc) |
2246 | return -EINVAL; | 2246 | return -EINVAL; |
2247 | 2247 | ||
2248 | /* Process parameters. */ | 2248 | /* Process parameters. */ |
2249 | error = sctp_apply_peer_addr_params(¶ms, trans, asoc, sp, | 2249 | error = sctp_apply_peer_addr_params(¶ms, trans, asoc, sp, |
2250 | hb_change, pmtud_change, | 2250 | hb_change, pmtud_change, |
2251 | sackdelay_change); | 2251 | sackdelay_change); |
2252 | 2252 | ||
2253 | if (error) | 2253 | if (error) |
2254 | return error; | 2254 | return error; |
2255 | 2255 | ||
2256 | /* If changes are for association, also apply parameters to each | 2256 | /* If changes are for association, also apply parameters to each |
2257 | * transport. | 2257 | * transport. |
2258 | */ | 2258 | */ |
2259 | if (!trans && asoc) { | 2259 | if (!trans && asoc) { |
2260 | struct list_head *pos; | 2260 | struct list_head *pos; |
2261 | 2261 | ||
2262 | list_for_each(pos, &asoc->peer.transport_addr_list) { | 2262 | list_for_each(pos, &asoc->peer.transport_addr_list) { |
2263 | trans = list_entry(pos, struct sctp_transport, | 2263 | trans = list_entry(pos, struct sctp_transport, |
2264 | transports); | 2264 | transports); |
2265 | sctp_apply_peer_addr_params(¶ms, trans, asoc, sp, | 2265 | sctp_apply_peer_addr_params(¶ms, trans, asoc, sp, |
2266 | hb_change, pmtud_change, | 2266 | hb_change, pmtud_change, |
2267 | sackdelay_change); | 2267 | sackdelay_change); |
2268 | } | 2268 | } |
2269 | } | 2269 | } |
2270 | 2270 | ||
2271 | return 0; | 2271 | return 0; |
2272 | } | 2272 | } |
2273 | 2273 | ||
2274 | /* 7.1.24. Delayed Ack Timer (SCTP_DELAYED_ACK_TIME) | 2274 | /* 7.1.24. Delayed Ack Timer (SCTP_DELAYED_ACK_TIME) |
2275 | * | 2275 | * |
2276 | * This options will get or set the delayed ack timer. The time is set | 2276 | * This options will get or set the delayed ack timer. The time is set |
2277 | * in milliseconds. If the assoc_id is 0, then this sets or gets the | 2277 | * in milliseconds. If the assoc_id is 0, then this sets or gets the |
2278 | * endpoints default delayed ack timer value. If the assoc_id field is | 2278 | * endpoints default delayed ack timer value. If the assoc_id field is |
2279 | * non-zero, then the set or get effects the specified association. | 2279 | * non-zero, then the set or get effects the specified association. |
2280 | * | 2280 | * |
2281 | * struct sctp_assoc_value { | 2281 | * struct sctp_assoc_value { |
2282 | * sctp_assoc_t assoc_id; | 2282 | * sctp_assoc_t assoc_id; |
2283 | * uint32_t assoc_value; | 2283 | * uint32_t assoc_value; |
2284 | * }; | 2284 | * }; |
2285 | * | 2285 | * |
2286 | * assoc_id - This parameter, indicates which association the | 2286 | * assoc_id - This parameter, indicates which association the |
2287 | * user is preforming an action upon. Note that if | 2287 | * user is preforming an action upon. Note that if |
2288 | * this field's value is zero then the endpoints | 2288 | * this field's value is zero then the endpoints |
2289 | * default value is changed (effecting future | 2289 | * default value is changed (effecting future |
2290 | * associations only). | 2290 | * associations only). |
2291 | * | 2291 | * |
2292 | * assoc_value - This parameter contains the number of milliseconds | 2292 | * assoc_value - This parameter contains the number of milliseconds |
2293 | * that the user is requesting the delayed ACK timer | 2293 | * that the user is requesting the delayed ACK timer |
2294 | * be set to. Note that this value is defined in | 2294 | * be set to. Note that this value is defined in |
2295 | * the standard to be between 200 and 500 milliseconds. | 2295 | * the standard to be between 200 and 500 milliseconds. |
2296 | * | 2296 | * |
2297 | * Note: a value of zero will leave the value alone, | 2297 | * Note: a value of zero will leave the value alone, |
2298 | * but disable SACK delay. A non-zero value will also | 2298 | * but disable SACK delay. A non-zero value will also |
2299 | * enable SACK delay. | 2299 | * enable SACK delay. |
2300 | */ | 2300 | */ |
2301 | 2301 | ||
2302 | static int sctp_setsockopt_delayed_ack_time(struct sock *sk, | 2302 | static int sctp_setsockopt_delayed_ack_time(struct sock *sk, |
2303 | char __user *optval, int optlen) | 2303 | char __user *optval, int optlen) |
2304 | { | 2304 | { |
2305 | struct sctp_assoc_value params; | 2305 | struct sctp_assoc_value params; |
2306 | struct sctp_transport *trans = NULL; | 2306 | struct sctp_transport *trans = NULL; |
2307 | struct sctp_association *asoc = NULL; | 2307 | struct sctp_association *asoc = NULL; |
2308 | struct sctp_sock *sp = sctp_sk(sk); | 2308 | struct sctp_sock *sp = sctp_sk(sk); |
2309 | 2309 | ||
2310 | if (optlen != sizeof(struct sctp_assoc_value)) | 2310 | if (optlen != sizeof(struct sctp_assoc_value)) |
2311 | return - EINVAL; | 2311 | return - EINVAL; |
2312 | 2312 | ||
2313 | if (copy_from_user(¶ms, optval, optlen)) | 2313 | if (copy_from_user(¶ms, optval, optlen)) |
2314 | return -EFAULT; | 2314 | return -EFAULT; |
2315 | 2315 | ||
2316 | /* Validate value parameter. */ | 2316 | /* Validate value parameter. */ |
2317 | if (params.assoc_value > 500) | 2317 | if (params.assoc_value > 500) |
2318 | return -EINVAL; | 2318 | return -EINVAL; |
2319 | 2319 | ||
2320 | /* Get association, if assoc_id != 0 and the socket is a one | 2320 | /* Get association, if assoc_id != 0 and the socket is a one |
2321 | * to many style socket, and an association was not found, then | 2321 | * to many style socket, and an association was not found, then |
2322 | * the id was invalid. | 2322 | * the id was invalid. |
2323 | */ | 2323 | */ |
2324 | asoc = sctp_id2assoc(sk, params.assoc_id); | 2324 | asoc = sctp_id2assoc(sk, params.assoc_id); |
2325 | if (!asoc && params.assoc_id && sctp_style(sk, UDP)) | 2325 | if (!asoc && params.assoc_id && sctp_style(sk, UDP)) |
2326 | return -EINVAL; | 2326 | return -EINVAL; |
2327 | 2327 | ||
2328 | if (params.assoc_value) { | 2328 | if (params.assoc_value) { |
2329 | if (asoc) { | 2329 | if (asoc) { |
2330 | asoc->sackdelay = | 2330 | asoc->sackdelay = |
2331 | msecs_to_jiffies(params.assoc_value); | 2331 | msecs_to_jiffies(params.assoc_value); |
2332 | asoc->param_flags = | 2332 | asoc->param_flags = |
2333 | (asoc->param_flags & ~SPP_SACKDELAY) | | 2333 | (asoc->param_flags & ~SPP_SACKDELAY) | |
2334 | SPP_SACKDELAY_ENABLE; | 2334 | SPP_SACKDELAY_ENABLE; |
2335 | } else { | 2335 | } else { |
2336 | sp->sackdelay = params.assoc_value; | 2336 | sp->sackdelay = params.assoc_value; |
2337 | sp->param_flags = | 2337 | sp->param_flags = |
2338 | (sp->param_flags & ~SPP_SACKDELAY) | | 2338 | (sp->param_flags & ~SPP_SACKDELAY) | |
2339 | SPP_SACKDELAY_ENABLE; | 2339 | SPP_SACKDELAY_ENABLE; |
2340 | } | 2340 | } |
2341 | } else { | 2341 | } else { |
2342 | if (asoc) { | 2342 | if (asoc) { |
2343 | asoc->param_flags = | 2343 | asoc->param_flags = |
2344 | (asoc->param_flags & ~SPP_SACKDELAY) | | 2344 | (asoc->param_flags & ~SPP_SACKDELAY) | |
2345 | SPP_SACKDELAY_DISABLE; | 2345 | SPP_SACKDELAY_DISABLE; |
2346 | } else { | 2346 | } else { |
2347 | sp->param_flags = | 2347 | sp->param_flags = |
2348 | (sp->param_flags & ~SPP_SACKDELAY) | | 2348 | (sp->param_flags & ~SPP_SACKDELAY) | |
2349 | SPP_SACKDELAY_DISABLE; | 2349 | SPP_SACKDELAY_DISABLE; |
2350 | } | 2350 | } |
2351 | } | 2351 | } |
2352 | 2352 | ||
2353 | /* If change is for association, also apply to each transport. */ | 2353 | /* If change is for association, also apply to each transport. */ |
2354 | if (asoc) { | 2354 | if (asoc) { |
2355 | struct list_head *pos; | 2355 | struct list_head *pos; |
2356 | 2356 | ||
2357 | list_for_each(pos, &asoc->peer.transport_addr_list) { | 2357 | list_for_each(pos, &asoc->peer.transport_addr_list) { |
2358 | trans = list_entry(pos, struct sctp_transport, | 2358 | trans = list_entry(pos, struct sctp_transport, |
2359 | transports); | 2359 | transports); |
2360 | if (params.assoc_value) { | 2360 | if (params.assoc_value) { |
2361 | trans->sackdelay = | 2361 | trans->sackdelay = |
2362 | msecs_to_jiffies(params.assoc_value); | 2362 | msecs_to_jiffies(params.assoc_value); |
2363 | trans->param_flags = | 2363 | trans->param_flags = |
2364 | (trans->param_flags & ~SPP_SACKDELAY) | | 2364 | (trans->param_flags & ~SPP_SACKDELAY) | |
2365 | SPP_SACKDELAY_ENABLE; | 2365 | SPP_SACKDELAY_ENABLE; |
2366 | } else { | 2366 | } else { |
2367 | trans->param_flags = | 2367 | trans->param_flags = |
2368 | (trans->param_flags & ~SPP_SACKDELAY) | | 2368 | (trans->param_flags & ~SPP_SACKDELAY) | |
2369 | SPP_SACKDELAY_DISABLE; | 2369 | SPP_SACKDELAY_DISABLE; |
2370 | } | 2370 | } |
2371 | } | 2371 | } |
2372 | } | 2372 | } |
2373 | 2373 | ||
2374 | return 0; | 2374 | return 0; |
2375 | } | 2375 | } |
2376 | 2376 | ||
2377 | /* 7.1.3 Initialization Parameters (SCTP_INITMSG) | 2377 | /* 7.1.3 Initialization Parameters (SCTP_INITMSG) |
2378 | * | 2378 | * |
2379 | * Applications can specify protocol parameters for the default association | 2379 | * Applications can specify protocol parameters for the default association |
2380 | * initialization. The option name argument to setsockopt() and getsockopt() | 2380 | * initialization. The option name argument to setsockopt() and getsockopt() |
2381 | * is SCTP_INITMSG. | 2381 | * is SCTP_INITMSG. |
2382 | * | 2382 | * |
2383 | * Setting initialization parameters is effective only on an unconnected | 2383 | * Setting initialization parameters is effective only on an unconnected |
2384 | * socket (for UDP-style sockets only future associations are effected | 2384 | * socket (for UDP-style sockets only future associations are effected |
2385 | * by the change). With TCP-style sockets, this option is inherited by | 2385 | * by the change). With TCP-style sockets, this option is inherited by |
2386 | * sockets derived from a listener socket. | 2386 | * sockets derived from a listener socket. |
2387 | */ | 2387 | */ |
2388 | static int sctp_setsockopt_initmsg(struct sock *sk, char __user *optval, int optlen) | 2388 | static int sctp_setsockopt_initmsg(struct sock *sk, char __user *optval, int optlen) |
2389 | { | 2389 | { |
2390 | struct sctp_initmsg sinit; | 2390 | struct sctp_initmsg sinit; |
2391 | struct sctp_sock *sp = sctp_sk(sk); | 2391 | struct sctp_sock *sp = sctp_sk(sk); |
2392 | 2392 | ||
2393 | if (optlen != sizeof(struct sctp_initmsg)) | 2393 | if (optlen != sizeof(struct sctp_initmsg)) |
2394 | return -EINVAL; | 2394 | return -EINVAL; |
2395 | if (copy_from_user(&sinit, optval, optlen)) | 2395 | if (copy_from_user(&sinit, optval, optlen)) |
2396 | return -EFAULT; | 2396 | return -EFAULT; |
2397 | 2397 | ||
2398 | if (sinit.sinit_num_ostreams) | 2398 | if (sinit.sinit_num_ostreams) |
2399 | sp->initmsg.sinit_num_ostreams = sinit.sinit_num_ostreams; | 2399 | sp->initmsg.sinit_num_ostreams = sinit.sinit_num_ostreams; |
2400 | if (sinit.sinit_max_instreams) | 2400 | if (sinit.sinit_max_instreams) |
2401 | sp->initmsg.sinit_max_instreams = sinit.sinit_max_instreams; | 2401 | sp->initmsg.sinit_max_instreams = sinit.sinit_max_instreams; |
2402 | if (sinit.sinit_max_attempts) | 2402 | if (sinit.sinit_max_attempts) |
2403 | sp->initmsg.sinit_max_attempts = sinit.sinit_max_attempts; | 2403 | sp->initmsg.sinit_max_attempts = sinit.sinit_max_attempts; |
2404 | if (sinit.sinit_max_init_timeo) | 2404 | if (sinit.sinit_max_init_timeo) |
2405 | sp->initmsg.sinit_max_init_timeo = sinit.sinit_max_init_timeo; | 2405 | sp->initmsg.sinit_max_init_timeo = sinit.sinit_max_init_timeo; |
2406 | 2406 | ||
2407 | return 0; | 2407 | return 0; |
2408 | } | 2408 | } |
2409 | 2409 | ||
2410 | /* | 2410 | /* |
2411 | * 7.1.14 Set default send parameters (SCTP_DEFAULT_SEND_PARAM) | 2411 | * 7.1.14 Set default send parameters (SCTP_DEFAULT_SEND_PARAM) |
2412 | * | 2412 | * |
2413 | * Applications that wish to use the sendto() system call may wish to | 2413 | * Applications that wish to use the sendto() system call may wish to |
2414 | * specify a default set of parameters that would normally be supplied | 2414 | * specify a default set of parameters that would normally be supplied |
2415 | * through the inclusion of ancillary data. This socket option allows | 2415 | * through the inclusion of ancillary data. This socket option allows |
2416 | * such an application to set the default sctp_sndrcvinfo structure. | 2416 | * such an application to set the default sctp_sndrcvinfo structure. |
2417 | * The application that wishes to use this socket option simply passes | 2417 | * The application that wishes to use this socket option simply passes |
2418 | * in to this call the sctp_sndrcvinfo structure defined in Section | 2418 | * in to this call the sctp_sndrcvinfo structure defined in Section |
2419 | * 5.2.2) The input parameters accepted by this call include | 2419 | * 5.2.2) The input parameters accepted by this call include |
2420 | * sinfo_stream, sinfo_flags, sinfo_ppid, sinfo_context, | 2420 | * sinfo_stream, sinfo_flags, sinfo_ppid, sinfo_context, |
2421 | * sinfo_timetolive. The user must provide the sinfo_assoc_id field in | 2421 | * sinfo_timetolive. The user must provide the sinfo_assoc_id field in |
2422 | * to this call if the caller is using the UDP model. | 2422 | * to this call if the caller is using the UDP model. |
2423 | */ | 2423 | */ |
2424 | static int sctp_setsockopt_default_send_param(struct sock *sk, | 2424 | static int sctp_setsockopt_default_send_param(struct sock *sk, |
2425 | char __user *optval, int optlen) | 2425 | char __user *optval, int optlen) |
2426 | { | 2426 | { |
2427 | struct sctp_sndrcvinfo info; | 2427 | struct sctp_sndrcvinfo info; |
2428 | struct sctp_association *asoc; | 2428 | struct sctp_association *asoc; |
2429 | struct sctp_sock *sp = sctp_sk(sk); | 2429 | struct sctp_sock *sp = sctp_sk(sk); |
2430 | 2430 | ||
2431 | if (optlen != sizeof(struct sctp_sndrcvinfo)) | 2431 | if (optlen != sizeof(struct sctp_sndrcvinfo)) |
2432 | return -EINVAL; | 2432 | return -EINVAL; |
2433 | if (copy_from_user(&info, optval, optlen)) | 2433 | if (copy_from_user(&info, optval, optlen)) |
2434 | return -EFAULT; | 2434 | return -EFAULT; |
2435 | 2435 | ||
2436 | asoc = sctp_id2assoc(sk, info.sinfo_assoc_id); | 2436 | asoc = sctp_id2assoc(sk, info.sinfo_assoc_id); |
2437 | if (!asoc && info.sinfo_assoc_id && sctp_style(sk, UDP)) | 2437 | if (!asoc && info.sinfo_assoc_id && sctp_style(sk, UDP)) |
2438 | return -EINVAL; | 2438 | return -EINVAL; |
2439 | 2439 | ||
2440 | if (asoc) { | 2440 | if (asoc) { |
2441 | asoc->default_stream = info.sinfo_stream; | 2441 | asoc->default_stream = info.sinfo_stream; |
2442 | asoc->default_flags = info.sinfo_flags; | 2442 | asoc->default_flags = info.sinfo_flags; |
2443 | asoc->default_ppid = info.sinfo_ppid; | 2443 | asoc->default_ppid = info.sinfo_ppid; |
2444 | asoc->default_context = info.sinfo_context; | 2444 | asoc->default_context = info.sinfo_context; |
2445 | asoc->default_timetolive = info.sinfo_timetolive; | 2445 | asoc->default_timetolive = info.sinfo_timetolive; |
2446 | } else { | 2446 | } else { |
2447 | sp->default_stream = info.sinfo_stream; | 2447 | sp->default_stream = info.sinfo_stream; |
2448 | sp->default_flags = info.sinfo_flags; | 2448 | sp->default_flags = info.sinfo_flags; |
2449 | sp->default_ppid = info.sinfo_ppid; | 2449 | sp->default_ppid = info.sinfo_ppid; |
2450 | sp->default_context = info.sinfo_context; | 2450 | sp->default_context = info.sinfo_context; |
2451 | sp->default_timetolive = info.sinfo_timetolive; | 2451 | sp->default_timetolive = info.sinfo_timetolive; |
2452 | } | 2452 | } |
2453 | 2453 | ||
2454 | return 0; | 2454 | return 0; |
2455 | } | 2455 | } |
2456 | 2456 | ||
2457 | /* 7.1.10 Set Primary Address (SCTP_PRIMARY_ADDR) | 2457 | /* 7.1.10 Set Primary Address (SCTP_PRIMARY_ADDR) |
2458 | * | 2458 | * |
2459 | * Requests that the local SCTP stack use the enclosed peer address as | 2459 | * Requests that the local SCTP stack use the enclosed peer address as |
2460 | * the association primary. The enclosed address must be one of the | 2460 | * the association primary. The enclosed address must be one of the |
2461 | * association peer's addresses. | 2461 | * association peer's addresses. |
2462 | */ | 2462 | */ |
2463 | static int sctp_setsockopt_primary_addr(struct sock *sk, char __user *optval, | 2463 | static int sctp_setsockopt_primary_addr(struct sock *sk, char __user *optval, |
2464 | int optlen) | 2464 | int optlen) |
2465 | { | 2465 | { |
2466 | struct sctp_prim prim; | 2466 | struct sctp_prim prim; |
2467 | struct sctp_transport *trans; | 2467 | struct sctp_transport *trans; |
2468 | 2468 | ||
2469 | if (optlen != sizeof(struct sctp_prim)) | 2469 | if (optlen != sizeof(struct sctp_prim)) |
2470 | return -EINVAL; | 2470 | return -EINVAL; |
2471 | 2471 | ||
2472 | if (copy_from_user(&prim, optval, sizeof(struct sctp_prim))) | 2472 | if (copy_from_user(&prim, optval, sizeof(struct sctp_prim))) |
2473 | return -EFAULT; | 2473 | return -EFAULT; |
2474 | 2474 | ||
2475 | trans = sctp_addr_id2transport(sk, &prim.ssp_addr, prim.ssp_assoc_id); | 2475 | trans = sctp_addr_id2transport(sk, &prim.ssp_addr, prim.ssp_assoc_id); |
2476 | if (!trans) | 2476 | if (!trans) |
2477 | return -EINVAL; | 2477 | return -EINVAL; |
2478 | 2478 | ||
2479 | sctp_assoc_set_primary(trans->asoc, trans); | 2479 | sctp_assoc_set_primary(trans->asoc, trans); |
2480 | 2480 | ||
2481 | return 0; | 2481 | return 0; |
2482 | } | 2482 | } |
2483 | 2483 | ||
2484 | /* | 2484 | /* |
2485 | * 7.1.5 SCTP_NODELAY | 2485 | * 7.1.5 SCTP_NODELAY |
2486 | * | 2486 | * |
2487 | * Turn on/off any Nagle-like algorithm. This means that packets are | 2487 | * Turn on/off any Nagle-like algorithm. This means that packets are |
2488 | * generally sent as soon as possible and no unnecessary delays are | 2488 | * generally sent as soon as possible and no unnecessary delays are |
2489 | * introduced, at the cost of more packets in the network. Expects an | 2489 | * introduced, at the cost of more packets in the network. Expects an |
2490 | * integer boolean flag. | 2490 | * integer boolean flag. |
2491 | */ | 2491 | */ |
2492 | static int sctp_setsockopt_nodelay(struct sock *sk, char __user *optval, | 2492 | static int sctp_setsockopt_nodelay(struct sock *sk, char __user *optval, |
2493 | int optlen) | 2493 | int optlen) |
2494 | { | 2494 | { |
2495 | int val; | 2495 | int val; |
2496 | 2496 | ||
2497 | if (optlen < sizeof(int)) | 2497 | if (optlen < sizeof(int)) |
2498 | return -EINVAL; | 2498 | return -EINVAL; |
2499 | if (get_user(val, (int __user *)optval)) | 2499 | if (get_user(val, (int __user *)optval)) |
2500 | return -EFAULT; | 2500 | return -EFAULT; |
2501 | 2501 | ||
2502 | sctp_sk(sk)->nodelay = (val == 0) ? 0 : 1; | 2502 | sctp_sk(sk)->nodelay = (val == 0) ? 0 : 1; |
2503 | return 0; | 2503 | return 0; |
2504 | } | 2504 | } |
2505 | 2505 | ||
2506 | /* | 2506 | /* |
2507 | * | 2507 | * |
2508 | * 7.1.1 SCTP_RTOINFO | 2508 | * 7.1.1 SCTP_RTOINFO |
2509 | * | 2509 | * |
2510 | * The protocol parameters used to initialize and bound retransmission | 2510 | * The protocol parameters used to initialize and bound retransmission |
2511 | * timeout (RTO) are tunable. sctp_rtoinfo structure is used to access | 2511 | * timeout (RTO) are tunable. sctp_rtoinfo structure is used to access |
2512 | * and modify these parameters. | 2512 | * and modify these parameters. |
2513 | * All parameters are time values, in milliseconds. A value of 0, when | 2513 | * All parameters are time values, in milliseconds. A value of 0, when |
2514 | * modifying the parameters, indicates that the current value should not | 2514 | * modifying the parameters, indicates that the current value should not |
2515 | * be changed. | 2515 | * be changed. |
2516 | * | 2516 | * |
2517 | */ | 2517 | */ |
2518 | static int sctp_setsockopt_rtoinfo(struct sock *sk, char __user *optval, int optlen) { | 2518 | static int sctp_setsockopt_rtoinfo(struct sock *sk, char __user *optval, int optlen) { |
2519 | struct sctp_rtoinfo rtoinfo; | 2519 | struct sctp_rtoinfo rtoinfo; |
2520 | struct sctp_association *asoc; | 2520 | struct sctp_association *asoc; |
2521 | 2521 | ||
2522 | if (optlen != sizeof (struct sctp_rtoinfo)) | 2522 | if (optlen != sizeof (struct sctp_rtoinfo)) |
2523 | return -EINVAL; | 2523 | return -EINVAL; |
2524 | 2524 | ||
2525 | if (copy_from_user(&rtoinfo, optval, optlen)) | 2525 | if (copy_from_user(&rtoinfo, optval, optlen)) |
2526 | return -EFAULT; | 2526 | return -EFAULT; |
2527 | 2527 | ||
2528 | asoc = sctp_id2assoc(sk, rtoinfo.srto_assoc_id); | 2528 | asoc = sctp_id2assoc(sk, rtoinfo.srto_assoc_id); |
2529 | 2529 | ||
2530 | /* Set the values to the specific association */ | 2530 | /* Set the values to the specific association */ |
2531 | if (!asoc && rtoinfo.srto_assoc_id && sctp_style(sk, UDP)) | 2531 | if (!asoc && rtoinfo.srto_assoc_id && sctp_style(sk, UDP)) |
2532 | return -EINVAL; | 2532 | return -EINVAL; |
2533 | 2533 | ||
2534 | if (asoc) { | 2534 | if (asoc) { |
2535 | if (rtoinfo.srto_initial != 0) | 2535 | if (rtoinfo.srto_initial != 0) |
2536 | asoc->rto_initial = | 2536 | asoc->rto_initial = |
2537 | msecs_to_jiffies(rtoinfo.srto_initial); | 2537 | msecs_to_jiffies(rtoinfo.srto_initial); |
2538 | if (rtoinfo.srto_max != 0) | 2538 | if (rtoinfo.srto_max != 0) |
2539 | asoc->rto_max = msecs_to_jiffies(rtoinfo.srto_max); | 2539 | asoc->rto_max = msecs_to_jiffies(rtoinfo.srto_max); |
2540 | if (rtoinfo.srto_min != 0) | 2540 | if (rtoinfo.srto_min != 0) |
2541 | asoc->rto_min = msecs_to_jiffies(rtoinfo.srto_min); | 2541 | asoc->rto_min = msecs_to_jiffies(rtoinfo.srto_min); |
2542 | } else { | 2542 | } else { |
2543 | /* If there is no association or the association-id = 0 | 2543 | /* If there is no association or the association-id = 0 |
2544 | * set the values to the endpoint. | 2544 | * set the values to the endpoint. |
2545 | */ | 2545 | */ |
2546 | struct sctp_sock *sp = sctp_sk(sk); | 2546 | struct sctp_sock *sp = sctp_sk(sk); |
2547 | 2547 | ||
2548 | if (rtoinfo.srto_initial != 0) | 2548 | if (rtoinfo.srto_initial != 0) |
2549 | sp->rtoinfo.srto_initial = rtoinfo.srto_initial; | 2549 | sp->rtoinfo.srto_initial = rtoinfo.srto_initial; |
2550 | if (rtoinfo.srto_max != 0) | 2550 | if (rtoinfo.srto_max != 0) |
2551 | sp->rtoinfo.srto_max = rtoinfo.srto_max; | 2551 | sp->rtoinfo.srto_max = rtoinfo.srto_max; |
2552 | if (rtoinfo.srto_min != 0) | 2552 | if (rtoinfo.srto_min != 0) |
2553 | sp->rtoinfo.srto_min = rtoinfo.srto_min; | 2553 | sp->rtoinfo.srto_min = rtoinfo.srto_min; |
2554 | } | 2554 | } |
2555 | 2555 | ||
2556 | return 0; | 2556 | return 0; |
2557 | } | 2557 | } |
2558 | 2558 | ||
2559 | /* | 2559 | /* |
2560 | * | 2560 | * |
2561 | * 7.1.2 SCTP_ASSOCINFO | 2561 | * 7.1.2 SCTP_ASSOCINFO |
2562 | * | 2562 | * |
2563 | * This option is used to tune the the maximum retransmission attempts | 2563 | * This option is used to tune the the maximum retransmission attempts |
2564 | * of the association. | 2564 | * of the association. |
2565 | * Returns an error if the new association retransmission value is | 2565 | * Returns an error if the new association retransmission value is |
2566 | * greater than the sum of the retransmission value of the peer. | 2566 | * greater than the sum of the retransmission value of the peer. |
2567 | * See [SCTP] for more information. | 2567 | * See [SCTP] for more information. |
2568 | * | 2568 | * |
2569 | */ | 2569 | */ |
2570 | static int sctp_setsockopt_associnfo(struct sock *sk, char __user *optval, int optlen) | 2570 | static int sctp_setsockopt_associnfo(struct sock *sk, char __user *optval, int optlen) |
2571 | { | 2571 | { |
2572 | 2572 | ||
2573 | struct sctp_assocparams assocparams; | 2573 | struct sctp_assocparams assocparams; |
2574 | struct sctp_association *asoc; | 2574 | struct sctp_association *asoc; |
2575 | 2575 | ||
2576 | if (optlen != sizeof(struct sctp_assocparams)) | 2576 | if (optlen != sizeof(struct sctp_assocparams)) |
2577 | return -EINVAL; | 2577 | return -EINVAL; |
2578 | if (copy_from_user(&assocparams, optval, optlen)) | 2578 | if (copy_from_user(&assocparams, optval, optlen)) |
2579 | return -EFAULT; | 2579 | return -EFAULT; |
2580 | 2580 | ||
2581 | asoc = sctp_id2assoc(sk, assocparams.sasoc_assoc_id); | 2581 | asoc = sctp_id2assoc(sk, assocparams.sasoc_assoc_id); |
2582 | 2582 | ||
2583 | if (!asoc && assocparams.sasoc_assoc_id && sctp_style(sk, UDP)) | 2583 | if (!asoc && assocparams.sasoc_assoc_id && sctp_style(sk, UDP)) |
2584 | return -EINVAL; | 2584 | return -EINVAL; |
2585 | 2585 | ||
2586 | /* Set the values to the specific association */ | 2586 | /* Set the values to the specific association */ |
2587 | if (asoc) { | 2587 | if (asoc) { |
2588 | if (assocparams.sasoc_asocmaxrxt != 0) { | 2588 | if (assocparams.sasoc_asocmaxrxt != 0) { |
2589 | __u32 path_sum = 0; | 2589 | __u32 path_sum = 0; |
2590 | int paths = 0; | 2590 | int paths = 0; |
2591 | struct list_head *pos; | 2591 | struct list_head *pos; |
2592 | struct sctp_transport *peer_addr; | 2592 | struct sctp_transport *peer_addr; |
2593 | 2593 | ||
2594 | list_for_each(pos, &asoc->peer.transport_addr_list) { | 2594 | list_for_each(pos, &asoc->peer.transport_addr_list) { |
2595 | peer_addr = list_entry(pos, | 2595 | peer_addr = list_entry(pos, |
2596 | struct sctp_transport, | 2596 | struct sctp_transport, |
2597 | transports); | 2597 | transports); |
2598 | path_sum += peer_addr->pathmaxrxt; | 2598 | path_sum += peer_addr->pathmaxrxt; |
2599 | paths++; | 2599 | paths++; |
2600 | } | 2600 | } |
2601 | 2601 | ||
2602 | /* Only validate asocmaxrxt if we have more then | 2602 | /* Only validate asocmaxrxt if we have more then |
2603 | * one path/transport. We do this because path | 2603 | * one path/transport. We do this because path |
2604 | * retransmissions are only counted when we have more | 2604 | * retransmissions are only counted when we have more |
2605 | * then one path. | 2605 | * then one path. |
2606 | */ | 2606 | */ |
2607 | if (paths > 1 && | 2607 | if (paths > 1 && |
2608 | assocparams.sasoc_asocmaxrxt > path_sum) | 2608 | assocparams.sasoc_asocmaxrxt > path_sum) |
2609 | return -EINVAL; | 2609 | return -EINVAL; |
2610 | 2610 | ||
2611 | asoc->max_retrans = assocparams.sasoc_asocmaxrxt; | 2611 | asoc->max_retrans = assocparams.sasoc_asocmaxrxt; |
2612 | } | 2612 | } |
2613 | 2613 | ||
2614 | if (assocparams.sasoc_cookie_life != 0) { | 2614 | if (assocparams.sasoc_cookie_life != 0) { |
2615 | asoc->cookie_life.tv_sec = | 2615 | asoc->cookie_life.tv_sec = |
2616 | assocparams.sasoc_cookie_life / 1000; | 2616 | assocparams.sasoc_cookie_life / 1000; |
2617 | asoc->cookie_life.tv_usec = | 2617 | asoc->cookie_life.tv_usec = |
2618 | (assocparams.sasoc_cookie_life % 1000) | 2618 | (assocparams.sasoc_cookie_life % 1000) |
2619 | * 1000; | 2619 | * 1000; |
2620 | } | 2620 | } |
2621 | } else { | 2621 | } else { |
2622 | /* Set the values to the endpoint */ | 2622 | /* Set the values to the endpoint */ |
2623 | struct sctp_sock *sp = sctp_sk(sk); | 2623 | struct sctp_sock *sp = sctp_sk(sk); |
2624 | 2624 | ||
2625 | if (assocparams.sasoc_asocmaxrxt != 0) | 2625 | if (assocparams.sasoc_asocmaxrxt != 0) |
2626 | sp->assocparams.sasoc_asocmaxrxt = | 2626 | sp->assocparams.sasoc_asocmaxrxt = |
2627 | assocparams.sasoc_asocmaxrxt; | 2627 | assocparams.sasoc_asocmaxrxt; |
2628 | if (assocparams.sasoc_cookie_life != 0) | 2628 | if (assocparams.sasoc_cookie_life != 0) |
2629 | sp->assocparams.sasoc_cookie_life = | 2629 | sp->assocparams.sasoc_cookie_life = |
2630 | assocparams.sasoc_cookie_life; | 2630 | assocparams.sasoc_cookie_life; |
2631 | } | 2631 | } |
2632 | return 0; | 2632 | return 0; |
2633 | } | 2633 | } |
2634 | 2634 | ||
2635 | /* | 2635 | /* |
2636 | * 7.1.16 Set/clear IPv4 mapped addresses (SCTP_I_WANT_MAPPED_V4_ADDR) | 2636 | * 7.1.16 Set/clear IPv4 mapped addresses (SCTP_I_WANT_MAPPED_V4_ADDR) |
2637 | * | 2637 | * |
2638 | * This socket option is a boolean flag which turns on or off mapped V4 | 2638 | * This socket option is a boolean flag which turns on or off mapped V4 |
2639 | * addresses. If this option is turned on and the socket is type | 2639 | * addresses. If this option is turned on and the socket is type |
2640 | * PF_INET6, then IPv4 addresses will be mapped to V6 representation. | 2640 | * PF_INET6, then IPv4 addresses will be mapped to V6 representation. |
2641 | * If this option is turned off, then no mapping will be done of V4 | 2641 | * If this option is turned off, then no mapping will be done of V4 |
2642 | * addresses and a user will receive both PF_INET6 and PF_INET type | 2642 | * addresses and a user will receive both PF_INET6 and PF_INET type |
2643 | * addresses on the socket. | 2643 | * addresses on the socket. |
2644 | */ | 2644 | */ |
2645 | static int sctp_setsockopt_mappedv4(struct sock *sk, char __user *optval, int optlen) | 2645 | static int sctp_setsockopt_mappedv4(struct sock *sk, char __user *optval, int optlen) |
2646 | { | 2646 | { |
2647 | int val; | 2647 | int val; |
2648 | struct sctp_sock *sp = sctp_sk(sk); | 2648 | struct sctp_sock *sp = sctp_sk(sk); |
2649 | 2649 | ||
2650 | if (optlen < sizeof(int)) | 2650 | if (optlen < sizeof(int)) |
2651 | return -EINVAL; | 2651 | return -EINVAL; |
2652 | if (get_user(val, (int __user *)optval)) | 2652 | if (get_user(val, (int __user *)optval)) |
2653 | return -EFAULT; | 2653 | return -EFAULT; |
2654 | if (val) | 2654 | if (val) |
2655 | sp->v4mapped = 1; | 2655 | sp->v4mapped = 1; |
2656 | else | 2656 | else |
2657 | sp->v4mapped = 0; | 2657 | sp->v4mapped = 0; |
2658 | 2658 | ||
2659 | return 0; | 2659 | return 0; |
2660 | } | 2660 | } |
2661 | 2661 | ||
2662 | /* | 2662 | /* |
2663 | * 7.1.17 Set the maximum fragrmentation size (SCTP_MAXSEG) | 2663 | * 7.1.17 Set the maximum fragrmentation size (SCTP_MAXSEG) |
2664 | * | 2664 | * |
2665 | * This socket option specifies the maximum size to put in any outgoing | 2665 | * This socket option specifies the maximum size to put in any outgoing |
2666 | * SCTP chunk. If a message is larger than this size it will be | 2666 | * SCTP chunk. If a message is larger than this size it will be |
2667 | * fragmented by SCTP into the specified size. Note that the underlying | 2667 | * fragmented by SCTP into the specified size. Note that the underlying |
2668 | * SCTP implementation may fragment into smaller sized chunks when the | 2668 | * SCTP implementation may fragment into smaller sized chunks when the |
2669 | * PMTU of the underlying association is smaller than the value set by | 2669 | * PMTU of the underlying association is smaller than the value set by |
2670 | * the user. | 2670 | * the user. |
2671 | */ | 2671 | */ |
2672 | static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, int optlen) | 2672 | static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, int optlen) |
2673 | { | 2673 | { |
2674 | struct sctp_association *asoc; | 2674 | struct sctp_association *asoc; |
2675 | struct list_head *pos; | 2675 | struct list_head *pos; |
2676 | struct sctp_sock *sp = sctp_sk(sk); | 2676 | struct sctp_sock *sp = sctp_sk(sk); |
2677 | int val; | 2677 | int val; |
2678 | 2678 | ||
2679 | if (optlen < sizeof(int)) | 2679 | if (optlen < sizeof(int)) |
2680 | return -EINVAL; | 2680 | return -EINVAL; |
2681 | if (get_user(val, (int __user *)optval)) | 2681 | if (get_user(val, (int __user *)optval)) |
2682 | return -EFAULT; | 2682 | return -EFAULT; |
2683 | if ((val != 0) && ((val < 8) || (val > SCTP_MAX_CHUNK_LEN))) | 2683 | if ((val != 0) && ((val < 8) || (val > SCTP_MAX_CHUNK_LEN))) |
2684 | return -EINVAL; | 2684 | return -EINVAL; |
2685 | sp->user_frag = val; | 2685 | sp->user_frag = val; |
2686 | 2686 | ||
2687 | /* Update the frag_point of the existing associations. */ | 2687 | /* Update the frag_point of the existing associations. */ |
2688 | list_for_each(pos, &(sp->ep->asocs)) { | 2688 | list_for_each(pos, &(sp->ep->asocs)) { |
2689 | asoc = list_entry(pos, struct sctp_association, asocs); | 2689 | asoc = list_entry(pos, struct sctp_association, asocs); |
2690 | asoc->frag_point = sctp_frag_point(sp, asoc->pathmtu); | 2690 | asoc->frag_point = sctp_frag_point(sp, asoc->pathmtu); |
2691 | } | 2691 | } |
2692 | 2692 | ||
2693 | return 0; | 2693 | return 0; |
2694 | } | 2694 | } |
2695 | 2695 | ||
2696 | 2696 | ||
2697 | /* | 2697 | /* |
2698 | * 7.1.9 Set Peer Primary Address (SCTP_SET_PEER_PRIMARY_ADDR) | 2698 | * 7.1.9 Set Peer Primary Address (SCTP_SET_PEER_PRIMARY_ADDR) |
2699 | * | 2699 | * |
2700 | * Requests that the peer mark the enclosed address as the association | 2700 | * Requests that the peer mark the enclosed address as the association |
2701 | * primary. The enclosed address must be one of the association's | 2701 | * primary. The enclosed address must be one of the association's |
2702 | * locally bound addresses. The following structure is used to make a | 2702 | * locally bound addresses. The following structure is used to make a |
2703 | * set primary request: | 2703 | * set primary request: |
2704 | */ | 2704 | */ |
2705 | static int sctp_setsockopt_peer_primary_addr(struct sock *sk, char __user *optval, | 2705 | static int sctp_setsockopt_peer_primary_addr(struct sock *sk, char __user *optval, |
2706 | int optlen) | 2706 | int optlen) |
2707 | { | 2707 | { |
2708 | struct sctp_sock *sp; | 2708 | struct sctp_sock *sp; |
2709 | struct sctp_endpoint *ep; | 2709 | struct sctp_endpoint *ep; |
2710 | struct sctp_association *asoc = NULL; | 2710 | struct sctp_association *asoc = NULL; |
2711 | struct sctp_setpeerprim prim; | 2711 | struct sctp_setpeerprim prim; |
2712 | struct sctp_chunk *chunk; | 2712 | struct sctp_chunk *chunk; |
2713 | int err; | 2713 | int err; |
2714 | 2714 | ||
2715 | sp = sctp_sk(sk); | 2715 | sp = sctp_sk(sk); |
2716 | ep = sp->ep; | 2716 | ep = sp->ep; |
2717 | 2717 | ||
2718 | if (!sctp_addip_enable) | 2718 | if (!sctp_addip_enable) |
2719 | return -EPERM; | 2719 | return -EPERM; |
2720 | 2720 | ||
2721 | if (optlen != sizeof(struct sctp_setpeerprim)) | 2721 | if (optlen != sizeof(struct sctp_setpeerprim)) |
2722 | return -EINVAL; | 2722 | return -EINVAL; |
2723 | 2723 | ||
2724 | if (copy_from_user(&prim, optval, optlen)) | 2724 | if (copy_from_user(&prim, optval, optlen)) |
2725 | return -EFAULT; | 2725 | return -EFAULT; |
2726 | 2726 | ||
2727 | asoc = sctp_id2assoc(sk, prim.sspp_assoc_id); | 2727 | asoc = sctp_id2assoc(sk, prim.sspp_assoc_id); |
2728 | if (!asoc) | 2728 | if (!asoc) |
2729 | return -EINVAL; | 2729 | return -EINVAL; |
2730 | 2730 | ||
2731 | if (!asoc->peer.asconf_capable) | 2731 | if (!asoc->peer.asconf_capable) |
2732 | return -EPERM; | 2732 | return -EPERM; |
2733 | 2733 | ||
2734 | if (asoc->peer.addip_disabled_mask & SCTP_PARAM_SET_PRIMARY) | 2734 | if (asoc->peer.addip_disabled_mask & SCTP_PARAM_SET_PRIMARY) |
2735 | return -EPERM; | 2735 | return -EPERM; |
2736 | 2736 | ||
2737 | if (!sctp_state(asoc, ESTABLISHED)) | 2737 | if (!sctp_state(asoc, ESTABLISHED)) |
2738 | return -ENOTCONN; | 2738 | return -ENOTCONN; |
2739 | 2739 | ||
2740 | if (!sctp_assoc_lookup_laddr(asoc, (union sctp_addr *)&prim.sspp_addr)) | 2740 | if (!sctp_assoc_lookup_laddr(asoc, (union sctp_addr *)&prim.sspp_addr)) |
2741 | return -EADDRNOTAVAIL; | 2741 | return -EADDRNOTAVAIL; |
2742 | 2742 | ||
2743 | /* Create an ASCONF chunk with SET_PRIMARY parameter */ | 2743 | /* Create an ASCONF chunk with SET_PRIMARY parameter */ |
2744 | chunk = sctp_make_asconf_set_prim(asoc, | 2744 | chunk = sctp_make_asconf_set_prim(asoc, |
2745 | (union sctp_addr *)&prim.sspp_addr); | 2745 | (union sctp_addr *)&prim.sspp_addr); |
2746 | if (!chunk) | 2746 | if (!chunk) |
2747 | return -ENOMEM; | 2747 | return -ENOMEM; |
2748 | 2748 | ||
2749 | err = sctp_send_asconf(asoc, chunk); | 2749 | err = sctp_send_asconf(asoc, chunk); |
2750 | 2750 | ||
2751 | SCTP_DEBUG_PRINTK("We set peer primary addr primitively.\n"); | 2751 | SCTP_DEBUG_PRINTK("We set peer primary addr primitively.\n"); |
2752 | 2752 | ||
2753 | return err; | 2753 | return err; |
2754 | } | 2754 | } |
2755 | 2755 | ||
2756 | static int sctp_setsockopt_adaption_layer(struct sock *sk, char __user *optval, | 2756 | static int sctp_setsockopt_adaption_layer(struct sock *sk, char __user *optval, |
2757 | int optlen) | 2757 | int optlen) |
2758 | { | 2758 | { |
2759 | struct sctp_setadaption adaption; | 2759 | struct sctp_setadaption adaption; |
2760 | 2760 | ||
2761 | if (optlen != sizeof(struct sctp_setadaption)) | 2761 | if (optlen != sizeof(struct sctp_setadaption)) |
2762 | return -EINVAL; | 2762 | return -EINVAL; |
2763 | if (copy_from_user(&adaption, optval, optlen)) | 2763 | if (copy_from_user(&adaption, optval, optlen)) |
2764 | return -EFAULT; | 2764 | return -EFAULT; |
2765 | 2765 | ||
2766 | sctp_sk(sk)->adaption_ind = adaption.ssb_adaption_ind; | 2766 | sctp_sk(sk)->adaption_ind = adaption.ssb_adaption_ind; |
2767 | 2767 | ||
2768 | return 0; | 2768 | return 0; |
2769 | } | 2769 | } |
2770 | 2770 | ||
2771 | /* API 6.2 setsockopt(), getsockopt() | 2771 | /* API 6.2 setsockopt(), getsockopt() |
2772 | * | 2772 | * |
2773 | * Applications use setsockopt() and getsockopt() to set or retrieve | 2773 | * Applications use setsockopt() and getsockopt() to set or retrieve |
2774 | * socket options. Socket options are used to change the default | 2774 | * socket options. Socket options are used to change the default |
2775 | * behavior of sockets calls. They are described in Section 7. | 2775 | * behavior of sockets calls. They are described in Section 7. |
2776 | * | 2776 | * |
2777 | * The syntax is: | 2777 | * The syntax is: |
2778 | * | 2778 | * |
2779 | * ret = getsockopt(int sd, int level, int optname, void __user *optval, | 2779 | * ret = getsockopt(int sd, int level, int optname, void __user *optval, |
2780 | * int __user *optlen); | 2780 | * int __user *optlen); |
2781 | * ret = setsockopt(int sd, int level, int optname, const void __user *optval, | 2781 | * ret = setsockopt(int sd, int level, int optname, const void __user *optval, |
2782 | * int optlen); | 2782 | * int optlen); |
2783 | * | 2783 | * |
2784 | * sd - the socket descript. | 2784 | * sd - the socket descript. |
2785 | * level - set to IPPROTO_SCTP for all SCTP options. | 2785 | * level - set to IPPROTO_SCTP for all SCTP options. |
2786 | * optname - the option name. | 2786 | * optname - the option name. |
2787 | * optval - the buffer to store the value of the option. | 2787 | * optval - the buffer to store the value of the option. |
2788 | * optlen - the size of the buffer. | 2788 | * optlen - the size of the buffer. |
2789 | */ | 2789 | */ |
2790 | SCTP_STATIC int sctp_setsockopt(struct sock *sk, int level, int optname, | 2790 | SCTP_STATIC int sctp_setsockopt(struct sock *sk, int level, int optname, |
2791 | char __user *optval, int optlen) | 2791 | char __user *optval, int optlen) |
2792 | { | 2792 | { |
2793 | int retval = 0; | 2793 | int retval = 0; |
2794 | 2794 | ||
2795 | SCTP_DEBUG_PRINTK("sctp_setsockopt(sk: %p... optname: %d)\n", | 2795 | SCTP_DEBUG_PRINTK("sctp_setsockopt(sk: %p... optname: %d)\n", |
2796 | sk, optname); | 2796 | sk, optname); |
2797 | 2797 | ||
2798 | /* I can hardly begin to describe how wrong this is. This is | 2798 | /* I can hardly begin to describe how wrong this is. This is |
2799 | * so broken as to be worse than useless. The API draft | 2799 | * so broken as to be worse than useless. The API draft |
2800 | * REALLY is NOT helpful here... I am not convinced that the | 2800 | * REALLY is NOT helpful here... I am not convinced that the |
2801 | * semantics of setsockopt() with a level OTHER THAN SOL_SCTP | 2801 | * semantics of setsockopt() with a level OTHER THAN SOL_SCTP |
2802 | * are at all well-founded. | 2802 | * are at all well-founded. |
2803 | */ | 2803 | */ |
2804 | if (level != SOL_SCTP) { | 2804 | if (level != SOL_SCTP) { |
2805 | struct sctp_af *af = sctp_sk(sk)->pf->af; | 2805 | struct sctp_af *af = sctp_sk(sk)->pf->af; |
2806 | retval = af->setsockopt(sk, level, optname, optval, optlen); | 2806 | retval = af->setsockopt(sk, level, optname, optval, optlen); |
2807 | goto out_nounlock; | 2807 | goto out_nounlock; |
2808 | } | 2808 | } |
2809 | 2809 | ||
2810 | sctp_lock_sock(sk); | 2810 | sctp_lock_sock(sk); |
2811 | 2811 | ||
2812 | switch (optname) { | 2812 | switch (optname) { |
2813 | case SCTP_SOCKOPT_BINDX_ADD: | 2813 | case SCTP_SOCKOPT_BINDX_ADD: |
2814 | /* 'optlen' is the size of the addresses buffer. */ | 2814 | /* 'optlen' is the size of the addresses buffer. */ |
2815 | retval = sctp_setsockopt_bindx(sk, (struct sockaddr __user *)optval, | 2815 | retval = sctp_setsockopt_bindx(sk, (struct sockaddr __user *)optval, |
2816 | optlen, SCTP_BINDX_ADD_ADDR); | 2816 | optlen, SCTP_BINDX_ADD_ADDR); |
2817 | break; | 2817 | break; |
2818 | 2818 | ||
2819 | case SCTP_SOCKOPT_BINDX_REM: | 2819 | case SCTP_SOCKOPT_BINDX_REM: |
2820 | /* 'optlen' is the size of the addresses buffer. */ | 2820 | /* 'optlen' is the size of the addresses buffer. */ |
2821 | retval = sctp_setsockopt_bindx(sk, (struct sockaddr __user *)optval, | 2821 | retval = sctp_setsockopt_bindx(sk, (struct sockaddr __user *)optval, |
2822 | optlen, SCTP_BINDX_REM_ADDR); | 2822 | optlen, SCTP_BINDX_REM_ADDR); |
2823 | break; | 2823 | break; |
2824 | 2824 | ||
2825 | case SCTP_SOCKOPT_CONNECTX: | 2825 | case SCTP_SOCKOPT_CONNECTX: |
2826 | /* 'optlen' is the size of the addresses buffer. */ | 2826 | /* 'optlen' is the size of the addresses buffer. */ |
2827 | retval = sctp_setsockopt_connectx(sk, (struct sockaddr __user *)optval, | 2827 | retval = sctp_setsockopt_connectx(sk, (struct sockaddr __user *)optval, |
2828 | optlen); | 2828 | optlen); |
2829 | break; | 2829 | break; |
2830 | 2830 | ||
2831 | case SCTP_DISABLE_FRAGMENTS: | 2831 | case SCTP_DISABLE_FRAGMENTS: |
2832 | retval = sctp_setsockopt_disable_fragments(sk, optval, optlen); | 2832 | retval = sctp_setsockopt_disable_fragments(sk, optval, optlen); |
2833 | break; | 2833 | break; |
2834 | 2834 | ||
2835 | case SCTP_EVENTS: | 2835 | case SCTP_EVENTS: |
2836 | retval = sctp_setsockopt_events(sk, optval, optlen); | 2836 | retval = sctp_setsockopt_events(sk, optval, optlen); |
2837 | break; | 2837 | break; |
2838 | 2838 | ||
2839 | case SCTP_AUTOCLOSE: | 2839 | case SCTP_AUTOCLOSE: |
2840 | retval = sctp_setsockopt_autoclose(sk, optval, optlen); | 2840 | retval = sctp_setsockopt_autoclose(sk, optval, optlen); |
2841 | break; | 2841 | break; |
2842 | 2842 | ||
2843 | case SCTP_PEER_ADDR_PARAMS: | 2843 | case SCTP_PEER_ADDR_PARAMS: |
2844 | retval = sctp_setsockopt_peer_addr_params(sk, optval, optlen); | 2844 | retval = sctp_setsockopt_peer_addr_params(sk, optval, optlen); |
2845 | break; | 2845 | break; |
2846 | 2846 | ||
2847 | case SCTP_DELAYED_ACK_TIME: | 2847 | case SCTP_DELAYED_ACK_TIME: |
2848 | retval = sctp_setsockopt_delayed_ack_time(sk, optval, optlen); | 2848 | retval = sctp_setsockopt_delayed_ack_time(sk, optval, optlen); |
2849 | break; | 2849 | break; |
2850 | 2850 | ||
2851 | case SCTP_INITMSG: | 2851 | case SCTP_INITMSG: |
2852 | retval = sctp_setsockopt_initmsg(sk, optval, optlen); | 2852 | retval = sctp_setsockopt_initmsg(sk, optval, optlen); |
2853 | break; | 2853 | break; |
2854 | case SCTP_DEFAULT_SEND_PARAM: | 2854 | case SCTP_DEFAULT_SEND_PARAM: |
2855 | retval = sctp_setsockopt_default_send_param(sk, optval, | 2855 | retval = sctp_setsockopt_default_send_param(sk, optval, |
2856 | optlen); | 2856 | optlen); |
2857 | break; | 2857 | break; |
2858 | case SCTP_PRIMARY_ADDR: | 2858 | case SCTP_PRIMARY_ADDR: |
2859 | retval = sctp_setsockopt_primary_addr(sk, optval, optlen); | 2859 | retval = sctp_setsockopt_primary_addr(sk, optval, optlen); |
2860 | break; | 2860 | break; |
2861 | case SCTP_SET_PEER_PRIMARY_ADDR: | 2861 | case SCTP_SET_PEER_PRIMARY_ADDR: |
2862 | retval = sctp_setsockopt_peer_primary_addr(sk, optval, optlen); | 2862 | retval = sctp_setsockopt_peer_primary_addr(sk, optval, optlen); |
2863 | break; | 2863 | break; |
2864 | case SCTP_NODELAY: | 2864 | case SCTP_NODELAY: |
2865 | retval = sctp_setsockopt_nodelay(sk, optval, optlen); | 2865 | retval = sctp_setsockopt_nodelay(sk, optval, optlen); |
2866 | break; | 2866 | break; |
2867 | case SCTP_RTOINFO: | 2867 | case SCTP_RTOINFO: |
2868 | retval = sctp_setsockopt_rtoinfo(sk, optval, optlen); | 2868 | retval = sctp_setsockopt_rtoinfo(sk, optval, optlen); |
2869 | break; | 2869 | break; |
2870 | case SCTP_ASSOCINFO: | 2870 | case SCTP_ASSOCINFO: |
2871 | retval = sctp_setsockopt_associnfo(sk, optval, optlen); | 2871 | retval = sctp_setsockopt_associnfo(sk, optval, optlen); |
2872 | break; | 2872 | break; |
2873 | case SCTP_I_WANT_MAPPED_V4_ADDR: | 2873 | case SCTP_I_WANT_MAPPED_V4_ADDR: |
2874 | retval = sctp_setsockopt_mappedv4(sk, optval, optlen); | 2874 | retval = sctp_setsockopt_mappedv4(sk, optval, optlen); |
2875 | break; | 2875 | break; |
2876 | case SCTP_MAXSEG: | 2876 | case SCTP_MAXSEG: |
2877 | retval = sctp_setsockopt_maxseg(sk, optval, optlen); | 2877 | retval = sctp_setsockopt_maxseg(sk, optval, optlen); |
2878 | break; | 2878 | break; |
2879 | case SCTP_ADAPTION_LAYER: | 2879 | case SCTP_ADAPTION_LAYER: |
2880 | retval = sctp_setsockopt_adaption_layer(sk, optval, optlen); | 2880 | retval = sctp_setsockopt_adaption_layer(sk, optval, optlen); |
2881 | break; | 2881 | break; |
2882 | 2882 | ||
2883 | default: | 2883 | default: |
2884 | retval = -ENOPROTOOPT; | 2884 | retval = -ENOPROTOOPT; |
2885 | break; | 2885 | break; |
2886 | }; | 2886 | }; |
2887 | 2887 | ||
2888 | sctp_release_sock(sk); | 2888 | sctp_release_sock(sk); |
2889 | 2889 | ||
2890 | out_nounlock: | 2890 | out_nounlock: |
2891 | return retval; | 2891 | return retval; |
2892 | } | 2892 | } |
2893 | 2893 | ||
2894 | /* API 3.1.6 connect() - UDP Style Syntax | 2894 | /* API 3.1.6 connect() - UDP Style Syntax |
2895 | * | 2895 | * |
2896 | * An application may use the connect() call in the UDP model to initiate an | 2896 | * An application may use the connect() call in the UDP model to initiate an |
2897 | * association without sending data. | 2897 | * association without sending data. |
2898 | * | 2898 | * |
2899 | * The syntax is: | 2899 | * The syntax is: |
2900 | * | 2900 | * |
2901 | * ret = connect(int sd, const struct sockaddr *nam, socklen_t len); | 2901 | * ret = connect(int sd, const struct sockaddr *nam, socklen_t len); |
2902 | * | 2902 | * |
2903 | * sd: the socket descriptor to have a new association added to. | 2903 | * sd: the socket descriptor to have a new association added to. |
2904 | * | 2904 | * |
2905 | * nam: the address structure (either struct sockaddr_in or struct | 2905 | * nam: the address structure (either struct sockaddr_in or struct |
2906 | * sockaddr_in6 defined in RFC2553 [7]). | 2906 | * sockaddr_in6 defined in RFC2553 [7]). |
2907 | * | 2907 | * |
2908 | * len: the size of the address. | 2908 | * len: the size of the address. |
2909 | */ | 2909 | */ |
2910 | SCTP_STATIC int sctp_connect(struct sock *sk, struct sockaddr *addr, | 2910 | SCTP_STATIC int sctp_connect(struct sock *sk, struct sockaddr *addr, |
2911 | int addr_len) | 2911 | int addr_len) |
2912 | { | 2912 | { |
2913 | int err = 0; | 2913 | int err = 0; |
2914 | struct sctp_af *af; | 2914 | struct sctp_af *af; |
2915 | 2915 | ||
2916 | sctp_lock_sock(sk); | 2916 | sctp_lock_sock(sk); |
2917 | 2917 | ||
2918 | SCTP_DEBUG_PRINTK("%s - sk: %p, sockaddr: %p, addr_len: %d\n", | 2918 | SCTP_DEBUG_PRINTK("%s - sk: %p, sockaddr: %p, addr_len: %d\n", |
2919 | __FUNCTION__, sk, addr, addr_len); | 2919 | __FUNCTION__, sk, addr, addr_len); |
2920 | 2920 | ||
2921 | /* Validate addr_len before calling common connect/connectx routine. */ | 2921 | /* Validate addr_len before calling common connect/connectx routine. */ |
2922 | af = sctp_get_af_specific(addr->sa_family); | 2922 | af = sctp_get_af_specific(addr->sa_family); |
2923 | if (!af || addr_len < af->sockaddr_len) { | 2923 | if (!af || addr_len < af->sockaddr_len) { |
2924 | err = -EINVAL; | 2924 | err = -EINVAL; |
2925 | } else { | 2925 | } else { |
2926 | /* Pass correct addr len to common routine (so it knows there | 2926 | /* Pass correct addr len to common routine (so it knows there |
2927 | * is only one address being passed. | 2927 | * is only one address being passed. |
2928 | */ | 2928 | */ |
2929 | err = __sctp_connect(sk, addr, af->sockaddr_len); | 2929 | err = __sctp_connect(sk, addr, af->sockaddr_len); |
2930 | } | 2930 | } |
2931 | 2931 | ||
2932 | sctp_release_sock(sk); | 2932 | sctp_release_sock(sk); |
2933 | return err; | 2933 | return err; |
2934 | } | 2934 | } |
2935 | 2935 | ||
2936 | /* FIXME: Write comments. */ | 2936 | /* FIXME: Write comments. */ |
2937 | SCTP_STATIC int sctp_disconnect(struct sock *sk, int flags) | 2937 | SCTP_STATIC int sctp_disconnect(struct sock *sk, int flags) |
2938 | { | 2938 | { |
2939 | return -EOPNOTSUPP; /* STUB */ | 2939 | return -EOPNOTSUPP; /* STUB */ |
2940 | } | 2940 | } |
2941 | 2941 | ||
2942 | /* 4.1.4 accept() - TCP Style Syntax | 2942 | /* 4.1.4 accept() - TCP Style Syntax |
2943 | * | 2943 | * |
2944 | * Applications use accept() call to remove an established SCTP | 2944 | * Applications use accept() call to remove an established SCTP |
2945 | * association from the accept queue of the endpoint. A new socket | 2945 | * association from the accept queue of the endpoint. A new socket |
2946 | * descriptor will be returned from accept() to represent the newly | 2946 | * descriptor will be returned from accept() to represent the newly |
2947 | * formed association. | 2947 | * formed association. |
2948 | */ | 2948 | */ |
2949 | SCTP_STATIC struct sock *sctp_accept(struct sock *sk, int flags, int *err) | 2949 | SCTP_STATIC struct sock *sctp_accept(struct sock *sk, int flags, int *err) |
2950 | { | 2950 | { |
2951 | struct sctp_sock *sp; | 2951 | struct sctp_sock *sp; |
2952 | struct sctp_endpoint *ep; | 2952 | struct sctp_endpoint *ep; |
2953 | struct sock *newsk = NULL; | 2953 | struct sock *newsk = NULL; |
2954 | struct sctp_association *asoc; | 2954 | struct sctp_association *asoc; |
2955 | long timeo; | 2955 | long timeo; |
2956 | int error = 0; | 2956 | int error = 0; |
2957 | 2957 | ||
2958 | sctp_lock_sock(sk); | 2958 | sctp_lock_sock(sk); |
2959 | 2959 | ||
2960 | sp = sctp_sk(sk); | 2960 | sp = sctp_sk(sk); |
2961 | ep = sp->ep; | 2961 | ep = sp->ep; |
2962 | 2962 | ||
2963 | if (!sctp_style(sk, TCP)) { | 2963 | if (!sctp_style(sk, TCP)) { |
2964 | error = -EOPNOTSUPP; | 2964 | error = -EOPNOTSUPP; |
2965 | goto out; | 2965 | goto out; |
2966 | } | 2966 | } |
2967 | 2967 | ||
2968 | if (!sctp_sstate(sk, LISTENING)) { | 2968 | if (!sctp_sstate(sk, LISTENING)) { |
2969 | error = -EINVAL; | 2969 | error = -EINVAL; |
2970 | goto out; | 2970 | goto out; |
2971 | } | 2971 | } |
2972 | 2972 | ||
2973 | timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); | 2973 | timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); |
2974 | 2974 | ||
2975 | error = sctp_wait_for_accept(sk, timeo); | 2975 | error = sctp_wait_for_accept(sk, timeo); |
2976 | if (error) | 2976 | if (error) |
2977 | goto out; | 2977 | goto out; |
2978 | 2978 | ||
2979 | /* We treat the list of associations on the endpoint as the accept | 2979 | /* We treat the list of associations on the endpoint as the accept |
2980 | * queue and pick the first association on the list. | 2980 | * queue and pick the first association on the list. |
2981 | */ | 2981 | */ |
2982 | asoc = list_entry(ep->asocs.next, struct sctp_association, asocs); | 2982 | asoc = list_entry(ep->asocs.next, struct sctp_association, asocs); |
2983 | 2983 | ||
2984 | newsk = sp->pf->create_accept_sk(sk, asoc); | 2984 | newsk = sp->pf->create_accept_sk(sk, asoc); |
2985 | if (!newsk) { | 2985 | if (!newsk) { |
2986 | error = -ENOMEM; | 2986 | error = -ENOMEM; |
2987 | goto out; | 2987 | goto out; |
2988 | } | 2988 | } |
2989 | 2989 | ||
2990 | /* Populate the fields of the newsk from the oldsk and migrate the | 2990 | /* Populate the fields of the newsk from the oldsk and migrate the |
2991 | * asoc to the newsk. | 2991 | * asoc to the newsk. |
2992 | */ | 2992 | */ |
2993 | sctp_sock_migrate(sk, newsk, asoc, SCTP_SOCKET_TCP); | 2993 | sctp_sock_migrate(sk, newsk, asoc, SCTP_SOCKET_TCP); |
2994 | 2994 | ||
2995 | out: | 2995 | out: |
2996 | sctp_release_sock(sk); | 2996 | sctp_release_sock(sk); |
2997 | *err = error; | 2997 | *err = error; |
2998 | return newsk; | 2998 | return newsk; |
2999 | } | 2999 | } |
3000 | 3000 | ||
3001 | /* The SCTP ioctl handler. */ | 3001 | /* The SCTP ioctl handler. */ |
3002 | SCTP_STATIC int sctp_ioctl(struct sock *sk, int cmd, unsigned long arg) | 3002 | SCTP_STATIC int sctp_ioctl(struct sock *sk, int cmd, unsigned long arg) |
3003 | { | 3003 | { |
3004 | return -ENOIOCTLCMD; | 3004 | return -ENOIOCTLCMD; |
3005 | } | 3005 | } |
3006 | 3006 | ||
3007 | /* This is the function which gets called during socket creation to | 3007 | /* This is the function which gets called during socket creation to |
3008 | * initialized the SCTP-specific portion of the sock. | 3008 | * initialized the SCTP-specific portion of the sock. |
3009 | * The sock structure should already be zero-filled memory. | 3009 | * The sock structure should already be zero-filled memory. |
3010 | */ | 3010 | */ |
3011 | SCTP_STATIC int sctp_init_sock(struct sock *sk) | 3011 | SCTP_STATIC int sctp_init_sock(struct sock *sk) |
3012 | { | 3012 | { |
3013 | struct sctp_endpoint *ep; | 3013 | struct sctp_endpoint *ep; |
3014 | struct sctp_sock *sp; | 3014 | struct sctp_sock *sp; |
3015 | 3015 | ||
3016 | SCTP_DEBUG_PRINTK("sctp_init_sock(sk: %p)\n", sk); | 3016 | SCTP_DEBUG_PRINTK("sctp_init_sock(sk: %p)\n", sk); |
3017 | 3017 | ||
3018 | sp = sctp_sk(sk); | 3018 | sp = sctp_sk(sk); |
3019 | 3019 | ||
3020 | /* Initialize the SCTP per socket area. */ | 3020 | /* Initialize the SCTP per socket area. */ |
3021 | switch (sk->sk_type) { | 3021 | switch (sk->sk_type) { |
3022 | case SOCK_SEQPACKET: | 3022 | case SOCK_SEQPACKET: |
3023 | sp->type = SCTP_SOCKET_UDP; | 3023 | sp->type = SCTP_SOCKET_UDP; |
3024 | break; | 3024 | break; |
3025 | case SOCK_STREAM: | 3025 | case SOCK_STREAM: |
3026 | sp->type = SCTP_SOCKET_TCP; | 3026 | sp->type = SCTP_SOCKET_TCP; |
3027 | break; | 3027 | break; |
3028 | default: | 3028 | default: |
3029 | return -ESOCKTNOSUPPORT; | 3029 | return -ESOCKTNOSUPPORT; |
3030 | } | 3030 | } |
3031 | 3031 | ||
3032 | /* Initialize default send parameters. These parameters can be | 3032 | /* Initialize default send parameters. These parameters can be |
3033 | * modified with the SCTP_DEFAULT_SEND_PARAM socket option. | 3033 | * modified with the SCTP_DEFAULT_SEND_PARAM socket option. |
3034 | */ | 3034 | */ |
3035 | sp->default_stream = 0; | 3035 | sp->default_stream = 0; |
3036 | sp->default_ppid = 0; | 3036 | sp->default_ppid = 0; |
3037 | sp->default_flags = 0; | 3037 | sp->default_flags = 0; |
3038 | sp->default_context = 0; | 3038 | sp->default_context = 0; |
3039 | sp->default_timetolive = 0; | 3039 | sp->default_timetolive = 0; |
3040 | 3040 | ||
3041 | /* Initialize default setup parameters. These parameters | 3041 | /* Initialize default setup parameters. These parameters |
3042 | * can be modified with the SCTP_INITMSG socket option or | 3042 | * can be modified with the SCTP_INITMSG socket option or |
3043 | * overridden by the SCTP_INIT CMSG. | 3043 | * overridden by the SCTP_INIT CMSG. |
3044 | */ | 3044 | */ |
3045 | sp->initmsg.sinit_num_ostreams = sctp_max_outstreams; | 3045 | sp->initmsg.sinit_num_ostreams = sctp_max_outstreams; |
3046 | sp->initmsg.sinit_max_instreams = sctp_max_instreams; | 3046 | sp->initmsg.sinit_max_instreams = sctp_max_instreams; |
3047 | sp->initmsg.sinit_max_attempts = sctp_max_retrans_init; | 3047 | sp->initmsg.sinit_max_attempts = sctp_max_retrans_init; |
3048 | sp->initmsg.sinit_max_init_timeo = sctp_rto_max; | 3048 | sp->initmsg.sinit_max_init_timeo = sctp_rto_max; |
3049 | 3049 | ||
3050 | /* Initialize default RTO related parameters. These parameters can | 3050 | /* Initialize default RTO related parameters. These parameters can |
3051 | * be modified for with the SCTP_RTOINFO socket option. | 3051 | * be modified for with the SCTP_RTOINFO socket option. |
3052 | */ | 3052 | */ |
3053 | sp->rtoinfo.srto_initial = sctp_rto_initial; | 3053 | sp->rtoinfo.srto_initial = sctp_rto_initial; |
3054 | sp->rtoinfo.srto_max = sctp_rto_max; | 3054 | sp->rtoinfo.srto_max = sctp_rto_max; |
3055 | sp->rtoinfo.srto_min = sctp_rto_min; | 3055 | sp->rtoinfo.srto_min = sctp_rto_min; |
3056 | 3056 | ||
3057 | /* Initialize default association related parameters. These parameters | 3057 | /* Initialize default association related parameters. These parameters |
3058 | * can be modified with the SCTP_ASSOCINFO socket option. | 3058 | * can be modified with the SCTP_ASSOCINFO socket option. |
3059 | */ | 3059 | */ |
3060 | sp->assocparams.sasoc_asocmaxrxt = sctp_max_retrans_association; | 3060 | sp->assocparams.sasoc_asocmaxrxt = sctp_max_retrans_association; |
3061 | sp->assocparams.sasoc_number_peer_destinations = 0; | 3061 | sp->assocparams.sasoc_number_peer_destinations = 0; |
3062 | sp->assocparams.sasoc_peer_rwnd = 0; | 3062 | sp->assocparams.sasoc_peer_rwnd = 0; |
3063 | sp->assocparams.sasoc_local_rwnd = 0; | 3063 | sp->assocparams.sasoc_local_rwnd = 0; |
3064 | sp->assocparams.sasoc_cookie_life = sctp_valid_cookie_life; | 3064 | sp->assocparams.sasoc_cookie_life = sctp_valid_cookie_life; |
3065 | 3065 | ||
3066 | /* Initialize default event subscriptions. By default, all the | 3066 | /* Initialize default event subscriptions. By default, all the |
3067 | * options are off. | 3067 | * options are off. |
3068 | */ | 3068 | */ |
3069 | memset(&sp->subscribe, 0, sizeof(struct sctp_event_subscribe)); | 3069 | memset(&sp->subscribe, 0, sizeof(struct sctp_event_subscribe)); |
3070 | 3070 | ||
3071 | /* Default Peer Address Parameters. These defaults can | 3071 | /* Default Peer Address Parameters. These defaults can |
3072 | * be modified via SCTP_PEER_ADDR_PARAMS | 3072 | * be modified via SCTP_PEER_ADDR_PARAMS |
3073 | */ | 3073 | */ |
3074 | sp->hbinterval = sctp_hb_interval; | 3074 | sp->hbinterval = sctp_hb_interval; |
3075 | sp->pathmaxrxt = sctp_max_retrans_path; | 3075 | sp->pathmaxrxt = sctp_max_retrans_path; |
3076 | sp->pathmtu = 0; // allow default discovery | 3076 | sp->pathmtu = 0; // allow default discovery |
3077 | sp->sackdelay = sctp_sack_timeout; | 3077 | sp->sackdelay = sctp_sack_timeout; |
3078 | sp->param_flags = SPP_HB_ENABLE | | 3078 | sp->param_flags = SPP_HB_ENABLE | |
3079 | SPP_PMTUD_ENABLE | | 3079 | SPP_PMTUD_ENABLE | |
3080 | SPP_SACKDELAY_ENABLE; | 3080 | SPP_SACKDELAY_ENABLE; |
3081 | 3081 | ||
3082 | /* If enabled no SCTP message fragmentation will be performed. | 3082 | /* If enabled no SCTP message fragmentation will be performed. |
3083 | * Configure through SCTP_DISABLE_FRAGMENTS socket option. | 3083 | * Configure through SCTP_DISABLE_FRAGMENTS socket option. |
3084 | */ | 3084 | */ |
3085 | sp->disable_fragments = 0; | 3085 | sp->disable_fragments = 0; |
3086 | 3086 | ||
3087 | /* Turn on/off any Nagle-like algorithm. */ | 3087 | /* Turn on/off any Nagle-like algorithm. */ |
3088 | sp->nodelay = 1; | 3088 | sp->nodelay = 1; |
3089 | 3089 | ||
3090 | /* Enable by default. */ | 3090 | /* Enable by default. */ |
3091 | sp->v4mapped = 1; | 3091 | sp->v4mapped = 1; |
3092 | 3092 | ||
3093 | /* Auto-close idle associations after the configured | 3093 | /* Auto-close idle associations after the configured |
3094 | * number of seconds. A value of 0 disables this | 3094 | * number of seconds. A value of 0 disables this |
3095 | * feature. Configure through the SCTP_AUTOCLOSE socket option, | 3095 | * feature. Configure through the SCTP_AUTOCLOSE socket option, |
3096 | * for UDP-style sockets only. | 3096 | * for UDP-style sockets only. |
3097 | */ | 3097 | */ |
3098 | sp->autoclose = 0; | 3098 | sp->autoclose = 0; |
3099 | 3099 | ||
3100 | /* User specified fragmentation limit. */ | 3100 | /* User specified fragmentation limit. */ |
3101 | sp->user_frag = 0; | 3101 | sp->user_frag = 0; |
3102 | 3102 | ||
3103 | sp->adaption_ind = 0; | 3103 | sp->adaption_ind = 0; |
3104 | 3104 | ||
3105 | sp->pf = sctp_get_pf_specific(sk->sk_family); | 3105 | sp->pf = sctp_get_pf_specific(sk->sk_family); |
3106 | 3106 | ||
3107 | /* Control variables for partial data delivery. */ | 3107 | /* Control variables for partial data delivery. */ |
3108 | sp->pd_mode = 0; | 3108 | sp->pd_mode = 0; |
3109 | skb_queue_head_init(&sp->pd_lobby); | 3109 | skb_queue_head_init(&sp->pd_lobby); |
3110 | 3110 | ||
3111 | /* Create a per socket endpoint structure. Even if we | 3111 | /* Create a per socket endpoint structure. Even if we |
3112 | * change the data structure relationships, this may still | 3112 | * change the data structure relationships, this may still |
3113 | * be useful for storing pre-connect address information. | 3113 | * be useful for storing pre-connect address information. |
3114 | */ | 3114 | */ |
3115 | ep = sctp_endpoint_new(sk, GFP_KERNEL); | 3115 | ep = sctp_endpoint_new(sk, GFP_KERNEL); |
3116 | if (!ep) | 3116 | if (!ep) |
3117 | return -ENOMEM; | 3117 | return -ENOMEM; |
3118 | 3118 | ||
3119 | sp->ep = ep; | 3119 | sp->ep = ep; |
3120 | sp->hmac = NULL; | 3120 | sp->hmac = NULL; |
3121 | 3121 | ||
3122 | SCTP_DBG_OBJCNT_INC(sock); | 3122 | SCTP_DBG_OBJCNT_INC(sock); |
3123 | return 0; | 3123 | return 0; |
3124 | } | 3124 | } |
3125 | 3125 | ||
3126 | /* Cleanup any SCTP per socket resources. */ | 3126 | /* Cleanup any SCTP per socket resources. */ |
3127 | SCTP_STATIC int sctp_destroy_sock(struct sock *sk) | 3127 | SCTP_STATIC int sctp_destroy_sock(struct sock *sk) |
3128 | { | 3128 | { |
3129 | struct sctp_endpoint *ep; | 3129 | struct sctp_endpoint *ep; |
3130 | 3130 | ||
3131 | SCTP_DEBUG_PRINTK("sctp_destroy_sock(sk: %p)\n", sk); | 3131 | SCTP_DEBUG_PRINTK("sctp_destroy_sock(sk: %p)\n", sk); |
3132 | 3132 | ||
3133 | /* Release our hold on the endpoint. */ | 3133 | /* Release our hold on the endpoint. */ |
3134 | ep = sctp_sk(sk)->ep; | 3134 | ep = sctp_sk(sk)->ep; |
3135 | sctp_endpoint_free(ep); | 3135 | sctp_endpoint_free(ep); |
3136 | 3136 | ||
3137 | return 0; | 3137 | return 0; |
3138 | } | 3138 | } |
3139 | 3139 | ||
3140 | /* API 4.1.7 shutdown() - TCP Style Syntax | 3140 | /* API 4.1.7 shutdown() - TCP Style Syntax |
3141 | * int shutdown(int socket, int how); | 3141 | * int shutdown(int socket, int how); |
3142 | * | 3142 | * |
3143 | * sd - the socket descriptor of the association to be closed. | 3143 | * sd - the socket descriptor of the association to be closed. |
3144 | * how - Specifies the type of shutdown. The values are | 3144 | * how - Specifies the type of shutdown. The values are |
3145 | * as follows: | 3145 | * as follows: |
3146 | * SHUT_RD | 3146 | * SHUT_RD |
3147 | * Disables further receive operations. No SCTP | 3147 | * Disables further receive operations. No SCTP |
3148 | * protocol action is taken. | 3148 | * protocol action is taken. |
3149 | * SHUT_WR | 3149 | * SHUT_WR |
3150 | * Disables further send operations, and initiates | 3150 | * Disables further send operations, and initiates |
3151 | * the SCTP shutdown sequence. | 3151 | * the SCTP shutdown sequence. |
3152 | * SHUT_RDWR | 3152 | * SHUT_RDWR |
3153 | * Disables further send and receive operations | 3153 | * Disables further send and receive operations |
3154 | * and initiates the SCTP shutdown sequence. | 3154 | * and initiates the SCTP shutdown sequence. |
3155 | */ | 3155 | */ |
3156 | SCTP_STATIC void sctp_shutdown(struct sock *sk, int how) | 3156 | SCTP_STATIC void sctp_shutdown(struct sock *sk, int how) |
3157 | { | 3157 | { |
3158 | struct sctp_endpoint *ep; | 3158 | struct sctp_endpoint *ep; |
3159 | struct sctp_association *asoc; | 3159 | struct sctp_association *asoc; |
3160 | 3160 | ||
3161 | if (!sctp_style(sk, TCP)) | 3161 | if (!sctp_style(sk, TCP)) |
3162 | return; | 3162 | return; |
3163 | 3163 | ||
3164 | if (how & SEND_SHUTDOWN) { | 3164 | if (how & SEND_SHUTDOWN) { |
3165 | ep = sctp_sk(sk)->ep; | 3165 | ep = sctp_sk(sk)->ep; |
3166 | if (!list_empty(&ep->asocs)) { | 3166 | if (!list_empty(&ep->asocs)) { |
3167 | asoc = list_entry(ep->asocs.next, | 3167 | asoc = list_entry(ep->asocs.next, |
3168 | struct sctp_association, asocs); | 3168 | struct sctp_association, asocs); |
3169 | sctp_primitive_SHUTDOWN(asoc, NULL); | 3169 | sctp_primitive_SHUTDOWN(asoc, NULL); |
3170 | } | 3170 | } |
3171 | } | 3171 | } |
3172 | } | 3172 | } |
3173 | 3173 | ||
3174 | /* 7.2.1 Association Status (SCTP_STATUS) | 3174 | /* 7.2.1 Association Status (SCTP_STATUS) |
3175 | 3175 | ||
3176 | * Applications can retrieve current status information about an | 3176 | * Applications can retrieve current status information about an |
3177 | * association, including association state, peer receiver window size, | 3177 | * association, including association state, peer receiver window size, |
3178 | * number of unacked data chunks, and number of data chunks pending | 3178 | * number of unacked data chunks, and number of data chunks pending |
3179 | * receipt. This information is read-only. | 3179 | * receipt. This information is read-only. |
3180 | */ | 3180 | */ |
3181 | static int sctp_getsockopt_sctp_status(struct sock *sk, int len, | 3181 | static int sctp_getsockopt_sctp_status(struct sock *sk, int len, |
3182 | char __user *optval, | 3182 | char __user *optval, |
3183 | int __user *optlen) | 3183 | int __user *optlen) |
3184 | { | 3184 | { |
3185 | struct sctp_status status; | 3185 | struct sctp_status status; |
3186 | struct sctp_association *asoc = NULL; | 3186 | struct sctp_association *asoc = NULL; |
3187 | struct sctp_transport *transport; | 3187 | struct sctp_transport *transport; |
3188 | sctp_assoc_t associd; | 3188 | sctp_assoc_t associd; |
3189 | int retval = 0; | 3189 | int retval = 0; |
3190 | 3190 | ||
3191 | if (len != sizeof(status)) { | 3191 | if (len != sizeof(status)) { |
3192 | retval = -EINVAL; | 3192 | retval = -EINVAL; |
3193 | goto out; | 3193 | goto out; |
3194 | } | 3194 | } |
3195 | 3195 | ||
3196 | if (copy_from_user(&status, optval, sizeof(status))) { | 3196 | if (copy_from_user(&status, optval, sizeof(status))) { |
3197 | retval = -EFAULT; | 3197 | retval = -EFAULT; |
3198 | goto out; | 3198 | goto out; |
3199 | } | 3199 | } |
3200 | 3200 | ||
3201 | associd = status.sstat_assoc_id; | 3201 | associd = status.sstat_assoc_id; |
3202 | asoc = sctp_id2assoc(sk, associd); | 3202 | asoc = sctp_id2assoc(sk, associd); |
3203 | if (!asoc) { | 3203 | if (!asoc) { |
3204 | retval = -EINVAL; | 3204 | retval = -EINVAL; |
3205 | goto out; | 3205 | goto out; |
3206 | } | 3206 | } |
3207 | 3207 | ||
3208 | transport = asoc->peer.primary_path; | 3208 | transport = asoc->peer.primary_path; |
3209 | 3209 | ||
3210 | status.sstat_assoc_id = sctp_assoc2id(asoc); | 3210 | status.sstat_assoc_id = sctp_assoc2id(asoc); |
3211 | status.sstat_state = asoc->state; | 3211 | status.sstat_state = asoc->state; |
3212 | status.sstat_rwnd = asoc->peer.rwnd; | 3212 | status.sstat_rwnd = asoc->peer.rwnd; |
3213 | status.sstat_unackdata = asoc->unack_data; | 3213 | status.sstat_unackdata = asoc->unack_data; |
3214 | 3214 | ||
3215 | status.sstat_penddata = sctp_tsnmap_pending(&asoc->peer.tsn_map); | 3215 | status.sstat_penddata = sctp_tsnmap_pending(&asoc->peer.tsn_map); |
3216 | status.sstat_instrms = asoc->c.sinit_max_instreams; | 3216 | status.sstat_instrms = asoc->c.sinit_max_instreams; |
3217 | status.sstat_outstrms = asoc->c.sinit_num_ostreams; | 3217 | status.sstat_outstrms = asoc->c.sinit_num_ostreams; |
3218 | status.sstat_fragmentation_point = asoc->frag_point; | 3218 | status.sstat_fragmentation_point = asoc->frag_point; |
3219 | status.sstat_primary.spinfo_assoc_id = sctp_assoc2id(transport->asoc); | 3219 | status.sstat_primary.spinfo_assoc_id = sctp_assoc2id(transport->asoc); |
3220 | memcpy(&status.sstat_primary.spinfo_address, | 3220 | memcpy(&status.sstat_primary.spinfo_address, |
3221 | &(transport->ipaddr), sizeof(union sctp_addr)); | 3221 | &(transport->ipaddr), sizeof(union sctp_addr)); |
3222 | /* Map ipv4 address into v4-mapped-on-v6 address. */ | 3222 | /* Map ipv4 address into v4-mapped-on-v6 address. */ |
3223 | sctp_get_pf_specific(sk->sk_family)->addr_v4map(sctp_sk(sk), | 3223 | sctp_get_pf_specific(sk->sk_family)->addr_v4map(sctp_sk(sk), |
3224 | (union sctp_addr *)&status.sstat_primary.spinfo_address); | 3224 | (union sctp_addr *)&status.sstat_primary.spinfo_address); |
3225 | status.sstat_primary.spinfo_state = transport->state; | 3225 | status.sstat_primary.spinfo_state = transport->state; |
3226 | status.sstat_primary.spinfo_cwnd = transport->cwnd; | 3226 | status.sstat_primary.spinfo_cwnd = transport->cwnd; |
3227 | status.sstat_primary.spinfo_srtt = transport->srtt; | 3227 | status.sstat_primary.spinfo_srtt = transport->srtt; |
3228 | status.sstat_primary.spinfo_rto = jiffies_to_msecs(transport->rto); | 3228 | status.sstat_primary.spinfo_rto = jiffies_to_msecs(transport->rto); |
3229 | status.sstat_primary.spinfo_mtu = transport->pathmtu; | 3229 | status.sstat_primary.spinfo_mtu = transport->pathmtu; |
3230 | 3230 | ||
3231 | if (status.sstat_primary.spinfo_state == SCTP_UNKNOWN) | 3231 | if (status.sstat_primary.spinfo_state == SCTP_UNKNOWN) |
3232 | status.sstat_primary.spinfo_state = SCTP_ACTIVE; | 3232 | status.sstat_primary.spinfo_state = SCTP_ACTIVE; |
3233 | 3233 | ||
3234 | if (put_user(len, optlen)) { | 3234 | if (put_user(len, optlen)) { |
3235 | retval = -EFAULT; | 3235 | retval = -EFAULT; |
3236 | goto out; | 3236 | goto out; |
3237 | } | 3237 | } |
3238 | 3238 | ||
3239 | SCTP_DEBUG_PRINTK("sctp_getsockopt_sctp_status(%d): %d %d %d\n", | 3239 | SCTP_DEBUG_PRINTK("sctp_getsockopt_sctp_status(%d): %d %d %d\n", |
3240 | len, status.sstat_state, status.sstat_rwnd, | 3240 | len, status.sstat_state, status.sstat_rwnd, |
3241 | status.sstat_assoc_id); | 3241 | status.sstat_assoc_id); |
3242 | 3242 | ||
3243 | if (copy_to_user(optval, &status, len)) { | 3243 | if (copy_to_user(optval, &status, len)) { |
3244 | retval = -EFAULT; | 3244 | retval = -EFAULT; |
3245 | goto out; | 3245 | goto out; |
3246 | } | 3246 | } |
3247 | 3247 | ||
3248 | out: | 3248 | out: |
3249 | return (retval); | 3249 | return (retval); |
3250 | } | 3250 | } |
3251 | 3251 | ||
3252 | 3252 | ||
3253 | /* 7.2.2 Peer Address Information (SCTP_GET_PEER_ADDR_INFO) | 3253 | /* 7.2.2 Peer Address Information (SCTP_GET_PEER_ADDR_INFO) |
3254 | * | 3254 | * |
3255 | * Applications can retrieve information about a specific peer address | 3255 | * Applications can retrieve information about a specific peer address |
3256 | * of an association, including its reachability state, congestion | 3256 | * of an association, including its reachability state, congestion |
3257 | * window, and retransmission timer values. This information is | 3257 | * window, and retransmission timer values. This information is |
3258 | * read-only. | 3258 | * read-only. |
3259 | */ | 3259 | */ |
3260 | static int sctp_getsockopt_peer_addr_info(struct sock *sk, int len, | 3260 | static int sctp_getsockopt_peer_addr_info(struct sock *sk, int len, |
3261 | char __user *optval, | 3261 | char __user *optval, |
3262 | int __user *optlen) | 3262 | int __user *optlen) |
3263 | { | 3263 | { |
3264 | struct sctp_paddrinfo pinfo; | 3264 | struct sctp_paddrinfo pinfo; |
3265 | struct sctp_transport *transport; | 3265 | struct sctp_transport *transport; |
3266 | int retval = 0; | 3266 | int retval = 0; |
3267 | 3267 | ||
3268 | if (len != sizeof(pinfo)) { | 3268 | if (len != sizeof(pinfo)) { |
3269 | retval = -EINVAL; | 3269 | retval = -EINVAL; |
3270 | goto out; | 3270 | goto out; |
3271 | } | 3271 | } |
3272 | 3272 | ||
3273 | if (copy_from_user(&pinfo, optval, sizeof(pinfo))) { | 3273 | if (copy_from_user(&pinfo, optval, sizeof(pinfo))) { |
3274 | retval = -EFAULT; | 3274 | retval = -EFAULT; |
3275 | goto out; | 3275 | goto out; |
3276 | } | 3276 | } |
3277 | 3277 | ||
3278 | transport = sctp_addr_id2transport(sk, &pinfo.spinfo_address, | 3278 | transport = sctp_addr_id2transport(sk, &pinfo.spinfo_address, |
3279 | pinfo.spinfo_assoc_id); | 3279 | pinfo.spinfo_assoc_id); |
3280 | if (!transport) | 3280 | if (!transport) |
3281 | return -EINVAL; | 3281 | return -EINVAL; |
3282 | 3282 | ||
3283 | pinfo.spinfo_assoc_id = sctp_assoc2id(transport->asoc); | 3283 | pinfo.spinfo_assoc_id = sctp_assoc2id(transport->asoc); |
3284 | pinfo.spinfo_state = transport->state; | 3284 | pinfo.spinfo_state = transport->state; |
3285 | pinfo.spinfo_cwnd = transport->cwnd; | 3285 | pinfo.spinfo_cwnd = transport->cwnd; |
3286 | pinfo.spinfo_srtt = transport->srtt; | 3286 | pinfo.spinfo_srtt = transport->srtt; |
3287 | pinfo.spinfo_rto = jiffies_to_msecs(transport->rto); | 3287 | pinfo.spinfo_rto = jiffies_to_msecs(transport->rto); |
3288 | pinfo.spinfo_mtu = transport->pathmtu; | 3288 | pinfo.spinfo_mtu = transport->pathmtu; |
3289 | 3289 | ||
3290 | if (pinfo.spinfo_state == SCTP_UNKNOWN) | 3290 | if (pinfo.spinfo_state == SCTP_UNKNOWN) |
3291 | pinfo.spinfo_state = SCTP_ACTIVE; | 3291 | pinfo.spinfo_state = SCTP_ACTIVE; |
3292 | 3292 | ||
3293 | if (put_user(len, optlen)) { | 3293 | if (put_user(len, optlen)) { |
3294 | retval = -EFAULT; | 3294 | retval = -EFAULT; |
3295 | goto out; | 3295 | goto out; |
3296 | } | 3296 | } |
3297 | 3297 | ||
3298 | if (copy_to_user(optval, &pinfo, len)) { | 3298 | if (copy_to_user(optval, &pinfo, len)) { |
3299 | retval = -EFAULT; | 3299 | retval = -EFAULT; |
3300 | goto out; | 3300 | goto out; |
3301 | } | 3301 | } |
3302 | 3302 | ||
3303 | out: | 3303 | out: |
3304 | return (retval); | 3304 | return (retval); |
3305 | } | 3305 | } |
3306 | 3306 | ||
3307 | /* 7.1.12 Enable/Disable message fragmentation (SCTP_DISABLE_FRAGMENTS) | 3307 | /* 7.1.12 Enable/Disable message fragmentation (SCTP_DISABLE_FRAGMENTS) |
3308 | * | 3308 | * |
3309 | * This option is a on/off flag. If enabled no SCTP message | 3309 | * This option is a on/off flag. If enabled no SCTP message |
3310 | * fragmentation will be performed. Instead if a message being sent | 3310 | * fragmentation will be performed. Instead if a message being sent |
3311 | * exceeds the current PMTU size, the message will NOT be sent and | 3311 | * exceeds the current PMTU size, the message will NOT be sent and |
3312 | * instead a error will be indicated to the user. | 3312 | * instead a error will be indicated to the user. |
3313 | */ | 3313 | */ |
3314 | static int sctp_getsockopt_disable_fragments(struct sock *sk, int len, | 3314 | static int sctp_getsockopt_disable_fragments(struct sock *sk, int len, |
3315 | char __user *optval, int __user *optlen) | 3315 | char __user *optval, int __user *optlen) |
3316 | { | 3316 | { |
3317 | int val; | 3317 | int val; |
3318 | 3318 | ||
3319 | if (len < sizeof(int)) | 3319 | if (len < sizeof(int)) |
3320 | return -EINVAL; | 3320 | return -EINVAL; |
3321 | 3321 | ||
3322 | len = sizeof(int); | 3322 | len = sizeof(int); |
3323 | val = (sctp_sk(sk)->disable_fragments == 1); | 3323 | val = (sctp_sk(sk)->disable_fragments == 1); |
3324 | if (put_user(len, optlen)) | 3324 | if (put_user(len, optlen)) |
3325 | return -EFAULT; | 3325 | return -EFAULT; |
3326 | if (copy_to_user(optval, &val, len)) | 3326 | if (copy_to_user(optval, &val, len)) |
3327 | return -EFAULT; | 3327 | return -EFAULT; |
3328 | return 0; | 3328 | return 0; |
3329 | } | 3329 | } |
3330 | 3330 | ||
3331 | /* 7.1.15 Set notification and ancillary events (SCTP_EVENTS) | 3331 | /* 7.1.15 Set notification and ancillary events (SCTP_EVENTS) |
3332 | * | 3332 | * |
3333 | * This socket option is used to specify various notifications and | 3333 | * This socket option is used to specify various notifications and |
3334 | * ancillary data the user wishes to receive. | 3334 | * ancillary data the user wishes to receive. |
3335 | */ | 3335 | */ |
3336 | static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval, | 3336 | static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval, |
3337 | int __user *optlen) | 3337 | int __user *optlen) |
3338 | { | 3338 | { |
3339 | if (len != sizeof(struct sctp_event_subscribe)) | 3339 | if (len != sizeof(struct sctp_event_subscribe)) |
3340 | return -EINVAL; | 3340 | return -EINVAL; |
3341 | if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len)) | 3341 | if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len)) |
3342 | return -EFAULT; | 3342 | return -EFAULT; |
3343 | return 0; | 3343 | return 0; |
3344 | } | 3344 | } |
3345 | 3345 | ||
3346 | /* 7.1.8 Automatic Close of associations (SCTP_AUTOCLOSE) | 3346 | /* 7.1.8 Automatic Close of associations (SCTP_AUTOCLOSE) |
3347 | * | 3347 | * |
3348 | * This socket option is applicable to the UDP-style socket only. When | 3348 | * This socket option is applicable to the UDP-style socket only. When |
3349 | * set it will cause associations that are idle for more than the | 3349 | * set it will cause associations that are idle for more than the |
3350 | * specified number of seconds to automatically close. An association | 3350 | * specified number of seconds to automatically close. An association |
3351 | * being idle is defined an association that has NOT sent or received | 3351 | * being idle is defined an association that has NOT sent or received |
3352 | * user data. The special value of '0' indicates that no automatic | 3352 | * user data. The special value of '0' indicates that no automatic |
3353 | * close of any associations should be performed. The option expects an | 3353 | * close of any associations should be performed. The option expects an |
3354 | * integer defining the number of seconds of idle time before an | 3354 | * integer defining the number of seconds of idle time before an |
3355 | * association is closed. | 3355 | * association is closed. |
3356 | */ | 3356 | */ |
3357 | static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen) | 3357 | static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen) |
3358 | { | 3358 | { |
3359 | /* Applicable to UDP-style socket only */ | 3359 | /* Applicable to UDP-style socket only */ |
3360 | if (sctp_style(sk, TCP)) | 3360 | if (sctp_style(sk, TCP)) |
3361 | return -EOPNOTSUPP; | 3361 | return -EOPNOTSUPP; |
3362 | if (len != sizeof(int)) | 3362 | if (len != sizeof(int)) |
3363 | return -EINVAL; | 3363 | return -EINVAL; |
3364 | if (copy_to_user(optval, &sctp_sk(sk)->autoclose, len)) | 3364 | if (copy_to_user(optval, &sctp_sk(sk)->autoclose, len)) |
3365 | return -EFAULT; | 3365 | return -EFAULT; |
3366 | return 0; | 3366 | return 0; |
3367 | } | 3367 | } |
3368 | 3368 | ||
3369 | /* Helper routine to branch off an association to a new socket. */ | 3369 | /* Helper routine to branch off an association to a new socket. */ |
3370 | SCTP_STATIC int sctp_do_peeloff(struct sctp_association *asoc, | 3370 | SCTP_STATIC int sctp_do_peeloff(struct sctp_association *asoc, |
3371 | struct socket **sockp) | 3371 | struct socket **sockp) |
3372 | { | 3372 | { |
3373 | struct sock *sk = asoc->base.sk; | 3373 | struct sock *sk = asoc->base.sk; |
3374 | struct socket *sock; | 3374 | struct socket *sock; |
3375 | int err = 0; | 3375 | int err = 0; |
3376 | 3376 | ||
3377 | /* An association cannot be branched off from an already peeled-off | 3377 | /* An association cannot be branched off from an already peeled-off |
3378 | * socket, nor is this supported for tcp style sockets. | 3378 | * socket, nor is this supported for tcp style sockets. |
3379 | */ | 3379 | */ |
3380 | if (!sctp_style(sk, UDP)) | 3380 | if (!sctp_style(sk, UDP)) |
3381 | return -EINVAL; | 3381 | return -EINVAL; |
3382 | 3382 | ||
3383 | /* Create a new socket. */ | 3383 | /* Create a new socket. */ |
3384 | err = sock_create(sk->sk_family, SOCK_SEQPACKET, IPPROTO_SCTP, &sock); | 3384 | err = sock_create(sk->sk_family, SOCK_SEQPACKET, IPPROTO_SCTP, &sock); |
3385 | if (err < 0) | 3385 | if (err < 0) |
3386 | return err; | 3386 | return err; |
3387 | 3387 | ||
3388 | /* Populate the fields of the newsk from the oldsk and migrate the | 3388 | /* Populate the fields of the newsk from the oldsk and migrate the |
3389 | * asoc to the newsk. | 3389 | * asoc to the newsk. |
3390 | */ | 3390 | */ |
3391 | sctp_sock_migrate(sk, sock->sk, asoc, SCTP_SOCKET_UDP_HIGH_BANDWIDTH); | 3391 | sctp_sock_migrate(sk, sock->sk, asoc, SCTP_SOCKET_UDP_HIGH_BANDWIDTH); |
3392 | *sockp = sock; | 3392 | *sockp = sock; |
3393 | 3393 | ||
3394 | return err; | 3394 | return err; |
3395 | } | 3395 | } |
3396 | 3396 | ||
3397 | static int sctp_getsockopt_peeloff(struct sock *sk, int len, char __user *optval, int __user *optlen) | 3397 | static int sctp_getsockopt_peeloff(struct sock *sk, int len, char __user *optval, int __user *optlen) |
3398 | { | 3398 | { |
3399 | sctp_peeloff_arg_t peeloff; | 3399 | sctp_peeloff_arg_t peeloff; |
3400 | struct socket *newsock; | 3400 | struct socket *newsock; |
3401 | int retval = 0; | 3401 | int retval = 0; |
3402 | struct sctp_association *asoc; | 3402 | struct sctp_association *asoc; |
3403 | 3403 | ||
3404 | if (len != sizeof(sctp_peeloff_arg_t)) | 3404 | if (len != sizeof(sctp_peeloff_arg_t)) |
3405 | return -EINVAL; | 3405 | return -EINVAL; |
3406 | if (copy_from_user(&peeloff, optval, len)) | 3406 | if (copy_from_user(&peeloff, optval, len)) |
3407 | return -EFAULT; | 3407 | return -EFAULT; |
3408 | 3408 | ||
3409 | asoc = sctp_id2assoc(sk, peeloff.associd); | 3409 | asoc = sctp_id2assoc(sk, peeloff.associd); |
3410 | if (!asoc) { | 3410 | if (!asoc) { |
3411 | retval = -EINVAL; | 3411 | retval = -EINVAL; |
3412 | goto out; | 3412 | goto out; |
3413 | } | 3413 | } |
3414 | 3414 | ||
3415 | SCTP_DEBUG_PRINTK("%s: sk: %p asoc: %p\n", __FUNCTION__, sk, asoc); | 3415 | SCTP_DEBUG_PRINTK("%s: sk: %p asoc: %p\n", __FUNCTION__, sk, asoc); |
3416 | 3416 | ||
3417 | retval = sctp_do_peeloff(asoc, &newsock); | 3417 | retval = sctp_do_peeloff(asoc, &newsock); |
3418 | if (retval < 0) | 3418 | if (retval < 0) |
3419 | goto out; | 3419 | goto out; |
3420 | 3420 | ||
3421 | /* Map the socket to an unused fd that can be returned to the user. */ | 3421 | /* Map the socket to an unused fd that can be returned to the user. */ |
3422 | retval = sock_map_fd(newsock); | 3422 | retval = sock_map_fd(newsock); |
3423 | if (retval < 0) { | 3423 | if (retval < 0) { |
3424 | sock_release(newsock); | 3424 | sock_release(newsock); |
3425 | goto out; | 3425 | goto out; |
3426 | } | 3426 | } |
3427 | 3427 | ||
3428 | SCTP_DEBUG_PRINTK("%s: sk: %p asoc: %p newsk: %p sd: %d\n", | 3428 | SCTP_DEBUG_PRINTK("%s: sk: %p asoc: %p newsk: %p sd: %d\n", |
3429 | __FUNCTION__, sk, asoc, newsock->sk, retval); | 3429 | __FUNCTION__, sk, asoc, newsock->sk, retval); |
3430 | 3430 | ||
3431 | /* Return the fd mapped to the new socket. */ | 3431 | /* Return the fd mapped to the new socket. */ |
3432 | peeloff.sd = retval; | 3432 | peeloff.sd = retval; |
3433 | if (copy_to_user(optval, &peeloff, len)) | 3433 | if (copy_to_user(optval, &peeloff, len)) |
3434 | retval = -EFAULT; | 3434 | retval = -EFAULT; |
3435 | 3435 | ||
3436 | out: | 3436 | out: |
3437 | return retval; | 3437 | return retval; |
3438 | } | 3438 | } |
3439 | 3439 | ||
3440 | /* 7.1.13 Peer Address Parameters (SCTP_PEER_ADDR_PARAMS) | 3440 | /* 7.1.13 Peer Address Parameters (SCTP_PEER_ADDR_PARAMS) |
3441 | * | 3441 | * |
3442 | * Applications can enable or disable heartbeats for any peer address of | 3442 | * Applications can enable or disable heartbeats for any peer address of |
3443 | * an association, modify an address's heartbeat interval, force a | 3443 | * an association, modify an address's heartbeat interval, force a |
3444 | * heartbeat to be sent immediately, and adjust the address's maximum | 3444 | * heartbeat to be sent immediately, and adjust the address's maximum |
3445 | * number of retransmissions sent before an address is considered | 3445 | * number of retransmissions sent before an address is considered |
3446 | * unreachable. The following structure is used to access and modify an | 3446 | * unreachable. The following structure is used to access and modify an |
3447 | * address's parameters: | 3447 | * address's parameters: |
3448 | * | 3448 | * |
3449 | * struct sctp_paddrparams { | 3449 | * struct sctp_paddrparams { |
3450 | * sctp_assoc_t spp_assoc_id; | 3450 | * sctp_assoc_t spp_assoc_id; |
3451 | * struct sockaddr_storage spp_address; | 3451 | * struct sockaddr_storage spp_address; |
3452 | * uint32_t spp_hbinterval; | 3452 | * uint32_t spp_hbinterval; |
3453 | * uint16_t spp_pathmaxrxt; | 3453 | * uint16_t spp_pathmaxrxt; |
3454 | * uint32_t spp_pathmtu; | 3454 | * uint32_t spp_pathmtu; |
3455 | * uint32_t spp_sackdelay; | 3455 | * uint32_t spp_sackdelay; |
3456 | * uint32_t spp_flags; | 3456 | * uint32_t spp_flags; |
3457 | * }; | 3457 | * }; |
3458 | * | 3458 | * |
3459 | * spp_assoc_id - (one-to-many style socket) This is filled in the | 3459 | * spp_assoc_id - (one-to-many style socket) This is filled in the |
3460 | * application, and identifies the association for | 3460 | * application, and identifies the association for |
3461 | * this query. | 3461 | * this query. |
3462 | * spp_address - This specifies which address is of interest. | 3462 | * spp_address - This specifies which address is of interest. |
3463 | * spp_hbinterval - This contains the value of the heartbeat interval, | 3463 | * spp_hbinterval - This contains the value of the heartbeat interval, |
3464 | * in milliseconds. If a value of zero | 3464 | * in milliseconds. If a value of zero |
3465 | * is present in this field then no changes are to | 3465 | * is present in this field then no changes are to |
3466 | * be made to this parameter. | 3466 | * be made to this parameter. |
3467 | * spp_pathmaxrxt - This contains the maximum number of | 3467 | * spp_pathmaxrxt - This contains the maximum number of |
3468 | * retransmissions before this address shall be | 3468 | * retransmissions before this address shall be |
3469 | * considered unreachable. If a value of zero | 3469 | * considered unreachable. If a value of zero |
3470 | * is present in this field then no changes are to | 3470 | * is present in this field then no changes are to |
3471 | * be made to this parameter. | 3471 | * be made to this parameter. |
3472 | * spp_pathmtu - When Path MTU discovery is disabled the value | 3472 | * spp_pathmtu - When Path MTU discovery is disabled the value |
3473 | * specified here will be the "fixed" path mtu. | 3473 | * specified here will be the "fixed" path mtu. |
3474 | * Note that if the spp_address field is empty | 3474 | * Note that if the spp_address field is empty |
3475 | * then all associations on this address will | 3475 | * then all associations on this address will |
3476 | * have this fixed path mtu set upon them. | 3476 | * have this fixed path mtu set upon them. |
3477 | * | 3477 | * |
3478 | * spp_sackdelay - When delayed sack is enabled, this value specifies | 3478 | * spp_sackdelay - When delayed sack is enabled, this value specifies |
3479 | * the number of milliseconds that sacks will be delayed | 3479 | * the number of milliseconds that sacks will be delayed |
3480 | * for. This value will apply to all addresses of an | 3480 | * for. This value will apply to all addresses of an |
3481 | * association if the spp_address field is empty. Note | 3481 | * association if the spp_address field is empty. Note |
3482 | * also, that if delayed sack is enabled and this | 3482 | * also, that if delayed sack is enabled and this |
3483 | * value is set to 0, no change is made to the last | 3483 | * value is set to 0, no change is made to the last |
3484 | * recorded delayed sack timer value. | 3484 | * recorded delayed sack timer value. |
3485 | * | 3485 | * |
3486 | * spp_flags - These flags are used to control various features | 3486 | * spp_flags - These flags are used to control various features |
3487 | * on an association. The flag field may contain | 3487 | * on an association. The flag field may contain |
3488 | * zero or more of the following options. | 3488 | * zero or more of the following options. |
3489 | * | 3489 | * |
3490 | * SPP_HB_ENABLE - Enable heartbeats on the | 3490 | * SPP_HB_ENABLE - Enable heartbeats on the |
3491 | * specified address. Note that if the address | 3491 | * specified address. Note that if the address |
3492 | * field is empty all addresses for the association | 3492 | * field is empty all addresses for the association |
3493 | * have heartbeats enabled upon them. | 3493 | * have heartbeats enabled upon them. |
3494 | * | 3494 | * |
3495 | * SPP_HB_DISABLE - Disable heartbeats on the | 3495 | * SPP_HB_DISABLE - Disable heartbeats on the |
3496 | * speicifed address. Note that if the address | 3496 | * speicifed address. Note that if the address |
3497 | * field is empty all addresses for the association | 3497 | * field is empty all addresses for the association |
3498 | * will have their heartbeats disabled. Note also | 3498 | * will have their heartbeats disabled. Note also |
3499 | * that SPP_HB_ENABLE and SPP_HB_DISABLE are | 3499 | * that SPP_HB_ENABLE and SPP_HB_DISABLE are |
3500 | * mutually exclusive, only one of these two should | 3500 | * mutually exclusive, only one of these two should |
3501 | * be specified. Enabling both fields will have | 3501 | * be specified. Enabling both fields will have |
3502 | * undetermined results. | 3502 | * undetermined results. |
3503 | * | 3503 | * |
3504 | * SPP_HB_DEMAND - Request a user initiated heartbeat | 3504 | * SPP_HB_DEMAND - Request a user initiated heartbeat |
3505 | * to be made immediately. | 3505 | * to be made immediately. |
3506 | * | 3506 | * |
3507 | * SPP_PMTUD_ENABLE - This field will enable PMTU | 3507 | * SPP_PMTUD_ENABLE - This field will enable PMTU |
3508 | * discovery upon the specified address. Note that | 3508 | * discovery upon the specified address. Note that |
3509 | * if the address feild is empty then all addresses | 3509 | * if the address feild is empty then all addresses |
3510 | * on the association are effected. | 3510 | * on the association are effected. |
3511 | * | 3511 | * |
3512 | * SPP_PMTUD_DISABLE - This field will disable PMTU | 3512 | * SPP_PMTUD_DISABLE - This field will disable PMTU |
3513 | * discovery upon the specified address. Note that | 3513 | * discovery upon the specified address. Note that |
3514 | * if the address feild is empty then all addresses | 3514 | * if the address feild is empty then all addresses |
3515 | * on the association are effected. Not also that | 3515 | * on the association are effected. Not also that |
3516 | * SPP_PMTUD_ENABLE and SPP_PMTUD_DISABLE are mutually | 3516 | * SPP_PMTUD_ENABLE and SPP_PMTUD_DISABLE are mutually |
3517 | * exclusive. Enabling both will have undetermined | 3517 | * exclusive. Enabling both will have undetermined |
3518 | * results. | 3518 | * results. |
3519 | * | 3519 | * |
3520 | * SPP_SACKDELAY_ENABLE - Setting this flag turns | 3520 | * SPP_SACKDELAY_ENABLE - Setting this flag turns |
3521 | * on delayed sack. The time specified in spp_sackdelay | 3521 | * on delayed sack. The time specified in spp_sackdelay |
3522 | * is used to specify the sack delay for this address. Note | 3522 | * is used to specify the sack delay for this address. Note |
3523 | * that if spp_address is empty then all addresses will | 3523 | * that if spp_address is empty then all addresses will |
3524 | * enable delayed sack and take on the sack delay | 3524 | * enable delayed sack and take on the sack delay |
3525 | * value specified in spp_sackdelay. | 3525 | * value specified in spp_sackdelay. |
3526 | * SPP_SACKDELAY_DISABLE - Setting this flag turns | 3526 | * SPP_SACKDELAY_DISABLE - Setting this flag turns |
3527 | * off delayed sack. If the spp_address field is blank then | 3527 | * off delayed sack. If the spp_address field is blank then |
3528 | * delayed sack is disabled for the entire association. Note | 3528 | * delayed sack is disabled for the entire association. Note |
3529 | * also that this field is mutually exclusive to | 3529 | * also that this field is mutually exclusive to |
3530 | * SPP_SACKDELAY_ENABLE, setting both will have undefined | 3530 | * SPP_SACKDELAY_ENABLE, setting both will have undefined |
3531 | * results. | 3531 | * results. |
3532 | */ | 3532 | */ |
3533 | static int sctp_getsockopt_peer_addr_params(struct sock *sk, int len, | 3533 | static int sctp_getsockopt_peer_addr_params(struct sock *sk, int len, |
3534 | char __user *optval, int __user *optlen) | 3534 | char __user *optval, int __user *optlen) |
3535 | { | 3535 | { |
3536 | struct sctp_paddrparams params; | 3536 | struct sctp_paddrparams params; |
3537 | struct sctp_transport *trans = NULL; | 3537 | struct sctp_transport *trans = NULL; |
3538 | struct sctp_association *asoc = NULL; | 3538 | struct sctp_association *asoc = NULL; |
3539 | struct sctp_sock *sp = sctp_sk(sk); | 3539 | struct sctp_sock *sp = sctp_sk(sk); |
3540 | 3540 | ||
3541 | if (len != sizeof(struct sctp_paddrparams)) | 3541 | if (len != sizeof(struct sctp_paddrparams)) |
3542 | return -EINVAL; | 3542 | return -EINVAL; |
3543 | 3543 | ||
3544 | if (copy_from_user(¶ms, optval, len)) | 3544 | if (copy_from_user(¶ms, optval, len)) |
3545 | return -EFAULT; | 3545 | return -EFAULT; |
3546 | 3546 | ||
3547 | /* If an address other than INADDR_ANY is specified, and | 3547 | /* If an address other than INADDR_ANY is specified, and |
3548 | * no transport is found, then the request is invalid. | 3548 | * no transport is found, then the request is invalid. |
3549 | */ | 3549 | */ |
3550 | if (!sctp_is_any(( union sctp_addr *)¶ms.spp_address)) { | 3550 | if (!sctp_is_any(( union sctp_addr *)¶ms.spp_address)) { |
3551 | trans = sctp_addr_id2transport(sk, ¶ms.spp_address, | 3551 | trans = sctp_addr_id2transport(sk, ¶ms.spp_address, |
3552 | params.spp_assoc_id); | 3552 | params.spp_assoc_id); |
3553 | if (!trans) { | 3553 | if (!trans) { |
3554 | SCTP_DEBUG_PRINTK("Failed no transport\n"); | 3554 | SCTP_DEBUG_PRINTK("Failed no transport\n"); |
3555 | return -EINVAL; | 3555 | return -EINVAL; |
3556 | } | 3556 | } |
3557 | } | 3557 | } |
3558 | 3558 | ||
3559 | /* Get association, if assoc_id != 0 and the socket is a one | 3559 | /* Get association, if assoc_id != 0 and the socket is a one |
3560 | * to many style socket, and an association was not found, then | 3560 | * to many style socket, and an association was not found, then |
3561 | * the id was invalid. | 3561 | * the id was invalid. |
3562 | */ | 3562 | */ |
3563 | asoc = sctp_id2assoc(sk, params.spp_assoc_id); | 3563 | asoc = sctp_id2assoc(sk, params.spp_assoc_id); |
3564 | if (!asoc && params.spp_assoc_id && sctp_style(sk, UDP)) { | 3564 | if (!asoc && params.spp_assoc_id && sctp_style(sk, UDP)) { |
3565 | SCTP_DEBUG_PRINTK("Failed no association\n"); | 3565 | SCTP_DEBUG_PRINTK("Failed no association\n"); |
3566 | return -EINVAL; | 3566 | return -EINVAL; |
3567 | } | 3567 | } |
3568 | 3568 | ||
3569 | if (trans) { | 3569 | if (trans) { |
3570 | /* Fetch transport values. */ | 3570 | /* Fetch transport values. */ |
3571 | params.spp_hbinterval = jiffies_to_msecs(trans->hbinterval); | 3571 | params.spp_hbinterval = jiffies_to_msecs(trans->hbinterval); |
3572 | params.spp_pathmtu = trans->pathmtu; | 3572 | params.spp_pathmtu = trans->pathmtu; |
3573 | params.spp_pathmaxrxt = trans->pathmaxrxt; | 3573 | params.spp_pathmaxrxt = trans->pathmaxrxt; |
3574 | params.spp_sackdelay = jiffies_to_msecs(trans->sackdelay); | 3574 | params.spp_sackdelay = jiffies_to_msecs(trans->sackdelay); |
3575 | 3575 | ||
3576 | /*draft-11 doesn't say what to return in spp_flags*/ | 3576 | /*draft-11 doesn't say what to return in spp_flags*/ |
3577 | params.spp_flags = trans->param_flags; | 3577 | params.spp_flags = trans->param_flags; |
3578 | } else if (asoc) { | 3578 | } else if (asoc) { |
3579 | /* Fetch association values. */ | 3579 | /* Fetch association values. */ |
3580 | params.spp_hbinterval = jiffies_to_msecs(asoc->hbinterval); | 3580 | params.spp_hbinterval = jiffies_to_msecs(asoc->hbinterval); |
3581 | params.spp_pathmtu = asoc->pathmtu; | 3581 | params.spp_pathmtu = asoc->pathmtu; |
3582 | params.spp_pathmaxrxt = asoc->pathmaxrxt; | 3582 | params.spp_pathmaxrxt = asoc->pathmaxrxt; |
3583 | params.spp_sackdelay = jiffies_to_msecs(asoc->sackdelay); | 3583 | params.spp_sackdelay = jiffies_to_msecs(asoc->sackdelay); |
3584 | 3584 | ||
3585 | /*draft-11 doesn't say what to return in spp_flags*/ | 3585 | /*draft-11 doesn't say what to return in spp_flags*/ |
3586 | params.spp_flags = asoc->param_flags; | 3586 | params.spp_flags = asoc->param_flags; |
3587 | } else { | 3587 | } else { |
3588 | /* Fetch socket values. */ | 3588 | /* Fetch socket values. */ |
3589 | params.spp_hbinterval = sp->hbinterval; | 3589 | params.spp_hbinterval = sp->hbinterval; |
3590 | params.spp_pathmtu = sp->pathmtu; | 3590 | params.spp_pathmtu = sp->pathmtu; |
3591 | params.spp_sackdelay = sp->sackdelay; | 3591 | params.spp_sackdelay = sp->sackdelay; |
3592 | params.spp_pathmaxrxt = sp->pathmaxrxt; | 3592 | params.spp_pathmaxrxt = sp->pathmaxrxt; |
3593 | 3593 | ||
3594 | /*draft-11 doesn't say what to return in spp_flags*/ | 3594 | /*draft-11 doesn't say what to return in spp_flags*/ |
3595 | params.spp_flags = sp->param_flags; | 3595 | params.spp_flags = sp->param_flags; |
3596 | } | 3596 | } |
3597 | 3597 | ||
3598 | if (copy_to_user(optval, ¶ms, len)) | 3598 | if (copy_to_user(optval, ¶ms, len)) |
3599 | return -EFAULT; | 3599 | return -EFAULT; |
3600 | 3600 | ||
3601 | if (put_user(len, optlen)) | 3601 | if (put_user(len, optlen)) |
3602 | return -EFAULT; | 3602 | return -EFAULT; |
3603 | 3603 | ||
3604 | return 0; | 3604 | return 0; |
3605 | } | 3605 | } |
3606 | 3606 | ||
3607 | /* 7.1.24. Delayed Ack Timer (SCTP_DELAYED_ACK_TIME) | 3607 | /* 7.1.24. Delayed Ack Timer (SCTP_DELAYED_ACK_TIME) |
3608 | * | 3608 | * |
3609 | * This options will get or set the delayed ack timer. The time is set | 3609 | * This options will get or set the delayed ack timer. The time is set |
3610 | * in milliseconds. If the assoc_id is 0, then this sets or gets the | 3610 | * in milliseconds. If the assoc_id is 0, then this sets or gets the |
3611 | * endpoints default delayed ack timer value. If the assoc_id field is | 3611 | * endpoints default delayed ack timer value. If the assoc_id field is |
3612 | * non-zero, then the set or get effects the specified association. | 3612 | * non-zero, then the set or get effects the specified association. |
3613 | * | 3613 | * |
3614 | * struct sctp_assoc_value { | 3614 | * struct sctp_assoc_value { |
3615 | * sctp_assoc_t assoc_id; | 3615 | * sctp_assoc_t assoc_id; |
3616 | * uint32_t assoc_value; | 3616 | * uint32_t assoc_value; |
3617 | * }; | 3617 | * }; |
3618 | * | 3618 | * |
3619 | * assoc_id - This parameter, indicates which association the | 3619 | * assoc_id - This parameter, indicates which association the |
3620 | * user is preforming an action upon. Note that if | 3620 | * user is preforming an action upon. Note that if |
3621 | * this field's value is zero then the endpoints | 3621 | * this field's value is zero then the endpoints |
3622 | * default value is changed (effecting future | 3622 | * default value is changed (effecting future |
3623 | * associations only). | 3623 | * associations only). |
3624 | * | 3624 | * |
3625 | * assoc_value - This parameter contains the number of milliseconds | 3625 | * assoc_value - This parameter contains the number of milliseconds |
3626 | * that the user is requesting the delayed ACK timer | 3626 | * that the user is requesting the delayed ACK timer |
3627 | * be set to. Note that this value is defined in | 3627 | * be set to. Note that this value is defined in |
3628 | * the standard to be between 200 and 500 milliseconds. | 3628 | * the standard to be between 200 and 500 milliseconds. |
3629 | * | 3629 | * |
3630 | * Note: a value of zero will leave the value alone, | 3630 | * Note: a value of zero will leave the value alone, |
3631 | * but disable SACK delay. A non-zero value will also | 3631 | * but disable SACK delay. A non-zero value will also |
3632 | * enable SACK delay. | 3632 | * enable SACK delay. |
3633 | */ | 3633 | */ |
3634 | static int sctp_getsockopt_delayed_ack_time(struct sock *sk, int len, | 3634 | static int sctp_getsockopt_delayed_ack_time(struct sock *sk, int len, |
3635 | char __user *optval, | 3635 | char __user *optval, |
3636 | int __user *optlen) | 3636 | int __user *optlen) |
3637 | { | 3637 | { |
3638 | struct sctp_assoc_value params; | 3638 | struct sctp_assoc_value params; |
3639 | struct sctp_association *asoc = NULL; | 3639 | struct sctp_association *asoc = NULL; |
3640 | struct sctp_sock *sp = sctp_sk(sk); | 3640 | struct sctp_sock *sp = sctp_sk(sk); |
3641 | 3641 | ||
3642 | if (len != sizeof(struct sctp_assoc_value)) | 3642 | if (len != sizeof(struct sctp_assoc_value)) |
3643 | return - EINVAL; | 3643 | return - EINVAL; |
3644 | 3644 | ||
3645 | if (copy_from_user(¶ms, optval, len)) | 3645 | if (copy_from_user(¶ms, optval, len)) |
3646 | return -EFAULT; | 3646 | return -EFAULT; |
3647 | 3647 | ||
3648 | /* Get association, if assoc_id != 0 and the socket is a one | 3648 | /* Get association, if assoc_id != 0 and the socket is a one |
3649 | * to many style socket, and an association was not found, then | 3649 | * to many style socket, and an association was not found, then |
3650 | * the id was invalid. | 3650 | * the id was invalid. |
3651 | */ | 3651 | */ |
3652 | asoc = sctp_id2assoc(sk, params.assoc_id); | 3652 | asoc = sctp_id2assoc(sk, params.assoc_id); |
3653 | if (!asoc && params.assoc_id && sctp_style(sk, UDP)) | 3653 | if (!asoc && params.assoc_id && sctp_style(sk, UDP)) |
3654 | return -EINVAL; | 3654 | return -EINVAL; |
3655 | 3655 | ||
3656 | if (asoc) { | 3656 | if (asoc) { |
3657 | /* Fetch association values. */ | 3657 | /* Fetch association values. */ |
3658 | if (asoc->param_flags & SPP_SACKDELAY_ENABLE) | 3658 | if (asoc->param_flags & SPP_SACKDELAY_ENABLE) |
3659 | params.assoc_value = jiffies_to_msecs( | 3659 | params.assoc_value = jiffies_to_msecs( |
3660 | asoc->sackdelay); | 3660 | asoc->sackdelay); |
3661 | else | 3661 | else |
3662 | params.assoc_value = 0; | 3662 | params.assoc_value = 0; |
3663 | } else { | 3663 | } else { |
3664 | /* Fetch socket values. */ | 3664 | /* Fetch socket values. */ |
3665 | if (sp->param_flags & SPP_SACKDELAY_ENABLE) | 3665 | if (sp->param_flags & SPP_SACKDELAY_ENABLE) |
3666 | params.assoc_value = sp->sackdelay; | 3666 | params.assoc_value = sp->sackdelay; |
3667 | else | 3667 | else |
3668 | params.assoc_value = 0; | 3668 | params.assoc_value = 0; |
3669 | } | 3669 | } |
3670 | 3670 | ||
3671 | if (copy_to_user(optval, ¶ms, len)) | 3671 | if (copy_to_user(optval, ¶ms, len)) |
3672 | return -EFAULT; | 3672 | return -EFAULT; |
3673 | 3673 | ||
3674 | if (put_user(len, optlen)) | 3674 | if (put_user(len, optlen)) |
3675 | return -EFAULT; | 3675 | return -EFAULT; |
3676 | 3676 | ||
3677 | return 0; | 3677 | return 0; |
3678 | } | 3678 | } |
3679 | 3679 | ||
3680 | /* 7.1.3 Initialization Parameters (SCTP_INITMSG) | 3680 | /* 7.1.3 Initialization Parameters (SCTP_INITMSG) |
3681 | * | 3681 | * |
3682 | * Applications can specify protocol parameters for the default association | 3682 | * Applications can specify protocol parameters for the default association |
3683 | * initialization. The option name argument to setsockopt() and getsockopt() | 3683 | * initialization. The option name argument to setsockopt() and getsockopt() |
3684 | * is SCTP_INITMSG. | 3684 | * is SCTP_INITMSG. |
3685 | * | 3685 | * |
3686 | * Setting initialization parameters is effective only on an unconnected | 3686 | * Setting initialization parameters is effective only on an unconnected |
3687 | * socket (for UDP-style sockets only future associations are effected | 3687 | * socket (for UDP-style sockets only future associations are effected |
3688 | * by the change). With TCP-style sockets, this option is inherited by | 3688 | * by the change). With TCP-style sockets, this option is inherited by |
3689 | * sockets derived from a listener socket. | 3689 | * sockets derived from a listener socket. |
3690 | */ | 3690 | */ |
3691 | static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen) | 3691 | static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen) |
3692 | { | 3692 | { |
3693 | if (len != sizeof(struct sctp_initmsg)) | 3693 | if (len != sizeof(struct sctp_initmsg)) |
3694 | return -EINVAL; | 3694 | return -EINVAL; |
3695 | if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len)) | 3695 | if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len)) |
3696 | return -EFAULT; | 3696 | return -EFAULT; |
3697 | return 0; | 3697 | return 0; |
3698 | } | 3698 | } |
3699 | 3699 | ||
3700 | static int sctp_getsockopt_peer_addrs_num_old(struct sock *sk, int len, | 3700 | static int sctp_getsockopt_peer_addrs_num_old(struct sock *sk, int len, |
3701 | char __user *optval, | 3701 | char __user *optval, |
3702 | int __user *optlen) | 3702 | int __user *optlen) |
3703 | { | 3703 | { |
3704 | sctp_assoc_t id; | 3704 | sctp_assoc_t id; |
3705 | struct sctp_association *asoc; | 3705 | struct sctp_association *asoc; |
3706 | struct list_head *pos; | 3706 | struct list_head *pos; |
3707 | int cnt = 0; | 3707 | int cnt = 0; |
3708 | 3708 | ||
3709 | if (len != sizeof(sctp_assoc_t)) | 3709 | if (len != sizeof(sctp_assoc_t)) |
3710 | return -EINVAL; | 3710 | return -EINVAL; |
3711 | 3711 | ||
3712 | if (copy_from_user(&id, optval, sizeof(sctp_assoc_t))) | 3712 | if (copy_from_user(&id, optval, sizeof(sctp_assoc_t))) |
3713 | return -EFAULT; | 3713 | return -EFAULT; |
3714 | 3714 | ||
3715 | /* For UDP-style sockets, id specifies the association to query. */ | 3715 | /* For UDP-style sockets, id specifies the association to query. */ |
3716 | asoc = sctp_id2assoc(sk, id); | 3716 | asoc = sctp_id2assoc(sk, id); |
3717 | if (!asoc) | 3717 | if (!asoc) |
3718 | return -EINVAL; | 3718 | return -EINVAL; |
3719 | 3719 | ||
3720 | list_for_each(pos, &asoc->peer.transport_addr_list) { | 3720 | list_for_each(pos, &asoc->peer.transport_addr_list) { |
3721 | cnt ++; | 3721 | cnt ++; |
3722 | } | 3722 | } |
3723 | 3723 | ||
3724 | return cnt; | 3724 | return cnt; |
3725 | } | 3725 | } |
3726 | 3726 | ||
3727 | /* | 3727 | /* |
3728 | * Old API for getting list of peer addresses. Does not work for 32-bit | 3728 | * Old API for getting list of peer addresses. Does not work for 32-bit |
3729 | * programs running on a 64-bit kernel | 3729 | * programs running on a 64-bit kernel |
3730 | */ | 3730 | */ |
3731 | static int sctp_getsockopt_peer_addrs_old(struct sock *sk, int len, | 3731 | static int sctp_getsockopt_peer_addrs_old(struct sock *sk, int len, |
3732 | char __user *optval, | 3732 | char __user *optval, |
3733 | int __user *optlen) | 3733 | int __user *optlen) |
3734 | { | 3734 | { |
3735 | struct sctp_association *asoc; | 3735 | struct sctp_association *asoc; |
3736 | struct list_head *pos; | 3736 | struct list_head *pos; |
3737 | int cnt = 0; | 3737 | int cnt = 0; |
3738 | struct sctp_getaddrs_old getaddrs; | 3738 | struct sctp_getaddrs_old getaddrs; |
3739 | struct sctp_transport *from; | 3739 | struct sctp_transport *from; |
3740 | void __user *to; | 3740 | void __user *to; |
3741 | union sctp_addr temp; | 3741 | union sctp_addr temp; |
3742 | struct sctp_sock *sp = sctp_sk(sk); | 3742 | struct sctp_sock *sp = sctp_sk(sk); |
3743 | int addrlen; | 3743 | int addrlen; |
3744 | 3744 | ||
3745 | if (len != sizeof(struct sctp_getaddrs_old)) | 3745 | if (len != sizeof(struct sctp_getaddrs_old)) |
3746 | return -EINVAL; | 3746 | return -EINVAL; |
3747 | 3747 | ||
3748 | if (copy_from_user(&getaddrs, optval, sizeof(struct sctp_getaddrs_old))) | 3748 | if (copy_from_user(&getaddrs, optval, sizeof(struct sctp_getaddrs_old))) |
3749 | return -EFAULT; | 3749 | return -EFAULT; |
3750 | 3750 | ||
3751 | if (getaddrs.addr_num <= 0) return -EINVAL; | 3751 | if (getaddrs.addr_num <= 0) return -EINVAL; |
3752 | 3752 | ||
3753 | /* For UDP-style sockets, id specifies the association to query. */ | 3753 | /* For UDP-style sockets, id specifies the association to query. */ |
3754 | asoc = sctp_id2assoc(sk, getaddrs.assoc_id); | 3754 | asoc = sctp_id2assoc(sk, getaddrs.assoc_id); |
3755 | if (!asoc) | 3755 | if (!asoc) |
3756 | return -EINVAL; | 3756 | return -EINVAL; |
3757 | 3757 | ||
3758 | to = (void __user *)getaddrs.addrs; | 3758 | to = (void __user *)getaddrs.addrs; |
3759 | list_for_each(pos, &asoc->peer.transport_addr_list) { | 3759 | list_for_each(pos, &asoc->peer.transport_addr_list) { |
3760 | from = list_entry(pos, struct sctp_transport, transports); | 3760 | from = list_entry(pos, struct sctp_transport, transports); |
3761 | memcpy(&temp, &from->ipaddr, sizeof(temp)); | 3761 | memcpy(&temp, &from->ipaddr, sizeof(temp)); |
3762 | sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, &temp); | 3762 | sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, &temp); |
3763 | addrlen = sctp_get_af_specific(sk->sk_family)->sockaddr_len; | 3763 | addrlen = sctp_get_af_specific(sk->sk_family)->sockaddr_len; |
3764 | temp.v4.sin_port = htons(temp.v4.sin_port); | 3764 | temp.v4.sin_port = htons(temp.v4.sin_port); |
3765 | if (copy_to_user(to, &temp, addrlen)) | 3765 | if (copy_to_user(to, &temp, addrlen)) |
3766 | return -EFAULT; | 3766 | return -EFAULT; |
3767 | to += addrlen ; | 3767 | to += addrlen ; |
3768 | cnt ++; | 3768 | cnt ++; |
3769 | if (cnt >= getaddrs.addr_num) break; | 3769 | if (cnt >= getaddrs.addr_num) break; |
3770 | } | 3770 | } |
3771 | getaddrs.addr_num = cnt; | 3771 | getaddrs.addr_num = cnt; |
3772 | if (copy_to_user(optval, &getaddrs, sizeof(struct sctp_getaddrs_old))) | 3772 | if (copy_to_user(optval, &getaddrs, sizeof(struct sctp_getaddrs_old))) |
3773 | return -EFAULT; | 3773 | return -EFAULT; |
3774 | 3774 | ||
3775 | return 0; | 3775 | return 0; |
3776 | } | 3776 | } |
3777 | 3777 | ||
3778 | static int sctp_getsockopt_peer_addrs(struct sock *sk, int len, | 3778 | static int sctp_getsockopt_peer_addrs(struct sock *sk, int len, |
3779 | char __user *optval, int __user *optlen) | 3779 | char __user *optval, int __user *optlen) |
3780 | { | 3780 | { |
3781 | struct sctp_association *asoc; | 3781 | struct sctp_association *asoc; |
3782 | struct list_head *pos; | 3782 | struct list_head *pos; |
3783 | int cnt = 0; | 3783 | int cnt = 0; |
3784 | struct sctp_getaddrs getaddrs; | 3784 | struct sctp_getaddrs getaddrs; |
3785 | struct sctp_transport *from; | 3785 | struct sctp_transport *from; |
3786 | void __user *to; | 3786 | void __user *to; |
3787 | union sctp_addr temp; | 3787 | union sctp_addr temp; |
3788 | struct sctp_sock *sp = sctp_sk(sk); | 3788 | struct sctp_sock *sp = sctp_sk(sk); |
3789 | int addrlen; | 3789 | int addrlen; |
3790 | size_t space_left; | 3790 | size_t space_left; |
3791 | int bytes_copied; | 3791 | int bytes_copied; |
3792 | 3792 | ||
3793 | if (len < sizeof(struct sctp_getaddrs)) | 3793 | if (len < sizeof(struct sctp_getaddrs)) |
3794 | return -EINVAL; | 3794 | return -EINVAL; |
3795 | 3795 | ||
3796 | if (copy_from_user(&getaddrs, optval, sizeof(struct sctp_getaddrs))) | 3796 | if (copy_from_user(&getaddrs, optval, sizeof(struct sctp_getaddrs))) |
3797 | return -EFAULT; | 3797 | return -EFAULT; |
3798 | 3798 | ||
3799 | /* For UDP-style sockets, id specifies the association to query. */ | 3799 | /* For UDP-style sockets, id specifies the association to query. */ |
3800 | asoc = sctp_id2assoc(sk, getaddrs.assoc_id); | 3800 | asoc = sctp_id2assoc(sk, getaddrs.assoc_id); |
3801 | if (!asoc) | 3801 | if (!asoc) |
3802 | return -EINVAL; | 3802 | return -EINVAL; |
3803 | 3803 | ||
3804 | to = optval + offsetof(struct sctp_getaddrs,addrs); | 3804 | to = optval + offsetof(struct sctp_getaddrs,addrs); |
3805 | space_left = len - sizeof(struct sctp_getaddrs) - | 3805 | space_left = len - sizeof(struct sctp_getaddrs) - |
3806 | offsetof(struct sctp_getaddrs,addrs); | 3806 | offsetof(struct sctp_getaddrs,addrs); |
3807 | 3807 | ||
3808 | list_for_each(pos, &asoc->peer.transport_addr_list) { | 3808 | list_for_each(pos, &asoc->peer.transport_addr_list) { |
3809 | from = list_entry(pos, struct sctp_transport, transports); | 3809 | from = list_entry(pos, struct sctp_transport, transports); |
3810 | memcpy(&temp, &from->ipaddr, sizeof(temp)); | 3810 | memcpy(&temp, &from->ipaddr, sizeof(temp)); |
3811 | sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, &temp); | 3811 | sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, &temp); |
3812 | addrlen = sctp_get_af_specific(sk->sk_family)->sockaddr_len; | 3812 | addrlen = sctp_get_af_specific(sk->sk_family)->sockaddr_len; |
3813 | if(space_left < addrlen) | 3813 | if(space_left < addrlen) |
3814 | return -ENOMEM; | 3814 | return -ENOMEM; |
3815 | temp.v4.sin_port = htons(temp.v4.sin_port); | 3815 | temp.v4.sin_port = htons(temp.v4.sin_port); |
3816 | if (copy_to_user(to, &temp, addrlen)) | 3816 | if (copy_to_user(to, &temp, addrlen)) |
3817 | return -EFAULT; | 3817 | return -EFAULT; |
3818 | to += addrlen; | 3818 | to += addrlen; |
3819 | cnt++; | 3819 | cnt++; |
3820 | space_left -= addrlen; | 3820 | space_left -= addrlen; |
3821 | } | 3821 | } |
3822 | 3822 | ||
3823 | if (put_user(cnt, &((struct sctp_getaddrs __user *)optval)->addr_num)) | 3823 | if (put_user(cnt, &((struct sctp_getaddrs __user *)optval)->addr_num)) |
3824 | return -EFAULT; | 3824 | return -EFAULT; |
3825 | bytes_copied = ((char __user *)to) - optval; | 3825 | bytes_copied = ((char __user *)to) - optval; |
3826 | if (put_user(bytes_copied, optlen)) | 3826 | if (put_user(bytes_copied, optlen)) |
3827 | return -EFAULT; | 3827 | return -EFAULT; |
3828 | 3828 | ||
3829 | return 0; | 3829 | return 0; |
3830 | } | 3830 | } |
3831 | 3831 | ||
3832 | static int sctp_getsockopt_local_addrs_num_old(struct sock *sk, int len, | 3832 | static int sctp_getsockopt_local_addrs_num_old(struct sock *sk, int len, |
3833 | char __user *optval, | 3833 | char __user *optval, |
3834 | int __user *optlen) | 3834 | int __user *optlen) |
3835 | { | 3835 | { |
3836 | sctp_assoc_t id; | 3836 | sctp_assoc_t id; |
3837 | struct sctp_bind_addr *bp; | 3837 | struct sctp_bind_addr *bp; |
3838 | struct sctp_association *asoc; | 3838 | struct sctp_association *asoc; |
3839 | struct list_head *pos; | 3839 | struct list_head *pos; |
3840 | struct sctp_sockaddr_entry *addr; | 3840 | struct sctp_sockaddr_entry *addr; |
3841 | rwlock_t *addr_lock; | 3841 | rwlock_t *addr_lock; |
3842 | unsigned long flags; | 3842 | unsigned long flags; |
3843 | int cnt = 0; | 3843 | int cnt = 0; |
3844 | 3844 | ||
3845 | if (len != sizeof(sctp_assoc_t)) | 3845 | if (len != sizeof(sctp_assoc_t)) |
3846 | return -EINVAL; | 3846 | return -EINVAL; |
3847 | 3847 | ||
3848 | if (copy_from_user(&id, optval, sizeof(sctp_assoc_t))) | 3848 | if (copy_from_user(&id, optval, sizeof(sctp_assoc_t))) |
3849 | return -EFAULT; | 3849 | return -EFAULT; |
3850 | 3850 | ||
3851 | /* | 3851 | /* |
3852 | * For UDP-style sockets, id specifies the association to query. | 3852 | * For UDP-style sockets, id specifies the association to query. |
3853 | * If the id field is set to the value '0' then the locally bound | 3853 | * If the id field is set to the value '0' then the locally bound |
3854 | * addresses are returned without regard to any particular | 3854 | * addresses are returned without regard to any particular |
3855 | * association. | 3855 | * association. |
3856 | */ | 3856 | */ |
3857 | if (0 == id) { | 3857 | if (0 == id) { |
3858 | bp = &sctp_sk(sk)->ep->base.bind_addr; | 3858 | bp = &sctp_sk(sk)->ep->base.bind_addr; |
3859 | addr_lock = &sctp_sk(sk)->ep->base.addr_lock; | 3859 | addr_lock = &sctp_sk(sk)->ep->base.addr_lock; |
3860 | } else { | 3860 | } else { |
3861 | asoc = sctp_id2assoc(sk, id); | 3861 | asoc = sctp_id2assoc(sk, id); |
3862 | if (!asoc) | 3862 | if (!asoc) |
3863 | return -EINVAL; | 3863 | return -EINVAL; |
3864 | bp = &asoc->base.bind_addr; | 3864 | bp = &asoc->base.bind_addr; |
3865 | addr_lock = &asoc->base.addr_lock; | 3865 | addr_lock = &asoc->base.addr_lock; |
3866 | } | 3866 | } |
3867 | 3867 | ||
3868 | sctp_read_lock(addr_lock); | 3868 | sctp_read_lock(addr_lock); |
3869 | 3869 | ||
3870 | /* If the endpoint is bound to 0.0.0.0 or ::0, count the valid | 3870 | /* If the endpoint is bound to 0.0.0.0 or ::0, count the valid |
3871 | * addresses from the global local address list. | 3871 | * addresses from the global local address list. |
3872 | */ | 3872 | */ |
3873 | if (sctp_list_single_entry(&bp->address_list)) { | 3873 | if (sctp_list_single_entry(&bp->address_list)) { |
3874 | addr = list_entry(bp->address_list.next, | 3874 | addr = list_entry(bp->address_list.next, |
3875 | struct sctp_sockaddr_entry, list); | 3875 | struct sctp_sockaddr_entry, list); |
3876 | if (sctp_is_any(&addr->a)) { | 3876 | if (sctp_is_any(&addr->a)) { |
3877 | sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags); | 3877 | sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags); |
3878 | list_for_each(pos, &sctp_local_addr_list) { | 3878 | list_for_each(pos, &sctp_local_addr_list) { |
3879 | addr = list_entry(pos, | 3879 | addr = list_entry(pos, |
3880 | struct sctp_sockaddr_entry, | 3880 | struct sctp_sockaddr_entry, |
3881 | list); | 3881 | list); |
3882 | if ((PF_INET == sk->sk_family) && | 3882 | if ((PF_INET == sk->sk_family) && |
3883 | (AF_INET6 == addr->a.sa.sa_family)) | 3883 | (AF_INET6 == addr->a.sa.sa_family)) |
3884 | continue; | 3884 | continue; |
3885 | cnt++; | 3885 | cnt++; |
3886 | } | 3886 | } |
3887 | sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, | 3887 | sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, |
3888 | flags); | 3888 | flags); |
3889 | } else { | 3889 | } else { |
3890 | cnt = 1; | 3890 | cnt = 1; |
3891 | } | 3891 | } |
3892 | goto done; | 3892 | goto done; |
3893 | } | 3893 | } |
3894 | 3894 | ||
3895 | list_for_each(pos, &bp->address_list) { | 3895 | list_for_each(pos, &bp->address_list) { |
3896 | cnt ++; | 3896 | cnt ++; |
3897 | } | 3897 | } |
3898 | 3898 | ||
3899 | done: | 3899 | done: |
3900 | sctp_read_unlock(addr_lock); | 3900 | sctp_read_unlock(addr_lock); |
3901 | return cnt; | 3901 | return cnt; |
3902 | } | 3902 | } |
3903 | 3903 | ||
3904 | /* Helper function that copies local addresses to user and returns the number | 3904 | /* Helper function that copies local addresses to user and returns the number |
3905 | * of addresses copied. | 3905 | * of addresses copied. |
3906 | */ | 3906 | */ |
3907 | static int sctp_copy_laddrs_to_user_old(struct sock *sk, __u16 port, int max_addrs, | 3907 | static int sctp_copy_laddrs_to_user_old(struct sock *sk, __u16 port, int max_addrs, |
3908 | void __user *to) | 3908 | void __user *to) |
3909 | { | 3909 | { |
3910 | struct list_head *pos; | 3910 | struct list_head *pos; |
3911 | struct sctp_sockaddr_entry *addr; | 3911 | struct sctp_sockaddr_entry *addr; |
3912 | unsigned long flags; | 3912 | unsigned long flags; |
3913 | union sctp_addr temp; | 3913 | union sctp_addr temp; |
3914 | int cnt = 0; | 3914 | int cnt = 0; |
3915 | int addrlen; | 3915 | int addrlen; |
3916 | 3916 | ||
3917 | sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags); | 3917 | sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags); |
3918 | list_for_each(pos, &sctp_local_addr_list) { | 3918 | list_for_each(pos, &sctp_local_addr_list) { |
3919 | addr = list_entry(pos, struct sctp_sockaddr_entry, list); | 3919 | addr = list_entry(pos, struct sctp_sockaddr_entry, list); |
3920 | if ((PF_INET == sk->sk_family) && | 3920 | if ((PF_INET == sk->sk_family) && |
3921 | (AF_INET6 == addr->a.sa.sa_family)) | 3921 | (AF_INET6 == addr->a.sa.sa_family)) |
3922 | continue; | 3922 | continue; |
3923 | memcpy(&temp, &addr->a, sizeof(temp)); | 3923 | memcpy(&temp, &addr->a, sizeof(temp)); |
3924 | sctp_get_pf_specific(sk->sk_family)->addr_v4map(sctp_sk(sk), | 3924 | sctp_get_pf_specific(sk->sk_family)->addr_v4map(sctp_sk(sk), |
3925 | &temp); | 3925 | &temp); |
3926 | addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len; | 3926 | addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len; |
3927 | temp.v4.sin_port = htons(port); | 3927 | temp.v4.sin_port = htons(port); |
3928 | if (copy_to_user(to, &temp, addrlen)) { | 3928 | if (copy_to_user(to, &temp, addrlen)) { |
3929 | sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, | 3929 | sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, |
3930 | flags); | 3930 | flags); |
3931 | return -EFAULT; | 3931 | return -EFAULT; |
3932 | } | 3932 | } |
3933 | to += addrlen; | 3933 | to += addrlen; |
3934 | cnt ++; | 3934 | cnt ++; |
3935 | if (cnt >= max_addrs) break; | 3935 | if (cnt >= max_addrs) break; |
3936 | } | 3936 | } |
3937 | sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags); | 3937 | sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags); |
3938 | 3938 | ||
3939 | return cnt; | 3939 | return cnt; |
3940 | } | 3940 | } |
3941 | 3941 | ||
3942 | static int sctp_copy_laddrs_to_user(struct sock *sk, __u16 port, | 3942 | static int sctp_copy_laddrs_to_user(struct sock *sk, __u16 port, |
3943 | void __user **to, size_t space_left) | 3943 | void __user **to, size_t space_left) |
3944 | { | 3944 | { |
3945 | struct list_head *pos; | 3945 | struct list_head *pos; |
3946 | struct sctp_sockaddr_entry *addr; | 3946 | struct sctp_sockaddr_entry *addr; |
3947 | unsigned long flags; | 3947 | unsigned long flags; |
3948 | union sctp_addr temp; | 3948 | union sctp_addr temp; |
3949 | int cnt = 0; | 3949 | int cnt = 0; |
3950 | int addrlen; | 3950 | int addrlen; |
3951 | 3951 | ||
3952 | sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags); | 3952 | sctp_spin_lock_irqsave(&sctp_local_addr_lock, flags); |
3953 | list_for_each(pos, &sctp_local_addr_list) { | 3953 | list_for_each(pos, &sctp_local_addr_list) { |
3954 | addr = list_entry(pos, struct sctp_sockaddr_entry, list); | 3954 | addr = list_entry(pos, struct sctp_sockaddr_entry, list); |
3955 | if ((PF_INET == sk->sk_family) && | 3955 | if ((PF_INET == sk->sk_family) && |
3956 | (AF_INET6 == addr->a.sa.sa_family)) | 3956 | (AF_INET6 == addr->a.sa.sa_family)) |
3957 | continue; | 3957 | continue; |
3958 | memcpy(&temp, &addr->a, sizeof(temp)); | 3958 | memcpy(&temp, &addr->a, sizeof(temp)); |
3959 | sctp_get_pf_specific(sk->sk_family)->addr_v4map(sctp_sk(sk), | 3959 | sctp_get_pf_specific(sk->sk_family)->addr_v4map(sctp_sk(sk), |
3960 | &temp); | 3960 | &temp); |
3961 | addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len; | 3961 | addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len; |
3962 | if(space_left<addrlen) | 3962 | if(space_left<addrlen) |
3963 | return -ENOMEM; | 3963 | return -ENOMEM; |
3964 | temp.v4.sin_port = htons(port); | 3964 | temp.v4.sin_port = htons(port); |
3965 | if (copy_to_user(*to, &temp, addrlen)) { | 3965 | if (copy_to_user(*to, &temp, addrlen)) { |
3966 | sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, | 3966 | sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, |
3967 | flags); | 3967 | flags); |
3968 | return -EFAULT; | 3968 | return -EFAULT; |
3969 | } | 3969 | } |
3970 | *to += addrlen; | 3970 | *to += addrlen; |
3971 | cnt ++; | 3971 | cnt ++; |
3972 | space_left -= addrlen; | 3972 | space_left -= addrlen; |
3973 | } | 3973 | } |
3974 | sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags); | 3974 | sctp_spin_unlock_irqrestore(&sctp_local_addr_lock, flags); |
3975 | 3975 | ||
3976 | return cnt; | 3976 | return cnt; |
3977 | } | 3977 | } |
3978 | 3978 | ||
3979 | /* Old API for getting list of local addresses. Does not work for 32-bit | 3979 | /* Old API for getting list of local addresses. Does not work for 32-bit |
3980 | * programs running on a 64-bit kernel | 3980 | * programs running on a 64-bit kernel |
3981 | */ | 3981 | */ |
3982 | static int sctp_getsockopt_local_addrs_old(struct sock *sk, int len, | 3982 | static int sctp_getsockopt_local_addrs_old(struct sock *sk, int len, |
3983 | char __user *optval, int __user *optlen) | 3983 | char __user *optval, int __user *optlen) |
3984 | { | 3984 | { |
3985 | struct sctp_bind_addr *bp; | 3985 | struct sctp_bind_addr *bp; |
3986 | struct sctp_association *asoc; | 3986 | struct sctp_association *asoc; |
3987 | struct list_head *pos; | 3987 | struct list_head *pos; |
3988 | int cnt = 0; | 3988 | int cnt = 0; |
3989 | struct sctp_getaddrs_old getaddrs; | 3989 | struct sctp_getaddrs_old getaddrs; |
3990 | struct sctp_sockaddr_entry *addr; | 3990 | struct sctp_sockaddr_entry *addr; |
3991 | void __user *to; | 3991 | void __user *to; |
3992 | union sctp_addr temp; | 3992 | union sctp_addr temp; |
3993 | struct sctp_sock *sp = sctp_sk(sk); | 3993 | struct sctp_sock *sp = sctp_sk(sk); |
3994 | int addrlen; | 3994 | int addrlen; |
3995 | rwlock_t *addr_lock; | 3995 | rwlock_t *addr_lock; |
3996 | int err = 0; | 3996 | int err = 0; |
3997 | 3997 | ||
3998 | if (len != sizeof(struct sctp_getaddrs_old)) | 3998 | if (len != sizeof(struct sctp_getaddrs_old)) |
3999 | return -EINVAL; | 3999 | return -EINVAL; |
4000 | 4000 | ||
4001 | if (copy_from_user(&getaddrs, optval, sizeof(struct sctp_getaddrs_old))) | 4001 | if (copy_from_user(&getaddrs, optval, sizeof(struct sctp_getaddrs_old))) |
4002 | return -EFAULT; | 4002 | return -EFAULT; |
4003 | 4003 | ||
4004 | if (getaddrs.addr_num <= 0) return -EINVAL; | 4004 | if (getaddrs.addr_num <= 0) return -EINVAL; |
4005 | /* | 4005 | /* |
4006 | * For UDP-style sockets, id specifies the association to query. | 4006 | * For UDP-style sockets, id specifies the association to query. |
4007 | * If the id field is set to the value '0' then the locally bound | 4007 | * If the id field is set to the value '0' then the locally bound |
4008 | * addresses are returned without regard to any particular | 4008 | * addresses are returned without regard to any particular |
4009 | * association. | 4009 | * association. |
4010 | */ | 4010 | */ |
4011 | if (0 == getaddrs.assoc_id) { | 4011 | if (0 == getaddrs.assoc_id) { |
4012 | bp = &sctp_sk(sk)->ep->base.bind_addr; | 4012 | bp = &sctp_sk(sk)->ep->base.bind_addr; |
4013 | addr_lock = &sctp_sk(sk)->ep->base.addr_lock; | 4013 | addr_lock = &sctp_sk(sk)->ep->base.addr_lock; |
4014 | } else { | 4014 | } else { |
4015 | asoc = sctp_id2assoc(sk, getaddrs.assoc_id); | 4015 | asoc = sctp_id2assoc(sk, getaddrs.assoc_id); |
4016 | if (!asoc) | 4016 | if (!asoc) |
4017 | return -EINVAL; | 4017 | return -EINVAL; |
4018 | bp = &asoc->base.bind_addr; | 4018 | bp = &asoc->base.bind_addr; |
4019 | addr_lock = &asoc->base.addr_lock; | 4019 | addr_lock = &asoc->base.addr_lock; |
4020 | } | 4020 | } |
4021 | 4021 | ||
4022 | to = getaddrs.addrs; | 4022 | to = getaddrs.addrs; |
4023 | 4023 | ||
4024 | sctp_read_lock(addr_lock); | 4024 | sctp_read_lock(addr_lock); |
4025 | 4025 | ||
4026 | /* If the endpoint is bound to 0.0.0.0 or ::0, get the valid | 4026 | /* If the endpoint is bound to 0.0.0.0 or ::0, get the valid |
4027 | * addresses from the global local address list. | 4027 | * addresses from the global local address list. |
4028 | */ | 4028 | */ |
4029 | if (sctp_list_single_entry(&bp->address_list)) { | 4029 | if (sctp_list_single_entry(&bp->address_list)) { |
4030 | addr = list_entry(bp->address_list.next, | 4030 | addr = list_entry(bp->address_list.next, |
4031 | struct sctp_sockaddr_entry, list); | 4031 | struct sctp_sockaddr_entry, list); |
4032 | if (sctp_is_any(&addr->a)) { | 4032 | if (sctp_is_any(&addr->a)) { |
4033 | cnt = sctp_copy_laddrs_to_user_old(sk, bp->port, | 4033 | cnt = sctp_copy_laddrs_to_user_old(sk, bp->port, |
4034 | getaddrs.addr_num, | 4034 | getaddrs.addr_num, |
4035 | to); | 4035 | to); |
4036 | if (cnt < 0) { | 4036 | if (cnt < 0) { |
4037 | err = cnt; | 4037 | err = cnt; |
4038 | goto unlock; | 4038 | goto unlock; |
4039 | } | 4039 | } |
4040 | goto copy_getaddrs; | 4040 | goto copy_getaddrs; |
4041 | } | 4041 | } |
4042 | } | 4042 | } |
4043 | 4043 | ||
4044 | list_for_each(pos, &bp->address_list) { | 4044 | list_for_each(pos, &bp->address_list) { |
4045 | addr = list_entry(pos, struct sctp_sockaddr_entry, list); | 4045 | addr = list_entry(pos, struct sctp_sockaddr_entry, list); |
4046 | memcpy(&temp, &addr->a, sizeof(temp)); | 4046 | memcpy(&temp, &addr->a, sizeof(temp)); |
4047 | sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, &temp); | 4047 | sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, &temp); |
4048 | addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len; | 4048 | addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len; |
4049 | temp.v4.sin_port = htons(temp.v4.sin_port); | 4049 | temp.v4.sin_port = htons(temp.v4.sin_port); |
4050 | if (copy_to_user(to, &temp, addrlen)) { | 4050 | if (copy_to_user(to, &temp, addrlen)) { |
4051 | err = -EFAULT; | 4051 | err = -EFAULT; |
4052 | goto unlock; | 4052 | goto unlock; |
4053 | } | 4053 | } |
4054 | to += addrlen; | 4054 | to += addrlen; |
4055 | cnt ++; | 4055 | cnt ++; |
4056 | if (cnt >= getaddrs.addr_num) break; | 4056 | if (cnt >= getaddrs.addr_num) break; |
4057 | } | 4057 | } |
4058 | 4058 | ||
4059 | copy_getaddrs: | 4059 | copy_getaddrs: |
4060 | getaddrs.addr_num = cnt; | 4060 | getaddrs.addr_num = cnt; |
4061 | if (copy_to_user(optval, &getaddrs, sizeof(struct sctp_getaddrs_old))) | 4061 | if (copy_to_user(optval, &getaddrs, sizeof(struct sctp_getaddrs_old))) |
4062 | err = -EFAULT; | 4062 | err = -EFAULT; |
4063 | 4063 | ||
4064 | unlock: | 4064 | unlock: |
4065 | sctp_read_unlock(addr_lock); | 4065 | sctp_read_unlock(addr_lock); |
4066 | return err; | 4066 | return err; |
4067 | } | 4067 | } |
4068 | 4068 | ||
4069 | static int sctp_getsockopt_local_addrs(struct sock *sk, int len, | 4069 | static int sctp_getsockopt_local_addrs(struct sock *sk, int len, |
4070 | char __user *optval, int __user *optlen) | 4070 | char __user *optval, int __user *optlen) |
4071 | { | 4071 | { |
4072 | struct sctp_bind_addr *bp; | 4072 | struct sctp_bind_addr *bp; |
4073 | struct sctp_association *asoc; | 4073 | struct sctp_association *asoc; |
4074 | struct list_head *pos; | 4074 | struct list_head *pos; |
4075 | int cnt = 0; | 4075 | int cnt = 0; |
4076 | struct sctp_getaddrs getaddrs; | 4076 | struct sctp_getaddrs getaddrs; |
4077 | struct sctp_sockaddr_entry *addr; | 4077 | struct sctp_sockaddr_entry *addr; |
4078 | void __user *to; | 4078 | void __user *to; |
4079 | union sctp_addr temp; | 4079 | union sctp_addr temp; |
4080 | struct sctp_sock *sp = sctp_sk(sk); | 4080 | struct sctp_sock *sp = sctp_sk(sk); |
4081 | int addrlen; | 4081 | int addrlen; |
4082 | rwlock_t *addr_lock; | 4082 | rwlock_t *addr_lock; |
4083 | int err = 0; | 4083 | int err = 0; |
4084 | size_t space_left; | 4084 | size_t space_left; |
4085 | int bytes_copied; | 4085 | int bytes_copied; |
4086 | 4086 | ||
4087 | if (len <= sizeof(struct sctp_getaddrs)) | 4087 | if (len <= sizeof(struct sctp_getaddrs)) |
4088 | return -EINVAL; | 4088 | return -EINVAL; |
4089 | 4089 | ||
4090 | if (copy_from_user(&getaddrs, optval, sizeof(struct sctp_getaddrs))) | 4090 | if (copy_from_user(&getaddrs, optval, sizeof(struct sctp_getaddrs))) |
4091 | return -EFAULT; | 4091 | return -EFAULT; |
4092 | 4092 | ||
4093 | /* | 4093 | /* |
4094 | * For UDP-style sockets, id specifies the association to query. | 4094 | * For UDP-style sockets, id specifies the association to query. |
4095 | * If the id field is set to the value '0' then the locally bound | 4095 | * If the id field is set to the value '0' then the locally bound |
4096 | * addresses are returned without regard to any particular | 4096 | * addresses are returned without regard to any particular |
4097 | * association. | 4097 | * association. |
4098 | */ | 4098 | */ |
4099 | if (0 == getaddrs.assoc_id) { | 4099 | if (0 == getaddrs.assoc_id) { |
4100 | bp = &sctp_sk(sk)->ep->base.bind_addr; | 4100 | bp = &sctp_sk(sk)->ep->base.bind_addr; |
4101 | addr_lock = &sctp_sk(sk)->ep->base.addr_lock; | 4101 | addr_lock = &sctp_sk(sk)->ep->base.addr_lock; |
4102 | } else { | 4102 | } else { |
4103 | asoc = sctp_id2assoc(sk, getaddrs.assoc_id); | 4103 | asoc = sctp_id2assoc(sk, getaddrs.assoc_id); |
4104 | if (!asoc) | 4104 | if (!asoc) |
4105 | return -EINVAL; | 4105 | return -EINVAL; |
4106 | bp = &asoc->base.bind_addr; | 4106 | bp = &asoc->base.bind_addr; |
4107 | addr_lock = &asoc->base.addr_lock; | 4107 | addr_lock = &asoc->base.addr_lock; |
4108 | } | 4108 | } |
4109 | 4109 | ||
4110 | to = optval + offsetof(struct sctp_getaddrs,addrs); | 4110 | to = optval + offsetof(struct sctp_getaddrs,addrs); |
4111 | space_left = len - sizeof(struct sctp_getaddrs) - | 4111 | space_left = len - sizeof(struct sctp_getaddrs) - |
4112 | offsetof(struct sctp_getaddrs,addrs); | 4112 | offsetof(struct sctp_getaddrs,addrs); |
4113 | 4113 | ||
4114 | sctp_read_lock(addr_lock); | 4114 | sctp_read_lock(addr_lock); |
4115 | 4115 | ||
4116 | /* If the endpoint is bound to 0.0.0.0 or ::0, get the valid | 4116 | /* If the endpoint is bound to 0.0.0.0 or ::0, get the valid |
4117 | * addresses from the global local address list. | 4117 | * addresses from the global local address list. |
4118 | */ | 4118 | */ |
4119 | if (sctp_list_single_entry(&bp->address_list)) { | 4119 | if (sctp_list_single_entry(&bp->address_list)) { |
4120 | addr = list_entry(bp->address_list.next, | 4120 | addr = list_entry(bp->address_list.next, |
4121 | struct sctp_sockaddr_entry, list); | 4121 | struct sctp_sockaddr_entry, list); |
4122 | if (sctp_is_any(&addr->a)) { | 4122 | if (sctp_is_any(&addr->a)) { |
4123 | cnt = sctp_copy_laddrs_to_user(sk, bp->port, | 4123 | cnt = sctp_copy_laddrs_to_user(sk, bp->port, |
4124 | &to, space_left); | 4124 | &to, space_left); |
4125 | if (cnt < 0) { | 4125 | if (cnt < 0) { |
4126 | err = cnt; | 4126 | err = cnt; |
4127 | goto unlock; | 4127 | goto unlock; |
4128 | } | 4128 | } |
4129 | goto copy_getaddrs; | 4129 | goto copy_getaddrs; |
4130 | } | 4130 | } |
4131 | } | 4131 | } |
4132 | 4132 | ||
4133 | list_for_each(pos, &bp->address_list) { | 4133 | list_for_each(pos, &bp->address_list) { |
4134 | addr = list_entry(pos, struct sctp_sockaddr_entry, list); | 4134 | addr = list_entry(pos, struct sctp_sockaddr_entry, list); |
4135 | memcpy(&temp, &addr->a, sizeof(temp)); | 4135 | memcpy(&temp, &addr->a, sizeof(temp)); |
4136 | sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, &temp); | 4136 | sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, &temp); |
4137 | addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len; | 4137 | addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len; |
4138 | if(space_left < addrlen) | 4138 | if(space_left < addrlen) |
4139 | return -ENOMEM; /*fixme: right error?*/ | 4139 | return -ENOMEM; /*fixme: right error?*/ |
4140 | temp.v4.sin_port = htons(temp.v4.sin_port); | 4140 | temp.v4.sin_port = htons(temp.v4.sin_port); |
4141 | if (copy_to_user(to, &temp, addrlen)) { | 4141 | if (copy_to_user(to, &temp, addrlen)) { |
4142 | err = -EFAULT; | 4142 | err = -EFAULT; |
4143 | goto unlock; | 4143 | goto unlock; |
4144 | } | 4144 | } |
4145 | to += addrlen; | 4145 | to += addrlen; |
4146 | cnt ++; | 4146 | cnt ++; |
4147 | space_left -= addrlen; | 4147 | space_left -= addrlen; |
4148 | } | 4148 | } |
4149 | 4149 | ||
4150 | copy_getaddrs: | 4150 | copy_getaddrs: |
4151 | if (put_user(cnt, &((struct sctp_getaddrs __user *)optval)->addr_num)) | 4151 | if (put_user(cnt, &((struct sctp_getaddrs __user *)optval)->addr_num)) |
4152 | return -EFAULT; | 4152 | return -EFAULT; |
4153 | bytes_copied = ((char __user *)to) - optval; | 4153 | bytes_copied = ((char __user *)to) - optval; |
4154 | if (put_user(bytes_copied, optlen)) | 4154 | if (put_user(bytes_copied, optlen)) |
4155 | return -EFAULT; | 4155 | return -EFAULT; |
4156 | 4156 | ||
4157 | unlock: | 4157 | unlock: |
4158 | sctp_read_unlock(addr_lock); | 4158 | sctp_read_unlock(addr_lock); |
4159 | return err; | 4159 | return err; |
4160 | } | 4160 | } |
4161 | 4161 | ||
4162 | /* 7.1.10 Set Primary Address (SCTP_PRIMARY_ADDR) | 4162 | /* 7.1.10 Set Primary Address (SCTP_PRIMARY_ADDR) |
4163 | * | 4163 | * |
4164 | * Requests that the local SCTP stack use the enclosed peer address as | 4164 | * Requests that the local SCTP stack use the enclosed peer address as |
4165 | * the association primary. The enclosed address must be one of the | 4165 | * the association primary. The enclosed address must be one of the |
4166 | * association peer's addresses. | 4166 | * association peer's addresses. |
4167 | */ | 4167 | */ |
4168 | static int sctp_getsockopt_primary_addr(struct sock *sk, int len, | 4168 | static int sctp_getsockopt_primary_addr(struct sock *sk, int len, |
4169 | char __user *optval, int __user *optlen) | 4169 | char __user *optval, int __user *optlen) |
4170 | { | 4170 | { |
4171 | struct sctp_prim prim; | 4171 | struct sctp_prim prim; |
4172 | struct sctp_association *asoc; | 4172 | struct sctp_association *asoc; |
4173 | struct sctp_sock *sp = sctp_sk(sk); | 4173 | struct sctp_sock *sp = sctp_sk(sk); |
4174 | 4174 | ||
4175 | if (len != sizeof(struct sctp_prim)) | 4175 | if (len != sizeof(struct sctp_prim)) |
4176 | return -EINVAL; | 4176 | return -EINVAL; |
4177 | 4177 | ||
4178 | if (copy_from_user(&prim, optval, sizeof(struct sctp_prim))) | 4178 | if (copy_from_user(&prim, optval, sizeof(struct sctp_prim))) |
4179 | return -EFAULT; | 4179 | return -EFAULT; |
4180 | 4180 | ||
4181 | asoc = sctp_id2assoc(sk, prim.ssp_assoc_id); | 4181 | asoc = sctp_id2assoc(sk, prim.ssp_assoc_id); |
4182 | if (!asoc) | 4182 | if (!asoc) |
4183 | return -EINVAL; | 4183 | return -EINVAL; |
4184 | 4184 | ||
4185 | if (!asoc->peer.primary_path) | 4185 | if (!asoc->peer.primary_path) |
4186 | return -ENOTCONN; | 4186 | return -ENOTCONN; |
4187 | 4187 | ||
4188 | asoc->peer.primary_path->ipaddr.v4.sin_port = | 4188 | asoc->peer.primary_path->ipaddr.v4.sin_port = |
4189 | htons(asoc->peer.primary_path->ipaddr.v4.sin_port); | 4189 | htons(asoc->peer.primary_path->ipaddr.v4.sin_port); |
4190 | memcpy(&prim.ssp_addr, &asoc->peer.primary_path->ipaddr, | 4190 | memcpy(&prim.ssp_addr, &asoc->peer.primary_path->ipaddr, |
4191 | sizeof(union sctp_addr)); | 4191 | sizeof(union sctp_addr)); |
4192 | asoc->peer.primary_path->ipaddr.v4.sin_port = | 4192 | asoc->peer.primary_path->ipaddr.v4.sin_port = |
4193 | ntohs(asoc->peer.primary_path->ipaddr.v4.sin_port); | 4193 | ntohs(asoc->peer.primary_path->ipaddr.v4.sin_port); |
4194 | 4194 | ||
4195 | sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, | 4195 | sctp_get_pf_specific(sk->sk_family)->addr_v4map(sp, |
4196 | (union sctp_addr *)&prim.ssp_addr); | 4196 | (union sctp_addr *)&prim.ssp_addr); |
4197 | 4197 | ||
4198 | if (copy_to_user(optval, &prim, sizeof(struct sctp_prim))) | 4198 | if (copy_to_user(optval, &prim, sizeof(struct sctp_prim))) |
4199 | return -EFAULT; | 4199 | return -EFAULT; |
4200 | 4200 | ||
4201 | return 0; | 4201 | return 0; |
4202 | } | 4202 | } |
4203 | 4203 | ||
4204 | /* | 4204 | /* |
4205 | * 7.1.11 Set Adaption Layer Indicator (SCTP_ADAPTION_LAYER) | 4205 | * 7.1.11 Set Adaption Layer Indicator (SCTP_ADAPTION_LAYER) |
4206 | * | 4206 | * |
4207 | * Requests that the local endpoint set the specified Adaption Layer | 4207 | * Requests that the local endpoint set the specified Adaption Layer |
4208 | * Indication parameter for all future INIT and INIT-ACK exchanges. | 4208 | * Indication parameter for all future INIT and INIT-ACK exchanges. |
4209 | */ | 4209 | */ |
4210 | static int sctp_getsockopt_adaption_layer(struct sock *sk, int len, | 4210 | static int sctp_getsockopt_adaption_layer(struct sock *sk, int len, |
4211 | char __user *optval, int __user *optlen) | 4211 | char __user *optval, int __user *optlen) |
4212 | { | 4212 | { |
4213 | struct sctp_setadaption adaption; | 4213 | struct sctp_setadaption adaption; |
4214 | 4214 | ||
4215 | if (len != sizeof(struct sctp_setadaption)) | 4215 | if (len != sizeof(struct sctp_setadaption)) |
4216 | return -EINVAL; | 4216 | return -EINVAL; |
4217 | 4217 | ||
4218 | adaption.ssb_adaption_ind = sctp_sk(sk)->adaption_ind; | 4218 | adaption.ssb_adaption_ind = sctp_sk(sk)->adaption_ind; |
4219 | if (copy_to_user(optval, &adaption, len)) | 4219 | if (copy_to_user(optval, &adaption, len)) |
4220 | return -EFAULT; | 4220 | return -EFAULT; |
4221 | 4221 | ||
4222 | return 0; | 4222 | return 0; |
4223 | } | 4223 | } |
4224 | 4224 | ||
4225 | /* | 4225 | /* |
4226 | * | 4226 | * |
4227 | * 7.1.14 Set default send parameters (SCTP_DEFAULT_SEND_PARAM) | 4227 | * 7.1.14 Set default send parameters (SCTP_DEFAULT_SEND_PARAM) |
4228 | * | 4228 | * |
4229 | * Applications that wish to use the sendto() system call may wish to | 4229 | * Applications that wish to use the sendto() system call may wish to |
4230 | * specify a default set of parameters that would normally be supplied | 4230 | * specify a default set of parameters that would normally be supplied |
4231 | * through the inclusion of ancillary data. This socket option allows | 4231 | * through the inclusion of ancillary data. This socket option allows |
4232 | * such an application to set the default sctp_sndrcvinfo structure. | 4232 | * such an application to set the default sctp_sndrcvinfo structure. |
4233 | 4233 | ||
4234 | 4234 | ||
4235 | * The application that wishes to use this socket option simply passes | 4235 | * The application that wishes to use this socket option simply passes |
4236 | * in to this call the sctp_sndrcvinfo structure defined in Section | 4236 | * in to this call the sctp_sndrcvinfo structure defined in Section |
4237 | * 5.2.2) The input parameters accepted by this call include | 4237 | * 5.2.2) The input parameters accepted by this call include |
4238 | * sinfo_stream, sinfo_flags, sinfo_ppid, sinfo_context, | 4238 | * sinfo_stream, sinfo_flags, sinfo_ppid, sinfo_context, |
4239 | * sinfo_timetolive. The user must provide the sinfo_assoc_id field in | 4239 | * sinfo_timetolive. The user must provide the sinfo_assoc_id field in |
4240 | * to this call if the caller is using the UDP model. | 4240 | * to this call if the caller is using the UDP model. |
4241 | * | 4241 | * |
4242 | * For getsockopt, it get the default sctp_sndrcvinfo structure. | 4242 | * For getsockopt, it get the default sctp_sndrcvinfo structure. |
4243 | */ | 4243 | */ |
4244 | static int sctp_getsockopt_default_send_param(struct sock *sk, | 4244 | static int sctp_getsockopt_default_send_param(struct sock *sk, |
4245 | int len, char __user *optval, | 4245 | int len, char __user *optval, |
4246 | int __user *optlen) | 4246 | int __user *optlen) |
4247 | { | 4247 | { |
4248 | struct sctp_sndrcvinfo info; | 4248 | struct sctp_sndrcvinfo info; |
4249 | struct sctp_association *asoc; | 4249 | struct sctp_association *asoc; |
4250 | struct sctp_sock *sp = sctp_sk(sk); | 4250 | struct sctp_sock *sp = sctp_sk(sk); |
4251 | 4251 | ||
4252 | if (len != sizeof(struct sctp_sndrcvinfo)) | 4252 | if (len != sizeof(struct sctp_sndrcvinfo)) |
4253 | return -EINVAL; | 4253 | return -EINVAL; |
4254 | if (copy_from_user(&info, optval, sizeof(struct sctp_sndrcvinfo))) | 4254 | if (copy_from_user(&info, optval, sizeof(struct sctp_sndrcvinfo))) |
4255 | return -EFAULT; | 4255 | return -EFAULT; |
4256 | 4256 | ||
4257 | asoc = sctp_id2assoc(sk, info.sinfo_assoc_id); | 4257 | asoc = sctp_id2assoc(sk, info.sinfo_assoc_id); |
4258 | if (!asoc && info.sinfo_assoc_id && sctp_style(sk, UDP)) | 4258 | if (!asoc && info.sinfo_assoc_id && sctp_style(sk, UDP)) |
4259 | return -EINVAL; | 4259 | return -EINVAL; |
4260 | 4260 | ||
4261 | if (asoc) { | 4261 | if (asoc) { |
4262 | info.sinfo_stream = asoc->default_stream; | 4262 | info.sinfo_stream = asoc->default_stream; |
4263 | info.sinfo_flags = asoc->default_flags; | 4263 | info.sinfo_flags = asoc->default_flags; |
4264 | info.sinfo_ppid = asoc->default_ppid; | 4264 | info.sinfo_ppid = asoc->default_ppid; |
4265 | info.sinfo_context = asoc->default_context; | 4265 | info.sinfo_context = asoc->default_context; |
4266 | info.sinfo_timetolive = asoc->default_timetolive; | 4266 | info.sinfo_timetolive = asoc->default_timetolive; |
4267 | } else { | 4267 | } else { |
4268 | info.sinfo_stream = sp->default_stream; | 4268 | info.sinfo_stream = sp->default_stream; |
4269 | info.sinfo_flags = sp->default_flags; | 4269 | info.sinfo_flags = sp->default_flags; |
4270 | info.sinfo_ppid = sp->default_ppid; | 4270 | info.sinfo_ppid = sp->default_ppid; |
4271 | info.sinfo_context = sp->default_context; | 4271 | info.sinfo_context = sp->default_context; |
4272 | info.sinfo_timetolive = sp->default_timetolive; | 4272 | info.sinfo_timetolive = sp->default_timetolive; |
4273 | } | 4273 | } |
4274 | 4274 | ||
4275 | if (copy_to_user(optval, &info, sizeof(struct sctp_sndrcvinfo))) | 4275 | if (copy_to_user(optval, &info, sizeof(struct sctp_sndrcvinfo))) |
4276 | return -EFAULT; | 4276 | return -EFAULT; |
4277 | 4277 | ||
4278 | return 0; | 4278 | return 0; |
4279 | } | 4279 | } |
4280 | 4280 | ||
4281 | /* | 4281 | /* |
4282 | * | 4282 | * |
4283 | * 7.1.5 SCTP_NODELAY | 4283 | * 7.1.5 SCTP_NODELAY |
4284 | * | 4284 | * |
4285 | * Turn on/off any Nagle-like algorithm. This means that packets are | 4285 | * Turn on/off any Nagle-like algorithm. This means that packets are |
4286 | * generally sent as soon as possible and no unnecessary delays are | 4286 | * generally sent as soon as possible and no unnecessary delays are |
4287 | * introduced, at the cost of more packets in the network. Expects an | 4287 | * introduced, at the cost of more packets in the network. Expects an |
4288 | * integer boolean flag. | 4288 | * integer boolean flag. |
4289 | */ | 4289 | */ |
4290 | 4290 | ||
4291 | static int sctp_getsockopt_nodelay(struct sock *sk, int len, | 4291 | static int sctp_getsockopt_nodelay(struct sock *sk, int len, |
4292 | char __user *optval, int __user *optlen) | 4292 | char __user *optval, int __user *optlen) |
4293 | { | 4293 | { |
4294 | int val; | 4294 | int val; |
4295 | 4295 | ||
4296 | if (len < sizeof(int)) | 4296 | if (len < sizeof(int)) |
4297 | return -EINVAL; | 4297 | return -EINVAL; |
4298 | 4298 | ||
4299 | len = sizeof(int); | 4299 | len = sizeof(int); |
4300 | val = (sctp_sk(sk)->nodelay == 1); | 4300 | val = (sctp_sk(sk)->nodelay == 1); |
4301 | if (put_user(len, optlen)) | 4301 | if (put_user(len, optlen)) |
4302 | return -EFAULT; | 4302 | return -EFAULT; |
4303 | if (copy_to_user(optval, &val, len)) | 4303 | if (copy_to_user(optval, &val, len)) |
4304 | return -EFAULT; | 4304 | return -EFAULT; |
4305 | return 0; | 4305 | return 0; |
4306 | } | 4306 | } |
4307 | 4307 | ||
4308 | /* | 4308 | /* |
4309 | * | 4309 | * |
4310 | * 7.1.1 SCTP_RTOINFO | 4310 | * 7.1.1 SCTP_RTOINFO |
4311 | * | 4311 | * |
4312 | * The protocol parameters used to initialize and bound retransmission | 4312 | * The protocol parameters used to initialize and bound retransmission |
4313 | * timeout (RTO) are tunable. sctp_rtoinfo structure is used to access | 4313 | * timeout (RTO) are tunable. sctp_rtoinfo structure is used to access |
4314 | * and modify these parameters. | 4314 | * and modify these parameters. |
4315 | * All parameters are time values, in milliseconds. A value of 0, when | 4315 | * All parameters are time values, in milliseconds. A value of 0, when |
4316 | * modifying the parameters, indicates that the current value should not | 4316 | * modifying the parameters, indicates that the current value should not |
4317 | * be changed. | 4317 | * be changed. |
4318 | * | 4318 | * |
4319 | */ | 4319 | */ |
4320 | static int sctp_getsockopt_rtoinfo(struct sock *sk, int len, | 4320 | static int sctp_getsockopt_rtoinfo(struct sock *sk, int len, |
4321 | char __user *optval, | 4321 | char __user *optval, |
4322 | int __user *optlen) { | 4322 | int __user *optlen) { |
4323 | struct sctp_rtoinfo rtoinfo; | 4323 | struct sctp_rtoinfo rtoinfo; |
4324 | struct sctp_association *asoc; | 4324 | struct sctp_association *asoc; |
4325 | 4325 | ||
4326 | if (len != sizeof (struct sctp_rtoinfo)) | 4326 | if (len != sizeof (struct sctp_rtoinfo)) |
4327 | return -EINVAL; | 4327 | return -EINVAL; |
4328 | 4328 | ||
4329 | if (copy_from_user(&rtoinfo, optval, sizeof (struct sctp_rtoinfo))) | 4329 | if (copy_from_user(&rtoinfo, optval, sizeof (struct sctp_rtoinfo))) |
4330 | return -EFAULT; | 4330 | return -EFAULT; |
4331 | 4331 | ||
4332 | asoc = sctp_id2assoc(sk, rtoinfo.srto_assoc_id); | 4332 | asoc = sctp_id2assoc(sk, rtoinfo.srto_assoc_id); |
4333 | 4333 | ||
4334 | if (!asoc && rtoinfo.srto_assoc_id && sctp_style(sk, UDP)) | 4334 | if (!asoc && rtoinfo.srto_assoc_id && sctp_style(sk, UDP)) |
4335 | return -EINVAL; | 4335 | return -EINVAL; |
4336 | 4336 | ||
4337 | /* Values corresponding to the specific association. */ | 4337 | /* Values corresponding to the specific association. */ |
4338 | if (asoc) { | 4338 | if (asoc) { |
4339 | rtoinfo.srto_initial = jiffies_to_msecs(asoc->rto_initial); | 4339 | rtoinfo.srto_initial = jiffies_to_msecs(asoc->rto_initial); |
4340 | rtoinfo.srto_max = jiffies_to_msecs(asoc->rto_max); | 4340 | rtoinfo.srto_max = jiffies_to_msecs(asoc->rto_max); |
4341 | rtoinfo.srto_min = jiffies_to_msecs(asoc->rto_min); | 4341 | rtoinfo.srto_min = jiffies_to_msecs(asoc->rto_min); |
4342 | } else { | 4342 | } else { |
4343 | /* Values corresponding to the endpoint. */ | 4343 | /* Values corresponding to the endpoint. */ |
4344 | struct sctp_sock *sp = sctp_sk(sk); | 4344 | struct sctp_sock *sp = sctp_sk(sk); |
4345 | 4345 | ||
4346 | rtoinfo.srto_initial = sp->rtoinfo.srto_initial; | 4346 | rtoinfo.srto_initial = sp->rtoinfo.srto_initial; |
4347 | rtoinfo.srto_max = sp->rtoinfo.srto_max; | 4347 | rtoinfo.srto_max = sp->rtoinfo.srto_max; |
4348 | rtoinfo.srto_min = sp->rtoinfo.srto_min; | 4348 | rtoinfo.srto_min = sp->rtoinfo.srto_min; |
4349 | } | 4349 | } |
4350 | 4350 | ||
4351 | if (put_user(len, optlen)) | 4351 | if (put_user(len, optlen)) |
4352 | return -EFAULT; | 4352 | return -EFAULT; |
4353 | 4353 | ||
4354 | if (copy_to_user(optval, &rtoinfo, len)) | 4354 | if (copy_to_user(optval, &rtoinfo, len)) |
4355 | return -EFAULT; | 4355 | return -EFAULT; |
4356 | 4356 | ||
4357 | return 0; | 4357 | return 0; |
4358 | } | 4358 | } |
4359 | 4359 | ||
4360 | /* | 4360 | /* |
4361 | * | 4361 | * |
4362 | * 7.1.2 SCTP_ASSOCINFO | 4362 | * 7.1.2 SCTP_ASSOCINFO |
4363 | * | 4363 | * |
4364 | * This option is used to tune the the maximum retransmission attempts | 4364 | * This option is used to tune the the maximum retransmission attempts |
4365 | * of the association. | 4365 | * of the association. |
4366 | * Returns an error if the new association retransmission value is | 4366 | * Returns an error if the new association retransmission value is |
4367 | * greater than the sum of the retransmission value of the peer. | 4367 | * greater than the sum of the retransmission value of the peer. |
4368 | * See [SCTP] for more information. | 4368 | * See [SCTP] for more information. |
4369 | * | 4369 | * |
4370 | */ | 4370 | */ |
4371 | static int sctp_getsockopt_associnfo(struct sock *sk, int len, | 4371 | static int sctp_getsockopt_associnfo(struct sock *sk, int len, |
4372 | char __user *optval, | 4372 | char __user *optval, |
4373 | int __user *optlen) | 4373 | int __user *optlen) |
4374 | { | 4374 | { |
4375 | 4375 | ||
4376 | struct sctp_assocparams assocparams; | 4376 | struct sctp_assocparams assocparams; |
4377 | struct sctp_association *asoc; | 4377 | struct sctp_association *asoc; |
4378 | struct list_head *pos; | 4378 | struct list_head *pos; |
4379 | int cnt = 0; | 4379 | int cnt = 0; |
4380 | 4380 | ||
4381 | if (len != sizeof (struct sctp_assocparams)) | 4381 | if (len != sizeof (struct sctp_assocparams)) |
4382 | return -EINVAL; | 4382 | return -EINVAL; |
4383 | 4383 | ||
4384 | if (copy_from_user(&assocparams, optval, | 4384 | if (copy_from_user(&assocparams, optval, |
4385 | sizeof (struct sctp_assocparams))) | 4385 | sizeof (struct sctp_assocparams))) |
4386 | return -EFAULT; | 4386 | return -EFAULT; |
4387 | 4387 | ||
4388 | asoc = sctp_id2assoc(sk, assocparams.sasoc_assoc_id); | 4388 | asoc = sctp_id2assoc(sk, assocparams.sasoc_assoc_id); |
4389 | 4389 | ||
4390 | if (!asoc && assocparams.sasoc_assoc_id && sctp_style(sk, UDP)) | 4390 | if (!asoc && assocparams.sasoc_assoc_id && sctp_style(sk, UDP)) |
4391 | return -EINVAL; | 4391 | return -EINVAL; |
4392 | 4392 | ||
4393 | /* Values correspoinding to the specific association */ | 4393 | /* Values correspoinding to the specific association */ |
4394 | if (asoc) { | 4394 | if (asoc) { |
4395 | assocparams.sasoc_asocmaxrxt = asoc->max_retrans; | 4395 | assocparams.sasoc_asocmaxrxt = asoc->max_retrans; |
4396 | assocparams.sasoc_peer_rwnd = asoc->peer.rwnd; | 4396 | assocparams.sasoc_peer_rwnd = asoc->peer.rwnd; |
4397 | assocparams.sasoc_local_rwnd = asoc->a_rwnd; | 4397 | assocparams.sasoc_local_rwnd = asoc->a_rwnd; |
4398 | assocparams.sasoc_cookie_life = (asoc->cookie_life.tv_sec | 4398 | assocparams.sasoc_cookie_life = (asoc->cookie_life.tv_sec |
4399 | * 1000) + | 4399 | * 1000) + |
4400 | (asoc->cookie_life.tv_usec | 4400 | (asoc->cookie_life.tv_usec |
4401 | / 1000); | 4401 | / 1000); |
4402 | 4402 | ||
4403 | list_for_each(pos, &asoc->peer.transport_addr_list) { | 4403 | list_for_each(pos, &asoc->peer.transport_addr_list) { |
4404 | cnt ++; | 4404 | cnt ++; |
4405 | } | 4405 | } |
4406 | 4406 | ||
4407 | assocparams.sasoc_number_peer_destinations = cnt; | 4407 | assocparams.sasoc_number_peer_destinations = cnt; |
4408 | } else { | 4408 | } else { |
4409 | /* Values corresponding to the endpoint */ | 4409 | /* Values corresponding to the endpoint */ |
4410 | struct sctp_sock *sp = sctp_sk(sk); | 4410 | struct sctp_sock *sp = sctp_sk(sk); |
4411 | 4411 | ||
4412 | assocparams.sasoc_asocmaxrxt = sp->assocparams.sasoc_asocmaxrxt; | 4412 | assocparams.sasoc_asocmaxrxt = sp->assocparams.sasoc_asocmaxrxt; |
4413 | assocparams.sasoc_peer_rwnd = sp->assocparams.sasoc_peer_rwnd; | 4413 | assocparams.sasoc_peer_rwnd = sp->assocparams.sasoc_peer_rwnd; |
4414 | assocparams.sasoc_local_rwnd = sp->assocparams.sasoc_local_rwnd; | 4414 | assocparams.sasoc_local_rwnd = sp->assocparams.sasoc_local_rwnd; |
4415 | assocparams.sasoc_cookie_life = | 4415 | assocparams.sasoc_cookie_life = |
4416 | sp->assocparams.sasoc_cookie_life; | 4416 | sp->assocparams.sasoc_cookie_life; |
4417 | assocparams.sasoc_number_peer_destinations = | 4417 | assocparams.sasoc_number_peer_destinations = |
4418 | sp->assocparams. | 4418 | sp->assocparams. |
4419 | sasoc_number_peer_destinations; | 4419 | sasoc_number_peer_destinations; |
4420 | } | 4420 | } |
4421 | 4421 | ||
4422 | if (put_user(len, optlen)) | 4422 | if (put_user(len, optlen)) |
4423 | return -EFAULT; | 4423 | return -EFAULT; |
4424 | 4424 | ||
4425 | if (copy_to_user(optval, &assocparams, len)) | 4425 | if (copy_to_user(optval, &assocparams, len)) |
4426 | return -EFAULT; | 4426 | return -EFAULT; |
4427 | 4427 | ||
4428 | return 0; | 4428 | return 0; |
4429 | } | 4429 | } |
4430 | 4430 | ||
4431 | /* | 4431 | /* |
4432 | * 7.1.16 Set/clear IPv4 mapped addresses (SCTP_I_WANT_MAPPED_V4_ADDR) | 4432 | * 7.1.16 Set/clear IPv4 mapped addresses (SCTP_I_WANT_MAPPED_V4_ADDR) |
4433 | * | 4433 | * |
4434 | * This socket option is a boolean flag which turns on or off mapped V4 | 4434 | * This socket option is a boolean flag which turns on or off mapped V4 |
4435 | * addresses. If this option is turned on and the socket is type | 4435 | * addresses. If this option is turned on and the socket is type |
4436 | * PF_INET6, then IPv4 addresses will be mapped to V6 representation. | 4436 | * PF_INET6, then IPv4 addresses will be mapped to V6 representation. |
4437 | * If this option is turned off, then no mapping will be done of V4 | 4437 | * If this option is turned off, then no mapping will be done of V4 |
4438 | * addresses and a user will receive both PF_INET6 and PF_INET type | 4438 | * addresses and a user will receive both PF_INET6 and PF_INET type |
4439 | * addresses on the socket. | 4439 | * addresses on the socket. |
4440 | */ | 4440 | */ |
4441 | static int sctp_getsockopt_mappedv4(struct sock *sk, int len, | 4441 | static int sctp_getsockopt_mappedv4(struct sock *sk, int len, |
4442 | char __user *optval, int __user *optlen) | 4442 | char __user *optval, int __user *optlen) |
4443 | { | 4443 | { |
4444 | int val; | 4444 | int val; |
4445 | struct sctp_sock *sp = sctp_sk(sk); | 4445 | struct sctp_sock *sp = sctp_sk(sk); |
4446 | 4446 | ||
4447 | if (len < sizeof(int)) | 4447 | if (len < sizeof(int)) |
4448 | return -EINVAL; | 4448 | return -EINVAL; |
4449 | 4449 | ||
4450 | len = sizeof(int); | 4450 | len = sizeof(int); |
4451 | val = sp->v4mapped; | 4451 | val = sp->v4mapped; |
4452 | if (put_user(len, optlen)) | 4452 | if (put_user(len, optlen)) |
4453 | return -EFAULT; | 4453 | return -EFAULT; |
4454 | if (copy_to_user(optval, &val, len)) | 4454 | if (copy_to_user(optval, &val, len)) |
4455 | return -EFAULT; | 4455 | return -EFAULT; |
4456 | 4456 | ||
4457 | return 0; | 4457 | return 0; |
4458 | } | 4458 | } |
4459 | 4459 | ||
4460 | /* | 4460 | /* |
4461 | * 7.1.17 Set the maximum fragrmentation size (SCTP_MAXSEG) | 4461 | * 7.1.17 Set the maximum fragrmentation size (SCTP_MAXSEG) |
4462 | * | 4462 | * |
4463 | * This socket option specifies the maximum size to put in any outgoing | 4463 | * This socket option specifies the maximum size to put in any outgoing |
4464 | * SCTP chunk. If a message is larger than this size it will be | 4464 | * SCTP chunk. If a message is larger than this size it will be |
4465 | * fragmented by SCTP into the specified size. Note that the underlying | 4465 | * fragmented by SCTP into the specified size. Note that the underlying |
4466 | * SCTP implementation may fragment into smaller sized chunks when the | 4466 | * SCTP implementation may fragment into smaller sized chunks when the |
4467 | * PMTU of the underlying association is smaller than the value set by | 4467 | * PMTU of the underlying association is smaller than the value set by |
4468 | * the user. | 4468 | * the user. |
4469 | */ | 4469 | */ |
4470 | static int sctp_getsockopt_maxseg(struct sock *sk, int len, | 4470 | static int sctp_getsockopt_maxseg(struct sock *sk, int len, |
4471 | char __user *optval, int __user *optlen) | 4471 | char __user *optval, int __user *optlen) |
4472 | { | 4472 | { |
4473 | int val; | 4473 | int val; |
4474 | 4474 | ||
4475 | if (len < sizeof(int)) | 4475 | if (len < sizeof(int)) |
4476 | return -EINVAL; | 4476 | return -EINVAL; |
4477 | 4477 | ||
4478 | len = sizeof(int); | 4478 | len = sizeof(int); |
4479 | 4479 | ||
4480 | val = sctp_sk(sk)->user_frag; | 4480 | val = sctp_sk(sk)->user_frag; |
4481 | if (put_user(len, optlen)) | 4481 | if (put_user(len, optlen)) |
4482 | return -EFAULT; | 4482 | return -EFAULT; |
4483 | if (copy_to_user(optval, &val, len)) | 4483 | if (copy_to_user(optval, &val, len)) |
4484 | return -EFAULT; | 4484 | return -EFAULT; |
4485 | 4485 | ||
4486 | return 0; | 4486 | return 0; |
4487 | } | 4487 | } |
4488 | 4488 | ||
4489 | SCTP_STATIC int sctp_getsockopt(struct sock *sk, int level, int optname, | 4489 | SCTP_STATIC int sctp_getsockopt(struct sock *sk, int level, int optname, |
4490 | char __user *optval, int __user *optlen) | 4490 | char __user *optval, int __user *optlen) |
4491 | { | 4491 | { |
4492 | int retval = 0; | 4492 | int retval = 0; |
4493 | int len; | 4493 | int len; |
4494 | 4494 | ||
4495 | SCTP_DEBUG_PRINTK("sctp_getsockopt(sk: %p... optname: %d)\n", | 4495 | SCTP_DEBUG_PRINTK("sctp_getsockopt(sk: %p... optname: %d)\n", |
4496 | sk, optname); | 4496 | sk, optname); |
4497 | 4497 | ||
4498 | /* I can hardly begin to describe how wrong this is. This is | 4498 | /* I can hardly begin to describe how wrong this is. This is |
4499 | * so broken as to be worse than useless. The API draft | 4499 | * so broken as to be worse than useless. The API draft |
4500 | * REALLY is NOT helpful here... I am not convinced that the | 4500 | * REALLY is NOT helpful here... I am not convinced that the |
4501 | * semantics of getsockopt() with a level OTHER THAN SOL_SCTP | 4501 | * semantics of getsockopt() with a level OTHER THAN SOL_SCTP |
4502 | * are at all well-founded. | 4502 | * are at all well-founded. |
4503 | */ | 4503 | */ |
4504 | if (level != SOL_SCTP) { | 4504 | if (level != SOL_SCTP) { |
4505 | struct sctp_af *af = sctp_sk(sk)->pf->af; | 4505 | struct sctp_af *af = sctp_sk(sk)->pf->af; |
4506 | 4506 | ||
4507 | retval = af->getsockopt(sk, level, optname, optval, optlen); | 4507 | retval = af->getsockopt(sk, level, optname, optval, optlen); |
4508 | return retval; | 4508 | return retval; |
4509 | } | 4509 | } |
4510 | 4510 | ||
4511 | if (get_user(len, optlen)) | 4511 | if (get_user(len, optlen)) |
4512 | return -EFAULT; | 4512 | return -EFAULT; |
4513 | 4513 | ||
4514 | sctp_lock_sock(sk); | 4514 | sctp_lock_sock(sk); |
4515 | 4515 | ||
4516 | switch (optname) { | 4516 | switch (optname) { |
4517 | case SCTP_STATUS: | 4517 | case SCTP_STATUS: |
4518 | retval = sctp_getsockopt_sctp_status(sk, len, optval, optlen); | 4518 | retval = sctp_getsockopt_sctp_status(sk, len, optval, optlen); |
4519 | break; | 4519 | break; |
4520 | case SCTP_DISABLE_FRAGMENTS: | 4520 | case SCTP_DISABLE_FRAGMENTS: |
4521 | retval = sctp_getsockopt_disable_fragments(sk, len, optval, | 4521 | retval = sctp_getsockopt_disable_fragments(sk, len, optval, |
4522 | optlen); | 4522 | optlen); |
4523 | break; | 4523 | break; |
4524 | case SCTP_EVENTS: | 4524 | case SCTP_EVENTS: |
4525 | retval = sctp_getsockopt_events(sk, len, optval, optlen); | 4525 | retval = sctp_getsockopt_events(sk, len, optval, optlen); |
4526 | break; | 4526 | break; |
4527 | case SCTP_AUTOCLOSE: | 4527 | case SCTP_AUTOCLOSE: |
4528 | retval = sctp_getsockopt_autoclose(sk, len, optval, optlen); | 4528 | retval = sctp_getsockopt_autoclose(sk, len, optval, optlen); |
4529 | break; | 4529 | break; |
4530 | case SCTP_SOCKOPT_PEELOFF: | 4530 | case SCTP_SOCKOPT_PEELOFF: |
4531 | retval = sctp_getsockopt_peeloff(sk, len, optval, optlen); | 4531 | retval = sctp_getsockopt_peeloff(sk, len, optval, optlen); |
4532 | break; | 4532 | break; |
4533 | case SCTP_PEER_ADDR_PARAMS: | 4533 | case SCTP_PEER_ADDR_PARAMS: |
4534 | retval = sctp_getsockopt_peer_addr_params(sk, len, optval, | 4534 | retval = sctp_getsockopt_peer_addr_params(sk, len, optval, |
4535 | optlen); | 4535 | optlen); |
4536 | break; | 4536 | break; |
4537 | case SCTP_DELAYED_ACK_TIME: | 4537 | case SCTP_DELAYED_ACK_TIME: |
4538 | retval = sctp_getsockopt_delayed_ack_time(sk, len, optval, | 4538 | retval = sctp_getsockopt_delayed_ack_time(sk, len, optval, |
4539 | optlen); | 4539 | optlen); |
4540 | break; | 4540 | break; |
4541 | case SCTP_INITMSG: | 4541 | case SCTP_INITMSG: |
4542 | retval = sctp_getsockopt_initmsg(sk, len, optval, optlen); | 4542 | retval = sctp_getsockopt_initmsg(sk, len, optval, optlen); |
4543 | break; | 4543 | break; |
4544 | case SCTP_GET_PEER_ADDRS_NUM_OLD: | 4544 | case SCTP_GET_PEER_ADDRS_NUM_OLD: |
4545 | retval = sctp_getsockopt_peer_addrs_num_old(sk, len, optval, | 4545 | retval = sctp_getsockopt_peer_addrs_num_old(sk, len, optval, |
4546 | optlen); | 4546 | optlen); |
4547 | break; | 4547 | break; |
4548 | case SCTP_GET_LOCAL_ADDRS_NUM_OLD: | 4548 | case SCTP_GET_LOCAL_ADDRS_NUM_OLD: |
4549 | retval = sctp_getsockopt_local_addrs_num_old(sk, len, optval, | 4549 | retval = sctp_getsockopt_local_addrs_num_old(sk, len, optval, |
4550 | optlen); | 4550 | optlen); |
4551 | break; | 4551 | break; |
4552 | case SCTP_GET_PEER_ADDRS_OLD: | 4552 | case SCTP_GET_PEER_ADDRS_OLD: |
4553 | retval = sctp_getsockopt_peer_addrs_old(sk, len, optval, | 4553 | retval = sctp_getsockopt_peer_addrs_old(sk, len, optval, |
4554 | optlen); | 4554 | optlen); |
4555 | break; | 4555 | break; |
4556 | case SCTP_GET_LOCAL_ADDRS_OLD: | 4556 | case SCTP_GET_LOCAL_ADDRS_OLD: |
4557 | retval = sctp_getsockopt_local_addrs_old(sk, len, optval, | 4557 | retval = sctp_getsockopt_local_addrs_old(sk, len, optval, |
4558 | optlen); | 4558 | optlen); |
4559 | break; | 4559 | break; |
4560 | case SCTP_GET_PEER_ADDRS: | 4560 | case SCTP_GET_PEER_ADDRS: |
4561 | retval = sctp_getsockopt_peer_addrs(sk, len, optval, | 4561 | retval = sctp_getsockopt_peer_addrs(sk, len, optval, |
4562 | optlen); | 4562 | optlen); |
4563 | break; | 4563 | break; |
4564 | case SCTP_GET_LOCAL_ADDRS: | 4564 | case SCTP_GET_LOCAL_ADDRS: |
4565 | retval = sctp_getsockopt_local_addrs(sk, len, optval, | 4565 | retval = sctp_getsockopt_local_addrs(sk, len, optval, |
4566 | optlen); | 4566 | optlen); |
4567 | break; | 4567 | break; |
4568 | case SCTP_DEFAULT_SEND_PARAM: | 4568 | case SCTP_DEFAULT_SEND_PARAM: |
4569 | retval = sctp_getsockopt_default_send_param(sk, len, | 4569 | retval = sctp_getsockopt_default_send_param(sk, len, |
4570 | optval, optlen); | 4570 | optval, optlen); |
4571 | break; | 4571 | break; |
4572 | case SCTP_PRIMARY_ADDR: | 4572 | case SCTP_PRIMARY_ADDR: |
4573 | retval = sctp_getsockopt_primary_addr(sk, len, optval, optlen); | 4573 | retval = sctp_getsockopt_primary_addr(sk, len, optval, optlen); |
4574 | break; | 4574 | break; |
4575 | case SCTP_NODELAY: | 4575 | case SCTP_NODELAY: |
4576 | retval = sctp_getsockopt_nodelay(sk, len, optval, optlen); | 4576 | retval = sctp_getsockopt_nodelay(sk, len, optval, optlen); |
4577 | break; | 4577 | break; |
4578 | case SCTP_RTOINFO: | 4578 | case SCTP_RTOINFO: |
4579 | retval = sctp_getsockopt_rtoinfo(sk, len, optval, optlen); | 4579 | retval = sctp_getsockopt_rtoinfo(sk, len, optval, optlen); |
4580 | break; | 4580 | break; |
4581 | case SCTP_ASSOCINFO: | 4581 | case SCTP_ASSOCINFO: |
4582 | retval = sctp_getsockopt_associnfo(sk, len, optval, optlen); | 4582 | retval = sctp_getsockopt_associnfo(sk, len, optval, optlen); |
4583 | break; | 4583 | break; |
4584 | case SCTP_I_WANT_MAPPED_V4_ADDR: | 4584 | case SCTP_I_WANT_MAPPED_V4_ADDR: |
4585 | retval = sctp_getsockopt_mappedv4(sk, len, optval, optlen); | 4585 | retval = sctp_getsockopt_mappedv4(sk, len, optval, optlen); |
4586 | break; | 4586 | break; |
4587 | case SCTP_MAXSEG: | 4587 | case SCTP_MAXSEG: |
4588 | retval = sctp_getsockopt_maxseg(sk, len, optval, optlen); | 4588 | retval = sctp_getsockopt_maxseg(sk, len, optval, optlen); |
4589 | break; | 4589 | break; |
4590 | case SCTP_GET_PEER_ADDR_INFO: | 4590 | case SCTP_GET_PEER_ADDR_INFO: |
4591 | retval = sctp_getsockopt_peer_addr_info(sk, len, optval, | 4591 | retval = sctp_getsockopt_peer_addr_info(sk, len, optval, |
4592 | optlen); | 4592 | optlen); |
4593 | break; | 4593 | break; |
4594 | case SCTP_ADAPTION_LAYER: | 4594 | case SCTP_ADAPTION_LAYER: |
4595 | retval = sctp_getsockopt_adaption_layer(sk, len, optval, | 4595 | retval = sctp_getsockopt_adaption_layer(sk, len, optval, |
4596 | optlen); | 4596 | optlen); |
4597 | break; | 4597 | break; |
4598 | default: | 4598 | default: |
4599 | retval = -ENOPROTOOPT; | 4599 | retval = -ENOPROTOOPT; |
4600 | break; | 4600 | break; |
4601 | }; | 4601 | }; |
4602 | 4602 | ||
4603 | sctp_release_sock(sk); | 4603 | sctp_release_sock(sk); |
4604 | return retval; | 4604 | return retval; |
4605 | } | 4605 | } |
4606 | 4606 | ||
4607 | static void sctp_hash(struct sock *sk) | 4607 | static void sctp_hash(struct sock *sk) |
4608 | { | 4608 | { |
4609 | /* STUB */ | 4609 | /* STUB */ |
4610 | } | 4610 | } |
4611 | 4611 | ||
4612 | static void sctp_unhash(struct sock *sk) | 4612 | static void sctp_unhash(struct sock *sk) |
4613 | { | 4613 | { |
4614 | /* STUB */ | 4614 | /* STUB */ |
4615 | } | 4615 | } |
4616 | 4616 | ||
4617 | /* Check if port is acceptable. Possibly find first available port. | 4617 | /* Check if port is acceptable. Possibly find first available port. |
4618 | * | 4618 | * |
4619 | * The port hash table (contained in the 'global' SCTP protocol storage | 4619 | * The port hash table (contained in the 'global' SCTP protocol storage |
4620 | * returned by struct sctp_protocol *sctp_get_protocol()). The hash | 4620 | * returned by struct sctp_protocol *sctp_get_protocol()). The hash |
4621 | * table is an array of 4096 lists (sctp_bind_hashbucket). Each | 4621 | * table is an array of 4096 lists (sctp_bind_hashbucket). Each |
4622 | * list (the list number is the port number hashed out, so as you | 4622 | * list (the list number is the port number hashed out, so as you |
4623 | * would expect from a hash function, all the ports in a given list have | 4623 | * would expect from a hash function, all the ports in a given list have |
4624 | * such a number that hashes out to the same list number; you were | 4624 | * such a number that hashes out to the same list number; you were |
4625 | * expecting that, right?); so each list has a set of ports, with a | 4625 | * expecting that, right?); so each list has a set of ports, with a |
4626 | * link to the socket (struct sock) that uses it, the port number and | 4626 | * link to the socket (struct sock) that uses it, the port number and |
4627 | * a fastreuse flag (FIXME: NPI ipg). | 4627 | * a fastreuse flag (FIXME: NPI ipg). |
4628 | */ | 4628 | */ |
4629 | static struct sctp_bind_bucket *sctp_bucket_create( | 4629 | static struct sctp_bind_bucket *sctp_bucket_create( |
4630 | struct sctp_bind_hashbucket *head, unsigned short snum); | 4630 | struct sctp_bind_hashbucket *head, unsigned short snum); |
4631 | 4631 | ||
4632 | static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr) | 4632 | static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr) |
4633 | { | 4633 | { |
4634 | struct sctp_bind_hashbucket *head; /* hash list */ | 4634 | struct sctp_bind_hashbucket *head; /* hash list */ |
4635 | struct sctp_bind_bucket *pp; /* hash list port iterator */ | 4635 | struct sctp_bind_bucket *pp; /* hash list port iterator */ |
4636 | unsigned short snum; | 4636 | unsigned short snum; |
4637 | int ret; | 4637 | int ret; |
4638 | 4638 | ||
4639 | /* NOTE: Remember to put this back to net order. */ | 4639 | /* NOTE: Remember to put this back to net order. */ |
4640 | addr->v4.sin_port = ntohs(addr->v4.sin_port); | 4640 | addr->v4.sin_port = ntohs(addr->v4.sin_port); |
4641 | snum = addr->v4.sin_port; | 4641 | snum = addr->v4.sin_port; |
4642 | 4642 | ||
4643 | SCTP_DEBUG_PRINTK("sctp_get_port() begins, snum=%d\n", snum); | 4643 | SCTP_DEBUG_PRINTK("sctp_get_port() begins, snum=%d\n", snum); |
4644 | sctp_local_bh_disable(); | 4644 | sctp_local_bh_disable(); |
4645 | 4645 | ||
4646 | if (snum == 0) { | 4646 | if (snum == 0) { |
4647 | /* Search for an available port. | 4647 | /* Search for an available port. |
4648 | * | 4648 | * |
4649 | * 'sctp_port_rover' was the last port assigned, so | 4649 | * 'sctp_port_rover' was the last port assigned, so |
4650 | * we start to search from 'sctp_port_rover + | 4650 | * we start to search from 'sctp_port_rover + |
4651 | * 1'. What we do is first check if port 'rover' is | 4651 | * 1'. What we do is first check if port 'rover' is |
4652 | * already in the hash table; if not, we use that; if | 4652 | * already in the hash table; if not, we use that; if |
4653 | * it is, we try next. | 4653 | * it is, we try next. |
4654 | */ | 4654 | */ |
4655 | int low = sysctl_local_port_range[0]; | 4655 | int low = sysctl_local_port_range[0]; |
4656 | int high = sysctl_local_port_range[1]; | 4656 | int high = sysctl_local_port_range[1]; |
4657 | int remaining = (high - low) + 1; | 4657 | int remaining = (high - low) + 1; |
4658 | int rover; | 4658 | int rover; |
4659 | int index; | 4659 | int index; |
4660 | 4660 | ||
4661 | sctp_spin_lock(&sctp_port_alloc_lock); | 4661 | sctp_spin_lock(&sctp_port_alloc_lock); |
4662 | rover = sctp_port_rover; | 4662 | rover = sctp_port_rover; |
4663 | do { | 4663 | do { |
4664 | rover++; | 4664 | rover++; |
4665 | if ((rover < low) || (rover > high)) | 4665 | if ((rover < low) || (rover > high)) |
4666 | rover = low; | 4666 | rover = low; |
4667 | index = sctp_phashfn(rover); | 4667 | index = sctp_phashfn(rover); |
4668 | head = &sctp_port_hashtable[index]; | 4668 | head = &sctp_port_hashtable[index]; |
4669 | sctp_spin_lock(&head->lock); | 4669 | sctp_spin_lock(&head->lock); |
4670 | for (pp = head->chain; pp; pp = pp->next) | 4670 | for (pp = head->chain; pp; pp = pp->next) |
4671 | if (pp->port == rover) | 4671 | if (pp->port == rover) |
4672 | goto next; | 4672 | goto next; |
4673 | break; | 4673 | break; |
4674 | next: | 4674 | next: |
4675 | sctp_spin_unlock(&head->lock); | 4675 | sctp_spin_unlock(&head->lock); |
4676 | } while (--remaining > 0); | 4676 | } while (--remaining > 0); |
4677 | sctp_port_rover = rover; | 4677 | sctp_port_rover = rover; |
4678 | sctp_spin_unlock(&sctp_port_alloc_lock); | 4678 | sctp_spin_unlock(&sctp_port_alloc_lock); |
4679 | 4679 | ||
4680 | /* Exhausted local port range during search? */ | 4680 | /* Exhausted local port range during search? */ |
4681 | ret = 1; | 4681 | ret = 1; |
4682 | if (remaining <= 0) | 4682 | if (remaining <= 0) |
4683 | goto fail; | 4683 | goto fail; |
4684 | 4684 | ||
4685 | /* OK, here is the one we will use. HEAD (the port | 4685 | /* OK, here is the one we will use. HEAD (the port |
4686 | * hash table list entry) is non-NULL and we hold it's | 4686 | * hash table list entry) is non-NULL and we hold it's |
4687 | * mutex. | 4687 | * mutex. |
4688 | */ | 4688 | */ |
4689 | snum = rover; | 4689 | snum = rover; |
4690 | } else { | 4690 | } else { |
4691 | /* We are given an specific port number; we verify | 4691 | /* We are given an specific port number; we verify |
4692 | * that it is not being used. If it is used, we will | 4692 | * that it is not being used. If it is used, we will |
4693 | * exahust the search in the hash list corresponding | 4693 | * exahust the search in the hash list corresponding |
4694 | * to the port number (snum) - we detect that with the | 4694 | * to the port number (snum) - we detect that with the |
4695 | * port iterator, pp being NULL. | 4695 | * port iterator, pp being NULL. |
4696 | */ | 4696 | */ |
4697 | head = &sctp_port_hashtable[sctp_phashfn(snum)]; | 4697 | head = &sctp_port_hashtable[sctp_phashfn(snum)]; |
4698 | sctp_spin_lock(&head->lock); | 4698 | sctp_spin_lock(&head->lock); |
4699 | for (pp = head->chain; pp; pp = pp->next) { | 4699 | for (pp = head->chain; pp; pp = pp->next) { |
4700 | if (pp->port == snum) | 4700 | if (pp->port == snum) |
4701 | goto pp_found; | 4701 | goto pp_found; |
4702 | } | 4702 | } |
4703 | } | 4703 | } |
4704 | pp = NULL; | 4704 | pp = NULL; |
4705 | goto pp_not_found; | 4705 | goto pp_not_found; |
4706 | pp_found: | 4706 | pp_found: |
4707 | if (!hlist_empty(&pp->owner)) { | 4707 | if (!hlist_empty(&pp->owner)) { |
4708 | /* We had a port hash table hit - there is an | 4708 | /* We had a port hash table hit - there is an |
4709 | * available port (pp != NULL) and it is being | 4709 | * available port (pp != NULL) and it is being |
4710 | * used by other socket (pp->owner not empty); that other | 4710 | * used by other socket (pp->owner not empty); that other |
4711 | * socket is going to be sk2. | 4711 | * socket is going to be sk2. |
4712 | */ | 4712 | */ |
4713 | int reuse = sk->sk_reuse; | 4713 | int reuse = sk->sk_reuse; |
4714 | struct sock *sk2; | 4714 | struct sock *sk2; |
4715 | struct hlist_node *node; | 4715 | struct hlist_node *node; |
4716 | 4716 | ||
4717 | SCTP_DEBUG_PRINTK("sctp_get_port() found a possible match\n"); | 4717 | SCTP_DEBUG_PRINTK("sctp_get_port() found a possible match\n"); |
4718 | if (pp->fastreuse && sk->sk_reuse) | 4718 | if (pp->fastreuse && sk->sk_reuse) |
4719 | goto success; | 4719 | goto success; |
4720 | 4720 | ||
4721 | /* Run through the list of sockets bound to the port | 4721 | /* Run through the list of sockets bound to the port |
4722 | * (pp->port) [via the pointers bind_next and | 4722 | * (pp->port) [via the pointers bind_next and |
4723 | * bind_pprev in the struct sock *sk2 (pp->sk)]. On each one, | 4723 | * bind_pprev in the struct sock *sk2 (pp->sk)]. On each one, |
4724 | * we get the endpoint they describe and run through | 4724 | * we get the endpoint they describe and run through |
4725 | * the endpoint's list of IP (v4 or v6) addresses, | 4725 | * the endpoint's list of IP (v4 or v6) addresses, |
4726 | * comparing each of the addresses with the address of | 4726 | * comparing each of the addresses with the address of |
4727 | * the socket sk. If we find a match, then that means | 4727 | * the socket sk. If we find a match, then that means |
4728 | * that this port/socket (sk) combination are already | 4728 | * that this port/socket (sk) combination are already |
4729 | * in an endpoint. | 4729 | * in an endpoint. |
4730 | */ | 4730 | */ |
4731 | sk_for_each_bound(sk2, node, &pp->owner) { | 4731 | sk_for_each_bound(sk2, node, &pp->owner) { |
4732 | struct sctp_endpoint *ep2; | 4732 | struct sctp_endpoint *ep2; |
4733 | ep2 = sctp_sk(sk2)->ep; | 4733 | ep2 = sctp_sk(sk2)->ep; |
4734 | 4734 | ||
4735 | if (reuse && sk2->sk_reuse) | 4735 | if (reuse && sk2->sk_reuse) |
4736 | continue; | 4736 | continue; |
4737 | 4737 | ||
4738 | if (sctp_bind_addr_match(&ep2->base.bind_addr, addr, | 4738 | if (sctp_bind_addr_match(&ep2->base.bind_addr, addr, |
4739 | sctp_sk(sk))) { | 4739 | sctp_sk(sk))) { |
4740 | ret = (long)sk2; | 4740 | ret = (long)sk2; |
4741 | goto fail_unlock; | 4741 | goto fail_unlock; |
4742 | } | 4742 | } |
4743 | } | 4743 | } |
4744 | SCTP_DEBUG_PRINTK("sctp_get_port(): Found a match\n"); | 4744 | SCTP_DEBUG_PRINTK("sctp_get_port(): Found a match\n"); |
4745 | } | 4745 | } |
4746 | pp_not_found: | 4746 | pp_not_found: |
4747 | /* If there was a hash table miss, create a new port. */ | 4747 | /* If there was a hash table miss, create a new port. */ |
4748 | ret = 1; | 4748 | ret = 1; |
4749 | if (!pp && !(pp = sctp_bucket_create(head, snum))) | 4749 | if (!pp && !(pp = sctp_bucket_create(head, snum))) |
4750 | goto fail_unlock; | 4750 | goto fail_unlock; |
4751 | 4751 | ||
4752 | /* In either case (hit or miss), make sure fastreuse is 1 only | 4752 | /* In either case (hit or miss), make sure fastreuse is 1 only |
4753 | * if sk->sk_reuse is too (that is, if the caller requested | 4753 | * if sk->sk_reuse is too (that is, if the caller requested |
4754 | * SO_REUSEADDR on this socket -sk-). | 4754 | * SO_REUSEADDR on this socket -sk-). |
4755 | */ | 4755 | */ |
4756 | if (hlist_empty(&pp->owner)) | 4756 | if (hlist_empty(&pp->owner)) |
4757 | pp->fastreuse = sk->sk_reuse ? 1 : 0; | 4757 | pp->fastreuse = sk->sk_reuse ? 1 : 0; |
4758 | else if (pp->fastreuse && !sk->sk_reuse) | 4758 | else if (pp->fastreuse && !sk->sk_reuse) |
4759 | pp->fastreuse = 0; | 4759 | pp->fastreuse = 0; |
4760 | 4760 | ||
4761 | /* We are set, so fill up all the data in the hash table | 4761 | /* We are set, so fill up all the data in the hash table |
4762 | * entry, tie the socket list information with the rest of the | 4762 | * entry, tie the socket list information with the rest of the |
4763 | * sockets FIXME: Blurry, NPI (ipg). | 4763 | * sockets FIXME: Blurry, NPI (ipg). |
4764 | */ | 4764 | */ |
4765 | success: | 4765 | success: |
4766 | inet_sk(sk)->num = snum; | 4766 | inet_sk(sk)->num = snum; |
4767 | if (!sctp_sk(sk)->bind_hash) { | 4767 | if (!sctp_sk(sk)->bind_hash) { |
4768 | sk_add_bind_node(sk, &pp->owner); | 4768 | sk_add_bind_node(sk, &pp->owner); |
4769 | sctp_sk(sk)->bind_hash = pp; | 4769 | sctp_sk(sk)->bind_hash = pp; |
4770 | } | 4770 | } |
4771 | ret = 0; | 4771 | ret = 0; |
4772 | 4772 | ||
4773 | fail_unlock: | 4773 | fail_unlock: |
4774 | sctp_spin_unlock(&head->lock); | 4774 | sctp_spin_unlock(&head->lock); |
4775 | 4775 | ||
4776 | fail: | 4776 | fail: |
4777 | sctp_local_bh_enable(); | 4777 | sctp_local_bh_enable(); |
4778 | addr->v4.sin_port = htons(addr->v4.sin_port); | 4778 | addr->v4.sin_port = htons(addr->v4.sin_port); |
4779 | return ret; | 4779 | return ret; |
4780 | } | 4780 | } |
4781 | 4781 | ||
4782 | /* Assign a 'snum' port to the socket. If snum == 0, an ephemeral | 4782 | /* Assign a 'snum' port to the socket. If snum == 0, an ephemeral |
4783 | * port is requested. | 4783 | * port is requested. |
4784 | */ | 4784 | */ |
4785 | static int sctp_get_port(struct sock *sk, unsigned short snum) | 4785 | static int sctp_get_port(struct sock *sk, unsigned short snum) |
4786 | { | 4786 | { |
4787 | long ret; | 4787 | long ret; |
4788 | union sctp_addr addr; | 4788 | union sctp_addr addr; |
4789 | struct sctp_af *af = sctp_sk(sk)->pf->af; | 4789 | struct sctp_af *af = sctp_sk(sk)->pf->af; |
4790 | 4790 | ||
4791 | /* Set up a dummy address struct from the sk. */ | 4791 | /* Set up a dummy address struct from the sk. */ |
4792 | af->from_sk(&addr, sk); | 4792 | af->from_sk(&addr, sk); |
4793 | addr.v4.sin_port = htons(snum); | 4793 | addr.v4.sin_port = htons(snum); |
4794 | 4794 | ||
4795 | /* Note: sk->sk_num gets filled in if ephemeral port request. */ | 4795 | /* Note: sk->sk_num gets filled in if ephemeral port request. */ |
4796 | ret = sctp_get_port_local(sk, &addr); | 4796 | ret = sctp_get_port_local(sk, &addr); |
4797 | 4797 | ||
4798 | return (ret ? 1 : 0); | 4798 | return (ret ? 1 : 0); |
4799 | } | 4799 | } |
4800 | 4800 | ||
4801 | /* | 4801 | /* |
4802 | * 3.1.3 listen() - UDP Style Syntax | 4802 | * 3.1.3 listen() - UDP Style Syntax |
4803 | * | 4803 | * |
4804 | * By default, new associations are not accepted for UDP style sockets. | 4804 | * By default, new associations are not accepted for UDP style sockets. |
4805 | * An application uses listen() to mark a socket as being able to | 4805 | * An application uses listen() to mark a socket as being able to |
4806 | * accept new associations. | 4806 | * accept new associations. |
4807 | */ | 4807 | */ |
4808 | SCTP_STATIC int sctp_seqpacket_listen(struct sock *sk, int backlog) | 4808 | SCTP_STATIC int sctp_seqpacket_listen(struct sock *sk, int backlog) |
4809 | { | 4809 | { |
4810 | struct sctp_sock *sp = sctp_sk(sk); | 4810 | struct sctp_sock *sp = sctp_sk(sk); |
4811 | struct sctp_endpoint *ep = sp->ep; | 4811 | struct sctp_endpoint *ep = sp->ep; |
4812 | 4812 | ||
4813 | /* Only UDP style sockets that are not peeled off are allowed to | 4813 | /* Only UDP style sockets that are not peeled off are allowed to |
4814 | * listen(). | 4814 | * listen(). |
4815 | */ | 4815 | */ |
4816 | if (!sctp_style(sk, UDP)) | 4816 | if (!sctp_style(sk, UDP)) |
4817 | return -EINVAL; | 4817 | return -EINVAL; |
4818 | 4818 | ||
4819 | /* If backlog is zero, disable listening. */ | 4819 | /* If backlog is zero, disable listening. */ |
4820 | if (!backlog) { | 4820 | if (!backlog) { |
4821 | if (sctp_sstate(sk, CLOSED)) | 4821 | if (sctp_sstate(sk, CLOSED)) |
4822 | return 0; | 4822 | return 0; |
4823 | 4823 | ||
4824 | sctp_unhash_endpoint(ep); | 4824 | sctp_unhash_endpoint(ep); |
4825 | sk->sk_state = SCTP_SS_CLOSED; | 4825 | sk->sk_state = SCTP_SS_CLOSED; |
4826 | } | 4826 | } |
4827 | 4827 | ||
4828 | /* Return if we are already listening. */ | 4828 | /* Return if we are already listening. */ |
4829 | if (sctp_sstate(sk, LISTENING)) | 4829 | if (sctp_sstate(sk, LISTENING)) |
4830 | return 0; | 4830 | return 0; |
4831 | 4831 | ||
4832 | /* | 4832 | /* |
4833 | * If a bind() or sctp_bindx() is not called prior to a listen() | 4833 | * If a bind() or sctp_bindx() is not called prior to a listen() |
4834 | * call that allows new associations to be accepted, the system | 4834 | * call that allows new associations to be accepted, the system |
4835 | * picks an ephemeral port and will choose an address set equivalent | 4835 | * picks an ephemeral port and will choose an address set equivalent |
4836 | * to binding with a wildcard address. | 4836 | * to binding with a wildcard address. |
4837 | * | 4837 | * |
4838 | * This is not currently spelled out in the SCTP sockets | 4838 | * This is not currently spelled out in the SCTP sockets |
4839 | * extensions draft, but follows the practice as seen in TCP | 4839 | * extensions draft, but follows the practice as seen in TCP |
4840 | * sockets. | 4840 | * sockets. |
4841 | */ | 4841 | */ |
4842 | if (!ep->base.bind_addr.port) { | 4842 | if (!ep->base.bind_addr.port) { |
4843 | if (sctp_autobind(sk)) | 4843 | if (sctp_autobind(sk)) |
4844 | return -EAGAIN; | 4844 | return -EAGAIN; |
4845 | } | 4845 | } |
4846 | sk->sk_state = SCTP_SS_LISTENING; | 4846 | sk->sk_state = SCTP_SS_LISTENING; |
4847 | sctp_hash_endpoint(ep); | 4847 | sctp_hash_endpoint(ep); |
4848 | return 0; | 4848 | return 0; |
4849 | } | 4849 | } |
4850 | 4850 | ||
4851 | /* | 4851 | /* |
4852 | * 4.1.3 listen() - TCP Style Syntax | 4852 | * 4.1.3 listen() - TCP Style Syntax |
4853 | * | 4853 | * |
4854 | * Applications uses listen() to ready the SCTP endpoint for accepting | 4854 | * Applications uses listen() to ready the SCTP endpoint for accepting |
4855 | * inbound associations. | 4855 | * inbound associations. |
4856 | */ | 4856 | */ |
4857 | SCTP_STATIC int sctp_stream_listen(struct sock *sk, int backlog) | 4857 | SCTP_STATIC int sctp_stream_listen(struct sock *sk, int backlog) |
4858 | { | 4858 | { |
4859 | struct sctp_sock *sp = sctp_sk(sk); | 4859 | struct sctp_sock *sp = sctp_sk(sk); |
4860 | struct sctp_endpoint *ep = sp->ep; | 4860 | struct sctp_endpoint *ep = sp->ep; |
4861 | 4861 | ||
4862 | /* If backlog is zero, disable listening. */ | 4862 | /* If backlog is zero, disable listening. */ |
4863 | if (!backlog) { | 4863 | if (!backlog) { |
4864 | if (sctp_sstate(sk, CLOSED)) | 4864 | if (sctp_sstate(sk, CLOSED)) |
4865 | return 0; | 4865 | return 0; |
4866 | 4866 | ||
4867 | sctp_unhash_endpoint(ep); | 4867 | sctp_unhash_endpoint(ep); |
4868 | sk->sk_state = SCTP_SS_CLOSED; | 4868 | sk->sk_state = SCTP_SS_CLOSED; |
4869 | } | 4869 | } |
4870 | 4870 | ||
4871 | if (sctp_sstate(sk, LISTENING)) | 4871 | if (sctp_sstate(sk, LISTENING)) |
4872 | return 0; | 4872 | return 0; |
4873 | 4873 | ||
4874 | /* | 4874 | /* |
4875 | * If a bind() or sctp_bindx() is not called prior to a listen() | 4875 | * If a bind() or sctp_bindx() is not called prior to a listen() |
4876 | * call that allows new associations to be accepted, the system | 4876 | * call that allows new associations to be accepted, the system |
4877 | * picks an ephemeral port and will choose an address set equivalent | 4877 | * picks an ephemeral port and will choose an address set equivalent |
4878 | * to binding with a wildcard address. | 4878 | * to binding with a wildcard address. |
4879 | * | 4879 | * |
4880 | * This is not currently spelled out in the SCTP sockets | 4880 | * This is not currently spelled out in the SCTP sockets |
4881 | * extensions draft, but follows the practice as seen in TCP | 4881 | * extensions draft, but follows the practice as seen in TCP |
4882 | * sockets. | 4882 | * sockets. |
4883 | */ | 4883 | */ |
4884 | if (!ep->base.bind_addr.port) { | 4884 | if (!ep->base.bind_addr.port) { |
4885 | if (sctp_autobind(sk)) | 4885 | if (sctp_autobind(sk)) |
4886 | return -EAGAIN; | 4886 | return -EAGAIN; |
4887 | } | 4887 | } |
4888 | sk->sk_state = SCTP_SS_LISTENING; | 4888 | sk->sk_state = SCTP_SS_LISTENING; |
4889 | sk->sk_max_ack_backlog = backlog; | 4889 | sk->sk_max_ack_backlog = backlog; |
4890 | sctp_hash_endpoint(ep); | 4890 | sctp_hash_endpoint(ep); |
4891 | return 0; | 4891 | return 0; |
4892 | } | 4892 | } |
4893 | 4893 | ||
4894 | /* | 4894 | /* |
4895 | * Move a socket to LISTENING state. | 4895 | * Move a socket to LISTENING state. |
4896 | */ | 4896 | */ |
4897 | int sctp_inet_listen(struct socket *sock, int backlog) | 4897 | int sctp_inet_listen(struct socket *sock, int backlog) |
4898 | { | 4898 | { |
4899 | struct sock *sk = sock->sk; | 4899 | struct sock *sk = sock->sk; |
4900 | struct crypto_hash *tfm = NULL; | 4900 | struct crypto_hash *tfm = NULL; |
4901 | int err = -EINVAL; | 4901 | int err = -EINVAL; |
4902 | 4902 | ||
4903 | if (unlikely(backlog < 0)) | 4903 | if (unlikely(backlog < 0)) |
4904 | goto out; | 4904 | goto out; |
4905 | 4905 | ||
4906 | sctp_lock_sock(sk); | 4906 | sctp_lock_sock(sk); |
4907 | 4907 | ||
4908 | if (sock->state != SS_UNCONNECTED) | 4908 | if (sock->state != SS_UNCONNECTED) |
4909 | goto out; | 4909 | goto out; |
4910 | 4910 | ||
4911 | /* Allocate HMAC for generating cookie. */ | 4911 | /* Allocate HMAC for generating cookie. */ |
4912 | if (sctp_hmac_alg) { | 4912 | if (sctp_hmac_alg) { |
4913 | tfm = crypto_alloc_hash(sctp_hmac_alg, 0, CRYPTO_ALG_ASYNC); | 4913 | tfm = crypto_alloc_hash(sctp_hmac_alg, 0, CRYPTO_ALG_ASYNC); |
4914 | if (!tfm) { | 4914 | if (!tfm) { |
4915 | err = -ENOSYS; | 4915 | err = -ENOSYS; |
4916 | goto out; | 4916 | goto out; |
4917 | } | 4917 | } |
4918 | } | 4918 | } |
4919 | 4919 | ||
4920 | switch (sock->type) { | 4920 | switch (sock->type) { |
4921 | case SOCK_SEQPACKET: | 4921 | case SOCK_SEQPACKET: |
4922 | err = sctp_seqpacket_listen(sk, backlog); | 4922 | err = sctp_seqpacket_listen(sk, backlog); |
4923 | break; | 4923 | break; |
4924 | case SOCK_STREAM: | 4924 | case SOCK_STREAM: |
4925 | err = sctp_stream_listen(sk, backlog); | 4925 | err = sctp_stream_listen(sk, backlog); |
4926 | break; | 4926 | break; |
4927 | default: | 4927 | default: |
4928 | break; | 4928 | break; |
4929 | }; | 4929 | }; |
4930 | if (err) | 4930 | if (err) |
4931 | goto cleanup; | 4931 | goto cleanup; |
4932 | 4932 | ||
4933 | /* Store away the transform reference. */ | 4933 | /* Store away the transform reference. */ |
4934 | sctp_sk(sk)->hmac = tfm; | 4934 | sctp_sk(sk)->hmac = tfm; |
4935 | out: | 4935 | out: |
4936 | sctp_release_sock(sk); | 4936 | sctp_release_sock(sk); |
4937 | return err; | 4937 | return err; |
4938 | cleanup: | 4938 | cleanup: |
4939 | crypto_free_hash(tfm); | 4939 | crypto_free_hash(tfm); |
4940 | goto out; | 4940 | goto out; |
4941 | } | 4941 | } |
4942 | 4942 | ||
4943 | /* | 4943 | /* |
4944 | * This function is done by modeling the current datagram_poll() and the | 4944 | * This function is done by modeling the current datagram_poll() and the |
4945 | * tcp_poll(). Note that, based on these implementations, we don't | 4945 | * tcp_poll(). Note that, based on these implementations, we don't |
4946 | * lock the socket in this function, even though it seems that, | 4946 | * lock the socket in this function, even though it seems that, |
4947 | * ideally, locking or some other mechanisms can be used to ensure | 4947 | * ideally, locking or some other mechanisms can be used to ensure |
4948 | * the integrity of the counters (sndbuf and wmem_alloc) used | 4948 | * the integrity of the counters (sndbuf and wmem_alloc) used |
4949 | * in this place. We assume that we don't need locks either until proven | 4949 | * in this place. We assume that we don't need locks either until proven |
4950 | * otherwise. | 4950 | * otherwise. |
4951 | * | 4951 | * |
4952 | * Another thing to note is that we include the Async I/O support | 4952 | * Another thing to note is that we include the Async I/O support |
4953 | * here, again, by modeling the current TCP/UDP code. We don't have | 4953 | * here, again, by modeling the current TCP/UDP code. We don't have |
4954 | * a good way to test with it yet. | 4954 | * a good way to test with it yet. |
4955 | */ | 4955 | */ |
4956 | unsigned int sctp_poll(struct file *file, struct socket *sock, poll_table *wait) | 4956 | unsigned int sctp_poll(struct file *file, struct socket *sock, poll_table *wait) |
4957 | { | 4957 | { |
4958 | struct sock *sk = sock->sk; | 4958 | struct sock *sk = sock->sk; |
4959 | struct sctp_sock *sp = sctp_sk(sk); | 4959 | struct sctp_sock *sp = sctp_sk(sk); |
4960 | unsigned int mask; | 4960 | unsigned int mask; |
4961 | 4961 | ||
4962 | poll_wait(file, sk->sk_sleep, wait); | 4962 | poll_wait(file, sk->sk_sleep, wait); |
4963 | 4963 | ||
4964 | /* A TCP-style listening socket becomes readable when the accept queue | 4964 | /* A TCP-style listening socket becomes readable when the accept queue |
4965 | * is not empty. | 4965 | * is not empty. |
4966 | */ | 4966 | */ |
4967 | if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING)) | 4967 | if (sctp_style(sk, TCP) && sctp_sstate(sk, LISTENING)) |
4968 | return (!list_empty(&sp->ep->asocs)) ? | 4968 | return (!list_empty(&sp->ep->asocs)) ? |
4969 | (POLLIN | POLLRDNORM) : 0; | 4969 | (POLLIN | POLLRDNORM) : 0; |
4970 | 4970 | ||
4971 | mask = 0; | 4971 | mask = 0; |
4972 | 4972 | ||
4973 | /* Is there any exceptional events? */ | 4973 | /* Is there any exceptional events? */ |
4974 | if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) | 4974 | if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) |
4975 | mask |= POLLERR; | 4975 | mask |= POLLERR; |
4976 | if (sk->sk_shutdown & RCV_SHUTDOWN) | 4976 | if (sk->sk_shutdown & RCV_SHUTDOWN) |
4977 | mask |= POLLRDHUP; | 4977 | mask |= POLLRDHUP; |
4978 | if (sk->sk_shutdown == SHUTDOWN_MASK) | 4978 | if (sk->sk_shutdown == SHUTDOWN_MASK) |
4979 | mask |= POLLHUP; | 4979 | mask |= POLLHUP; |
4980 | 4980 | ||
4981 | /* Is it readable? Reconsider this code with TCP-style support. */ | 4981 | /* Is it readable? Reconsider this code with TCP-style support. */ |
4982 | if (!skb_queue_empty(&sk->sk_receive_queue) || | 4982 | if (!skb_queue_empty(&sk->sk_receive_queue) || |
4983 | (sk->sk_shutdown & RCV_SHUTDOWN)) | 4983 | (sk->sk_shutdown & RCV_SHUTDOWN)) |
4984 | mask |= POLLIN | POLLRDNORM; | 4984 | mask |= POLLIN | POLLRDNORM; |
4985 | 4985 | ||
4986 | /* The association is either gone or not ready. */ | 4986 | /* The association is either gone or not ready. */ |
4987 | if (!sctp_style(sk, UDP) && sctp_sstate(sk, CLOSED)) | 4987 | if (!sctp_style(sk, UDP) && sctp_sstate(sk, CLOSED)) |
4988 | return mask; | 4988 | return mask; |
4989 | 4989 | ||
4990 | /* Is it writable? */ | 4990 | /* Is it writable? */ |
4991 | if (sctp_writeable(sk)) { | 4991 | if (sctp_writeable(sk)) { |
4992 | mask |= POLLOUT | POLLWRNORM; | 4992 | mask |= POLLOUT | POLLWRNORM; |
4993 | } else { | 4993 | } else { |
4994 | set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); | 4994 | set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); |
4995 | /* | 4995 | /* |
4996 | * Since the socket is not locked, the buffer | 4996 | * Since the socket is not locked, the buffer |
4997 | * might be made available after the writeable check and | 4997 | * might be made available after the writeable check and |
4998 | * before the bit is set. This could cause a lost I/O | 4998 | * before the bit is set. This could cause a lost I/O |
4999 | * signal. tcp_poll() has a race breaker for this race | 4999 | * signal. tcp_poll() has a race breaker for this race |
5000 | * condition. Based on their implementation, we put | 5000 | * condition. Based on their implementation, we put |
5001 | * in the following code to cover it as well. | 5001 | * in the following code to cover it as well. |
5002 | */ | 5002 | */ |
5003 | if (sctp_writeable(sk)) | 5003 | if (sctp_writeable(sk)) |
5004 | mask |= POLLOUT | POLLWRNORM; | 5004 | mask |= POLLOUT | POLLWRNORM; |
5005 | } | 5005 | } |
5006 | return mask; | 5006 | return mask; |
5007 | } | 5007 | } |
5008 | 5008 | ||
5009 | /******************************************************************** | 5009 | /******************************************************************** |
5010 | * 2nd Level Abstractions | 5010 | * 2nd Level Abstractions |
5011 | ********************************************************************/ | 5011 | ********************************************************************/ |
5012 | 5012 | ||
5013 | static struct sctp_bind_bucket *sctp_bucket_create( | 5013 | static struct sctp_bind_bucket *sctp_bucket_create( |
5014 | struct sctp_bind_hashbucket *head, unsigned short snum) | 5014 | struct sctp_bind_hashbucket *head, unsigned short snum) |
5015 | { | 5015 | { |
5016 | struct sctp_bind_bucket *pp; | 5016 | struct sctp_bind_bucket *pp; |
5017 | 5017 | ||
5018 | pp = kmem_cache_alloc(sctp_bucket_cachep, SLAB_ATOMIC); | 5018 | pp = kmem_cache_alloc(sctp_bucket_cachep, SLAB_ATOMIC); |
5019 | SCTP_DBG_OBJCNT_INC(bind_bucket); | 5019 | SCTP_DBG_OBJCNT_INC(bind_bucket); |
5020 | if (pp) { | 5020 | if (pp) { |
5021 | pp->port = snum; | 5021 | pp->port = snum; |
5022 | pp->fastreuse = 0; | 5022 | pp->fastreuse = 0; |
5023 | INIT_HLIST_HEAD(&pp->owner); | 5023 | INIT_HLIST_HEAD(&pp->owner); |
5024 | if ((pp->next = head->chain) != NULL) | 5024 | if ((pp->next = head->chain) != NULL) |
5025 | pp->next->pprev = &pp->next; | 5025 | pp->next->pprev = &pp->next; |
5026 | head->chain = pp; | 5026 | head->chain = pp; |
5027 | pp->pprev = &head->chain; | 5027 | pp->pprev = &head->chain; |
5028 | } | 5028 | } |
5029 | return pp; | 5029 | return pp; |
5030 | } | 5030 | } |
5031 | 5031 | ||
5032 | /* Caller must hold hashbucket lock for this tb with local BH disabled */ | 5032 | /* Caller must hold hashbucket lock for this tb with local BH disabled */ |
5033 | static void sctp_bucket_destroy(struct sctp_bind_bucket *pp) | 5033 | static void sctp_bucket_destroy(struct sctp_bind_bucket *pp) |
5034 | { | 5034 | { |
5035 | if (pp && hlist_empty(&pp->owner)) { | 5035 | if (pp && hlist_empty(&pp->owner)) { |
5036 | if (pp->next) | 5036 | if (pp->next) |
5037 | pp->next->pprev = pp->pprev; | 5037 | pp->next->pprev = pp->pprev; |
5038 | *(pp->pprev) = pp->next; | 5038 | *(pp->pprev) = pp->next; |
5039 | kmem_cache_free(sctp_bucket_cachep, pp); | 5039 | kmem_cache_free(sctp_bucket_cachep, pp); |
5040 | SCTP_DBG_OBJCNT_DEC(bind_bucket); | 5040 | SCTP_DBG_OBJCNT_DEC(bind_bucket); |
5041 | } | 5041 | } |
5042 | } | 5042 | } |
5043 | 5043 | ||
5044 | /* Release this socket's reference to a local port. */ | 5044 | /* Release this socket's reference to a local port. */ |
5045 | static inline void __sctp_put_port(struct sock *sk) | 5045 | static inline void __sctp_put_port(struct sock *sk) |
5046 | { | 5046 | { |
5047 | struct sctp_bind_hashbucket *head = | 5047 | struct sctp_bind_hashbucket *head = |
5048 | &sctp_port_hashtable[sctp_phashfn(inet_sk(sk)->num)]; | 5048 | &sctp_port_hashtable[sctp_phashfn(inet_sk(sk)->num)]; |
5049 | struct sctp_bind_bucket *pp; | 5049 | struct sctp_bind_bucket *pp; |
5050 | 5050 | ||
5051 | sctp_spin_lock(&head->lock); | 5051 | sctp_spin_lock(&head->lock); |
5052 | pp = sctp_sk(sk)->bind_hash; | 5052 | pp = sctp_sk(sk)->bind_hash; |
5053 | __sk_del_bind_node(sk); | 5053 | __sk_del_bind_node(sk); |
5054 | sctp_sk(sk)->bind_hash = NULL; | 5054 | sctp_sk(sk)->bind_hash = NULL; |
5055 | inet_sk(sk)->num = 0; | 5055 | inet_sk(sk)->num = 0; |
5056 | sctp_bucket_destroy(pp); | 5056 | sctp_bucket_destroy(pp); |
5057 | sctp_spin_unlock(&head->lock); | 5057 | sctp_spin_unlock(&head->lock); |
5058 | } | 5058 | } |
5059 | 5059 | ||
5060 | void sctp_put_port(struct sock *sk) | 5060 | void sctp_put_port(struct sock *sk) |
5061 | { | 5061 | { |
5062 | sctp_local_bh_disable(); | 5062 | sctp_local_bh_disable(); |
5063 | __sctp_put_port(sk); | 5063 | __sctp_put_port(sk); |
5064 | sctp_local_bh_enable(); | 5064 | sctp_local_bh_enable(); |
5065 | } | 5065 | } |
5066 | 5066 | ||
5067 | /* | 5067 | /* |
5068 | * The system picks an ephemeral port and choose an address set equivalent | 5068 | * The system picks an ephemeral port and choose an address set equivalent |
5069 | * to binding with a wildcard address. | 5069 | * to binding with a wildcard address. |
5070 | * One of those addresses will be the primary address for the association. | 5070 | * One of those addresses will be the primary address for the association. |
5071 | * This automatically enables the multihoming capability of SCTP. | 5071 | * This automatically enables the multihoming capability of SCTP. |
5072 | */ | 5072 | */ |
5073 | static int sctp_autobind(struct sock *sk) | 5073 | static int sctp_autobind(struct sock *sk) |
5074 | { | 5074 | { |
5075 | union sctp_addr autoaddr; | 5075 | union sctp_addr autoaddr; |
5076 | struct sctp_af *af; | 5076 | struct sctp_af *af; |
5077 | unsigned short port; | 5077 | unsigned short port; |
5078 | 5078 | ||
5079 | /* Initialize a local sockaddr structure to INADDR_ANY. */ | 5079 | /* Initialize a local sockaddr structure to INADDR_ANY. */ |
5080 | af = sctp_sk(sk)->pf->af; | 5080 | af = sctp_sk(sk)->pf->af; |
5081 | 5081 | ||
5082 | port = htons(inet_sk(sk)->num); | 5082 | port = htons(inet_sk(sk)->num); |
5083 | af->inaddr_any(&autoaddr, port); | 5083 | af->inaddr_any(&autoaddr, port); |
5084 | 5084 | ||
5085 | return sctp_do_bind(sk, &autoaddr, af->sockaddr_len); | 5085 | return sctp_do_bind(sk, &autoaddr, af->sockaddr_len); |
5086 | } | 5086 | } |
5087 | 5087 | ||
5088 | /* Parse out IPPROTO_SCTP CMSG headers. Perform only minimal validation. | 5088 | /* Parse out IPPROTO_SCTP CMSG headers. Perform only minimal validation. |
5089 | * | 5089 | * |
5090 | * From RFC 2292 | 5090 | * From RFC 2292 |
5091 | * 4.2 The cmsghdr Structure * | 5091 | * 4.2 The cmsghdr Structure * |
5092 | * | 5092 | * |
5093 | * When ancillary data is sent or received, any number of ancillary data | 5093 | * When ancillary data is sent or received, any number of ancillary data |
5094 | * objects can be specified by the msg_control and msg_controllen members of | 5094 | * objects can be specified by the msg_control and msg_controllen members of |
5095 | * the msghdr structure, because each object is preceded by | 5095 | * the msghdr structure, because each object is preceded by |
5096 | * a cmsghdr structure defining the object's length (the cmsg_len member). | 5096 | * a cmsghdr structure defining the object's length (the cmsg_len member). |
5097 | * Historically Berkeley-derived implementations have passed only one object | 5097 | * Historically Berkeley-derived implementations have passed only one object |
5098 | * at a time, but this API allows multiple objects to be | 5098 | * at a time, but this API allows multiple objects to be |
5099 | * passed in a single call to sendmsg() or recvmsg(). The following example | 5099 | * passed in a single call to sendmsg() or recvmsg(). The following example |
5100 | * shows two ancillary data objects in a control buffer. | 5100 | * shows two ancillary data objects in a control buffer. |
5101 | * | 5101 | * |
5102 | * |<--------------------------- msg_controllen -------------------------->| | 5102 | * |<--------------------------- msg_controllen -------------------------->| |
5103 | * | | | 5103 | * | | |
5104 | * | 5104 | * |
5105 | * |<----- ancillary data object ----->|<----- ancillary data object ----->| | 5105 | * |<----- ancillary data object ----->|<----- ancillary data object ----->| |
5106 | * | 5106 | * |
5107 | * |<---------- CMSG_SPACE() --------->|<---------- CMSG_SPACE() --------->| | 5107 | * |<---------- CMSG_SPACE() --------->|<---------- CMSG_SPACE() --------->| |
5108 | * | | | | 5108 | * | | | |
5109 | * | 5109 | * |
5110 | * |<---------- cmsg_len ---------->| |<--------- cmsg_len ----------->| | | 5110 | * |<---------- cmsg_len ---------->| |<--------- cmsg_len ----------->| | |
5111 | * | 5111 | * |
5112 | * |<--------- CMSG_LEN() --------->| |<-------- CMSG_LEN() ---------->| | | 5112 | * |<--------- CMSG_LEN() --------->| |<-------- CMSG_LEN() ---------->| | |
5113 | * | | | | | | 5113 | * | | | | | |
5114 | * | 5114 | * |
5115 | * +-----+-----+-----+--+-----------+--+-----+-----+-----+--+-----------+--+ | 5115 | * +-----+-----+-----+--+-----------+--+-----+-----+-----+--+-----------+--+ |
5116 | * |cmsg_|cmsg_|cmsg_|XX| |XX|cmsg_|cmsg_|cmsg_|XX| |XX| | 5116 | * |cmsg_|cmsg_|cmsg_|XX| |XX|cmsg_|cmsg_|cmsg_|XX| |XX| |
5117 | * | 5117 | * |
5118 | * |len |level|type |XX|cmsg_data[]|XX|len |level|type |XX|cmsg_data[]|XX| | 5118 | * |len |level|type |XX|cmsg_data[]|XX|len |level|type |XX|cmsg_data[]|XX| |
5119 | * | 5119 | * |
5120 | * +-----+-----+-----+--+-----------+--+-----+-----+-----+--+-----------+--+ | 5120 | * +-----+-----+-----+--+-----------+--+-----+-----+-----+--+-----------+--+ |
5121 | * ^ | 5121 | * ^ |
5122 | * | | 5122 | * | |
5123 | * | 5123 | * |
5124 | * msg_control | 5124 | * msg_control |
5125 | * points here | 5125 | * points here |
5126 | */ | 5126 | */ |
5127 | SCTP_STATIC int sctp_msghdr_parse(const struct msghdr *msg, | 5127 | SCTP_STATIC int sctp_msghdr_parse(const struct msghdr *msg, |
5128 | sctp_cmsgs_t *cmsgs) | 5128 | sctp_cmsgs_t *cmsgs) |
5129 | { | 5129 | { |
5130 | struct cmsghdr *cmsg; | 5130 | struct cmsghdr *cmsg; |
5131 | 5131 | ||
5132 | for (cmsg = CMSG_FIRSTHDR(msg); | 5132 | for (cmsg = CMSG_FIRSTHDR(msg); |
5133 | cmsg != NULL; | 5133 | cmsg != NULL; |
5134 | cmsg = CMSG_NXTHDR((struct msghdr*)msg, cmsg)) { | 5134 | cmsg = CMSG_NXTHDR((struct msghdr*)msg, cmsg)) { |
5135 | if (!CMSG_OK(msg, cmsg)) | 5135 | if (!CMSG_OK(msg, cmsg)) |
5136 | return -EINVAL; | 5136 | return -EINVAL; |
5137 | 5137 | ||
5138 | /* Should we parse this header or ignore? */ | 5138 | /* Should we parse this header or ignore? */ |
5139 | if (cmsg->cmsg_level != IPPROTO_SCTP) | 5139 | if (cmsg->cmsg_level != IPPROTO_SCTP) |
5140 | continue; | 5140 | continue; |
5141 | 5141 | ||
5142 | /* Strictly check lengths following example in SCM code. */ | 5142 | /* Strictly check lengths following example in SCM code. */ |
5143 | switch (cmsg->cmsg_type) { | 5143 | switch (cmsg->cmsg_type) { |
5144 | case SCTP_INIT: | 5144 | case SCTP_INIT: |
5145 | /* SCTP Socket API Extension | 5145 | /* SCTP Socket API Extension |
5146 | * 5.2.1 SCTP Initiation Structure (SCTP_INIT) | 5146 | * 5.2.1 SCTP Initiation Structure (SCTP_INIT) |
5147 | * | 5147 | * |
5148 | * This cmsghdr structure provides information for | 5148 | * This cmsghdr structure provides information for |
5149 | * initializing new SCTP associations with sendmsg(). | 5149 | * initializing new SCTP associations with sendmsg(). |
5150 | * The SCTP_INITMSG socket option uses this same data | 5150 | * The SCTP_INITMSG socket option uses this same data |
5151 | * structure. This structure is not used for | 5151 | * structure. This structure is not used for |
5152 | * recvmsg(). | 5152 | * recvmsg(). |
5153 | * | 5153 | * |
5154 | * cmsg_level cmsg_type cmsg_data[] | 5154 | * cmsg_level cmsg_type cmsg_data[] |
5155 | * ------------ ------------ ---------------------- | 5155 | * ------------ ------------ ---------------------- |
5156 | * IPPROTO_SCTP SCTP_INIT struct sctp_initmsg | 5156 | * IPPROTO_SCTP SCTP_INIT struct sctp_initmsg |
5157 | */ | 5157 | */ |
5158 | if (cmsg->cmsg_len != | 5158 | if (cmsg->cmsg_len != |
5159 | CMSG_LEN(sizeof(struct sctp_initmsg))) | 5159 | CMSG_LEN(sizeof(struct sctp_initmsg))) |
5160 | return -EINVAL; | 5160 | return -EINVAL; |
5161 | cmsgs->init = (struct sctp_initmsg *)CMSG_DATA(cmsg); | 5161 | cmsgs->init = (struct sctp_initmsg *)CMSG_DATA(cmsg); |
5162 | break; | 5162 | break; |
5163 | 5163 | ||
5164 | case SCTP_SNDRCV: | 5164 | case SCTP_SNDRCV: |
5165 | /* SCTP Socket API Extension | 5165 | /* SCTP Socket API Extension |
5166 | * 5.2.2 SCTP Header Information Structure(SCTP_SNDRCV) | 5166 | * 5.2.2 SCTP Header Information Structure(SCTP_SNDRCV) |
5167 | * | 5167 | * |
5168 | * This cmsghdr structure specifies SCTP options for | 5168 | * This cmsghdr structure specifies SCTP options for |
5169 | * sendmsg() and describes SCTP header information | 5169 | * sendmsg() and describes SCTP header information |
5170 | * about a received message through recvmsg(). | 5170 | * about a received message through recvmsg(). |
5171 | * | 5171 | * |
5172 | * cmsg_level cmsg_type cmsg_data[] | 5172 | * cmsg_level cmsg_type cmsg_data[] |
5173 | * ------------ ------------ ---------------------- | 5173 | * ------------ ------------ ---------------------- |
5174 | * IPPROTO_SCTP SCTP_SNDRCV struct sctp_sndrcvinfo | 5174 | * IPPROTO_SCTP SCTP_SNDRCV struct sctp_sndrcvinfo |
5175 | */ | 5175 | */ |
5176 | if (cmsg->cmsg_len != | 5176 | if (cmsg->cmsg_len != |
5177 | CMSG_LEN(sizeof(struct sctp_sndrcvinfo))) | 5177 | CMSG_LEN(sizeof(struct sctp_sndrcvinfo))) |
5178 | return -EINVAL; | 5178 | return -EINVAL; |
5179 | 5179 | ||
5180 | cmsgs->info = | 5180 | cmsgs->info = |
5181 | (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); | 5181 | (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); |
5182 | 5182 | ||
5183 | /* Minimally, validate the sinfo_flags. */ | 5183 | /* Minimally, validate the sinfo_flags. */ |
5184 | if (cmsgs->info->sinfo_flags & | 5184 | if (cmsgs->info->sinfo_flags & |
5185 | ~(SCTP_UNORDERED | SCTP_ADDR_OVER | | 5185 | ~(SCTP_UNORDERED | SCTP_ADDR_OVER | |
5186 | SCTP_ABORT | SCTP_EOF)) | 5186 | SCTP_ABORT | SCTP_EOF)) |
5187 | return -EINVAL; | 5187 | return -EINVAL; |
5188 | break; | 5188 | break; |
5189 | 5189 | ||
5190 | default: | 5190 | default: |
5191 | return -EINVAL; | 5191 | return -EINVAL; |
5192 | }; | 5192 | }; |
5193 | } | 5193 | } |
5194 | return 0; | 5194 | return 0; |
5195 | } | 5195 | } |
5196 | 5196 | ||
5197 | /* | 5197 | /* |
5198 | * Wait for a packet.. | 5198 | * Wait for a packet.. |
5199 | * Note: This function is the same function as in core/datagram.c | 5199 | * Note: This function is the same function as in core/datagram.c |
5200 | * with a few modifications to make lksctp work. | 5200 | * with a few modifications to make lksctp work. |
5201 | */ | 5201 | */ |
5202 | static int sctp_wait_for_packet(struct sock * sk, int *err, long *timeo_p) | 5202 | static int sctp_wait_for_packet(struct sock * sk, int *err, long *timeo_p) |
5203 | { | 5203 | { |
5204 | int error; | 5204 | int error; |
5205 | DEFINE_WAIT(wait); | 5205 | DEFINE_WAIT(wait); |
5206 | 5206 | ||
5207 | prepare_to_wait_exclusive(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE); | 5207 | prepare_to_wait_exclusive(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE); |
5208 | 5208 | ||
5209 | /* Socket errors? */ | 5209 | /* Socket errors? */ |
5210 | error = sock_error(sk); | 5210 | error = sock_error(sk); |
5211 | if (error) | 5211 | if (error) |
5212 | goto out; | 5212 | goto out; |
5213 | 5213 | ||
5214 | if (!skb_queue_empty(&sk->sk_receive_queue)) | 5214 | if (!skb_queue_empty(&sk->sk_receive_queue)) |
5215 | goto ready; | 5215 | goto ready; |
5216 | 5216 | ||
5217 | /* Socket shut down? */ | 5217 | /* Socket shut down? */ |
5218 | if (sk->sk_shutdown & RCV_SHUTDOWN) | 5218 | if (sk->sk_shutdown & RCV_SHUTDOWN) |
5219 | goto out; | 5219 | goto out; |
5220 | 5220 | ||
5221 | /* Sequenced packets can come disconnected. If so we report the | 5221 | /* Sequenced packets can come disconnected. If so we report the |
5222 | * problem. | 5222 | * problem. |
5223 | */ | 5223 | */ |
5224 | error = -ENOTCONN; | 5224 | error = -ENOTCONN; |
5225 | 5225 | ||
5226 | /* Is there a good reason to think that we may receive some data? */ | 5226 | /* Is there a good reason to think that we may receive some data? */ |
5227 | if (list_empty(&sctp_sk(sk)->ep->asocs) && !sctp_sstate(sk, LISTENING)) | 5227 | if (list_empty(&sctp_sk(sk)->ep->asocs) && !sctp_sstate(sk, LISTENING)) |
5228 | goto out; | 5228 | goto out; |
5229 | 5229 | ||
5230 | /* Handle signals. */ | 5230 | /* Handle signals. */ |
5231 | if (signal_pending(current)) | 5231 | if (signal_pending(current)) |
5232 | goto interrupted; | 5232 | goto interrupted; |
5233 | 5233 | ||
5234 | /* Let another process have a go. Since we are going to sleep | 5234 | /* Let another process have a go. Since we are going to sleep |
5235 | * anyway. Note: This may cause odd behaviors if the message | 5235 | * anyway. Note: This may cause odd behaviors if the message |
5236 | * does not fit in the user's buffer, but this seems to be the | 5236 | * does not fit in the user's buffer, but this seems to be the |
5237 | * only way to honor MSG_DONTWAIT realistically. | 5237 | * only way to honor MSG_DONTWAIT realistically. |
5238 | */ | 5238 | */ |
5239 | sctp_release_sock(sk); | 5239 | sctp_release_sock(sk); |
5240 | *timeo_p = schedule_timeout(*timeo_p); | 5240 | *timeo_p = schedule_timeout(*timeo_p); |
5241 | sctp_lock_sock(sk); | 5241 | sctp_lock_sock(sk); |
5242 | 5242 | ||
5243 | ready: | 5243 | ready: |
5244 | finish_wait(sk->sk_sleep, &wait); | 5244 | finish_wait(sk->sk_sleep, &wait); |
5245 | return 0; | 5245 | return 0; |
5246 | 5246 | ||
5247 | interrupted: | 5247 | interrupted: |
5248 | error = sock_intr_errno(*timeo_p); | 5248 | error = sock_intr_errno(*timeo_p); |
5249 | 5249 | ||
5250 | out: | 5250 | out: |
5251 | finish_wait(sk->sk_sleep, &wait); | 5251 | finish_wait(sk->sk_sleep, &wait); |
5252 | *err = error; | 5252 | *err = error; |
5253 | return error; | 5253 | return error; |
5254 | } | 5254 | } |
5255 | 5255 | ||
5256 | /* Receive a datagram. | 5256 | /* Receive a datagram. |
5257 | * Note: This is pretty much the same routine as in core/datagram.c | 5257 | * Note: This is pretty much the same routine as in core/datagram.c |
5258 | * with a few changes to make lksctp work. | 5258 | * with a few changes to make lksctp work. |
5259 | */ | 5259 | */ |
5260 | static struct sk_buff *sctp_skb_recv_datagram(struct sock *sk, int flags, | 5260 | static struct sk_buff *sctp_skb_recv_datagram(struct sock *sk, int flags, |
5261 | int noblock, int *err) | 5261 | int noblock, int *err) |
5262 | { | 5262 | { |
5263 | int error; | 5263 | int error; |
5264 | struct sk_buff *skb; | 5264 | struct sk_buff *skb; |
5265 | long timeo; | 5265 | long timeo; |
5266 | 5266 | ||
5267 | timeo = sock_rcvtimeo(sk, noblock); | 5267 | timeo = sock_rcvtimeo(sk, noblock); |
5268 | 5268 | ||
5269 | SCTP_DEBUG_PRINTK("Timeout: timeo: %ld, MAX: %ld.\n", | 5269 | SCTP_DEBUG_PRINTK("Timeout: timeo: %ld, MAX: %ld.\n", |
5270 | timeo, MAX_SCHEDULE_TIMEOUT); | 5270 | timeo, MAX_SCHEDULE_TIMEOUT); |
5271 | 5271 | ||
5272 | do { | 5272 | do { |
5273 | /* Again only user level code calls this function, | 5273 | /* Again only user level code calls this function, |
5274 | * so nothing interrupt level | 5274 | * so nothing interrupt level |
5275 | * will suddenly eat the receive_queue. | 5275 | * will suddenly eat the receive_queue. |
5276 | * | 5276 | * |
5277 | * Look at current nfs client by the way... | 5277 | * Look at current nfs client by the way... |
5278 | * However, this function was corrent in any case. 8) | 5278 | * However, this function was corrent in any case. 8) |
5279 | */ | 5279 | */ |
5280 | if (flags & MSG_PEEK) { | 5280 | if (flags & MSG_PEEK) { |
5281 | spin_lock_bh(&sk->sk_receive_queue.lock); | 5281 | spin_lock_bh(&sk->sk_receive_queue.lock); |
5282 | skb = skb_peek(&sk->sk_receive_queue); | 5282 | skb = skb_peek(&sk->sk_receive_queue); |
5283 | if (skb) | 5283 | if (skb) |
5284 | atomic_inc(&skb->users); | 5284 | atomic_inc(&skb->users); |
5285 | spin_unlock_bh(&sk->sk_receive_queue.lock); | 5285 | spin_unlock_bh(&sk->sk_receive_queue.lock); |
5286 | } else { | 5286 | } else { |
5287 | skb = skb_dequeue(&sk->sk_receive_queue); | 5287 | skb = skb_dequeue(&sk->sk_receive_queue); |
5288 | } | 5288 | } |
5289 | 5289 | ||
5290 | if (skb) | 5290 | if (skb) |
5291 | return skb; | 5291 | return skb; |
5292 | 5292 | ||
5293 | /* Caller is allowed not to check sk->sk_err before calling. */ | 5293 | /* Caller is allowed not to check sk->sk_err before calling. */ |
5294 | error = sock_error(sk); | 5294 | error = sock_error(sk); |
5295 | if (error) | 5295 | if (error) |
5296 | goto no_packet; | 5296 | goto no_packet; |
5297 | 5297 | ||
5298 | if (sk->sk_shutdown & RCV_SHUTDOWN) | 5298 | if (sk->sk_shutdown & RCV_SHUTDOWN) |
5299 | break; | 5299 | break; |
5300 | 5300 | ||
5301 | /* User doesn't want to wait. */ | 5301 | /* User doesn't want to wait. */ |
5302 | error = -EAGAIN; | 5302 | error = -EAGAIN; |
5303 | if (!timeo) | 5303 | if (!timeo) |
5304 | goto no_packet; | 5304 | goto no_packet; |
5305 | } while (sctp_wait_for_packet(sk, err, &timeo) == 0); | 5305 | } while (sctp_wait_for_packet(sk, err, &timeo) == 0); |
5306 | 5306 | ||
5307 | return NULL; | 5307 | return NULL; |
5308 | 5308 | ||
5309 | no_packet: | 5309 | no_packet: |
5310 | *err = error; | 5310 | *err = error; |
5311 | return NULL; | 5311 | return NULL; |
5312 | } | 5312 | } |
5313 | 5313 | ||
5314 | /* If sndbuf has changed, wake up per association sndbuf waiters. */ | 5314 | /* If sndbuf has changed, wake up per association sndbuf waiters. */ |
5315 | static void __sctp_write_space(struct sctp_association *asoc) | 5315 | static void __sctp_write_space(struct sctp_association *asoc) |
5316 | { | 5316 | { |
5317 | struct sock *sk = asoc->base.sk; | 5317 | struct sock *sk = asoc->base.sk; |
5318 | struct socket *sock = sk->sk_socket; | 5318 | struct socket *sock = sk->sk_socket; |
5319 | 5319 | ||
5320 | if ((sctp_wspace(asoc) > 0) && sock) { | 5320 | if ((sctp_wspace(asoc) > 0) && sock) { |
5321 | if (waitqueue_active(&asoc->wait)) | 5321 | if (waitqueue_active(&asoc->wait)) |
5322 | wake_up_interruptible(&asoc->wait); | 5322 | wake_up_interruptible(&asoc->wait); |
5323 | 5323 | ||
5324 | if (sctp_writeable(sk)) { | 5324 | if (sctp_writeable(sk)) { |
5325 | if (sk->sk_sleep && waitqueue_active(sk->sk_sleep)) | 5325 | if (sk->sk_sleep && waitqueue_active(sk->sk_sleep)) |
5326 | wake_up_interruptible(sk->sk_sleep); | 5326 | wake_up_interruptible(sk->sk_sleep); |
5327 | 5327 | ||
5328 | /* Note that we try to include the Async I/O support | 5328 | /* Note that we try to include the Async I/O support |
5329 | * here by modeling from the current TCP/UDP code. | 5329 | * here by modeling from the current TCP/UDP code. |
5330 | * We have not tested with it yet. | 5330 | * We have not tested with it yet. |
5331 | */ | 5331 | */ |
5332 | if (sock->fasync_list && | 5332 | if (sock->fasync_list && |
5333 | !(sk->sk_shutdown & SEND_SHUTDOWN)) | 5333 | !(sk->sk_shutdown & SEND_SHUTDOWN)) |
5334 | sock_wake_async(sock, 2, POLL_OUT); | 5334 | sock_wake_async(sock, 2, POLL_OUT); |
5335 | } | 5335 | } |
5336 | } | 5336 | } |
5337 | } | 5337 | } |
5338 | 5338 | ||
5339 | /* Do accounting for the sndbuf space. | 5339 | /* Do accounting for the sndbuf space. |
5340 | * Decrement the used sndbuf space of the corresponding association by the | 5340 | * Decrement the used sndbuf space of the corresponding association by the |
5341 | * data size which was just transmitted(freed). | 5341 | * data size which was just transmitted(freed). |
5342 | */ | 5342 | */ |
5343 | static void sctp_wfree(struct sk_buff *skb) | 5343 | static void sctp_wfree(struct sk_buff *skb) |
5344 | { | 5344 | { |
5345 | struct sctp_association *asoc; | 5345 | struct sctp_association *asoc; |
5346 | struct sctp_chunk *chunk; | 5346 | struct sctp_chunk *chunk; |
5347 | struct sock *sk; | 5347 | struct sock *sk; |
5348 | 5348 | ||
5349 | /* Get the saved chunk pointer. */ | 5349 | /* Get the saved chunk pointer. */ |
5350 | chunk = *((struct sctp_chunk **)(skb->cb)); | 5350 | chunk = *((struct sctp_chunk **)(skb->cb)); |
5351 | asoc = chunk->asoc; | 5351 | asoc = chunk->asoc; |
5352 | sk = asoc->base.sk; | 5352 | sk = asoc->base.sk; |
5353 | asoc->sndbuf_used -= SCTP_DATA_SNDSIZE(chunk) + | 5353 | asoc->sndbuf_used -= SCTP_DATA_SNDSIZE(chunk) + |
5354 | sizeof(struct sk_buff) + | 5354 | sizeof(struct sk_buff) + |
5355 | sizeof(struct sctp_chunk); | 5355 | sizeof(struct sctp_chunk); |
5356 | 5356 | ||
5357 | atomic_sub(sizeof(struct sctp_chunk), &sk->sk_wmem_alloc); | 5357 | atomic_sub(sizeof(struct sctp_chunk), &sk->sk_wmem_alloc); |
5358 | 5358 | ||
5359 | sock_wfree(skb); | 5359 | sock_wfree(skb); |
5360 | __sctp_write_space(asoc); | 5360 | __sctp_write_space(asoc); |
5361 | 5361 | ||
5362 | sctp_association_put(asoc); | 5362 | sctp_association_put(asoc); |
5363 | } | 5363 | } |
5364 | 5364 | ||
5365 | /* Helper function to wait for space in the sndbuf. */ | 5365 | /* Helper function to wait for space in the sndbuf. */ |
5366 | static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p, | 5366 | static int sctp_wait_for_sndbuf(struct sctp_association *asoc, long *timeo_p, |
5367 | size_t msg_len) | 5367 | size_t msg_len) |
5368 | { | 5368 | { |
5369 | struct sock *sk = asoc->base.sk; | 5369 | struct sock *sk = asoc->base.sk; |
5370 | int err = 0; | 5370 | int err = 0; |
5371 | long current_timeo = *timeo_p; | 5371 | long current_timeo = *timeo_p; |
5372 | DEFINE_WAIT(wait); | 5372 | DEFINE_WAIT(wait); |
5373 | 5373 | ||
5374 | SCTP_DEBUG_PRINTK("wait_for_sndbuf: asoc=%p, timeo=%ld, msg_len=%zu\n", | 5374 | SCTP_DEBUG_PRINTK("wait_for_sndbuf: asoc=%p, timeo=%ld, msg_len=%zu\n", |
5375 | asoc, (long)(*timeo_p), msg_len); | 5375 | asoc, (long)(*timeo_p), msg_len); |
5376 | 5376 | ||
5377 | /* Increment the association's refcnt. */ | 5377 | /* Increment the association's refcnt. */ |
5378 | sctp_association_hold(asoc); | 5378 | sctp_association_hold(asoc); |
5379 | 5379 | ||
5380 | /* Wait on the association specific sndbuf space. */ | 5380 | /* Wait on the association specific sndbuf space. */ |
5381 | for (;;) { | 5381 | for (;;) { |
5382 | prepare_to_wait_exclusive(&asoc->wait, &wait, | 5382 | prepare_to_wait_exclusive(&asoc->wait, &wait, |
5383 | TASK_INTERRUPTIBLE); | 5383 | TASK_INTERRUPTIBLE); |
5384 | if (!*timeo_p) | 5384 | if (!*timeo_p) |
5385 | goto do_nonblock; | 5385 | goto do_nonblock; |
5386 | if (sk->sk_err || asoc->state >= SCTP_STATE_SHUTDOWN_PENDING || | 5386 | if (sk->sk_err || asoc->state >= SCTP_STATE_SHUTDOWN_PENDING || |
5387 | asoc->base.dead) | 5387 | asoc->base.dead) |
5388 | goto do_error; | 5388 | goto do_error; |
5389 | if (signal_pending(current)) | 5389 | if (signal_pending(current)) |
5390 | goto do_interrupted; | 5390 | goto do_interrupted; |
5391 | if (msg_len <= sctp_wspace(asoc)) | 5391 | if (msg_len <= sctp_wspace(asoc)) |
5392 | break; | 5392 | break; |
5393 | 5393 | ||
5394 | /* Let another process have a go. Since we are going | 5394 | /* Let another process have a go. Since we are going |
5395 | * to sleep anyway. | 5395 | * to sleep anyway. |
5396 | */ | 5396 | */ |
5397 | sctp_release_sock(sk); | 5397 | sctp_release_sock(sk); |
5398 | current_timeo = schedule_timeout(current_timeo); | 5398 | current_timeo = schedule_timeout(current_timeo); |
5399 | BUG_ON(sk != asoc->base.sk); | 5399 | BUG_ON(sk != asoc->base.sk); |
5400 | sctp_lock_sock(sk); | 5400 | sctp_lock_sock(sk); |
5401 | 5401 | ||
5402 | *timeo_p = current_timeo; | 5402 | *timeo_p = current_timeo; |
5403 | } | 5403 | } |
5404 | 5404 | ||
5405 | out: | 5405 | out: |
5406 | finish_wait(&asoc->wait, &wait); | 5406 | finish_wait(&asoc->wait, &wait); |
5407 | 5407 | ||
5408 | /* Release the association's refcnt. */ | 5408 | /* Release the association's refcnt. */ |
5409 | sctp_association_put(asoc); | 5409 | sctp_association_put(asoc); |
5410 | 5410 | ||
5411 | return err; | 5411 | return err; |
5412 | 5412 | ||
5413 | do_error: | 5413 | do_error: |
5414 | err = -EPIPE; | 5414 | err = -EPIPE; |
5415 | goto out; | 5415 | goto out; |
5416 | 5416 | ||
5417 | do_interrupted: | 5417 | do_interrupted: |
5418 | err = sock_intr_errno(*timeo_p); | 5418 | err = sock_intr_errno(*timeo_p); |
5419 | goto out; | 5419 | goto out; |
5420 | 5420 | ||
5421 | do_nonblock: | 5421 | do_nonblock: |
5422 | err = -EAGAIN; | 5422 | err = -EAGAIN; |
5423 | goto out; | 5423 | goto out; |
5424 | } | 5424 | } |
5425 | 5425 | ||
5426 | /* If socket sndbuf has changed, wake up all per association waiters. */ | 5426 | /* If socket sndbuf has changed, wake up all per association waiters. */ |
5427 | void sctp_write_space(struct sock *sk) | 5427 | void sctp_write_space(struct sock *sk) |
5428 | { | 5428 | { |
5429 | struct sctp_association *asoc; | 5429 | struct sctp_association *asoc; |
5430 | struct list_head *pos; | 5430 | struct list_head *pos; |
5431 | 5431 | ||
5432 | /* Wake up the tasks in each wait queue. */ | 5432 | /* Wake up the tasks in each wait queue. */ |
5433 | list_for_each(pos, &((sctp_sk(sk))->ep->asocs)) { | 5433 | list_for_each(pos, &((sctp_sk(sk))->ep->asocs)) { |
5434 | asoc = list_entry(pos, struct sctp_association, asocs); | 5434 | asoc = list_entry(pos, struct sctp_association, asocs); |
5435 | __sctp_write_space(asoc); | 5435 | __sctp_write_space(asoc); |
5436 | } | 5436 | } |
5437 | } | 5437 | } |
5438 | 5438 | ||
5439 | /* Is there any sndbuf space available on the socket? | 5439 | /* Is there any sndbuf space available on the socket? |
5440 | * | 5440 | * |
5441 | * Note that sk_wmem_alloc is the sum of the send buffers on all of the | 5441 | * Note that sk_wmem_alloc is the sum of the send buffers on all of the |
5442 | * associations on the same socket. For a UDP-style socket with | 5442 | * associations on the same socket. For a UDP-style socket with |
5443 | * multiple associations, it is possible for it to be "unwriteable" | 5443 | * multiple associations, it is possible for it to be "unwriteable" |
5444 | * prematurely. I assume that this is acceptable because | 5444 | * prematurely. I assume that this is acceptable because |
5445 | * a premature "unwriteable" is better than an accidental "writeable" which | 5445 | * a premature "unwriteable" is better than an accidental "writeable" which |
5446 | * would cause an unwanted block under certain circumstances. For the 1-1 | 5446 | * would cause an unwanted block under certain circumstances. For the 1-1 |
5447 | * UDP-style sockets or TCP-style sockets, this code should work. | 5447 | * UDP-style sockets or TCP-style sockets, this code should work. |
5448 | * - Daisy | 5448 | * - Daisy |
5449 | */ | 5449 | */ |
5450 | static int sctp_writeable(struct sock *sk) | 5450 | static int sctp_writeable(struct sock *sk) |
5451 | { | 5451 | { |
5452 | int amt = 0; | 5452 | int amt = 0; |
5453 | 5453 | ||
5454 | amt = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc); | 5454 | amt = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc); |
5455 | if (amt < 0) | 5455 | if (amt < 0) |
5456 | amt = 0; | 5456 | amt = 0; |
5457 | return amt; | 5457 | return amt; |
5458 | } | 5458 | } |
5459 | 5459 | ||
5460 | /* Wait for an association to go into ESTABLISHED state. If timeout is 0, | 5460 | /* Wait for an association to go into ESTABLISHED state. If timeout is 0, |
5461 | * returns immediately with EINPROGRESS. | 5461 | * returns immediately with EINPROGRESS. |
5462 | */ | 5462 | */ |
5463 | static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p) | 5463 | static int sctp_wait_for_connect(struct sctp_association *asoc, long *timeo_p) |
5464 | { | 5464 | { |
5465 | struct sock *sk = asoc->base.sk; | 5465 | struct sock *sk = asoc->base.sk; |
5466 | int err = 0; | 5466 | int err = 0; |
5467 | long current_timeo = *timeo_p; | 5467 | long current_timeo = *timeo_p; |
5468 | DEFINE_WAIT(wait); | 5468 | DEFINE_WAIT(wait); |
5469 | 5469 | ||
5470 | SCTP_DEBUG_PRINTK("%s: asoc=%p, timeo=%ld\n", __FUNCTION__, asoc, | 5470 | SCTP_DEBUG_PRINTK("%s: asoc=%p, timeo=%ld\n", __FUNCTION__, asoc, |
5471 | (long)(*timeo_p)); | 5471 | (long)(*timeo_p)); |
5472 | 5472 | ||
5473 | /* Increment the association's refcnt. */ | 5473 | /* Increment the association's refcnt. */ |
5474 | sctp_association_hold(asoc); | 5474 | sctp_association_hold(asoc); |
5475 | 5475 | ||
5476 | for (;;) { | 5476 | for (;;) { |
5477 | prepare_to_wait_exclusive(&asoc->wait, &wait, | 5477 | prepare_to_wait_exclusive(&asoc->wait, &wait, |
5478 | TASK_INTERRUPTIBLE); | 5478 | TASK_INTERRUPTIBLE); |
5479 | if (!*timeo_p) | 5479 | if (!*timeo_p) |
5480 | goto do_nonblock; | 5480 | goto do_nonblock; |
5481 | if (sk->sk_shutdown & RCV_SHUTDOWN) | 5481 | if (sk->sk_shutdown & RCV_SHUTDOWN) |
5482 | break; | 5482 | break; |
5483 | if (sk->sk_err || asoc->state >= SCTP_STATE_SHUTDOWN_PENDING || | 5483 | if (sk->sk_err || asoc->state >= SCTP_STATE_SHUTDOWN_PENDING || |
5484 | asoc->base.dead) | 5484 | asoc->base.dead) |
5485 | goto do_error; | 5485 | goto do_error; |
5486 | if (signal_pending(current)) | 5486 | if (signal_pending(current)) |
5487 | goto do_interrupted; | 5487 | goto do_interrupted; |
5488 | 5488 | ||
5489 | if (sctp_state(asoc, ESTABLISHED)) | 5489 | if (sctp_state(asoc, ESTABLISHED)) |
5490 | break; | 5490 | break; |
5491 | 5491 | ||
5492 | /* Let another process have a go. Since we are going | 5492 | /* Let another process have a go. Since we are going |
5493 | * to sleep anyway. | 5493 | * to sleep anyway. |
5494 | */ | 5494 | */ |
5495 | sctp_release_sock(sk); | 5495 | sctp_release_sock(sk); |
5496 | current_timeo = schedule_timeout(current_timeo); | 5496 | current_timeo = schedule_timeout(current_timeo); |
5497 | sctp_lock_sock(sk); | 5497 | sctp_lock_sock(sk); |
5498 | 5498 | ||
5499 | *timeo_p = current_timeo; | 5499 | *timeo_p = current_timeo; |
5500 | } | 5500 | } |
5501 | 5501 | ||
5502 | out: | 5502 | out: |
5503 | finish_wait(&asoc->wait, &wait); | 5503 | finish_wait(&asoc->wait, &wait); |
5504 | 5504 | ||
5505 | /* Release the association's refcnt. */ | 5505 | /* Release the association's refcnt. */ |
5506 | sctp_association_put(asoc); | 5506 | sctp_association_put(asoc); |
5507 | 5507 | ||
5508 | return err; | 5508 | return err; |
5509 | 5509 | ||
5510 | do_error: | 5510 | do_error: |
5511 | if (asoc->init_err_counter + 1 > asoc->max_init_attempts) | 5511 | if (asoc->init_err_counter + 1 > asoc->max_init_attempts) |
5512 | err = -ETIMEDOUT; | 5512 | err = -ETIMEDOUT; |
5513 | else | 5513 | else |
5514 | err = -ECONNREFUSED; | 5514 | err = -ECONNREFUSED; |
5515 | goto out; | 5515 | goto out; |
5516 | 5516 | ||
5517 | do_interrupted: | 5517 | do_interrupted: |
5518 | err = sock_intr_errno(*timeo_p); | 5518 | err = sock_intr_errno(*timeo_p); |
5519 | goto out; | 5519 | goto out; |
5520 | 5520 | ||
5521 | do_nonblock: | 5521 | do_nonblock: |
5522 | err = -EINPROGRESS; | 5522 | err = -EINPROGRESS; |
5523 | goto out; | 5523 | goto out; |
5524 | } | 5524 | } |
5525 | 5525 | ||
5526 | static int sctp_wait_for_accept(struct sock *sk, long timeo) | 5526 | static int sctp_wait_for_accept(struct sock *sk, long timeo) |
5527 | { | 5527 | { |
5528 | struct sctp_endpoint *ep; | 5528 | struct sctp_endpoint *ep; |
5529 | int err = 0; | 5529 | int err = 0; |
5530 | DEFINE_WAIT(wait); | 5530 | DEFINE_WAIT(wait); |
5531 | 5531 | ||
5532 | ep = sctp_sk(sk)->ep; | 5532 | ep = sctp_sk(sk)->ep; |
5533 | 5533 | ||
5534 | 5534 | ||
5535 | for (;;) { | 5535 | for (;;) { |
5536 | prepare_to_wait_exclusive(sk->sk_sleep, &wait, | 5536 | prepare_to_wait_exclusive(sk->sk_sleep, &wait, |
5537 | TASK_INTERRUPTIBLE); | 5537 | TASK_INTERRUPTIBLE); |
5538 | 5538 | ||
5539 | if (list_empty(&ep->asocs)) { | 5539 | if (list_empty(&ep->asocs)) { |
5540 | sctp_release_sock(sk); | 5540 | sctp_release_sock(sk); |
5541 | timeo = schedule_timeout(timeo); | 5541 | timeo = schedule_timeout(timeo); |
5542 | sctp_lock_sock(sk); | 5542 | sctp_lock_sock(sk); |
5543 | } | 5543 | } |
5544 | 5544 | ||
5545 | err = -EINVAL; | 5545 | err = -EINVAL; |
5546 | if (!sctp_sstate(sk, LISTENING)) | 5546 | if (!sctp_sstate(sk, LISTENING)) |
5547 | break; | 5547 | break; |
5548 | 5548 | ||
5549 | err = 0; | 5549 | err = 0; |
5550 | if (!list_empty(&ep->asocs)) | 5550 | if (!list_empty(&ep->asocs)) |
5551 | break; | 5551 | break; |
5552 | 5552 | ||
5553 | err = sock_intr_errno(timeo); | 5553 | err = sock_intr_errno(timeo); |
5554 | if (signal_pending(current)) | 5554 | if (signal_pending(current)) |
5555 | break; | 5555 | break; |
5556 | 5556 | ||
5557 | err = -EAGAIN; | 5557 | err = -EAGAIN; |
5558 | if (!timeo) | 5558 | if (!timeo) |
5559 | break; | 5559 | break; |
5560 | } | 5560 | } |
5561 | 5561 | ||
5562 | finish_wait(sk->sk_sleep, &wait); | 5562 | finish_wait(sk->sk_sleep, &wait); |
5563 | 5563 | ||
5564 | return err; | 5564 | return err; |
5565 | } | 5565 | } |
5566 | 5566 | ||
5567 | void sctp_wait_for_close(struct sock *sk, long timeout) | 5567 | void sctp_wait_for_close(struct sock *sk, long timeout) |
5568 | { | 5568 | { |
5569 | DEFINE_WAIT(wait); | 5569 | DEFINE_WAIT(wait); |
5570 | 5570 | ||
5571 | do { | 5571 | do { |
5572 | prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE); | 5572 | prepare_to_wait(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE); |
5573 | if (list_empty(&sctp_sk(sk)->ep->asocs)) | 5573 | if (list_empty(&sctp_sk(sk)->ep->asocs)) |
5574 | break; | 5574 | break; |
5575 | sctp_release_sock(sk); | 5575 | sctp_release_sock(sk); |
5576 | timeout = schedule_timeout(timeout); | 5576 | timeout = schedule_timeout(timeout); |
5577 | sctp_lock_sock(sk); | 5577 | sctp_lock_sock(sk); |
5578 | } while (!signal_pending(current) && timeout); | 5578 | } while (!signal_pending(current) && timeout); |
5579 | 5579 | ||
5580 | finish_wait(sk->sk_sleep, &wait); | 5580 | finish_wait(sk->sk_sleep, &wait); |
5581 | } | 5581 | } |
5582 | 5582 | ||
5583 | /* Populate the fields of the newsk from the oldsk and migrate the assoc | 5583 | /* Populate the fields of the newsk from the oldsk and migrate the assoc |
5584 | * and its messages to the newsk. | 5584 | * and its messages to the newsk. |
5585 | */ | 5585 | */ |
5586 | static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk, | 5586 | static void sctp_sock_migrate(struct sock *oldsk, struct sock *newsk, |
5587 | struct sctp_association *assoc, | 5587 | struct sctp_association *assoc, |
5588 | sctp_socket_type_t type) | 5588 | sctp_socket_type_t type) |
5589 | { | 5589 | { |
5590 | struct sctp_sock *oldsp = sctp_sk(oldsk); | 5590 | struct sctp_sock *oldsp = sctp_sk(oldsk); |
5591 | struct sctp_sock *newsp = sctp_sk(newsk); | 5591 | struct sctp_sock *newsp = sctp_sk(newsk); |
5592 | struct sctp_bind_bucket *pp; /* hash list port iterator */ | 5592 | struct sctp_bind_bucket *pp; /* hash list port iterator */ |
5593 | struct sctp_endpoint *newep = newsp->ep; | 5593 | struct sctp_endpoint *newep = newsp->ep; |
5594 | struct sk_buff *skb, *tmp; | 5594 | struct sk_buff *skb, *tmp; |
5595 | struct sctp_ulpevent *event; | 5595 | struct sctp_ulpevent *event; |
5596 | int flags = 0; | 5596 | int flags = 0; |
5597 | 5597 | ||
5598 | /* Migrate socket buffer sizes and all the socket level options to the | 5598 | /* Migrate socket buffer sizes and all the socket level options to the |
5599 | * new socket. | 5599 | * new socket. |
5600 | */ | 5600 | */ |
5601 | newsk->sk_sndbuf = oldsk->sk_sndbuf; | 5601 | newsk->sk_sndbuf = oldsk->sk_sndbuf; |
5602 | newsk->sk_rcvbuf = oldsk->sk_rcvbuf; | 5602 | newsk->sk_rcvbuf = oldsk->sk_rcvbuf; |
5603 | /* Brute force copy old sctp opt. */ | 5603 | /* Brute force copy old sctp opt. */ |
5604 | inet_sk_copy_descendant(newsk, oldsk); | 5604 | inet_sk_copy_descendant(newsk, oldsk); |
5605 | 5605 | ||
5606 | /* Restore the ep value that was overwritten with the above structure | 5606 | /* Restore the ep value that was overwritten with the above structure |
5607 | * copy. | 5607 | * copy. |
5608 | */ | 5608 | */ |
5609 | newsp->ep = newep; | 5609 | newsp->ep = newep; |
5610 | newsp->hmac = NULL; | 5610 | newsp->hmac = NULL; |
5611 | 5611 | ||
5612 | /* Hook this new socket in to the bind_hash list. */ | 5612 | /* Hook this new socket in to the bind_hash list. */ |
5613 | pp = sctp_sk(oldsk)->bind_hash; | 5613 | pp = sctp_sk(oldsk)->bind_hash; |
5614 | sk_add_bind_node(newsk, &pp->owner); | 5614 | sk_add_bind_node(newsk, &pp->owner); |
5615 | sctp_sk(newsk)->bind_hash = pp; | 5615 | sctp_sk(newsk)->bind_hash = pp; |
5616 | inet_sk(newsk)->num = inet_sk(oldsk)->num; | 5616 | inet_sk(newsk)->num = inet_sk(oldsk)->num; |
5617 | 5617 | ||
5618 | /* Copy the bind_addr list from the original endpoint to the new | 5618 | /* Copy the bind_addr list from the original endpoint to the new |
5619 | * endpoint so that we can handle restarts properly | 5619 | * endpoint so that we can handle restarts properly |
5620 | */ | 5620 | */ |
5621 | if (PF_INET6 == assoc->base.sk->sk_family) | 5621 | if (PF_INET6 == assoc->base.sk->sk_family) |
5622 | flags = SCTP_ADDR6_ALLOWED; | 5622 | flags = SCTP_ADDR6_ALLOWED; |
5623 | if (assoc->peer.ipv4_address) | 5623 | if (assoc->peer.ipv4_address) |
5624 | flags |= SCTP_ADDR4_PEERSUPP; | 5624 | flags |= SCTP_ADDR4_PEERSUPP; |
5625 | if (assoc->peer.ipv6_address) | 5625 | if (assoc->peer.ipv6_address) |
5626 | flags |= SCTP_ADDR6_PEERSUPP; | 5626 | flags |= SCTP_ADDR6_PEERSUPP; |
5627 | sctp_bind_addr_copy(&newsp->ep->base.bind_addr, | 5627 | sctp_bind_addr_copy(&newsp->ep->base.bind_addr, |
5628 | &oldsp->ep->base.bind_addr, | 5628 | &oldsp->ep->base.bind_addr, |
5629 | SCTP_SCOPE_GLOBAL, GFP_KERNEL, flags); | 5629 | SCTP_SCOPE_GLOBAL, GFP_KERNEL, flags); |
5630 | 5630 | ||
5631 | /* Move any messages in the old socket's receive queue that are for the | 5631 | /* Move any messages in the old socket's receive queue that are for the |
5632 | * peeled off association to the new socket's receive queue. | 5632 | * peeled off association to the new socket's receive queue. |
5633 | */ | 5633 | */ |
5634 | sctp_skb_for_each(skb, &oldsk->sk_receive_queue, tmp) { | 5634 | sctp_skb_for_each(skb, &oldsk->sk_receive_queue, tmp) { |
5635 | event = sctp_skb2event(skb); | 5635 | event = sctp_skb2event(skb); |
5636 | if (event->asoc == assoc) { | 5636 | if (event->asoc == assoc) { |
5637 | sock_rfree(skb); | 5637 | sock_rfree(skb); |
5638 | __skb_unlink(skb, &oldsk->sk_receive_queue); | 5638 | __skb_unlink(skb, &oldsk->sk_receive_queue); |
5639 | __skb_queue_tail(&newsk->sk_receive_queue, skb); | 5639 | __skb_queue_tail(&newsk->sk_receive_queue, skb); |
5640 | skb_set_owner_r(skb, newsk); | 5640 | skb_set_owner_r(skb, newsk); |
5641 | } | 5641 | } |
5642 | } | 5642 | } |
5643 | 5643 | ||
5644 | /* Clean up any messages pending delivery due to partial | 5644 | /* Clean up any messages pending delivery due to partial |
5645 | * delivery. Three cases: | 5645 | * delivery. Three cases: |
5646 | * 1) No partial deliver; no work. | 5646 | * 1) No partial deliver; no work. |
5647 | * 2) Peeling off partial delivery; keep pd_lobby in new pd_lobby. | 5647 | * 2) Peeling off partial delivery; keep pd_lobby in new pd_lobby. |
5648 | * 3) Peeling off non-partial delivery; move pd_lobby to receive_queue. | 5648 | * 3) Peeling off non-partial delivery; move pd_lobby to receive_queue. |
5649 | */ | 5649 | */ |
5650 | skb_queue_head_init(&newsp->pd_lobby); | 5650 | skb_queue_head_init(&newsp->pd_lobby); |
5651 | sctp_sk(newsk)->pd_mode = assoc->ulpq.pd_mode; | 5651 | sctp_sk(newsk)->pd_mode = assoc->ulpq.pd_mode; |
5652 | 5652 | ||
5653 | if (sctp_sk(oldsk)->pd_mode) { | 5653 | if (sctp_sk(oldsk)->pd_mode) { |
5654 | struct sk_buff_head *queue; | 5654 | struct sk_buff_head *queue; |
5655 | 5655 | ||
5656 | /* Decide which queue to move pd_lobby skbs to. */ | 5656 | /* Decide which queue to move pd_lobby skbs to. */ |
5657 | if (assoc->ulpq.pd_mode) { | 5657 | if (assoc->ulpq.pd_mode) { |
5658 | queue = &newsp->pd_lobby; | 5658 | queue = &newsp->pd_lobby; |
5659 | } else | 5659 | } else |
5660 | queue = &newsk->sk_receive_queue; | 5660 | queue = &newsk->sk_receive_queue; |
5661 | 5661 | ||
5662 | /* Walk through the pd_lobby, looking for skbs that | 5662 | /* Walk through the pd_lobby, looking for skbs that |
5663 | * need moved to the new socket. | 5663 | * need moved to the new socket. |
5664 | */ | 5664 | */ |
5665 | sctp_skb_for_each(skb, &oldsp->pd_lobby, tmp) { | 5665 | sctp_skb_for_each(skb, &oldsp->pd_lobby, tmp) { |
5666 | event = sctp_skb2event(skb); | 5666 | event = sctp_skb2event(skb); |
5667 | if (event->asoc == assoc) { | 5667 | if (event->asoc == assoc) { |
5668 | sock_rfree(skb); | 5668 | sock_rfree(skb); |
5669 | __skb_unlink(skb, &oldsp->pd_lobby); | 5669 | __skb_unlink(skb, &oldsp->pd_lobby); |
5670 | __skb_queue_tail(queue, skb); | 5670 | __skb_queue_tail(queue, skb); |
5671 | skb_set_owner_r(skb, newsk); | 5671 | skb_set_owner_r(skb, newsk); |
5672 | } | 5672 | } |
5673 | } | 5673 | } |
5674 | 5674 | ||
5675 | /* Clear up any skbs waiting for the partial | 5675 | /* Clear up any skbs waiting for the partial |
5676 | * delivery to finish. | 5676 | * delivery to finish. |
5677 | */ | 5677 | */ |
5678 | if (assoc->ulpq.pd_mode) | 5678 | if (assoc->ulpq.pd_mode) |
5679 | sctp_clear_pd(oldsk); | 5679 | sctp_clear_pd(oldsk); |
5680 | 5680 | ||
5681 | } | 5681 | } |
5682 | 5682 | ||
5683 | /* Set the type of socket to indicate that it is peeled off from the | 5683 | /* Set the type of socket to indicate that it is peeled off from the |
5684 | * original UDP-style socket or created with the accept() call on a | 5684 | * original UDP-style socket or created with the accept() call on a |
5685 | * TCP-style socket.. | 5685 | * TCP-style socket.. |
5686 | */ | 5686 | */ |
5687 | newsp->type = type; | 5687 | newsp->type = type; |
5688 | 5688 | ||
5689 | /* Mark the new socket "in-use" by the user so that any packets | 5689 | /* Mark the new socket "in-use" by the user so that any packets |
5690 | * that may arrive on the association after we've moved it are | 5690 | * that may arrive on the association after we've moved it are |
5691 | * queued to the backlog. This prevents a potential race between | 5691 | * queued to the backlog. This prevents a potential race between |
5692 | * backlog processing on the old socket and new-packet processing | 5692 | * backlog processing on the old socket and new-packet processing |
5693 | * on the new socket. | 5693 | * on the new socket. |
5694 | */ | 5694 | */ |
5695 | sctp_lock_sock(newsk); | 5695 | sctp_lock_sock(newsk); |
5696 | sctp_assoc_migrate(assoc, newsk); | 5696 | sctp_assoc_migrate(assoc, newsk); |
5697 | 5697 | ||
5698 | /* If the association on the newsk is already closed before accept() | 5698 | /* If the association on the newsk is already closed before accept() |
5699 | * is called, set RCV_SHUTDOWN flag. | 5699 | * is called, set RCV_SHUTDOWN flag. |
5700 | */ | 5700 | */ |
5701 | if (sctp_state(assoc, CLOSED) && sctp_style(newsk, TCP)) | 5701 | if (sctp_state(assoc, CLOSED) && sctp_style(newsk, TCP)) |
5702 | newsk->sk_shutdown |= RCV_SHUTDOWN; | 5702 | newsk->sk_shutdown |= RCV_SHUTDOWN; |
5703 | 5703 | ||
5704 | newsk->sk_state = SCTP_SS_ESTABLISHED; | 5704 | newsk->sk_state = SCTP_SS_ESTABLISHED; |
5705 | sctp_release_sock(newsk); | 5705 | sctp_release_sock(newsk); |
5706 | } | 5706 | } |
5707 | 5707 | ||
5708 | /* This proto struct describes the ULP interface for SCTP. */ | 5708 | /* This proto struct describes the ULP interface for SCTP. */ |
5709 | struct proto sctp_prot = { | 5709 | struct proto sctp_prot = { |
5710 | .name = "SCTP", | 5710 | .name = "SCTP", |
5711 | .owner = THIS_MODULE, | 5711 | .owner = THIS_MODULE, |
5712 | .close = sctp_close, | 5712 | .close = sctp_close, |
5713 | .connect = sctp_connect, | 5713 | .connect = sctp_connect, |
5714 | .disconnect = sctp_disconnect, | 5714 | .disconnect = sctp_disconnect, |
5715 | .accept = sctp_accept, | 5715 | .accept = sctp_accept, |
5716 | .ioctl = sctp_ioctl, | 5716 | .ioctl = sctp_ioctl, |
5717 | .init = sctp_init_sock, | 5717 | .init = sctp_init_sock, |
5718 | .destroy = sctp_destroy_sock, | 5718 | .destroy = sctp_destroy_sock, |
5719 | .shutdown = sctp_shutdown, | 5719 | .shutdown = sctp_shutdown, |
5720 | .setsockopt = sctp_setsockopt, | 5720 | .setsockopt = sctp_setsockopt, |
5721 | .getsockopt = sctp_getsockopt, | 5721 | .getsockopt = sctp_getsockopt, |
5722 | .sendmsg = sctp_sendmsg, | 5722 | .sendmsg = sctp_sendmsg, |
5723 | .recvmsg = sctp_recvmsg, | 5723 | .recvmsg = sctp_recvmsg, |
5724 | .bind = sctp_bind, | 5724 | .bind = sctp_bind, |
5725 | .backlog_rcv = sctp_backlog_rcv, | 5725 | .backlog_rcv = sctp_backlog_rcv, |
5726 | .hash = sctp_hash, | 5726 | .hash = sctp_hash, |
5727 | .unhash = sctp_unhash, | 5727 | .unhash = sctp_unhash, |
5728 | .get_port = sctp_get_port, | 5728 | .get_port = sctp_get_port, |
5729 | .obj_size = sizeof(struct sctp_sock), | 5729 | .obj_size = sizeof(struct sctp_sock), |
5730 | }; | 5730 | }; |
5731 | 5731 | ||
5732 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | 5732 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
5733 | struct proto sctpv6_prot = { | 5733 | struct proto sctpv6_prot = { |
5734 | .name = "SCTPv6", | 5734 | .name = "SCTPv6", |
5735 | .owner = THIS_MODULE, | 5735 | .owner = THIS_MODULE, |
5736 | .close = sctp_close, | 5736 | .close = sctp_close, |
5737 | .connect = sctp_connect, | 5737 | .connect = sctp_connect, |
5738 | .disconnect = sctp_disconnect, | 5738 | .disconnect = sctp_disconnect, |
5739 | .accept = sctp_accept, | 5739 | .accept = sctp_accept, |
5740 | .ioctl = sctp_ioctl, | 5740 | .ioctl = sctp_ioctl, |
5741 | .init = sctp_init_sock, | 5741 | .init = sctp_init_sock, |
5742 | .destroy = sctp_destroy_sock, | 5742 | .destroy = sctp_destroy_sock, |
5743 | .shutdown = sctp_shutdown, | 5743 | .shutdown = sctp_shutdown, |
5744 | .setsockopt = sctp_setsockopt, | 5744 | .setsockopt = sctp_setsockopt, |
5745 | .getsockopt = sctp_getsockopt, | 5745 | .getsockopt = sctp_getsockopt, |
5746 | .sendmsg = sctp_sendmsg, | 5746 | .sendmsg = sctp_sendmsg, |
5747 | .recvmsg = sctp_recvmsg, | 5747 | .recvmsg = sctp_recvmsg, |
5748 | .bind = sctp_bind, | 5748 | .bind = sctp_bind, |
5749 | .backlog_rcv = sctp_backlog_rcv, | 5749 | .backlog_rcv = sctp_backlog_rcv, |
5750 | .hash = sctp_hash, | 5750 | .hash = sctp_hash, |
5751 | .unhash = sctp_unhash, | 5751 | .unhash = sctp_unhash, |
5752 | .get_port = sctp_get_port, | 5752 | .get_port = sctp_get_port, |
5753 | .obj_size = sizeof(struct sctp6_sock), | 5753 | .obj_size = sizeof(struct sctp6_sock), |
5754 | }; | 5754 | }; |
5755 | #endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */ | 5755 | #endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */ |
5756 | 5756 |