From: Antonio Quartulli antonio@open-mesh.com
Some components inside batman-adv are still not fully vlan aware. In order to change them and improve their vlan support, the semantic used for variables storing the VID values has to be modified and 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
Signed-off-by: Antonio Quartulli antonio@open-mesh.com ---
v2: - change commit message to clearly state that this is an improvement: batman-adv already works with vlans - move the HAS_VID_TAG declaration in main.h since it is not sent over the wire
Cheers,
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 6a4f728..7b131f8 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 %u\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 %u\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 %u\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 %u\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, %u), 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 %u 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 %u\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 %u\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,7 +657,7 @@ 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 %u (sent by %pM)... CRC = %#.4x\n", vid, backbone_gw->orig, crc);
if (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 %u (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 %u (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 = (struct ethhdr *)skb_mac_header(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,8 +910,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 %d ...(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 %u ...(hw_src %pM, hw_dst %pM)\n", + ethhdr->h_source, vid, hw_src, + hw_dst);
if (ret < 2) return ret; @@ -944,7 +946,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 %u ...(hw_src %pM, hw_dst %pM)\n", ethhdr->h_source, vid, hw_src, hw_dst); return 1; } @@ -1033,7 +1035,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 %u, time out\n", claim->addr, claim->vid);
purge_now: @@ -1358,7 +1360,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 +1377,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 +1427,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 +1522,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 +1627,10 @@ 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 fd6d7d3..6792866 100644 --- a/main.h +++ b/main.h @@ -136,6 +136,17 @@ enum batadv_uev_type { #define BATADV_DAT_CANDIDATE_NOT_FOUND 0 #define BATADV_DAT_CANDIDATE_ORIG 1
+/* mask needed to extract the vlan ID (12bits) from a 16bits variable */ +#define BATADV_VID_MASK 0x0FFF + +/** + * 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), +}; + /* Debug Messages */ #ifdef pr_fmt #undef pr_fmt diff --git a/soft-interface.c b/soft-interface.c index 403b8c4..34597a2 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 0c77d67..296472e 100644 --- a/types.h +++ b/types.h @@ -670,7 +670,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; @@ -693,7 +693,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;
Acked-by: Simon Wunderlich siwu@hrz.tu-chemnitz.de
Just a small thing which can be adjusted when merging:
On Mon, Apr 08, 2013 at 11:17:16AM +0200, Antonio Quartulli wrote:
@@ -909,8 +910,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 %d ...(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 %u ...(hw_src %pM, hw_dst %pM)\n",
ethhdr->h_source, vid, hw_src,
hw_dst);
This could be put on one line.
Cheers, Simon
On Monday, April 08, 2013 17:17:16 Antonio Quartulli wrote:
@@ -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 %u\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 %u\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 %u\n",
It should be %hu instead of %u for unsigned short.
Please make sure the printed vid does not contain the BATADV_VLAN_HAS_TAG mixed with the real vid.
Cheers, Marek
b.a.t.m.a.n@lists.open-mesh.org