b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: The list for a Better Approach To Mobile Ad-hoc Networking
	<b.a.t.m.a.n@lists.open-mesh.org>
Cc: Linus L??ssing <linus.luessing@ascom.ch>
Subject: Re: [B.A.T.M.A.N.] [PATCH 02/13] batman-adv: Add explicit batman header structure
Date: Wed, 16 Feb 2011 07:08:11 +0100	[thread overview]
Message-ID: <20110216060811.GB11570@lunn.ch> (raw)
In-Reply-To: <1297789948-16948-3-git-send-email-linus.luessing@ascom.ch>

On Tue, Feb 15, 2011 at 06:12:17PM +0100, Linus L??ssing wrote:
> Just a minor style adjustment, to give people a hint which fields should
> not be reordered and need to be at the beginning of each packet with
> batman-adv's frame type.

Hi Linus
  
> +struct batman_header {
> +	uint8_t  packet_type;
> +	uint8_t  version;  /* batman version field */
> +	uint8_t  ttl;
> +	uint8_t  align;
> +} __packed;
> +
>  struct batman_packet {
> -	uint8_t  packet_type;
> -	uint8_t  version;  /* batman version field */
> +	struct   batman_header header;
> +	uint32_t seqno;
>  	uint8_t  flags;    /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
>  	uint8_t  tq;
> -	uint32_t seqno;
>  	uint8_t  orig[6];
>  	uint8_t  prev_sender[6];
> -	uint8_t  ttl;
>  	uint8_t  num_hna;
>  	uint8_t  gw_flags;  /* flags related to gateway class */
> -	uint8_t  align;
>  } __packed;

Two different ideas, both triggered by the align byte in header. This
byte is a waste of space, it is not used, and it is probably not easy
to find something which all packet types are going to need in the
future. 

1) Did you try not having it. So long header is __packed, and all the
structures it is used in are __packed, i think the compiler will do
the right thing. The downside is that alignment is not obvious. Most
people will assume header is 4 bytes, not 3, and think the alignment
of the packets is wrong. 

2) Did you consider using a union? It is a more invasive patch, but
the alignment is then clear. The downside is sizeof() no longer gives
you the per packet type size, rather it gives you the size of the
biggest member of the union. So this makes the change even more
invasive and bug prone.

I think i prefer 1), with appropriate comments to explain the
alignment issue.

	  Andrew

  reply	other threads:[~2011-02-16  6:08 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-15 17:12 [B.A.T.M.A.N.] Redundancy bonding mode patches, v1 Linus Lüssing
2011-02-15 17:12 ` [B.A.T.M.A.N.] [PATCH 01/13] batman-adv: Remove unused hdr_size variable in route_unicast_packet() Linus Lüssing
2011-02-15 17:12 ` [B.A.T.M.A.N.] [PATCH 02/13] batman-adv: Add explicit batman header structure Linus Lüssing
2011-02-16  6:08   ` Andrew Lunn [this message]
2011-02-16 15:05     ` Linus Luessing
2011-02-15 17:12 ` [B.A.T.M.A.N.] [PATCH 03/13] batman-adv: Unify TTL handling Linus Lüssing
2011-02-16  6:16   ` Andrew Lunn
2011-02-16 14:42     ` Linus Luessing
2011-02-15 17:12 ` [B.A.T.M.A.N.] [PATCH 04/13] batman-adv: Make route_unicast_packet() packet_type independent Linus Lüssing
2011-02-15 17:12 ` [B.A.T.M.A.N.] [PATCH 05/13] batman-adv: Add rcu-refcount wrapper for orig_node hash_find() Linus Lüssing
2011-02-15 17:12 ` [B.A.T.M.A.N.] [PATCH 06/13] batman-adv: Use route_unicast_packet() for sending own unicast packets Linus Lüssing
2011-02-15 17:12 ` [B.A.T.M.A.N.] [PATCH 07/13] batman-adv: Avoid redundant hash_find() call for " Linus Lüssing
2011-02-15 17:12 ` [B.A.T.M.A.N.] [PATCH 08/13] batman-adv: Use packet lists for unicast packet sending Linus Lüssing
2011-02-15 17:12 ` [B.A.T.M.A.N.] [PATCH 09/13] batman-adv: Add sysfs option for enabling redundant bonding mode Linus Lüssing
2011-02-15 17:12 ` [B.A.T.M.A.N.] [PATCH 10/13] batman-adv: Adding redundant bonding mode transmission Linus Lüssing
2011-02-15 17:12 ` [B.A.T.M.A.N.] [PATCH 11/13] batman-adv: Adding unicast_safe packet reception Linus Lüssing
2011-02-15 17:12 ` [B.A.T.M.A.N.] [PATCH 12/13] batman-adv: Generic sequence number checking for data packets Linus Lüssing
2011-02-15 17:12 ` [B.A.T.M.A.N.] [PATCH 13/13] batman-adv: Add sequence number and duplicate checks for unicasts_safe Linus Lüssing

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=20110216060811.GB11570@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=linus.luessing@ascom.ch \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).