From: Antonio Quartulli antonio@open-mesh.com
In order to make batman-adv fully vlan aware later, the semantic used for variables storing the VLAN ID values has to be changed in order to be adapted to the new one which will be used batman-adv wide.
In particular, the VID has to be an "_unsigned_ short int" and its 4 MSB will be used as a flag bitfield, while the remaining 12 bits are used to store the real VID value
Cc: Simon Wunderlich siwu@hrz.tu-chemnitz.de Signed-off-by: Antonio Quartulli antonio@open-mesh.com ---
v2: - fix print format on every occurence - add second patch to print VID+FLAGS properly
bridge_loop_avoidance.c | 86 +++++++++++++++++++++++++++---------------------- bridge_loop_avoidance.h | 12 ++++--- main.h | 11 +++++++ soft-interface.c | 4 +-- types.h | 4 +-- 5 files changed, 69 insertions(+), 48 deletions(-)
diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c index 0cc0c3e..16f9239 100644 --- a/bridge_loop_avoidance.c +++ b/bridge_loop_avoidance.c @@ -180,7 +180,7 @@ static struct batadv_bla_claim */ static struct batadv_bla_backbone_gw * batadv_backbone_hash_find(struct batadv_priv *bat_priv, - uint8_t *addr, short vid) + uint8_t *addr, unsigned short vid) { struct batadv_hashtable *hash = bat_priv->bla.backbone_hash; struct hlist_head *head; @@ -257,7 +257,7 @@ batadv_bla_del_backbone_claims(struct batadv_bla_backbone_gw *backbone_gw) * @claimtype: the type of the claim (CLAIM, UNCLAIM, ANNOUNCE, ...) */ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac, - short vid, int claimtype) + unsigned short vid, int claimtype) { struct sk_buff *skb; struct ethhdr *ethhdr; @@ -307,7 +307,7 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac, */ memcpy(ethhdr->h_source, mac, ETH_ALEN); batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_send_claim(): CLAIM %pM on vid %d\n", mac, vid); + "bla_send_claim(): CLAIM %pM on vid %hu\n", mac, vid); break; case BATADV_CLAIM_TYPE_UNCLAIM: /* unclaim frame @@ -315,7 +315,7 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac, */ memcpy(hw_src, mac, ETH_ALEN); batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_send_claim(): UNCLAIM %pM on vid %d\n", mac, + "bla_send_claim(): UNCLAIM %pM on vid %hu\n", mac, vid); break; case BATADV_CLAIM_TYPE_ANNOUNCE: @@ -324,7 +324,7 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac, */ memcpy(hw_src, mac, ETH_ALEN); batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_send_claim(): ANNOUNCE of %pM on vid %d\n", + "bla_send_claim(): ANNOUNCE of %pM on vid %hu\n", ethhdr->h_source, vid); break; case BATADV_CLAIM_TYPE_REQUEST: @@ -335,13 +335,13 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac, memcpy(hw_src, mac, ETH_ALEN); memcpy(ethhdr->h_dest, mac, ETH_ALEN); batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_send_claim(): REQUEST of %pM to %pMon vid %d\n", + "bla_send_claim(): REQUEST of %pM to %pM on vid %hu\n", ethhdr->h_source, ethhdr->h_dest, vid); break; }
- if (vid != -1) - skb = vlan_insert_tag(skb, vid); + if (vid & BATADV_VLAN_HAS_TAG) + skb = vlan_insert_tag(skb, vid & BATADV_VID_MASK);
skb_reset_mac_header(skb); skb->protocol = eth_type_trans(skb, soft_iface); @@ -367,7 +367,7 @@ out: */ static struct batadv_bla_backbone_gw * batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, uint8_t *orig, - short vid, bool own_backbone) + unsigned short vid, bool own_backbone) { struct batadv_bla_backbone_gw *entry; struct batadv_orig_node *orig_node; @@ -379,7 +379,7 @@ batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, uint8_t *orig, return entry;
batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_get_backbone_gw(): not found (%pM, %d), creating new entry\n", + "bla_get_backbone_gw(): not found (%pM, %hu), creating new entry\n", orig, vid);
entry = kzalloc(sizeof(*entry), GFP_ATOMIC); @@ -434,7 +434,7 @@ batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, uint8_t *orig, static void batadv_bla_update_own_backbone_gw(struct batadv_priv *bat_priv, struct batadv_hard_iface *primary_if, - short vid) + unsigned short vid) { struct batadv_bla_backbone_gw *backbone_gw;
@@ -456,7 +456,7 @@ batadv_bla_update_own_backbone_gw(struct batadv_priv *bat_priv, */ static void batadv_bla_answer_request(struct batadv_priv *bat_priv, struct batadv_hard_iface *primary_if, - short vid) + unsigned short vid) { struct hlist_head *head; struct batadv_hashtable *hash; @@ -547,7 +547,7 @@ static void batadv_bla_send_announce(struct batadv_priv *bat_priv, * @backbone_gw: the backbone gateway which claims it */ static void batadv_bla_add_claim(struct batadv_priv *bat_priv, - const uint8_t *mac, const short vid, + const uint8_t *mac, const unsigned short vid, struct batadv_bla_backbone_gw *backbone_gw) { struct batadv_bla_claim *claim; @@ -571,7 +571,7 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,
atomic_set(&claim->refcount, 2); batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_add_claim(): adding new entry %pM, vid %d to hash ...\n", + "bla_add_claim(): adding new entry %pM, vid %hu to hash ...\n", mac, vid); hash_added = batadv_hash_add(bat_priv->bla.claim_hash, batadv_compare_claim, @@ -590,7 +590,7 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv, goto claim_free_ref;
batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_add_claim(): changing ownership for %pM, vid %d\n", + "bla_add_claim(): changing ownership for %pM, vid %hu\n", mac, vid);
claim->backbone_gw->crc ^= crc16(0, claim->addr, ETH_ALEN); @@ -611,7 +611,7 @@ claim_free_ref: * given mac address and vid. */ static void batadv_bla_del_claim(struct batadv_priv *bat_priv, - const uint8_t *mac, const short vid) + const uint8_t *mac, const unsigned short vid) { struct batadv_bla_claim search_claim, *claim;
@@ -621,7 +621,7 @@ static void batadv_bla_del_claim(struct batadv_priv *bat_priv, if (!claim) return;
- batadv_dbg(BATADV_DBG_BLA, bat_priv, "bla_del_claim(): %pM, vid %d\n", + batadv_dbg(BATADV_DBG_BLA, bat_priv, "bla_del_claim(): %pM, vid %hu\n", mac, vid);
batadv_hash_remove(bat_priv->bla.claim_hash, batadv_compare_claim, @@ -637,7 +637,7 @@ static void batadv_bla_del_claim(struct batadv_priv *bat_priv, /* check for ANNOUNCE frame, return 1 if handled */ static int batadv_handle_announce(struct batadv_priv *bat_priv, uint8_t *an_addr, uint8_t *backbone_addr, - short vid) + unsigned short vid) { struct batadv_bla_backbone_gw *backbone_gw; uint16_t crc; @@ -657,12 +657,12 @@ static int batadv_handle_announce(struct batadv_priv *bat_priv, crc = ntohs(*((__be16 *)(&an_addr[4])));
batadv_dbg(BATADV_DBG_BLA, bat_priv, - "handle_announce(): ANNOUNCE vid %d (sent by %pM)... CRC = %#.4x\n", + "handle_announce(): ANNOUNCE vid %hu (sent by %pM)... CRC = %#.4x\n", vid, backbone_gw->orig, crc);
if (backbone_gw->crc != crc) { batadv_dbg(BATADV_DBG_BLA, backbone_gw->bat_priv, - "handle_announce(): CRC FAILED for %pM/%d (my = %#.4x, sent = %#.4x)\n", + "handle_announce(): CRC FAILED for %pM/%hu (my = %#.4x, sent = %#.4x)\n", backbone_gw->orig, backbone_gw->vid, backbone_gw->crc, crc);
@@ -685,7 +685,7 @@ static int batadv_handle_announce(struct batadv_priv *bat_priv, static int batadv_handle_request(struct batadv_priv *bat_priv, struct batadv_hard_iface *primary_if, uint8_t *backbone_addr, - struct ethhdr *ethhdr, short vid) + struct ethhdr *ethhdr, unsigned short vid) { /* check for REQUEST frame */ if (!batadv_compare_eth(backbone_addr, ethhdr->h_dest)) @@ -698,7 +698,7 @@ static int batadv_handle_request(struct batadv_priv *bat_priv, return 1;
batadv_dbg(BATADV_DBG_BLA, bat_priv, - "handle_request(): REQUEST vid %d (sent by %pM)...\n", + "handle_request(): REQUEST vid %hu (sent by %pM)...\n", vid, ethhdr->h_source);
batadv_bla_answer_request(bat_priv, primary_if, vid); @@ -709,7 +709,7 @@ static int batadv_handle_request(struct batadv_priv *bat_priv, static int batadv_handle_unclaim(struct batadv_priv *bat_priv, struct batadv_hard_iface *primary_if, uint8_t *backbone_addr, - uint8_t *claim_addr, short vid) + uint8_t *claim_addr, unsigned short vid) { struct batadv_bla_backbone_gw *backbone_gw;
@@ -726,7 +726,7 @@ static int batadv_handle_unclaim(struct batadv_priv *bat_priv,
/* this must be an UNCLAIM frame */ batadv_dbg(BATADV_DBG_BLA, bat_priv, - "handle_unclaim(): UNCLAIM %pM on vid %d (sent by %pM)...\n", + "handle_unclaim(): UNCLAIM %pM on vid %hu (sent by %pM)...\n", claim_addr, vid, backbone_gw->orig);
batadv_bla_del_claim(bat_priv, claim_addr, vid); @@ -738,7 +738,7 @@ static int batadv_handle_unclaim(struct batadv_priv *bat_priv, static int batadv_handle_claim(struct batadv_priv *bat_priv, struct batadv_hard_iface *primary_if, uint8_t *backbone_addr, uint8_t *claim_addr, - short vid) + unsigned short vid) { struct batadv_bla_backbone_gw *backbone_gw;
@@ -861,7 +861,7 @@ static int batadv_bla_process_claim(struct batadv_priv *bat_priv, struct batadv_bla_claim_dst *bla_dst; uint16_t proto; int headlen; - short vid = -1; + unsigned short vid = BATADV_NO_FLAGS; int ret;
ethhdr = eth_hdr(skb); @@ -869,6 +869,7 @@ static int batadv_bla_process_claim(struct batadv_priv *bat_priv, if (ntohs(ethhdr->h_proto) == ETH_P_8021Q) { vhdr = (struct vlan_ethhdr *)ethhdr; vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK; + vid |= BATADV_VLAN_HAS_TAG; proto = ntohs(vhdr->h_vlan_encapsulated_proto); headlen = sizeof(*vhdr); } else { @@ -909,7 +910,7 @@ static int batadv_bla_process_claim(struct batadv_priv *bat_priv, ethhdr); if (ret == 1) batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_process_claim(): received a claim frame from another group. From: %pM on vid %d ...(hw_src %pM, hw_dst %pM)\n", + "bla_process_claim(): received a claim frame from another group. From: %pM on vid %hu ...(hw_src %pM, hw_dst %pM)\n", ethhdr->h_source, vid, hw_src, hw_dst);
if (ret < 2) @@ -944,7 +945,7 @@ static int batadv_bla_process_claim(struct batadv_priv *bat_priv, }
batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_process_claim(): ERROR - this looks like a claim frame, but is useless. eth src %pM on vid %d ...(hw_src %pM, hw_dst %pM)\n", + "bla_process_claim(): ERROR - this looks like a claim frame, but is useless. eth src %pM on vid %hu ...(hw_src %pM, hw_dst %pM)\n", ethhdr->h_source, vid, hw_src, hw_dst); return 1; } @@ -1033,7 +1034,7 @@ static void batadv_bla_purge_claims(struct batadv_priv *bat_priv, continue;
batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_purge_claims(): %pM, vid %d, time out\n", + "bla_purge_claims(): %pM, vid %hu, time out\n", claim->addr, claim->vid);
purge_now: @@ -1358,7 +1359,7 @@ int batadv_bla_is_backbone_gw(struct sk_buff *skb, struct ethhdr *ethhdr; struct vlan_ethhdr *vhdr; struct batadv_bla_backbone_gw *backbone_gw; - short vid = -1; + unsigned short vid = BATADV_NO_FLAGS;
if (!atomic_read(&orig_node->bat_priv->bridge_loop_avoidance)) return 0; @@ -1375,6 +1376,7 @@ int batadv_bla_is_backbone_gw(struct sk_buff *skb,
vhdr = (struct vlan_ethhdr *)(skb->data + hdr_size); vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK; + vid |= BATADV_VLAN_HAS_TAG; }
/* see if this originator is a backbone gw for this VLAN */ @@ -1424,8 +1426,8 @@ void batadv_bla_free(struct batadv_priv *bat_priv) * returns 1, otherwise it returns 0 and the caller shall further * process the skb. */ -int batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb, short vid, - bool is_bcast) +int batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb, + unsigned short vid, bool is_bcast) { struct ethhdr *ethhdr; struct batadv_bla_claim search_claim, *claim = NULL; @@ -1519,7 +1521,8 @@ out: * returns 1, otherwise it returns 0 and the caller shall further * process the skb. */ -int batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb, short vid) +int batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb, + unsigned short vid) { struct ethhdr *ethhdr; struct batadv_bla_claim search_claim, *claim = NULL; @@ -1623,9 +1626,11 @@ int batadv_bla_claim_table_seq_print_text(struct seq_file *seq, void *offset) hlist_for_each_entry_rcu(claim, head, hash_entry) { is_own = batadv_compare_eth(claim->backbone_gw->orig, primary_addr); - seq_printf(seq, " * %pM on % 5d by %pM [%c] (%#.4x)\n", - claim->addr, claim->vid, - claim->backbone_gw->orig, + seq_printf(seq, + " * %pM on %5u (tag: %3s) by %pM [%c] (%#.4x)\n", + claim->addr, claim->vid & BATADV_VID_MASK, + (claim->vid & BATADV_VLAN_HAS_TAG ? + "yes" : "no"), claim->backbone_gw->orig, (is_own ? 'x' : ' '), claim->backbone_gw->crc); } @@ -1677,9 +1682,12 @@ int batadv_bla_backbone_table_seq_print_text(struct seq_file *seq, void *offset) continue;
seq_printf(seq, - " * %pM on % 5d % 4i.%03is (%#.4x)\n", - backbone_gw->orig, backbone_gw->vid, - secs, msecs, backbone_gw->crc); + " * %pM on %5u (tag: %3s) % 4i.%03is (%#.4x)\n", + backbone_gw->orig, + backbone_gw->vid & BATADV_VID_MASK, + (backbone_gw->vid & BATADV_VLAN_HAS_TAG ? + "yes" : "no"), secs, msecs, + backbone_gw->crc); } rcu_read_unlock(); } diff --git a/bridge_loop_avoidance.h b/bridge_loop_avoidance.h index dea2fbc..4b102e7 100644 --- a/bridge_loop_avoidance.h +++ b/bridge_loop_avoidance.h @@ -21,9 +21,10 @@ #define _NET_BATMAN_ADV_BLA_H_
#ifdef CONFIG_BATMAN_ADV_BLA -int batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb, short vid, - bool is_bcast); -int batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb, short vid); +int batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb, + unsigned short vid, bool is_bcast); +int batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb, + unsigned short vid); int batadv_bla_is_backbone_gw(struct sk_buff *skb, struct batadv_orig_node *orig_node, int hdr_size); int batadv_bla_claim_table_seq_print_text(struct seq_file *seq, void *offset); @@ -42,13 +43,14 @@ void batadv_bla_free(struct batadv_priv *bat_priv); #else /* ifdef CONFIG_BATMAN_ADV_BLA */
static inline int batadv_bla_rx(struct batadv_priv *bat_priv, - struct sk_buff *skb, short vid, bool is_bcast) + struct sk_buff *skb, unsigned short vid, + bool is_bcast) { return 0; }
static inline int batadv_bla_tx(struct batadv_priv *bat_priv, - struct sk_buff *skb, short vid) + struct sk_buff *skb, unsigned short vid) { return 0; } diff --git a/main.h b/main.h index 24063e7..7fce4f0 100644 --- a/main.h +++ b/main.h @@ -164,6 +164,17 @@ enum batadv_uev_type {
#include "types.h"
+/** + * batadv_vlan_flags - flags for the four MSB of any vlan ID field + * @BATADV_VLAN_HAS_TAG: whether the field contains a valid vlan tag or not + */ +enum batadv_vlan_flags { + BATADV_VLAN_HAS_TAG = BIT(15), +}; + +/* mask needed to extract the vlan ID (12bits) from a 16bits variable */ +#define BATADV_VID_MASK 0x0FFF + extern char batadv_routing_algo[]; extern struct list_head batadv_hardif_list;
diff --git a/soft-interface.c b/soft-interface.c index b26a6cd..700d0b4 100644 --- a/soft-interface.c +++ b/soft-interface.c @@ -154,7 +154,7 @@ static int batadv_interface_tx(struct sk_buff *skb, 0x00, 0x00}; unsigned int header_len = 0; int data_len = skb->len, ret; - short vid __maybe_unused = -1; + unsigned short vid __maybe_unused = BATADV_NO_FLAGS; bool do_bcast = false; uint32_t seqno; unsigned long brd_delay = 1; @@ -303,7 +303,7 @@ void batadv_interface_rx(struct net_device *soft_iface, struct ethhdr *ethhdr; struct vlan_ethhdr *vhdr; struct batadv_header *batadv_header = (struct batadv_header *)skb->data; - short vid __maybe_unused = -1; + unsigned short vid __maybe_unused = BATADV_NO_FLAGS; __be16 ethertype = __constant_htons(ETH_P_BATMAN); bool is_bcast;
diff --git a/types.h b/types.h index 5f542bd..b2c94e1 100644 --- a/types.h +++ b/types.h @@ -642,7 +642,7 @@ struct batadv_socket_packet { #ifdef CONFIG_BATMAN_ADV_BLA struct batadv_bla_backbone_gw { uint8_t orig[ETH_ALEN]; - short vid; + unsigned short vid; struct hlist_node hash_entry; struct batadv_priv *bat_priv; unsigned long lasttime; @@ -665,7 +665,7 @@ struct batadv_bla_backbone_gw { */ struct batadv_bla_claim { uint8_t addr[ETH_ALEN]; - short vid; + unsigned short vid; struct batadv_bla_backbone_gw *backbone_gw; unsigned long lasttime; struct hlist_node hash_entry;
From: Antonio Quartulli antonio@open-mesh.com
Since the MSB bits of any vid variable are now used for storing flags, print the vid properly by taking the flags away and printing -1 in case of VID representing no real VLAN.
Signed-off-by: Antonio Quartulli antonio@open-mesh.com --- bridge_loop_avoidance.c | 57 ++++++++++++++++++++++++++----------------------- main.h | 2 ++ 2 files changed, 32 insertions(+), 27 deletions(-)
diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c index 16f9239..24a62ac 100644 --- a/bridge_loop_avoidance.c +++ b/bridge_loop_avoidance.c @@ -307,7 +307,8 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac, */ memcpy(ethhdr->h_source, mac, ETH_ALEN); batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_send_claim(): CLAIM %pM on vid %hu\n", mac, vid); + "bla_send_claim(): CLAIM %pM on vid %hd\n", mac, + BATADV_PRINT_VID(vid)); break; case BATADV_CLAIM_TYPE_UNCLAIM: /* unclaim frame @@ -315,8 +316,8 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac, */ memcpy(hw_src, mac, ETH_ALEN); batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_send_claim(): UNCLAIM %pM on vid %hu\n", mac, - vid); + "bla_send_claim(): UNCLAIM %pM on vid %hd\n", mac, + BATADV_PRINT_VID(vid)); break; case BATADV_CLAIM_TYPE_ANNOUNCE: /* announcement frame @@ -324,8 +325,8 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac, */ memcpy(hw_src, mac, ETH_ALEN); batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_send_claim(): ANNOUNCE of %pM on vid %hu\n", - ethhdr->h_source, vid); + "bla_send_claim(): ANNOUNCE of %pM on vid %hd\n", + ethhdr->h_source, BATADV_PRINT_VID(vid)); break; case BATADV_CLAIM_TYPE_REQUEST: /* request frame @@ -335,8 +336,9 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac, memcpy(hw_src, mac, ETH_ALEN); memcpy(ethhdr->h_dest, mac, ETH_ALEN); batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_send_claim(): REQUEST of %pM to %pM on vid %hu\n", - ethhdr->h_source, ethhdr->h_dest, vid); + "bla_send_claim(): REQUEST of %pM to %pM on vid %hd\n", + ethhdr->h_source, ethhdr->h_dest, + BATADV_PRINT_VID(vid)); break; }
@@ -379,8 +381,8 @@ batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, uint8_t *orig, return entry;
batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_get_backbone_gw(): not found (%pM, %hu), creating new entry\n", - orig, vid); + "bla_get_backbone_gw(): not found (%pM, %hd), creating new entry\n", + orig, BATADV_PRINT_VID(vid));
entry = kzalloc(sizeof(*entry), GFP_ATOMIC); if (!entry) @@ -571,8 +573,8 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,
atomic_set(&claim->refcount, 2); batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_add_claim(): adding new entry %pM, vid %hu to hash ...\n", - mac, vid); + "bla_add_claim(): adding new entry %pM, vid %hd to hash ...\n", + mac, BATADV_PRINT_VID(vid)); hash_added = batadv_hash_add(bat_priv->bla.claim_hash, batadv_compare_claim, batadv_choose_claim, claim, @@ -590,8 +592,8 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv, goto claim_free_ref;
batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_add_claim(): changing ownership for %pM, vid %hu\n", - mac, vid); + "bla_add_claim(): changing ownership for %pM, vid %hd\n", + mac, BATADV_PRINT_VID(vid));
claim->backbone_gw->crc ^= crc16(0, claim->addr, ETH_ALEN); batadv_backbone_gw_free_ref(claim->backbone_gw); @@ -621,8 +623,8 @@ static void batadv_bla_del_claim(struct batadv_priv *bat_priv, if (!claim) return;
- batadv_dbg(BATADV_DBG_BLA, bat_priv, "bla_del_claim(): %pM, vid %hu\n", - mac, vid); + batadv_dbg(BATADV_DBG_BLA, bat_priv, "bla_del_claim(): %pM, vid %hd\n", + mac, BATADV_PRINT_VID(vid));
batadv_hash_remove(bat_priv->bla.claim_hash, batadv_compare_claim, batadv_choose_claim, claim); @@ -657,13 +659,13 @@ static int batadv_handle_announce(struct batadv_priv *bat_priv, crc = ntohs(*((__be16 *)(&an_addr[4])));
batadv_dbg(BATADV_DBG_BLA, bat_priv, - "handle_announce(): ANNOUNCE vid %hu (sent by %pM)... CRC = %#.4x\n", - vid, backbone_gw->orig, crc); + "handle_announce(): ANNOUNCE vid %hd (sent by %pM)... CRC = %#.4x\n", + BATADV_PRINT_VID(vid), backbone_gw->orig, crc);
if (backbone_gw->crc != crc) { batadv_dbg(BATADV_DBG_BLA, backbone_gw->bat_priv, - "handle_announce(): CRC FAILED for %pM/%hu (my = %#.4x, sent = %#.4x)\n", - backbone_gw->orig, backbone_gw->vid, + "handle_announce(): CRC FAILED for %pM/%hd (my = %#.4x, sent = %#.4x)\n", + backbone_gw->orig, BATADV_PRINT_VID(backbone_gw->vid), backbone_gw->crc, crc);
batadv_bla_send_request(backbone_gw); @@ -698,8 +700,8 @@ static int batadv_handle_request(struct batadv_priv *bat_priv, return 1;
batadv_dbg(BATADV_DBG_BLA, bat_priv, - "handle_request(): REQUEST vid %hu (sent by %pM)...\n", - vid, ethhdr->h_source); + "handle_request(): REQUEST vid %hd (sent by %pM)...\n", + BATADV_PRINT_VID(vid), ethhdr->h_source);
batadv_bla_answer_request(bat_priv, primary_if, vid); return 1; @@ -726,8 +728,8 @@ static int batadv_handle_unclaim(struct batadv_priv *bat_priv,
/* this must be an UNCLAIM frame */ batadv_dbg(BATADV_DBG_BLA, bat_priv, - "handle_unclaim(): UNCLAIM %pM on vid %hu (sent by %pM)...\n", - claim_addr, vid, backbone_gw->orig); + "handle_unclaim(): UNCLAIM %pM on vid %hd (sent by %pM)...\n", + claim_addr, BATADV_PRINT_VID(vid), backbone_gw->orig);
batadv_bla_del_claim(bat_priv, claim_addr, vid); batadv_backbone_gw_free_ref(backbone_gw); @@ -910,8 +912,9 @@ static int batadv_bla_process_claim(struct batadv_priv *bat_priv, ethhdr); if (ret == 1) batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_process_claim(): received a claim frame from another group. From: %pM on vid %hu ...(hw_src %pM, hw_dst %pM)\n", - ethhdr->h_source, vid, hw_src, hw_dst); + "bla_process_claim(): received a claim frame from another group. From: %pM on vid %hd ...(hw_src %pM, hw_dst %pM)\n", + ethhdr->h_source, BATADV_PRINT_VID(vid), hw_src, + hw_dst);
if (ret < 2) return ret; @@ -945,8 +948,8 @@ static int batadv_bla_process_claim(struct batadv_priv *bat_priv, }
batadv_dbg(BATADV_DBG_BLA, bat_priv, - "bla_process_claim(): ERROR - this looks like a claim frame, but is useless. eth src %pM on vid %hu ...(hw_src %pM, hw_dst %pM)\n", - ethhdr->h_source, vid, hw_src, hw_dst); + "bla_process_claim(): ERROR - this looks like a claim frame, but is useless. eth src %pM on vid %hd ...(hw_src %pM, hw_dst %pM)\n", + ethhdr->h_source, BATADV_PRINT_VID(vid), hw_src, hw_dst); return 1; }
diff --git a/main.h b/main.h index 7fce4f0..815fb69 100644 --- a/main.h +++ b/main.h @@ -174,6 +174,8 @@ enum batadv_vlan_flags {
/* mask needed to extract the vlan ID (12bits) from a 16bits variable */ #define BATADV_VID_MASK 0x0FFF +#define BATADV_PRINT_VID(vid) ((short)(vid & BATADV_VLAN_HAS_TAG ? \ + vid & BATADV_VID_MASK : -1))
extern char batadv_routing_algo[]; extern struct list_head batadv_hardif_list;
On Thu, Apr 18, 2013 at 03:43:47PM +0200, Antonio Quartulli wrote:
From: Antonio Quartulli antonio@open-mesh.com
Since the MSB bits of any vid variable are now used for storing flags, print the vid properly by taking the flags away and printing -1 in case of VID representing no real VLAN.
Signed-off-by: Antonio Quartulli antonio@open-mesh.com
bridge_loop_avoidance.c | 57 ++++++++++++++++++++++++++----------------------- main.h | 2 ++ 2 files changed, 32 insertions(+), 27 deletions(-)
diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c index 16f9239..24a62ac 100644 --- a/bridge_loop_avoidance.c +++ b/bridge_loop_avoidance.c @@ -307,7 +307,8 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac, */ memcpy(ethhdr->h_source, mac, ETH_ALEN); batadv_dbg(BATADV_DBG_BLA, bat_priv,
"bla_send_claim(): CLAIM %pM on vid %hu\n", mac, vid);
"bla_send_claim(): CLAIM %pM on vid %hd\n", mac,
BATADV_PRINT_VID(vid));
You've changed all these strings from %d into %hu and now back to %hd? Why not just leave everything at %d and reduce the bloat of these patches? It should not hurt anyone - yes, printing -1 is not pretty but this is developer debug info anyway. And keeping %d instead of %hd should not be a problem as far as I understand.
Apart from that, using the BATADV_PRINT_VID macro is a good idea IMHO.
Cheers, Simon
On Fri, Apr 19, 2013 at 03:12:47PM +0200, Simon Wunderlich wrote:
On Thu, Apr 18, 2013 at 03:43:47PM +0200, Antonio Quartulli wrote:
From: Antonio Quartulli antonio@open-mesh.com
Since the MSB bits of any vid variable are now used for storing flags, print the vid properly by taking the flags away and printing -1 in case of VID representing no real VLAN.
Signed-off-by: Antonio Quartulli antonio@open-mesh.com
bridge_loop_avoidance.c | 57 ++++++++++++++++++++++++++----------------------- main.h | 2 ++ 2 files changed, 32 insertions(+), 27 deletions(-)
diff --git a/bridge_loop_avoidance.c b/bridge_loop_avoidance.c index 16f9239..24a62ac 100644 --- a/bridge_loop_avoidance.c +++ b/bridge_loop_avoidance.c @@ -307,7 +307,8 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac, */ memcpy(ethhdr->h_source, mac, ETH_ALEN); batadv_dbg(BATADV_DBG_BLA, bat_priv,
"bla_send_claim(): CLAIM %pM on vid %hu\n", mac, vid);
"bla_send_claim(): CLAIM %pM on vid %hd\n", mac,
BATADV_PRINT_VID(vid));
You've changed all these strings from %d into %hu and now back to %hd? Why not just leave everything at %d and reduce the bloat of these patches? It should not hurt anyone - yes, printing -1 is not pretty but this is developer debug info anyway. And keeping %d instead of %hd should not be a problem as far as I understand.
Apart from that, using the BATADV_PRINT_VID macro is a good idea IMHO.
Ok, I'll remove all the format changes and keep the %d :)
Cheers,
b.a.t.m.a.n@lists.open-mesh.org