From: Simon Wunderlich <sw@simonwunderlich.de>
To: b.a.t.m.a.n@lists.open-mesh.org
Cc: Marek Lindner <mareklindner@neomailbox.ch>
Subject: Re: [B.A.T.M.A.N.] [PATCHv2] batman-adv: drop QinQ claim frames in bridge loop avoidance
Date: Sat, 21 Jun 2014 16:57:42 +0200 [thread overview]
Message-ID: <201406211657.42780.sw@simonwunderlich.de> (raw)
In-Reply-To: <2808362.GMTcl9ijMO@diderot>
> On Friday 13 June 2014 11:15:50 Simon Wunderlich wrote:
> > +/**
> > + * batadv_is_encapsulated_claim - checks if a claim frame is
> > encapsulated + * @bat_priv: the bat priv with all the soft interface
> > information + * @skb: skb to be checked
> > + *
> > + * Check if this frame is a claim frame encapsulated in at least two
> > layers + * of VLANs.
>
> Maybe you mention QinQ here ? 'Two layers of VLANs' isn't that obvious
> (without the commit message).
OK, sure.
>
> > + * Returns 1 if this is an encapsulated claim frame, 0 otherwise.
>
> Boolean functions should return bool instead of 0 / 1.
OK.
>
> > + * At this point it is known that the first two protocols
> > + * are VLAN headers, so start checking at the encapsulated protocol
> > + * of the second header.
>
> The first two protocols ? Are you trying to say that at this point we
> already know we are having QinQ ?
>
Yep. I can make that more clear.
> > + */
> > + headlen = VLAN_ETH_HLEN;
> > + do {
> > + vhdr_ptr = skb_header_pointer(skb, headlen, VLAN_HLEN, &vhdr);
> > + if (!vhdr_ptr)
> > + return 0;
> > +
> > + headlen += VLAN_HLEN;
> > + } while (vhdr_ptr->h_vlan_encapsulated_proto == htons(ETH_P_8021Q));
>
> Is there a length check somewhere in skb_header_pointer() ? We wouldn't
> want to read more than we have in the skb, right ?
>
Yes, skb_header_pointer (or also skb_copy_bits() which is called by that)
checks the length, so we don't have to do that on our own.
> > + if (vhdr_ptr->h_vlan_encapsulated_proto != htons(ETH_P_ARP))
> > + return 0;
> > +
> > + if (unlikely(!pskb_may_pull(skb, headlen + arp_hdr_len(skb->dev))))
> > + return 0;
> > +
> > + /* pskb_may_pull() may have modified the pointers, get ethhdr again */
> > + ethhdr = eth_hdr(skb);
> > + arphdr = (struct arphdr *)((uint8_t *)ethhdr + headlen);
> > +
> > + /* Check whether the ARP frame carries a valid IP information */
> > + if (arphdr->ar_hrd != htons(ARPHRD_ETHER))
> > + return 0;
> > + if (arphdr->ar_pro != htons(ETH_P_IP))
> > + return 0;
> > + if (arphdr->ar_hln != ETH_ALEN)
> > + return 0;
> > + if (arphdr->ar_pln != 4)
> > + return 0;
> > +
> > + hw_src = (uint8_t *)arphdr + sizeof(struct arphdr);
> > + hw_dst = hw_src + ETH_ALEN + 4;
> > + bla_dst = (struct batadv_bla_claim_dst *)hw_dst;
> > + bla_dst_own = &bat_priv->bla.claim_dest;
>
> Looks like copy & paste from batadv_bla_process_claim() ? How about using a
> shared function ?
Yeah, it's copy and pasted. The only thing which we could put into a common
function are the 4 checks, the local variables are used in a different way for
the further code in each function. This didn't really look worth it so I
didn't bother to refactor in that patch, if you feel otherwise let me know and
i'll refactor in v2.
Thanks!
Simon
next prev parent reply other threads:[~2014-06-21 14:57 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-13 9:15 [B.A.T.M.A.N.] [PATCHv2] batman-adv: drop QinQ claim frames in bridge loop avoidance Simon Wunderlich
2014-06-21 12:50 ` Marek Lindner
2014-06-21 14:57 ` Simon Wunderlich [this message]
2014-06-22 9:21 ` Marek Lindner
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=201406211657.42780.sw@simonwunderlich.de \
--to=sw@simonwunderlich.de \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
--cc=mareklindner@neomailbox.ch \
/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