Skip to content

Commit

Permalink
batman-adv: tvlv - convert tt data sent within OGMs
Browse files Browse the repository at this point in the history
The translation table meta data (version number, crc checksum, etc)
as well as the translation table diff propgated within OGMs now uses
the newly introduced tvlv infrastructure.

Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Signed-off-by: Antonio Quartulli <antonio@meshcoding.com>
  • Loading branch information
Marek Lindner authored and ordex committed Oct 9, 2013
1 parent 3f4841f commit e1bf0c1
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 158 deletions.
44 changes: 14 additions & 30 deletions net/batman-adv/bat_iv_ogm.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
batadv_ogm_packet->flags = BATADV_NO_FLAGS;
batadv_ogm_packet->reserved = 0;
batadv_ogm_packet->tq = BATADV_TQ_MAX_VALUE;
batadv_ogm_packet->tt_num_changes = 0;
batadv_ogm_packet->ttvn = 0;

res = 0;

Expand Down Expand Up @@ -257,14 +255,14 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
fwd_str = "Sending own";

batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
"%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s, ttvn %d) on interface %s [%pM]\n",
"%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s) on interface %s [%pM]\n",
fwd_str, (packet_num > 0 ? "aggregated " : ""),
batadv_ogm_packet->orig,
ntohl(batadv_ogm_packet->seqno),
batadv_ogm_packet->tq, batadv_ogm_packet->header.ttl,
(batadv_ogm_packet->flags & BATADV_DIRECTLINK ?
"on" : "off"),
batadv_ogm_packet->ttvn, hard_iface->net_dev->name,
hard_iface->net_dev->name,
hard_iface->net_dev->dev_addr);

buff_pos += BATADV_OGM_HLEN;
Expand Down Expand Up @@ -689,17 +687,22 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
struct batadv_ogm_packet *batadv_ogm_packet;
struct batadv_hard_iface *primary_if;
int *ogm_buff_len = &hard_iface->bat_iv.ogm_buff_len;
int vis_server, tt_num_changes = 0;
int vis_server;
uint32_t seqno;
uint16_t tvlv_len = 0;

vis_server = atomic_read(&bat_priv->vis_mode);
primary_if = batadv_primary_if_get_selected(bat_priv);

if (hard_iface == primary_if)
if (hard_iface == primary_if) {
/* tt changes have to be committed before the tvlv data is
* appended as it may alter the tt tvlv container
*/
batadv_tt_local_commit_changes(bat_priv);
tvlv_len = batadv_tvlv_container_ogm_append(bat_priv, ogm_buff,
ogm_buff_len,
BATADV_OGM_HLEN);
}

batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
batadv_ogm_packet->tvlv_len = htons(tvlv_len);
Expand All @@ -709,11 +712,6 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
batadv_ogm_packet->seqno = htonl(seqno);
atomic_inc(&hard_iface->bat_iv.ogm_seqno);

batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
if (tt_num_changes >= 0)
batadv_ogm_packet->tt_num_changes = tt_num_changes;

if (vis_server == BATADV_VIS_TYPE_SERVER_SYNC)
batadv_ogm_packet->flags |= BATADV_VIS_SERVER;
else
Expand Down Expand Up @@ -814,11 +812,11 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,
*/
router = batadv_orig_node_get_router(orig_node);
if (router == neigh_node)
goto update_tt;
goto out;

/* if this neighbor does not offer a better TQ we won't consider it */
if (router && (router->tq_avg > neigh_node->tq_avg))
goto update_tt;
goto out;

/* if the TQ is the same and the link not more symmetric we
* won't consider it either
Expand All @@ -837,22 +835,10 @@ batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv,
spin_unlock_bh(&orig_node_tmp->ogm_cnt_lock);

if (sum_orig >= sum_neigh)
goto update_tt;
goto out;
}

batadv_update_route(bat_priv, orig_node, neigh_node);

update_tt:
/* I have to check for transtable changes only if the OGM has been
* sent through a primary interface
*/
if (((batadv_ogm_packet->orig != ethhdr->h_source) &&
(batadv_ogm_packet->header.ttl > 2)) ||
(batadv_ogm_packet->flags & BATADV_PRIMARIES_FIRST_HOP))
batadv_tt_update_orig(bat_priv, orig_node, tt_buff,
batadv_ogm_packet->tt_num_changes,
batadv_ogm_packet->ttvn,
ntohs(batadv_ogm_packet->tt_crc));
goto out;

unlock:
Expand Down Expand Up @@ -1103,13 +1089,11 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
is_single_hop_neigh = true;

batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
"Received BATMAN packet via NB: %pM, IF: %s [%pM] (from OG: %pM, via prev OG: %pM, seqno %u, ttvn %u, crc %#.4x, changes %u, tq %d, TTL %d, V %d, IDF %d)\n",
"Received BATMAN packet via NB: %pM, IF: %s [%pM] (from OG: %pM, via prev OG: %pM, seqno %u, tq %d, TTL %d, V %d, IDF %d)\n",
ethhdr->h_source, if_incoming->net_dev->name,
if_incoming->net_dev->dev_addr, batadv_ogm_packet->orig,
batadv_ogm_packet->prev_sender,
ntohl(batadv_ogm_packet->seqno), batadv_ogm_packet->ttvn,
ntohs(batadv_ogm_packet->tt_crc),
batadv_ogm_packet->tt_num_changes, batadv_ogm_packet->tq,
ntohl(batadv_ogm_packet->seqno), batadv_ogm_packet->tq,
batadv_ogm_packet->header.ttl,
batadv_ogm_packet->header.version, has_directlink_flag);

Expand Down
51 changes: 41 additions & 10 deletions net/batman-adv/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,21 @@ enum batadv_unicast_frag_flags {
/* TT_QUERY subtypes */
#define BATADV_TT_QUERY_TYPE_MASK 0x3

enum batadv_tt_query_packettype {
BATADV_TT_REQUEST = 0,
BATADV_TT_RESPONSE = 1,
};
/* tt data subtypes */
#define BATADV_TT_DATA_TYPE_MASK 0x0F

/* TT_QUERY flags */
enum batadv_tt_query_flags {
BATADV_TT_FULL_TABLE = BIT(2),
/**
* enum batadv_tt_data_flags - flags for tt data tvlv
* @BATADV_TT_OGM_DIFF: TT diff propagated through OGM
* @BATADV_TT_REQUEST: TT request message
* @BATADV_TT_RESPONSE: TT response message
* @BATADV_TT_FULL_TABLE: contains full table to replace existing table
*/
enum batadv_tt_data_flags {
BATADV_TT_OGM_DIFF = BIT(0),
BATADV_TT_REQUEST = BIT(1),
BATADV_TT_RESPONSE = BIT(2),
BATADV_TT_FULL_TABLE = BIT(4),
};

/* BATADV_TT_CLIENT flags.
Expand Down Expand Up @@ -123,11 +130,13 @@ enum batadv_bla_claimframe {
* @BATADV_TVLV_GW: gateway tvlv
* @BATADV_TVLV_DAT: distributed arp table tvlv
* @BATADV_TVLV_NC: network coding tvlv
* @BATADV_TVLV_TT: translation table tvlv
*/
enum batadv_tvlv_type {
BATADV_TVLV_GW = 0x01,
BATADV_TVLV_DAT = 0x02,
BATADV_TVLV_NC = 0x03,
BATADV_TVLV_TT = 0x04,
};

/* the destination hardware field in the ARP frame is used to
Expand Down Expand Up @@ -161,9 +170,6 @@ struct batadv_ogm_packet {
uint8_t prev_sender[ETH_ALEN];
uint8_t reserved;
uint8_t tq;
uint8_t tt_num_changes;
uint8_t ttvn; /* translation table version number */
__be16 tt_crc;
__be16 tvlv_len;
} __packed;

Expand Down Expand Up @@ -375,4 +381,29 @@ struct batadv_tvlv_gateway_data {
__be32 bandwidth_up;
};

/**
* struct batadv_tvlv_tt_data - tt data propagated through the tt tvlv container
* @flags: translation table flags (see batadv_tt_data_flags)
* @ttvn: translation table version number
* @crc: crc16 checksum of the local translation table
*/
struct batadv_tvlv_tt_data {
uint8_t flags;
uint8_t ttvn;
__be16 crc;
};

/**
* struct batadv_tvlv_tt_change - translation table diff data
* @flags: status indicators concerning the non-mesh client (see
* batadv_tt_client_flags)
* @reserved: reserved field
* @addr: mac address of non-mesh client that triggered this tt change
*/
struct batadv_tvlv_tt_change {
uint8_t flags;
uint8_t reserved;
uint8_t addr[ETH_ALEN];
};

#endif /* _NET_BATMAN_ADV_PACKET_H_ */
Loading

0 comments on commit e1bf0c1

Please sign in to comment.