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 #ifdef HAVE_NLA_STRLCPY
34 #define nla_strscpy nla_strlcpy
35 #endif /* HAVE_NLA_STRLCPY */
37 #ifndef HAVE_NL_PARSE_WITH_EXT_ACK
39 #define NL_SET_BAD_ATTR(extack, attr)
41 /* this can be increased when necessary - don't expose to userland */
42 #define NETLINK_MAX_COOKIE_LEN 20
45 * struct netlink_ext_ack - netlink extended ACK report struct
46 * @_msg: message string to report - don't access directly, use
48 * @bad_attr: attribute with error
49 * @cookie: cookie data to return to userspace (for success)
50 * @cookie_len: actual cookie data length
52 struct netlink_ext_ack {
54 const struct nlattr *bad_attr;
55 u8 cookie[NETLINK_MAX_COOKIE_LEN];
59 #define GENL_SET_ERR_MSG(info, msg) NL_SET_ERR_MSG(NULL, msg)
61 static inline int cfs_nla_parse(struct nlattr **tb, int maxtype,
62 const struct nlattr *head, int len,
63 const struct nla_policy *policy,
64 struct netlink_ext_ack *extack)
66 return nla_parse(tb, maxtype, head, len, policy);
69 static inline int cfs_nla_parse_nested(struct nlattr *tb[], int maxtype,
70 const struct nlattr *nla,
71 const struct nla_policy *policy,
72 struct netlink_ext_ack *extack)
74 return nla_parse_nested(tb, maxtype, nla, policy);
77 #else /* !HAVE_NL_PARSE_WITH_EXT_ACK */
79 #define cfs_nla_parse_nested nla_parse_nested
80 #define cfs_nla_parse nla_parse
84 #ifndef HAVE_GENL_DUMPIT_INFO
85 struct cfs_genl_dumpit_info {
86 const struct genl_family *family;
87 const struct genl_ops *ops;
88 struct nlattr **attrs;
91 static inline const struct cfs_genl_dumpit_info *
92 lnet_genl_dumpit_info(struct netlink_callback *cb)
94 return (const struct cfs_genl_dumpit_info *)cb->args[1];
97 #define cfs_genl_dumpit_info genl_dumpit_info
99 static inline const struct cfs_genl_dumpit_info *
100 lnet_genl_dumpit_info(struct netlink_callback *cb)
102 return (const struct cfs_genl_dumpit_info *)genl_dumpit_info(cb);
104 #endif /* HAVE_GENL_DUMPIT_INFO */
106 #ifdef HAVE_KERNEL_SETSOCKOPT
110 #if !defined(HAVE_TCP_SOCK_SET_QUICKACK)
111 static inline void tcp_sock_set_quickack(struct sock *sk, int opt)
113 struct socket *sock = sk->sk_socket;
115 kernel_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
116 (char *)&opt, sizeof(opt));
118 #endif /* HAVE_TCP_SOCK_SET_QUICKACK */
120 #if !defined(HAVE_TCP_SOCK_SET_NODELAY)
121 static inline void tcp_sock_set_nodelay(struct sock *sk)
124 struct socket *sock = sk->sk_socket;
126 kernel_setsockopt(sock, SOL_TCP, TCP_NODELAY,
127 (char *)&opt, sizeof(opt));
129 #endif /* HAVE_TCP_SOCK_SET_NODELAY */
131 #if !defined(HAVE_TCP_SOCK_SET_KEEPIDLE)
132 static inline int tcp_sock_set_keepidle(struct sock *sk, int opt)
134 struct socket *sock = sk->sk_socket;
136 return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPIDLE,
137 (char *)&opt, sizeof(opt));
139 #endif /* HAVE_TCP_SOCK_SET_KEEPIDLE */
141 #if !defined(HAVE_TCP_SOCK_SET_KEEPINTVL)
142 static inline int tcp_sock_set_keepintvl(struct sock *sk, int opt)
144 struct socket *sock = sk->sk_socket;
146 return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPINTVL,
147 (char *)&opt, sizeof(opt));
149 #endif /* HAVE_TCP_SOCK_SET_KEEPINTVL */
151 #if !defined(HAVE_TCP_SOCK_SET_KEEPCNT)
152 static inline int tcp_sock_set_keepcnt(struct sock *sk, int opt)
154 struct socket *sock = sk->sk_socket;
156 return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPCNT,
157 (char *)&opt, sizeof(opt));
159 #endif /* HAVE_TCP_SOCK_SET_KEEPCNT */
160 #endif /* HAVE_KERNEL_SETSOCKOPT */
162 #endif /* __LIBCFS_LINUX_NET_H__ */