netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Antonio Quartulli <antonio-x4xJYDvStAgysxA8WJXlww@public.gmane.org>
To: The list for a Better Approach To Mobile Ad-hoc Networking
	<b.a.t.m.a.n-ZwoEplunGu2X36UT3dwllkB+6BGkLq7r@public.gmane.org>
Cc: netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Marek Lindner <lindner_marek-LWAfsSFWpa4@public.gmane.org>,
	davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org,
	Simon Wunderlich
	<siwu-MaAgPAbsBIVS8oHt8HbXEIQuADTiUCJX@public.gmane.org>
Subject: Re: [PATCH 13/16] batman-adv: add build check macros for packet member offset
Date: Thu, 10 Oct 2013 10:55:06 +0200	[thread overview]
Message-ID: <20131010085506.GB576@neomailbox.net> (raw)
In-Reply-To: <AE90C24D6B3A694183C094C60CF0A2F6026B7387-CgBM+Bx2aUAnGFn1LkZF6NBPR1lH4CV8@public.gmane.org>

[-- Attachment #1: Type: text/plain, Size: 1735 bytes --]

On Thu, Oct 10, 2013 at 09:37:32AM +0100, David Laight wrote:
> > Since we removed the __packed from most of the packets, we should
> > make sure that the offset generated by the compiler are correct for
> > sent/received data.
> ...
> > +	/* compile time checks for struct member offsets */
> > +	BUILD_BUG_ON(offsetof(struct batadv_unicast_4addr_packet, src) != 10);
> > +	BUILD_BUG_ON(offsetof(struct batadv_unicast_packet, dest) != 4);
> > +	BUILD_BUG_ON(offsetof(struct batadv_unicast_frag_packet, dest) != 4);
> > +	BUILD_BUG_ON(offsetof(struct batadv_unicast_tvlv_packet, dst) != 4);
> > +	BUILD_BUG_ON(offsetof(struct batadv_icmp_packet, dst) != 4);
> > +	BUILD_BUG_ON(offsetof(struct batadv_icmp_packet_rr, dst) != 4);
> 
> It is usually enough to check the size of the structures.

What if two fields are inverted by mistake in a way that the
size of the struct remains the same? The size check would not complain but the
code would not work anymore.

We use a "generic" struct to access the initial part of any packet.
Therefore these checks are to ensure that the information we are going to access
is really placed at that offset, whatever packet we have.
It was not possible to use a common inner struct and so we relied on this test
to be safe.

> Which is also best done in the .h file so it is validated
> in all the compilation environments that might be used.
> 

This does not really hurt at the moment because we placed them in main.c which
is a file that is always compiled. But thanks for the suggestion: putting them
in the .h file helps to remind the developer to add a new BUILD_ON_BUG when
creating a new packet type.


Thanks a lot.

Regards,

-- 
Antonio Quartulli

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

  parent reply	other threads:[~2013-10-10  8:55 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-09 19:32 pull request: batman-adv 2013-10-09b Antonio Quartulli
2013-10-09 19:32 ` [PATCH 01/16] MAINTAINERS: batman-adv - update emails Antonio Quartulli
2013-10-09 19:32 ` [PATCH 02/16] batman-adv: switch to a new packet compatibility version Antonio Quartulli
2013-10-09 19:32 ` [PATCH 03/16] batman-adv: tvlv - basic infrastructure Antonio Quartulli
2013-10-09 19:32 ` [PATCH 04/16] batman-adv: tvlv - gateway download/upload bandwidth container Antonio Quartulli
2013-10-09 19:32 ` [PATCH 05/16] batman-adv: tvlv - add distributed arp table container Antonio Quartulli
2013-10-09 19:32 ` [PATCH 06/16] batman-adv: tvlv - add network coding container Antonio Quartulli
2013-10-09 19:32 ` [PATCH 07/16] batman-adv: tvlv - convert tt data sent within OGMs Antonio Quartulli
2013-10-09 19:32 ` [PATCH 08/16] batman-adv: tvlv - convert tt query packet to use tvlv unicast packets Antonio Quartulli
2013-10-09 19:32 ` [PATCH 09/16] batman-adv: tvlv - convert roaming adv " Antonio Quartulli
2013-10-09 19:32 ` [PATCH 10/16] batman-adv: use CRC32C instead of CRC16 in TT code Antonio Quartulli
2013-10-09 19:32 ` [PATCH 11/16] batman-adv: move BATADV_TT_CLIENT_TEMP to higher bit Antonio Quartulli
2013-10-09 19:32 ` [PATCH 12/16] batman-adv: remove vis functionality Antonio Quartulli
2013-10-09 19:32 ` [PATCH 13/16] batman-adv: add build check macros for packet member offset Antonio Quartulli
     [not found]   ` <1381347174-3629-14-git-send-email-antonio-x4xJYDvStAgysxA8WJXlww@public.gmane.org>
2013-10-10  8:37     ` David Laight
     [not found]       ` <AE90C24D6B3A694183C094C60CF0A2F6026B7387-CgBM+Bx2aUAnGFn1LkZF6NBPR1lH4CV8@public.gmane.org>
2013-10-10  8:55         ` Antonio Quartulli [this message]
2013-10-09 19:32 ` [PATCH 14/16] batman-adv: reorder packet types Antonio Quartulli
2013-10-09 19:32 ` [PATCH 15/16] batman-adv: remove packed from batadv_ogm_packet Antonio Quartulli
2013-10-09 19:32 ` [PATCH 16/16] batman-adv: reorder batadv_iv_flags Antonio Quartulli
2013-10-09 19:56 ` pull request: batman-adv 2013-10-09b David Miller
2013-10-11  6:10   ` Antonio Quartulli
     [not found]     ` <20131011061053.GF576-rVWd3aGhH2zPj3vggD0kEA@public.gmane.org>
2013-10-11 20:45       ` David Miller
  -- strict thread matches above, loose matches on Subject: below --
2013-10-09 12:40 pull request: batman-adv 2013-10-09 Antonio Quartulli
2013-10-09 12:40 ` [PATCH 13/16] batman-adv: add build check macros for packet member offset Antonio Quartulli

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=20131010085506.GB576@neomailbox.net \
    --to=antonio-x4xjydvstagysxa8wjxlww@public.gmane.org \
    --cc=b.a.t.m.a.n-ZwoEplunGu2X36UT3dwllkB+6BGkLq7r@public.gmane.org \
    --cc=davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org \
    --cc=lindner_marek-LWAfsSFWpa4@public.gmane.org \
    --cc=netdev-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=siwu-MaAgPAbsBIVS8oHt8HbXEIQuADTiUCJX@public.gmane.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 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).