Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 170420
b: refs/heads/master
c: 9777500
h: refs/heads/master
v: v3
  • Loading branch information
Neil Horman authored and David S. Miller committed Oct 5, 2009
1 parent 9b7d973 commit a515dc2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 69ef9694099802f7feeb23182dfb869e7c5f76f0
refs/heads/master: 977750076d98c7ff6cbda51858bb5a5894a9d9ab
2 changes: 2 additions & 0 deletions trunk/include/linux/if_packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ struct sockaddr_ll
#define PACKET_RESERVE 12
#define PACKET_TX_RING 13
#define PACKET_LOSS 14
#define PACKET_GAPDATA 15

struct tpacket_stats
{
unsigned int tp_packets;
unsigned int tp_drops;
unsigned int tp_gap;
};

struct tpacket_auxdata
Expand Down
33 changes: 33 additions & 0 deletions trunk/net/packet/af_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,31 @@ static inline unsigned int run_filter(struct sk_buff *skb, struct sock *sk,
return res;
}

/*
* If we've lost frames since the last time we queued one to the
* sk_receive_queue, we need to record it here.
* This must be called under the protection of the socket lock
* to prevent racing with other softirqs and user space
*/
static inline void record_packet_gap(struct sk_buff *skb,
struct packet_sock *po)
{
/*
* We overload the mark field here, since we're about
* to enqueue to a receive queue and no body else will
* use this field at this point
*/
skb->mark = po->stats.tp_gap;
po->stats.tp_gap = 0;
return;

}

static inline __u32 check_packet_gap(struct sk_buff *skb)
{
return skb->mark;
}

/*
This function makes lazy skb cloning in hope that most of packets
are discarded by BPF.
Expand Down Expand Up @@ -626,6 +651,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,

spin_lock(&sk->sk_receive_queue.lock);
po->stats.tp_packets++;
record_packet_gap(skb, po);
__skb_queue_tail(&sk->sk_receive_queue, skb);
spin_unlock(&sk->sk_receive_queue.lock);
sk->sk_data_ready(sk, skb->len);
Expand All @@ -634,6 +660,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
drop_n_acct:
spin_lock(&sk->sk_receive_queue.lock);
po->stats.tp_drops++;
po->stats.tp_gap++;
spin_unlock(&sk->sk_receive_queue.lock);

drop_n_restore:
Expand Down Expand Up @@ -811,6 +838,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,

ring_is_full:
po->stats.tp_drops++;
po->stats.tp_gap++;
spin_unlock(&sk->sk_receive_queue.lock);

sk->sk_data_ready(sk, 0);
Expand Down Expand Up @@ -1418,6 +1446,7 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
struct sk_buff *skb;
int copied, err;
struct sockaddr_ll *sll;
__u32 gap;

err = -EINVAL;
if (flags & ~(MSG_PEEK|MSG_DONTWAIT|MSG_TRUNC|MSG_CMSG_COMPAT))
Expand Down Expand Up @@ -1496,6 +1525,10 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
put_cmsg(msg, SOL_PACKET, PACKET_AUXDATA, sizeof(aux), &aux);
}

gap = check_packet_gap(skb);
if (gap)
put_cmsg(msg, SOL_PACKET, PACKET_GAPDATA, sizeof(__u32), &gap);

/*
* Free or return the buffer as appropriate. Again this
* hides all the races and re-entrancy issues from us.
Expand Down

0 comments on commit a515dc2

Please sign in to comment.