Skip to content

Commit

Permalink
Merge branch 'batman-adv/next' of git://git.open-mesh.org/ecsv/linux-…
Browse files Browse the repository at this point in the history
…merge
  • Loading branch information
David S. Miller committed Jun 20, 2011
2 parents 1b9c413 + 43676ab commit eac5646
Show file tree
Hide file tree
Showing 27 changed files with 2,080 additions and 462 deletions.
1 change: 1 addition & 0 deletions net/batman-adv/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
config BATMAN_ADV
tristate "B.A.T.M.A.N. Advanced Meshing Protocol"
depends on NET
select CRC16
default n
---help---

Expand Down
25 changes: 11 additions & 14 deletions net/batman-adv/aggregation.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,12 @@
*/

#include "main.h"
#include "translation-table.h"
#include "aggregation.h"
#include "send.h"
#include "routing.h"
#include "hard-interface.h"

/* calculate the size of the tt information for a given packet */
static int tt_len(const struct batman_packet *batman_packet)
{
return batman_packet->num_tt * ETH_ALEN;
}

/* return true if new_packet can be aggregated with forw_packet */
static bool can_aggregate_with(const struct batman_packet *new_batman_packet,
int packet_len,
Expand Down Expand Up @@ -195,7 +190,7 @@ static void aggregate(struct forw_packet *forw_packet_aggr,

void add_bat_packet_to_list(struct bat_priv *bat_priv,
unsigned char *packet_buff, int packet_len,
struct hard_iface *if_incoming, char own_packet,
struct hard_iface *if_incoming, int own_packet,
unsigned long send_time)
{
/**
Expand Down Expand Up @@ -264,18 +259,20 @@ void receive_aggr_bat_packet(const struct ethhdr *ethhdr,
batman_packet = (struct batman_packet *)packet_buff;

do {
/* network to host order for our 32bit seqno, and the
orig_interval. */
/* network to host order for our 32bit seqno and the
orig_interval */
batman_packet->seqno = ntohl(batman_packet->seqno);
batman_packet->tt_crc = ntohs(batman_packet->tt_crc);

tt_buff = packet_buff + buff_pos + BAT_PACKET_LEN;
receive_bat_packet(ethhdr, batman_packet,
tt_buff, tt_len(batman_packet),
if_incoming);

buff_pos += BAT_PACKET_LEN + tt_len(batman_packet);
receive_bat_packet(ethhdr, batman_packet, tt_buff, if_incoming);

buff_pos += BAT_PACKET_LEN +
tt_len(batman_packet->tt_num_changes);

batman_packet = (struct batman_packet *)
(packet_buff + buff_pos);
} while (aggregated_packet(buff_pos, packet_len,
batman_packet->num_tt));
batman_packet->tt_num_changes));
}
8 changes: 5 additions & 3 deletions net/batman-adv/aggregation.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@
#include "main.h"

/* is there another aggregated packet here? */
static inline int aggregated_packet(int buff_pos, int packet_len, int num_tt)
static inline int aggregated_packet(int buff_pos, int packet_len,
int tt_num_changes)
{
int next_buff_pos = buff_pos + BAT_PACKET_LEN + (num_tt * ETH_ALEN);
int next_buff_pos = buff_pos + BAT_PACKET_LEN + (tt_num_changes *
sizeof(struct tt_change));

return (next_buff_pos <= packet_len) &&
(next_buff_pos <= MAX_AGGREGATION_BYTES);
}

void add_bat_packet_to_list(struct bat_priv *bat_priv,
unsigned char *packet_buff, int packet_len,
struct hard_iface *if_incoming, char own_packet,
struct hard_iface *if_incoming, int own_packet,
unsigned long send_time);
void receive_aggr_bat_packet(const struct ethhdr *ethhdr,
unsigned char *packet_buff, int packet_len,
Expand Down
73 changes: 72 additions & 1 deletion net/batman-adv/bat_sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ static struct bat_priv *kobj_to_batpriv(struct kobject *obj)
return netdev_priv(net_dev);
}

#define UEV_TYPE_VAR "BATTYPE="
#define UEV_ACTION_VAR "BATACTION="
#define UEV_DATA_VAR "BATDATA="

static char *uev_action_str[] = {
"add",
"del",
"change"
};

static char *uev_type_str[] = {
"gw"
};

/* Use this, if you have customized show and store functions */
#define BAT_ATTR(_name, _mode, _show, _store) \
struct bat_attribute bat_attr_##_name = { \
Expand Down Expand Up @@ -375,7 +389,7 @@ BAT_ATTR_UINT(gw_sel_class, S_IRUGO | S_IWUSR, 1, TQ_MAX_VALUE,
static BAT_ATTR(gw_bandwidth, S_IRUGO | S_IWUSR, show_gw_bwidth,
store_gw_bwidth);
#ifdef CONFIG_BATMAN_ADV_DEBUG
BAT_ATTR_UINT(log_level, S_IRUGO | S_IWUSR, 0, 3, NULL);
BAT_ATTR_UINT(log_level, S_IRUGO | S_IWUSR, 0, 7, NULL);
#endif

static struct bat_attribute *mesh_attrs[] = {
Expand Down Expand Up @@ -601,3 +615,60 @@ void sysfs_del_hardif(struct kobject **hardif_obj)
kobject_put(*hardif_obj);
*hardif_obj = NULL;
}

int throw_uevent(struct bat_priv *bat_priv, enum uev_type type,
enum uev_action action, const char *data)
{
int ret = -1;
struct hard_iface *primary_if = NULL;
struct kobject *bat_kobj;
char *uevent_env[4] = { NULL, NULL, NULL, NULL };

primary_if = primary_if_get_selected(bat_priv);
if (!primary_if)
goto out;

bat_kobj = &primary_if->soft_iface->dev.kobj;

uevent_env[0] = kmalloc(strlen(UEV_TYPE_VAR) +
strlen(uev_type_str[type]) + 1,
GFP_ATOMIC);
if (!uevent_env[0])
goto out;

sprintf(uevent_env[0], "%s%s", UEV_TYPE_VAR, uev_type_str[type]);

uevent_env[1] = kmalloc(strlen(UEV_ACTION_VAR) +
strlen(uev_action_str[action]) + 1,
GFP_ATOMIC);
if (!uevent_env[1])
goto out;

sprintf(uevent_env[1], "%s%s", UEV_ACTION_VAR, uev_action_str[action]);

/* If the event is DEL, ignore the data field */
if (action != UEV_DEL) {
uevent_env[2] = kmalloc(strlen(UEV_DATA_VAR) +
strlen(data) + 1, GFP_ATOMIC);
if (!uevent_env[2])
goto out;

sprintf(uevent_env[2], "%s%s", UEV_DATA_VAR, data);
}

ret = kobject_uevent_env(bat_kobj, KOBJ_CHANGE, uevent_env);
out:
kfree(uevent_env[0]);
kfree(uevent_env[1]);
kfree(uevent_env[2]);

if (primary_if)
hardif_free_ref(primary_if);

if (ret)
bat_dbg(DBG_BATMAN, bat_priv, "Impossible to send "
"uevent for (%s,%s,%s) event (err: %d)\n",
uev_type_str[type], uev_action_str[action],
(action == UEV_DEL ? "NULL" : data), ret);
return ret;
}
2 changes: 2 additions & 0 deletions net/batman-adv/bat_sysfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ int sysfs_add_meshif(struct net_device *dev);
void sysfs_del_meshif(struct net_device *dev);
int sysfs_add_hardif(struct kobject **hardif_obj, struct net_device *dev);
void sysfs_del_hardif(struct kobject **hardif_obj);
int throw_uevent(struct bat_priv *bat_priv, enum uev_type type,
enum uev_action action, const char *data);

#endif /* _NET_BATMAN_ADV_SYSFS_H_ */
8 changes: 4 additions & 4 deletions net/batman-adv/bitarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

/* returns true if the corresponding bit in the given seq_bits indicates true
* and curr_seqno is within range of last_seqno */
uint8_t get_bit_status(const unsigned long *seq_bits, uint32_t last_seqno,
uint32_t curr_seqno)
int get_bit_status(const unsigned long *seq_bits, uint32_t last_seqno,
uint32_t curr_seqno)
{
int32_t diff, word_offset, word_num;

Expand Down Expand Up @@ -127,8 +127,8 @@ static void bit_reset_window(unsigned long *seq_bits)
* 1 if the window was moved (either new or very old)
* 0 if the window was not moved/shifted.
*/
char bit_get_packet(void *priv, unsigned long *seq_bits,
int32_t seq_num_diff, int8_t set_mark)
int bit_get_packet(void *priv, unsigned long *seq_bits,
int32_t seq_num_diff, int set_mark)
{
struct bat_priv *bat_priv = priv;

Expand Down
8 changes: 4 additions & 4 deletions net/batman-adv/bitarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@

/* returns true if the corresponding bit in the given seq_bits indicates true
* and curr_seqno is within range of last_seqno */
uint8_t get_bit_status(const unsigned long *seq_bits, uint32_t last_seqno,
uint32_t curr_seqno);
int get_bit_status(const unsigned long *seq_bits, uint32_t last_seqno,
uint32_t curr_seqno);

/* turn corresponding bit on, so we can remember that we got the packet */
void bit_mark(unsigned long *seq_bits, int32_t n);


/* receive and process one packet, returns 1 if received seq_num is considered
* new, 0 if old */
char bit_get_packet(void *priv, unsigned long *seq_bits,
int32_t seq_num_diff, int8_t set_mark);
int bit_get_packet(void *priv, unsigned long *seq_bits,
int32_t seq_num_diff, int set_mark);

/* count the hamming weight, how many good packets did we receive? */
int bit_packet_count(const unsigned long *seq_bits);
Expand Down
Loading

0 comments on commit eac5646

Please sign in to comment.