Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * SUCS NET3: |
| 3 | * |
| 4 | * Generic datagram handling routines. These are generic for all |
| 5 | * protocols. Possibly a generic IP version on top of these would |
| 6 | * make sense. Not tonight however 8-). |
| 7 | * This is used because UDP, RAW, PACKET, DDP, IPX, AX.25 and |
| 8 | * NetROM layer all have identical poll code and mostly |
| 9 | * identical recvmsg() code. So we share it here. The poll was |
| 10 | * shared before but buried in udp.c so I moved it. |
| 11 | * |
Alan Cox | 113aa83 | 2008-10-13 19:01:08 -0700 | [diff] [blame] | 12 | * Authors: Alan Cox <alan@lxorguk.ukuu.org.uk>. (datagram_poll() from old |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * udp.c code) |
| 14 | * |
| 15 | * Fixes: |
| 16 | * Alan Cox : NULL return from skb_peek_copy() |
| 17 | * understood |
| 18 | * Alan Cox : Rewrote skb_read_datagram to avoid the |
| 19 | * skb_peek_copy stuff. |
| 20 | * Alan Cox : Added support for SOCK_SEQPACKET. |
| 21 | * IPX can no longer use the SO_TYPE hack |
| 22 | * but AX.25 now works right, and SPX is |
| 23 | * feasible. |
| 24 | * Alan Cox : Fixed write poll of non IP protocol |
| 25 | * crash. |
| 26 | * Florian La Roche: Changed for my new skbuff handling. |
| 27 | * Darryl Miles : Fixed non-blocking SOCK_SEQPACKET. |
| 28 | * Linus Torvalds : BSD semantic fixes. |
| 29 | * Alan Cox : Datagram iovec handling |
| 30 | * Darryl Miles : Fixed non-blocking SOCK_STREAM. |
| 31 | * Alan Cox : POSIXisms |
| 32 | * Pete Wyckoff : Unconnected accept() fix. |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | #include <linux/module.h> |
| 37 | #include <linux/types.h> |
| 38 | #include <linux/kernel.h> |
| 39 | #include <asm/uaccess.h> |
| 40 | #include <asm/system.h> |
| 41 | #include <linux/mm.h> |
| 42 | #include <linux/interrupt.h> |
| 43 | #include <linux/errno.h> |
| 44 | #include <linux/sched.h> |
| 45 | #include <linux/inet.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <linux/netdevice.h> |
| 47 | #include <linux/rtnetlink.h> |
| 48 | #include <linux/poll.h> |
| 49 | #include <linux/highmem.h> |
Herbert Xu | 3305b80 | 2005-12-13 23:16:37 -0800 | [diff] [blame] | 50 | #include <linux/spinlock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | #include <net/protocol.h> |
| 53 | #include <linux/skbuff.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
Arnaldo Carvalho de Melo | c752f07 | 2005-08-09 20:08:28 -0700 | [diff] [blame] | 55 | #include <net/checksum.h> |
| 56 | #include <net/sock.h> |
| 57 | #include <net/tcp_states.h> |
Neil Horman | e9b3cc1 | 2009-08-13 05:19:44 +0000 | [diff] [blame] | 58 | #include <trace/events/skb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | /* |
| 61 | * Is a socket 'connection oriented' ? |
| 62 | */ |
| 63 | static inline int connection_based(struct sock *sk) |
| 64 | { |
| 65 | return sk->sk_type == SOCK_SEQPACKET || sk->sk_type == SOCK_STREAM; |
| 66 | } |
| 67 | |
Eric Dumazet | bf368e4 | 2009-04-28 02:24:21 -0700 | [diff] [blame] | 68 | static int receiver_wake_function(wait_queue_t *wait, unsigned mode, int sync, |
| 69 | void *key) |
| 70 | { |
| 71 | unsigned long bits = (unsigned long)key; |
| 72 | |
| 73 | /* |
| 74 | * Avoid a wakeup if event not interesting for us |
| 75 | */ |
| 76 | if (bits && !(bits & (POLLIN | POLLERR))) |
| 77 | return 0; |
| 78 | return autoremove_wake_function(wait, mode, sync, key); |
| 79 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | /* |
| 81 | * Wait for a packet.. |
| 82 | */ |
| 83 | static int wait_for_packet(struct sock *sk, int *err, long *timeo_p) |
| 84 | { |
| 85 | int error; |
Eric Dumazet | bf368e4 | 2009-04-28 02:24:21 -0700 | [diff] [blame] | 86 | DEFINE_WAIT_FUNC(wait, receiver_wake_function); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | prepare_to_wait_exclusive(sk->sk_sleep, &wait, TASK_INTERRUPTIBLE); |
| 89 | |
| 90 | /* Socket errors? */ |
| 91 | error = sock_error(sk); |
| 92 | if (error) |
| 93 | goto out_err; |
| 94 | |
| 95 | if (!skb_queue_empty(&sk->sk_receive_queue)) |
| 96 | goto out; |
| 97 | |
| 98 | /* Socket shut down? */ |
| 99 | if (sk->sk_shutdown & RCV_SHUTDOWN) |
| 100 | goto out_noerr; |
| 101 | |
| 102 | /* Sequenced packets can come disconnected. |
| 103 | * If so we report the problem |
| 104 | */ |
| 105 | error = -ENOTCONN; |
| 106 | if (connection_based(sk) && |
| 107 | !(sk->sk_state == TCP_ESTABLISHED || sk->sk_state == TCP_LISTEN)) |
| 108 | goto out_err; |
| 109 | |
| 110 | /* handle signals */ |
| 111 | if (signal_pending(current)) |
| 112 | goto interrupted; |
| 113 | |
| 114 | error = 0; |
| 115 | *timeo_p = schedule_timeout(*timeo_p); |
| 116 | out: |
| 117 | finish_wait(sk->sk_sleep, &wait); |
| 118 | return error; |
| 119 | interrupted: |
| 120 | error = sock_intr_errno(*timeo_p); |
| 121 | out_err: |
| 122 | *err = error; |
| 123 | goto out; |
| 124 | out_noerr: |
| 125 | *err = 0; |
| 126 | error = 1; |
| 127 | goto out; |
| 128 | } |
| 129 | |
| 130 | /** |
Herbert Xu | a59322b | 2007-12-05 01:53:40 -0800 | [diff] [blame] | 131 | * __skb_recv_datagram - Receive a datagram skbuff |
Pavel Pisa | 4dc3b16 | 2005-05-01 08:59:25 -0700 | [diff] [blame] | 132 | * @sk: socket |
| 133 | * @flags: MSG_ flags |
Herbert Xu | a59322b | 2007-12-05 01:53:40 -0800 | [diff] [blame] | 134 | * @peeked: returns non-zero if this packet has been seen before |
Pavel Pisa | 4dc3b16 | 2005-05-01 08:59:25 -0700 | [diff] [blame] | 135 | * @err: error code returned |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | * |
| 137 | * Get a datagram skbuff, understands the peeking, nonblocking wakeups |
| 138 | * and possible races. This replaces identical code in packet, raw and |
| 139 | * udp, as well as the IPX AX.25 and Appletalk. It also finally fixes |
| 140 | * the long standing peek and read race for datagram sockets. If you |
| 141 | * alter this routine remember it must be re-entrant. |
| 142 | * |
| 143 | * This function will lock the socket if a skb is returned, so the caller |
| 144 | * needs to unlock the socket in that case (usually by calling |
| 145 | * skb_free_datagram) |
| 146 | * |
| 147 | * * It does not lock socket since today. This function is |
| 148 | * * free of race conditions. This measure should/can improve |
| 149 | * * significantly datagram socket latencies at high loads, |
| 150 | * * when data copying to user space takes lots of time. |
| 151 | * * (BTW I've just killed the last cli() in IP/IPv6/core/netlink/packet |
| 152 | * * 8) Great win.) |
| 153 | * * --ANK (980729) |
| 154 | * |
| 155 | * The order of the tests when we find no data waiting are specified |
| 156 | * quite explicitly by POSIX 1003.1g, don't change them without having |
| 157 | * the standard around please. |
| 158 | */ |
Herbert Xu | a59322b | 2007-12-05 01:53:40 -0800 | [diff] [blame] | 159 | struct sk_buff *__skb_recv_datagram(struct sock *sk, unsigned flags, |
| 160 | int *peeked, int *err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { |
| 162 | struct sk_buff *skb; |
| 163 | long timeo; |
| 164 | /* |
| 165 | * Caller is allowed not to check sk->sk_err before skb_recv_datagram() |
| 166 | */ |
| 167 | int error = sock_error(sk); |
| 168 | |
| 169 | if (error) |
| 170 | goto no_packet; |
| 171 | |
Herbert Xu | a59322b | 2007-12-05 01:53:40 -0800 | [diff] [blame] | 172 | timeo = sock_rcvtimeo(sk, flags & MSG_DONTWAIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
| 174 | do { |
| 175 | /* Again only user level code calls this function, so nothing |
| 176 | * interrupt level will suddenly eat the receive_queue. |
| 177 | * |
| 178 | * Look at current nfs client by the way... |
| 179 | * However, this function was corrent in any case. 8) |
| 180 | */ |
Herbert Xu | a59322b | 2007-12-05 01:53:40 -0800 | [diff] [blame] | 181 | unsigned long cpu_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Herbert Xu | a59322b | 2007-12-05 01:53:40 -0800 | [diff] [blame] | 183 | spin_lock_irqsave(&sk->sk_receive_queue.lock, cpu_flags); |
| 184 | skb = skb_peek(&sk->sk_receive_queue); |
| 185 | if (skb) { |
| 186 | *peeked = skb->peeked; |
| 187 | if (flags & MSG_PEEK) { |
| 188 | skb->peeked = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | atomic_inc(&skb->users); |
Herbert Xu | a59322b | 2007-12-05 01:53:40 -0800 | [diff] [blame] | 190 | } else |
| 191 | __skb_unlink(skb, &sk->sk_receive_queue); |
| 192 | } |
| 193 | spin_unlock_irqrestore(&sk->sk_receive_queue.lock, cpu_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
| 195 | if (skb) |
| 196 | return skb; |
| 197 | |
| 198 | /* User doesn't want to wait */ |
| 199 | error = -EAGAIN; |
| 200 | if (!timeo) |
| 201 | goto no_packet; |
| 202 | |
| 203 | } while (!wait_for_packet(sk, err, &timeo)); |
| 204 | |
| 205 | return NULL; |
| 206 | |
| 207 | no_packet: |
| 208 | *err = error; |
| 209 | return NULL; |
| 210 | } |
Herbert Xu | a59322b | 2007-12-05 01:53:40 -0800 | [diff] [blame] | 211 | EXPORT_SYMBOL(__skb_recv_datagram); |
| 212 | |
| 213 | struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, |
| 214 | int noblock, int *err) |
| 215 | { |
| 216 | int peeked; |
| 217 | |
| 218 | return __skb_recv_datagram(sk, flags | (noblock ? MSG_DONTWAIT : 0), |
| 219 | &peeked, err); |
| 220 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | |
| 222 | void skb_free_datagram(struct sock *sk, struct sk_buff *skb) |
| 223 | { |
Neil Horman | ead2ceb | 2009-03-11 09:49:55 +0000 | [diff] [blame] | 224 | consume_skb(skb); |
Eric Dumazet | 270acef | 2008-11-05 01:38:06 -0800 | [diff] [blame] | 225 | sk_mem_reclaim_partial(sk); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
Eric Dumazet | 9d410c7 | 2009-10-30 05:03:53 +0000 | [diff] [blame] | 227 | EXPORT_SYMBOL(skb_free_datagram); |
| 228 | |
| 229 | void skb_free_datagram_locked(struct sock *sk, struct sk_buff *skb) |
| 230 | { |
| 231 | lock_sock(sk); |
| 232 | skb_free_datagram(sk, skb); |
| 233 | release_sock(sk); |
| 234 | } |
| 235 | EXPORT_SYMBOL(skb_free_datagram_locked); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
| 237 | /** |
Herbert Xu | 3305b80 | 2005-12-13 23:16:37 -0800 | [diff] [blame] | 238 | * skb_kill_datagram - Free a datagram skbuff forcibly |
| 239 | * @sk: socket |
| 240 | * @skb: datagram skbuff |
| 241 | * @flags: MSG_ flags |
| 242 | * |
| 243 | * This function frees a datagram skbuff that was received by |
| 244 | * skb_recv_datagram. The flags argument must match the one |
| 245 | * used for skb_recv_datagram. |
| 246 | * |
| 247 | * If the MSG_PEEK flag is set, and the packet is still on the |
| 248 | * receive queue of the socket, it will be taken off the queue |
| 249 | * before it is freed. |
| 250 | * |
| 251 | * This function currently only disables BH when acquiring the |
| 252 | * sk_receive_queue lock. Therefore it must not be used in a |
| 253 | * context where that lock is acquired in an IRQ context. |
Herbert Xu | 27ab256 | 2007-12-05 01:51:58 -0800 | [diff] [blame] | 254 | * |
| 255 | * It returns 0 if the packet was removed by us. |
Herbert Xu | 3305b80 | 2005-12-13 23:16:37 -0800 | [diff] [blame] | 256 | */ |
| 257 | |
Herbert Xu | 27ab256 | 2007-12-05 01:51:58 -0800 | [diff] [blame] | 258 | int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags) |
Herbert Xu | 3305b80 | 2005-12-13 23:16:37 -0800 | [diff] [blame] | 259 | { |
Herbert Xu | 27ab256 | 2007-12-05 01:51:58 -0800 | [diff] [blame] | 260 | int err = 0; |
| 261 | |
Herbert Xu | 3305b80 | 2005-12-13 23:16:37 -0800 | [diff] [blame] | 262 | if (flags & MSG_PEEK) { |
Herbert Xu | 27ab256 | 2007-12-05 01:51:58 -0800 | [diff] [blame] | 263 | err = -ENOENT; |
Herbert Xu | 3305b80 | 2005-12-13 23:16:37 -0800 | [diff] [blame] | 264 | spin_lock_bh(&sk->sk_receive_queue.lock); |
| 265 | if (skb == skb_peek(&sk->sk_receive_queue)) { |
| 266 | __skb_unlink(skb, &sk->sk_receive_queue); |
| 267 | atomic_dec(&skb->users); |
Herbert Xu | 27ab256 | 2007-12-05 01:51:58 -0800 | [diff] [blame] | 268 | err = 0; |
Herbert Xu | 3305b80 | 2005-12-13 23:16:37 -0800 | [diff] [blame] | 269 | } |
| 270 | spin_unlock_bh(&sk->sk_receive_queue.lock); |
| 271 | } |
| 272 | |
John Dykstra | 61de71c | 2009-05-08 14:57:01 -0700 | [diff] [blame] | 273 | kfree_skb(skb); |
Eric Dumazet | 8edf19c | 2009-10-15 00:12:40 +0000 | [diff] [blame] | 274 | atomic_inc(&sk->sk_drops); |
John Dykstra | 61de71c | 2009-05-08 14:57:01 -0700 | [diff] [blame] | 275 | sk_mem_reclaim_partial(sk); |
| 276 | |
Herbert Xu | 27ab256 | 2007-12-05 01:51:58 -0800 | [diff] [blame] | 277 | return err; |
Herbert Xu | 3305b80 | 2005-12-13 23:16:37 -0800 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | EXPORT_SYMBOL(skb_kill_datagram); |
| 281 | |
| 282 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | * skb_copy_datagram_iovec - Copy a datagram to an iovec. |
Pavel Pisa | 4dc3b16 | 2005-05-01 08:59:25 -0700 | [diff] [blame] | 284 | * @skb: buffer to copy |
| 285 | * @offset: offset in the buffer to start copying from |
Martin Waitz | 67be2dd | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 286 | * @to: io vector to copy to |
Pavel Pisa | 4dc3b16 | 2005-05-01 08:59:25 -0700 | [diff] [blame] | 287 | * @len: amount of data to copy from buffer to iovec |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | * |
| 289 | * Note: the iovec is modified during the copy. |
| 290 | */ |
| 291 | int skb_copy_datagram_iovec(const struct sk_buff *skb, int offset, |
| 292 | struct iovec *to, int len) |
| 293 | { |
David S. Miller | 1a028e5 | 2007-04-27 15:21:23 -0700 | [diff] [blame] | 294 | int start = skb_headlen(skb); |
| 295 | int i, copy = start - offset; |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 296 | struct sk_buff *frag_iter; |
Herbert Xu | c75d721 | 2005-11-02 18:55:00 +1100 | [diff] [blame] | 297 | |
Neil Horman | e9b3cc1 | 2009-08-13 05:19:44 +0000 | [diff] [blame] | 298 | trace_skb_copy_datagram_iovec(skb, len); |
| 299 | |
David S. Miller | b4d9eda | 2006-02-13 16:06:10 -0800 | [diff] [blame] | 300 | /* Copy header. */ |
| 301 | if (copy > 0) { |
| 302 | if (copy > len) |
| 303 | copy = len; |
| 304 | if (memcpy_toiovec(to, skb->data + offset, copy)) |
| 305 | goto fault; |
| 306 | if ((len -= copy) == 0) |
| 307 | return 0; |
| 308 | offset += copy; |
| 309 | } |
Herbert Xu | c75d721 | 2005-11-02 18:55:00 +1100 | [diff] [blame] | 310 | |
David S. Miller | b4d9eda | 2006-02-13 16:06:10 -0800 | [diff] [blame] | 311 | /* Copy paged appendix. Hmm... why does this look so complicated? */ |
| 312 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
David S. Miller | 1a028e5 | 2007-04-27 15:21:23 -0700 | [diff] [blame] | 313 | int end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Ilpo Järvinen | 547b792 | 2008-07-25 21:43:18 -0700 | [diff] [blame] | 315 | WARN_ON(start > offset + len); |
David S. Miller | 1a028e5 | 2007-04-27 15:21:23 -0700 | [diff] [blame] | 316 | |
| 317 | end = start + skb_shinfo(skb)->frags[i].size; |
David S. Miller | b4d9eda | 2006-02-13 16:06:10 -0800 | [diff] [blame] | 318 | if ((copy = end - offset) > 0) { |
| 319 | int err; |
| 320 | u8 *vaddr; |
| 321 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 322 | struct page *page = frag->page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | if (copy > len) |
| 325 | copy = len; |
David S. Miller | b4d9eda | 2006-02-13 16:06:10 -0800 | [diff] [blame] | 326 | vaddr = kmap(page); |
David S. Miller | 1a028e5 | 2007-04-27 15:21:23 -0700 | [diff] [blame] | 327 | err = memcpy_toiovec(to, vaddr + frag->page_offset + |
| 328 | offset - start, copy); |
David S. Miller | b4d9eda | 2006-02-13 16:06:10 -0800 | [diff] [blame] | 329 | kunmap(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | if (err) |
| 331 | goto fault; |
| 332 | if (!(len -= copy)) |
| 333 | return 0; |
| 334 | offset += copy; |
| 335 | } |
David S. Miller | 1a028e5 | 2007-04-27 15:21:23 -0700 | [diff] [blame] | 336 | start = end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | } |
David S. Miller | b4d9eda | 2006-02-13 16:06:10 -0800 | [diff] [blame] | 338 | |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 339 | skb_walk_frags(skb, frag_iter) { |
| 340 | int end; |
David S. Miller | b4d9eda | 2006-02-13 16:06:10 -0800 | [diff] [blame] | 341 | |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 342 | WARN_ON(start > offset + len); |
David S. Miller | b4d9eda | 2006-02-13 16:06:10 -0800 | [diff] [blame] | 343 | |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 344 | end = start + frag_iter->len; |
| 345 | if ((copy = end - offset) > 0) { |
| 346 | if (copy > len) |
| 347 | copy = len; |
| 348 | if (skb_copy_datagram_iovec(frag_iter, |
| 349 | offset - start, |
| 350 | to, copy)) |
| 351 | goto fault; |
| 352 | if ((len -= copy) == 0) |
| 353 | return 0; |
| 354 | offset += copy; |
David S. Miller | b4d9eda | 2006-02-13 16:06:10 -0800 | [diff] [blame] | 355 | } |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 356 | start = end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | } |
David S. Miller | b4d9eda | 2006-02-13 16:06:10 -0800 | [diff] [blame] | 358 | if (!len) |
| 359 | return 0; |
| 360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | fault: |
| 362 | return -EFAULT; |
| 363 | } |
| 364 | |
Rusty Russell | db543c1 | 2008-08-15 15:13:53 -0700 | [diff] [blame] | 365 | /** |
Michael S. Tsirkin | 0a1ec07 | 2009-04-20 01:25:46 +0000 | [diff] [blame] | 366 | * skb_copy_datagram_const_iovec - Copy a datagram to an iovec. |
| 367 | * @skb: buffer to copy |
| 368 | * @offset: offset in the buffer to start copying from |
| 369 | * @to: io vector to copy to |
| 370 | * @to_offset: offset in the io vector to start copying to |
| 371 | * @len: amount of data to copy from buffer to iovec |
| 372 | * |
| 373 | * Returns 0 or -EFAULT. |
| 374 | * Note: the iovec is not modified during the copy. |
| 375 | */ |
| 376 | int skb_copy_datagram_const_iovec(const struct sk_buff *skb, int offset, |
| 377 | const struct iovec *to, int to_offset, |
| 378 | int len) |
| 379 | { |
| 380 | int start = skb_headlen(skb); |
| 381 | int i, copy = start - offset; |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 382 | struct sk_buff *frag_iter; |
Michael S. Tsirkin | 0a1ec07 | 2009-04-20 01:25:46 +0000 | [diff] [blame] | 383 | |
| 384 | /* Copy header. */ |
| 385 | if (copy > 0) { |
| 386 | if (copy > len) |
| 387 | copy = len; |
| 388 | if (memcpy_toiovecend(to, skb->data + offset, to_offset, copy)) |
| 389 | goto fault; |
| 390 | if ((len -= copy) == 0) |
| 391 | return 0; |
| 392 | offset += copy; |
| 393 | to_offset += copy; |
| 394 | } |
| 395 | |
| 396 | /* Copy paged appendix. Hmm... why does this look so complicated? */ |
| 397 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 398 | int end; |
| 399 | |
| 400 | WARN_ON(start > offset + len); |
| 401 | |
| 402 | end = start + skb_shinfo(skb)->frags[i].size; |
| 403 | if ((copy = end - offset) > 0) { |
| 404 | int err; |
| 405 | u8 *vaddr; |
| 406 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 407 | struct page *page = frag->page; |
| 408 | |
| 409 | if (copy > len) |
| 410 | copy = len; |
| 411 | vaddr = kmap(page); |
| 412 | err = memcpy_toiovecend(to, vaddr + frag->page_offset + |
| 413 | offset - start, to_offset, copy); |
| 414 | kunmap(page); |
| 415 | if (err) |
| 416 | goto fault; |
| 417 | if (!(len -= copy)) |
| 418 | return 0; |
| 419 | offset += copy; |
| 420 | to_offset += copy; |
| 421 | } |
| 422 | start = end; |
| 423 | } |
| 424 | |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 425 | skb_walk_frags(skb, frag_iter) { |
| 426 | int end; |
Michael S. Tsirkin | 0a1ec07 | 2009-04-20 01:25:46 +0000 | [diff] [blame] | 427 | |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 428 | WARN_ON(start > offset + len); |
Michael S. Tsirkin | 0a1ec07 | 2009-04-20 01:25:46 +0000 | [diff] [blame] | 429 | |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 430 | end = start + frag_iter->len; |
| 431 | if ((copy = end - offset) > 0) { |
| 432 | if (copy > len) |
| 433 | copy = len; |
| 434 | if (skb_copy_datagram_const_iovec(frag_iter, |
| 435 | offset - start, |
| 436 | to, to_offset, |
| 437 | copy)) |
| 438 | goto fault; |
| 439 | if ((len -= copy) == 0) |
| 440 | return 0; |
| 441 | offset += copy; |
| 442 | to_offset += copy; |
Michael S. Tsirkin | 0a1ec07 | 2009-04-20 01:25:46 +0000 | [diff] [blame] | 443 | } |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 444 | start = end; |
Michael S. Tsirkin | 0a1ec07 | 2009-04-20 01:25:46 +0000 | [diff] [blame] | 445 | } |
| 446 | if (!len) |
| 447 | return 0; |
| 448 | |
| 449 | fault: |
| 450 | return -EFAULT; |
| 451 | } |
| 452 | EXPORT_SYMBOL(skb_copy_datagram_const_iovec); |
| 453 | |
| 454 | /** |
Rusty Russell | db543c1 | 2008-08-15 15:13:53 -0700 | [diff] [blame] | 455 | * skb_copy_datagram_from_iovec - Copy a datagram from an iovec. |
| 456 | * @skb: buffer to copy |
| 457 | * @offset: offset in the buffer to start copying to |
| 458 | * @from: io vector to copy to |
Michael S. Tsirkin | 6f26c9a | 2009-04-20 01:26:11 +0000 | [diff] [blame] | 459 | * @from_offset: offset in the io vector to start copying from |
Rusty Russell | db543c1 | 2008-08-15 15:13:53 -0700 | [diff] [blame] | 460 | * @len: amount of data to copy to buffer from iovec |
| 461 | * |
| 462 | * Returns 0 or -EFAULT. |
Michael S. Tsirkin | 6f26c9a | 2009-04-20 01:26:11 +0000 | [diff] [blame] | 463 | * Note: the iovec is not modified during the copy. |
Rusty Russell | db543c1 | 2008-08-15 15:13:53 -0700 | [diff] [blame] | 464 | */ |
| 465 | int skb_copy_datagram_from_iovec(struct sk_buff *skb, int offset, |
Michael S. Tsirkin | 6f26c9a | 2009-04-20 01:26:11 +0000 | [diff] [blame] | 466 | const struct iovec *from, int from_offset, |
| 467 | int len) |
Rusty Russell | db543c1 | 2008-08-15 15:13:53 -0700 | [diff] [blame] | 468 | { |
| 469 | int start = skb_headlen(skb); |
| 470 | int i, copy = start - offset; |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 471 | struct sk_buff *frag_iter; |
Rusty Russell | db543c1 | 2008-08-15 15:13:53 -0700 | [diff] [blame] | 472 | |
| 473 | /* Copy header. */ |
| 474 | if (copy > 0) { |
| 475 | if (copy > len) |
| 476 | copy = len; |
Sridhar Samudrala | d2d27bf | 2009-06-05 09:35:40 +0000 | [diff] [blame] | 477 | if (memcpy_fromiovecend(skb->data + offset, from, from_offset, |
| 478 | copy)) |
Rusty Russell | db543c1 | 2008-08-15 15:13:53 -0700 | [diff] [blame] | 479 | goto fault; |
| 480 | if ((len -= copy) == 0) |
| 481 | return 0; |
| 482 | offset += copy; |
Michael S. Tsirkin | 6f26c9a | 2009-04-20 01:26:11 +0000 | [diff] [blame] | 483 | from_offset += copy; |
Rusty Russell | db543c1 | 2008-08-15 15:13:53 -0700 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | /* Copy paged appendix. Hmm... why does this look so complicated? */ |
| 487 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
| 488 | int end; |
| 489 | |
| 490 | WARN_ON(start > offset + len); |
| 491 | |
| 492 | end = start + skb_shinfo(skb)->frags[i].size; |
| 493 | if ((copy = end - offset) > 0) { |
| 494 | int err; |
| 495 | u8 *vaddr; |
| 496 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 497 | struct page *page = frag->page; |
| 498 | |
| 499 | if (copy > len) |
| 500 | copy = len; |
| 501 | vaddr = kmap(page); |
Michael S. Tsirkin | 6f26c9a | 2009-04-20 01:26:11 +0000 | [diff] [blame] | 502 | err = memcpy_fromiovecend(vaddr + frag->page_offset + |
| 503 | offset - start, |
| 504 | from, from_offset, copy); |
Rusty Russell | db543c1 | 2008-08-15 15:13:53 -0700 | [diff] [blame] | 505 | kunmap(page); |
| 506 | if (err) |
| 507 | goto fault; |
| 508 | |
| 509 | if (!(len -= copy)) |
| 510 | return 0; |
| 511 | offset += copy; |
Michael S. Tsirkin | 6f26c9a | 2009-04-20 01:26:11 +0000 | [diff] [blame] | 512 | from_offset += copy; |
Rusty Russell | db543c1 | 2008-08-15 15:13:53 -0700 | [diff] [blame] | 513 | } |
| 514 | start = end; |
| 515 | } |
| 516 | |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 517 | skb_walk_frags(skb, frag_iter) { |
| 518 | int end; |
Rusty Russell | db543c1 | 2008-08-15 15:13:53 -0700 | [diff] [blame] | 519 | |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 520 | WARN_ON(start > offset + len); |
Rusty Russell | db543c1 | 2008-08-15 15:13:53 -0700 | [diff] [blame] | 521 | |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 522 | end = start + frag_iter->len; |
| 523 | if ((copy = end - offset) > 0) { |
| 524 | if (copy > len) |
| 525 | copy = len; |
| 526 | if (skb_copy_datagram_from_iovec(frag_iter, |
| 527 | offset - start, |
| 528 | from, |
| 529 | from_offset, |
| 530 | copy)) |
| 531 | goto fault; |
| 532 | if ((len -= copy) == 0) |
| 533 | return 0; |
| 534 | offset += copy; |
| 535 | from_offset += copy; |
Rusty Russell | db543c1 | 2008-08-15 15:13:53 -0700 | [diff] [blame] | 536 | } |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 537 | start = end; |
Rusty Russell | db543c1 | 2008-08-15 15:13:53 -0700 | [diff] [blame] | 538 | } |
| 539 | if (!len) |
| 540 | return 0; |
| 541 | |
| 542 | fault: |
| 543 | return -EFAULT; |
| 544 | } |
| 545 | EXPORT_SYMBOL(skb_copy_datagram_from_iovec); |
| 546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | static int skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset, |
| 548 | u8 __user *to, int len, |
Al Viro | 5084205 | 2006-11-14 21:36:34 -0800 | [diff] [blame] | 549 | __wsum *csump) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | { |
David S. Miller | 1a028e5 | 2007-04-27 15:21:23 -0700 | [diff] [blame] | 551 | int start = skb_headlen(skb); |
David S. Miller | 1a028e5 | 2007-04-27 15:21:23 -0700 | [diff] [blame] | 552 | int i, copy = start - offset; |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 553 | struct sk_buff *frag_iter; |
| 554 | int pos = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
| 556 | /* Copy header. */ |
| 557 | if (copy > 0) { |
| 558 | int err = 0; |
| 559 | if (copy > len) |
| 560 | copy = len; |
| 561 | *csump = csum_and_copy_to_user(skb->data + offset, to, copy, |
| 562 | *csump, &err); |
| 563 | if (err) |
| 564 | goto fault; |
| 565 | if ((len -= copy) == 0) |
| 566 | return 0; |
| 567 | offset += copy; |
| 568 | to += copy; |
| 569 | pos = copy; |
| 570 | } |
| 571 | |
| 572 | for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { |
David S. Miller | 1a028e5 | 2007-04-27 15:21:23 -0700 | [diff] [blame] | 573 | int end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | |
Ilpo Järvinen | 547b792 | 2008-07-25 21:43:18 -0700 | [diff] [blame] | 575 | WARN_ON(start > offset + len); |
David S. Miller | 1a028e5 | 2007-04-27 15:21:23 -0700 | [diff] [blame] | 576 | |
| 577 | end = start + skb_shinfo(skb)->frags[i].size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | if ((copy = end - offset) > 0) { |
Al Viro | 5084205 | 2006-11-14 21:36:34 -0800 | [diff] [blame] | 579 | __wsum csum2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | int err = 0; |
| 581 | u8 *vaddr; |
| 582 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 583 | struct page *page = frag->page; |
| 584 | |
| 585 | if (copy > len) |
| 586 | copy = len; |
| 587 | vaddr = kmap(page); |
| 588 | csum2 = csum_and_copy_to_user(vaddr + |
David S. Miller | 1a028e5 | 2007-04-27 15:21:23 -0700 | [diff] [blame] | 589 | frag->page_offset + |
| 590 | offset - start, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | to, copy, 0, &err); |
| 592 | kunmap(page); |
| 593 | if (err) |
| 594 | goto fault; |
| 595 | *csump = csum_block_add(*csump, csum2, pos); |
| 596 | if (!(len -= copy)) |
| 597 | return 0; |
| 598 | offset += copy; |
| 599 | to += copy; |
| 600 | pos += copy; |
| 601 | } |
David S. Miller | 1a028e5 | 2007-04-27 15:21:23 -0700 | [diff] [blame] | 602 | start = end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | } |
| 604 | |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 605 | skb_walk_frags(skb, frag_iter) { |
| 606 | int end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 608 | WARN_ON(start > offset + len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 610 | end = start + frag_iter->len; |
| 611 | if ((copy = end - offset) > 0) { |
| 612 | __wsum csum2 = 0; |
| 613 | if (copy > len) |
| 614 | copy = len; |
| 615 | if (skb_copy_and_csum_datagram(frag_iter, |
| 616 | offset - start, |
| 617 | to, copy, |
| 618 | &csum2)) |
| 619 | goto fault; |
| 620 | *csump = csum_block_add(*csump, csum2, pos); |
| 621 | if ((len -= copy) == 0) |
| 622 | return 0; |
| 623 | offset += copy; |
| 624 | to += copy; |
| 625 | pos += copy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | } |
David S. Miller | 5b1a002 | 2009-06-09 00:18:15 -0700 | [diff] [blame] | 627 | start = end; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | } |
| 629 | if (!len) |
| 630 | return 0; |
| 631 | |
| 632 | fault: |
| 633 | return -EFAULT; |
| 634 | } |
| 635 | |
Herbert Xu | 759e5d0 | 2007-03-25 20:10:56 -0700 | [diff] [blame] | 636 | __sum16 __skb_checksum_complete_head(struct sk_buff *skb, int len) |
Herbert Xu | fb286bb | 2005-11-10 13:01:24 -0800 | [diff] [blame] | 637 | { |
Al Viro | d3bc23e | 2006-11-14 21:24:49 -0800 | [diff] [blame] | 638 | __sum16 sum; |
Herbert Xu | fb286bb | 2005-11-10 13:01:24 -0800 | [diff] [blame] | 639 | |
Herbert Xu | 759e5d0 | 2007-03-25 20:10:56 -0700 | [diff] [blame] | 640 | sum = csum_fold(skb_checksum(skb, 0, len, skb->csum)); |
Herbert Xu | fb286bb | 2005-11-10 13:01:24 -0800 | [diff] [blame] | 641 | if (likely(!sum)) { |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 642 | if (unlikely(skb->ip_summed == CHECKSUM_COMPLETE)) |
Herbert Xu | fb286bb | 2005-11-10 13:01:24 -0800 | [diff] [blame] | 643 | netdev_rx_csum_fault(skb->dev); |
| 644 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 645 | } |
| 646 | return sum; |
| 647 | } |
Herbert Xu | 759e5d0 | 2007-03-25 20:10:56 -0700 | [diff] [blame] | 648 | EXPORT_SYMBOL(__skb_checksum_complete_head); |
| 649 | |
| 650 | __sum16 __skb_checksum_complete(struct sk_buff *skb) |
| 651 | { |
| 652 | return __skb_checksum_complete_head(skb, skb->len); |
| 653 | } |
Herbert Xu | fb286bb | 2005-11-10 13:01:24 -0800 | [diff] [blame] | 654 | EXPORT_SYMBOL(__skb_checksum_complete); |
| 655 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | /** |
| 657 | * skb_copy_and_csum_datagram_iovec - Copy and checkum skb to user iovec. |
Pavel Pisa | 4dc3b16 | 2005-05-01 08:59:25 -0700 | [diff] [blame] | 658 | * @skb: skbuff |
| 659 | * @hlen: hardware length |
Martin Waitz | 67be2dd | 2005-05-01 08:59:26 -0700 | [diff] [blame] | 660 | * @iov: io vector |
YOSHIFUJI Hideaki | 4ec93ed | 2007-02-09 23:24:36 +0900 | [diff] [blame] | 661 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | * Caller _must_ check that skb will fit to this iovec. |
| 663 | * |
| 664 | * Returns: 0 - success. |
| 665 | * -EINVAL - checksum failure. |
| 666 | * -EFAULT - fault during copy. Beware, in this case iovec |
| 667 | * can be modified! |
| 668 | */ |
Herbert Xu | fb286bb | 2005-11-10 13:01:24 -0800 | [diff] [blame] | 669 | int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | int hlen, struct iovec *iov) |
| 671 | { |
Al Viro | d3bc23e | 2006-11-14 21:24:49 -0800 | [diff] [blame] | 672 | __wsum csum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | int chunk = skb->len - hlen; |
| 674 | |
Herbert Xu | ef8aef5 | 2007-09-06 14:06:35 +0100 | [diff] [blame] | 675 | if (!chunk) |
| 676 | return 0; |
| 677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | /* Skip filled elements. |
| 679 | * Pretty silly, look at memcpy_toiovec, though 8) |
| 680 | */ |
| 681 | while (!iov->iov_len) |
| 682 | iov++; |
| 683 | |
| 684 | if (iov->iov_len < chunk) { |
Herbert Xu | fb286bb | 2005-11-10 13:01:24 -0800 | [diff] [blame] | 685 | if (__skb_checksum_complete(skb)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | goto csum_error; |
| 687 | if (skb_copy_datagram_iovec(skb, hlen, iov, chunk)) |
| 688 | goto fault; |
| 689 | } else { |
| 690 | csum = csum_partial(skb->data, hlen, skb->csum); |
| 691 | if (skb_copy_and_csum_datagram(skb, hlen, iov->iov_base, |
| 692 | chunk, &csum)) |
| 693 | goto fault; |
Al Viro | d3bc23e | 2006-11-14 21:24:49 -0800 | [diff] [blame] | 694 | if (csum_fold(csum)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | goto csum_error; |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 696 | if (unlikely(skb->ip_summed == CHECKSUM_COMPLETE)) |
Herbert Xu | fb286bb | 2005-11-10 13:01:24 -0800 | [diff] [blame] | 697 | netdev_rx_csum_fault(skb->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | iov->iov_len -= chunk; |
| 699 | iov->iov_base += chunk; |
| 700 | } |
| 701 | return 0; |
| 702 | csum_error: |
| 703 | return -EINVAL; |
| 704 | fault: |
| 705 | return -EFAULT; |
| 706 | } |
| 707 | |
| 708 | /** |
| 709 | * datagram_poll - generic datagram poll |
Pavel Pisa | 4dc3b16 | 2005-05-01 08:59:25 -0700 | [diff] [blame] | 710 | * @file: file struct |
| 711 | * @sock: socket |
| 712 | * @wait: poll table |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | * |
| 714 | * Datagram poll: Again totally generic. This also handles |
| 715 | * sequenced packet sockets providing the socket receive queue |
| 716 | * is only ever holding data ready to receive. |
| 717 | * |
| 718 | * Note: when you _don't_ use this routine for this protocol, |
| 719 | * and you use a different write policy from sock_writeable() |
| 720 | * then please supply your own write_space callback. |
| 721 | */ |
| 722 | unsigned int datagram_poll(struct file *file, struct socket *sock, |
| 723 | poll_table *wait) |
| 724 | { |
| 725 | struct sock *sk = sock->sk; |
| 726 | unsigned int mask; |
| 727 | |
Jiri Olsa | a57de0b | 2009-07-08 12:09:13 +0000 | [diff] [blame] | 728 | sock_poll_wait(file, sk->sk_sleep, wait); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | mask = 0; |
| 730 | |
| 731 | /* exceptional events? */ |
| 732 | if (sk->sk_err || !skb_queue_empty(&sk->sk_error_queue)) |
| 733 | mask |= POLLERR; |
Davide Libenzi | f348d70 | 2006-03-25 03:07:39 -0800 | [diff] [blame] | 734 | if (sk->sk_shutdown & RCV_SHUTDOWN) |
| 735 | mask |= POLLRDHUP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | if (sk->sk_shutdown == SHUTDOWN_MASK) |
| 737 | mask |= POLLHUP; |
| 738 | |
| 739 | /* readable? */ |
| 740 | if (!skb_queue_empty(&sk->sk_receive_queue) || |
| 741 | (sk->sk_shutdown & RCV_SHUTDOWN)) |
| 742 | mask |= POLLIN | POLLRDNORM; |
| 743 | |
| 744 | /* Connection-based need to check for termination and startup */ |
| 745 | if (connection_based(sk)) { |
| 746 | if (sk->sk_state == TCP_CLOSE) |
| 747 | mask |= POLLHUP; |
| 748 | /* connection hasn't started yet? */ |
| 749 | if (sk->sk_state == TCP_SYN_SENT) |
| 750 | return mask; |
| 751 | } |
| 752 | |
| 753 | /* writable? */ |
| 754 | if (sock_writeable(sk)) |
| 755 | mask |= POLLOUT | POLLWRNORM | POLLWRBAND; |
| 756 | else |
| 757 | set_bit(SOCK_ASYNC_NOSPACE, &sk->sk_socket->flags); |
| 758 | |
| 759 | return mask; |
| 760 | } |
| 761 | |
| 762 | EXPORT_SYMBOL(datagram_poll); |
| 763 | EXPORT_SYMBOL(skb_copy_and_csum_datagram_iovec); |
| 764 | EXPORT_SYMBOL(skb_copy_datagram_iovec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | EXPORT_SYMBOL(skb_recv_datagram); |