Whamcloud - gitweb
LU-13783 libcfs: support removal of kernel_setsockopt()
[fs/lustre-release.git] / libcfs / include / libcfs / linux / linux-net.h
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22
23 #ifndef __LIBCFS_LINUX_NET_H__
24 #define __LIBCFS_LINUX_NET_H__
25
26 #ifdef HAVE_KERNEL_SETSOCKOPT
27
28 #include <net/tcp.h>
29
30 static inline void tcp_sock_set_quickack(struct sock *sk, int opt)
31 {
32         struct socket *sock = sk->sk_socket;
33
34         kernel_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
35                           (char *)&opt, sizeof(opt));
36 }
37
38 static inline void tcp_sock_set_nodelay(struct sock *sk)
39 {
40         int opt = 1;
41         struct socket *sock = sk->sk_socket;
42
43         kernel_setsockopt(sock, SOL_TCP, TCP_NODELAY,
44                           (char *)&opt, sizeof(opt));
45 }
46
47 static inline int tcp_sock_set_keepidle(struct sock *sk, int opt)
48 {
49         struct socket *sock = sk->sk_socket;
50
51         return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPIDLE,
52                                  (char *)&opt, sizeof(opt));
53 }
54
55 static inline int tcp_sock_set_keepintvl(struct sock *sk, int opt)
56 {
57         struct socket *sock = sk->sk_socket;
58
59         return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPINTVL,
60                                  (char *)&opt, sizeof(opt));
61 }
62
63 static inline int tcp_sock_set_keepcnt(struct sock *sk, int opt)
64 {
65         struct socket *sock = sk->sk_socket;
66
67         return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPCNT,
68                                  (char *)&opt, sizeof(opt));
69 }
70 #endif /* HAVE_KERNEL_SETSOCKOPT */
71
72 #endif /* __LIBCFS_LINUX_NET_H__ */