Commit eb2deb6b authored by Antonio Quartulli's avatar Antonio Quartulli Committed by Antonio Quartulli

batman-adv: change VID semantic in the BLA code

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
Signed-off-by: default avatarAntonio Quartulli <antonio@open-mesh.com>
Signed-off-by: default avatarMarek Lindner <lindner_marek@yahoo.de>
Acked-by: default avatarSimon Wunderlich <siwu@hrz.tu-chemnitz.de>
parent aa27c312
...@@ -180,7 +180,7 @@ static struct batadv_bla_claim ...@@ -180,7 +180,7 @@ static struct batadv_bla_claim
*/ */
static struct batadv_bla_backbone_gw * static struct batadv_bla_backbone_gw *
batadv_backbone_hash_find(struct batadv_priv *bat_priv, 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 batadv_hashtable *hash = bat_priv->bla.backbone_hash;
struct hlist_head *head; struct hlist_head *head;
...@@ -257,7 +257,7 @@ batadv_bla_del_backbone_claims(struct batadv_bla_backbone_gw *backbone_gw) ...@@ -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, ...) * @claimtype: the type of the claim (CLAIM, UNCLAIM, ANNOUNCE, ...)
*/ */
static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac, 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 sk_buff *skb;
struct ethhdr *ethhdr; struct ethhdr *ethhdr;
...@@ -335,13 +335,14 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac, ...@@ -335,13 +335,14 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac,
memcpy(hw_src, mac, ETH_ALEN); memcpy(hw_src, mac, ETH_ALEN);
memcpy(ethhdr->h_dest, mac, ETH_ALEN); memcpy(ethhdr->h_dest, mac, ETH_ALEN);
batadv_dbg(BATADV_DBG_BLA, bat_priv, 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 %d\n",
ethhdr->h_source, ethhdr->h_dest, vid); ethhdr->h_source, ethhdr->h_dest, vid);
break; break;
} }
if (vid != -1) if (vid & BATADV_VLAN_HAS_TAG)
skb = vlan_insert_tag(skb, htons(ETH_P_8021Q), vid); skb = vlan_insert_tag(skb, htons(ETH_P_8021Q),
vid & VLAN_VID_MASK);
skb_reset_mac_header(skb); skb_reset_mac_header(skb);
skb->protocol = eth_type_trans(skb, soft_iface); skb->protocol = eth_type_trans(skb, soft_iface);
...@@ -367,7 +368,7 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac, ...@@ -367,7 +368,7 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac,
*/ */
static struct batadv_bla_backbone_gw * static struct batadv_bla_backbone_gw *
batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, uint8_t *orig, 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_bla_backbone_gw *entry;
struct batadv_orig_node *orig_node; struct batadv_orig_node *orig_node;
...@@ -434,7 +435,7 @@ batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, uint8_t *orig, ...@@ -434,7 +435,7 @@ batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, uint8_t *orig,
static void static void
batadv_bla_update_own_backbone_gw(struct batadv_priv *bat_priv, batadv_bla_update_own_backbone_gw(struct batadv_priv *bat_priv,
struct batadv_hard_iface *primary_if, struct batadv_hard_iface *primary_if,
short vid) unsigned short vid)
{ {
struct batadv_bla_backbone_gw *backbone_gw; struct batadv_bla_backbone_gw *backbone_gw;
...@@ -456,7 +457,7 @@ batadv_bla_update_own_backbone_gw(struct batadv_priv *bat_priv, ...@@ -456,7 +457,7 @@ batadv_bla_update_own_backbone_gw(struct batadv_priv *bat_priv,
*/ */
static void batadv_bla_answer_request(struct batadv_priv *bat_priv, static void batadv_bla_answer_request(struct batadv_priv *bat_priv,
struct batadv_hard_iface *primary_if, struct batadv_hard_iface *primary_if,
short vid) unsigned short vid)
{ {
struct hlist_head *head; struct hlist_head *head;
struct batadv_hashtable *hash; struct batadv_hashtable *hash;
...@@ -547,7 +548,7 @@ static void batadv_bla_send_announce(struct batadv_priv *bat_priv, ...@@ -547,7 +548,7 @@ static void batadv_bla_send_announce(struct batadv_priv *bat_priv,
* @backbone_gw: the backbone gateway which claims it * @backbone_gw: the backbone gateway which claims it
*/ */
static void batadv_bla_add_claim(struct batadv_priv *bat_priv, 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_backbone_gw *backbone_gw)
{ {
struct batadv_bla_claim *claim; struct batadv_bla_claim *claim;
...@@ -611,7 +612,7 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv, ...@@ -611,7 +612,7 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,
* given mac address and vid. * given mac address and vid.
*/ */
static void batadv_bla_del_claim(struct batadv_priv *bat_priv, 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; struct batadv_bla_claim search_claim, *claim;
...@@ -637,7 +638,7 @@ static void batadv_bla_del_claim(struct batadv_priv *bat_priv, ...@@ -637,7 +638,7 @@ static void batadv_bla_del_claim(struct batadv_priv *bat_priv,
/* check for ANNOUNCE frame, return 1 if handled */ /* check for ANNOUNCE frame, return 1 if handled */
static int batadv_handle_announce(struct batadv_priv *bat_priv, static int batadv_handle_announce(struct batadv_priv *bat_priv,
uint8_t *an_addr, uint8_t *backbone_addr, uint8_t *an_addr, uint8_t *backbone_addr,
short vid) unsigned short vid)
{ {
struct batadv_bla_backbone_gw *backbone_gw; struct batadv_bla_backbone_gw *backbone_gw;
uint16_t crc; uint16_t crc;
...@@ -685,7 +686,7 @@ static int batadv_handle_announce(struct batadv_priv *bat_priv, ...@@ -685,7 +686,7 @@ static int batadv_handle_announce(struct batadv_priv *bat_priv,
static int batadv_handle_request(struct batadv_priv *bat_priv, static int batadv_handle_request(struct batadv_priv *bat_priv,
struct batadv_hard_iface *primary_if, struct batadv_hard_iface *primary_if,
uint8_t *backbone_addr, uint8_t *backbone_addr,
struct ethhdr *ethhdr, short vid) struct ethhdr *ethhdr, unsigned short vid)
{ {
/* check for REQUEST frame */ /* check for REQUEST frame */
if (!batadv_compare_eth(backbone_addr, ethhdr->h_dest)) if (!batadv_compare_eth(backbone_addr, ethhdr->h_dest))
...@@ -709,7 +710,7 @@ static int batadv_handle_request(struct batadv_priv *bat_priv, ...@@ -709,7 +710,7 @@ static int batadv_handle_request(struct batadv_priv *bat_priv,
static int batadv_handle_unclaim(struct batadv_priv *bat_priv, static int batadv_handle_unclaim(struct batadv_priv *bat_priv,
struct batadv_hard_iface *primary_if, struct batadv_hard_iface *primary_if,
uint8_t *backbone_addr, uint8_t *backbone_addr,
uint8_t *claim_addr, short vid) uint8_t *claim_addr, unsigned short vid)
{ {
struct batadv_bla_backbone_gw *backbone_gw; struct batadv_bla_backbone_gw *backbone_gw;
...@@ -738,7 +739,7 @@ static int batadv_handle_unclaim(struct batadv_priv *bat_priv, ...@@ -738,7 +739,7 @@ static int batadv_handle_unclaim(struct batadv_priv *bat_priv,
static int batadv_handle_claim(struct batadv_priv *bat_priv, static int batadv_handle_claim(struct batadv_priv *bat_priv,
struct batadv_hard_iface *primary_if, struct batadv_hard_iface *primary_if,
uint8_t *backbone_addr, uint8_t *claim_addr, uint8_t *backbone_addr, uint8_t *claim_addr,
short vid) unsigned short vid)
{ {
struct batadv_bla_backbone_gw *backbone_gw; struct batadv_bla_backbone_gw *backbone_gw;
...@@ -861,7 +862,7 @@ static int batadv_bla_process_claim(struct batadv_priv *bat_priv, ...@@ -861,7 +862,7 @@ static int batadv_bla_process_claim(struct batadv_priv *bat_priv,
struct batadv_bla_claim_dst *bla_dst; struct batadv_bla_claim_dst *bla_dst;
uint16_t proto; uint16_t proto;
int headlen; int headlen;
short vid = -1; unsigned short vid = BATADV_NO_FLAGS;
int ret; int ret;
ethhdr = eth_hdr(skb); ethhdr = eth_hdr(skb);
...@@ -869,6 +870,7 @@ static int batadv_bla_process_claim(struct batadv_priv *bat_priv, ...@@ -869,6 +870,7 @@ static int batadv_bla_process_claim(struct batadv_priv *bat_priv,
if (ntohs(ethhdr->h_proto) == ETH_P_8021Q) { if (ntohs(ethhdr->h_proto) == ETH_P_8021Q) {
vhdr = (struct vlan_ethhdr *)ethhdr; vhdr = (struct vlan_ethhdr *)ethhdr;
vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK; vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
vid |= BATADV_VLAN_HAS_TAG;
proto = ntohs(vhdr->h_vlan_encapsulated_proto); proto = ntohs(vhdr->h_vlan_encapsulated_proto);
headlen = sizeof(*vhdr); headlen = sizeof(*vhdr);
} else { } else {
...@@ -1358,7 +1360,7 @@ int batadv_bla_is_backbone_gw(struct sk_buff *skb, ...@@ -1358,7 +1360,7 @@ int batadv_bla_is_backbone_gw(struct sk_buff *skb,
struct ethhdr *ethhdr; struct ethhdr *ethhdr;
struct vlan_ethhdr *vhdr; struct vlan_ethhdr *vhdr;
struct batadv_bla_backbone_gw *backbone_gw; 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)) if (!atomic_read(&orig_node->bat_priv->bridge_loop_avoidance))
return 0; return 0;
...@@ -1375,6 +1377,7 @@ int batadv_bla_is_backbone_gw(struct sk_buff *skb, ...@@ -1375,6 +1377,7 @@ int batadv_bla_is_backbone_gw(struct sk_buff *skb,
vhdr = (struct vlan_ethhdr *)(skb->data + hdr_size); vhdr = (struct vlan_ethhdr *)(skb->data + hdr_size);
vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK; 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 */ /* see if this originator is a backbone gw for this VLAN */
...@@ -1424,8 +1427,8 @@ void batadv_bla_free(struct batadv_priv *bat_priv) ...@@ -1424,8 +1427,8 @@ void batadv_bla_free(struct batadv_priv *bat_priv)
* returns 1, otherwise it returns 0 and the caller shall further * returns 1, otherwise it returns 0 and the caller shall further
* process the skb. * process the skb.
*/ */
int batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb, short vid, int batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb,
bool is_bcast) unsigned short vid, bool is_bcast)
{ {
struct ethhdr *ethhdr; struct ethhdr *ethhdr;
struct batadv_bla_claim search_claim, *claim = NULL; struct batadv_bla_claim search_claim, *claim = NULL;
...@@ -1519,7 +1522,8 @@ int batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb, short vid, ...@@ -1519,7 +1522,8 @@ int batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb, short vid,
* returns 1, otherwise it returns 0 and the caller shall further * returns 1, otherwise it returns 0 and the caller shall further
* process the skb. * 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 ethhdr *ethhdr;
struct batadv_bla_claim search_claim, *claim = NULL; struct batadv_bla_claim search_claim, *claim = NULL;
...@@ -1623,7 +1627,7 @@ int batadv_bla_claim_table_seq_print_text(struct seq_file *seq, void *offset) ...@@ -1623,7 +1627,7 @@ int batadv_bla_claim_table_seq_print_text(struct seq_file *seq, void *offset)
hlist_for_each_entry_rcu(claim, head, hash_entry) { hlist_for_each_entry_rcu(claim, head, hash_entry) {
is_own = batadv_compare_eth(claim->backbone_gw->orig, is_own = batadv_compare_eth(claim->backbone_gw->orig,
primary_addr); primary_addr);
seq_printf(seq, " * %pM on % 5d by %pM [%c] (%#.4x)\n", seq_printf(seq, " * %pM on %5d by %pM [%c] (%#.4x)\n",
claim->addr, claim->vid, claim->addr, claim->vid,
claim->backbone_gw->orig, claim->backbone_gw->orig,
(is_own ? 'x' : ' '), (is_own ? 'x' : ' '),
...@@ -1676,10 +1680,9 @@ int batadv_bla_backbone_table_seq_print_text(struct seq_file *seq, void *offset) ...@@ -1676,10 +1680,9 @@ int batadv_bla_backbone_table_seq_print_text(struct seq_file *seq, void *offset)
if (is_own) if (is_own)
continue; continue;
seq_printf(seq, seq_printf(seq, " * %pM on %5d %4i.%03is (%#.4x)\n",
" * %pM on % 5d % 4i.%03is (%#.4x)\n", backbone_gw->orig, backbone_gw->vid, secs,
backbone_gw->orig, backbone_gw->vid, msecs, backbone_gw->crc);
secs, msecs, backbone_gw->crc);
} }
rcu_read_unlock(); rcu_read_unlock();
} }
......
...@@ -21,9 +21,10 @@ ...@@ -21,9 +21,10 @@
#define _NET_BATMAN_ADV_BLA_H_ #define _NET_BATMAN_ADV_BLA_H_
#ifdef CONFIG_BATMAN_ADV_BLA #ifdef CONFIG_BATMAN_ADV_BLA
int batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb, short vid, int batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb,
bool is_bcast); unsigned short vid, bool is_bcast);
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);
int batadv_bla_is_backbone_gw(struct sk_buff *skb, int batadv_bla_is_backbone_gw(struct sk_buff *skb,
struct batadv_orig_node *orig_node, int hdr_size); struct batadv_orig_node *orig_node, int hdr_size);
int batadv_bla_claim_table_seq_print_text(struct seq_file *seq, void *offset); 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); ...@@ -42,13 +43,14 @@ void batadv_bla_free(struct batadv_priv *bat_priv);
#else /* ifdef CONFIG_BATMAN_ADV_BLA */ #else /* ifdef CONFIG_BATMAN_ADV_BLA */
static inline int batadv_bla_rx(struct batadv_priv *bat_priv, 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; return 0;
} }
static inline int batadv_bla_tx(struct batadv_priv *bat_priv, 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; return 0;
} }
......
...@@ -162,6 +162,17 @@ enum batadv_uev_type { ...@@ -162,6 +162,17 @@ enum batadv_uev_type {
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include "types.h" #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),
};
#define BATADV_PRINT_VID(vid) (vid & BATADV_VLAN_HAS_TAG ? \
(int)(vid & VLAN_VID_MASK) : -1)
extern char batadv_routing_algo[]; extern char batadv_routing_algo[];
extern struct list_head batadv_hardif_list; extern struct list_head batadv_hardif_list;
......
...@@ -154,7 +154,7 @@ static int batadv_interface_tx(struct sk_buff *skb, ...@@ -154,7 +154,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
0x00, 0x00}; 0x00, 0x00};
unsigned int header_len = 0; unsigned int header_len = 0;
int data_len = skb->len, ret; int data_len = skb->len, ret;
short vid __maybe_unused = -1; unsigned short vid __maybe_unused = BATADV_NO_FLAGS;
bool do_bcast = false; bool do_bcast = false;
uint32_t seqno; uint32_t seqno;
unsigned long brd_delay = 1; unsigned long brd_delay = 1;
...@@ -303,7 +303,7 @@ void batadv_interface_rx(struct net_device *soft_iface, ...@@ -303,7 +303,7 @@ void batadv_interface_rx(struct net_device *soft_iface,
struct ethhdr *ethhdr; struct ethhdr *ethhdr;
struct vlan_ethhdr *vhdr; struct vlan_ethhdr *vhdr;
struct batadv_header *batadv_header = (struct batadv_header *)skb->data; 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); __be16 ethertype = __constant_htons(ETH_P_BATMAN);
bool is_bcast; bool is_bcast;
......
...@@ -642,7 +642,7 @@ struct batadv_socket_packet { ...@@ -642,7 +642,7 @@ struct batadv_socket_packet {
#ifdef CONFIG_BATMAN_ADV_BLA #ifdef CONFIG_BATMAN_ADV_BLA
struct batadv_bla_backbone_gw { struct batadv_bla_backbone_gw {
uint8_t orig[ETH_ALEN]; uint8_t orig[ETH_ALEN];
short vid; unsigned short vid;
struct hlist_node hash_entry; struct hlist_node hash_entry;
struct batadv_priv *bat_priv; struct batadv_priv *bat_priv;
unsigned long lasttime; unsigned long lasttime;
...@@ -665,7 +665,7 @@ struct batadv_bla_backbone_gw { ...@@ -665,7 +665,7 @@ struct batadv_bla_backbone_gw {
*/ */
struct batadv_bla_claim { struct batadv_bla_claim {
uint8_t addr[ETH_ALEN]; uint8_t addr[ETH_ALEN];
short vid; unsigned short vid;
struct batadv_bla_backbone_gw *backbone_gw; struct batadv_bla_backbone_gw *backbone_gw;
unsigned long lasttime; unsigned long lasttime;
struct hlist_node hash_entry; struct hlist_node hash_entry;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment