[B.A.T.M.A.N.] [PATCH] batctl: fix a memory leak in bat_hosts_init
by Jonathan Neuschäfer
normalized was not being free'd when hash_new failed, now it is.
Signed-off-by: Jonathan Neuschäfer <j.neuschaefer(a)gmx.net>
---
bat-hosts.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/bat-hosts.c b/bat-hosts.c
index 0ea4134..179e733 100644
--- a/bat-hosts.c
+++ b/bat-hosts.c
@@ -179,7 +179,7 @@ void bat_hosts_init(int read_opt)
if (!host_hash) {
if (read_opt & USE_BAT_HOSTS)
printf("Warning - could not create bat hosts hash table\n");
- return;
+ goto out;
}
homedir = getenv("HOME");
@@ -216,6 +216,7 @@ void bat_hosts_init(int read_opt)
parse_hosts_file(&host_hash, normalized + (i * PATH_MAX), read_opt);
}
+out:
free(normalized);
}
--
1.7.5.4
9 years, 8 months
[B.A.T.M.A.N.] [PATCH] batman-adv: merge update_transtable() into tt related code
by Marek Lindner
Signed-off-by: Marek Lindner <lindner_marek(a)yahoo.de>
---
routing.c | 66 ++----------------------------------------------
translation-table.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++---
translation-table.h | 9 ++----
3 files changed, 70 insertions(+), 74 deletions(-)
diff --git a/routing.c b/routing.c
index 91a7860..1949928 100644
--- a/routing.c
+++ b/routing.c
@@ -64,65 +64,6 @@ void slide_own_bcast_window(struct hard_iface *hard_iface)
}
}
-static void update_transtable(struct bat_priv *bat_priv,
- struct orig_node *orig_node,
- const unsigned char *tt_buff,
- uint8_t tt_num_changes, uint8_t ttvn,
- uint16_t tt_crc)
-{
- uint8_t orig_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn);
- bool full_table = true;
-
- /* the ttvn increased by one -> we can apply the attached changes */
- if (ttvn - orig_ttvn == 1) {
- /* the OGM could not contain the changes due to their size or
- * because they have already been sent TT_OGM_APPEND_MAX times.
- * In this case send a tt request */
- if (!tt_num_changes) {
- full_table = false;
- goto request_table;
- }
-
- tt_update_changes(bat_priv, orig_node, tt_num_changes, ttvn,
- (struct tt_change *)tt_buff);
-
- /* Even if we received the precomputed crc with the OGM, we
- * prefer to recompute it to spot any possible inconsistency
- * in the global table */
- orig_node->tt_crc = tt_global_crc(bat_priv, orig_node);
-
- /* The ttvn alone is not enough to guarantee consistency
- * because a single value could represent different states
- * (due to the wrap around). Thus a node has to check whether
- * the resulting table (after applying the changes) is still
- * consistent or not. E.g. a node could disconnect while its
- * ttvn is X and reconnect on ttvn = X + TTVN_MAX: in this case
- * checking the CRC value is mandatory to detect the
- * inconsistency */
- if (orig_node->tt_crc != tt_crc)
- goto request_table;
-
- /* Roaming phase is over: tables are in sync again. I can
- * unset the flag */
- orig_node->tt_poss_change = false;
- } else {
- /* if we missed more than one change or our tables are not
- * in sync anymore -> request fresh tt data */
- if (ttvn != orig_ttvn || orig_node->tt_crc != tt_crc) {
-request_table:
- bat_dbg(DBG_TT, bat_priv, "TT inconsistency for %pM. "
- "Need to retrieve the correct information "
- "(ttvn: %u last_ttvn: %u crc: %u last_crc: "
- "%u num_changes: %u)\n", orig_node->orig, ttvn,
- orig_ttvn, tt_crc, orig_node->tt_crc,
- tt_num_changes);
- send_tt_request(bat_priv, orig_node, ttvn, tt_crc,
- full_table);
- return;
- }
- }
-}
-
static void update_route(struct bat_priv *bat_priv,
struct orig_node *orig_node,
struct neigh_node *neigh_node)
@@ -499,10 +440,9 @@ update_tt:
if (((batman_packet->orig != ethhdr->h_source) &&
(batman_packet->ttl > 2)) ||
(batman_packet->flags & PRIMARIES_FIRST_HOP))
- update_transtable(bat_priv, orig_node, tt_buff,
- batman_packet->tt_num_changes,
- batman_packet->ttvn,
- batman_packet->tt_crc);
+ tt_update_orig(bat_priv, orig_node, tt_buff,
+ batman_packet->tt_num_changes,
+ batman_packet->ttvn, batman_packet->tt_crc);
if (orig_node->gw_flags != batman_packet->gw_flags)
gw_node_update(bat_priv, orig_node, batman_packet->gw_flags);
diff --git a/translation-table.c b/translation-table.c
index e8f849f..cc53f78 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -1079,8 +1079,9 @@ out:
return skb;
}
-int send_tt_request(struct bat_priv *bat_priv, struct orig_node *dst_orig_node,
- uint8_t ttvn, uint16_t tt_crc, bool full_table)
+static int send_tt_request(struct bat_priv *bat_priv,
+ struct orig_node *dst_orig_node,
+ uint8_t ttvn, uint16_t tt_crc, bool full_table)
{
struct sk_buff *skb = NULL;
struct tt_query_packet *tt_request;
@@ -1455,9 +1456,10 @@ out:
orig_node_free_ref(orig_node);
}
-void tt_update_changes(struct bat_priv *bat_priv, struct orig_node *orig_node,
- uint16_t tt_num_changes, uint8_t ttvn,
- struct tt_change *tt_change)
+static void tt_update_changes(struct bat_priv *bat_priv,
+ struct orig_node *orig_node,
+ uint16_t tt_num_changes, uint8_t ttvn,
+ struct tt_change *tt_change)
{
_tt_update_changes(bat_priv, orig_node, tt_change, tt_num_changes,
ttvn);
@@ -1802,3 +1804,60 @@ out:
tt_local_entry_free_ref(tt_local_entry);
return ret;
}
+
+void tt_update_orig(struct bat_priv *bat_priv, struct orig_node *orig_node,
+ const unsigned char *tt_buff, uint8_t tt_num_changes,
+ uint8_t ttvn, uint16_t tt_crc)
+{
+ uint8_t orig_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn);
+ bool full_table = true;
+
+ /* the ttvn increased by one -> we can apply the attached changes */
+ if (ttvn - orig_ttvn == 1) {
+ /* the OGM could not contain the changes due to their size or
+ * because they have already been sent TT_OGM_APPEND_MAX times.
+ * In this case send a tt request */
+ if (!tt_num_changes) {
+ full_table = false;
+ goto request_table;
+ }
+
+ tt_update_changes(bat_priv, orig_node, tt_num_changes, ttvn,
+ (struct tt_change *)tt_buff);
+
+ /* Even if we received the precomputed crc with the OGM, we
+ * prefer to recompute it to spot any possible inconsistency
+ * in the global table */
+ orig_node->tt_crc = tt_global_crc(bat_priv, orig_node);
+
+ /* The ttvn alone is not enough to guarantee consistency
+ * because a single value could represent different states
+ * (due to the wrap around). Thus a node has to check whether
+ * the resulting table (after applying the changes) is still
+ * consistent or not. E.g. a node could disconnect while its
+ * ttvn is X and reconnect on ttvn = X + TTVN_MAX: in this case
+ * checking the CRC value is mandatory to detect the
+ * inconsistency */
+ if (orig_node->tt_crc != tt_crc)
+ goto request_table;
+
+ /* Roaming phase is over: tables are in sync again. I can
+ * unset the flag */
+ orig_node->tt_poss_change = false;
+ } else {
+ /* if we missed more than one change or our tables are not
+ * in sync anymore -> request fresh tt data */
+ if (ttvn != orig_ttvn || orig_node->tt_crc != tt_crc) {
+request_table:
+ bat_dbg(DBG_TT, bat_priv, "TT inconsistency for %pM. "
+ "Need to retrieve the correct information "
+ "(ttvn: %u last_ttvn: %u crc: %u last_crc: "
+ "%u num_changes: %u)\n", orig_node->orig, ttvn,
+ orig_ttvn, tt_crc, orig_node->tt_crc,
+ tt_num_changes);
+ send_tt_request(bat_priv, orig_node, ttvn, tt_crc,
+ full_table);
+ return;
+ }
+ }
+}
diff --git a/translation-table.h b/translation-table.h
index b47e876..30efd49 100644
--- a/translation-table.h
+++ b/translation-table.h
@@ -49,14 +49,8 @@ void tt_save_orig_buffer(struct bat_priv *bat_priv, struct orig_node *orig_node,
uint16_t tt_local_crc(struct bat_priv *bat_priv);
uint16_t tt_global_crc(struct bat_priv *bat_priv, struct orig_node *orig_node);
void tt_free(struct bat_priv *bat_priv);
-int send_tt_request(struct bat_priv *bat_priv,
- struct orig_node *dst_orig_node, uint8_t ttvn,
- uint16_t tt_crc, bool full_table);
bool send_tt_response(struct bat_priv *bat_priv,
struct tt_query_packet *tt_request);
-void tt_update_changes(struct bat_priv *bat_priv, struct orig_node *orig_node,
- uint16_t tt_num_changes, uint8_t ttvn,
- struct tt_change *tt_change);
bool is_my_client(struct bat_priv *bat_priv, const uint8_t *addr);
void handle_tt_response(struct bat_priv *bat_priv,
struct tt_query_packet *tt_response);
@@ -64,5 +58,8 @@ void send_roam_adv(struct bat_priv *bat_priv, uint8_t *client,
struct orig_node *orig_node);
void tt_commit_changes(struct bat_priv *bat_priv);
bool is_ap_isolated(struct bat_priv *bat_priv, uint8_t *src, uint8_t *dst);
+void tt_update_orig(struct bat_priv *bat_priv, struct orig_node *orig_node,
+ const unsigned char *tt_buff, uint8_t tt_num_changes,
+ uint8_t ttvn, uint16_t tt_crc);
#endif /* _NET_BATMAN_ADV_TRANSLATION_TABLE_H_ */
--
1.7.5.3
9 years, 8 months
[B.A.T.M.A.N.] [PATCH] batman-adv: handle hash_add() return value in the TT code
by Antonio Quartulli
hash_add() can fail and for this reason its return value has to be
correctly interpreted to avoid memory leaks.
Signed-off-by: Antonio Quartulli <ordex(a)autistici.org>
---
This patch needs
"[PATCH] batman-adv: hash_add() has to discriminate on the return value"
to work
translation-table.c | 27 +++++++++++++++++++++------
1 files changed, 21 insertions(+), 6 deletions(-)
diff --git a/translation-table.c b/translation-table.c
index fb6931d..267a287 100644
--- a/translation-table.c
+++ b/translation-table.c
@@ -188,6 +188,7 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr)
struct bat_priv *bat_priv = netdev_priv(soft_iface);
struct tt_local_entry *tt_local_entry = NULL;
struct tt_global_entry *tt_global_entry = NULL;
+ int hash_added;
tt_local_entry = tt_local_hash_find(bat_priv, addr);
@@ -220,8 +221,14 @@ void tt_local_add(struct net_device *soft_iface, const uint8_t *addr)
* (consistency check) */
tt_local_entry->flags |= TT_CLIENT_NEW;
- hash_add(bat_priv->tt_local_hash, compare_ltt, choose_orig,
- tt_local_entry, &tt_local_entry->hash_entry);
+ hash_added = hash_add(bat_priv->tt_local_hash, compare_ltt,
+ choose_orig, tt_local_entry,
+ &tt_local_entry->hash_entry);
+ if (hash_added != 0)
+ tt_local_entry_free_ref(tt_local_entry);
+
+ if (hash_added < 0)
+ goto out;
/* remove address from global hash if present */
tt_global_entry = tt_global_hash_find(bat_priv, addr);
@@ -500,6 +507,7 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node,
struct tt_global_entry *tt_global_entry;
struct orig_node *orig_node_tmp;
int ret = 0;
+ int hash_added;
tt_global_entry = tt_global_hash_find(bat_priv, tt_addr);
@@ -519,10 +527,17 @@ int tt_global_add(struct bat_priv *bat_priv, struct orig_node *orig_node,
tt_global_entry->roam_at = 0;
atomic_set(&tt_global_entry->refcount, 2);
- hash_add(bat_priv->tt_global_hash, compare_gtt,
- choose_orig, tt_global_entry,
- &tt_global_entry->hash_entry);
- atomic_inc(&orig_node->tt_size);
+ hash_added = hash_add(bat_priv->tt_global_hash, compare_gtt,
+ choose_orig, tt_global_entry,
+ &tt_global_entry->hash_entry);
+ if (hash_added != 0)
+ tt_global_entry_free_ref(tt_global_entry);
+
+ if (hash_added < 0)
+ goto out;
+
+ if (!hash_added)
+ atomic_inc(&orig_node->tt_size);
} else {
if (tt_global_entry->orig_node != orig_node) {
atomic_dec(&tt_global_entry->orig_node->tt_size);
--
1.7.3.4
9 years, 8 months
[B.A.T.M.A.N.] [PATCH] batman-adv: reuse tt_len() to calculate tt buffer length
by Marek Lindner
Signed-off-by: Marek Lindner <lindner_marek(a)yahoo.de>
---
aggregation.h | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/aggregation.h b/aggregation.h
index 216337b..df4a5a9 100644
--- a/aggregation.h
+++ b/aggregation.h
@@ -28,8 +28,7 @@
static inline int aggregated_packet(int buff_pos, int packet_len,
int tt_num_changes)
{
- int next_buff_pos = buff_pos + BAT_PACKET_LEN + (tt_num_changes *
- sizeof(struct tt_change));
+ int next_buff_pos = buff_pos + BAT_PACKET_LEN + tt_len(tt_num_changes);
return (next_buff_pos <= packet_len) &&
(next_buff_pos <= MAX_AGGREGATION_BYTES);
--
1.7.5.3
9 years, 8 months
[B.A.T.M.A.N.] per interface hop penalty
by Gioacchino Mazzurco
Hey all reading batman-adv documentation I have found the option hop
penalty that seems quite good for example with vpn links
The problem is that actual hop penalty is per node but not per
interface, the fact to have per interface hop penalty could be useful
on nodes that have both vpn and real interface and someone want to
penalize only vpn interfaces
it is possible to have that implemented soon ?
Very
9 years, 8 months
[B.A.T.M.A.N.] Filtering BATMAN-ADV packet
by Nik M. Anas Kamarudin
Hello all,
I need some help with batmand-adv packet filtering on wireless interface.
I successfully filter batman-adv packet using ebtables. This what i do:
/usr/sbin/brctl addbr br0
/usr/sbin/brctl addif br0 eth0
/sbin/ifconfig br0 up
/sbin/ifconfig eth0 192.168.5.2 up
then wait around 15 ~ 30 second.
/sbin/modprobe /lib/modules/`2.6.35.13/batman-adv/batman-adv.ko
/usr/sbin/batctl if add br0
/sbin/ifconfig bat0 192.168.5.41 up
/sbin/ifconfig br0 192.168.5.1 up
and filter up the batman-adv packet using etables like this:
`/usr/sbin/ebtables -A INPUT -s AA:AA:AA:AA:AA -j DROP`
BUT, this only work for Ethernet interface/ wire.. i need to do this
same thing using wireless interface. Anyone got any ideas?
9 years, 8 months
[B.A.T.M.A.N.] [PATCHv4 02/11] batman-adv: Remove private define of atomic_dec_not_zero
by Sven Eckelmann
atomic_dec_not_zero is defined through <linux/atomic.h> for all
architectures and batman-adv doesn't need an extra define which may
collide with the global one.
Signed-off-by: Sven Eckelmann <sven(a)narfation.org>
Cc: Marek Lindner <lindner_marek(a)yahoo.de>
Cc: Simon Wunderlich <siwu(a)hrz.tu-chemnitz.de>
Cc: b.a.t.m.a.n(a)lists.open-mesh.org
---
net/batman-adv/main.h | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/net/batman-adv/main.h b/net/batman-adv/main.h
index a6df61a..d986f34 100644
--- a/net/batman-adv/main.h
+++ b/net/batman-adv/main.h
@@ -201,8 +201,6 @@ static inline int compare_eth(const void *data1, const void *data2)
}
-#define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0)
-
/* Returns the smallest signed integer in two's complement with the sizeof x */
#define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u)))
--
1.7.5.4
9 years, 8 months
[B.A.T.M.A.N.] [PATCH] batctl: detect clients connected through a 802.11 device
by Antonio Quartull
From: Antonio Quartulli <ordex(a)autistici.org>
Clients connected through a 802.11 device are now marked with the
TT_CLIENT_WIFI flag. This flag is also advertised with the tt
announcement.
Signed-off-by: Antonio Quartulli <ordex(a)autistici.org>
---
packet.h | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/packet.h b/packet.h
index b76b4be..8802eab 100644
--- a/packet.h
+++ b/packet.h
@@ -84,6 +84,7 @@ enum tt_query_flags {
enum tt_client_flags {
TT_CLIENT_DEL = 1 << 0,
TT_CLIENT_ROAM = 1 << 1,
+ TT_CLIENT_WIFI = 1 << 2,
TT_CLIENT_NOPURGE = 1 << 8,
TT_CLIENT_NEW = 1 << 9,
TT_CLIENT_PENDING = 1 << 10
--
1.7.3.4
9 years, 8 months
[B.A.T.M.A.N.] [PATCH] batctl: added ap_isolation support
by Antonio Quartulli
This patch introduces the possibility of enabling/disabling the
ap_isolation feature in batman-adv
Signed-off-by: Antonio Quartulli <ordex(a)autistici.org>
---
main.c | 6 ++++++
sys.c | 7 +++++++
sys.h | 2 ++
3 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/main.c b/main.c
index eb67737..059c00f 100644
--- a/main.c
+++ b/main.c
@@ -58,6 +58,7 @@ void print_usage(void) {
printf(" \taggregation|ag [0|1] \tdisplay or modify the packet aggregation setting\n");
printf(" \tbonding|b [0|1] \tdisplay or modify the bonding mode setting\n");
printf(" \tfragmentation|f [0|1] \tdisplay or modify the fragmentation mode setting\n");
+ printf(" \tap_isolation|ap [0|1] \tdisplay or modify the ap isolation mode setting\n");
printf("\n");
printf(" \tping|p <destination> \tping another batman adv host via layer 2\n");
printf(" \ttraceroute|tr <destination> \ttraceroute another batman adv host via layer 2\n");
@@ -188,6 +189,11 @@ int main(int argc, char **argv)
ret = handle_sys_setting(mesh_iface, argc - 1, argv + 1,
SYS_FRAG, fragmentation_usage, sysfs_param_enable);
+ } else if ((strcmp(argv[1], "ap_isolation") == 0) || (strcmp(argv[1], "ap") == 0)) {
+
+ ret = handle_sys_setting(mesh_iface, argc - 1, argv + 1,
+ SYS_AP_ISOLA, ap_isolation_usage, sysfs_param_enable);
+
} else if ((strcmp(argv[1], "bisect") == 0)) {
ret = bisect(argc - 1, argv + 1);
diff --git a/sys.c b/sys.c
index dbf5383..4f2b2c5 100644
--- a/sys.c
+++ b/sys.c
@@ -270,6 +270,13 @@ void fragmentation_usage(void)
printf(" \t -h print this help\n");
}
+void ap_isolation_usage(void)
+{
+ printf("Usage: batctl [options] ap_isolation [0|1]\n");
+ printf("options:\n");
+ printf(" \t -h print this help\n");
+}
+
int handle_sys_setting(char *mesh_iface, int argc, char **argv,
char *file_path, void setting_usage(void),
const char *sysfs_param[])
diff --git a/sys.h b/sys.h
index 2c47550..2df846c 100644
--- a/sys.h
+++ b/sys.h
@@ -34,6 +34,7 @@
#define SYS_MESH_IFACE_FMT SYS_IFACE_PATH"/%s/batman_adv/mesh_iface"
#define SYS_IFACE_STATUS_FMT SYS_IFACE_PATH"/%s/batman_adv/iface_status"
#define SYS_FRAG "fragmentation"
+#define SYS_AP_ISOLA "ap_isolation"
enum gw_modes {
GW_MODE_OFF,
@@ -47,6 +48,7 @@ extern const char *sysfs_param_server[];
void aggregation_usage(void);
void bonding_usage(void);
void fragmentation_usage(void);
+void ap_isolation_usage(void);
void gw_mode_usage(void);
void vis_mode_usage(void);
void orig_interval_usage(void);
--
1.7.3.4
9 years, 8 months