Skip to contentSkip to conversation

batman-adv: Record route for ICMP messages

PATCH Superseded Daniel Seither 2 participants 3 messages Feb 15, 2010

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 batman-adv: Record route for ICMP messages

The standard layer 3 ping utility can use the record route (RR) option of IP to collect route data for sent ping messages (ping -R). This patch introduces comparable functionality for batman-adv ICMP messages.

The patch adds a second batman ICMP packet format (icmp_packet_rr) such that up to 17 MAC addresses can be recorded (sufficient for up to 8 hops per direction). When no RR is wanted, the old icmp_packet without the RR overhead can be sent.

batctl is extended to recognize the -R option for the ping subcommand. The output should be the same as for the standard iputils ping program. For this, the destination host is printed two times.

---

types.h +1 -1
Index: batman-adv-kernelland/types.h
===================================================================
@@ -106,7 +106,7 @@
 
 struct device_packet {
 	struct list_head list;
-	struct icmp_packet icmp_packet;
+	struct icmp_packet_rr icmp_packet;
 };
 
 struct hna_local_entry {
packet.h +18 -0
Index: batman-adv-kernelland/packet.h
===================================================================
@@ -26,6 +26,7 @@
 #define BAT_UNICAST   0x03
 #define BAT_BCAST     0x04
 #define BAT_VIS       0x05
+#define BAT_ICMP_RR   0x06
 
 /* this file is included by batctl which needs these defines */
 #define COMPAT_VERSION 9
@@ -71,6 +72,23 @@
 	uint8_t  uid;
 } __attribute__((packed));
 
+#define BAT_RR_LEN 96
+
+/* icmp_packet_rr must start with all fields from imcp_packet
+   as this is assumed by code that handles ICMP packets */
+struct icmp_packet_rr {
+	uint8_t  packet_type;
+	uint8_t  version;  /* batman version field */
+	uint8_t  msg_type; /* see ICMP message types above */
+	uint8_t  ttl;
+	uint8_t  dst[6];
+	uint8_t  orig[6];
+	uint16_t seqno;
+	uint8_t  uid;
+	uint8_t  rr_cur;
+	uint8_t  rr[BAT_RR_LEN];
+} __attribute__((packed));
+
 struct unicast_packet {
 	uint8_t  packet_type;
 	uint8_t  version;  /* batman version field */
device.c +39 -11

121 lines not on this page · raw message

device.h +2 -2
Index: batman-adv-kernelland/device.h
===================================================================
@@ -32,5 +32,5 @@
 			 size_t len, loff_t *off);
 unsigned int bat_device_poll(struct file *file, poll_table *wait);
 void bat_device_add_packet(struct device_client *device_client,
-			   struct icmp_packet *icmp_packet);
-void bat_device_receive_packet(struct icmp_packet *icmp_packet);
+			   struct icmp_packet_rr *icmp_packet);
+void bat_device_receive_packet(struct icmp_packet_rr *icmp_packet);
hard-interface.c +1 -0
Index: batman-adv-kernelland/hard-interface.c
===================================================================
@@ -479,6 +479,7 @@
 
 		/* batman icmp packet */
 	case BAT_ICMP:
+	case BAT_ICMP_RR:
 		ret = recv_icmp_packet(skb);
 		break;
 
routing.c +33 -9

112 lines not on this page · raw message

ping.c +57 -12

136 lines not on this page · raw message

#1 lore raw
Quoted 5 lines
packet.h +5 -0
+#define BAT_RR_LEN 96
+
+/* icmp_packet_rr must start with all fields from imcp_packet
+   as this is assumed by code that handles ICMP packets */
+struct icmp_packet_rr {

packet.h line 89

Quoted 10 lines
packet.h +10 -0
+	uint8_t  packet_type;
+	uint8_t  version;  /* batman version field */
+	uint8_t  msg_type; /* see ICMP message types above */
+	uint8_t  ttl;
+	uint8_t  dst[6];
+	uint8_t  orig[6];
+	uint16_t seqno;
+	uint8_t  uid;
+	uint8_t  rr_cur;
+	uint8_t  rr[BAT_RR_LEN];

This might be more readable as

uint8_t rr[BAT_RR_ENTRIES][ETH_ALEN];

and then your memcpy becomes

/* add record route information if not full */

if (icmp_packet->rr_cur < BAT_RR_ENTRIES) {
	memcpy(icmp_packet->rr[icmp_packet->rr_cur++],
		ethhdr->h_dest, ETH_ALEN);
}

while looks nicer.

Quoted 14 lines
device.c +2 -1
+} __attribute__((packed));
 
 
 ssize_t bat_device_write(struct file *file, const char __user *buff,
@@ -206,28 +210,42 @@
 {
 	struct device_client *device_client =
 		(struct device_client *)file->private_data;
-	struct icmp_packet icmp_packet;
+	struct icmp_packet_rr icmp_packet;
 	struct orig_node *orig_node;
 	struct batman_if *batman_if;
 	uint8_t dstaddr[ETH_ALEN];
 	unsigned long flags;

device.c line 226

Quoted 10 lines
device.c +3 -1
+	size_t packet_len = sizeof(struct icmp_packet);
+	int with_rr = 0;
 
 	if (len < sizeof(struct icmp_packet)) {
 		bat_dbg(DBG_BATMAN, "batman-adv:Error - can't send packet from char device: invalid packet size\n");
 		return -EINVAL;
 	}
 
-	if (!access_ok(VERIFY_READ, buff, sizeof(struct icmp_packet)))
+	if (len >= sizeof(struct icmp_packet_rr)) {

At first look, this looks wrong. I would of expected icmp_packet, not icmp_packet_rr. But maybe it is right?

Quoted 16 lines
routing.c +4 -2
 int recv_icmp_packet(struct sk_buff *skb)
 {
-	struct icmp_packet *icmp_packet;
+	struct icmp_packet_rr *icmp_packet;
 	struct ethhdr *ethhdr;
 	struct orig_node *orig_node;
 	struct sk_buff *skb_old;
@@ -860,8 +868,24 @@
 	if (!is_my_mac(ethhdr->h_dest))
 		return NET_RX_DROP;
 
-	icmp_packet = (struct icmp_packet *) skb->data;
+	icmp_packet = (struct icmp_packet_rr *) skb->data;
 
+	if (icmp_packet->packet_type == BAT_ICMP_RR) {
+		hdr_size = sizeof(struct icmp_packet_rr);

routing.c line 884

Quoted 10 lines
routing.c +10 -0
+
+		/* drop packet if it has not necessary minimum size */
+		if (skb_headlen(skb) < hdr_size)
+			return NET_RX_DROP;
+
+		/* add record route information if not full */
+		if (icmp_packet->rr_cur > 0
+			&& icmp_packet->rr_cur < BAT_RR_LEN / ETH_ALEN) {
+			memcpy(&(icmp_packet->rr[icmp_packet->rr_cur * ETH_ALEN]),
+				ethhdr->h_dest, ETH_ALEN);

Why rr_cur > 0?

Andrew

#2 lore raw
Quoted 6 lines · Andrew Lunn

packet.h line 89

Quoted 1 line
packet.h +1 -0
+	uint8_t  rr[BAT_RR_LEN];

This might be more readable as

uint8_t rr[BAT_RR_ENTRIES][ETH_ALEN];

Quoted 7 lines

and then your memcpy becomes

/* add record route information if not full */

if (icmp_packet->rr_cur < BAT_RR_ENTRIES) {
	memcpy(icmp_packet->rr[icmp_packet->rr_cur++],
		ethhdr->h_dest, ETH_ALEN);
}

You're right, this makes things easier => changed.

Quoted 19 lines
Quoted 19 lines

ssize_t bat_device_write(struct file *file, const char __user *buff,

device.c +3 -1
@@ -206,28 +210,42 @@
 {
 	struct device_client *device_client =
 		(struct device_client *)file->private_data;
-	struct icmp_packet icmp_packet;
+	struct icmp_packet_rr icmp_packet;
 	struct orig_node *orig_node;
 	struct batman_if *batman_if;
 	uint8_t dstaddr[ETH_ALEN];
 	unsigned long flags;
+	size_t packet_len = sizeof(struct icmp_packet);
+	int with_rr = 0;
 
 	if (len < sizeof(struct icmp_packet)) {
 		bat_dbg(DBG_BATMAN, "batman-adv:Error - can't send packet from char device: invalid packet size\n");
 		return -EINVAL;
 	}
 
Quoted 5 lines

device.c line 226

Quoted 2 lines
device.c +1 -1
-	if (!access_ok(VERIFY_READ, buff, sizeof(struct icmp_packet)))
+	if (len >= sizeof(struct icmp_packet_rr)) {

At first look, this looks wrong. I would of expected icmp_packet, not icmp_packet_rr. But maybe it is right?

It is right: At this point, the program doesn't know whether an icmp_packet or an icmp_packet_rr is written. However, it can distinguish these two by looking at the length of the data: if len >= sizeof(struct icmp_packet_rr), the packet is long enough to include RR info and is therefore treated as such.

Quoted 14 lines
Quoted 14 lines
routing.c +2 -2
 int recv_icmp_packet(struct sk_buff *skb)
 {
-	struct icmp_packet *icmp_packet;
+	struct icmp_packet_rr *icmp_packet;
 	struct ethhdr *ethhdr;
 	struct orig_node *orig_node;
 	struct sk_buff *skb_old;
@@ -860,8 +868,24 @@
 	if (!is_my_mac(ethhdr->h_dest))
 		return NET_RX_DROP;
 
-	icmp_packet = (struct icmp_packet *) skb->data;
+	icmp_packet = (struct icmp_packet_rr *) skb->data;
 
Quoted 14 lines

routing.c line 884

Quoted 12 lines
routing.c +12 -0
+	if (icmp_packet->packet_type == BAT_ICMP_RR) {
+		hdr_size = sizeof(struct icmp_packet_rr);
+
+		/* drop packet if it has not necessary minimum size */
+		if (skb_headlen(skb) < hdr_size)
+			return NET_RX_DROP;
+
+		/* add record route information if not full */
+		if (icmp_packet->rr_cur > 0
+			&& icmp_packet->rr_cur < BAT_RR_LEN / ETH_ALEN) {
+			memcpy(&(icmp_packet->rr[icmp_packet->rr_cur * ETH_ALEN]),
+				ethhdr->h_dest, ETH_ALEN);

Why rr_cur > 0?

For historical reasons ;-) rr_cur generally is the index for rr that indicates the next position to be written to. In the first version of the patch, a value of 0 for rr_cur indicated that RR is not active. This is no longer neccessary => changed. Thanks for pointing out.

Regards, Daniel