diff options
author | Johannes Berg <johannes.berg@intel.com> | 2018-10-02 17:25:18 +0200 |
---|---|---|
committer | Johannes Berg <johannes.berg@intel.com> | 2018-10-02 21:31:58 +0200 |
commit | ff6746638cf14d7b812ccb6bdfd4b91e6e9c5c79 (patch) | |
tree | 14e8e7918d928f8c234ae467fa50db9a53b3048a /backport/backport-include | |
parent | bb1b944b60c02ac7551bab4579f38007ba146125 (diff) |
backports: genetlink: update completely
Replace all the different nested versions of generic netlink
backport with a single one, covering from < 3.13 all the way
to the upcoming netlink policy improvements in 4.20.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Diffstat (limited to 'backport/backport-include')
-rw-r--r-- | backport/backport-include/linux/netlink.h | 2 | ||||
-rw-r--r-- | backport/backport-include/net/genetlink.h | 238 |
2 files changed, 82 insertions, 158 deletions
diff --git a/backport/backport-include/linux/netlink.h b/backport/backport-include/linux/netlink.h index 366c9e27..f956a769 100644 --- a/backport/backport-include/linux/netlink.h +++ b/backport/backport-include/linux/netlink.h @@ -20,7 +20,7 @@ struct netlink_ext_ack { u8 cookie_len; /* backport only field */ - void *__bp_genl_real_ops; + void *__bp_doit; }; #define NL_SET_ERR_MSG(extack, msg) do { \ diff --git a/backport/backport-include/net/genetlink.h b/backport/backport-include/net/genetlink.h index d80d979a..84011e72 100644 --- a/backport/backport-include/net/genetlink.h +++ b/backport/backport-include/net/genetlink.h @@ -15,18 +15,14 @@ static inline void *__bp_genl_info_userhdr(struct genl_info *info) } #if LINUX_VERSION_IS_LESS(4,12,0) -#define GENL_SET_ERR_MSG(info, msg) do { } while (0) +#define GENL_SET_ERR_MSG(info, msg) NL_SET_ERR_MSG(genl_info_extack(info), msg) static inline int genl_err_attr(struct genl_info *info, int err, struct nlattr *attr) { -#if LINUX_VERSION_IS_GEQ(4,12,0) - info->extack->bad_attr = attr; -#endif - return err; } -#endif +#endif /* < 4.12 */ /* this is for patches we apply */ static inline struct netlink_ext_ack *genl_info_extack(struct genl_info *info) @@ -51,12 +47,24 @@ static inline void *genl_info_userhdr(struct genl_info *info) #define genl_info_snd_portid(__genl_info) (__genl_info->snd_portid) #endif +#if LINUX_VERSION_IS_LESS(3,13,0) +#define __genl_const +#else /* < 3.13 */ +#define __genl_const const +#endif /* < 3.13 */ + #ifndef GENLMSG_DEFAULT_SIZE #define GENLMSG_DEFAULT_SIZE (NLMSG_DEFAULT_SIZE - GENL_HDRLEN) #endif #if LINUX_VERSION_IS_LESS(3,1,0) -#define genl_dump_check_consistent(cb, user_hdr) +#define genl_dump_check_consistent(cb, user_hdr) do { } while (0) +#endif + +#if LINUX_VERSION_IS_LESS(4,10,0) +#define __genl_ro_after_init +#else +#define __genl_ro_after_init __ro_after_init #endif #if LINUX_VERSION_IS_LESS(4,15,0) @@ -83,148 +91,87 @@ void backport_genl_dump_check_consistent(struct netlink_callback *cb, #endif #endif /* LINUX_VERSION_IS_LESS(4,15,0) */ -#if LINUX_VERSION_IS_LESS(3,13,0) && RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(7,0) -static inline int __real_genl_register_family(struct genl_family *family) +#if LINUX_VERSION_IS_LESS(4,20,0) +static inline int +__real_backport_genl_register_family(struct genl_family *family) { return genl_register_family(family); } - -/* Needed for the mcgrps pointer */ -struct backport_genl_family { - struct genl_family family; - - unsigned int id, hdrsize, version, maxattr; - char name[GENL_NAMSIZ]; - bool netnsok; - bool parallel_ops; - - struct nlattr **attrbuf; - - int (*pre_doit)(struct genl_ops *ops, struct sk_buff *skb, - struct genl_info *info); - - void (*post_doit)(struct genl_ops *ops, struct sk_buff *skb, - struct genl_info *info); - - struct genl_multicast_group *mcgrps; - struct genl_ops *ops; - unsigned int n_mcgrps, n_ops; - - struct module *module; -}; -#define genl_family LINUX_BACKPORT(genl_family) - -int __backport_genl_register_family(struct genl_family *family); - -#define genl_register_family LINUX_BACKPORT(genl_register_family) static inline int -genl_register_family(struct genl_family *family) +__real_backport_genl_unregister_family(struct genl_family *family) { - family->module = THIS_MODULE; - return __backport_genl_register_family(family); + return genl_unregister_family(family); } -#define _genl_register_family_with_ops_grps \ - _backport_genl_register_family_with_ops_grps -static inline int -_genl_register_family_with_ops_grps(struct genl_family *family, - struct genl_ops *ops, size_t n_ops, - struct genl_multicast_group *mcgrps, - size_t n_mcgrps) -{ - family->ops = ops; - family->n_ops = n_ops; - family->mcgrps = mcgrps; - family->n_mcgrps = n_mcgrps; - return genl_register_family(family); -} +struct backport_genl_family { + struct genl_family family; + const struct genl_ops * copy_ops; + + /* copied */ + int id; /* private */ + unsigned int hdrsize; + char name[GENL_NAMSIZ]; + unsigned int version; + unsigned int maxattr; + bool netnsok; + bool parallel_ops; + int (*pre_doit)(__genl_const struct genl_ops *ops, + struct sk_buff *skb, + struct genl_info *info); + void (*post_doit)(__genl_const struct genl_ops *ops, + struct sk_buff *skb, + struct genl_info *info); +/* + * unsupported! + int (*mcast_bind)(struct net *net, int group); + void (*mcast_unbind)(struct net *net, int group); + */ + struct nlattr ** attrbuf; /* private */ + __genl_const struct genl_ops * ops; + __genl_const struct genl_multicast_group *mcgrps; + unsigned int n_ops; + unsigned int n_mcgrps; + struct module *module; +}; +#undef genl_family +#define genl_family backport_genl_family -#define genl_register_family_with_ops(family, ops) \ - _genl_register_family_with_ops_grps((family), \ - (ops), ARRAY_SIZE(ops), \ - NULL, 0) -#define genl_register_family_with_ops_groups(family, ops, grps) \ - _genl_register_family_with_ops_grps((family), \ - (ops), ARRAY_SIZE(ops), \ - (grps), ARRAY_SIZE(grps)) +#define genl_register_family backport_genl_register_family +int genl_register_family(struct genl_family *family); #define genl_unregister_family backport_genl_unregister_family -int genl_unregister_family(struct genl_family *family); +int backport_genl_unregister_family(struct genl_family *family); -#if LINUX_VERSION_IS_LESS(3,3,0) -extern void genl_notify(struct sk_buff *skb, struct net *net, u32 pid, - u32 group, struct nlmsghdr *nlh, gfp_t flags); -#endif -#define genl_notify(_fam, _skb, _info, _group, _flags) \ - genl_notify(_skb, genl_info_net(_info), \ - genl_info_snd_portid(_info), \ - (_fam)->mcgrps[_group].id, _info->nlhdr, _flags) -#define genlmsg_put(_skb, _pid, _seq, _fam, _flags, _cmd) \ - genlmsg_put(_skb, _pid, _seq, &(_fam)->family, _flags, _cmd) +#define genl_notify LINUX_BACKPORT(genl_notify) +void genl_notify(const struct genl_family *family, struct sk_buff *skb, + struct genl_info *info, u32 group, gfp_t flags); + +#define genlmsg_put LINUX_BACKPORT(genlmsg_put) +void *genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq, + const struct genl_family *family, int flags, u8 cmd); + +#define genlmsg_put_reply LINUX_BACKPORT(genlmsg_put_reply) +void *genlmsg_put_reply(struct sk_buff *skb, + struct genl_info *info, + const struct genl_family *family, + int flags, u8 cmd); -#ifndef genlmsg_put_reply /* might already be there from _info override above */ -#define genlmsg_put_reply(_skb, _info, _fam, _flags, _cmd) \ - genlmsg_put_reply(_skb, _info, &(_fam)->family, _flags, _cmd) -#endif #define genlmsg_multicast_netns LINUX_BACKPORT(genlmsg_multicast_netns) -static inline int genlmsg_multicast_netns(struct genl_family *family, - struct net *net, struct sk_buff *skb, - u32 portid, unsigned int group, - gfp_t flags) -{ - if (WARN_ON_ONCE(group >= family->n_mcgrps)) - return -EINVAL; - group = family->mcgrps[group].id; - return nlmsg_multicast( - net->genl_sock, - skb, portid, group, flags); -} +int genlmsg_multicast_netns(const struct genl_family *family, + struct net *net, struct sk_buff *skb, + u32 portid, unsigned int group, + gfp_t flags); + #define genlmsg_multicast LINUX_BACKPORT(genlmsg_multicast) -static inline int genlmsg_multicast(struct genl_family *family, - struct sk_buff *skb, u32 portid, - unsigned int group, gfp_t flags) -{ - if (WARN_ON_ONCE(group >= family->n_mcgrps)) - return -EINVAL; - group = family->mcgrps[group].id; - return nlmsg_multicast( - init_net.genl_sock, - skb, portid, group, flags); -} -static inline int -backport_genlmsg_multicast_allns(struct genl_family *family, - struct sk_buff *skb, u32 portid, - unsigned int group, gfp_t flags) -{ - if (WARN_ON_ONCE(group >= family->n_mcgrps)) - return -EINVAL; - group = family->mcgrps[group].id; - return genlmsg_multicast_allns(skb, portid, group, flags); -} -#define genlmsg_multicast_allns LINUX_BACKPORT(genlmsg_multicast_allns) +int genlmsg_multicast(const struct genl_family *family, + struct sk_buff *skb, u32 portid, + unsigned int group, gfp_t flags); -#define __genl_const -#else /* < 3.13 */ -#define __genl_const const -#if LINUX_VERSION_IS_LESS(4,4,0) -#define genl_notify(_fam, _skb, _info, _group, _flags) \ - genl_notify(_fam, _skb, genl_info_net(_info), \ - genl_info_snd_portid(_info), \ - _group, _info->nlhdr, _flags) -#endif /* < 4.4 */ -#endif /* < 3.13 */ +#define genlmsg_multicast_allns LINUX_BACKPORT(genlmsg_multicast_allns) +int backport_genlmsg_multicast_allns(const struct genl_family *family, + struct sk_buff *skb, u32 portid, + unsigned int group, gfp_t flags); -#if LINUX_VERSION_IS_LESS(4,10,0) -/** - * genl_family_attrbuf - return family's attrbuf - * @family: the family - * - * Return the family's attrbuf, while validating that it's - * actually valid to access it. - * - * You cannot use this function with a family that has parallel_ops - * and you can only use it within (pre/post) doit/dumpit callbacks. - */ #define genl_family_attrbuf LINUX_BACKPORT(genl_family_attrbuf) static inline struct nlattr **genl_family_attrbuf(struct genl_family *family) { @@ -232,29 +179,6 @@ static inline struct nlattr **genl_family_attrbuf(struct genl_family *family) return family->attrbuf; } - -#define __genl_ro_after_init -#else -#define __genl_ro_after_init __ro_after_init -#endif - -#if LINUX_VERSION_IS_LESS(4,12,0) -static inline int -__real_bp_extack_genl_register_family(struct genl_family *family) -{ - return genl_register_family(family); -} -static inline int -__real_bp_extack_genl_unregister_family(struct genl_family *family) -{ - return genl_unregister_family(family); -} -int bp_extack_genl_register_family(struct genl_family *family); -int bp_extack_genl_unregister_family(struct genl_family *family); -#undef genl_register_family -#define genl_register_family bp_extack_genl_register_family -#undef genl_unregister_family -#define genl_unregister_family bp_extack_genl_unregister_family -#endif +#endif /* LINUX_VERSION_IS_LESS(4,20,0) */ #endif /* __BACKPORT_NET_GENETLINK_H */ |