]> git.proxmox.com Git - ovs.git/blob - datapath/linux/compat/include/net/genetlink.h
compat: Fix RHEL7 build.
[ovs.git] / datapath / linux / compat / include / net / genetlink.h
1 #ifndef __NET_GENERIC_NETLINK_WRAPPER_H
2 #define __NET_GENERIC_NETLINK_WRAPPER_H 1
3
4 #include <linux/version.h>
5 #include <linux/netlink.h>
6 #include <net/net_namespace.h>
7 #include_next <net/genetlink.h>
8
9 /*
10 * 15e473046cb6e5d18a4d0057e61d76315230382b renames pid to portid
11 * the affected structures are
12 * netlink_skb_parms::pid -> portid
13 * genl_info::snd_pid -> snd_portid
14 */
15 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0)
16 #define snd_portid snd_pid
17 #define portid pid
18 #endif
19
20 #ifndef HAVE_GENL_NOTIFY_TAKES_FAMILY
21 struct rpl_genl_family {
22 struct genl_family compat_family;
23 unsigned int id;
24 unsigned int hdrsize;
25 char name[GENL_NAMSIZ];
26 unsigned int version;
27 unsigned int maxattr;
28 bool netnsok;
29 bool parallel_ops;
30 int (*pre_doit)(const struct genl_ops *ops,
31 struct sk_buff *skb,
32 struct genl_info *info);
33 void (*post_doit)(const struct genl_ops *ops,
34 struct sk_buff *skb,
35 struct genl_info *info);
36 struct nlattr ** attrbuf; /* private */
37 const struct genl_ops * ops; /* private */
38 const struct genl_multicast_group *mcgrps; /* private */
39 unsigned int n_ops; /* private */
40 unsigned int n_mcgrps; /* private */
41 unsigned int mcgrp_offset; /* private */
42 struct list_head family_list; /* private */
43 struct module *module;
44 };
45
46 #define genl_family rpl_genl_family
47 #define genl_notify rpl_genl_notify
48 void genl_notify(struct genl_family *family,
49 struct sk_buff *skb, struct net *net, u32 portid, u32 group,
50 struct nlmsghdr *nlh, gfp_t flags);
51
52 static inline void *rpl_genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq,
53 struct genl_family *family, int flags, u8 cmd)
54 {
55 return genlmsg_put(skb, portid, seq, &family->compat_family, flags, cmd);
56 }
57
58 #define genlmsg_put rpl_genlmsg_put
59
60 static inline int rpl_genl_unregister_family(struct genl_family *family)
61 {
62 return genl_unregister_family(&family->compat_family);
63 }
64 #define genl_unregister_family rpl_genl_unregister_family
65
66 #define genl_set_err rpl_genl_set_err
67 static inline int genl_set_err(struct genl_family *family, struct net *net,
68 u32 portid, u32 group, int code)
69 {
70 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
71 netlink_set_err(net->genl_sock, portid, group, code);
72 return 0;
73 #else
74 return netlink_set_err(net->genl_sock, portid, group, code);
75 #endif
76 }
77
78 #define genlmsg_multicast_netns rpl_genlmsg_multicast_netns
79 static inline int genlmsg_multicast_netns(struct genl_family *family,
80 struct net *net, struct sk_buff *skb,
81 u32 portid, unsigned int group, gfp_t flags)
82 {
83 return nlmsg_multicast(net->genl_sock, skb, portid, group, flags);
84 }
85
86
87 #define __genl_register_family rpl___genl_register_family
88 int rpl___genl_register_family(struct genl_family *family);
89
90 #define genl_register_family rpl_genl_register_family
91 static inline int rpl_genl_register_family(struct genl_family *family)
92 {
93 family->module = THIS_MODULE;
94 return rpl___genl_register_family(family);
95 }
96
97 #endif
98
99 #ifndef HAVE_GENLMSG_NEW_UNICAST
100 static inline struct sk_buff *genlmsg_new_unicast(size_t payload,
101 struct genl_info *info,
102 gfp_t flags)
103 {
104 return genlmsg_new(payload, flags);
105 }
106 #endif
107
108 #ifndef HAVE_GENL_HAS_LISTENERS
109 static inline int genl_has_listeners(struct genl_family *family,
110 struct net *net, unsigned int group)
111 {
112 #ifdef HAVE_MCGRP_OFFSET
113 if (WARN_ON_ONCE(group >= family->n_mcgrps))
114 return -EINVAL;
115 group = family->mcgrp_offset + group;
116 #endif
117 return netlink_has_listeners(net->genl_sock, group);
118 }
119 #else
120
121 #ifndef HAVE_GENL_HAS_LISTENERS_TAKES_NET
122 static inline int rpl_genl_has_listeners(struct genl_family *family,
123 struct net *net, unsigned int group)
124 {
125 #ifdef HAVE_GENL_NOTIFY_TAKES_FAMILY
126 return genl_has_listeners(family, net->genl_sock, group);
127 #else
128 return genl_has_listeners(&family->compat_family, net->genl_sock, group);
129 #endif
130 }
131
132 #define genl_has_listeners rpl_genl_has_listeners
133 #endif
134
135 #endif /* HAVE_GENL_HAS_LISTENERS */
136
137 #ifndef HAVE_GENLMSG_PARSE
138 static inline int genlmsg_parse(const struct nlmsghdr *nlh,
139 const struct genl_family *family,
140 struct nlattr *tb[], int maxtype,
141 const struct nla_policy *policy)
142 {
143 return nlmsg_parse(nlh, family->hdrsize + GENL_HDRLEN, tb, maxtype,
144 policy);
145 }
146 #endif
147
148 #endif /* genetlink.h */