diff options
author | Richard Cochran <richardcochran@gmail.com> | 2013-07-19 13:40:09 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2013-07-22 17:58:19 -0400 |
commit | cb820f8e4b7f73d1a32175e6591735b25bb5398d (patch) | |
tree | 0a361e6465be4bd549c17d957708d2e280914f21 /net/core/sock.c | |
parent | 0887a576a17965732270b2f8d37821fc02ef2feb (diff) |
net: Provide a generic socket error queue delivery method for Tx time stamps.
This patch moves the private error queue delivery function from the
af_packet code to the core socket method. In this way, network layers
only needing the error queue for transmit time stamping can share common
code.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core/sock.c')
-rw-r--r-- | net/core/sock.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/net/core/sock.c b/net/core/sock.c index 548d716c5f62..85e8de1bc7fd 100644 --- a/net/core/sock.c +++ b/net/core/sock.c | |||
@@ -93,6 +93,7 @@ | |||
93 | 93 | ||
94 | #include <linux/capability.h> | 94 | #include <linux/capability.h> |
95 | #include <linux/errno.h> | 95 | #include <linux/errno.h> |
96 | #include <linux/errqueue.h> | ||
96 | #include <linux/types.h> | 97 | #include <linux/types.h> |
97 | #include <linux/socket.h> | 98 | #include <linux/socket.h> |
98 | #include <linux/in.h> | 99 | #include <linux/in.h> |
@@ -2425,6 +2426,52 @@ void sock_enable_timestamp(struct sock *sk, int flag) | |||
2425 | } | 2426 | } |
2426 | } | 2427 | } |
2427 | 2428 | ||
2429 | int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len, | ||
2430 | int level, int type) | ||
2431 | { | ||
2432 | struct sock_exterr_skb *serr; | ||
2433 | struct sk_buff *skb, *skb2; | ||
2434 | int copied, err; | ||
2435 | |||
2436 | err = -EAGAIN; | ||
2437 | skb = skb_dequeue(&sk->sk_error_queue); | ||
2438 | if (skb == NULL) | ||
2439 | goto out; | ||
2440 | |||
2441 | copied = skb->len; | ||
2442 | if (copied > len) { | ||
2443 | msg->msg_flags |= MSG_TRUNC; | ||
2444 | copied = len; | ||
2445 | } | ||
2446 | err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); | ||
2447 | if (err) | ||
2448 | goto out_free_skb; | ||
2449 | |||
2450 | sock_recv_timestamp(msg, sk, skb); | ||
2451 | |||
2452 | serr = SKB_EXT_ERR(skb); | ||
2453 | put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee); | ||
2454 | |||
2455 | msg->msg_flags |= MSG_ERRQUEUE; | ||
2456 | err = copied; | ||
2457 | |||
2458 | /* Reset and regenerate socket error */ | ||
2459 | spin_lock_bh(&sk->sk_error_queue.lock); | ||
2460 | sk->sk_err = 0; | ||
2461 | if ((skb2 = skb_peek(&sk->sk_error_queue)) != NULL) { | ||
2462 | sk->sk_err = SKB_EXT_ERR(skb2)->ee.ee_errno; | ||
2463 | spin_unlock_bh(&sk->sk_error_queue.lock); | ||
2464 | sk->sk_error_report(sk); | ||
2465 | } else | ||
2466 | spin_unlock_bh(&sk->sk_error_queue.lock); | ||
2467 | |||
2468 | out_free_skb: | ||
2469 | kfree_skb(skb); | ||
2470 | out: | ||
2471 | return err; | ||
2472 | } | ||
2473 | EXPORT_SYMBOL(sock_recv_errqueue); | ||
2474 | |||
2428 | /* | 2475 | /* |
2429 | * Get a socket option on an socket. | 2476 | * Get a socket option on an socket. |
2430 | * | 2477 | * |