Skip to content

Commit

Permalink
Merge tag 'batman-adv-for-davem' of git://git.open-mesh.org/linux-merge
Browse files Browse the repository at this point in the history
Included changes:
- Increase batman-adv version
- Bridge Loop Avoidance: compute checksum (using crc32) on skb fragments instead
  of linearising it
- sort the sysfs documentation
- some other minor cleanups

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Nov 21, 2012
2 parents de4594a + e022b95 commit 76e0d67
Show file tree
Hide file tree
Showing 16 changed files with 268 additions and 194 deletions.
11 changes: 6 additions & 5 deletions Documentation/ABI/testing/sysfs-class-net-batman-adv
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

What: /sys/class/net/<iface>/batman-adv/iface_status
Date: May 2010
Contact: Marek Lindner <lindner_marek@yahoo.de>
Description:
Indicates the status of <iface> as it is seen by batman.

What: /sys/class/net/<iface>/batman-adv/mesh_iface
Date: May 2010
Contact: Marek Lindner <lindner_marek@yahoo.de>
Expand All @@ -7,8 +13,3 @@ Description:
displays the batman mesh interface this <iface>
currently is associated with.

What: /sys/class/net/<iface>/batman-adv/iface_status
Date: May 2010
Contact: Marek Lindner <lindner_marek@yahoo.de>
Description:
Indicates the status of <iface> as it is seen by batman.
40 changes: 20 additions & 20 deletions Documentation/ABI/testing/sysfs-class-net-mesh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ Description:
Indicates whether the batman protocol messages of the
mesh <mesh_iface> shall be aggregated or not.

What: /sys/class/net/<mesh_iface>/mesh/ap_isolation
Date: May 2011
Contact: Antonio Quartulli <ordex@autistici.org>
Description:
Indicates whether the data traffic going from a
wireless client to another wireless client will be
silently dropped.

What: /sys/class/net/<mesh_iface>/mesh/bonding
Date: June 2010
Contact: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
Expand All @@ -31,14 +39,6 @@ Description:
mesh will be fragmented or silently discarded if the
packet size exceeds the outgoing interface MTU.

What: /sys/class/net/<mesh_iface>/mesh/ap_isolation
Date: May 2011
Contact: Antonio Quartulli <ordex@autistici.org>
Description:
Indicates whether the data traffic going from a
wireless client to another wireless client will be
silently dropped.

What: /sys/class/net/<mesh_iface>/mesh/gw_bandwidth
Date: October 2010
Contact: Marek Lindner <lindner_marek@yahoo.de>
Expand All @@ -60,26 +60,26 @@ Description:
Defines the selection criteria this node will use
to choose a gateway if gw_mode was set to 'client'.

What: /sys/class/net/<mesh_iface>/mesh/hop_penalty
Date: Oct 2010
Contact: Linus Lüssing <linus.luessing@web.de>
Description:
Defines the penalty which will be applied to an
originator message's tq-field on every hop.

What: /sys/class/net/<mesh_iface>/mesh/orig_interval
Date: May 2010
Contact: Marek Lindner <lindner_marek@yahoo.de>
Description:
Defines the interval in milliseconds in which batman
sends its protocol messages.

What: /sys/class/net/<mesh_iface>/mesh/hop_penalty
Date: Oct 2010
Contact: Linus Lüssing <linus.luessing@web.de>
Description:
Defines the penalty which will be applied to an
originator message's tq-field on every hop.

What: /sys/class/net/<mesh_iface>/mesh/routing_algo
Date: Dec 2011
Contact: Marek Lindner <lindner_marek@yahoo.de>
What: /sys/class/net/<mesh_iface>/mesh/routing_algo
Date: Dec 2011
Contact: Marek Lindner <lindner_marek@yahoo.de>
Description:
Defines the routing procotol this mesh instance
uses to find the optimal paths through the mesh.
Defines the routing procotol this mesh instance
uses to find the optimal paths through the mesh.

What: /sys/class/net/<mesh_iface>/mesh/vis_mode
Date: May 2010
Expand Down
1 change: 1 addition & 0 deletions net/batman-adv/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ config BATMAN_ADV
tristate "B.A.T.M.A.N. Advanced Meshing Protocol"
depends on NET
select CRC16
select LIBCRC32C
default n
help
B.A.T.M.A.N. (better approach to mobile ad-hoc networking) is
Expand Down
36 changes: 23 additions & 13 deletions net/batman-adv/bridge_loop_avoidance.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,15 @@ static int batadv_compare_backbone_gw(const struct hlist_node *node,
{
const void *data1 = container_of(node, struct batadv_backbone_gw,
hash_entry);
const struct batadv_backbone_gw *gw1 = data1, *gw2 = data2;

return (memcmp(data1, data2, ETH_ALEN + sizeof(short)) == 0 ? 1 : 0);
if (!batadv_compare_eth(gw1->orig, gw2->orig))
return 0;

if (gw1->vid != gw2->vid)
return 0;

return 1;
}

/* compares address and vid of two claims */
Expand All @@ -87,8 +94,15 @@ static int batadv_compare_claim(const struct hlist_node *node,
{
const void *data1 = container_of(node, struct batadv_claim,
hash_entry);
const struct batadv_claim *cl1 = data1, *cl2 = data2;

return (memcmp(data1, data2, ETH_ALEN + sizeof(short)) == 0 ? 1 : 0);
if (!batadv_compare_eth(cl1->addr, cl2->addr))
return 0;

if (cl1->vid != cl2->vid)
return 0;

return 1;
}

/* free a backbone gw */
Expand Down Expand Up @@ -1235,8 +1249,7 @@ int batadv_bla_init(struct batadv_priv *bat_priv)
/**
* batadv_bla_check_bcast_duplist
* @bat_priv: the bat priv with all the soft interface information
* @bcast_packet: encapsulated broadcast frame plus batman header
* @bcast_packet_len: length of encapsulated broadcast frame plus batman header
* @skb: contains the bcast_packet to be checked
*
* check if it is on our broadcast list. Another gateway might
* have sent the same packet because it is connected to the same backbone,
Expand All @@ -1248,20 +1261,17 @@ int batadv_bla_init(struct batadv_priv *bat_priv)
* the same host however as this might be intended.
*/
int batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv,
struct batadv_bcast_packet *bcast_packet,
int bcast_packet_len)
struct sk_buff *skb)
{
int i, length, curr, ret = 0;
uint8_t *content;
uint16_t crc;
int i, curr, ret = 0;
__be32 crc;
struct batadv_bcast_packet *bcast_packet;
struct batadv_bcast_duplist_entry *entry;

length = bcast_packet_len - sizeof(*bcast_packet);
content = (uint8_t *)bcast_packet;
content += sizeof(*bcast_packet);
bcast_packet = (struct batadv_bcast_packet *)skb->data;

/* calculate the crc ... */
crc = crc16(0, content, length);
crc = batadv_skb_crc32(skb, (u8 *)(bcast_packet + 1));

spin_lock_bh(&bat_priv->bla.bcast_duplist_lock);

Expand Down
6 changes: 2 additions & 4 deletions net/batman-adv/bridge_loop_avoidance.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ int batadv_bla_backbone_table_seq_print_text(struct seq_file *seq,
void *offset);
int batadv_bla_is_backbone_gw_orig(struct batadv_priv *bat_priv, uint8_t *orig);
int batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv,
struct batadv_bcast_packet *bcast_packet,
int hdr_size);
struct sk_buff *skb);
void batadv_bla_update_orig_address(struct batadv_priv *bat_priv,
struct batadv_hard_iface *primary_if,
struct batadv_hard_iface *oldif);
Expand Down Expand Up @@ -81,8 +80,7 @@ static inline int batadv_bla_is_backbone_gw_orig(struct batadv_priv *bat_priv,

static inline int
batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv,
struct batadv_bcast_packet *bcast_packet,
int hdr_size)
struct sk_buff *skb)
{
return 0;
}
Expand Down
34 changes: 25 additions & 9 deletions net/batman-adv/debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,17 @@ struct batadv_debuginfo batadv_debuginfo_##_name = { \
} \
};

/* the following attributes are general and therefore they will be directly
* placed in the BATADV_DEBUGFS_SUBDIR subdirectory of debugfs
*/
static BATADV_DEBUGINFO(routing_algos, S_IRUGO, batadv_algorithms_open);

static struct batadv_debuginfo *batadv_general_debuginfos[] = {
&batadv_debuginfo_routing_algos,
NULL,
};

/* The following attributes are per soft interface */
static BATADV_DEBUGINFO(originators, S_IRUGO, batadv_originators_open);
static BATADV_DEBUGINFO(gateways, S_IRUGO, batadv_gateways_open);
static BATADV_DEBUGINFO(transtable_global, S_IRUGO,
Expand Down Expand Up @@ -358,25 +368,31 @@ static struct batadv_debuginfo *batadv_mesh_debuginfos[] = {

void batadv_debugfs_init(void)
{
struct batadv_debuginfo *bat_debug;
struct batadv_debuginfo **bat_debug;
struct dentry *file;

batadv_debugfs = debugfs_create_dir(BATADV_DEBUGFS_SUBDIR, NULL);
if (batadv_debugfs == ERR_PTR(-ENODEV))
batadv_debugfs = NULL;

if (!batadv_debugfs)
goto out;
goto err;

bat_debug = &batadv_debuginfo_routing_algos;
file = debugfs_create_file(bat_debug->attr.name,
S_IFREG | bat_debug->attr.mode,
batadv_debugfs, NULL, &bat_debug->fops);
if (!file)
pr_err("Can't add debugfs file: %s\n", bat_debug->attr.name);
for (bat_debug = batadv_general_debuginfos; *bat_debug; ++bat_debug) {
file = debugfs_create_file(((*bat_debug)->attr).name,
S_IFREG | ((*bat_debug)->attr).mode,
batadv_debugfs, NULL,
&(*bat_debug)->fops);
if (!file) {
pr_err("Can't add general debugfs file: %s\n",
((*bat_debug)->attr).name);
goto err;
}
}

out:
return;
err:
debugfs_remove_recursive(batadv_debugfs);
}

void batadv_debugfs_destroy(void)
Expand Down
34 changes: 34 additions & 0 deletions net/batman-adv/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* 02110-1301, USA
*/

#include <linux/crc32c.h>
#include <linux/highmem.h>
#include "main.h"
#include "sysfs.h"
#include "debugfs.h"
Expand Down Expand Up @@ -420,6 +422,38 @@ int batadv_algo_seq_print_text(struct seq_file *seq, void *offset)
return 0;
}

/**
* batadv_skb_crc32 - calculate CRC32 of the whole packet and skip bytes in
* the header
* @skb: skb pointing to fragmented socket buffers
* @payload_ptr: Pointer to position inside the head buffer of the skb
* marking the start of the data to be CRC'ed
*
* payload_ptr must always point to an address in the skb head buffer and not to
* a fragment.
*/
__be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr)
{
u32 crc = 0;
unsigned int from;
unsigned int to = skb->len;
struct skb_seq_state st;
const u8 *data;
unsigned int len;
unsigned int consumed = 0;

from = (unsigned int)(payload_ptr - skb->data);

skb_prepare_seq_read(skb, from, to, &st);
while ((len = skb_seq_read(consumed, &data, &st)) != 0) {
crc = crc32c(crc, data, len);
consumed += len;
}
skb_abort_seq_read(&st);

return htonl(crc);
}

static int batadv_param_set_ra(const char *val, const struct kernel_param *kp)
{
struct batadv_algo_ops *bat_algo_ops;
Expand Down
3 changes: 2 additions & 1 deletion net/batman-adv/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define BATADV_DRIVER_DEVICE "batman-adv"

#ifndef BATADV_SOURCE_VERSION
#define BATADV_SOURCE_VERSION "2012.4.0"
#define BATADV_SOURCE_VERSION "2012.5.0"
#endif

/* B.A.T.M.A.N. parameters */
Expand Down Expand Up @@ -174,6 +174,7 @@ void batadv_recv_handler_unregister(uint8_t packet_type);
int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops);
int batadv_algo_select(struct batadv_priv *bat_priv, char *name);
int batadv_algo_seq_print_text(struct seq_file *seq, void *offset);
__be32 batadv_skb_crc32(struct sk_buff *skb, u8 *payload_ptr);

/**
* enum batadv_dbg_level - available log levels
Expand Down
16 changes: 15 additions & 1 deletion net/batman-adv/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,18 @@ struct batadv_icmp_packet_rr {
uint8_t rr[BATADV_RR_LEN][ETH_ALEN];
};

/* All packet headers in front of an ethernet header have to be completely
* divisible by 2 but not by 4 to make the payload after the ethernet
* header again 4 bytes boundary aligned.
*
* A packing of 2 is necessary to avoid extra padding at the end of the struct
* caused by a structure member which is larger than two bytes. Otherwise
* the structure would not fulfill the previously mentioned rule to avoid the
* misalignment of the payload after the ethernet header. It may also lead to
* leakage of information when the padding it not initialized before sending.
*/
#pragma pack(2)

struct batadv_unicast_packet {
struct batadv_header header;
uint8_t ttvn; /* destination translation table version number */
Expand Down Expand Up @@ -216,7 +228,9 @@ struct batadv_bcast_packet {
/* "4 bytes boundary + 2 bytes" long to make the payload after the
* following ethernet header again 4 bytes boundary aligned
*/
} __packed;
};

#pragma pack()

struct batadv_vis_packet {
struct batadv_header header;
Expand Down
Loading

0 comments on commit 76e0d67

Please sign in to comment.