Repository : ssh://git@open-mesh.org/batctl
On branch : master
commit 0270fea0a0cac4864d709b5e6c12849d62610151 Author: Marek Lindner lindner_marek@yahoo.de Date: Tue Apr 23 21:39:57 2013 +0800
batctl: 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
0270fea0a0cac4864d709b5e6c12849d62610151 Makefile | 2 +- main.h | 8 ++++++++ packet.h | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 1 deletion(-)
diff --git a/Makefile b/Makefile index 311e70e..00cce9d 100755 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ OBJ_BISECT = bisect_iv.o MANPAGE = man/batctl.8
# batctl flags and options -CFLAGS += -pedantic -Wall -W -std=gnu99 -fno-strict-aliasing -MD +CFLAGS += -Wall -W -std=gnu99 -fno-strict-aliasing -MD LDLIBS += -lm
# disable verbose output diff --git a/main.h b/main.h index c916353..ad13c2a 100644 --- a/main.h +++ b/main.h @@ -33,6 +33,14 @@ #define DEBUG_TABLE_PATH_MAX_LEN 20 #define SETTINGS_PATH_MAX_LEN 25
+#if BYTE_ORDER == BIG_ENDIAN +#define __BIG_ENDIAN_BITFIELD +#elif BYTE_ORDER == LITTLE_ENDIAN +#define __LITTLE_ENDIAN_BITFIELD +#else +#error "unknown endianess" +#endif + #define __packed __attribute((packed)) /* linux kernel compat */ #define BIT(nr) (1UL << (nr)) /* linux kernel compat */
diff --git a/packet.h b/packet.h index 11a22c8..f990531 100644 --- a/packet.h +++ b/packet.h @@ -20,6 +20,10 @@ #ifndef _NET_BATMAN_ADV_PACKET_H_ #define _NET_BATMAN_ADV_PACKET_H_
+/** + * enum batadv_packettype - types for batman-adv encapsulated packets + * @BATADV_UNICAST_TVLV: unicast packet carrying TVLV containers + */ enum batadv_packettype { BATADV_IV_OGM = 0x01, BATADV_ICMP = 0x02, @@ -31,6 +35,7 @@ enum batadv_packettype { BATADV_ROAM_ADV = 0x08, BATADV_UNICAST_4ADDR = 0x09, BATADV_CODED = 0x0a, + BATADV_UNICAST_TVLV = 0x0b, };
/** @@ -131,6 +136,11 @@ struct batadv_header { */ };
+/** + * struct batadv_ogm_packet - ogm (routing protocol) packet + * @header: common batman packet header + * @tvlv_len: length of tvlv data following the ogm header + */ struct batadv_ogm_packet { struct batadv_header header; uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */ @@ -142,6 +152,7 @@ struct batadv_ogm_packet { uint8_t tt_num_changes; uint8_t ttvn; /* translation table version number */ __be16 tt_crc; + __be16 tvlv_len; } __packed;
#define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet) @@ -311,4 +322,60 @@ struct batadv_coded_packet { __be16 coded_len; };
+/** + * struct batadv_unicast_tvlv - generic unicast packet with tvlv payload + * @header: common batman packet header + * @reserved: reserved field (for packet alignment) + * @src: address of the source + * @dst: address of the destination + * @tvlv_len: length of tvlv data following the unicast tvlv header + */ +struct batadv_unicast_tvlv_packet { + struct batadv_header header; + uint8_t reserved; + uint8_t dst[ETH_ALEN]; + uint8_t src[ETH_ALEN]; + __be16 tvlv_len; +}; + +/** + * struct batadv_tvlv_hdr - base tvlv header struct + * @long_tvlv: flag indicating whether this is a short tvlv container (max 256 + * bytes) or a long tvlv one (up to ETH_DATA_LEN) + * @type: tvlv container type (see batadv_tvlv_type) + * @version: tvlv container version + */ +struct batadv_tvlv_hdr { +#if defined(__BIG_ENDIAN_BITFIELD) + uint8_t long_tvlv:1; + uint8_t type:7; +#elif defined(__LITTLE_ENDIAN_BITFIELD) + uint8_t type:7; + uint8_t long_tvlv:1; +#else +#error "unknown bitfield endianess" +#endif + uint8_t version; +}; + +/** + * struct batadv_tvlv_short - short tvlv header struct + * @tvlv_hdr: base tvlv header + * @len: tvlv container length (limited to 255 bytes) + */ +struct batadv_tvlv_short { + struct batadv_tvlv_hdr tvlv_hdr; + uint8_t len; +}; + +/** + * struct batadv_tvlv_long - long tvlv header struct + * @tvlv_hdr: base tvlv header + * @len: tvlv container length + */ +struct batadv_tvlv_long { + struct batadv_tvlv_hdr tvlv_hdr; + __be16 len; +}; + #endif /* _NET_BATMAN_ADV_PACKET_H_ */