9aea997778ed62a088f780e5682b81b300029b8e
[cascardo/ovs.git] / datapath / linux / compat / genetlink-openvswitch.c
1 #include <net/genetlink.h>
2 #include <linux/version.h>
3
4 #ifndef HAVE_GENL_NOTIFY_TAKES_FAMILY
5
6 #undef genl_notify
7
8 void rpl_genl_notify(struct rpl_genl_family *family, struct sk_buff *skb,
9                      struct net *net, u32 portid, u32 group,
10                      struct nlmsghdr *nlh, gfp_t flags)
11 {
12 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0)
13         struct sock *sk = net->genl_sock;
14         int report = 0;
15
16         if (nlh)
17                 report = nlmsg_report(nlh);
18
19         nlmsg_notify(sk, skb, portid, group, report, flags);
20 #else
21         genl_notify(skb, net, portid, group, nlh, flags);
22 #endif
23 }
24 EXPORT_SYMBOL_GPL(rpl_genl_notify);
25
26 int rpl___genl_register_family(struct rpl_genl_family *f)
27 {
28         int err;
29
30         f->compat_family.id = f->id;
31         f->compat_family.hdrsize = f->hdrsize;
32         strncpy(f->compat_family.name, f->name, GENL_NAMSIZ);
33         f->compat_family.version = f->version;
34         f->compat_family.maxattr = f->maxattr;
35         f->compat_family.netnsok = f->netnsok;
36 #ifdef HAVE_PARALLEL_OPS
37         f->compat_family.parallel_ops = f->parallel_ops;
38 #endif
39         err = genl_register_family_with_ops(&f->compat_family,
40                                             (struct genl_ops *) f->ops, f->n_ops);
41         if (err)
42                 goto error;
43
44         if (f->mcgrps) {
45                 /* Need to Fix GROUP_ID() for more than one group. */
46                 BUG_ON(f->n_mcgrps > 1);
47                 err = genl_register_mc_group(&f->compat_family,
48                                              (struct genl_multicast_group *) f->mcgrps);
49                 if (err)
50                         goto error;
51         }
52 error:
53         return err;
54
55 }
56 EXPORT_SYMBOL_GPL(rpl___genl_register_family);
57
58 #endif /* kernel version < 3.13.0 */