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 #ifndef HAVE_NLA_STRDUP
30 char *nla_strdup(const struct nlattr *nla, gfp_t flags);
31 #endif /* !HAVE_NLA_STRDUP */
33 #ifndef HAVE_NL_PARSE_WITH_EXT_ACK
35 #define NL_SET_BAD_ATTR(extack, attr)
37 /* this can be increased when necessary - don't expose to userland */
38 #define NETLINK_MAX_COOKIE_LEN 20
41 * struct netlink_ext_ack - netlink extended ACK report struct
42 * @_msg: message string to report - don't access directly, use
44 * @bad_attr: attribute with error
45 * @cookie: cookie data to return to userspace (for success)
46 * @cookie_len: actual cookie data length
48 struct netlink_ext_ack {
50 const struct nlattr *bad_attr;
51 u8 cookie[NETLINK_MAX_COOKIE_LEN];
55 #define GENL_SET_ERR_MSG(info, msg) NL_SET_ERR_MSG(NULL, msg)
57 static inline int cfs_nla_parse(struct nlattr **tb, int maxtype,
58 const struct nlattr *head, int len,
59 const struct nla_policy *policy,
60 struct netlink_ext_ack *extack)
62 return nla_parse(tb, maxtype, head, len, policy);
65 static inline int cfs_nla_parse_nested(struct nlattr *tb[], int maxtype,
66 const struct nlattr *nla,
67 const struct nla_policy *policy,
68 struct netlink_ext_ack *extack)
70 return nla_parse_nested(tb, maxtype, nla, policy);
73 #else /* !HAVE_NL_PARSE_WITH_EXT_ACK */
75 #define cfs_nla_parse_nested nla_parse_nested
76 #define cfs_nla_parse nla_parse
80 #ifndef HAVE_GENL_DUMPIT_INFO
81 struct cfs_genl_dumpit_info {
82 const struct genl_family *family;
83 const struct genl_ops *ops;
84 struct nlattr **attrs;
87 static inline const struct cfs_genl_dumpit_info *
88 lnet_genl_dumpit_info(struct netlink_callback *cb)
90 return (const struct cfs_genl_dumpit_info *)cb->args[1];
93 #define cfs_genl_dumpit_info genl_dumpit_info
95 static inline const struct cfs_genl_dumpit_info *
96 lnet_genl_dumpit_info(struct netlink_callback *cb)
98 return (const struct cfs_genl_dumpit_info *)genl_dumpit_info(cb);
100 #endif /* HAVE_GENL_DUMPIT_INFO */
102 #ifdef HAVE_KERNEL_SETSOCKOPT
106 #if !defined(HAVE_TCP_SOCK_SET_QUICKACK)
107 static inline void tcp_sock_set_quickack(struct sock *sk, int opt)
109 struct socket *sock = sk->sk_socket;
111 kernel_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
112 (char *)&opt, sizeof(opt));
114 #endif /* HAVE_TCP_SOCK_SET_QUICKACK */
116 #if !defined(HAVE_TCP_SOCK_SET_NODELAY)
117 static inline void tcp_sock_set_nodelay(struct sock *sk)
120 struct socket *sock = sk->sk_socket;
122 kernel_setsockopt(sock, SOL_TCP, TCP_NODELAY,
123 (char *)&opt, sizeof(opt));
125 #endif /* HAVE_TCP_SOCK_SET_NODELAY */
127 #if !defined(HAVE_TCP_SOCK_SET_KEEPIDLE)
128 static inline int tcp_sock_set_keepidle(struct sock *sk, int opt)
130 struct socket *sock = sk->sk_socket;
132 return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPIDLE,
133 (char *)&opt, sizeof(opt));
135 #endif /* HAVE_TCP_SOCK_SET_KEEPIDLE */
137 #if !defined(HAVE_TCP_SOCK_SET_KEEPINTVL)
138 static inline int tcp_sock_set_keepintvl(struct sock *sk, int opt)
140 struct socket *sock = sk->sk_socket;
142 return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPINTVL,
143 (char *)&opt, sizeof(opt));
145 #endif /* HAVE_TCP_SOCK_SET_KEEPINTVL */
147 #if !defined(HAVE_TCP_SOCK_SET_KEEPCNT)
148 static inline int tcp_sock_set_keepcnt(struct sock *sk, int opt)
150 struct socket *sock = sk->sk_socket;
152 return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPCNT,
153 (char *)&opt, sizeof(opt));
155 #endif /* HAVE_TCP_SOCK_SET_KEEPCNT */
156 #endif /* HAVE_KERNEL_SETSOCKOPT */
158 #endif /* __LIBCFS_LINUX_NET_H__ */