diff options
Diffstat (limited to 'include/net/sock.h')
| -rw-r--r-- | include/net/sock.h | 118 |
1 files changed, 51 insertions, 67 deletions
diff --git a/include/net/sock.h b/include/net/sock.h index fd9876087651..dc42b44c2aa1 100644 --- a/include/net/sock.h +++ b/include/net/sock.h | |||
| @@ -47,7 +47,6 @@ | |||
| 47 | #include <linux/module.h> | 47 | #include <linux/module.h> |
| 48 | #include <linux/lockdep.h> | 48 | #include <linux/lockdep.h> |
| 49 | #include <linux/netdevice.h> | 49 | #include <linux/netdevice.h> |
| 50 | #include <linux/pcounter.h> | ||
| 51 | #include <linux/skbuff.h> /* struct sk_buff */ | 50 | #include <linux/skbuff.h> /* struct sk_buff */ |
| 52 | #include <linux/mm.h> | 51 | #include <linux/mm.h> |
| 53 | #include <linux/security.h> | 52 | #include <linux/security.h> |
| @@ -70,7 +69,11 @@ | |||
| 70 | #define SOCK_DEBUG(sk, msg...) do { if ((sk) && sock_flag((sk), SOCK_DBG)) \ | 69 | #define SOCK_DEBUG(sk, msg...) do { if ((sk) && sock_flag((sk), SOCK_DBG)) \ |
| 71 | printk(KERN_DEBUG msg); } while (0) | 70 | printk(KERN_DEBUG msg); } while (0) |
| 72 | #else | 71 | #else |
| 73 | #define SOCK_DEBUG(sk, msg...) do { } while (0) | 72 | /* Validate arguments and do nothing */ |
| 73 | static void inline int __attribute__ ((format (printf, 2, 3))) | ||
| 74 | SOCK_DEBUG(struct sock *sk, const char *msg, ...) | ||
| 75 | { | ||
| 76 | } | ||
| 74 | #endif | 77 | #endif |
| 75 | 78 | ||
| 76 | /* This is the per-socket lock. The spinlock provides a synchronization | 79 | /* This is the per-socket lock. The spinlock provides a synchronization |
| @@ -122,7 +125,9 @@ struct sock_common { | |||
| 122 | atomic_t skc_refcnt; | 125 | atomic_t skc_refcnt; |
| 123 | unsigned int skc_hash; | 126 | unsigned int skc_hash; |
| 124 | struct proto *skc_prot; | 127 | struct proto *skc_prot; |
| 128 | #ifdef CONFIG_NET_NS | ||
| 125 | struct net *skc_net; | 129 | struct net *skc_net; |
| 130 | #endif | ||
| 126 | }; | 131 | }; |
| 127 | 132 | ||
| 128 | /** | 133 | /** |
| @@ -151,6 +156,7 @@ struct sock_common { | |||
| 151 | * @sk_no_check: %SO_NO_CHECK setting, wether or not checkup packets | 156 | * @sk_no_check: %SO_NO_CHECK setting, wether or not checkup packets |
| 152 | * @sk_route_caps: route capabilities (e.g. %NETIF_F_TSO) | 157 | * @sk_route_caps: route capabilities (e.g. %NETIF_F_TSO) |
| 153 | * @sk_gso_type: GSO type (e.g. %SKB_GSO_TCPV4) | 158 | * @sk_gso_type: GSO type (e.g. %SKB_GSO_TCPV4) |
| 159 | * @sk_gso_max_size: Maximum GSO segment size to build | ||
| 154 | * @sk_lingertime: %SO_LINGER l_linger setting | 160 | * @sk_lingertime: %SO_LINGER l_linger setting |
| 155 | * @sk_backlog: always used with the per-socket spinlock held | 161 | * @sk_backlog: always used with the per-socket spinlock held |
| 156 | * @sk_callback_lock: used with the callbacks in the end of this struct | 162 | * @sk_callback_lock: used with the callbacks in the end of this struct |
| @@ -237,6 +243,7 @@ struct sock { | |||
| 237 | gfp_t sk_allocation; | 243 | gfp_t sk_allocation; |
| 238 | int sk_route_caps; | 244 | int sk_route_caps; |
| 239 | int sk_gso_type; | 245 | int sk_gso_type; |
| 246 | unsigned int sk_gso_max_size; | ||
| 240 | int sk_rcvlowat; | 247 | int sk_rcvlowat; |
| 241 | unsigned long sk_flags; | 248 | unsigned long sk_flags; |
| 242 | unsigned long sk_lingertime; | 249 | unsigned long sk_lingertime; |
| @@ -498,6 +505,7 @@ extern int sk_wait_data(struct sock *sk, long *timeo); | |||
| 498 | struct request_sock_ops; | 505 | struct request_sock_ops; |
| 499 | struct timewait_sock_ops; | 506 | struct timewait_sock_ops; |
| 500 | struct inet_hashinfo; | 507 | struct inet_hashinfo; |
| 508 | struct raw_hashinfo; | ||
| 501 | 509 | ||
| 502 | /* Networking protocol blocks we attach to sockets. | 510 | /* Networking protocol blocks we attach to sockets. |
| 503 | * socket layer -> transport layer interface | 511 | * socket layer -> transport layer interface |
| @@ -553,7 +561,7 @@ struct proto { | |||
| 553 | 561 | ||
| 554 | /* Keeping track of sockets in use */ | 562 | /* Keeping track of sockets in use */ |
| 555 | #ifdef CONFIG_PROC_FS | 563 | #ifdef CONFIG_PROC_FS |
| 556 | struct pcounter inuse; | 564 | unsigned int inuse_idx; |
| 557 | #endif | 565 | #endif |
| 558 | 566 | ||
| 559 | /* Memory pressure */ | 567 | /* Memory pressure */ |
| @@ -580,7 +588,11 @@ struct proto { | |||
| 580 | struct request_sock_ops *rsk_prot; | 588 | struct request_sock_ops *rsk_prot; |
| 581 | struct timewait_sock_ops *twsk_prot; | 589 | struct timewait_sock_ops *twsk_prot; |
| 582 | 590 | ||
| 583 | struct inet_hashinfo *hashinfo; | 591 | union { |
| 592 | struct inet_hashinfo *hashinfo; | ||
| 593 | struct hlist_head *udp_hash; | ||
| 594 | struct raw_hashinfo *raw_hash; | ||
| 595 | } h; | ||
| 584 | 596 | ||
| 585 | struct module *owner; | 597 | struct module *owner; |
| 586 | 598 | ||
| @@ -622,36 +634,12 @@ static inline void sk_refcnt_debug_release(const struct sock *sk) | |||
| 622 | 634 | ||
| 623 | 635 | ||
| 624 | #ifdef CONFIG_PROC_FS | 636 | #ifdef CONFIG_PROC_FS |
| 625 | # define DEFINE_PROTO_INUSE(NAME) DEFINE_PCOUNTER(NAME) | ||
| 626 | # define REF_PROTO_INUSE(NAME) PCOUNTER_MEMBER_INITIALIZER(NAME, .inuse) | ||
| 627 | /* Called with local bh disabled */ | 637 | /* Called with local bh disabled */ |
| 628 | static inline void sock_prot_inuse_add(struct proto *prot, int inc) | 638 | extern void sock_prot_inuse_add(struct net *net, struct proto *prot, int inc); |
| 629 | { | 639 | extern int sock_prot_inuse_get(struct net *net, struct proto *proto); |
| 630 | pcounter_add(&prot->inuse, inc); | ||
| 631 | } | ||
| 632 | static inline int sock_prot_inuse_init(struct proto *proto) | ||
| 633 | { | ||
| 634 | return pcounter_alloc(&proto->inuse); | ||
| 635 | } | ||
| 636 | static inline int sock_prot_inuse_get(struct proto *proto) | ||
| 637 | { | ||
| 638 | return pcounter_getval(&proto->inuse); | ||
| 639 | } | ||
| 640 | static inline void sock_prot_inuse_free(struct proto *proto) | ||
| 641 | { | ||
| 642 | pcounter_free(&proto->inuse); | ||
| 643 | } | ||
| 644 | #else | 640 | #else |
| 645 | # define DEFINE_PROTO_INUSE(NAME) | 641 | static void inline sock_prot_inuse_add(struct net *net, struct proto *prot, |
| 646 | # define REF_PROTO_INUSE(NAME) | 642 | int inc) |
| 647 | static void inline sock_prot_inuse_add(struct proto *prot, int inc) | ||
| 648 | { | ||
| 649 | } | ||
| 650 | static int inline sock_prot_inuse_init(struct proto *proto) | ||
| 651 | { | ||
| 652 | return 0; | ||
| 653 | } | ||
| 654 | static void inline sock_prot_inuse_free(struct proto *proto) | ||
| 655 | { | 643 | { |
| 656 | } | 644 | } |
| 657 | #endif | 645 | #endif |
| @@ -850,6 +838,7 @@ extern struct sock *sk_alloc(struct net *net, int family, | |||
| 850 | gfp_t priority, | 838 | gfp_t priority, |
| 851 | struct proto *prot); | 839 | struct proto *prot); |
| 852 | extern void sk_free(struct sock *sk); | 840 | extern void sk_free(struct sock *sk); |
| 841 | extern void sk_release_kernel(struct sock *sk); | ||
| 853 | extern struct sock *sk_clone(const struct sock *sk, | 842 | extern struct sock *sk_clone(const struct sock *sk, |
| 854 | const gfp_t priority); | 843 | const gfp_t priority); |
| 855 | 844 | ||
| @@ -939,41 +928,6 @@ extern void sk_common_release(struct sock *sk); | |||
| 939 | extern void sock_init_data(struct socket *sock, struct sock *sk); | 928 | extern void sock_init_data(struct socket *sock, struct sock *sk); |
| 940 | 929 | ||
| 941 | /** | 930 | /** |
| 942 | * sk_filter - run a packet through a socket filter | ||
| 943 | * @sk: sock associated with &sk_buff | ||
| 944 | * @skb: buffer to filter | ||
| 945 | * @needlock: set to 1 if the sock is not locked by caller. | ||
| 946 | * | ||
| 947 | * Run the filter code and then cut skb->data to correct size returned by | ||
| 948 | * sk_run_filter. If pkt_len is 0 we toss packet. If skb->len is smaller | ||
| 949 | * than pkt_len we keep whole skb->data. This is the socket level | ||
| 950 | * wrapper to sk_run_filter. It returns 0 if the packet should | ||
| 951 | * be accepted or -EPERM if the packet should be tossed. | ||
| 952 | * | ||
| 953 | */ | ||
| 954 | |||
| 955 | static inline int sk_filter(struct sock *sk, struct sk_buff *skb) | ||
| 956 | { | ||
| 957 | int err; | ||
| 958 | struct sk_filter *filter; | ||
| 959 | |||
| 960 | err = security_sock_rcv_skb(sk, skb); | ||
| 961 | if (err) | ||
| 962 | return err; | ||
| 963 | |||
| 964 | rcu_read_lock_bh(); | ||
| 965 | filter = rcu_dereference(sk->sk_filter); | ||
| 966 | if (filter) { | ||
| 967 | unsigned int pkt_len = sk_run_filter(skb, filter->insns, | ||
| 968 | filter->len); | ||
| 969 | err = pkt_len ? pskb_trim(skb, pkt_len) : -EPERM; | ||
| 970 | } | ||
| 971 | rcu_read_unlock_bh(); | ||
| 972 | |||
| 973 | return err; | ||
| 974 | } | ||
| 975 | |||
| 976 | /** | ||
| 977 | * sk_filter_release: Release a socket filter | 931 | * sk_filter_release: Release a socket filter |
| 978 | * @sk: socket | 932 | * @sk: socket |
| 979 | * @fp: filter to remove | 933 | * @fp: filter to remove |
| @@ -1333,6 +1287,36 @@ static inline void sk_eat_skb(struct sock *sk, struct sk_buff *skb, int copied_e | |||
| 1333 | } | 1287 | } |
| 1334 | #endif | 1288 | #endif |
| 1335 | 1289 | ||
| 1290 | static inline | ||
| 1291 | struct net *sock_net(const struct sock *sk) | ||
| 1292 | { | ||
| 1293 | #ifdef CONFIG_NET_NS | ||
| 1294 | return sk->sk_net; | ||
| 1295 | #else | ||
| 1296 | return &init_net; | ||
| 1297 | #endif | ||
| 1298 | } | ||
| 1299 | |||
| 1300 | static inline | ||
| 1301 | void sock_net_set(struct sock *sk, struct net *net) | ||
| 1302 | { | ||
| 1303 | #ifdef CONFIG_NET_NS | ||
| 1304 | sk->sk_net = net; | ||
| 1305 | #endif | ||
| 1306 | } | ||
| 1307 | |||
| 1308 | /* | ||
| 1309 | * Kernel sockets, f.e. rtnl or icmp_socket, are a part of a namespace. | ||
| 1310 | * They should not hold a referrence to a namespace in order to allow | ||
| 1311 | * to stop it. | ||
| 1312 | * Sockets after sk_change_net should be released using sk_release_kernel | ||
| 1313 | */ | ||
| 1314 | static inline void sk_change_net(struct sock *sk, struct net *net) | ||
| 1315 | { | ||
| 1316 | put_net(sock_net(sk)); | ||
| 1317 | sock_net_set(sk, hold_net(net)); | ||
| 1318 | } | ||
| 1319 | |||
| 1336 | extern void sock_enable_timestamp(struct sock *sk); | 1320 | extern void sock_enable_timestamp(struct sock *sk); |
| 1337 | extern int sock_get_timestamp(struct sock *, struct timeval __user *); | 1321 | extern int sock_get_timestamp(struct sock *, struct timeval __user *); |
| 1338 | extern int sock_get_timestampns(struct sock *, struct timespec __user *); | 1322 | extern int sock_get_timestampns(struct sock *, struct timespec __user *); |
