]> git.proxmox.com Git - ovs.git/blob - datapath/linux/compat/include/net/genetlink.h
b05eae5fa342130c197cf6053ab7d6169ea246db
[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 static inline void *rpl_genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq,
48 struct genl_family *family, int flags, u8 cmd)
49 {
50 return genlmsg_put(skb, portid, seq, &family->compat_family, flags, cmd);
51 }
52
53 #define genlmsg_put rpl_genlmsg_put
54
55 static inline int rpl_genl_unregister_family(struct genl_family *family)
56 {
57 return genl_unregister_family(&family->compat_family);
58 }
59 #define genl_unregister_family rpl_genl_unregister_family
60
61 #define genl_set_err rpl_genl_set_err
62 static inline int genl_set_err(struct genl_family *family, struct net *net,
63 u32 portid, u32 group, int code)
64 {
65 #ifdef HAVE_VOID_NETLINK_SET_ERR
66 netlink_set_err(net->genl_sock, portid, group, code);
67 return 0;
68 #else
69 return netlink_set_err(net->genl_sock, portid, group, code);
70 #endif
71 }
72
73 #define genlmsg_multicast_netns rpl_genlmsg_multicast_netns
74 static inline int genlmsg_multicast_netns(struct genl_family *family,
75 struct net *net, struct sk_buff *skb,
76 u32 portid, unsigned int group, gfp_t flags)
77 {
78 return nlmsg_multicast(net->genl_sock, skb, portid, group, flags);
79 }
80
81
82 #define __genl_register_family rpl___genl_register_family
83 int rpl___genl_register_family(struct genl_family *family);
84
85 #define genl_register_family rpl_genl_register_family
86 static inline int rpl_genl_register_family(struct genl_family *family)
87 {
88 family->module = THIS_MODULE;
89 return rpl___genl_register_family(family);
90 }
91 #endif
92
93 #ifdef HAVE_GENL_NOTIFY_TAKES_NET
94 #define genl_notify rpl_genl_notify
95 void rpl_genl_notify(struct genl_family *family, struct sk_buff *skb,
96 struct genl_info *info , u32 group, gfp_t flags);
97 #endif
98
99 #ifndef HAVE_GENL_HAS_LISTENERS
100 static inline int genl_has_listeners(struct genl_family *family,
101 struct net *net, unsigned int group)
102 {
103 #ifdef HAVE_MCGRP_OFFSET
104 if (WARN_ON_ONCE(group >= family->n_mcgrps))
105 return -EINVAL;
106 group = family->mcgrp_offset + group;
107 #endif
108 return netlink_has_listeners(net->genl_sock, group);
109 }
110 #else
111
112 #ifndef HAVE_GENL_HAS_LISTENERS_TAKES_NET
113 static inline int rpl_genl_has_listeners(struct genl_family *family,
114 struct net *net, unsigned int group)
115 {
116 #ifdef HAVE_GENL_NOTIFY_TAKES_FAMILY
117 return genl_has_listeners(family, net->genl_sock, group);
118 #else
119 return genl_has_listeners(&family->compat_family, net->genl_sock, group);
120 #endif
121 }
122
123 #define genl_has_listeners rpl_genl_has_listeners
124 #endif
125
126 #endif /* HAVE_GENL_HAS_LISTENERS */
127
128 #ifndef HAVE_NETLINK_EXT_ACK
129 struct netlink_ext_ack;
130
131 static inline int rpl_genlmsg_parse(const struct nlmsghdr *nlh,
132 const struct genl_family *family,
133 struct nlattr *tb[], int maxtype,
134 const struct nla_policy *policy,
135 struct netlink_ext_ack *extack)
136 {
137 #ifdef HAVE_GENLMSG_PARSE
138 return genlmsg_parse(nlh, family, tb, maxtype, policy);
139 #else
140 return nlmsg_parse(nlh, family->hdrsize + GENL_HDRLEN, tb, maxtype,
141 policy);
142 #endif
143 }
144 #define genlmsg_parse rpl_genlmsg_parse
145 #endif
146
147 #endif /* genetlink.h */