[B.A.T.M.A.N.] Antwort: Re: Antwort: Re: [PATCHv2 2/7] batman-adv: speed up dat by snooping received ip traffic

Andreas Pape
2016-03-02T07:17:12Z

Hello Sven,

Sven Eckelmann <sven@narfation.org> schrieb am 01.03.2016 17:02:57:

> You definitely have to check the size for the IP header. The vlan
ethernet
> header check is a different playground and mostly unrelated to your
problem.
>

If I understood you correctly I am supposed to implement something like
this:

switch (ntohs(ethhdr->h_proto)) {
case ETH_P_IP:
if (unlikely(!pskb_may_pull(skb, sizeof(struct iphdr))))
goto dropped;
iphdr = (struct iphdr *)(skb->data + ETH_HLEN);
/* snoop incoming traffic for dat update using the source
mac
* and source ip to speed up dat.
*/
batadv_dat_entry_check(bat_priv, iphdr->saddr,
ethhdr->h_source, vid);
break;
case ETH_P_8021Q:
if (unlikely(!pskb_may_pull(skb, sizeof(struct
vlan_ethhdr))))
goto dropped;
vhdr = (struct vlan_ethhdr *)(skb->data + ETH_HLEN);

if (vhdr->h_vlan_encapsulated_proto != ethertype) {
/* snoop incoming traffic for dat update also for
vlan
* tagged frames.
*/
if (ntohs(vhdr->h_vlan_encapsulated_proto) ==
ETH_P_IP) {
iphdr = (struct iphdr *)(vhdr + 1);
batadv_dat_entry_check(bat_priv,
iphdr->saddr,
vhdr->h_source,
vid);
}
break;
}
Correctly understood?

Looking through the code of this function batadv_interface_rx leads me to
another
question: Am I right that skb->data is pointing to the beginning of the
mac
layer 2 header of the packet at that point in time as it isn't advanced to
the beginning of the layer 3 header by calling eth_type_trans yet(which is
called
a few lines later)?

> Btw. you can skip this check when you just use skb_header_pointer to
access
> the IPv4 header. It will return NULL when the data cannot be accessed.
It
> will also take care of copying data out of the fragments in your
temporary
> "buffer" when the bytes are not in the main buffer of the skb. You just
have
> to prepare a large enough buffer on the stack and only use the returned
> pointer.
>
Kind regards,
Andreas

..................................................................
PHOENIX CONTACT ELECTRONICS GmbH

Sitz der Gesellschaft / registered office of the company: 31812 Bad Pyrmont
USt-Id-Nr.: DE811742156
Amtsgericht Hannover HRB 100528 / district court Hannover HRB 100528
Geschäftsführer / Executive Board: Roland Bent, Dr. Martin Heubeck
___________________________________________________________________
Diese E-Mail enthält vertrauliche und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren, jegliche anderweitige Verwendung sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.
----------------------------------------------------------------------------------------------------
This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure, distribution or other use of the material or parts thereof is strictly forbidden.
___________________________________________________________________