3 #include <net/genetlink.h>
4 #include <linux/version.h>
6 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
7 #include <linux/mutex.h>
8 #include <linux/openvswitch.h>
10 #include "openvswitch/datapath-compat.h"
12 static DEFINE_MUTEX(mc_group_mutex);
14 int genl_register_mc_group(struct genl_family *family,
15 struct genl_multicast_group *grp)
17 static int next_group = GENL_FIRST_MCGROUP;
21 if (!strcmp(grp->name, OVS_VPORT_MCGROUP)) {
22 grp->id = OVS_VPORT_MCGROUP_FALLBACK_ID;
26 mutex_lock(&mc_group_mutex);
29 if (++next_group > GENL_LAST_MCGROUP)
30 next_group = GENL_FIRST_MCGROUP;
31 mutex_unlock(&mc_group_mutex);
35 #endif /* kernel < 2.6.23 */
37 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)
39 * genl_register_family_with_ops - register a generic netlink family
40 * @family: generic netlink family
41 * @ops: operations to be registered
42 * @n_ops: number of elements to register
44 * Registers the specified family and operations from the specified table.
45 * Only one family may be registered with the same family name or identifier.
47 * The family id may equal GENL_ID_GENERATE causing an unique id to
48 * be automatically generated and assigned.
50 * Either a doit or dumpit callback must be specified for every registered
51 * operation or the function will fail. Only one operation structure per
52 * command identifier may be registered.
54 * See include/net/genetlink.h for more documenation on the operations
57 * This is equivalent to calling genl_register_family() followed by
58 * genl_register_ops() for every operation entry in the table taking
59 * care to unregister the family on error path.
61 * Return 0 on success or a negative error code.
63 int genl_register_family_with_ops(struct genl_family *family,
64 struct genl_ops *ops, size_t n_ops)
68 err = genl_register_family(family);
72 for (i = 0; i < n_ops; ++i, ++ops) {
73 err = genl_register_ops(family, ops);
79 genl_unregister_family(family);
84 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
86 * nlmsg_notify - send a notification netlink message
87 * @sk: netlink socket to use
88 * @skb: notification message
89 * @pid: destination netlink pid for reports or 0
90 * @group: destination multicast group or 0
91 * @report: 1 to report back, 0 to disable
92 * @flags: allocation flags
94 int nlmsg_notify(struct sock *sk, struct sk_buff *skb, u32 pid,
95 unsigned int group, int report, gfp_t flags)
103 atomic_inc(&skb->users);
107 /* errors reported via destination sk->sk_err, but propagate
108 * delivery errors if NETLINK_BROADCAST_ERROR flag is set */
109 err = nlmsg_multicast(sk, skb, exclude_pid, group, flags);
115 err2 = nlmsg_unicast(sk, skb, pid);
116 if (!err || err == -ESRCH)
124 /* This is analogous to rtnl_notify() but uses genl_sock instead of rtnl.
126 * This is not (yet) in any upstream kernel. */
127 void genl_notify(struct sk_buff *skb, struct net *net, u32 pid, u32 group,
128 struct nlmsghdr *nlh, gfp_t flags)
130 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)
131 struct sock *sk = net->genl_sock;
133 struct sock *sk = genl_sock;
138 report = nlmsg_report(nlh);
140 nlmsg_notify(sk, skb, pid, group, report, flags);
143 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
144 /* This function wasn't exported before 2.6.30. Lose! */
145 void netlink_set_err(struct sock *ssk, u32 pid, u32 group, int code)