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 <linux/netdevice.h>
27 #include <net/netlink.h>
28 #include <net/genetlink.h>
30 #ifndef HAVE_NETDEV_CMD_TO_NAME
31 static inline const char *netdev_cmd_to_name(unsigned long cmd)
35 return "NETDEV_" __stringify(val);
37 N(UP) N(DOWN) N(REBOOT) N(CHANGE) N(REGISTER) N(UNREGISTER)
38 N(CHANGEMTU) N(CHANGEADDR) N(GOING_DOWN) N(CHANGENAME) N(FEAT_CHANGE)
39 N(BONDING_FAILOVER) N(PRE_UP) N(PRE_TYPE_CHANGE) N(POST_TYPE_CHANGE)
40 N(POST_INIT) N(RELEASE) N(NOTIFY_PEERS) N(JOIN) N(CHANGEUPPER)
41 N(RESEND_IGMP) N(PRECHANGEMTU) N(CHANGEINFODATA) N(BONDING_INFO)
42 N(PRECHANGEUPPER) N(CHANGELOWERSTATE) N(UDP_TUNNEL_PUSH_INFO)
43 N(UDP_TUNNEL_DROP_INFO) N(CHANGE_TX_QUEUE_LEN)
46 return "UNKNOWN_NETDEV_EVENT";
50 /* NL_SET_ERR_MSG macros is already defined in kernels
51 * 3.10.0-1160 and above. For older kernels (3.10.0-957)
52 * where this is not defined we put the message to the
53 * system log as a workaround
55 #ifndef NL_SET_ERR_MSG
56 #define NL_SET_ERR_MSG(unused, msg) do { \
57 static const char __msg[] = msg; \
58 pr_debug("%s\n", __msg); \
62 #ifndef NLM_F_DUMP_FILTERED
63 #define NLM_F_DUMP_FILTERED 0x20 /* Dump was filtered as requested */
66 #ifndef HAVE_NLA_STRDUP
67 char *nla_strdup(const struct nlattr *nla, gfp_t flags);
68 #endif /* !HAVE_NLA_STRDUP */
70 #ifdef HAVE_NLA_STRLCPY
71 #define nla_strscpy nla_strlcpy
72 #endif /* HAVE_NLA_STRLCPY */
74 #ifndef HAVE_NL_PARSE_WITH_EXT_ACK
76 #define NL_SET_BAD_ATTR(extack, attr)
78 /* this can be increased when necessary - don't expose to userland */
79 #define NETLINK_MAX_COOKIE_LEN 20
82 * struct netlink_ext_ack - netlink extended ACK report struct
83 * @_msg: message string to report - don't access directly, use
85 * @bad_attr: attribute with error
86 * @cookie: cookie data to return to userspace (for success)
87 * @cookie_len: actual cookie data length
89 struct netlink_ext_ack {
91 const struct nlattr *bad_attr;
92 u8 cookie[NETLINK_MAX_COOKIE_LEN];
96 #define GENL_SET_ERR_MSG(info, msg) NL_SET_ERR_MSG(NULL, msg)
98 static inline int cfs_nla_parse(struct nlattr **tb, int maxtype,
99 const struct nlattr *head, int len,
100 const struct nla_policy *policy,
101 struct netlink_ext_ack *extack)
103 return nla_parse(tb, maxtype, head, len, policy);
106 static inline int cfs_nla_parse_nested(struct nlattr *tb[], int maxtype,
107 const struct nlattr *nla,
108 const struct nla_policy *policy,
109 struct netlink_ext_ack *extack)
111 return nla_parse_nested(tb, maxtype, nla, policy);
114 #else /* !HAVE_NL_PARSE_WITH_EXT_ACK */
116 #define cfs_nla_parse_nested nla_parse_nested
117 #define cfs_nla_parse nla_parse
121 #ifndef HAVE_GENL_DUMPIT_INFO
122 struct cfs_genl_dumpit_info {
123 const struct genl_family *family;
124 const struct genl_ops *ops;
125 struct nlattr **attrs;
128 static inline const struct cfs_genl_dumpit_info *
129 lnet_genl_dumpit_info(struct netlink_callback *cb)
131 return (const struct cfs_genl_dumpit_info *)cb->args[1];
134 #define cfs_genl_dumpit_info genl_dumpit_info
136 static inline const struct cfs_genl_dumpit_info *
137 lnet_genl_dumpit_info(struct netlink_callback *cb)
139 return (const struct cfs_genl_dumpit_info *)genl_dumpit_info(cb);
141 #endif /* HAVE_GENL_DUMPIT_INFO */
143 #ifdef HAVE_KERNEL_SETSOCKOPT
147 #if !defined(HAVE_TCP_SOCK_SET_QUICKACK)
148 static inline void tcp_sock_set_quickack(struct sock *sk, int opt)
150 struct socket *sock = sk->sk_socket;
152 kernel_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
153 (char *)&opt, sizeof(opt));
155 #endif /* HAVE_TCP_SOCK_SET_QUICKACK */
157 #if !defined(HAVE_TCP_SOCK_SET_NODELAY)
158 static inline void tcp_sock_set_nodelay(struct sock *sk)
161 struct socket *sock = sk->sk_socket;
163 kernel_setsockopt(sock, SOL_TCP, TCP_NODELAY,
164 (char *)&opt, sizeof(opt));
166 #endif /* HAVE_TCP_SOCK_SET_NODELAY */
168 #if !defined(HAVE_TCP_SOCK_SET_KEEPIDLE)
169 static inline int tcp_sock_set_keepidle(struct sock *sk, int opt)
171 struct socket *sock = sk->sk_socket;
173 return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPIDLE,
174 (char *)&opt, sizeof(opt));
176 #endif /* HAVE_TCP_SOCK_SET_KEEPIDLE */
178 #if !defined(HAVE_TCP_SOCK_SET_KEEPINTVL)
179 static inline int tcp_sock_set_keepintvl(struct sock *sk, int opt)
181 struct socket *sock = sk->sk_socket;
183 return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPINTVL,
184 (char *)&opt, sizeof(opt));
186 #endif /* HAVE_TCP_SOCK_SET_KEEPINTVL */
188 #if !defined(HAVE_TCP_SOCK_SET_KEEPCNT)
189 static inline int tcp_sock_set_keepcnt(struct sock *sk, int opt)
191 struct socket *sock = sk->sk_socket;
193 return kernel_setsockopt(sock, SOL_TCP, TCP_KEEPCNT,
194 (char *)&opt, sizeof(opt));
196 #endif /* HAVE_TCP_SOCK_SET_KEEPCNT */
198 #if !defined(HAVE_IP6_SET_PREF)
199 static inline void ip6_sock_set_addr_preferences(struct sock *sk,
202 kernel_setsockopt(sk->sk_socket, SOL_IPV6, IPV6_ADDR_PREFERENCES,
203 (char *)&pref, sizeof(pref));
205 #endif /* HAVE_IP6_SET_PREF */
207 #if !defined(HAVE_IP_SET_TOS)
208 static inline void ip_sock_set_tos(struct sock *sk, int val)
210 kernel_setsockopt(sk->sk_socket, IPPROTO_IP, IP_TOS,
211 (char *)&val, sizeof(val));
213 #endif /* HAVE_IP_SET_TOS */
214 #endif /* HAVE_KERNEL_SETSOCKOPT */
216 #endif /* __LIBCFS_LINUX_NET_H__ */