Whamcloud - gitweb
LU-14713 llite: mend the trunc_sem_up_write()
[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 #include <net/netlink.h>
27
28 #ifndef HAVE_NLA_STRDUP
29 char *nla_strdup(const struct nlattr *nla, gfp_t flags);
30 #endif /* !HAVE_NLA_STRDUP */
31
32 #ifndef HAVE_NL_PARSE_WITH_EXT_ACK
33
34 #define NL_SET_BAD_ATTR(extack, attr)
35
36 /* this can be increased when necessary - don't expose to userland */
37 #define NETLINK_MAX_COOKIE_LEN  20
38
39 /**
40  * struct netlink_ext_ack - netlink extended ACK report struct
41  * @_msg: message string to report - don't access directly, use
42  *      %NL_SET_ERR_MSG
43  * @bad_attr: attribute with error
44  * @cookie: cookie data to return to userspace (for success)
45  * @cookie_len: actual cookie data length
46  */
47 struct netlink_ext_ack {
48         const char *_msg;
49         const struct nlattr *bad_attr;
50         u8 cookie[NETLINK_MAX_COOKIE_LEN];
51         u8 cookie_len;
52 };
53
54 #define GENL_SET_ERR_MSG(info, msg) NL_SET_ERR_MSG(NULL, msg)
55
56 static inline int cfs_nla_parse(struct nlattr **tb, int maxtype,
57                                 const struct nlattr *head, int len,
58                                 const struct nla_policy *policy,
59                                 struct netlink_ext_ack *extack)
60 {
61         return nla_parse(tb, maxtype, head, len, policy);
62 }
63
64 static inline int cfs_nla_parse_nested(struct nlattr *tb[], int maxtype,
65                                        const struct nlattr *nla,
66                                        const struct nla_policy *policy,
67                                        struct netlink_ext_ack *extack)
68 {
69         return nla_parse_nested(tb, maxtype, nla, policy);
70 }
71
72 #else /* !HAVE_NL_PARSE_WITH_EXT_ACK */
73
74 #define cfs_nla_parse_nested    nla_parse_nested
75 #define cfs_nla_parse           nla_parse
76
77 #endif
78
79 #ifdef HAVE_KERNEL_SETSOCKOPT
80
81 #include <net/tcp.h>
82
83 #if !defined(HAVE_TCP_SOCK_SET_QUICKACK)
84 static inline void tcp_sock_set_quickack(struct sock *sk, int opt)
85 {
86         struct socket *sock = sk->sk_socket;
87
88         kernel_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
89                           (char *)&opt, sizeof(opt));
90 }
91 #endif /* HAVE_TCP_SOCK_SET_QUICKACK */
92
93 #if !defined(HAVE_TCP_SOCK_SET_NODELAY)
94 static inline void tcp_sock_set_nodelay(struct sock *sk)
95 {
96         int opt = 1;
97         struct socket *sock = sk->sk_socket;
98
99         kernel_setsockopt(sock, SOL_TCP, TCP_NODELAY,
100                           (char *)&opt, sizeof(opt));
101 }
102 #endif /* HAVE_TCP_SOCK_SET_NODELAY */
103
104 #if !defined(HAVE_TCP_SOCK_SET_KEEPIDLE)
105 static inline int tcp_sock_set_keepidle(struct sock *sk, int opt)
106 {
107         struct socket *sock = sk->sk_socket;
108
109         return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPIDLE,
110                                  (char *)&opt, sizeof(opt));
111 }
112 #endif /* HAVE_TCP_SOCK_SET_KEEPIDLE */
113
114 #if !defined(HAVE_TCP_SOCK_SET_KEEPINTVL)
115 static inline int tcp_sock_set_keepintvl(struct sock *sk, int opt)
116 {
117         struct socket *sock = sk->sk_socket;
118
119         return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPINTVL,
120                                  (char *)&opt, sizeof(opt));
121 }
122 #endif /* HAVE_TCP_SOCK_SET_KEEPINTVL */
123
124 #if !defined(HAVE_TCP_SOCK_SET_KEEPCNT)
125 static inline int tcp_sock_set_keepcnt(struct sock *sk, int opt)
126 {
127         struct socket *sock = sk->sk_socket;
128
129         return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPCNT,
130                                  (char *)&opt, sizeof(opt));
131 }
132 #endif /* HAVE_TCP_SOCK_SET_KEEPCNT */
133 #endif /* HAVE_KERNEL_SETSOCKOPT */
134
135 #endif /* __LIBCFS_LINUX_NET_H__ */