Re: [B.A.T.M.A.N.] [PATCHv7 4/4] batman-adv: Add IPv4 link-local/IPv6-ll-all-nodes multicast support

Simon Wunderlich
2013-07-12T09:12:16Z

[-- Attachment #1: Type: text/plain, Size: 3195 bytes --]

On Thu, Jul 04, 2013 at 12:03:22AM +0200, Linus Lüssing wrote:
> [...]
> +enum batadv_forw_mode
> +batadv_mcast_forw_mode(struct sk_buff *skb, struct batadv_priv *bat_priv)
> +{
> + struct ethhdr *ethhdr = (struct ethhdr *)(skb->data);
> + int ret;
> +
> + ret = batadv_mcast_forw_mode_check(skb, bat_priv);
> + if (ret == -ENOMEM)
> + return BATADV_FORW_NONE;
> + else if (ret == -EINVAL)

Shouldn't this better be "ret < 0", in case you add more error cases later?

> return BATADV_FORW_ALL;
>
> - count = batadv_tt_global_hash_count(bat_priv, ethhdr->h_dest,
> + ret = batadv_tt_global_hash_count(bat_priv, ethhdr->h_dest,
> BATADV_NO_FLAGS);
>
> - switch (count) {
> + switch (ret) {
> case 0:
> return BATADV_FORW_NONE;
> case 1:
> @@ -263,6 +348,28 @@ batadv_mcast_forw_mode(struct sk_buff *skb, struct batadv_priv *bat_priv)
> }
>
> /**
> + * batadv_mcast_tvlv_update_flag_counter - update the counter of a flag
> + * @flag: the flag we want to update counters for
> + * @flag_counter: the counter we might update
> + * @new_flags: the new capability bitset of a node
> + * @old_flags: the current, to be updated bitset of a node
> + *
> + * Update the given flag_counter with the help of the new flag information
> + * of a node to reflect how many nodes have the given flag unset.
> + */
> +static void batadv_mcast_tvlv_update_flag_counter(uint8_t flag,
> + atomic_t *flag_counter,
> + uint8_t new_flags,
> + int old_flags)

Why are parts of the bitsets uint8_t, some int?

Also, this function should go into one of the previous patches, this has nothing to do with
IPv4 but is just a refactoring.

> +{
> + if (!(new_flags & flag) &&
> + (old_flags & flag || old_flags & BATADV_UNINIT_FLAGS))
> + atomic_inc(flag_counter);
> + else if (new_flags & flag && !(old_flags & flag))
> + atomic_dec(flag_counter);
> +}
> +
> +/**
> * batadv_mcast_tvlv_ogm_handler_v1 - process incoming multicast tvlv container
> * @bat_priv: the bat priv with all the soft interface information
> * @orig: the orig_node of the ogm
> @@ -285,13 +392,14 @@ static void batadv_mcast_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv,
> (tvlv_value) && (tvlv_value_len == sizeof(mcast_flags)))
> mcast_flags = *(uint8_t *)tvlv_value;
>
> - if (!(mcast_flags & BATADV_MCAST_LISTENER_ANNOUNCEMENT) &&
> - (orig->mcast_flags & BATADV_MCAST_LISTENER_ANNOUNCEMENT ||
> - orig->mcast_flags & BATADV_UNINIT_FLAGS))
> - atomic_inc(&bat_priv->mcast.num_no_mla);
> - else if (mcast_flags & BATADV_MCAST_LISTENER_ANNOUNCEMENT &&
> - !(orig->mcast_flags & BATADV_MCAST_LISTENER_ANNOUNCEMENT))
> - atomic_dec(&bat_priv->mcast.num_no_mla);
> + batadv_mcast_tvlv_update_flag_counter(
> + BATADV_MCAST_LISTENER_ANNOUNCEMENT,
> + &bat_priv->mcast.num_no_mla,
> + mcast_flags, orig->mcast_flags);
> + batadv_mcast_tvlv_update_flag_counter(
> + BATADV_MCAST_HAS_NO_BRIDGE,
> + &bat_priv->mcast.num_has_bridge,
> + mcast_flags, orig->mcast_flags);

You should find a shorter name, the alignment looks really ugly. :)

Cheers,
Simon

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]