Skip to content

Commit

Permalink
batman-adv: rename all instances of batman_packet to batman_ogm_packet
Browse files Browse the repository at this point in the history
The follow-up routing code changes are going to introduce additional
routing packet types which make this distinction necessary.

Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
  • Loading branch information
Marek Lindner committed Sep 8, 2011
1 parent a943cac commit b6da4bf
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 182 deletions.
48 changes: 26 additions & 22 deletions net/batman-adv/aggregation.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@
#include "hard-interface.h"

/* return true if new_packet can be aggregated with forw_packet */
static bool can_aggregate_with(const struct batman_packet *new_batman_packet,
static bool can_aggregate_with(const struct batman_ogm_packet
*new_batman_ogm_packet,
struct bat_priv *bat_priv,
int packet_len,
unsigned long send_time,
bool directlink,
const struct hard_iface *if_incoming,
const struct forw_packet *forw_packet)
{
struct batman_packet *batman_packet =
(struct batman_packet *)forw_packet->skb->data;
struct batman_ogm_packet *batman_ogm_packet =
(struct batman_ogm_packet *)forw_packet->skb->data;
int aggregated_bytes = forw_packet->packet_len + packet_len;
struct hard_iface *primary_if = NULL;
bool res = false;
Expand Down Expand Up @@ -71,8 +72,8 @@ static bool can_aggregate_with(const 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_ogm_packet->flags & DIRECTLINK)) &&
(batman_ogm_packet->ttl != 1) &&

/* own packets originating non-primary
* interfaces leave only that interface */
Expand All @@ -85,13 +86,13 @@ static bool can_aggregate_with(const 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_ogm_packet->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_ogm_packet->flags & DIRECTLINK ||
(forw_packet->own &&
forw_packet->if_incoming != primary_if))) {
res = true;
Expand Down Expand Up @@ -213,17 +214,19 @@ 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_ogm_packet *batman_ogm_packet;
bool direct_link;

batman_ogm_packet = (struct batman_ogm_packet *)packet_buff;
direct_link = batman_ogm_packet->flags & DIRECTLINK ? 1 : 0;

/* find position for the packet in the forward queue */
spin_lock_bh(&bat_priv->forw_bat_list_lock);
/* own packets are not to be aggregated */
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_ogm_packet,
bat_priv,
packet_len,
send_time,
Expand Down Expand Up @@ -267,27 +270,28 @@ void receive_aggr_bat_packet(const struct ethhdr *ethhdr,
unsigned char *packet_buff, int packet_len,
struct hard_iface *if_incoming)
{
struct batman_packet *batman_packet;
struct batman_ogm_packet *batman_ogm_packet;
int buff_pos = 0;
unsigned char *tt_buff;

batman_packet = (struct batman_packet *)packet_buff;
batman_ogm_packet = (struct batman_ogm_packet *)packet_buff;

do {
/* 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);
batman_ogm_packet->seqno = ntohl(batman_ogm_packet->seqno);
batman_ogm_packet->tt_crc = ntohs(batman_ogm_packet->tt_crc);

tt_buff = packet_buff + buff_pos + BAT_PACKET_LEN;
tt_buff = packet_buff + buff_pos + BATMAN_OGM_LEN;

receive_bat_packet(ethhdr, batman_packet, tt_buff, if_incoming);
receive_bat_packet(ethhdr, batman_ogm_packet,
tt_buff, if_incoming);

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

batman_packet = (struct batman_packet *)
(packet_buff + buff_pos);
batman_ogm_packet = (struct batman_ogm_packet *)
(packet_buff + buff_pos);
} while (aggregated_packet(buff_pos, packet_len,
batman_packet->tt_num_changes));
batman_ogm_packet->tt_num_changes));
}
2 changes: 1 addition & 1 deletion net/batman-adv/aggregation.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +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_len(tt_num_changes);
int next_buff_pos = buff_pos + BATMAN_OGM_LEN + tt_len(tt_num_changes);

return (next_buff_pos <= packet_len) &&
(next_buff_pos <= MAX_AGGREGATION_BYTES);
Expand Down
49 changes: 27 additions & 22 deletions net/batman-adv/hard-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ static void primary_if_select(struct bat_priv *bat_priv,
struct hard_iface *new_hard_iface)
{
struct hard_iface *curr_hard_iface;
struct batman_packet *batman_packet;
struct batman_ogm_packet *batman_ogm_packet;

ASSERT_RTNL();

Expand All @@ -147,9 +147,10 @@ static void primary_if_select(struct bat_priv *bat_priv,
if (!new_hard_iface)
return;

batman_packet = (struct batman_packet *)(new_hard_iface->packet_buff);
batman_packet->flags = PRIMARIES_FIRST_HOP;
batman_packet->ttl = TTL;
batman_ogm_packet = (struct batman_ogm_packet *)
(new_hard_iface->packet_buff);
batman_ogm_packet->flags = PRIMARIES_FIRST_HOP;
batman_ogm_packet->ttl = TTL;

primary_if_update_addr(bat_priv);
}
Expand All @@ -164,9 +165,12 @@ static bool hardif_is_iface_up(const struct hard_iface *hard_iface)

static void update_mac_addresses(struct hard_iface *hard_iface)
{
memcpy(((struct batman_packet *)(hard_iface->packet_buff))->orig,
struct batman_ogm_packet *batman_ogm_packet;

batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff;
memcpy(batman_ogm_packet->orig,
hard_iface->net_dev->dev_addr, ETH_ALEN);
memcpy(((struct batman_packet *)(hard_iface->packet_buff))->prev_sender,
memcpy(batman_ogm_packet->prev_sender,
hard_iface->net_dev->dev_addr, ETH_ALEN);
}

Expand Down Expand Up @@ -283,7 +287,7 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
const char *iface_name)
{
struct bat_priv *bat_priv;
struct batman_packet *batman_packet;
struct batman_ogm_packet *batman_ogm_packet;
struct net_device *soft_iface;
int ret;

Expand Down Expand Up @@ -318,7 +322,7 @@ int hardif_enable_interface(struct hard_iface *hard_iface,

hard_iface->soft_iface = soft_iface;
bat_priv = netdev_priv(hard_iface->soft_iface);
hard_iface->packet_len = BAT_PACKET_LEN;
hard_iface->packet_len = BATMAN_OGM_LEN;
hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);

if (!hard_iface->packet_buff) {
Expand All @@ -328,14 +332,15 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
goto err;
}

batman_packet = (struct batman_packet *)(hard_iface->packet_buff);
batman_packet->packet_type = BAT_PACKET;
batman_packet->version = COMPAT_VERSION;
batman_packet->flags = NO_FLAGS;
batman_packet->ttl = 2;
batman_packet->tq = TQ_MAX_VALUE;
batman_packet->tt_num_changes = 0;
batman_packet->ttvn = 0;
batman_ogm_packet = (struct batman_ogm_packet *)
(hard_iface->packet_buff);
batman_ogm_packet->packet_type = BAT_OGM;
batman_ogm_packet->version = COMPAT_VERSION;
batman_ogm_packet->flags = NO_FLAGS;
batman_ogm_packet->ttl = 2;
batman_ogm_packet->tq = TQ_MAX_VALUE;
batman_ogm_packet->tt_num_changes = 0;
batman_ogm_packet->ttvn = 0;

hard_iface->if_num = bat_priv->num_ifaces;
bat_priv->num_ifaces++;
Expand Down Expand Up @@ -580,7 +585,7 @@ static int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
struct net_device *orig_dev)
{
struct bat_priv *bat_priv;
struct batman_packet *batman_packet;
struct batman_ogm_packet *batman_ogm_packet;
struct hard_iface *hard_iface;
int ret;

Expand Down Expand Up @@ -612,21 +617,21 @@ static int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
if (hard_iface->if_status != IF_ACTIVE)
goto err_free;

batman_packet = (struct batman_packet *)skb->data;
batman_ogm_packet = (struct batman_ogm_packet *)skb->data;

if (batman_packet->version != COMPAT_VERSION) {
if (batman_ogm_packet->version != COMPAT_VERSION) {
bat_dbg(DBG_BATMAN, bat_priv,
"Drop packet: incompatible batman version (%i)\n",
batman_packet->version);
batman_ogm_packet->version);
goto err_free;
}

/* all receive handlers return whether they received or reused
* the supplied skb. if not, we have to free the skb. */

switch (batman_packet->packet_type) {
switch (batman_ogm_packet->packet_type) {
/* batman originator packet */
case BAT_PACKET:
case BAT_OGM:
ret = recv_bat_packet(skb, hard_iface);
break;

Expand Down
18 changes: 9 additions & 9 deletions net/batman-adv/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@
#define ETH_P_BATMAN 0x4305 /* unofficial/not registered Ethertype */

enum bat_packettype {
BAT_PACKET = 0x01,
BAT_ICMP = 0x02,
BAT_UNICAST = 0x03,
BAT_BCAST = 0x04,
BAT_VIS = 0x05,
BAT_OGM = 0x01,
BAT_ICMP = 0x02,
BAT_UNICAST = 0x03,
BAT_BCAST = 0x04,
BAT_VIS = 0x05,
BAT_UNICAST_FRAG = 0x06,
BAT_TT_QUERY = 0x07,
BAT_ROAM_ADV = 0x08
BAT_TT_QUERY = 0x07,
BAT_ROAM_ADV = 0x08
};

/* this file is included by batctl which needs these defines */
Expand Down Expand Up @@ -90,7 +90,7 @@ enum tt_client_flags {
TT_CLIENT_PENDING = 1 << 10
};

struct batman_packet {
struct batman_ogm_packet {
uint8_t packet_type;
uint8_t version; /* batman version field */
uint8_t ttl;
Expand All @@ -105,7 +105,7 @@ struct batman_packet {
uint16_t tt_crc;
} __packed;

#define BAT_PACKET_LEN sizeof(struct batman_packet)
#define BATMAN_OGM_LEN sizeof(struct batman_ogm_packet)

struct icmp_packet {
uint8_t packet_type;
Expand Down
Loading

0 comments on commit b6da4bf

Please sign in to comment.