b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Al Viro <viro@ZenIV.linux.org.uk>
To: Antonio Quartulli <ordex@autistici.org>
Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org,
	davem@davemloft.net
Subject: [B.A.T.M.A.N.] batman: trivial endianness annotations
Date: Wed, 18 Apr 2012 19:14:55 +0100	[thread overview]
Message-ID: <20120418181455.GF6589@ZenIV.linux.org.uk> (raw)
In-Reply-To: <20120418180837.GB6589@ZenIV.linux.org.uk>

Missing endianness annotations - on-the-wire data and ip addresses.
BTW, casting memcpy() arguments to (uint8_t *) is cargo-cult programming -
they are void *, which is precisely "take any pointer to object"...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
 net/batman-adv/bridge_loop_avoidance.c |    8 ++++----
 net/batman-adv/distributed-arp-table.c |   16 ++++++++--------
 net/batman-adv/distributed-arp-table.h |    4 ++--
 net/batman-adv/packet.h                |   12 ++++++------
 4 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
index 8bf9751..d51288b 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -258,7 +258,7 @@ static void bla_send_claim(struct bat_priv *bat_priv, uint8_t *mac,
 	struct net_device *soft_iface;
 	uint8_t *hw_src;
 	struct bla_claim_dst local_claim_dest;
-	uint32_t zeroip = 0;
+	__be32 zeroip = 0;
 
 	primary_if = primary_if_get_selected(bat_priv);
 	if (!primary_if)
@@ -506,11 +506,11 @@ static void bla_send_announce(struct bat_priv *bat_priv,
 			      struct backbone_gw *backbone_gw)
 {
 	uint8_t mac[ETH_ALEN];
-	uint16_t crc;
+	__be16 crc;
 
 	memcpy(mac, announce_mac, 4);
 	crc = htons(backbone_gw->crc);
-	memcpy(&mac[4], (uint8_t *)&crc, 2);
+	memcpy(&mac[4], &crc, 2);
 
 	bla_send_claim(bat_priv, mac, backbone_gw->vid, CLAIM_TYPE_ANNOUNCE);
 
@@ -627,7 +627,7 @@ static int handle_announce(struct bat_priv *bat_priv,
 
 	/* handle as ANNOUNCE frame */
 	backbone_gw->lasttime = jiffies;
-	crc = ntohs(*((uint16_t *)(&an_addr[4])));
+	crc = ntohs(*((__be16 *)(&an_addr[4])));
 
 	bat_dbg(DBG_BLA, bat_priv,
 		"handle_announce(): ANNOUNCE vid %d (sent by %pM)... CRC = %04x\n",
diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c
index b43bece..d87f914 100644
--- a/net/batman-adv/distributed-arp-table.c
+++ b/net/batman-adv/distributed-arp-table.c
@@ -192,7 +192,7 @@ static void choose_next_candidate(struct bat_priv *bat_priv,
  *
  * return an array of size DHT_CANDIDATES_NUM */
 static struct dht_candidate *dht_select_candidates(struct bat_priv *bat_priv,
-						   uint32_t ip_dst)
+						   __be32 ip_dst)
 {
 	int select;
 	dat_addr_t last_max = DAT_ADDR_MAX, ip_key;
@@ -224,7 +224,7 @@ static struct dht_candidate *dht_select_candidates(struct bat_priv *bat_priv,
  * If the packet is successfully sent to at least one candidate, then this
  * function returns true */
 static bool dht_send_data(struct bat_priv *bat_priv, struct sk_buff *skb,
-			  uint32_t ip, int packet_subtype)
+			  __be32 ip, int packet_subtype)
 {
 	int i;
 	bool ret = false;
@@ -270,7 +270,7 @@ out:
 /* Update the neighbour entry corresponding to the IP passed as parameter with
  * the hw address hw. If the neighbour entry doesn't exists, then it will be
  * created */
-static void arp_neigh_update(struct bat_priv *bat_priv, uint32_t ip,
+static void arp_neigh_update(struct bat_priv *bat_priv, __be32 ip,
 			     uint8_t *hw)
 {
 	struct neighbour *n = NULL;
@@ -299,7 +299,7 @@ static uint16_t arp_get_type(struct bat_priv *bat_priv, struct sk_buff *skb,
 {
 	struct arphdr *arphdr;
 	struct ethhdr *ethhdr;
-	uint32_t ip_src, ip_dst;
+	__be32 ip_src, ip_dst;
 	uint16_t type = 0;
 
 	/* pull the ethernet header */
@@ -352,7 +352,7 @@ bool dat_snoop_outgoing_arp_request(struct bat_priv *bat_priv,
 				    struct sk_buff *skb)
 {
 	uint16_t type = 0;
-	uint32_t ip_dst, ip_src;
+	__be32 ip_dst, ip_src;
 	uint8_t *hw_src;
 	bool ret = false;
 	struct neighbour *n = NULL;
@@ -414,7 +414,7 @@ bool dat_snoop_incoming_arp_request(struct bat_priv *bat_priv,
 				    struct sk_buff *skb, int hdr_size)
 {
 	uint16_t type;
-	uint32_t ip_src, ip_dst;
+	__be32 ip_src, ip_dst;
 	uint8_t *hw_src;
 	struct hard_iface *primary_if = NULL;
 	struct sk_buff *skb_new;
@@ -470,7 +470,7 @@ bool dat_snoop_outgoing_arp_reply(struct bat_priv *bat_priv,
 				  struct sk_buff *skb)
 {
 	uint16_t type;
-	uint32_t ip_src, ip_dst;
+	__be32 ip_src, ip_dst;
 	uint8_t *hw_src, *hw_dst;
 	bool ret = false;
 
@@ -503,7 +503,7 @@ bool dat_snoop_incoming_arp_reply(struct bat_priv *bat_priv,
 				  struct sk_buff *skb, int hdr_size)
 {
 	uint16_t type;
-	uint32_t ip_src, ip_dst;
+	__be32 ip_src, ip_dst;
 	uint8_t *hw_src, *hw_dst;
 	bool ret = false;
 
diff --git a/net/batman-adv/distributed-arp-table.h b/net/batman-adv/distributed-arp-table.h
index fcf6c15..01d5b4f 100644
--- a/net/batman-adv/distributed-arp-table.h
+++ b/net/batman-adv/distributed-arp-table.h
@@ -33,10 +33,10 @@
 
 #define ARP_HW_SRC(skb, hdr_size) ((uint8_t *)(skb->data + hdr_size) + \
 				   ETH_HLEN + sizeof(struct arphdr))
-#define ARP_IP_SRC(skb, hdr_size) (*(uint32_t *)(ARP_HW_SRC(skb, hdr_size) + \
+#define ARP_IP_SRC(skb, hdr_size) (*(__be32 *)(ARP_HW_SRC(skb, hdr_size) + \
 				   ETH_ALEN))
 #define ARP_HW_DST(skb, hdr_size) (ARP_HW_SRC(skb, hdr_size) + ETH_ALEN + 4)
-#define ARP_IP_DST(skb, hdr_size) (*(uint32_t *)(ARP_HW_SRC(skb, hdr_size) + \
+#define ARP_IP_DST(skb, hdr_size) (*(__be32 *)(ARP_HW_SRC(skb, hdr_size) + \
 				   ETH_ALEN * 2 + 4))
 
 bool dat_snoop_outgoing_arp_request(struct bat_priv *bat_priv,
diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h
index ad39938..eb4fdf6 100644
--- a/net/batman-adv/packet.h
+++ b/net/batman-adv/packet.h
@@ -113,7 +113,7 @@ enum bla_claimframe {
 struct bla_claim_dst {
 	uint8_t magic[3];	/* FF:43:05 */
 	uint8_t type;		/* bla_claimframe */
-	uint16_t group;		/* group id */
+	__be16 group;		/* group id */
 } __packed;
 
 struct batman_header {
@@ -142,7 +142,7 @@ struct icmp_packet {
 	uint8_t  msg_type; /* see ICMP message types above */
 	uint8_t  dst[ETH_ALEN];
 	uint8_t  orig[ETH_ALEN];
-	uint16_t seqno;
+	__be16   seqno;
 	uint8_t  uid;
 	uint8_t  reserved;
 } __packed;
@@ -156,7 +156,7 @@ struct icmp_packet_rr {
 	uint8_t  msg_type; /* see ICMP message types above */
 	uint8_t  dst[ETH_ALEN];
 	uint8_t  orig[ETH_ALEN];
-	uint16_t seqno;
+	__be16   seqno;
 	uint8_t  uid;
 	uint8_t  rr_cur;
 	uint8_t  rr[BAT_RR_LEN][ETH_ALEN];
@@ -181,20 +181,20 @@ struct unicast_frag_packet {
 	uint8_t  flags;
 	uint8_t  align;
 	uint8_t  orig[ETH_ALEN];
-	uint16_t seqno;
+	__be16   seqno;
 } __packed;
 
 struct bcast_packet {
 	struct batman_header header;
 	uint8_t  reserved;
-	uint32_t seqno;
+	__be32   seqno;
 	uint8_t  orig[ETH_ALEN];
 } __packed;
 
 struct vis_packet {
 	struct batman_header header;
 	uint8_t  vis_type;	 /* which type of vis-participant sent this? */
-	uint32_t seqno;		 /* sequence number */
+	__be32   seqno;		 /* sequence number */
 	uint8_t  entries;	 /* number of entries behind this struct */
 	uint8_t  reserved;
 	uint8_t  vis_orig[ETH_ALEN];	/* originator reporting its neighbors */
-- 
1.7.2.5


  parent reply	other threads:[~2012-04-18 18:14 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-18  9:59 [B.A.T.M.A.N.] pull request: batman-adv 2012-04-18 Antonio Quartulli
2012-04-18  9:59 ` [B.A.T.M.A.N.] [PATCH 01/13] batman-adv: convert the tt_crc to network order Antonio Quartulli
2012-04-18  9:59 ` [B.A.T.M.A.N.] [PATCH 02/13] batman-adv: remove duplicated line in comment Antonio Quartulli
2012-04-18 10:00 ` [B.A.T.M.A.N.] [PATCH 03/13] batman-adv: move ogm initialization into the proper function Antonio Quartulli
2012-04-18 10:00 ` [B.A.T.M.A.N.] [PATCH 04/13] batman-adv: refactoring API: find generalized name for bat_ogm_init callback Antonio Quartulli
2012-04-18 10:00 ` [B.A.T.M.A.N.] [PATCH 05/13] batman-adv: randomize initial seqno to avoid collision Antonio Quartulli
2012-04-18 10:00 ` [B.A.T.M.A.N.] [PATCH 06/13] batman-adv: add iface_disable() callback to routing API Antonio Quartulli
2012-04-18 10:00 ` [B.A.T.M.A.N.] [PATCH 07/13] batman-adv: handle routing code initialization properly Antonio Quartulli
2012-04-18 10:00 ` [B.A.T.M.A.N.] [PATCH 08/13] batman-adv: refactoring API: find generalized name for bat_ogm_init_primary callback Antonio Quartulli
2012-04-18 10:00 ` [B.A.T.M.A.N.] [PATCH 09/13] batman-adv: rename BATMAN_OGM_LEN to BATMAN_OGM_HLEN Antonio Quartulli
2012-04-18 10:00 ` [B.A.T.M.A.N.] [PATCH 10/13] batman-adv: mark existing ogm variables as batman iv Antonio Quartulli
2012-04-18 10:00 ` [B.A.T.M.A.N.] [PATCH 11/13] batman-adv: use ETH_HLEN instead of sizeof(struct ethhdr) Antonio Quartulli
2012-04-18 10:00 ` [B.A.T.M.A.N.] [PATCH 12/13] batman-adv: print OGM seq numbers as unsigned int Antonio Quartulli
2012-04-18 10:00 ` [B.A.T.M.A.N.] [PATCH 13/13] batman-adv: skip the window protection test when the originator has no neighbours Antonio Quartulli
2012-04-18 17:22 ` [B.A.T.M.A.N.] pull request: batman-adv 2012-04-18 David Miller
2012-04-18 18:08 ` Al Viro
2012-04-18 18:09   ` [B.A.T.M.A.N.] [PATCH 1/4] batman: don't bother flipping ->tt_data Al Viro
2012-04-18 18:10   ` [B.A.T.M.A.N.] [PATCH 2/4] batman: don't bother flipping ->tt_crc Al Viro
2012-04-19  5:41     ` Antonio Quartulli
2012-04-19  5:49       ` Antonio Quartulli
2012-04-18 18:11   ` [B.A.T.M.A.N.] batman: keep batman_ogm_packet ->seqno net-endian all along Al Viro
2012-04-18 18:15     ` Al Viro
2012-04-18 18:14   ` Al Viro [this message]
     [not found]   ` <20120419061026.GC8658@ritirata.org>
     [not found]     ` <20120419134854.GA6871@ZenIV.linux.org.uk>
2012-04-19 14:09       ` [B.A.T.M.A.N.] pull request: batman-adv 2012-04-18 Antonio Quartulli
2012-04-23  5:18         ` Marek Lindner
2012-04-23  6:43           ` Al Viro
2012-04-23  7:17             ` Marek Lindner
     [not found]     ` <20120422064426.GU6871@ZenIV.linux.org.uk>
2012-04-25 12:11       ` [B.A.T.M.A.N.] [PATCH 1/5] batman-adv: don't bother flipping ->tt_data Marek Lindner
     [not found]     ` <20120422065029.GY6871@ZenIV.linux.org.uk>
2012-04-25 12:14       ` [B.A.T.M.A.N.] [PATCH 5/5] batman-adv: get rid of pointless cast in memcpy() Marek Lindner
     [not found]     ` <20120422064750.GX6871@ZenIV.linux.org.uk>
2012-04-25 12:18       ` [B.A.T.M.A.N.] [PATCH 4/5] batman-adv: trivial endianness annotations Marek Lindner
     [not found]     ` <20120422064629.GW6871@ZenIV.linux.org.uk>
2012-04-25 12:25       ` [B.A.T.M.A.N.] [PATCH 3/5] batman-adv: keep batman_ogm_packet ->seqno net-endian all along Marek Lindner

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=20120418181455.GF6589@ZenIV.linux.org.uk \
    --to=viro@zeniv.linux.org.uk \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=ordex@autistici.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).