Skip to content

Commit ef26157

Browse files
Marek Lindnerordex
authored andcommitted
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 <[email protected]> Signed-off-by: Spyros Gasteratos <[email protected]> Signed-off-by: Antonio Quartulli <[email protected]>
1 parent 60cf798 commit ef26157

File tree

7 files changed

+794
-17
lines changed

7 files changed

+794
-17
lines changed

net/batman-adv/bat_iv_ogm.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,12 @@ static uint8_t batadv_hop_penalty(uint8_t tq,
207207

208208
/* is there another aggregated packet here? */
209209
static int batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len,
210-
int tt_num_changes)
210+
__be16 tvlv_len)
211211
{
212212
int next_buff_pos = 0;
213213

214214
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);
216216

217217
return (next_buff_pos <= packet_len) &&
218218
(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,
240240

241241
/* adjust all flags and log packets */
242242
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)) {
244244
/* we might have aggregated direct link packets with an
245245
* ordinary base packet
246246
*/
@@ -267,7 +267,7 @@ static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet,
267267
hard_iface->net_dev->dev_addr);
268268

269269
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);
271271
packet_num++;
272272
packet_pos = forw_packet->skb->data + buff_pos;
273273
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,
601601
struct batadv_hard_iface *if_incoming)
602602
{
603603
struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface);
604-
uint8_t tt_num_changes;
604+
uint16_t tvlv_len;
605605

606606
if (batadv_ogm_packet->header.ttl <= 1) {
607607
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,
621621
return;
622622
}
623623

624-
tt_num_changes = batadv_ogm_packet->tt_num_changes;
624+
tvlv_len = ntohs(batadv_ogm_packet->tvlv_len);
625625

626626
batadv_ogm_packet->header.ttl--;
627627
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,
642642
batadv_ogm_packet->flags &= ~BATADV_DIRECTLINK;
643643

644644
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,
646646
if_incoming, 0, batadv_iv_ogm_fwd_send_time());
647647
}
648648

@@ -691,16 +691,18 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
691691
int vis_server, tt_num_changes = 0;
692692
uint32_t seqno;
693693
uint8_t bandwidth;
694+
uint16_t tvlv_len = 0;
694695

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

698699
if (hard_iface == primary_if)
699-
tt_num_changes = batadv_tt_append_diff(bat_priv, ogm_buff,
700-
ogm_buff_len,
701-
BATADV_OGM_HLEN);
700+
tvlv_len = batadv_tvlv_container_ogm_append(bat_priv, ogm_buff,
701+
ogm_buff_len,
702+
BATADV_OGM_HLEN);
702703

703704
batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
705+
batadv_ogm_packet->tvlv_len = htons(tvlv_len);
704706

705707
/* change sequence number to network order */
706708
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,
12541256
goto out;
12551257
}
12561258

1259+
batadv_tvlv_ogm_receive(bat_priv, batadv_ogm_packet, orig_node);
1260+
12571261
/* if sender is a direct neighbor the sender mac equals
12581262
* originator mac
12591263
*/
@@ -1350,9 +1354,9 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb,
13501354
struct batadv_ogm_packet *batadv_ogm_packet;
13511355
struct ethhdr *ethhdr;
13521356
int buff_pos = 0, packet_len;
1353-
unsigned char *tt_buff, *packet_buff;
1354-
bool ret;
1357+
unsigned char *tvlv_buff, *packet_buff;
13551358
uint8_t *packet_pos;
1359+
bool ret;
13561360

13571361
ret = batadv_check_management_packet(skb, if_incoming, BATADV_OGM_HLEN);
13581362
if (!ret)
@@ -1375,14 +1379,14 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb,
13751379

13761380
/* unpack the aggregated packets and process them one by one */
13771381
while (batadv_iv_ogm_aggr_packet(buff_pos, packet_len,
1378-
batadv_ogm_packet->tt_num_changes)) {
1379-
tt_buff = packet_buff + buff_pos + BATADV_OGM_HLEN;
1382+
batadv_ogm_packet->tvlv_len)) {
1383+
tvlv_buff = packet_buff + buff_pos + BATADV_OGM_HLEN;
13801384

1381-
batadv_iv_ogm_process(ethhdr, batadv_ogm_packet, tt_buff,
1382-
if_incoming);
1385+
batadv_iv_ogm_process(ethhdr, batadv_ogm_packet,
1386+
tvlv_buff, if_incoming);
13831387

13841388
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);
13861390

13871391
packet_pos = packet_buff + buff_pos;
13881392
batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos;

0 commit comments

Comments
 (0)