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>
28 #ifndef HAVE_NLA_STRDUP
29 char *nla_strdup(const struct nlattr *nla, gfp_t flags);
30 #endif /* !HAVE_NLA_STRDUP */
32 #ifndef HAVE_NL_PARSE_WITH_EXT_ACK
34 #define NL_SET_BAD_ATTR(extack, attr)
36 /* this can be increased when necessary - don't expose to userland */
37 #define NETLINK_MAX_COOKIE_LEN 20
40 * struct netlink_ext_ack - netlink extended ACK report struct
41 * @_msg: message string to report - don't access directly, use
43 * @bad_attr: attribute with error
44 * @cookie: cookie data to return to userspace (for success)
45 * @cookie_len: actual cookie data length
47 struct netlink_ext_ack {
49 const struct nlattr *bad_attr;
50 u8 cookie[NETLINK_MAX_COOKIE_LEN];
54 #define GENL_SET_ERR_MSG(info, msg) NL_SET_ERR_MSG(NULL, msg)
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)
61 return nla_parse(tb, maxtype, head, len, policy);
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)
69 return nla_parse_nested(tb, maxtype, nla, policy);
72 #else /* !HAVE_NL_PARSE_WITH_EXT_ACK */
74 #define cfs_nla_parse_nested nla_parse_nested
75 #define cfs_nla_parse nla_parse
79 #ifdef HAVE_KERNEL_SETSOCKOPT
83 #if !defined(HAVE_TCP_SOCK_SET_QUICKACK)
84 static inline void tcp_sock_set_quickack(struct sock *sk, int opt)
86 struct socket *sock = sk->sk_socket;
88 kernel_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
89 (char *)&opt, sizeof(opt));
91 #endif /* HAVE_TCP_SOCK_SET_QUICKACK */
93 #if !defined(HAVE_TCP_SOCK_SET_NODELAY)
94 static inline void tcp_sock_set_nodelay(struct sock *sk)
97 struct socket *sock = sk->sk_socket;
99 kernel_setsockopt(sock, SOL_TCP, TCP_NODELAY,
100 (char *)&opt, sizeof(opt));
102 #endif /* HAVE_TCP_SOCK_SET_NODELAY */
104 #if !defined(HAVE_TCP_SOCK_SET_KEEPIDLE)
105 static inline int tcp_sock_set_keepidle(struct sock *sk, int opt)
107 struct socket *sock = sk->sk_socket;
109 return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPIDLE,
110 (char *)&opt, sizeof(opt));
112 #endif /* HAVE_TCP_SOCK_SET_KEEPIDLE */
114 #if !defined(HAVE_TCP_SOCK_SET_KEEPINTVL)
115 static inline int tcp_sock_set_keepintvl(struct sock *sk, int opt)
117 struct socket *sock = sk->sk_socket;
119 return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPINTVL,
120 (char *)&opt, sizeof(opt));
122 #endif /* HAVE_TCP_SOCK_SET_KEEPINTVL */
124 #if !defined(HAVE_TCP_SOCK_SET_KEEPCNT)
125 static inline int tcp_sock_set_keepcnt(struct sock *sk, int opt)
127 struct socket *sock = sk->sk_socket;
129 return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPCNT,
130 (char *)&opt, sizeof(opt));
132 #endif /* HAVE_TCP_SOCK_SET_KEEPCNT */
133 #endif /* HAVE_KERNEL_SETSOCKOPT */
135 #endif /* __LIBCFS_LINUX_NET_H__ */