Skip to contentSkip to conversation

NDP patches v3

B.A.T.M.A.N. In review Linus Lüssing 3 participants 20 messages Dec 14, 2010 – Dec 28, 2010 Kbuild

lore
Share & tools
lore
#0 lore raw

Hi everyone,

another small, but important update on the NDP patches:
* linearize NDP packet's skb before looking at its neighbor entries
* Avoid disabling bottom halves twice when receiving/processing OGMs

Cheers, Linus

#1 lore raw

PATCH 1/10 batman-adv: Creating new neighbor discovery packet

This patch creates the new neighbor discovery packet type (which is not actually being used with this patch). It will later be responsible to detect neighbors and calculate the link quality to them.

---
 aggregation.c       |   44 +++++++++++-----------
 aggregation.h       |    2 +-
 hard-interface.c    |   43 +++++++++++----------
 packet.h            |   28 ++++++++++----
 routing.c           |  101 ++++++++++++++++++++++++------------------------
 routing.h           |    2 +-
 send.c              |  106 ++++++++++++++++++++++++++-------------------------
 send.h              |    2 +-
 soft-interface.c    |   18 +++++----
 translation-table.c |    2 +-
 10 files changed, 183 insertions(+), 165 deletions(-)
aggregation.c +22 -22
index 0c92e3b..c158df2 100644
@@ -25,21 +25,21 @@
 #include "routing.h"
 
 /* calculate the size of the hna information for a given packet */
-static int hna_len(struct batman_packet *batman_packet)
+static int hna_len(struct batman_packet_ogm *batman_packet_ogm)
 {
-	return batman_packet->num_hna * ETH_ALEN;
+	return batman_packet_ogm->num_hna * ETH_ALEN;
 }
 
 /* return true if new_packet can be aggregated with forw_packet */
-static bool can_aggregate_with(struct batman_packet *new_batman_packet,
+static bool can_aggregate_with(struct batman_packet_ogm *new_batman_packet_ogm,
 			       int packet_len,
 			       unsigned long send_time,
 			       bool directlink,
 			       struct batman_if *if_incoming,
 			       struct forw_packet *forw_packet)
 {
-	struct batman_packet *batman_packet =
-		(struct batman_packet *)forw_packet->skb->data;
+	struct batman_packet_ogm *batman_packet_ogm =
+		(struct batman_packet_ogm *)forw_packet->skb->data;
 	int aggregated_bytes = forw_packet->packet_len + packet_len;
 
 	/**
@@ -68,8 +68,8 @@ static bool can_aggregate_with(struct batman_packet *new_batman_packet,
 		/* packets without direct link flag and high TTL
 		 * are flooded through the net  */
 		if ((!directlink) &&
-		    (!(batman_packet->flags & DIRECTLINK)) &&
-		    (batman_packet->ttl != 1) &&
+		    (!(batman_packet_ogm->flags & DIRECTLINK)) &&
+		    (batman_packet_ogm->ttl != 1) &&
 
 		    /* own packets originating non-primary
 		     * interfaces leave only that interface */
@@ -80,13 +80,13 @@ static bool can_aggregate_with(struct batman_packet *new_batman_packet,
 		/* if the incoming packet is sent via this one
 		 * interface only - we still can aggregate */
 		if ((directlink) &&
-		    (new_batman_packet->ttl == 1) &&
+		    (new_batman_packet_ogm->ttl == 1) &&
 		    (forw_packet->if_incoming == if_incoming) &&
 
 		    /* packets from direct neighbors or
 		     * own secondary interface packets
 		     * (= secondary interface packets in general) */
-		    (batman_packet->flags & DIRECTLINK ||
+		    (batman_packet_ogm->flags & DIRECTLINK ||
 		     (forw_packet->own &&
 		      forw_packet->if_incoming->if_num != 0)))
 			return true;
@@ -197,9 +197,9 @@ void add_bat_packet_to_list(struct bat_priv *bat_priv,
 	 */
 	struct forw_packet *forw_packet_aggr = NULL, *forw_packet_pos = NULL;
 	struct hlist_node *tmp_node;
-	struct batman_packet *batman_packet =
-		(struct batman_packet *)packet_buff;
-	bool direct_link = batman_packet->flags & DIRECTLINK ? 1 : 0;
+	struct batman_packet_ogm *batman_packet_ogm =
+		(struct batman_packet_ogm *)packet_buff;
+	bool direct_link = batman_packet_ogm->flags & DIRECTLINK ? 1 : 0;
 
 	/* find position for the packet in the forward queue */
 	spin_lock_bh(&bat_priv->forw_bat_list_lock);
@@ -207,7 +207,7 @@ void add_bat_packet_to_list(struct bat_priv *bat_priv,
 	if ((atomic_read(&bat_priv->aggregated_ogms)) && (!own_packet)) {
 		hlist_for_each_entry(forw_packet_pos, tmp_node,
 				     &bat_priv->forw_bat_list, list) {
-			if (can_aggregate_with(batman_packet,
+			if (can_aggregate_with(batman_packet_ogm,
 					       packet_len,
 					       send_time,
 					       direct_link,
@@ -249,25 +249,25 @@ void add_bat_packet_to_list(struct bat_priv *bat_priv,
 void receive_aggr_bat_packet(struct ethhdr *ethhdr, unsigned char *packet_buff,
 			     int packet_len, struct batman_if *if_incoming)
 {
-	struct batman_packet *batman_packet;
+	struct batman_packet_ogm *batman_packet_ogm;
 	int buff_pos = 0;
 	unsigned char *hna_buff;
 
-	batman_packet = (struct batman_packet *)packet_buff;
+	batman_packet_ogm = (struct batman_packet_ogm *)packet_buff;
 
 	do {
 		/* network to host order for our 32bit seqno, and the
 		   orig_interval. */
-		batman_packet->seqno = ntohl(batman_packet->seqno);
+		batman_packet_ogm->seqno = ntohl(batman_packet_ogm->seqno);
 
-		hna_buff = packet_buff + buff_pos + BAT_PACKET_LEN;
-		receive_bat_packet(ethhdr, batman_packet,
-				   hna_buff, hna_len(batman_packet),
+		hna_buff = packet_buff + buff_pos + BAT_PACKET_OGM_LEN;
+		receive_bat_packet(ethhdr, batman_packet_ogm,
+				   hna_buff, hna_len(batman_packet_ogm),
 				   if_incoming);
 
-		buff_pos += BAT_PACKET_LEN + hna_len(batman_packet);
-		batman_packet = (struct batman_packet *)
+		buff_pos += BAT_PACKET_OGM_LEN + hna_len(batman_packet_ogm);
+		batman_packet_ogm = (struct batman_packet_ogm *)
 			(packet_buff + buff_pos);
 	} while (aggregated_packet(buff_pos, packet_len,
-				   batman_packet->num_hna));
+				   batman_packet_ogm->num_hna));
 }
aggregation.h +1 -1
index 71a91b3..1a7a0b6 100644
@@ -27,7 +27,7 @@
 /* is there another aggregated packet here? */
 static inline int aggregated_packet(int buff_pos, int packet_len, int num_hna)
 {
-	int next_buff_pos = buff_pos + BAT_PACKET_LEN + (num_hna * ETH_ALEN);
+	int next_buff_pos = buff_pos + BAT_PACKET_OGM_LEN + (num_hna * ETH_ALEN);
 
 	return (next_buff_pos <= packet_len) &&
 		(next_buff_pos <= MAX_AGGREGATION_BYTES);
hard-interface.c +22 -21

102 lines not on this page · raw message

packet.h +20 -8
index b49fdf7..beb1b56 100644
@@ -24,12 +24,13 @@
 
 #define ETH_P_BATMAN  0x4305	/* unofficial/not registered Ethertype */
 
-#define BAT_PACKET       0x01
-#define BAT_ICMP         0x02
-#define BAT_UNICAST      0x03
-#define BAT_BCAST        0x04
-#define BAT_VIS          0x05
-#define BAT_UNICAST_FRAG 0x06
+#define BAT_PACKET_NDP   0x01
+#define BAT_PACKET_OGM   0x02
+#define BAT_ICMP         0x03
+#define BAT_UNICAST      0x04
+#define BAT_BCAST        0x05
+#define BAT_VIS          0x06
+#define BAT_UNICAST_FRAG 0x07
 
 /* this file is included by batctl which needs these defines */
 #define COMPAT_VERSION 12
@@ -51,7 +52,18 @@
 /* fragmentation defines */
 #define UNI_FRAG_HEAD 0x01
 
-struct batman_packet {
+/* Neighbor discovery packet */
+struct batman_packet_ndp {
+	uint8_t  packet_type;
+	uint8_t  version;  /* batman version field */
+	uint8_t  orig[6];
+	uint32_t seqno;
+	uint8_t  num_neighbors;
+	uint8_t  align[3];
+} __attribute__((packed));
+
+/* Originator message packet */
+struct batman_packet_ogm {
 	uint8_t  packet_type;
 	uint8_t  version;  /* batman version field */
 	uint8_t  flags;    /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
@@ -65,7 +77,7 @@ struct batman_packet {
 	uint8_t  align;
 } __attribute__((packed));
 
-#define BAT_PACKET_LEN sizeof(struct batman_packet)
+#define BAT_PACKET_OGM_LEN sizeof(struct batman_packet_ogm)
 
 struct icmp_packet {
 	uint8_t  packet_type;
routing.c +51 -50

289 lines not on this page · raw message

routing.h +1 -1
index f108f23..81e27d5 100644
@@ -26,7 +26,7 @@
 
 void slide_own_bcast_window(struct batman_if *batman_if);
 void receive_bat_packet(struct ethhdr *ethhdr,
-				struct batman_packet *batman_packet,
+				struct batman_packet_ogm *batman_packet_ogm,
 				unsigned char *hna_buff, int hna_buff_len,
 				struct batman_if *if_incoming);
 void update_routes(struct bat_priv *bat_priv, struct orig_node *orig_node,
send.c +54 -52

243 lines not on this page · raw message

send.h +1 -1
index c4cefa8..acf59e7 100644
@@ -30,7 +30,7 @@ int send_skb_packet(struct sk_buff *skb,
 void schedule_own_packet(struct batman_if *batman_if);
 void schedule_forward_packet(struct orig_node *orig_node,
 			     struct ethhdr *ethhdr,
-			     struct batman_packet *batman_packet,
+			     struct batman_packet_ogm *batman_packet_ogm,
 			     uint8_t directlink, int hna_buff_len,
 			     struct batman_if *if_outgoing);
 int add_bcast_packet_to_list(struct bat_priv *bat_priv, struct sk_buff *skb);
soft-interface.c +10 -8
index e89ede1..ac65bc1 100644
@@ -221,28 +221,30 @@ static void softif_batman_recv(struct sk_buff *skb, struct net_device *dev,
 {
 	struct bat_priv *bat_priv = netdev_priv(dev);
 	struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
-	struct batman_packet *batman_packet;
+	struct batman_packet_ogm *batman_packet_ogm;
 	struct softif_neigh *softif_neigh, *softif_neigh_tmp;
 
 	if (ntohs(ethhdr->h_proto) == ETH_P_8021Q)
-		batman_packet = (struct batman_packet *)
+		batman_packet_ogm = (struct batman_packet_ogm *)
 					(skb->data + ETH_HLEN + VLAN_HLEN);
 	else
-		batman_packet = (struct batman_packet *)(skb->data + ETH_HLEN);
+		batman_packet_ogm = (struct batman_packet_ogm *)
+					(skb->data + ETH_HLEN);
 
-	if (batman_packet->version != COMPAT_VERSION)
+	if (batman_packet_ogm->version != COMPAT_VERSION)
 		goto err;
 
-	if (batman_packet->packet_type != BAT_PACKET)
+	if (batman_packet_ogm->packet_type != BAT_PACKET_OGM)
 		goto err;
 
-	if (!(batman_packet->flags & PRIMARIES_FIRST_HOP))
+	if (!(batman_packet_ogm->flags & PRIMARIES_FIRST_HOP))
 		goto err;
 
-	if (is_my_mac(batman_packet->orig))
+	if (is_my_mac(batman_packet_ogm->orig))
 		goto err;
 
-	softif_neigh = softif_neigh_get(bat_priv, batman_packet->orig, vid);
+	softif_neigh = softif_neigh_get(bat_priv, batman_packet_ogm->orig,
+					vid);
 
 	if (!softif_neigh)
 		goto err;
translation-table.c +1 -1
index 4b0a107..6d5d3ec 100644
@@ -77,7 +77,7 @@ void hna_local_add(struct net_device *soft_iface, uint8_t *addr)
 	   space in batman_packet->num_hna That also should give a limit to
 	   MAC-flooding. */
 	required_bytes = (bat_priv->num_local_hna + 1) * ETH_ALEN;
-	required_bytes += BAT_PACKET_LEN;
+	required_bytes += BAT_PACKET_OGM_LEN;
 
 	if ((required_bytes > ETH_DATA_LEN) ||
 	    (atomic_read(&bat_priv->aggregated_ogms) &&
Signature · 1 line
1.7.1
#2 lore raw

Re: [B.A.T.M.A.N.] [PATCH 01/10] batman-adv: Creating new neighbor discovery packet

Quoted 3 lines · On Tuesday 14 December 2010 10:58:07 Linus Lüssing wrote:

This patch creates the new neighbor discovery packet type (which is not actually being used with this patch). It will later be responsible to detect neighbors and calculate the link quality to them.

In fact, most of the patch renames batman_packet to batman_packet_ogm. Why not making this a rename patch only ? The next patch still renames some more stuff which could go into this patch as well (e.g. schedule_own_packet).

How about renaming batman_packet to batman_ogm and batman_packet_ndp to batman_ndp ? Or ogm_packet / ndp_packet ? The 80 chars per line limitation does not make these long names very handy ...

packet.h line 33

Quoted 13 lines
packet.h +7 -6
-#define BAT_PACKET       0x01
-#define BAT_ICMP         0x02
-#define BAT_UNICAST      0x03
-#define BAT_BCAST        0x04
-#define BAT_VIS          0x05
-#define BAT_UNICAST_FRAG 0x06
+#define BAT_PACKET_NDP   0x01
+#define BAT_PACKET_OGM   0x02
+#define BAT_ICMP         0x03
+#define BAT_UNICAST      0x04
+#define BAT_BCAST        0x05
+#define BAT_VIS          0x06
+#define BAT_UNICAST_FRAG 0x07

Although I like this reordering (I would like to see BAT_UNICAST followed by BAT_UNICAST_FRAG) I think we can't easily touch this without annoying the wireshark folks. Maybe we don't care because they hate us already ?

packet.h line 63

Quoted 10 lines
packet.h +9 -1
-struct batman_packet {
+/* Neighbor discovery packet */
+struct batman_packet_ndp {
+	uint8_t  packet_type;
+	uint8_t  version;  /* batman version field */
+	uint8_t  orig[6];
+	uint32_t seqno;
+	uint8_t  num_neighbors;
+	uint8_t  align[3];
+} __attribute__((packed));

This should go into one of the later patches where it is used.

Cheers,
Marek

#3 lore raw

Re: [B.A.T.M.A.N.] [PATCH 01/10] batman-adv: Creating new neighbor discovery packet

Quoted 9 lines
Quoted 9 lines
packet.h +3 -6
-#define BAT_PACKET       0x01
-#define BAT_ICMP         0x02
-#define BAT_UNICAST      0x03
-#define BAT_BCAST        0x04
-#define BAT_VIS          0x05
-#define BAT_UNICAST_FRAG 0x06
+#define BAT_PACKET_NDP   0x01
+#define BAT_PACKET_OGM   0x02
+#define BAT_ICMP         0x03
Quoted 8 lines

packet.h line 33

Quoted 4 lines
packet.h +4 -0
+#define BAT_UNICAST      0x04
+#define BAT_BCAST        0x05
+#define BAT_VIS          0x06
+#define BAT_UNICAST_FRAG 0x07

Although I like this reordering (I would like to see BAT_UNICAST followed by BAT_UNICAST_FRAG) I think we can't easily touch this without annoying the wireshark folks. Maybe we don't care because they hate us already ?

It will also be interesting to see what David Miller says the first time you increment the version number, or make some other backward incompatible change.

Andrew

#4 lore raw

PATCH 2/10 batman-adv: Adding jittering methods for ndp

In reply to Linus Lüssing

This patch adds a function for fetching and jittering an ndp interval from batman-if structure. Needed later for timing the neighbor discovery packets.

---
 hard-interface.c |    2 +-
 routing.c        |    2 +-
 send.c           |   18 +++++++++++++-----
 send.h           |    3 ++-
 types.h          |    1 +
 5 files changed, 18 insertions(+), 8 deletions(-)
hard-interface.c +1 -1
index 784c475..da7b9a9 100644
@@ -360,7 +360,7 @@ int hardif_enable_interface(struct batman_if *batman_if, char *iface_name)
 			batman_if->net_dev->name);
 
 	/* begin scheduling originator messages on that interface */
-	schedule_own_packet(batman_if);
+	schedule_own_ogm_packet(batman_if);
 
 out:
 	return 0;
routing.c +1 -1
index a9406ba..7ebb631 100644
@@ -561,7 +561,7 @@ void receive_bat_packet(struct ethhdr *ethhdr,
 	if (batman_packet_ogm->packet_type != BAT_PACKET_OGM)
 		return;
 
-	/* could be changed by schedule_own_packet() */
+	/* could be changed by schedule_own_ogm_packet() */
 	if_incoming_seqno = atomic_read(&if_incoming->seqno);
 
 	has_directlink_flag = (batman_packet_ogm->flags & DIRECTLINK ? 1 : 0);
send.c +13 -5
index eb9c1e3..910411c 100644
@@ -40,8 +40,16 @@ static uint8_t hop_penalty(const uint8_t tq, struct bat_priv *bat_priv)
 	return (tq * (TQ_MAX_VALUE - hop_penalty)) / (TQ_MAX_VALUE);
 }
 
-/* when do we schedule our own packet to be sent */
-static unsigned long own_send_time(struct bat_priv *bat_priv)
+/* when do we schedule our own neighbor discovery packet to be sent */
+unsigned long own_ndp_send_time(struct batman_if *batman_if)
+{
+	return jiffies + msecs_to_jiffies(
+		   atomic_read(&batman_if->ndp_interval) -
+		   JITTER + (random32() % 2*JITTER));
+}
+
+/* when do we schedule our own originator packet to be sent */
+static unsigned long own_ogm_send_time(struct bat_priv *bat_priv)
 {
 	return jiffies + msecs_to_jiffies(
 		   atomic_read(&bat_priv->orig_interval) -
@@ -243,7 +251,7 @@ static void rebuild_batman_packet_ogm(struct bat_priv *bat_priv,
 	}
 }
 
-void schedule_own_packet(struct batman_if *batman_if)
+void schedule_own_ogm_packet(struct batman_if *batman_if)
 {
 	struct bat_priv *bat_priv = netdev_priv(batman_if->soft_iface);
 	unsigned long send_time;
@@ -296,7 +304,7 @@ void schedule_own_packet(struct batman_if *batman_if)
 	atomic_inc(&batman_if->seqno);
 
 	slide_own_bcast_window(batman_if);
-	send_time = own_send_time(bat_priv);
+	send_time = own_ogm_send_time(bat_priv);
 	add_bat_packet_to_list(bat_priv,
 			       batman_if->packet_buff,
 			       batman_if->packet_len,
@@ -513,7 +521,7 @@ void send_outstanding_bat_packet(struct work_struct *work)
 	 * shutting down
 	 */
 	if (forw_packet->own)
-		schedule_own_packet(forw_packet->if_incoming);
+		schedule_own_ogm_packet(forw_packet->if_incoming);
 
 out:
 	/* don't count own packet */
send.h +2 -1
index acf59e7..b626ddf 100644
@@ -27,7 +27,8 @@
 int send_skb_packet(struct sk_buff *skb,
 				struct batman_if *batman_if,
 				uint8_t *dst_addr);
-void schedule_own_packet(struct batman_if *batman_if);
+unsigned long own_ndp_send_time(struct batman_if *batman_if);
+void schedule_own_ogm_packet(struct batman_if *batman_if);
 void schedule_forward_packet(struct orig_node *orig_node,
 			     struct ethhdr *ethhdr,
 			     struct batman_packet_ogm *batman_packet_ogm,
types.h +1 -0
index 1d00849..8921e20 100644
@@ -47,6 +47,7 @@ struct batman_if {
 	struct packet_type batman_adv_ptype;
 	struct net_device *soft_iface;
 	struct rcu_head rcu;
+	atomic_t ndp_interval;
 };
 
 /**
Signature · 1 line
1.7.1
#5 lore raw

PATCH 3/10 batman-adv: Adding workqueue for new ndp packets

In reply to Linus Lüssing

The new neighbor discovery packets will later need their own interval per interface. For instance on a wifi interface which has regularly changing link qualities the ndp interval should be faster than on a static cable link where we would need some probes from time to time only.

This patch adds a workqueue per interface used by batman-adv. When an interface is active, a ndp_send() with the according batman_if structure will be called every second now.

---
 Makefile.kbuild  |    1 +
 hard-interface.c |    6 ++++++
 ndp.c            |   44 ++++++++++++++++++++++++++++++++++++++++++++
 ndp.h            |    6 ++++++
 types.h          |    2 ++
 5 files changed, 59 insertions(+), 0 deletions(-)
 create mode 100644 ndp.c
 create mode 100644 ndp.h
Makefile.kbuild +1 -0
index e99c198..094eb31 100644
@@ -42,6 +42,7 @@ batman-adv-y += hard-interface.o
 batman-adv-y += hash.o
 batman-adv-y += icmp_socket.o
 batman-adv-y += main.o
+batman-adv-y += ndp.o
 batman-adv-y += originator.o
 batman-adv-y += ring_buffer.o
 batman-adv-y += routing.o
hard-interface.c +6 -0
index da7b9a9..cb81c13 100644
@@ -26,6 +26,7 @@
 #include "translation-table.h"
 #include "routing.h"
 #include "bat_sysfs.h"
+#include "ndp.h"
 #include "originator.h"
 #include "hash.h"
 
@@ -260,6 +261,7 @@ static void hardif_activate_interface(struct batman_if *batman_if)
 		 batman_if->net_dev->name);
 
 	update_min_mtu(batman_if->soft_iface);
+	start_ndp_timer(batman_if);
 	return;
 }
 
@@ -274,6 +276,7 @@ static void hardif_deactivate_interface(struct batman_if *batman_if)
 	bat_info(batman_if->soft_iface, "Interface deactivated: %s\n",
 		 batman_if->net_dev->name);
 
+	stop_ndp_timer(batman_if);
 	update_min_mtu(batman_if->soft_iface);
 }
 
@@ -328,6 +331,8 @@ int hardif_enable_interface(struct batman_if *batman_if, char *iface_name)
 
 	atomic_set(&batman_if->seqno, 1);
 	atomic_set(&batman_if->frag_seqno, 1);
+	ndp_init(batman_if);
+
 	bat_info(batman_if->soft_iface, "Adding interface: %s\n",
 		 batman_if->net_dev->name);
 
@@ -381,6 +386,7 @@ void hardif_disable_interface(struct batman_if *batman_if)
 
 	bat_info(batman_if->soft_iface, "Removing interface: %s\n",
 		 batman_if->net_dev->name);
+	ndp_free(batman_if);
 	dev_remove_pack(&batman_if->batman_adv_ptype);
 	kref_put(&batman_if->refcount, hardif_free_ref);
 
ndp.c new file +44 -0

44 lines not on this page · raw message

ndp.h new file +6 -0
new file mode 100644
index 0000000..de85910
@@ -0,0 +1,6 @@
+
+void start_ndp_timer(struct batman_if *batman_if);
+void stop_ndp_timer(struct batman_if *batman_if);
+
+int ndp_init(struct batman_if *batman_if);
+void ndp_free(struct batman_if *batman_if);
types.h +2 -0
index 8921e20..e8dfdf6 100644
@@ -48,6 +48,8 @@ struct batman_if {
 	struct net_device *soft_iface;
 	struct rcu_head rcu;
 	atomic_t ndp_interval;
+	atomic_t ndp_seqno;
+	struct delayed_work ndp_wq;
 };
 
 /**
Signature · 1 line
1.7.1
#6 lore raw

Re: [B.A.T.M.A.N.] [PATCH 03/10] batman-adv: Adding workqueue for new ndp packets

ndp.c line 2

Quoted 8 lines · On Tuesday 14 December 2010 10:58:09 Linus Lüssing wrote:
ndp.c new file +2 -0
new file mode 100644
index 0000000..2dfb06d
@@ -0,0 +1,44 @@
+#include "main.h"
+#include "send.h"

I think it would make more sense to have own_ndp_send_time() in ndp.c as it is not used anywhere else.
We don't have to repeat the mistakes from the past. ;-)

ndp.c line 16

Quoted 13 lines
ndp.c new file +13 -0
+
+void start_ndp_timer(struct batman_if *batman_if)
+{
+	// adding some jitter
+	unsigned long ndp_interval = own_ndp_send_time(batman_if);
+	queue_delayed_work(bat_event_workqueue, &batman_if->ndp_wq,
+			   ndp_interval - jiffies);
+}
+
+void stop_ndp_timer(struct batman_if *batman_if)
+{
+	cancel_delayed_work_sync(&batman_if->ndp_wq);
+}

Would you mind renaming these functions, so that they begin with ndp_*() ? Checkpatch does not like C99 style comments ("//").

ndp.c line 39

Quoted 8 lines
ndp.c new file +8 -0
+int ndp_init(struct batman_if *batman_if)
+{
+	atomic_set(&batman_if->ndp_interval, 500);
+	atomic_set(&batman_if->ndp_seqno, 0);
+	INIT_DELAYED_WORK(&batman_if->ndp_wq, ndp_send);
+
+	return 0;
+}

Wouldn't it be better to initialize the ndp_interval in hardif_add_interface(), so that an interface disable/enable does not overwrite user specified ndp intervals ?

Cheers,
Marek

#7 lore raw

PATCH 4/10 batman-adv: Send neighbor discovery packets

In reply to Linus Lüssing

This patch makes use of the previously introduced periodic tasks per interface and actually sends neighbor discovery packets on these now.
Note: The TQ values of each neighbor are not being added yet to these NDPs and also no evaluation of these packets is being done.

---
 hard-interface.c |    5 ++++-
 ndp.c            |   36 +++++++++++++++++++++++++++++++++++-
 types.h          |    5 +++++
 3 files changed, 44 insertions(+), 2 deletions(-)
hard-interface.c +4 -1
index cb81c13..887f794 100644
@@ -284,6 +284,7 @@ int hardif_enable_interface(struct batman_if *batman_if, char *iface_name)
 {
 	struct bat_priv *bat_priv;
 	struct batman_packet_ogm *batman_packet_ogm;
+	int ret;
 
 	if (batman_if->if_status != IF_NOT_IN_USE)
 		goto out;
@@ -331,7 +332,9 @@ int hardif_enable_interface(struct batman_if *batman_if, char *iface_name)
 
 	atomic_set(&batman_if->seqno, 1);
 	atomic_set(&batman_if->frag_seqno, 1);
-	ndp_init(batman_if);
+	ret = ndp_init(batman_if);
+	if (ret)
+		goto err;
 
 	bat_info(batman_if->soft_iface, "Adding interface: %s\n",
 		 batman_if->net_dev->name);
ndp.c +35 -1
index 2dfb06d..94d1971 100644
@@ -20,10 +20,21 @@ static void ndp_send(struct work_struct *work)
 	struct batman_if *batman_if = container_of(work, struct batman_if,
 							ndp_wq.work);
 	struct bat_priv *bat_priv = netdev_priv(batman_if->soft_iface);
+	struct batman_packet_ndp *ndp_packet;
+	struct sk_buff *skb;
+
+	skb = skb_clone(batman_if->ndp_skb, GFP_ATOMIC);
+	ndp_packet = (struct batman_packet_ndp*)skb->data;
+	ndp_packet->seqno = htonl(atomic_read(&batman_if->ndp_seqno));
+	ndp_packet->num_neighbors = 0;
+	memcpy(ndp_packet->orig, bat_priv->primary_if->net_dev->dev_addr,
+	       ETH_ALEN);
 
 	bat_dbg(DBG_BATMAN, bat_priv,
 		"batman-adv:Sending ndp packet on interface %s, seqno %d\n",
-		batman_if->net_dev, atomic_read(&batman_if->ndp_seqno));
+		batman_if->net_dev, ntohl(ndp_packet->seqno));
+
+	send_skb_packet(skb, batman_if, broadcast_addr);
 
 	atomic_inc(&batman_if->ndp_seqno);
 	start_ndp_timer(batman_if);
@@ -31,14 +42,37 @@ static void ndp_send(struct work_struct *work)
 
 int ndp_init(struct batman_if *batman_if)
 {
+	struct batman_packet_ndp *ndp_packet;
+
 	atomic_set(&batman_if->ndp_interval, 500);
 	atomic_set(&batman_if->ndp_seqno, 0);
+
+	batman_if->ndp_skb =
+		dev_alloc_skb(ETH_DATA_LEN + sizeof(struct ethhdr));
+	if (!batman_if->ndp_skb) {
+		printk(KERN_ERR "batman-adv: Can't add "
+			"local interface packet (%s): out of memory\n",
+			batman_if->net_dev->name);
+		goto err;
+	}
+	skb_reserve(batman_if->ndp_skb, sizeof(struct ethhdr) +
+					sizeof(struct batman_packet_ndp));
+	ndp_packet = (struct batman_packet_ndp*)
+		skb_push(batman_if->ndp_skb, sizeof(struct batman_packet_ndp));
+	memset(ndp_packet, 0, sizeof(struct batman_packet_ndp));
+
+	ndp_packet->packet_type = BAT_PACKET_NDP;
+	ndp_packet->version = COMPAT_VERSION;
+
 	INIT_DELAYED_WORK(&batman_if->ndp_wq, ndp_send);
 
 	return 0;
+err:
+	return 1;
 }
 
 void ndp_free(struct batman_if *batman_if)
 {
 	stop_ndp_timer(batman_if);
+	dev_kfree_skb(batman_if->ndp_skb);
 }
types.h +5 -0
index e8dfdf6..c5a26a7 100644
@@ -49,6 +49,7 @@ struct batman_if {
 	struct rcu_head rcu;
 	atomic_t ndp_interval;
 	atomic_t ndp_seqno;
+	struct sk_buff *ndp_skb;
 	struct delayed_work ndp_wq;
 };
 
@@ -122,6 +123,10 @@ struct neigh_node {
 	struct batman_if *if_incoming;
 };
 
+struct neigh_entry {
+	uint8_t addr[ETH_ALEN];
+	uint8_t rq;
+};
 
 struct bat_priv {
 	atomic_t mesh_state;
Signature · 1 line
1.7.1
#8 lore raw

Re: [B.A.T.M.A.N.] [PATCH 04/10] batman-adv: Send neighbor discovery packets

hard-interface.c int hardif_enable_interface(struct batman_if · line 338

Quoted 9 lines · On Tuesday 14 December 2010 10:58:10 Linus Lüssing wrote:
hard-interface.c +3 -1
@@ -331,7 +332,9 @@ int hardif_enable_interface(struct batman_if
 *batman_if, char *iface_name)
 
 	atomic_set(&batman_if->seqno, 1);
 	atomic_set(&batman_if->frag_seqno, 1);
-	ndp_init(batman_if);
+	ret = ndp_init(batman_if);
+	if (ret)
+		goto err;

This introduces a potential memory leak, next to other problems. If the code jumps to "err" batman_if->packet_buff is not free()'d, bat_priv->num_ifaces is wrong, the orig_hash has one interface too much, etc. Please check the error handling here and make sure that there is a clean rollback.

ndp.c static void ndp_send(struct work_struct *work) · line 31

Quoted 6 lines
ndp.c +6 -0
+	skb = skb_clone(batman_if->ndp_skb, GFP_ATOMIC);
+	ndp_packet = (struct batman_packet_ndp*)skb->data;
+	ndp_packet->seqno = htonl(atomic_read(&batman_if->ndp_seqno));
+	ndp_packet->num_neighbors = 0;
+	memcpy(ndp_packet->orig, bat_priv->primary_if->net_dev->dev_addr,
+	       ETH_ALEN);

I don't think you want to use skb_clone() here as it "only" copies the sk_buff and not skb->data. That means all threads write on the same skb->data ...

types.h struct neigh_node { · line 129

Quoted 4 lines
types.h +4 -0
+struct neigh_entry {
+	uint8_t addr[ETH_ALEN];
+	uint8_t rq;
+};

Again, this struct is not used and can be added later.

Checkpatch gives 2 errors ..

Cheers,
Marek

#9 lore raw

PATCH 5/10 batman-adv: Creating neighbor structures, updating LQs

In reply to Linus Lüssing

It will now be checked if a neighbor discovery packet from a new neighbor on a certain interface has been received. If so, structures in memory will be allocated for further seqno-tracking and RQ calculations, and TQ reception, which will be updated frequently from this commit on.

---
 hard-interface.c |    5 ++
 ndp.c            |  142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ndp.h            |    5 ++
 routing.c        |   42 ++++++++++++++++-
 routing.h        |    1 +
 types.h          |    5 ++
 6 files changed, 199 insertions(+), 1 deletions(-)
hard-interface.c +5 -0
index 887f794..820121a 100644
@@ -608,6 +608,11 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
 	 * the supplied skb. if not, we have to free the skb. */
 
 	switch (batman_packet_ogm->packet_type) {
+		/* batman neighbor discovery protocol packet */
+	case BAT_PACKET_NDP:
+		ret = recv_ndp_packet(skb, batman_if);
+		break;
+
 		/* batman originator packet */
 	case BAT_PACKET_OGM:
 		ret = recv_bat_packet(skb, batman_if);
ndp.c +142 -0

169 lines not on this page · raw message

ndp.h +5 -0
index de85910..35146ce 100644
@@ -4,3 +4,8 @@ void stop_ndp_timer(struct batman_if *batman_if);
 
 int ndp_init(struct batman_if *batman_if);
 void ndp_free(struct batman_if *batman_if);
+
+uint8_t ndp_fetch_tq(struct batman_packet_ndp *packet,
+		 uint8_t *my_if_addr);
+int ndp_update_neighbor(uint8_t my_tq, uint32_t seqno,
+			struct batman_if *batman_if, uint8_t *neigh_addr);
routing.c +41 -1

54 lines not on this page · raw message

routing.h +1 -0
index 81e27d5..a319714 100644
@@ -39,6 +39,7 @@ int recv_unicast_packet(struct sk_buff *skb, struct batman_if *recv_if);
 int recv_ucast_frag_packet(struct sk_buff *skb, struct batman_if *recv_if);
 int recv_bcast_packet(struct sk_buff *skb, struct batman_if *recv_if);
 int recv_vis_packet(struct sk_buff *skb, struct batman_if *recv_if);
+int recv_ndp_packet(struct sk_buff *skb, struct batman_if *recv_if);
 int recv_bat_packet(struct sk_buff *skb, struct batman_if *recv_if);
 struct neigh_node *find_router(struct bat_priv *bat_priv,
 		struct orig_node *orig_node, struct batman_if *recv_if);
types.h +5 -0
index c5a26a7..d3efb53 100644
@@ -51,6 +51,8 @@ struct batman_if {
 	atomic_t ndp_seqno;
 	struct sk_buff *ndp_skb;
 	struct delayed_work ndp_wq;
+	struct list_head neigh_list;
+	spinlock_t neigh_list_lock;
 };
 
 /**
@@ -112,6 +114,9 @@ struct neigh_node {
 	struct list_head list;
 	uint8_t addr[ETH_ALEN];
 	uint8_t real_packet_count;
+	uint8_t rq;
+	uint32_t last_rq_seqno;
+	TYPE_OF_WORD rq_real_bits[NUM_WORDS];
 	uint8_t tq_recv[TQ_GLOBAL_WINDOW_SIZE];
 	uint8_t tq_index;
 	uint8_t tq_avg;
Signature · 1 line
1.7.1
#10 lore raw

[B.A.T.M.A.N.] linearize skb earlier

The skb has to be linearized before setting any pointers to avoid etthdr/packet pointing to the wrong, outdated memory addresses.

Cheers, Linus

#11 lore raw

PATCH v2 5/10 batman-adv: Creating neighbor structures, updating LQs

In reply to Linus Lüssing

It will now be checked if a neighbor discovery packet from a new neighbor on a certain interface has been received. If so, structures in memory will be allocated for further seqno-tracking and RQ calculations, and TQ reception, which will be updated frequently from this commit on.

---
 hard-interface.c |    5 ++
 ndp.c            |  142 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ndp.h            |    5 ++
 routing.c        |   42 ++++++++++++++++-
 routing.h        |    1 +
 types.h          |    5 ++
 6 files changed, 199 insertions(+), 1 deletions(-)
hard-interface.c +5 -0
index 887f794..820121a 100644
@@ -608,6 +608,11 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
 	 * the supplied skb. if not, we have to free the skb. */
 
 	switch (batman_packet_ogm->packet_type) {
+		/* batman neighbor discovery protocol packet */
+	case BAT_PACKET_NDP:
+		ret = recv_ndp_packet(skb, batman_if);
+		break;
+
 		/* batman originator packet */
 	case BAT_PACKET_OGM:
 		ret = recv_bat_packet(skb, batman_if);
ndp.c +142 -0

169 lines not on this page · raw message

ndp.h +5 -0
index de85910..35146ce 100644
@@ -4,3 +4,8 @@ void stop_ndp_timer(struct batman_if *batman_if);
 
 int ndp_init(struct batman_if *batman_if);
 void ndp_free(struct batman_if *batman_if);
+
+uint8_t ndp_fetch_tq(struct batman_packet_ndp *packet,
+		 uint8_t *my_if_addr);
+int ndp_update_neighbor(uint8_t my_tq, uint32_t seqno,
+			struct batman_if *batman_if, uint8_t *neigh_addr);
routing.c +41 -1

54 lines not on this page · raw message

routing.h +1 -0
index 81e27d5..a319714 100644
@@ -39,6 +39,7 @@ int recv_unicast_packet(struct sk_buff *skb, struct batman_if *recv_if);
 int recv_ucast_frag_packet(struct sk_buff *skb, struct batman_if *recv_if);
 int recv_bcast_packet(struct sk_buff *skb, struct batman_if *recv_if);
 int recv_vis_packet(struct sk_buff *skb, struct batman_if *recv_if);
+int recv_ndp_packet(struct sk_buff *skb, struct batman_if *recv_if);
 int recv_bat_packet(struct sk_buff *skb, struct batman_if *recv_if);
 struct neigh_node *find_router(struct bat_priv *bat_priv,
 		struct orig_node *orig_node, struct batman_if *recv_if);
types.h +5 -0
index c5a26a7..d3efb53 100644
@@ -51,6 +51,8 @@ struct batman_if {
 	atomic_t ndp_seqno;
 	struct sk_buff *ndp_skb;
 	struct delayed_work ndp_wq;
+	struct list_head neigh_list;
+	spinlock_t neigh_list_lock;
 };
 
 /**
@@ -112,6 +114,9 @@ struct neigh_node {
 	struct list_head list;
 	uint8_t addr[ETH_ALEN];
 	uint8_t real_packet_count;
+	uint8_t rq;
+	uint32_t last_rq_seqno;
+	TYPE_OF_WORD rq_real_bits[NUM_WORDS];
 	uint8_t tq_recv[TQ_GLOBAL_WINDOW_SIZE];
 	uint8_t tq_index;
 	uint8_t tq_avg;
Signature · 1 line
1.7.1
#12 lore raw

Re: [B.A.T.M.A.N.] [PATCHv2 05/10] batman-adv: Creating neighbor structures, updating LQs

Quoted 5 lines · On Wednesday 15 December 2010 18:09:29 Linus Lüssing wrote:

It will now be checked if a neighbor discovery packet from a new neighbor on a certain interface has been received. If so, structures in memory will be allocated for further seqno-tracking and RQ calculations, and TQ reception, which will be updated frequently from this commit on.

Checkpatch found 8 errors - please make all your patches "checkpatch clean". I also noticed that the new ndp files ndp.c / ndp.h lack a proper licence header.

ndp.c line 4

Quoted 5 lines
ndp.c +1 -0
@@ -1,6 +1,8 @@
 #include "main.h"
 #include "send.h"
 #include "ndp.h"
+#include "soft-interface.h"

This include is not necessary as far as I can tell.

Quoted 4 lines
ndp.c +4 -0
+int ndp_update_neighbor(uint8_t my_tq, uint32_t seqno,
+			struct batman_if *batman_if, uint8_t *neigh_addr)
+{
+	struct bat_priv *bat_priv = netdev_priv(batman_if->soft_iface);

ndp.c void ndp_free(struct batman_if *batman_if) · line 200

Quoted 10 lines
ndp.c +10 -0
+	struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL;
+	int ret = 1;
+
+	spin_lock_bh(&batman_if->neigh_list_lock);
+	// old neighbor?
+	list_for_each_entry(tmp_neigh_node, &batman_if->neigh_list, list) {
+		if (!compare_orig(tmp_neigh_node->addr, neigh_addr))
+			continue;
+
+		neigh_node = tmp_neigh_node;

A "break" could be added here.

Quoted 10 lines
ndp.c +10 -0
+	}
+
+	// new neighbor?
+	if (!neigh_node) {
+		neigh_node = ndp_create_neighbor(my_tq, seqno, neigh_addr,
+						 bat_priv);
+		if (!neigh_node)
+			goto ret;
+
+		list_add_tail(&neigh_node->list, &batman_if->neigh_list);

ndp.c void ndp_free(struct batman_if *batman_if) · line 220

Quoted 10 lines
ndp.c +10 -0
+	}
+
+	ndp_update_neighbor_lq(my_tq, seqno, neigh_node, bat_priv);
+
+	ret = 0;
+
+ret:
+	spin_unlock_bh(&batman_if->neigh_list_lock);
+	return ret;
+}

Instead of holding a spinlock all the time to protect a single neigh_node pointer you should protect the NDP neighbor list with RCU locks and the pointers with refcounting.

routing.c void receive_bat_packet(struct ethhdr *ethhdr, · line 798

Quoted 7 lines
routing.c +7 -0
+	ret = ndp_update_neighbor(my_tq, ntohl(packet->seqno),
+					batman_if, ethhdr->h_source);
+	if (ret)
+		return NET_RX_DROP;
+
+	kfree_skb(skb);
+	return NET_RX_SUCCESS;

Why not simply returning NET_RX_DROP ?

types.h struct batman_if { · line 55

Quoted 2 lines
types.h +2 -0
+	struct list_head neigh_list;
+	spinlock_t neigh_list_lock;

We already have a neigh_list and a neigh_list_lock. Either the old one gets removed or we should pick another name to avoid confusion.

types.h struct neigh_node { · line 119

Quoted 1 line
types.h +1 -0
+	TYPE_OF_WORD rq_real_bits[NUM_WORDS];

rq_real_bits is not a very good name. I know, the current OGM code uses the same bad name but I believe we can safely break with the tradition here. How about something more descriptive like "rq_ndp_window" ?

Cheers,
Marek

#13 lore raw

PATCH 6/10 batman-adv: Purge outdated ndp neighbours

In reply to Linus Lüssing

If no new packet has been received from a neighbour for a while, then delete it from memory.

---
 ndp.c        |   25 +++++++++++++++++++++++++
 ndp.h        |    1 +
 originator.c |    2 ++
 3 files changed, 28 insertions(+), 0 deletions(-)
ndp.c +25 -0
index 408dd70..80b30f1 100644
@@ -184,6 +184,31 @@ static struct neigh_node *ndp_create_neighbor(uint8_t my_tq, uint32_t seqno,
 	return neigh_node;
 }
 
+void ndp_purge_neighbors(void)
+{
+	struct neigh_node *neigh_node, *neigh_node_tmp;
+	struct batman_if *batman_if;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(batman_if, &if_list, list) {
+		if (batman_if->if_status != IF_ACTIVE)
+			continue;
+
+		spin_lock_bh(&batman_if->neigh_list_lock);
+		list_for_each_entry_safe(neigh_node, neigh_node_tmp,
+					 &batman_if->neigh_list, list) {
+			if (time_before(jiffies,
+			    neigh_node->last_valid + PURGE_TIMEOUT * HZ))
+				continue;
+
+			list_del(&neigh_node->list);
+			kfree(neigh_node);
+		}
+		spin_unlock_bh(&batman_if->neigh_list_lock);
+	}
+	rcu_read_unlock();
+}
+
 int ndp_update_neighbor(uint8_t my_tq, uint32_t seqno,
 			struct batman_if *batman_if, uint8_t *neigh_addr)
 {
ndp.h +1 -0
index 35146ce..5679f36 100644
@@ -7,5 +7,6 @@ void ndp_free(struct batman_if *batman_if);
 
 uint8_t ndp_fetch_tq(struct batman_packet_ndp *packet,
 		 uint8_t *my_if_addr);
+void ndp_purge_neighbors(void);
 int ndp_update_neighbor(uint8_t my_tq, uint32_t seqno,
 			struct batman_if *batman_if, uint8_t *neigh_addr);
originator.c +2 -0
index 89ec021..ad31bf7 100644
@@ -22,6 +22,7 @@
 /* increase the reference counter for this originator */
 
 #include "main.h"
+#include "ndp.h"
 #include "originator.h"
 #include "hash.h"
 #include "translation-table.h"
@@ -307,6 +308,7 @@ static void purge_orig(struct work_struct *work)
 		container_of(delayed_work, struct bat_priv, orig_work);
 
 	_purge_orig(bat_priv);
+	ndp_purge_neighbors();
 	start_purge_timer(bat_priv);
 }
 
Signature · 1 line
1.7.1
#14 lore raw

Re: [B.A.T.M.A.N.] [PATCH 06/10] batman-adv: Purge outdated ndp neighbours

ndp.c static struct neigh_node *ndp_create_neighbor(uint8_t my_tq, uint32_t seqno, · line 202

Quoted 5 lines · On Tuesday 14 December 2010 10:58:12 Linus Lüssing wrote:
ndp.c +5 -0
+               list_for_each_entry_safe(neigh_node, neigh_node_tmp,
+                                        &batman_if->neigh_list, list) {
+                       if (time_before(jiffies,
+                           neigh_node->last_valid + PURGE_TIMEOUT * HZ))
+                               continue;

We should continue to use msecs_to_jiffies() for readability reasons.

Cheers,
Marek

#15 lore raw

PATCH 7/10 batman-adv: Adding ndp debugfs output

In reply to Linus Lüssing

Lists all neighbours and their tq/rq values detected and measured by the Neighbor Discovery Protocol (NDP).

---
 bat_debugfs.c |    9 ++++++++
 ndp.c         |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 ndp.h         |    1 +
 3 files changed, 70 insertions(+), 0 deletions(-)
bat_debugfs.c +9 -0
index 0ae81d0..602aa15 100644
@@ -25,6 +25,7 @@
 
 #include "bat_debugfs.h"
 #include "translation-table.h"
+#include "ndp.h"
 #include "originator.h"
 #include "hard-interface.h"
 #include "gateway_common.h"
@@ -222,6 +223,12 @@ static void debug_log_cleanup(struct bat_priv *bat_priv)
 }
 #endif
 
+static int neighbors_open(struct inode *inode, struct file *file)
+{
+	struct net_device *net_dev = (struct net_device *)inode->i_private;
+	return single_open(file, ndp_seq_print_text, net_dev);
+}
+
 static int originators_open(struct inode *inode, struct file *file)
 {
 	struct net_device *net_dev = (struct net_device *)inode->i_private;
@@ -275,6 +282,7 @@ struct bat_debuginfo bat_debuginfo_##_name = {	\
 		}				\
 };
 
+static BAT_DEBUGINFO(neighbors, S_IRUGO, neighbors_open);
 static BAT_DEBUGINFO(originators, S_IRUGO, originators_open);
 static BAT_DEBUGINFO(gateways, S_IRUGO, gateways_open);
 static BAT_DEBUGINFO(softif_neigh, S_IRUGO, softif_neigh_open);
@@ -283,6 +291,7 @@ static BAT_DEBUGINFO(transtable_local, S_IRUGO, transtable_local_open);
 static BAT_DEBUGINFO(vis_data, S_IRUGO, vis_data_open);
 
 static struct bat_debuginfo *mesh_debuginfos[] = {
+	&bat_debuginfo_neighbors,
 	&bat_debuginfo_originators,
 	&bat_debuginfo_gateways,
 	&bat_debuginfo_softif_neigh,
ndp.c +60 -0

69 lines not on this page · raw message

ndp.h +1 -0
index 5679f36..26be41f 100644
@@ -10,3 +10,4 @@ uint8_t ndp_fetch_tq(struct batman_packet_ndp *packet,
 void ndp_purge_neighbors(void);
 int ndp_update_neighbor(uint8_t my_tq, uint32_t seqno,
 			struct batman_if *batman_if, uint8_t *neigh_addr);
+int ndp_seq_print_text(struct seq_file *seq, void *offset);
Signature · 1 line
1.7.1
#16 lore raw

PATCH 8/10 batman-adv: Adding batman_if specific sysfs wrapper macros for UINT

In reply to Linus Lüssing

This allows us to easily add a sysfs parameter for an unsigned int later, which is not for a batman mesh interface (e.g. bat0), but for a common interface instead. It allows reading and writing an atomic_t in batman_if (instead of bat_priv compared to the mesh variant).

---
 bat_sysfs.c |   27 +++++++++++++++++++++++++++
 1 files changed, 27 insertions(+), 0 deletions(-)
bat_sysfs.c +27 -0
index cd7bb51..98c10a3 100644
@@ -94,6 +94,33 @@ ssize_t show_##_name(struct kobject *kobj, struct attribute *attr,	\
 	static BAT_ATTR(_name, _mode, show_##_name, store_##_name)
 
 
+#define BAT_ATTR_IF_STORE_UINT(_name, _min, _max, _post_func)		\
+ssize_t store_##_name(struct kobject *kobj, struct attribute *attr,	\
+			     char *buff, size_t count)			\
+{									\
+	struct net_device *net_dev = kobj_to_netdev(kobj);		\
+	struct batman_if *batman_if = get_batman_if_by_netdev(net_dev);	\
+	return __store_uint_attr(buff, count, _min, _max, _post_func,	\
+				 attr, &batman_if->_name, net_dev);	\
+}
+
+#define BAT_ATTR_IF_SHOW_UINT(_name)					\
+ssize_t show_##_name(struct kobject *kobj, struct attribute *attr,	\
+			    char *buff)					\
+{									\
+	struct net_device *net_dev = kobj_to_netdev(kobj);		\
+	struct batman_if *batman_if = get_batman_if_by_netdev(net_dev);	\
+	return sprintf(buff, "%i\n", atomic_read(&batman_if->_name));	\
+}									\
+
+/* Use this, if you are going to set [name] in batman_if to unsigned integer
+ * values only */
+#define BAT_ATTR_IF_UINT(_name, _mode, _min, _max, _post_func)		\
+	static BAT_ATTR_IF_STORE_UINT(_name, _min, _max, _post_func)	\
+	static BAT_ATTR_IF_SHOW_UINT(_name)				\
+	static BAT_ATTR(_name, _mode, show_##_name, store_##_name)
+
+
 static int store_bool_attr(char *buff, size_t count,
 			   struct net_device *net_dev,
 			   char *attr_name, atomic_t *attr)
Signature · 1 line
1.7.1
#17 lore raw

Re: [B.A.T.M.A.N.] [PATCH 08/10] batman-adv: Adding batman_if specific sysfs wrapper macros for UINT

Quoted 8 lines · On Tuesday 14 December 2010 10:58:14 Linus Lüssing wrote:
bat_sysfs.c +8 -0
+#define BAT_ATTR_IF_STORE_UINT(_name, _min, _max, _post_func)          \
+ssize_t store_##_name(struct kobject *kobj, struct attribute *attr,    \
+                            char *buff, size_t count)                  \
+{                                                                      \
+       struct net_device *net_dev = kobj_to_netdev(kobj);              \
+       struct batman_if *batman_if = get_batman_if_by_netdev(net_dev); \
+       return __store_uint_attr(buff, count, _min, _max, _post_func,   \
+                                attr, &batman_if->_name, net_dev);     \

bat_sysfs.c ssize_t show_##_name(struct kobject *kobj, struct attribute *attr, \

Quoted 10 lines
bat_sysfs.c +10 -0
+}
+
+#define BAT_ATTR_IF_SHOW_UINT(_name)                                   \
+ssize_t show_##_name(struct kobject *kobj, struct attribute *attr,     \
+                           char *buff)                                 \
+{                                                                      \
+       struct net_device *net_dev = kobj_to_netdev(kobj);              \
+       struct batman_if *batman_if = get_batman_if_by_netdev(net_dev); \
+       return sprintf(buff, "%i\n", atomic_read(&batman_if->_name));   \
+}     

get_batman_if_by_netdev() increases the batman_if refcount which is never decreased. Check the other get_batman_if_by_netdev() calls in the same file to get an idea how to handle this,

Cheers,
Marek

#18 lore raw

PATCH 9/10 batman-adv: Adding sysfs parameter for ndp interval

In reply to Linus Lüssing

This parameter can be set individually on each interface and allows the configuration of the ndp interval for the link quality measurements during runtime. Usually it is desirable to set it to a higher (= slower) value on interfaces which have a more static characteristic (e.g. wired interfaces) or very dense neighbourhoods to reduce overhead.

---
 bat_sysfs.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
bat_sysfs.c +2 -0
index 98c10a3..1dcd986 100644
@@ -572,10 +572,12 @@ static ssize_t show_iface_status(struct kobject *kobj, struct attribute *attr,
 static BAT_ATTR(mesh_iface, S_IRUGO | S_IWUSR,
 		show_mesh_iface, store_mesh_iface);
 static BAT_ATTR(iface_status, S_IRUGO, show_iface_status, NULL);
+BAT_ATTR_IF_UINT(ndp_interval, S_IRUGO | S_IWUSR, 2 * JITTER, INT_MAX, NULL);
 
 static struct bat_attribute *batman_attrs[] = {
 	&bat_attr_mesh_iface,
 	&bat_attr_iface_status,
+	&bat_attr_ndp_interval,
 	NULL,
 };
 
Signature · 1 line
1.7.1
#19 lore raw

PATCH 10/10 batman-adv: Use local tq values determined by NDP on OGMs

In reply to Linus Lüssing

With this commit not the local transmit quality values determined by the OGMs themselves are applied on received OGMs, but the local transmit quality detemined by NDP instead. Usually the link quality measurements of NDP are more up-to-date than the one of the OGMs, as NDP is using a more frequent interval because NDP's packets are not being flooded through the whole mesh.

---
 routing.c |   58 +++++++++++++++++++++++++++-------------------------------
 1 files changed, 27 insertions(+), 31 deletions(-)
routing.c +27 -31
index dbea97f..16e1377 100644
@@ -136,7 +136,7 @@ static int is_bidirectional_neigh(struct orig_node *orig_node,
 {
 	struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
 	struct neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL;
-	unsigned char total_count;
+	uint8_t local_tq = 0, local_rq = 0;
 
 	if (orig_node == orig_neigh_node) {
 		list_for_each_entry(tmp_neigh_node,
@@ -180,25 +180,22 @@ static int is_bidirectional_neigh(struct orig_node *orig_node,
 			return 0;
 	}
 
-	orig_node->last_valid = jiffies;
+	/* note, bottom halves are already deactivated outside in
+	 * recv_bat_packet() */
+	spin_lock(&if_incoming->neigh_list_lock);
+	list_for_each_entry(neigh_node, &if_incoming->neigh_list, list) {
+		if (!compare_orig(neigh_node->addr, orig_neigh_node->orig))
+			continue;
 
-	/* pay attention to not get a value bigger than 100 % */
-	total_count = (orig_neigh_node->bcast_own_sum[if_incoming->if_num] >
-		       neigh_node->real_packet_count ?
-		       neigh_node->real_packet_count :
-		       orig_neigh_node->bcast_own_sum[if_incoming->if_num]);
+		orig_node->last_valid = jiffies;
+		local_tq = neigh_node->tq_avg;
+		local_rq = neigh_node->rq;
+		break;
+	}
+	spin_unlock(&if_incoming->neigh_list_lock);
 
-	/* if we have too few packets (too less data) we set tq_own to zero */
-	/* if we receive too few packets it is not considered bidirectional */
-	if ((total_count < TQ_LOCAL_BIDRECT_SEND_MINIMUM) ||
-	    (neigh_node->real_packet_count < TQ_LOCAL_BIDRECT_RECV_MINIMUM))
-		orig_neigh_node->tq_own = 0;
-	else
-		/* neigh_node->real_packet_count is never zero as we
-		 * only purge old information when getting new
-		 * information */
-		orig_neigh_node->tq_own = (TQ_MAX_VALUE * total_count) /
-			neigh_node->real_packet_count;
+	if (local_tq == 0)
+		return 0;
 
 	/*
 	 * 1 - ((1-x) ** 3), normalized to TQ_MAX_VALUE this does
@@ -209,25 +206,23 @@ static int is_bidirectional_neigh(struct orig_node *orig_node,
 	orig_neigh_node->tq_asym_penalty =
 		TQ_MAX_VALUE -
 		(TQ_MAX_VALUE *
-		 (TQ_LOCAL_WINDOW_SIZE - neigh_node->real_packet_count) *
-		 (TQ_LOCAL_WINDOW_SIZE - neigh_node->real_packet_count) *
-		 (TQ_LOCAL_WINDOW_SIZE - neigh_node->real_packet_count)) /
-		(TQ_LOCAL_WINDOW_SIZE *
-		 TQ_LOCAL_WINDOW_SIZE *
-		 TQ_LOCAL_WINDOW_SIZE);
+		 (TQ_MAX_VALUE - local_rq) *
+		 (TQ_MAX_VALUE - local_rq) *
+		 (TQ_MAX_VALUE - local_rq)) /
+		(TQ_MAX_VALUE *
+		 TQ_MAX_VALUE *
+		 TQ_MAX_VALUE);
 
 	batman_packet_ogm->tq = ((batman_packet_ogm->tq *
-			      orig_neigh_node->tq_own *
+			      local_tq *
 			      orig_neigh_node->tq_asym_penalty) /
-			     (TQ_MAX_VALUE * TQ_MAX_VALUE));
+			      (TQ_MAX_VALUE * TQ_MAX_VALUE));
 
 	bat_dbg(DBG_BATMAN, bat_priv,
 		"bidirectional: "
-		"orig = %-15pM neigh = %-15pM => own_bcast = %2i, "
-		"real recv = %2i, local tq: %3i, asym_penalty: %3i, "
-		"total tq: %3i\n",
-		orig_node->orig, orig_neigh_node->orig, total_count,
-		neigh_node->real_packet_count, orig_neigh_node->tq_own,
+		"orig = %-15pM neigh = %-15pM => local tq = %3i, "
+	        "local rq: %3i, asym_penalty: %3i, total tq: %3i\n",
+		orig_node->orig, orig_neigh_node->orig, local_tq, local_rq,
 		orig_neigh_node->tq_asym_penalty, batman_packet_ogm->tq);
 
 	/* if link has the minimum required transmission quality
@@ -828,6 +823,7 @@ int recv_bat_packet(struct sk_buff *skb,
 
 	ethhdr = (struct ethhdr *)skb_mac_header(skb);
 
+	/* note, is_bidirectional_neigh() relies on deactivated bottom halves */
 	spin_lock_bh(&bat_priv->orig_hash_lock);
 	receive_aggr_bat_packet(ethhdr,
 				skb->data,
Signature · 1 line
1.7.1