All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Seither <post@tiwoc.de>
To: The list for a Better Approach To Mobile Ad-hoc Networking
	<b.a.t.m.a.n@lists.open-mesh.org>
Subject: Re: [B.A.T.M.A.N.] [PATCH v2] batman-adv: Record route for ICMP messages
Date: Mon, 15 Feb 2010 22:21:56 +0100	[thread overview]
Message-ID: <4B79BAF4.3010105@tiwoc.de> (raw)
In-Reply-To: <20100215162258.GL2900@lunn.ch>

Andrew Lunn schrieb:
>> +	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);
> }

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

>>  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;
>> +	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?

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.

>>  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);
>> +
>> +		/* 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

      reply	other threads:[~2010-02-15 21:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-15 15:28 [B.A.T.M.A.N.] [PATCH v2] batman-adv: Record route for ICMP messages Daniel Seither
2010-02-15 16:22 ` Andrew Lunn
2010-02-15 21:21   ` Daniel Seither [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B79BAF4.3010105@tiwoc.de \
    --to=post@tiwoc.de \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.