aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/bat_iv_ogm.c
diff options
context:
space:
mode:
authorMarek Lindner <lindner_marek@yahoo.de>2013-04-23 09:39:57 -0400
committerAntonio Quartulli <antonio@meshcoding.com>2013-10-09 15:22:26 -0400
commitef26157747d42254453f6b3ac2bd8bd3c53339c3 (patch)
treeac9f366de417ca89b225143eb176b9618376f5eb /net/batman-adv/bat_iv_ogm.c
parent60cf7981b770e329a05734d1e6eb055f13219202 (diff)
batman-adv: tvlv - basic infrastructure
The goal is to provide the infrastructure for sending, receiving and parsing information 'containers' while preserving backward compatibility. TVLV (based on the commonly known Type Length Value technique) was chosen as the format for those containers. Even if a node does not know the tvlv type of a certain container it can simply skip the current container and proceed with the next. Past experience has shown features evolve over time, so a 'version' field was added right from the start to allow differentiating between feature variants - hence the name: T(ype) V(ersion) L(ength) V(alue). This patch introduces the basic TVLV infrastructure: * register / unregister tvlv containers to be sent with each OGM (on primary interfaces only) * register / unregister callback handlers to be called upon finding the corresponding tvlv type in a tvlv buffer * unicast tvlv send / receive API calls Signed-off-by: Marek Lindner <lindner_marek@yahoo.de> Signed-off-by: Spyros Gasteratos <morfeas3000@gmail.com> Signed-off-by: Antonio Quartulli <antonio@meshcoding.com>
Diffstat (limited to 'net/batman-adv/bat_iv_ogm.c')
-rw-r--r--net/batman-adv/bat_iv_ogm.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 0a8a80cd4bf1..f7dd7e51fff4 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -207,12 +207,12 @@ static uint8_t batadv_hop_penalty(uint8_t tq,
207 207
208/* is there another aggregated packet here? */ 208/* is there another aggregated packet here? */
209static int batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len, 209static int batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len,
210 int tt_num_changes) 210 __be16 tvlv_len)
211{ 211{
212 int next_buff_pos = 0; 212 int next_buff_pos = 0;
213 213
214 next_buff_pos += buff_pos + BATADV_OGM_HLEN; 214 next_buff_pos += buff_pos + BATADV_OGM_HLEN;
215 next_buff_pos += batadv_tt_len(tt_num_changes); 215 next_buff_pos += ntohs(tvlv_len);
216 216
217 return (next_buff_pos <= packet_len) && 217 return (next_buff_pos <= packet_len) &&
218 (next_buff_pos <= BATADV_MAX_AGGREGATION_BYTES); 218 (next_buff_pos <= BATADV_MAX_AGGREGATION_BYTES);
@@ -240,7 +240,7 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
240 240
241 /* adjust all flags and log packets */ 241 /* adjust all flags and log packets */
242 while (batadv_iv_ogm_aggr_packet(buff_pos, forw_packet->packet_len, 242 while (batadv_iv_ogm_aggr_packet(buff_pos, forw_packet->packet_len,
243 batadv_ogm_packet->tt_num_changes)) { 243 batadv_ogm_packet->tvlv_len)) {
244 /* we might have aggregated direct link packets with an 244 /* we might have aggregated direct link packets with an
245 * ordinary base packet 245 * ordinary base packet
246 */ 246 */
@@ -267,7 +267,7 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
267 hard_iface->net_dev->dev_addr); 267 hard_iface->net_dev->dev_addr);
268 268
269 buff_pos += BATADV_OGM_HLEN; 269 buff_pos += BATADV_OGM_HLEN;
270 buff_pos += batadv_tt_len(batadv_ogm_packet->tt_num_changes); 270 buff_pos += ntohs(batadv_ogm_packet->tvlv_len);
271 packet_num++; 271 packet_num++;
272 packet_pos = forw_packet->skb->data + buff_pos; 272 packet_pos = forw_packet->skb->data + buff_pos;
273 batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos; 273 batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos;
@@ -601,7 +601,7 @@ static void batadv_iv_ogm_forward(struct batadv_orig_node *orig_node,
601 struct batadv_hard_iface *if_incoming) 601 struct batadv_hard_iface *if_incoming)
602{ 602{
603 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); 603 struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
604 uint8_t tt_num_changes; 604 uint16_t tvlv_len;
605 605
606 if (batadv_ogm_packet->header.ttl <= 1) { 606 if (batadv_ogm_packet->header.ttl <= 1) {
607 batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "ttl exceeded\n"); 607 batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "ttl exceeded\n");
@@ -621,7 +621,7 @@ static void batadv_iv_ogm_forward(struct batadv_orig_node *orig_node,
621 return; 621 return;
622 } 622 }
623 623
624 tt_num_changes = batadv_ogm_packet->tt_num_changes; 624 tvlv_len = ntohs(batadv_ogm_packet->tvlv_len);
625 625
626 batadv_ogm_packet->header.ttl--; 626 batadv_ogm_packet->header.ttl--;
627 memcpy(batadv_ogm_packet->prev_sender, ethhdr->h_source, ETH_ALEN); 627 memcpy(batadv_ogm_packet->prev_sender, ethhdr->h_source, ETH_ALEN);
@@ -642,7 +642,7 @@ static void batadv_iv_ogm_forward(struct batadv_orig_node *orig_node,
642 batadv_ogm_packet->flags &= ~BATADV_DIRECTLINK; 642 batadv_ogm_packet->flags &= ~BATADV_DIRECTLINK;
643 643
644 batadv_iv_ogm_queue_add(bat_priv, (unsigned char *)batadv_ogm_packet, 644 batadv_iv_ogm_queue_add(bat_priv, (unsigned char *)batadv_ogm_packet,
645 BATADV_OGM_HLEN + batadv_tt_len(tt_num_changes), 645 BATADV_OGM_HLEN + tvlv_len,
646 if_incoming, 0, batadv_iv_ogm_fwd_send_time()); 646 if_incoming, 0, batadv_iv_ogm_fwd_send_time());
647} 647}
648 648
@@ -691,16 +691,18 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
691 int vis_server, tt_num_changes = 0; 691 int vis_server, tt_num_changes = 0;
692 uint32_t seqno; 692 uint32_t seqno;
693 uint8_t bandwidth; 693 uint8_t bandwidth;
694 uint16_t tvlv_len = 0;
694 695
695 vis_server = atomic_read(&bat_priv->vis_mode); 696 vis_server = atomic_read(&bat_priv->vis_mode);
696 primary_if = batadv_primary_if_get_selected(bat_priv); 697 primary_if = batadv_primary_if_get_selected(bat_priv);
697 698
698 if (hard_iface == primary_if) 699 if (hard_iface == primary_if)
699 tt_num_changes = batadv_tt_append_diff(bat_priv, ogm_buff, 700 tvlv_len = batadv_tvlv_container_ogm_append(bat_priv, ogm_buff,
700 ogm_buff_len, 701 ogm_buff_len,
701 BATADV_OGM_HLEN); 702 BATADV_OGM_HLEN);
702 703
703 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff); 704 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
705 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
704 706
705 /* change sequence number to network order */ 707 /* change sequence number to network order */
706 seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno); 708 seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
@@ -1254,6 +1256,8 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
1254 goto out; 1256 goto out;
1255 } 1257 }
1256 1258
1259 batadv_tvlv_ogm_receive(bat_priv, batadv_ogm_packet, orig_node);
1260
1257 /* if sender is a direct neighbor the sender mac equals 1261 /* if sender is a direct neighbor the sender mac equals
1258 * originator mac 1262 * originator mac
1259 */ 1263 */
@@ -1350,9 +1354,9 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb,
1350 struct batadv_ogm_packet *batadv_ogm_packet; 1354 struct batadv_ogm_packet *batadv_ogm_packet;
1351 struct ethhdr *ethhdr; 1355 struct ethhdr *ethhdr;
1352 int buff_pos = 0, packet_len; 1356 int buff_pos = 0, packet_len;
1353 unsigned char *tt_buff, *packet_buff; 1357 unsigned char *tvlv_buff, *packet_buff;
1354 bool ret;
1355 uint8_t *packet_pos; 1358 uint8_t *packet_pos;
1359 bool ret;
1356 1360
1357 ret = batadv_check_management_packet(skb, if_incoming, BATADV_OGM_HLEN); 1361 ret = batadv_check_management_packet(skb, if_incoming, BATADV_OGM_HLEN);
1358 if (!ret) 1362 if (!ret)
@@ -1375,14 +1379,14 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb,
1375 1379
1376 /* unpack the aggregated packets and process them one by one */ 1380 /* unpack the aggregated packets and process them one by one */
1377 while (batadv_iv_ogm_aggr_packet(buff_pos, packet_len, 1381 while (batadv_iv_ogm_aggr_packet(buff_pos, packet_len,
1378 batadv_ogm_packet->tt_num_changes)) { 1382 batadv_ogm_packet->tvlv_len)) {
1379 tt_buff = packet_buff + buff_pos + BATADV_OGM_HLEN; 1383 tvlv_buff = packet_buff + buff_pos + BATADV_OGM_HLEN;
1380 1384
1381 batadv_iv_ogm_process(ethhdr, batadv_ogm_packet, tt_buff, 1385 batadv_iv_ogm_process(ethhdr, batadv_ogm_packet,
1382 if_incoming); 1386 tvlv_buff, if_incoming);
1383 1387
1384 buff_pos += BATADV_OGM_HLEN; 1388 buff_pos += BATADV_OGM_HLEN;
1385 buff_pos += batadv_tt_len(batadv_ogm_packet->tt_num_changes); 1389 buff_pos += ntohs(batadv_ogm_packet->tvlv_len);
1386 1390
1387 packet_pos = packet_buff + buff_pos; 1391 packet_pos = packet_buff + buff_pos;
1388 batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos; 1392 batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos;