[B.A.T.M.A.N.] [PATCH 3/6] batman-adv: register batman ogm receive function during protocol init

Simon Wunderlich simon.wunderlich at s2003.tu-chemnitz.de
Sat Mar 3 18:59:53 CET 2012


On Thu, Mar 01, 2012 at 03:35:18PM +0800, Marek Lindner wrote:
> -static void bat_iv_ogm_receive(struct hard_iface *if_incoming,
> -			       struct sk_buff *skb)
> +static void _bat_iv_ogm_receive(struct sk_buff *skb,
> +				struct hard_iface *if_incoming)

<rant>
Personally, I don't like underscore functions. They are usually created
because of a lack of creativity, but are later called from different places,
do different jobs and in the end everyone is confused. :) Is it possibble to
change the name, e.g. to bat_iv_ogm_handle()?
</rant>


>  {
>  	struct batman_ogm_packet *batman_ogm_packet;
>  	struct ethhdr *ethhdr;
> @@ -1200,6 +1200,39 @@ static void bat_iv_ogm_receive(struct hard_iface *if_incoming,
>  					batman_ogm_packet->tt_num_changes));
>  }
>  
> +static int bat_iv_ogm_receive(struct sk_buff *skb,
> +			      struct hard_iface *hard_iface)
> +{
> +	struct ethhdr *ethhdr;
> +
> +	/* drop packet if it has not necessary minimum size */
> +	if (unlikely(!pskb_may_pull(skb, BATMAN_OGM_HLEN)))
> +		return NET_RX_DROP;
> +
> +	ethhdr = (struct ethhdr *)skb_mac_header(skb);
> +
> +	/* packet with broadcast indication but unicast recipient */
> +	if (!is_broadcast_ether_addr(ethhdr->h_dest))
> +		return NET_RX_DROP;
> +
> +	/* packet with broadcast sender address */
> +	if (is_broadcast_ether_addr(ethhdr->h_source))
> +		return NET_RX_DROP;
> +
> +	/* create a copy of the skb, if needed, to modify it. */
> +	if (skb_cow(skb, 0) < 0)
> +		return NET_RX_DROP;
> +
> +	/* keep skb linear */
> +	if (skb_linearize(skb) < 0)
> +		return NET_RX_DROP;
> +
> +	_bat_iv_ogm_receive(skb, hard_iface);
> +
> +	kfree_skb(skb);
> +	return NET_RX_SUCCESS;
> +}
> +

We should somewhere add a check whether the hard_iface is actually assigned to
a mesh using the BATMAN IV algorithm. When more algorithms are added, we only want
the assigned protocol to be handled, others should be ignored.

Cheers,
	Simon
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.open-mesh.org/pipermail/b.a.t.m.a.n/attachments/20120303/9742f311/attachment.pgp>


More information about the B.A.T.M.A.N mailing list