#include <net/genetlink.h>
#include <linux/version.h>
-#define GENL_FIRST_MCGROUP 16
-#define GENL_LAST_MCGROUP 31
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,13,0)
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
-#include <linux/mutex.h>
-#include <linux/openvswitch.h>
+#undef genl_notify
-#include "openvswitch/datapath-compat.h"
-
-static DEFINE_MUTEX(mc_group_mutex);
-
-int genl_register_mc_group(struct genl_family *family,
- struct genl_multicast_group *grp)
+void rpl_genl_notify(struct rpl_genl_family *family, struct sk_buff *skb,
+ struct net *net, u32 portid, u32 group,
+ struct nlmsghdr *nlh, gfp_t flags)
{
- static int next_group = GENL_FIRST_MCGROUP;
-
- grp->family = family;
-
- if (!strcmp(grp->name, OVS_VPORT_MCGROUP)) {
- grp->id = OVS_VPORT_MCGROUP_FALLBACK_ID;
- return 0;
- }
-
- mutex_lock(&mc_group_mutex);
- grp->id = next_group;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0)
+ struct sock *sk = net->genl_sock;
+ int report = 0;
- if (++next_group > GENL_LAST_MCGROUP)
- next_group = GENL_FIRST_MCGROUP;
- mutex_unlock(&mc_group_mutex);
+ if (nlh)
+ report = nlmsg_report(nlh);
- return 0;
+ nlmsg_notify(sk, skb, portid, group, report, flags);
+#else
+ genl_notify(skb, net, portid, group, nlh, flags);
+#endif
}
-#endif /* kernel < 2.6.23 */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)
-/**
- * genl_register_family_with_ops - register a generic netlink family
- * @family: generic netlink family
- * @ops: operations to be registered
- * @n_ops: number of elements to register
- *
- * Registers the specified family and operations from the specified table.
- * Only one family may be registered with the same family name or identifier.
- *
- * The family id may equal GENL_ID_GENERATE causing an unique id to
- * be automatically generated and assigned.
- *
- * Either a doit or dumpit callback must be specified for every registered
- * operation or the function will fail. Only one operation structure per
- * command identifier may be registered.
- *
- * See include/net/genetlink.h for more documenation on the operations
- * structure.
- *
- * This is equivalent to calling genl_register_family() followed by
- * genl_register_ops() for every operation entry in the table taking
- * care to unregister the family on error path.
- *
- * Return 0 on success or a negative error code.
- */
-int genl_register_family_with_ops(struct genl_family *family,
- struct genl_ops *ops, size_t n_ops)
+int rpl___genl_register_family(struct rpl_genl_family *f)
{
- int err, i;
-
- err = genl_register_family(family);
+ int err;
+
+ f->compat_family.id = f->id;
+ f->compat_family.hdrsize = f->hdrsize;
+ strncpy(f->compat_family.name, f->name, GENL_NAMSIZ);
+ f->compat_family.version = f->version;
+ f->compat_family.maxattr = f->maxattr;
+ f->compat_family.netnsok = f->netnsok;
+#ifdef HAVE_PARALLEL_OPS
+ f->compat_family.parallel_ops = f->parallel_ops;
+#endif
+ err = genl_register_family_with_ops(&f->compat_family,
+ (struct genl_ops *) f->ops, f->n_ops);
if (err)
- return err;
+ goto error;
- for (i = 0; i < n_ops; ++i, ++ops) {
- err = genl_register_ops(family, ops);
+ if (f->mcgrps) {
+ /* Need to Fix GROUP_ID() for more than one group. */
+ BUG_ON(f->n_mcgrps > 1);
+ err = genl_register_mc_group(&f->compat_family,
+ (struct genl_multicast_group *) f->mcgrps);
if (err)
- goto err_out;
- }
- return 0;
-err_out:
- genl_unregister_family(family);
- return err;
-}
-#endif
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-/**
- * nlmsg_notify - send a notification netlink message
- * @sk: netlink socket to use
- * @skb: notification message
- * @portid: destination netlink portid for reports or 0
- * @group: destination multicast group or 0
- * @report: 1 to report back, 0 to disable
- * @flags: allocation flags
- */
-int nlmsg_notify(struct sock *sk, struct sk_buff *skb, u32 portid,
- unsigned int group, int report, gfp_t flags)
-{
- int err = 0;
-
- if (group) {
- int exclude_portid = 0;
-
- if (report) {
- atomic_inc(&skb->users);
- exclude_portid = portid;
- }
-
- /* errors reported via destination sk->sk_err, but propagate
- * delivery errors if NETLINK_BROADCAST_ERROR flag is set */
- err = nlmsg_multicast(sk, skb, exclude_portid, group, flags);
- }
-
- if (report) {
- int err2;
-
- err2 = nlmsg_unicast(sk, skb, portid);
- if (!err || err == -ESRCH)
- err = err2;
+ goto error;
}
-
+error:
return err;
-}
-#endif
-
-/* This is analogous to rtnl_notify() but uses genl_sock instead of rtnl.
- *
- * This is not (yet) in any upstream kernel. */
-void genl_notify(struct sk_buff *skb, struct net *net, u32 portid, u32 group,
- struct nlmsghdr *nlh, gfp_t flags)
-{
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)
- struct sock *sk = net->genl_sock;
-#else
- struct sock *sk = genl_sock;
-#endif
- int report = 0;
-
- if (nlh)
- report = nlmsg_report(nlh);
- nlmsg_notify(sk, skb, portid, group, report, flags);
}
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
-/* This function wasn't exported before 2.6.30. Lose! */
-void netlink_set_err(struct sock *ssk, u32 portid, u32 group, int code)
-{
-}
-#endif
+#endif /* kernel version < 3.13.0 */