Skip to content

Commit

Permalink
batman-adv: fix size of batadv_icmp_header
Browse files Browse the repository at this point in the history
struct batadv_icmp_header currently has a size of 17, which
will be padded to 20 on some architectures. Fix this by
unrolling the header into the parent structures.

Moreover keep the ICMP parsing functions as generic as they
are now by using a stub icmp_header struct during packet
parsing.

Signed-off-by: Antonio Quartulli <[email protected]>
Signed-off-by: Marek Lindner <[email protected]>
  • Loading branch information
ordex committed Dec 28, 2013
1 parent a40d9b0 commit 27a417e
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
4 changes: 2 additions & 2 deletions net/batman-adv/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,8 @@ static void batadv_recv_handler_init(void)
BUILD_BUG_ON(offsetof(struct batadv_unicast_packet, dest) != 4);
BUILD_BUG_ON(offsetof(struct batadv_unicast_tvlv_packet, dst) != 4);
BUILD_BUG_ON(offsetof(struct batadv_frag_packet, dest) != 4);
BUILD_BUG_ON(offsetof(struct batadv_icmp_packet, icmph.dst) != 4);
BUILD_BUG_ON(offsetof(struct batadv_icmp_packet_rr, icmph.dst) != 4);
BUILD_BUG_ON(offsetof(struct batadv_icmp_packet, dst) != 4);
BUILD_BUG_ON(offsetof(struct batadv_icmp_packet_rr, dst) != 4);

/* broadcast packet */
batadv_rx_handler[BATADV_BCAST] = batadv_recv_bcast_packet;
Expand Down
40 changes: 35 additions & 5 deletions net/batman-adv/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,19 @@ struct batadv_ogm_packet {
#define BATADV_OGM_HLEN sizeof(struct batadv_ogm_packet)

/**
* batadv_icmp_header - common ICMP header
* batadv_icmp_header - common members among all the ICMP packets
* @packet_type: batman-adv packet type, part of the general header
* @version: batman-adv protocol version, part of the genereal header
* @ttl: time to live for this packet, part of the genereal header
* @msg_type: ICMP packet type
* @dst: address of the destination node
* @orig: address of the source node
* @uid: local ICMP socket identifier
* @align: not used - useful for alignment purposes only
*
* This structure is used for ICMP packets parsing only and it is never sent
* over the wire. The alignment field at the end is there to ensure that
* members are padded the same way as they are in real packets.
*/
struct batadv_icmp_header {
uint8_t packet_type;
Expand All @@ -208,16 +213,29 @@ struct batadv_icmp_header {
uint8_t dst[ETH_ALEN];
uint8_t orig[ETH_ALEN];
uint8_t uid;
uint8_t align[3];
};

/**
* batadv_icmp_packet - ICMP packet
* @icmph: common ICMP header
* @packet_type: batman-adv packet type, part of the general header
* @version: batman-adv protocol version, part of the genereal header
* @ttl: time to live for this packet, part of the genereal header
* @msg_type: ICMP packet type
* @dst: address of the destination node
* @orig: address of the source node
* @uid: local ICMP socket identifier
* @reserved: not used - useful for alignment
* @seqno: ICMP sequence number
*/
struct batadv_icmp_packet {
struct batadv_icmp_header icmph;
uint8_t packet_type;
uint8_t version;
uint8_t ttl;
uint8_t msg_type; /* see ICMP message types above */
uint8_t dst[ETH_ALEN];
uint8_t orig[ETH_ALEN];
uint8_t uid;
uint8_t reserved;
__be16 seqno;
};
Expand All @@ -226,13 +244,25 @@ struct batadv_icmp_packet {

/**
* batadv_icmp_packet_rr - ICMP RouteRecord packet
* @icmph: common ICMP header
* @packet_type: batman-adv packet type, part of the general header
* @version: batman-adv protocol version, part of the genereal header
* @ttl: time to live for this packet, part of the genereal header
* @msg_type: ICMP packet type
* @dst: address of the destination node
* @orig: address of the source node
* @uid: local ICMP socket identifier
* @rr_cur: number of entries the rr array
* @seqno: ICMP sequence number
* @rr: route record array
*/
struct batadv_icmp_packet_rr {
struct batadv_icmp_header icmph;
uint8_t packet_type;
uint8_t version;
uint8_t ttl;
uint8_t msg_type; /* see ICMP message types above */
uint8_t dst[ETH_ALEN];
uint8_t orig[ETH_ALEN];
uint8_t uid;
uint8_t rr_cur;
__be16 seqno;
uint8_t rr[BATADV_RR_LEN][ETH_ALEN];
Expand Down
14 changes: 7 additions & 7 deletions net/batman-adv/routing.c
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,9 @@ static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv,
icmp_packet = (struct batadv_icmp_packet *)skb->data;

/* send TTL exceeded if packet is an echo request (traceroute) */
if (icmp_packet->icmph.msg_type != BATADV_ECHO_REQUEST) {
if (icmp_packet->msg_type != BATADV_ECHO_REQUEST) {
pr_debug("Warning - can't forward icmp packet from %pM to %pM: ttl exceeded\n",
icmp_packet->icmph.orig, icmp_packet->icmph.dst);
icmp_packet->orig, icmp_packet->dst);
goto out;
}

Expand All @@ -349,7 +349,7 @@ static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv,
goto out;

/* get routing information */
orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->icmph.orig);
orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->orig);
if (!orig_node)
goto out;

Expand All @@ -359,11 +359,11 @@ static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv,

icmp_packet = (struct batadv_icmp_packet *)skb->data;

memcpy(icmp_packet->icmph.dst, icmp_packet->icmph.orig, ETH_ALEN);
memcpy(icmp_packet->icmph.orig, primary_if->net_dev->dev_addr,
memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN);
memcpy(icmp_packet->orig, primary_if->net_dev->dev_addr,
ETH_ALEN);
icmp_packet->icmph.msg_type = BATADV_TTL_EXCEEDED;
icmp_packet->icmph.ttl = BATADV_TTL;
icmp_packet->msg_type = BATADV_TTL_EXCEEDED;
icmp_packet->ttl = BATADV_TTL;

if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP)
ret = NET_RX_SUCCESS;
Expand Down

0 comments on commit 27a417e

Please sign in to comment.