[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1395851472-10524-2-git-send-email-jiri@resnulli.us>
Date: Wed, 26 Mar 2014 17:31:07 +0100
From: Jiri Pirko <jiri@...nulli.us>
To: netdev@...r.kernel.org
Cc: davem@...emloft.net, nhorman@...driver.com, andy@...yhouse.net,
tgraf@...g.ch, dborkman@...hat.com, ogerlitz@...lanox.com,
jesse@...ira.com, pshelar@...ira.com, azhou@...ira.com,
ben@...adent.org.uk, stephen@...workplumber.org,
jeffrey.t.kirsher@...el.com, vyasevic@...hat.com,
xiyou.wangcong@...il.com, john.r.fastabend@...el.com,
edumazet@...gle.com, jhs@...atatu.com, sfeldma@...ulusnetworks.com,
f.fainelli@...il.com, roopa@...ulusnetworks.com,
linville@...driver.com, dev@...nvswitch.org
Subject: [patch net-next RFC v2 1/6] net: make packet_type->ak_packet_priv generic
The priv is used now by af_packet. Rename it to make it useable for
others as well. Also, introduce packet_id_match to move the sk matching
from skb_loop_sk to af_packet code where it belongs.
Signed-off-by: Jiri Pirko <jiri@...nulli.us>
---
include/linux/netdevice.h | 2 +-
net/core/dev.c | 4 +---
net/packet/af_packet.c | 22 +++++++++++++++-------
3 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 4b6d12c..6b70e6f 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1777,7 +1777,7 @@ struct packet_type {
struct net_device *);
bool (*id_match)(struct packet_type *ptype,
struct sock *sk);
- void *af_packet_priv;
+ void *priv;
struct list_head list;
};
diff --git a/net/core/dev.c b/net/core/dev.c
index 55f8e64..61ce72d 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -1719,13 +1719,11 @@ static inline int deliver_skb(struct sk_buff *skb,
static inline bool skb_loop_sk(struct packet_type *ptype, struct sk_buff *skb)
{
- if (!ptype->af_packet_priv || !skb->sk)
+ if (!ptype->priv || !skb->sk)
return false;
if (ptype->id_match)
return ptype->id_match(ptype, skb->sk);
- else if ((struct sock *)ptype->af_packet_priv == skb->sk)
- return true;
return false;
}
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 2923044..a36ac08 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1343,7 +1343,7 @@ static bool fanout_has_flag(struct packet_fanout *f, u16 flag)
static int packet_rcv_fanout(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt, struct net_device *orig_dev)
{
- struct packet_fanout *f = pt->af_packet_priv;
+ struct packet_fanout *f = pt->priv;
unsigned int num = f->num_members;
struct packet_sock *po;
unsigned int idx;
@@ -1425,7 +1425,7 @@ static void __fanout_unlink(struct sock *sk, struct packet_sock *po)
static bool match_fanout_group(struct packet_type *ptype, struct sock *sk)
{
- if (ptype->af_packet_priv == (void *)((struct packet_sock *)sk)->fanout)
+ if (ptype->priv == (void *)((struct packet_sock *)sk)->fanout)
return true;
return false;
@@ -1487,7 +1487,7 @@ static int fanout_add(struct sock *sk, u16 id, u16 type_flags)
match->prot_hook.type = po->prot_hook.type;
match->prot_hook.dev = po->prot_hook.dev;
match->prot_hook.func = packet_rcv_fanout;
- match->prot_hook.af_packet_priv = match;
+ match->prot_hook.priv = match;
match->prot_hook.id_match = match_fanout_group;
dev_add_pack(&match->prot_hook);
list_add(&match->list, &fanout_list);
@@ -1545,7 +1545,7 @@ static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev,
* field for just this event.
*/
- sk = pt->af_packet_priv;
+ sk = pt->priv;
/*
* Yank back the headers [hope the device set this
@@ -1768,7 +1768,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
if (skb->pkt_type == PACKET_LOOPBACK)
goto drop;
- sk = pt->af_packet_priv;
+ sk = pt->priv;
po = pkt_sk(sk);
if (!net_eq(dev_net(dev), sock_net(sk)))
@@ -1893,7 +1893,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
if (skb->pkt_type == PACKET_LOOPBACK)
goto drop;
- sk = pt->af_packet_priv;
+ sk = pt->priv;
po = pkt_sk(sk);
if (!net_eq(dev_net(dev), sock_net(sk)))
@@ -2768,6 +2768,13 @@ static struct proto packet_proto = {
.obj_size = sizeof(struct packet_sock),
};
+static bool packet_id_match(struct packet_type *ptype, struct sock *sk)
+{
+ if ((struct sock *) ptype->priv == sk)
+ return true;
+ return false;
+}
+
/*
* Create a packet of type SOCK_PACKET.
*/
@@ -2824,7 +2831,8 @@ static int packet_create(struct net *net, struct socket *sock, int protocol,
if (sock->type == SOCK_PACKET)
po->prot_hook.func = packet_rcv_spkt;
- po->prot_hook.af_packet_priv = sk;
+ po->prot_hook.id_match = packet_id_match,
+ po->prot_hook.priv = sk;
if (proto) {
po->prot_hook.type = proto;
--
1.8.5.3
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists