b655d243621bc8de25df273c4681c5b28c557621
1 #ifndef __BACKPORT_NET_GENETLINK_H
2 #define __BACKPORT_NET_GENETLINK_H
3 #include_next <net/genetlink.h>
4 #include <linux/version.h>
6 #if LINUX_VERSION_IS_LESS(4,12,0)
7 #define GENL_SET_ERR_MSG(info, msg) do { } while (0)
9 static inline int genl_err_attr(struct genl_info
*info
, int err
,
12 #if LINUX_VERSION_IS_GEQ(4,12,0)
13 info
->extack
->bad_attr
= attr
;
20 /* this is for patches we apply */
21 static inline struct netlink_ext_ack
*genl_info_extack(struct genl_info
*info
)
23 #if LINUX_VERSION_IS_GEQ(4,12,0)
30 /* this is for patches we apply */
31 #if LINUX_VERSION_IS_LESS(3,7,0)
32 #define genl_info_snd_portid(__genl_info) (__genl_info->snd_pid)
34 #define genl_info_snd_portid(__genl_info) (__genl_info->snd_portid)
37 #ifndef GENLMSG_DEFAULT_SIZE
38 #define GENLMSG_DEFAULT_SIZE (NLMSG_DEFAULT_SIZE - GENL_HDRLEN)
41 #if LINUX_VERSION_IS_LESS(3,1,0)
42 #define genl_dump_check_consistent(cb, user_hdr, family)
45 #if LINUX_VERSION_IS_LESS(3,13,0) && RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(7,0)
46 static inline int __real_genl_register_family(struct genl_family
*family
)
48 return genl_register_family(family
);
51 /* Needed for the mcgrps pointer */
52 struct backport_genl_family
{
53 struct genl_family family
;
55 unsigned int id
, hdrsize
, version
, maxattr
;
56 char name
[GENL_NAMSIZ
];
60 struct nlattr
**attrbuf
;
62 int (*pre_doit
)(struct genl_ops
*ops
, struct sk_buff
*skb
,
63 struct genl_info
*info
);
65 void (*post_doit
)(struct genl_ops
*ops
, struct sk_buff
*skb
,
66 struct genl_info
*info
);
68 struct genl_multicast_group
*mcgrps
;
70 unsigned int n_mcgrps
, n_ops
;
72 struct module
*module
;
74 #define genl_family LINUX_BACKPORT(genl_family)
76 int __backport_genl_register_family(struct genl_family
*family
);
78 #define genl_register_family LINUX_BACKPORT(genl_register_family)
80 genl_register_family(struct genl_family
*family
)
82 family
->module
= THIS_MODULE
;
83 return __backport_genl_register_family(family
);
86 #define _genl_register_family_with_ops_grps \
87 _backport_genl_register_family_with_ops_grps
89 _genl_register_family_with_ops_grps(struct genl_family
*family
,
90 struct genl_ops
*ops
, size_t n_ops
,
91 struct genl_multicast_group
*mcgrps
,
95 family
->n_ops
= n_ops
;
96 family
->mcgrps
= mcgrps
;
97 family
->n_mcgrps
= n_mcgrps
;
98 return genl_register_family(family
);
101 #define genl_register_family_with_ops(family, ops) \
102 _genl_register_family_with_ops_grps((family), \
103 (ops), ARRAY_SIZE(ops), \
105 #define genl_register_family_with_ops_groups(family, ops, grps) \
106 _genl_register_family_with_ops_grps((family), \
107 (ops), ARRAY_SIZE(ops), \
108 (grps), ARRAY_SIZE(grps))
110 #define genl_unregister_family backport_genl_unregister_family
111 int genl_unregister_family(struct genl_family
*family
);
113 #if LINUX_VERSION_IS_LESS(3,3,0)
114 extern void genl_notify(struct sk_buff
*skb
, struct net
*net
, u32 pid
,
115 u32 group
, struct nlmsghdr
*nlh
, gfp_t flags
);
117 #define genl_notify(_fam, _skb, _info, _group, _flags) \
118 genl_notify(_skb, genl_info_net(_info), \
119 genl_info_snd_portid(_info), \
120 (_fam)->mcgrps[_group].id, _info->nlhdr, _flags)
121 #define genlmsg_put(_skb, _pid, _seq, _fam, _flags, _cmd) \
122 genlmsg_put(_skb, _pid, _seq, &(_fam)->family, _flags, _cmd)
123 #define genlmsg_nlhdr(_hdr, _fam) \
124 genlmsg_nlhdr(_hdr, &(_fam)->family)
125 #ifndef genl_dump_check_consistent
126 #define genl_dump_check_consistent(_cb, _hdr, _fam) \
127 genl_dump_check_consistent(_cb, _hdr, &(_fam)->family)
129 #ifndef genlmsg_put_reply /* might already be there from _info override above */
130 #define genlmsg_put_reply(_skb, _info, _fam, _flags, _cmd) \
131 genlmsg_put_reply(_skb, _info, &(_fam)->family, _flags, _cmd)
133 #define genlmsg_multicast_netns LINUX_BACKPORT(genlmsg_multicast_netns)
134 static inline int genlmsg_multicast_netns(struct genl_family
*family
,
135 struct net
*net
, struct sk_buff
*skb
,
136 u32 portid
, unsigned int group
,
139 if (WARN_ON_ONCE(group
>= family
->n_mcgrps
))
141 group
= family
->mcgrps
[group
].id
;
142 return nlmsg_multicast(
144 skb
, portid
, group
, flags
);
146 #define genlmsg_multicast LINUX_BACKPORT(genlmsg_multicast)
147 static inline int genlmsg_multicast(struct genl_family
*family
,
148 struct sk_buff
*skb
, u32 portid
,
149 unsigned int group
, gfp_t flags
)
151 if (WARN_ON_ONCE(group
>= family
->n_mcgrps
))
153 group
= family
->mcgrps
[group
].id
;
154 return nlmsg_multicast(
156 skb
, portid
, group
, flags
);
159 backport_genlmsg_multicast_allns(struct genl_family
*family
,
160 struct sk_buff
*skb
, u32 portid
,
161 unsigned int group
, gfp_t flags
)
163 if (WARN_ON_ONCE(group
>= family
->n_mcgrps
))
165 group
= family
->mcgrps
[group
].id
;
166 return genlmsg_multicast_allns(skb
, portid
, group
, flags
);
168 #define genlmsg_multicast_allns LINUX_BACKPORT(genlmsg_multicast_allns)
172 #define __genl_const const
173 #if LINUX_VERSION_IS_LESS(4,4,0)
174 #define genl_notify(_fam, _skb, _info, _group, _flags) \
175 genl_notify(_fam, _skb, genl_info_net(_info), \
176 genl_info_snd_portid(_info), \
177 _group, _info->nlhdr, _flags)
181 #if LINUX_VERSION_IS_LESS(4,10,0)
183 * genl_family_attrbuf - return family's attrbuf
184 * @family: the family
186 * Return the family's attrbuf, while validating that it's
187 * actually valid to access it.
189 * You cannot use this function with a family that has parallel_ops
190 * and you can only use it within (pre/post) doit/dumpit callbacks.
192 #define genl_family_attrbuf LINUX_BACKPORT(genl_family_attrbuf)
193 static inline struct nlattr
**genl_family_attrbuf(struct genl_family
*family
)
195 WARN_ON(family
->parallel_ops
);
197 return family
->attrbuf
;
200 #define __genl_ro_after_init
202 #define __genl_ro_after_init __ro_after_init
205 #endif /* __BACKPORT_NET_GENETLINK_H */