Skip to content

Commit

Permalink
datapath: Cleanup netlink compat code.
Browse files Browse the repository at this point in the history
Patch removes genl, netlink, rtnl compat code and dpif-linux
fallback-id compat code.

Signed-off-by: Pravin B Shelar <[email protected]>
Acked-by: Jesse Gross <[email protected]>
  • Loading branch information
Pravin B Shelar committed Sep 6, 2013
1 parent 07ac71e commit b3dcb73
Show file tree
Hide file tree
Showing 14 changed files with 13 additions and 527 deletions.
8 changes: 0 additions & 8 deletions datapath/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,6 @@ static inline void skb_clear_rxhash(struct sk_buff *skb)
#endif
}

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32)
#define GENL_SOCK(net) (genl_sock)
#define SET_NETNSOK
#else
#define GENL_SOCK(net) ((net)->genl_sock)
#define SET_NETNSOK .netnsok = true,
#endif

#ifdef HAVE_PARALLEL_OPS
#define SET_PARALLEL_OPS .parallel_ops = true,
#else
Expand Down
12 changes: 6 additions & 6 deletions datapath/datapath.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ static struct genl_family dp_packet_genl_family = {
.name = OVS_PACKET_FAMILY,
.version = OVS_PACKET_VERSION,
.maxattr = OVS_PACKET_ATTR_MAX,
SET_NETNSOK
.netnsok = true,
SET_PARALLEL_OPS
};

Expand Down Expand Up @@ -1003,7 +1003,7 @@ static struct genl_family dp_flow_genl_family = {
.name = OVS_FLOW_FAMILY,
.version = OVS_FLOW_VERSION,
.maxattr = OVS_FLOW_ATTR_MAX,
SET_NETNSOK
.netnsok = true,
SET_PARALLEL_OPS
};

Expand Down Expand Up @@ -1387,7 +1387,7 @@ static int ovs_flow_cmd_new_or_set(struct sk_buff *skb, struct genl_info *info)
if (!IS_ERR(reply))
ovs_notify(reply, info, &ovs_dp_flow_multicast_group);
else
netlink_set_err(GENL_SOCK(sock_net(skb->sk)), 0,
netlink_set_err(sock_net(skb->sk)->genl_sock, 0,
ovs_dp_flow_multicast_group.id, PTR_ERR(reply));
return 0;

Expand Down Expand Up @@ -1583,7 +1583,7 @@ static struct genl_family dp_datapath_genl_family = {
.name = OVS_DATAPATH_FAMILY,
.version = OVS_DATAPATH_VERSION,
.maxattr = OVS_DP_ATTR_MAX,
SET_NETNSOK
.netnsok = true,
SET_PARALLEL_OPS
};

Expand Down Expand Up @@ -1850,7 +1850,7 @@ static int ovs_dp_cmd_set(struct sk_buff *skb, struct genl_info *info)
info->snd_seq, OVS_DP_CMD_NEW);
if (IS_ERR(reply)) {
err = PTR_ERR(reply);
netlink_set_err(GENL_SOCK(sock_net(skb->sk)), 0,
netlink_set_err(sock_net(skb->sk)->genl_sock, 0,
ovs_dp_datapath_multicast_group.id, err);
err = 0;
goto unlock;
Expand Down Expand Up @@ -1963,7 +1963,7 @@ static struct genl_family dp_vport_genl_family = {
.name = OVS_VPORT_FAMILY,
.version = OVS_VPORT_VERSION,
.maxattr = OVS_VPORT_ATTR_MAX,
SET_NETNSOK
.netnsok = true,
SET_PARALLEL_OPS
};

Expand Down
2 changes: 1 addition & 1 deletion datapath/dp_notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static void dp_detach_port_notify(struct vport *vport)
OVS_VPORT_CMD_DEL);
ovs_dp_detach_port(vport);
if (IS_ERR(notify)) {
netlink_set_err(GENL_SOCK(ovs_dp_get_net(dp)), 0,
netlink_set_err(ovs_dp_get_net(dp)->genl_sock, 0,
ovs_dp_vport_multicast_group.id,
PTR_ERR(notify));
return;
Expand Down
132 changes: 0 additions & 132 deletions datapath/linux/compat/genetlink-openvswitch.c
Original file line number Diff line number Diff line change
@@ -1,149 +1,17 @@
#include <net/genetlink.h>
#include <linux/version.h>

#define GENL_FIRST_MCGROUP 16
#define GENL_LAST_MCGROUP 31

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
#include <linux/mutex.h>
#include <linux/openvswitch.h>

#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)
{
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 (++next_group > GENL_LAST_MCGROUP)
next_group = GENL_FIRST_MCGROUP;
mutex_unlock(&mc_group_mutex);

return 0;
}
#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 err, i;

err = genl_register_family(family);
if (err)
return err;

for (i = 0; i < n_ops; ++i, ++ops) {
err = genl_register_ops(family, ops);
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;
}

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
16 changes: 0 additions & 16 deletions datapath/linux/compat/include/linux/netlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,9 @@
#endif

#include <net/netlink.h>
#include <linux/version.h>

#ifndef NLMSG_DEFAULT_SIZE
#define NLMSG_DEFAULT_SIZE (NLMSG_GOODSIZE - NLMSG_HDRLEN)
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
#define nlmsg_new(s, f) nlmsg_new_proper((s), (f))
static inline struct sk_buff *nlmsg_new_proper(int size, gfp_t flags)
{
return alloc_skb(size, flags);
}
#endif /* linux kernel < 2.6.19 */

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
static inline struct nlmsghdr *nlmsg_hdr(const struct sk_buff *skb)
{
return (struct nlmsghdr *)skb->data;
}
#endif

#endif
43 changes: 0 additions & 43 deletions datapath/linux/compat/include/linux/rtnetlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,6 @@

#include_next <linux/rtnetlink.h>

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
static inline void rtnl_notify(struct sk_buff *skb, u32 portid, u32 group,
struct nlmsghdr *nlh, gfp_t flags)
{
BUG_ON(nlh != NULL); /* not implemented */
if (group) {
/* errors reported via destination sk->sk_err */
nlmsg_multicast(rtnl, skb, 0, group, flags);
}
}

static inline void rtnl_set_sk_err(u32 group, int error)
{
netlink_set_err(rtnl, 0, group, error);
}
#endif

/* No 'net' parameter in these versions. */
#define rtnl_notify(skb, net, portid, group, nlh, flags) \
((void) rtnl_notify(skb, portid, group, nlh, flags))
#define rtnl_set_sk_err(net, group, error) \
(rtnl_set_sk_err(group, error))
#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
/* Make the return type effectively 'void' to match Linux 2.6.30+. */
#define rtnl_notify(skb, net, portid, group, nlh, flags) \
((void) rtnl_notify(skb, net, portid, group, nlh, flags))
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
static inline int rtnl_is_locked(void)
{
if (unlikely(rtnl_trylock())) {
rtnl_unlock();
return 0;
}

return 1;
}

#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34)
#ifdef CONFIG_PROVE_LOCKING
static inline int lockdep_rtnl_is_held(void)
Expand Down
Loading

0 comments on commit b3dcb73

Please sign in to comment.