sock.c (f2f872f9272a79a1048877ea14c15576f46c225e) | sock.c (e0d1095ae3405404d247afb00233ef837d58da83) |
---|---|
1/* 2 * INET An implementation of the TCP/IP protocol suite for the LINUX 3 * operating system. INET is implemented using the BSD Socket 4 * interface as the means of communication with the user level. 5 * 6 * Generic socket support routines. Memory allocators, socket lock/release 7 * handler for protocols to use and generic option handler. 8 * --- 79 unchanged lines hidden (view full) --- 88 * as published by the Free Software Foundation; either version 89 * 2 of the License, or (at your option) any later version. 90 */ 91 92#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 93 94#include <linux/capability.h> 95#include <linux/errno.h> | 1/* 2 * INET An implementation of the TCP/IP protocol suite for the LINUX 3 * operating system. INET is implemented using the BSD Socket 4 * interface as the means of communication with the user level. 5 * 6 * Generic socket support routines. Memory allocators, socket lock/release 7 * handler for protocols to use and generic option handler. 8 * --- 79 unchanged lines hidden (view full) --- 88 * as published by the Free Software Foundation; either version 89 * 2 of the License, or (at your option) any later version. 90 */ 91 92#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 93 94#include <linux/capability.h> 95#include <linux/errno.h> |
96#include <linux/errqueue.h> | |
97#include <linux/types.h> 98#include <linux/socket.h> 99#include <linux/in.h> 100#include <linux/kernel.h> 101#include <linux/module.h> 102#include <linux/proc_fs.h> 103#include <linux/seq_file.h> 104#include <linux/sched.h> --- 791 unchanged lines hidden (view full) --- 896 case SO_NOFCS: 897 sock_valbool_flag(sk, SOCK_NOFCS, valbool); 898 break; 899 900 case SO_SELECT_ERR_QUEUE: 901 sock_valbool_flag(sk, SOCK_SELECT_ERR_QUEUE, valbool); 902 break; 903 | 96#include <linux/types.h> 97#include <linux/socket.h> 98#include <linux/in.h> 99#include <linux/kernel.h> 100#include <linux/module.h> 101#include <linux/proc_fs.h> 102#include <linux/seq_file.h> 103#include <linux/sched.h> --- 791 unchanged lines hidden (view full) --- 895 case SO_NOFCS: 896 sock_valbool_flag(sk, SOCK_NOFCS, valbool); 897 break; 898 899 case SO_SELECT_ERR_QUEUE: 900 sock_valbool_flag(sk, SOCK_SELECT_ERR_QUEUE, valbool); 901 break; 902 |
904#ifdef CONFIG_NET_LL_RX_POLL | 903#ifdef CONFIG_NET_RX_BUSY_POLL |
905 case SO_BUSY_POLL: 906 /* allow unprivileged users to decrease the value */ 907 if ((val > sk->sk_ll_usec) && !capable(CAP_NET_ADMIN)) 908 ret = -EPERM; 909 else { 910 if (val < 0) 911 ret = -EINVAL; 912 else --- 253 unchanged lines hidden (view full) --- 1166 case SO_LOCK_FILTER: 1167 v.val = sock_flag(sk, SOCK_FILTER_LOCKED); 1168 break; 1169 1170 case SO_SELECT_ERR_QUEUE: 1171 v.val = sock_flag(sk, SOCK_SELECT_ERR_QUEUE); 1172 break; 1173 | 904 case SO_BUSY_POLL: 905 /* allow unprivileged users to decrease the value */ 906 if ((val > sk->sk_ll_usec) && !capable(CAP_NET_ADMIN)) 907 ret = -EPERM; 908 else { 909 if (val < 0) 910 ret = -EINVAL; 911 else --- 253 unchanged lines hidden (view full) --- 1165 case SO_LOCK_FILTER: 1166 v.val = sock_flag(sk, SOCK_FILTER_LOCKED); 1167 break; 1168 1169 case SO_SELECT_ERR_QUEUE: 1170 v.val = sock_flag(sk, SOCK_SELECT_ERR_QUEUE); 1171 break; 1172 |
1174#ifdef CONFIG_NET_LL_RX_POLL | 1173#ifdef CONFIG_NET_RX_BUSY_POLL |
1175 case SO_BUSY_POLL: 1176 v.val = sk->sk_ll_usec; 1177 break; 1178#endif 1179 1180 default: 1181 return -ENOPROTOOPT; 1182 } --- 388 unchanged lines hidden (view full) --- 1571 * if sk_wmem_alloc reaches 0, we must finish what sk_free() 1572 * could not do because of in-flight packets 1573 */ 1574 if (atomic_sub_and_test(len, &sk->sk_wmem_alloc)) 1575 __sk_free(sk); 1576} 1577EXPORT_SYMBOL(sock_wfree); 1578 | 1174 case SO_BUSY_POLL: 1175 v.val = sk->sk_ll_usec; 1176 break; 1177#endif 1178 1179 default: 1180 return -ENOPROTOOPT; 1181 } --- 388 unchanged lines hidden (view full) --- 1570 * if sk_wmem_alloc reaches 0, we must finish what sk_free() 1571 * could not do because of in-flight packets 1572 */ 1573 if (atomic_sub_and_test(len, &sk->sk_wmem_alloc)) 1574 __sk_free(sk); 1575} 1576EXPORT_SYMBOL(sock_wfree); 1577 |
1579void skb_orphan_partial(struct sk_buff *skb) 1580{ 1581 /* TCP stack sets skb->ooo_okay based on sk_wmem_alloc, 1582 * so we do not completely orphan skb, but transfert all 1583 * accounted bytes but one, to avoid unexpected reorders. 1584 */ 1585 if (skb->destructor == sock_wfree 1586#ifdef CONFIG_INET 1587 || skb->destructor == tcp_wfree 1588#endif 1589 ) { 1590 atomic_sub(skb->truesize - 1, &skb->sk->sk_wmem_alloc); 1591 skb->truesize = 1; 1592 } else { 1593 skb_orphan(skb); 1594 } 1595} 1596EXPORT_SYMBOL(skb_orphan_partial); 1597 | |
1598/* 1599 * Read buffer destructor automatically called from kfree_skb. 1600 */ 1601void sock_rfree(struct sk_buff *skb) 1602{ 1603 struct sock *sk = skb->sk; 1604 unsigned int len = skb->truesize; 1605 --- 701 unchanged lines hidden (view full) --- 2307 sk->sk_peer_cred = NULL; 2308 sk->sk_write_pending = 0; 2309 sk->sk_rcvlowat = 1; 2310 sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT; 2311 sk->sk_sndtimeo = MAX_SCHEDULE_TIMEOUT; 2312 2313 sk->sk_stamp = ktime_set(-1L, 0); 2314 | 1578/* 1579 * Read buffer destructor automatically called from kfree_skb. 1580 */ 1581void sock_rfree(struct sk_buff *skb) 1582{ 1583 struct sock *sk = skb->sk; 1584 unsigned int len = skb->truesize; 1585 --- 701 unchanged lines hidden (view full) --- 2287 sk->sk_peer_cred = NULL; 2288 sk->sk_write_pending = 0; 2289 sk->sk_rcvlowat = 1; 2290 sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT; 2291 sk->sk_sndtimeo = MAX_SCHEDULE_TIMEOUT; 2292 2293 sk->sk_stamp = ktime_set(-1L, 0); 2294 |
2315#ifdef CONFIG_NET_LL_RX_POLL | 2295#ifdef CONFIG_NET_RX_BUSY_POLL |
2316 sk->sk_napi_id = 0; 2317 sk->sk_ll_usec = sysctl_net_busy_read; 2318#endif 2319 2320 /* 2321 * Before updating sk_refcnt, we must commit prior changes to memory 2322 * (Documentation/RCU/rculist_nulls.txt for details) 2323 */ --- 116 unchanged lines hidden (view full) --- 2440 * time stamping, but time stamping might have been on 2441 * already because of the other one 2442 */ 2443 if (!(previous_flags & SK_FLAGS_TIMESTAMP)) 2444 net_enable_timestamp(); 2445 } 2446} 2447 | 2296 sk->sk_napi_id = 0; 2297 sk->sk_ll_usec = sysctl_net_busy_read; 2298#endif 2299 2300 /* 2301 * Before updating sk_refcnt, we must commit prior changes to memory 2302 * (Documentation/RCU/rculist_nulls.txt for details) 2303 */ --- 116 unchanged lines hidden (view full) --- 2420 * time stamping, but time stamping might have been on 2421 * already because of the other one 2422 */ 2423 if (!(previous_flags & SK_FLAGS_TIMESTAMP)) 2424 net_enable_timestamp(); 2425 } 2426} 2427 |
2448int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len, 2449 int level, int type) 2450{ 2451 struct sock_exterr_skb *serr; 2452 struct sk_buff *skb, *skb2; 2453 int copied, err; 2454 2455 err = -EAGAIN; 2456 skb = skb_dequeue(&sk->sk_error_queue); 2457 if (skb == NULL) 2458 goto out; 2459 2460 copied = skb->len; 2461 if (copied > len) { 2462 msg->msg_flags |= MSG_TRUNC; 2463 copied = len; 2464 } 2465 err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied); 2466 if (err) 2467 goto out_free_skb; 2468 2469 sock_recv_timestamp(msg, sk, skb); 2470 2471 serr = SKB_EXT_ERR(skb); 2472 put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee); 2473 2474 msg->msg_flags |= MSG_ERRQUEUE; 2475 err = copied; 2476 2477 /* Reset and regenerate socket error */ 2478 spin_lock_bh(&sk->sk_error_queue.lock); 2479 sk->sk_err = 0; 2480 if ((skb2 = skb_peek(&sk->sk_error_queue)) != NULL) { 2481 sk->sk_err = SKB_EXT_ERR(skb2)->ee.ee_errno; 2482 spin_unlock_bh(&sk->sk_error_queue.lock); 2483 sk->sk_error_report(sk); 2484 } else 2485 spin_unlock_bh(&sk->sk_error_queue.lock); 2486 2487out_free_skb: 2488 kfree_skb(skb); 2489out: 2490 return err; 2491} 2492EXPORT_SYMBOL(sock_recv_errqueue); 2493 | |
2494/* 2495 * Get a socket option on an socket. 2496 * 2497 * FIX: POSIX 1003.1g is very ambiguous here. It states that 2498 * asynchronous errors should be reported by getsockopt. We assume 2499 * this means if you specify SO_ERROR (otherwise whats the point of it). 2500 */ 2501int sock_common_getsockopt(struct socket *sock, int level, int optname, --- 437 unchanged lines hidden --- | 2428/* 2429 * Get a socket option on an socket. 2430 * 2431 * FIX: POSIX 1003.1g is very ambiguous here. It states that 2432 * asynchronous errors should be reported by getsockopt. We assume 2433 * this means if you specify SO_ERROR (otherwise whats the point of it). 2434 */ 2435int sock_common_getsockopt(struct socket *sock, int level, int optname, --- 437 unchanged lines hidden --- |