netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <shemminger@linux-foundation.org>
To: David Miller <davem@davemloft.net>
Cc: bridge@linux-foundation.org, netdev@vger.kernel.org
Subject: [RFC 2/2] bridge: per device promiscious taps
Date: Fri, 2 Mar 2007 14:14:18 -0800	[thread overview]
Message-ID: <20070302141418.1daa9047@freekitty> (raw)
In-Reply-To: <20070302140929.262e8460@freekitty>

Part of the next set of bridge patches includes this.

It allows packet capture by interface on a bridge:
	tcpdump -i eth0

will work as expected.

@@ -128,34 +125,45 @@ static inline int is_link_local(const un
 int br_handle_frame(struct net_bridge_port *p, struct sk_buff **pskb)
 {
 	struct sk_buff *skb = *pskb;
+	struct sk_buff *skb2 = NULL;
 	const unsigned char *dest = eth_hdr(skb)->h_dest;
 
	if (!is_valid_ether_addr(eth_hdr(skb)->h_source))
		goto err;

 	if (unlikely(is_link_local(dest))) {
 		skb->pkt_type = PACKET_HOST;
 		return NF_HOOK(PF_BRIDGE, NF_BR_LOCAL_IN, skb, skb->dev,
 			       NULL, br_handle_local_finish) != 0;
 	}
+
+	if (unlikely(p->dev->promiscuity > 1))
+		skb2 = skb_clone(skb, GFP_ATOMIC);
 
-	if (p->state == BR_STATE_FORWARDING || p->state == BR_STATE_LEARNING) {
+	switch (p->state) {
+	case BR_STATE_FORWARDING:
 		if (br_should_route_hook) {
-			if (br_should_route_hook(pskb))
+			if (br_should_route_hook(pskb)) {
+				kfree_skb(skb2);
 				return 0;
+			}
 			skb = *pskb;
 			dest = eth_hdr(skb)->h_dest;
 		}
 
 		if (!compare_ether_addr(p->br->dev->dev_addr, dest))
 			skb->pkt_type = PACKET_HOST;
+		/* fall thru */
 
+	case BR_STATE_LEARNING:
 		NF_HOOK(PF_BRIDGE, NF_BR_PRE_ROUTING, skb, skb->dev, NULL,
 			br_handle_frame_finish);
-		return 1;
+		break;
+
+	default:
+		kfree_skb(skb);
 	}
 
-err:
-	kfree_skb(skb);
-	return 1;
+	if (likely(!skb2))
+		return 1;
+
+	*pskb = skb2;
+	return 0;
 }

  reply	other threads:[~2007-03-02 22:14 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-01  1:18 [PATCH] bridge: avoid ptype_all packet handling Stephen Hemminger
2007-03-01  1:28 ` Ben Greear
2007-03-01  3:56   ` Stephen Hemminger
2007-03-01  4:05     ` Ben Greear
2007-03-01  7:04       ` Stephen Hemminger
2007-03-01  7:22         ` David Miller
2007-03-01  7:26           ` Stephen Hemminger
2007-03-01  7:30             ` David Miller
2007-03-01 11:47               ` jamal
2007-03-03  2:14               ` Andi Kleen
2007-03-03  4:22                 ` David Miller
2007-03-03  7:09                   ` Stephen Hemminger
2007-03-03 12:30                   ` Andi Kleen
2007-03-02 21:26 ` David Miller
2007-03-02 22:09   ` [RFC 1/2] " Stephen Hemminger
2007-03-02 22:14     ` Stephen Hemminger [this message]
2007-03-02 22:48     ` David Miller
2007-03-02 23:18       ` David Miller
2007-03-02 23:34         ` Stephen Hemminger
2007-03-02 23:41           ` David Miller
2007-03-03  5:38         ` Herbert Xu
2007-03-03  5:59           ` David Miller
2007-03-03  6:42             ` Herbert Xu
2007-03-02 22:15   ` Stephen Hemminger
2007-03-03 12:04   ` [PATCH] " Stefan Rompf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070302141418.1daa9047@freekitty \
    --to=shemminger@linux-foundation.org \
    --cc=bridge@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).