4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
23 #ifndef __LIBCFS_LINUX_NET_H__
24 #define __LIBCFS_LINUX_NET_H__
26 #include <net/netlink.h>
27 #include <net/genetlink.h>
29 /* NL_SET_ERR_MSG macros is already defined in kernels
30 * 3.10.0-1160 and above. For older kernels (3.10.0-957)
31 * where this is not defined we put the message to the
32 * system log as a workaround
34 #ifndef NL_SET_ERR_MSG
35 #define NL_SET_ERR_MSG(unused, msg) do { \
36 static const char __msg[] = msg; \
37 pr_debug("%s\n", __msg); \
41 #ifndef NLM_F_DUMP_FILTERED
42 #define NLM_F_DUMP_FILTERED 0x20 /* Dump was filtered as requested */
45 #ifndef HAVE_NLA_STRDUP
46 char *nla_strdup(const struct nlattr *nla, gfp_t flags);
47 #endif /* !HAVE_NLA_STRDUP */
49 #ifdef HAVE_NLA_STRLCPY
50 #define nla_strscpy nla_strlcpy
51 #endif /* HAVE_NLA_STRLCPY */
53 #ifndef HAVE_NL_PARSE_WITH_EXT_ACK
55 #define NL_SET_BAD_ATTR(extack, attr)
57 /* this can be increased when necessary - don't expose to userland */
58 #define NETLINK_MAX_COOKIE_LEN 20
61 * struct netlink_ext_ack - netlink extended ACK report struct
62 * @_msg: message string to report - don't access directly, use
64 * @bad_attr: attribute with error
65 * @cookie: cookie data to return to userspace (for success)
66 * @cookie_len: actual cookie data length
68 struct netlink_ext_ack {
70 const struct nlattr *bad_attr;
71 u8 cookie[NETLINK_MAX_COOKIE_LEN];
75 #define GENL_SET_ERR_MSG(info, msg) NL_SET_ERR_MSG(NULL, msg)
77 static inline int cfs_nla_parse(struct nlattr **tb, int maxtype,
78 const struct nlattr *head, int len,
79 const struct nla_policy *policy,
80 struct netlink_ext_ack *extack)
82 return nla_parse(tb, maxtype, head, len, policy);
85 static inline int cfs_nla_parse_nested(struct nlattr *tb[], int maxtype,
86 const struct nlattr *nla,
87 const struct nla_policy *policy,
88 struct netlink_ext_ack *extack)
90 return nla_parse_nested(tb, maxtype, nla, policy);
93 #else /* !HAVE_NL_PARSE_WITH_EXT_ACK */
95 #define cfs_nla_parse_nested nla_parse_nested
96 #define cfs_nla_parse nla_parse
100 #ifndef HAVE_GENL_DUMPIT_INFO
101 struct cfs_genl_dumpit_info {
102 const struct genl_family *family;
103 const struct genl_ops *ops;
104 struct nlattr **attrs;
107 static inline const struct cfs_genl_dumpit_info *
108 lnet_genl_dumpit_info(struct netlink_callback *cb)
110 return (const struct cfs_genl_dumpit_info *)cb->args[1];
113 #define cfs_genl_dumpit_info genl_dumpit_info
115 static inline const struct cfs_genl_dumpit_info *
116 lnet_genl_dumpit_info(struct netlink_callback *cb)
118 return (const struct cfs_genl_dumpit_info *)genl_dumpit_info(cb);
120 #endif /* HAVE_GENL_DUMPIT_INFO */
122 #ifdef HAVE_KERNEL_SETSOCKOPT
126 #if !defined(HAVE_TCP_SOCK_SET_QUICKACK)
127 static inline void tcp_sock_set_quickack(struct sock *sk, int opt)
129 struct socket *sock = sk->sk_socket;
131 kernel_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
132 (char *)&opt, sizeof(opt));
134 #endif /* HAVE_TCP_SOCK_SET_QUICKACK */
136 #if !defined(HAVE_TCP_SOCK_SET_NODELAY)
137 static inline void tcp_sock_set_nodelay(struct sock *sk)
140 struct socket *sock = sk->sk_socket;
142 kernel_setsockopt(sock, SOL_TCP, TCP_NODELAY,
143 (char *)&opt, sizeof(opt));
145 #endif /* HAVE_TCP_SOCK_SET_NODELAY */
147 #if !defined(HAVE_TCP_SOCK_SET_KEEPIDLE)
148 static inline int tcp_sock_set_keepidle(struct sock *sk, int opt)
150 struct socket *sock = sk->sk_socket;
152 return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPIDLE,
153 (char *)&opt, sizeof(opt));
155 #endif /* HAVE_TCP_SOCK_SET_KEEPIDLE */
157 #if !defined(HAVE_TCP_SOCK_SET_KEEPINTVL)
158 static inline int tcp_sock_set_keepintvl(struct sock *sk, int opt)
160 struct socket *sock = sk->sk_socket;
162 return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPINTVL,
163 (char *)&opt, sizeof(opt));
165 #endif /* HAVE_TCP_SOCK_SET_KEEPINTVL */
167 #if !defined(HAVE_TCP_SOCK_SET_KEEPCNT)
168 static inline int tcp_sock_set_keepcnt(struct sock *sk, int opt)
170 struct socket *sock = sk->sk_socket;
172 return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPCNT,
173 (char *)&opt, sizeof(opt));
175 #endif /* HAVE_TCP_SOCK_SET_KEEPCNT */
177 #if !defined(HAVE_IP6_SET_PREF)
178 static inline void ip6_sock_set_addr_preferences(struct sock *sk,
181 kernel_setsockopt(sk->sk_socket, SOL_IPV6, IPV6_ADDR_PREFERENCES,
182 (char *)&pref, sizeof(pref));
184 #endif /* HAVE_IP6_SET_PREF */
186 #if !defined(HAVE_IP_SET_TOS)
187 static inline void ip_sock_set_tos(struct sock *sk, int val)
189 kernel_setsockopt(sk->sk_socket, IPPROTO_IP, IP_TOS,
190 (char *)&val, sizeof(val));
192 #endif /* HAVE_IP_SET_TOS */
193 #endif /* HAVE_KERNEL_SETSOCKOPT */
195 #endif /* __LIBCFS_LINUX_NET_H__ */