datapath: Add support for kernels 3.13
[sliver-openvswitch.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 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,13,0)
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 #define genl_notify rpl_genl_notify
48 void genl_notify(struct genl_family *family,
49                  struct sk_buff *skb, struct net *net, u32 portid, u32 group,
50                  struct nlmsghdr *nlh, gfp_t flags);
51
52 static inline void *rpl_genlmsg_put(struct sk_buff *skb, u32 portid, u32 seq,
53                                     struct genl_family *family, int flags, u8 cmd)
54 {
55         return genlmsg_put(skb, portid, seq, &family->compat_family, flags, cmd);
56 }
57
58 #define genlmsg_put rpl_genlmsg_put
59
60 static inline int rpl_genl_unregister_family(struct genl_family *family)
61 {
62         return genl_unregister_family(&family->compat_family);
63 }
64 #define genl_unregister_family rpl_genl_unregister_family
65
66 #define genl_set_err rpl_genl_set_err
67 static inline int genl_set_err(struct genl_family *family, struct net *net,
68                                u32 portid, u32 group, int code)
69 {
70 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)
71         netlink_set_err(net->genl_sock, portid, group, code);
72         return 0;
73 #else
74         return netlink_set_err(net->genl_sock, portid, group, code);
75 #endif
76 }
77
78 #define genlmsg_multicast_netns rpl_genlmsg_multicast_netns
79 static inline int genlmsg_multicast_netns(struct genl_family *family,
80                                           struct net *net, struct sk_buff *skb,
81                                           u32 portid, unsigned int group, gfp_t flags)
82 {
83         return nlmsg_multicast(net->genl_sock, skb, portid, group, flags);
84 }
85
86
87 #define __genl_register_family rpl___genl_register_family
88 int rpl___genl_register_family(struct genl_family *family);
89
90 #define genl_register_family rpl_genl_register_family
91 static inline int rpl_genl_register_family(struct genl_family *family)
92 {
93         family->module = THIS_MODULE;
94         return rpl___genl_register_family(family);
95 }
96
97 #endif
98
99 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,14,0)
100 static inline struct sk_buff *genlmsg_new_unicast(size_t payload,
101                                                   struct genl_info *info,
102                                                   gfp_t flags)
103 {
104         return genlmsg_new(payload, flags);
105 }
106 #endif
107
108 #endif /* genetlink.h */