public inbox for b.a.t.m.a.n@lists.open-mesh.org
 help / color / mirror / Atom feed
From: Simon Wunderlich <simon.wunderlich@s2003.tu-chemnitz.de>
To: The list for a Better Approach To Mobile Ad-hoc Networking
	<b.a.t.m.a.n@lists.open-mesh.org>
Subject: Re: [B.A.T.M.A.N.] [PATCH 3/6] batman-adv: Distributed ARP Table - create the DHT helper functions
Date: Mon, 31 Oct 2011 01:08:42 +0100	[thread overview]
Message-ID: <20111031000841.GD10726@pandem0nium> (raw)
In-Reply-To: <1319964962-5092-4-git-send-email-ordex@autistici.org>

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

On Sun, Oct 30, 2011 at 09:55:59AM +0100, Antonio Quartulli wrote:
> [...]
> +		for (i = 0; i < hash->size; i++) {
> +			head = &hash->table[i];
> +
> +			rcu_read_lock();
> +			hlist_for_each_entry_rcu(orig_node, node, head,
> +						 hash_entry) {
> +				if (orig_node->dht_hash > ip_key)
> +					tmp_max = USHRT_MAX -
> +						orig_node->dht_hash + ip_key;
> +				else
> +					tmp_max = ip_key - orig_node->dht_hash;
> +
> +				/* this is closest! */
> +				if (tmp_max <= max)
> +					continue;
> +
> +				/* this has already been selected */
> +				if (tmp_max > last_max)
> +					continue;
> +
> +				if (!atomic_inc_not_zero(&orig_node->refcount))
> +					continue;
> +
> +				/* In case of hash collision we can select two
> +				 * nodes with the same hash, but we have ensure
> +				 * they are different */
> +				if (tmp_max == last_max) {
> +					for (j = 0; j < select; j++)
> +						if (res[j].orig_node ==
> +						    orig_node)
> +							break;
> +					if (j < select)
> +						continue;
> +				}
> +
> +				if (!atomic_inc_not_zero(&orig_node->refcount))
> +					continue;

Why do you increase the refcount two times? If it is really required, please
add a comment.

> +
> +				max = tmp_max;
> +				if (max_orig_node)
> +					orig_node_free_ref(max_orig_node);
> +				max_orig_node = orig_node;
> +			}
> +			rcu_read_unlock();
> +		}
> +		last_max = max;
> +		if (max_orig_node) {
> +			res[select].type = DHT_CANDIDATE_ORIG;
> +			res[select].orig_node = max_orig_node;
> +			bat_dbg(DBG_ARP, bat_priv, "DHT_SEL_CAND %d: %pM %u\n",
> +				select, max_orig_node->orig, max);
> +		}
> +		if (res[select].type == DHT_CANDIDATE_ME) {
> +			chosen_me = true;
> +			bat_dbg(DBG_ARP, bat_priv, "DHT_SEL_CAND %d: ME %u\n",
> +				select, bat_priv->dht_hash);
> +		}
> +
> +		max_orig_node = NULL;
> +	}
> +
> +	return res;
> +}
> +
> +/*
> + * Sends the skb payload passed as argument to the candidates selected for
> + * 'ip'. The skb is copied by means of pskb_copy() and is sent as unicast packet
> + * to each of the selected candidate. */
> +static bool dht_send_data(struct bat_priv *bat_priv, struct sk_buff *skb,
> +			  uint32_t ip)
> +{
> +	int i;
> +	bool ret = false;
> +	struct neigh_node *neigh_node = NULL;
> +	struct sk_buff *tmp_skb;
> +	struct dht_candidate *cand = dht_select_candidates(bat_priv, ip);
> +
> +	if (!cand)
> +		goto out;
> +
> +	bat_dbg(DBG_ARP, bat_priv, "DHT_SEND for %pI4\n", &ip);
> +
> +	for (i = 0; i < DHT_CANDIDATES_NUM; i++) {
> +		if (cand[i].type == DHT_CANDIDATE_ME ||
> +		    cand[i].type == DHT_CANDIDATE_NULL) {
> +			continue;
> +		}

no braces are required here.

> +
> +		neigh_node = orig_node_get_router(cand[i].orig_node);
> +		if (!neigh_node)
> +			goto free_orig;
> +
> +		tmp_skb = pskb_copy(skb, GFP_ATOMIC);
> +		tmp_skb = prepare_unicast_packet(tmp_skb, cand[i].orig_node);
> +		if (tmp_skb)
> +			send_skb_packet(tmp_skb, neigh_node->if_incoming,
> +					neigh_node->addr);
> +		/* set ret to true only if we send at least one request */
> +		ret = true;
> +		neigh_node_free_ref(neigh_node);
> +free_orig:
> +		orig_node_free_ref(cand[i].orig_node);
> +	}
> +
> +out:
> +	kfree(cand);
> +	return ret;
> +}

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

  reply	other threads:[~2011-10-31  0:08 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-30  8:55 [B.A.T.M.A.N.] [PATCH 0/6] DAT: Distributed ARP Table Antonio Quartulli
2011-10-30  8:55 ` [B.A.T.M.A.N.] [PATCH 1/6] batman-adv: implement an helper function to forge unicast packets Antonio Quartulli
2011-10-31  0:05   ` Simon Wunderlich
2011-11-01  9:12     ` Antonio Quartulli
2011-10-30  8:55 ` [B.A.T.M.A.N.] [PATCH 2/6] batman-adv: add a new log level for DAT-ARP debugging Antonio Quartulli
2011-10-30  8:55 ` [B.A.T.M.A.N.] [PATCH 3/6] batman-adv: Distributed ARP Table - create the DHT helper functions Antonio Quartulli
2011-10-31  0:08   ` Simon Wunderlich [this message]
2011-10-30  8:56 ` [B.A.T.M.A.N.] [PATCH 4/6] batman-adv: Distributed ARP Table - add ARP parsing functions Antonio Quartulli
2011-10-31  0:10   ` Simon Wunderlich
2011-11-01  9:14     ` Antonio Quartulli
2011-10-30  8:56 ` [B.A.T.M.A.N.] [PATCH 5/6] batman-adv: Distributed ARP Table - add snooping functions for ARP messages Antonio Quartulli
2011-10-30  9:18   ` Sven Eckelmann
2011-10-30  9:29     ` Antonio Quartulli
2011-10-31  0:12   ` Simon Wunderlich
2011-11-01  9:16     ` Antonio Quartulli
2011-10-30  8:56 ` [B.A.T.M.A.N.] [PATCH 6/6] batman-adv: Distributed ARP Table - increase default soft_iface ARP table timeout Antonio Quartulli
2011-10-31  0:03 ` [B.A.T.M.A.N.] [PATCH 0/6] DAT: Distributed ARP Table Simon Wunderlich
2011-10-31  9:26   ` Martin Hundebøll
2011-10-31  9:42     ` Marek Lindner
2011-10-31  9:48       ` Simon Wunderlich
2011-11-01  9:16         ` Antonio Quartulli
2011-10-31 18:53 ` Gus Wirth
2011-10-31 23:11   ` Simon Wunderlich
2011-11-01  9:10   ` Antonio Quartulli

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=20111031000841.GD10726@pandem0nium \
    --to=simon.wunderlich@s2003.tu-chemnitz.de \
    --cc=b.a.t.m.a.n@lists.open-mesh.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