Commit b45bd46d authored by David S. Miller's avatar David S. Miller

Merge tag 'batman-adv-for-davem' of git://git.open-mesh.org/linux-merge

Antonio Quartulli says:

====================
this is another set of changes intended for net-next/linux-3.13.
(probably our last pull request for this cycle)

Patches 1 and 2 reshape two of our main data structures in a way that they can
easily be extended in the future to accommodate new routing protocols.

Patches from 3 to 9 improve our routing protocol API and its users so that all
the protocol-related code is not mixed up with the other components anymore.

Patch 10 limits the local Translation Table maximum size to a value such that it
can be fully transfered over the air if needed. This value depends on
fragmentation being enabled or not and on the mtu values.

Patch 11 makes batman-adv send a uevent in case of soft-interface destruction
while a "bat-Gateway" was configured (this informs userspace about the GW not
being available anymore).

Patches 13 and 14 enable the TT component to detect non-mesh client flag
changes at runtime (till now those flags where set upon client detection and
were not changed anymore).

Patch 16 is a generalisation of our user-to-kernel space communication (and
viceversa) used to exchange ICMP packets to send/received to/from the mesh
network. Now it can easily accommodate new ICMP packet types without breaking
the existing userspace API anymore.

Remaining patches are minor changes and cleanups.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 0cad43a7 da6b8c20
This diff is collapsed.
...@@ -137,7 +137,7 @@ batadv_gw_get_best_gw_node(struct batadv_priv *bat_priv) ...@@ -137,7 +137,7 @@ batadv_gw_get_best_gw_node(struct batadv_priv *bat_priv)
if (!atomic_inc_not_zero(&gw_node->refcount)) if (!atomic_inc_not_zero(&gw_node->refcount))
goto next; goto next;
tq_avg = router->tq_avg; tq_avg = router->bat_iv.tq_avg;
switch (atomic_read(&bat_priv->gw_sel_class)) { switch (atomic_read(&bat_priv->gw_sel_class)) {
case 1: /* fast connection */ case 1: /* fast connection */
...@@ -256,7 +256,7 @@ void batadv_gw_election(struct batadv_priv *bat_priv) ...@@ -256,7 +256,7 @@ void batadv_gw_election(struct batadv_priv *bat_priv)
next_gw->bandwidth_down / 10, next_gw->bandwidth_down / 10,
next_gw->bandwidth_down % 10, next_gw->bandwidth_down % 10,
next_gw->bandwidth_up / 10, next_gw->bandwidth_up / 10,
next_gw->bandwidth_up % 10, router->tq_avg); next_gw->bandwidth_up % 10, router->bat_iv.tq_avg);
batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_ADD, batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_ADD,
gw_addr); gw_addr);
} else { } else {
...@@ -266,7 +266,7 @@ void batadv_gw_election(struct batadv_priv *bat_priv) ...@@ -266,7 +266,7 @@ void batadv_gw_election(struct batadv_priv *bat_priv)
next_gw->bandwidth_down / 10, next_gw->bandwidth_down / 10,
next_gw->bandwidth_down % 10, next_gw->bandwidth_down % 10,
next_gw->bandwidth_up / 10, next_gw->bandwidth_up / 10,
next_gw->bandwidth_up % 10, router->tq_avg); next_gw->bandwidth_up % 10, router->bat_iv.tq_avg);
batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_CHANGE, batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_CHANGE,
gw_addr); gw_addr);
} }
...@@ -305,8 +305,8 @@ void batadv_gw_check_election(struct batadv_priv *bat_priv, ...@@ -305,8 +305,8 @@ void batadv_gw_check_election(struct batadv_priv *bat_priv,
if (!router_orig) if (!router_orig)
goto out; goto out;
gw_tq_avg = router_gw->tq_avg; gw_tq_avg = router_gw->bat_iv.tq_avg;
orig_tq_avg = router_orig->tq_avg; orig_tq_avg = router_orig->bat_iv.tq_avg;
/* the TQ value has to be better */ /* the TQ value has to be better */
if (orig_tq_avg < gw_tq_avg) if (orig_tq_avg < gw_tq_avg)
...@@ -528,7 +528,7 @@ static int batadv_write_buffer_text(struct batadv_priv *bat_priv, ...@@ -528,7 +528,7 @@ static int batadv_write_buffer_text(struct batadv_priv *bat_priv,
ret = seq_printf(seq, "%s %pM (%3i) %pM [%10s]: %u.%u/%u.%u MBit\n", ret = seq_printf(seq, "%s %pM (%3i) %pM [%10s]: %u.%u/%u.%u MBit\n",
(curr_gw == gw_node ? "=>" : " "), (curr_gw == gw_node ? "=>" : " "),
gw_node->orig_node->orig, gw_node->orig_node->orig,
router->tq_avg, router->addr, router->bat_iv.tq_avg, router->addr,
router->if_incoming->net_dev->name, router->if_incoming->net_dev->name,
gw_node->bandwidth_down / 10, gw_node->bandwidth_down / 10,
gw_node->bandwidth_down % 10, gw_node->bandwidth_down % 10,
...@@ -792,7 +792,7 @@ bool batadv_gw_out_of_range(struct batadv_priv *bat_priv, ...@@ -792,7 +792,7 @@ bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,
if (!neigh_curr) if (!neigh_curr)
goto out; goto out;
curr_tq_avg = neigh_curr->tq_avg; curr_tq_avg = neigh_curr->bat_iv.tq_avg;
break; break;
case BATADV_GW_MODE_OFF: case BATADV_GW_MODE_OFF:
default: default:
...@@ -803,7 +803,7 @@ bool batadv_gw_out_of_range(struct batadv_priv *bat_priv, ...@@ -803,7 +803,7 @@ bool batadv_gw_out_of_range(struct batadv_priv *bat_priv,
if (!neigh_old) if (!neigh_old)
goto out; goto out;
if (curr_tq_avg - neigh_old->tq_avg > BATADV_GW_THRESHOLD) if (curr_tq_avg - neigh_old->bat_iv.tq_avg > BATADV_GW_THRESHOLD)
out_of_range = true; out_of_range = true;
out: out:
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "originator.h" #include "originator.h"
#include "hash.h" #include "hash.h"
#include "bridge_loop_avoidance.h" #include "bridge_loop_avoidance.h"
#include "gateway_client.h"
#include <linux/if_arp.h> #include <linux/if_arp.h>
#include <linux/if_ether.h> #include <linux/if_ether.h>
...@@ -124,8 +125,11 @@ static int batadv_is_valid_iface(const struct net_device *net_dev) ...@@ -124,8 +125,11 @@ static int batadv_is_valid_iface(const struct net_device *net_dev)
* *
* Returns true if the net device is a 802.11 wireless device, false otherwise. * Returns true if the net device is a 802.11 wireless device, false otherwise.
*/ */
static bool batadv_is_wifi_netdev(struct net_device *net_device) bool batadv_is_wifi_netdev(struct net_device *net_device)
{ {
if (!net_device)
return false;
#ifdef CONFIG_WIRELESS_EXT #ifdef CONFIG_WIRELESS_EXT
/* pre-cfg80211 drivers have to implement WEXT, so it is possible to /* pre-cfg80211 drivers have to implement WEXT, so it is possible to
* check for wireless_handlers != NULL * check for wireless_handlers != NULL
...@@ -141,34 +145,6 @@ static bool batadv_is_wifi_netdev(struct net_device *net_device) ...@@ -141,34 +145,6 @@ static bool batadv_is_wifi_netdev(struct net_device *net_device)
return false; return false;
} }
/**
* batadv_is_wifi_iface - check if the given interface represented by ifindex
* is a wifi interface
* @ifindex: interface index to check
*
* Returns true if the interface represented by ifindex is a 802.11 wireless
* device, false otherwise.
*/
bool batadv_is_wifi_iface(int ifindex)
{
struct net_device *net_device = NULL;
bool ret = false;
if (ifindex == BATADV_NULL_IFINDEX)
goto out;
net_device = dev_get_by_index(&init_net, ifindex);
if (!net_device)
goto out;
ret = batadv_is_wifi_netdev(net_device);
out:
if (net_device)
dev_put(net_device);
return ret;
}
static struct batadv_hard_iface * static struct batadv_hard_iface *
batadv_hardif_get_active(const struct net_device *soft_iface) batadv_hardif_get_active(const struct net_device *soft_iface)
{ {
...@@ -266,16 +242,9 @@ static void batadv_check_known_mac_addr(const struct net_device *net_dev) ...@@ -266,16 +242,9 @@ static void batadv_check_known_mac_addr(const struct net_device *net_dev)
int batadv_hardif_min_mtu(struct net_device *soft_iface) int batadv_hardif_min_mtu(struct net_device *soft_iface)
{ {
const struct batadv_priv *bat_priv = netdev_priv(soft_iface); struct batadv_priv *bat_priv = netdev_priv(soft_iface);
const struct batadv_hard_iface *hard_iface; const struct batadv_hard_iface *hard_iface;
/* allow big frames if all devices are capable to do so
* (have MTU > 1500 + batadv_max_header_len())
*/
int min_mtu = ETH_DATA_LEN; int min_mtu = ETH_DATA_LEN;
int max_header_len = batadv_max_header_len();
if (atomic_read(&bat_priv->fragmentation))
goto out;
rcu_read_lock(); rcu_read_lock();
list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) {
...@@ -286,22 +255,40 @@ int batadv_hardif_min_mtu(struct net_device *soft_iface) ...@@ -286,22 +255,40 @@ int batadv_hardif_min_mtu(struct net_device *soft_iface)
if (hard_iface->soft_iface != soft_iface) if (hard_iface->soft_iface != soft_iface)
continue; continue;
min_mtu = min_t(int, hard_iface->net_dev->mtu - max_header_len, min_mtu = min_t(int, hard_iface->net_dev->mtu, min_mtu);
min_mtu);
} }
rcu_read_unlock(); rcu_read_unlock();
atomic_set(&bat_priv->packet_size_max, min_mtu);
if (atomic_read(&bat_priv->fragmentation) == 0)
goto out;
/* with fragmentation enabled the maximum size of internally generated
* packets such as translation table exchanges or tvlv containers, etc
* has to be calculated
*/
min_mtu = min_t(int, min_mtu, BATADV_FRAG_MAX_FRAG_SIZE);
min_mtu -= sizeof(struct batadv_frag_packet);
min_mtu *= BATADV_FRAG_MAX_FRAGMENTS;
atomic_set(&bat_priv->packet_size_max, min_mtu);
/* with fragmentation enabled we can fragment external packets easily */
min_mtu = min_t(int, min_mtu, ETH_DATA_LEN);
out: out:
return min_mtu; return min_mtu - batadv_max_header_len();
} }
/* adjusts the MTU if a new interface with a smaller MTU appeared. */ /* adjusts the MTU if a new interface with a smaller MTU appeared. */
void batadv_update_min_mtu(struct net_device *soft_iface) void batadv_update_min_mtu(struct net_device *soft_iface)
{ {
int min_mtu; soft_iface->mtu = batadv_hardif_min_mtu(soft_iface);
min_mtu = batadv_hardif_min_mtu(soft_iface); /* Check if the local translate table should be cleaned up to match a
if (soft_iface->mtu != min_mtu) * new (and smaller) MTU.
soft_iface->mtu = min_mtu; */
batadv_tt_local_resize_to_mtu(soft_iface);
} }
static void static void
...@@ -524,8 +511,12 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface, ...@@ -524,8 +511,12 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface,
dev_put(hard_iface->soft_iface); dev_put(hard_iface->soft_iface);
/* nobody uses this interface anymore */ /* nobody uses this interface anymore */
if (!bat_priv->num_ifaces && autodel == BATADV_IF_CLEANUP_AUTO) if (!bat_priv->num_ifaces) {
batadv_gw_check_client_stop(bat_priv);
if (autodel == BATADV_IF_CLEANUP_AUTO)
batadv_softif_destroy_sysfs(hard_iface->soft_iface); batadv_softif_destroy_sysfs(hard_iface->soft_iface);
}
netdev_upper_dev_unlink(hard_iface->net_dev, hard_iface->soft_iface); netdev_upper_dev_unlink(hard_iface->net_dev, hard_iface->soft_iface);
hard_iface->soft_iface = NULL; hard_iface->soft_iface = NULL;
......
...@@ -41,6 +41,7 @@ enum batadv_hard_if_cleanup { ...@@ -41,6 +41,7 @@ enum batadv_hard_if_cleanup {
extern struct notifier_block batadv_hard_if_notifier; extern struct notifier_block batadv_hard_if_notifier;
bool batadv_is_wifi_netdev(struct net_device *net_device);
struct batadv_hard_iface* struct batadv_hard_iface*
batadv_hardif_get_by_netdev(const struct net_device *net_dev); batadv_hardif_get_by_netdev(const struct net_device *net_dev);
int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
...@@ -51,7 +52,6 @@ void batadv_hardif_remove_interfaces(void); ...@@ -51,7 +52,6 @@ void batadv_hardif_remove_interfaces(void);
int batadv_hardif_min_mtu(struct net_device *soft_iface); int batadv_hardif_min_mtu(struct net_device *soft_iface);
void batadv_update_min_mtu(struct net_device *soft_iface); void batadv_update_min_mtu(struct net_device *soft_iface);
void batadv_hardif_free_rcu(struct rcu_head *rcu); void batadv_hardif_free_rcu(struct rcu_head *rcu);
bool batadv_is_wifi_iface(int ifindex);
static inline void static inline void
batadv_hardif_free_ref(struct batadv_hard_iface *hard_iface) batadv_hardif_free_ref(struct batadv_hard_iface *hard_iface)
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
static struct batadv_socket_client *batadv_socket_client_hash[256]; static struct batadv_socket_client *batadv_socket_client_hash[256];
static void batadv_socket_add_packet(struct batadv_socket_client *socket_client, static void batadv_socket_add_packet(struct batadv_socket_client *socket_client,
struct batadv_icmp_packet_rr *icmp_packet, struct batadv_icmp_header *icmph,
size_t icmp_len); size_t icmp_len);
void batadv_socket_init(void) void batadv_socket_init(void)
...@@ -155,13 +155,13 @@ static ssize_t batadv_socket_write(struct file *file, const char __user *buff, ...@@ -155,13 +155,13 @@ static ssize_t batadv_socket_write(struct file *file, const char __user *buff,
struct batadv_priv *bat_priv = socket_client->bat_priv; struct batadv_priv *bat_priv = socket_client->bat_priv;
struct batadv_hard_iface *primary_if = NULL; struct batadv_hard_iface *primary_if = NULL;
struct sk_buff *skb; struct sk_buff *skb;
struct batadv_icmp_packet_rr *icmp_packet; struct batadv_icmp_packet_rr *icmp_packet_rr;
struct batadv_icmp_header *icmp_header;
struct batadv_orig_node *orig_node = NULL; struct batadv_orig_node *orig_node = NULL;
struct batadv_neigh_node *neigh_node = NULL; struct batadv_neigh_node *neigh_node = NULL;
size_t packet_len = sizeof(struct batadv_icmp_packet); size_t packet_len = sizeof(struct batadv_icmp_packet);
if (len < sizeof(struct batadv_icmp_packet)) { if (len < sizeof(struct batadv_icmp_header)) {
batadv_dbg(BATADV_DBG_BATMAN, bat_priv, batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
"Error - can't send packet from char device: invalid packet size\n"); "Error - can't send packet from char device: invalid packet size\n");
return -EINVAL; return -EINVAL;
...@@ -174,8 +174,10 @@ static ssize_t batadv_socket_write(struct file *file, const char __user *buff, ...@@ -174,8 +174,10 @@ static ssize_t batadv_socket_write(struct file *file, const char __user *buff,
goto out; goto out;
} }
if (len >= sizeof(struct batadv_icmp_packet_rr)) if (len >= BATADV_ICMP_MAX_PACKET_SIZE)
packet_len = sizeof(struct batadv_icmp_packet_rr); packet_len = BATADV_ICMP_MAX_PACKET_SIZE;
else
packet_len = len;
skb = netdev_alloc_skb_ip_align(NULL, packet_len + ETH_HLEN); skb = netdev_alloc_skb_ip_align(NULL, packet_len + ETH_HLEN);
if (!skb) { if (!skb) {
...@@ -185,41 +187,33 @@ static ssize_t batadv_socket_write(struct file *file, const char __user *buff, ...@@ -185,41 +187,33 @@ static ssize_t batadv_socket_write(struct file *file, const char __user *buff,
skb->priority = TC_PRIO_CONTROL; skb->priority = TC_PRIO_CONTROL;
skb_reserve(skb, ETH_HLEN); skb_reserve(skb, ETH_HLEN);
icmp_packet = (struct batadv_icmp_packet_rr *)skb_put(skb, packet_len); icmp_header = (struct batadv_icmp_header *)skb_put(skb, packet_len);
if (copy_from_user(icmp_packet, buff, packet_len)) { if (copy_from_user(icmp_header, buff, packet_len)) {
len = -EFAULT; len = -EFAULT;
goto free_skb; goto free_skb;
} }
if (icmp_packet->icmph.header.packet_type != BATADV_ICMP) { if (icmp_header->header.packet_type != BATADV_ICMP) {
batadv_dbg(BATADV_DBG_BATMAN, bat_priv, batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
"Error - can't send packet from char device: got bogus packet type (expected: BAT_ICMP)\n"); "Error - can't send packet from char device: got bogus packet type (expected: BAT_ICMP)\n");
len = -EINVAL; len = -EINVAL;
goto free_skb; goto free_skb;
} }
if (icmp_packet->icmph.msg_type != BATADV_ECHO_REQUEST) { switch (icmp_header->msg_type) {
case BATADV_ECHO_REQUEST:
if (len < sizeof(struct batadv_icmp_packet)) {
batadv_dbg(BATADV_DBG_BATMAN, bat_priv, batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
"Error - can't send packet from char device: got bogus message type (expected: ECHO_REQUEST)\n"); "Error - can't send packet from char device: invalid packet size\n");
len = -EINVAL; len = -EINVAL;
goto free_skb; goto free_skb;
} }
icmp_packet->icmph.uid = socket_client->index;
if (icmp_packet->icmph.header.version != BATADV_COMPAT_VERSION) {
icmp_packet->icmph.msg_type = BATADV_PARAMETER_PROBLEM;
icmp_packet->icmph.header.version = BATADV_COMPAT_VERSION;
batadv_socket_add_packet(socket_client, icmp_packet,
packet_len);
goto free_skb;
}
if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE) if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
goto dst_unreach; goto dst_unreach;
orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->icmph.dst); orig_node = batadv_orig_hash_find(bat_priv, icmp_header->dst);
if (!orig_node) if (!orig_node)
goto dst_unreach; goto dst_unreach;
...@@ -233,19 +227,38 @@ static ssize_t batadv_socket_write(struct file *file, const char __user *buff, ...@@ -233,19 +227,38 @@ static ssize_t batadv_socket_write(struct file *file, const char __user *buff,
if (neigh_node->if_incoming->if_status != BATADV_IF_ACTIVE) if (neigh_node->if_incoming->if_status != BATADV_IF_ACTIVE)
goto dst_unreach; goto dst_unreach;
memcpy(icmp_packet->icmph.orig, icmp_packet_rr = (struct batadv_icmp_packet_rr *)icmp_header;
primary_if->net_dev->dev_addr, ETH_ALEN); if (packet_len == sizeof(*icmp_packet_rr))
memcpy(icmp_packet_rr->rr,
neigh_node->if_incoming->net_dev->dev_addr,
ETH_ALEN);
if (packet_len == sizeof(struct batadv_icmp_packet_rr)) break;
memcpy(icmp_packet->rr, default:
neigh_node->if_incoming->net_dev->dev_addr, ETH_ALEN); batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
"Error - can't send packet from char device: got unknown message type\n");
len = -EINVAL;
goto free_skb;
}
icmp_header->uid = socket_client->index;
if (icmp_header->header.version != BATADV_COMPAT_VERSION) {
icmp_header->msg_type = BATADV_PARAMETER_PROBLEM;
icmp_header->header.version = BATADV_COMPAT_VERSION;
batadv_socket_add_packet(socket_client, icmp_header,
packet_len);
goto free_skb;
}
memcpy(icmp_header->orig, primary_if->net_dev->dev_addr, ETH_ALEN);
batadv_send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr); batadv_send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr);
goto out; goto out;
dst_unreach: dst_unreach:
icmp_packet->icmph.msg_type = BATADV_DESTINATION_UNREACHABLE; icmp_header->msg_type = BATADV_DESTINATION_UNREACHABLE;
batadv_socket_add_packet(socket_client, icmp_packet, packet_len); batadv_socket_add_packet(socket_client, icmp_header, packet_len);
free_skb: free_skb:
kfree_skb(skb); kfree_skb(skb);
out: out:
...@@ -298,27 +311,40 @@ int batadv_socket_setup(struct batadv_priv *bat_priv) ...@@ -298,27 +311,40 @@ int batadv_socket_setup(struct batadv_priv *bat_priv)
return -ENOMEM; return -ENOMEM;
} }
/**
* batadv_socket_receive_packet - schedule an icmp packet to be sent to userspace
* on an icmp socket.
* @socket_client: the socket this packet belongs to
* @icmph: pointer to the header of the icmp packet
* @icmp_len: total length of the icmp packet
*/
static void batadv_socket_add_packet(struct batadv_socket_client *socket_client, static void batadv_socket_add_packet(struct batadv_socket_client *socket_client,
struct batadv_icmp_packet_rr *icmp_packet, struct batadv_icmp_header *icmph,
size_t icmp_len) size_t icmp_len)
{ {
struct batadv_socket_packet *socket_packet; struct batadv_socket_packet *socket_packet;
size_t len;
socket_packet = kmalloc(sizeof(*socket_packet), GFP_ATOMIC); socket_packet = kmalloc(sizeof(*socket_packet), GFP_ATOMIC);
if (!socket_packet) if (!socket_packet)
return; return;
len = icmp_len;
/* check the maximum length before filling the buffer */
if (len > sizeof(socket_packet->icmp_packet))
len = sizeof(socket_packet->icmp_packet);
INIT_LIST_HEAD(&socket_packet->list); INIT_LIST_HEAD(&socket_packet->list);
memcpy(&socket_packet->icmp_packet, icmp_packet, icmp_len); memcpy(&socket_packet->icmp_packet, icmph, len);
socket_packet->icmp_len = icmp_len; socket_packet->icmp_len = len;
spin_lock_bh(&socket_client->lock); spin_lock_bh(&socket_client->lock);
/* while waiting for the lock the socket_client could have been /* while waiting for the lock the socket_client could have been
* deleted * deleted
*/ */
if (!batadv_socket_client_hash[icmp_packet->icmph.uid]) { if (!batadv_socket_client_hash[icmph->uid]) {
spin_unlock_bh(&socket_client->lock); spin_unlock_bh(&socket_client->lock);
kfree(socket_packet); kfree(socket_packet);
return; return;
...@@ -342,12 +368,18 @@ static void batadv_socket_add_packet(struct batadv_socket_client *socket_client, ...@@ -342,12 +368,18 @@ static void batadv_socket_add_packet(struct batadv_socket_client *socket_client,
wake_up(&socket_client->queue_wait); wake_up(&socket_client->queue_wait);
} }
void batadv_socket_receive_packet(struct batadv_icmp_packet_rr *icmp_packet, /**
* batadv_socket_receive_packet - schedule an icmp packet to be received
* locally and sent to userspace.
* @icmph: pointer to the header of the icmp packet
* @icmp_len: total length of the icmp packet
*/
void batadv_socket_receive_packet(struct batadv_icmp_header *icmph,
size_t icmp_len) size_t icmp_len)
{ {
struct batadv_socket_client *hash; struct batadv_socket_client *hash;
hash = batadv_socket_client_hash[icmp_packet->icmph.uid]; hash = batadv_socket_client_hash[icmph->uid];
if (hash) if (hash)
batadv_socket_add_packet(hash, icmp_packet, icmp_len); batadv_socket_add_packet(hash, icmph, icmp_len);
} }
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
void batadv_socket_init(void); void batadv_socket_init(void);
int batadv_socket_setup(struct batadv_priv *bat_priv); int batadv_socket_setup(struct batadv_priv *bat_priv);
void batadv_socket_receive_packet(struct batadv_icmp_packet_rr *icmp_packet, void batadv_socket_receive_packet(struct batadv_icmp_header *icmph,
size_t icmp_len); size_t icmp_len);
#endif /* _NET_BATMAN_ADV_ICMP_SOCKET_H_ */ #endif /* _NET_BATMAN_ADV_ICMP_SOCKET_H_ */
...@@ -501,7 +501,9 @@ int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops) ...@@ -501,7 +501,9 @@ int batadv_algo_register(struct batadv_algo_ops *bat_algo_ops)
!bat_algo_ops->bat_iface_update_mac || !bat_algo_ops->bat_iface_update_mac ||
!bat_algo_ops->bat_primary_iface_set || !bat_algo_ops->bat_primary_iface_set ||
!bat_algo_ops->bat_ogm_schedule || !bat_algo_ops->bat_ogm_schedule ||
!bat_algo_ops->bat_ogm_emit) { !bat_algo_ops->bat_ogm_emit ||
!bat_algo_ops->bat_neigh_cmp ||
!bat_algo_ops->bat_neigh_is_equiv_or_better) {
pr_info("Routing algo '%s' does not implement required ops\n", pr_info("Routing algo '%s' does not implement required ops\n",
bat_algo_ops->name); bat_algo_ops->name);
ret = -EINVAL; ret = -EINVAL;
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#define BATADV_DRIVER_DEVICE "batman-adv" #define BATADV_DRIVER_DEVICE "batman-adv"
#ifndef BATADV_SOURCE_VERSION #ifndef BATADV_SOURCE_VERSION
#define BATADV_SOURCE_VERSION "2013.4.0" #define BATADV_SOURCE_VERSION "2013.5.0"
#endif #endif
/* B.A.T.M.A.N. parameters */ /* B.A.T.M.A.N. parameters */
...@@ -86,6 +86,12 @@ ...@@ -86,6 +86,12 @@
/* numbers of originator to contact for any PUT/GET DHT operation */ /* numbers of originator to contact for any PUT/GET DHT operation */
#define BATADV_DAT_CANDIDATES_NUM 3 #define BATADV_DAT_CANDIDATES_NUM 3
/**
* BATADV_TQ_SIMILARITY_THRESHOLD - TQ points that a secondary metric can differ
* at most from the primary one in order to be still considered acceptable
*/
#define BATADV_TQ_SIMILARITY_THRESHOLD 50
/* how much worse secondary interfaces may be to be considered as bonding /* how much worse secondary interfaces may be to be considered as bonding
* candidates * candidates
*/ */
......
...@@ -1003,7 +1003,7 @@ static bool batadv_nc_code_packets(struct batadv_priv *bat_priv, ...@@ -1003,7 +1003,7 @@ static bool batadv_nc_code_packets(struct batadv_priv *bat_priv,
struct batadv_nc_packet *nc_packet, struct batadv_nc_packet *nc_packet,
struct batadv_neigh_node *neigh_node) struct batadv_neigh_node *neigh_node)
{ {
uint8_t tq_weighted_neigh, tq_weighted_coding; uint8_t tq_weighted_neigh, tq_weighted_coding, tq_tmp;
struct sk_buff *skb_dest, *skb_src; struct sk_buff *skb_dest, *skb_src;
struct batadv_unicast_packet *packet1; struct batadv_unicast_packet *packet1;
struct batadv_unicast_packet *packet2; struct batadv_unicast_packet *packet2;
...@@ -1028,8 +1028,10 @@ static bool batadv_nc_code_packets(struct batadv_priv *bat_priv, ...@@ -1028,8 +1028,10 @@ static bool batadv_nc_code_packets(struct batadv_priv *bat_priv,
if (!router_coding) if (!router_coding)
goto out; goto out;
tq_weighted_neigh = batadv_nc_random_weight_tq(router_neigh->tq_avg); tq_tmp = batadv_nc_random_weight_tq(router_neigh->bat_iv.tq_avg);
tq_weighted_coding = batadv_nc_random_weight_tq(router_coding->tq_avg); tq_weighted_neigh = tq_tmp;
tq_tmp = batadv_nc_random_weight_tq(router_coding->bat_iv.tq_avg);
tq_weighted_coding = tq_tmp;
/* Select one destination for the MAC-header dst-field based on /* Select one destination for the MAC-header dst-field based on
* weighted TQ-values. * weighted TQ-values.
......
This diff is collapsed.
...@@ -22,16 +22,18 @@ ...@@ -22,16 +22,18 @@
#include "hash.h" #include "hash.h"
int batadv_compare_orig(const struct hlist_node *node, const void *data2);
int batadv_originator_init(struct batadv_priv *bat_priv); int batadv_originator_init(struct batadv_priv *bat_priv);
void batadv_originator_free(struct batadv_priv *bat_priv); void batadv_originator_free(struct batadv_priv *bat_priv);
void batadv_purge_orig_ref(struct batadv_priv *bat_priv); void batadv_purge_orig_ref(struct batadv_priv *bat_priv);
void batadv_orig_node_free_ref(struct batadv_orig_node *orig_node); void batadv_orig_node_free_ref(struct batadv_orig_node *orig_node);
void batadv_orig_node_free_ref_now(struct batadv_orig_node *orig_node); void batadv_orig_node_free_ref_now(struct batadv_orig_node *orig_node);
struct batadv_orig_node *batadv_get_orig_node(struct batadv_priv *bat_priv, struct batadv_orig_node *batadv_orig_node_new(struct batadv_priv *bat_priv,
const uint8_t *addr); const uint8_t *addr);
struct batadv_neigh_node * struct batadv_neigh_node *
batadv_neigh_node_new(struct batadv_hard_iface *hard_iface, batadv_neigh_node_new(struct batadv_hard_iface *hard_iface,
const uint8_t *neigh_addr); const uint8_t *neigh_addr,
struct batadv_orig_node *orig_node);
void batadv_neigh_node_free_ref(struct batadv_neigh_node *neigh_node); void batadv_neigh_node_free_ref(struct batadv_neigh_node *neigh_node);
struct batadv_neigh_node * struct batadv_neigh_node *
batadv_orig_node_get_router(struct batadv_orig_node *orig_node); batadv_orig_node_get_router(struct batadv_orig_node *orig_node);
......
...@@ -110,12 +110,13 @@ enum batadv_tt_data_flags { ...@@ -110,12 +110,13 @@ enum batadv_tt_data_flags {
/* BATADV_TT_CLIENT flags. /* BATADV_TT_CLIENT flags.
* Flags from BIT(0) to BIT(7) are sent on the wire, while flags from BIT(8) to * Flags from BIT(0) to BIT(7) are sent on the wire, while flags from BIT(8) to
* BIT(15) are used for local computation only * BIT(15) are used for local computation only.
* Flags from BIT(4) to BIT(7) are kept in sync with the rest of the network.
*/ */
enum batadv_tt_client_flags { enum batadv_tt_client_flags {
BATADV_TT_CLIENT_DEL = BIT(0), BATADV_TT_CLIENT_DEL = BIT(0),
BATADV_TT_CLIENT_ROAM = BIT(1), BATADV_TT_CLIENT_ROAM = BIT(1),
BATADV_TT_CLIENT_WIFI = BIT(2), BATADV_TT_CLIENT_WIFI = BIT(4),
BATADV_TT_CLIENT_NOPURGE = BIT(8), BATADV_TT_CLIENT_NOPURGE = BIT(8),
BATADV_TT_CLIENT_NEW = BIT(9), BATADV_TT_CLIENT_NEW = BIT(9),
BATADV_TT_CLIENT_PENDING = BIT(10), BATADV_TT_CLIENT_PENDING = BIT(10),
...@@ -238,6 +239,8 @@ struct batadv_icmp_packet_rr { ...@@ -238,6 +239,8 @@ struct batadv_icmp_packet_rr {
uint8_t rr[BATADV_RR_LEN][ETH_ALEN]; uint8_t rr[BATADV_RR_LEN][ETH_ALEN];
}; };
#define BATADV_ICMP_MAX_PACKET_SIZE sizeof(struct batadv_icmp_packet_rr)
/* All packet headers in front of an ethernet header have to be completely /* All packet headers in front of an ethernet header have to be completely
* divisible by 2 but not by 4 to make the payload after the ethernet * divisible by 2 but not by 4 to make the payload after the ethernet
* header again 4 bytes boundary aligned. * header again 4 bytes boundary aligned.
......
...@@ -115,9 +115,19 @@ void batadv_bonding_candidate_del(struct batadv_orig_node *orig_node, ...@@ -115,9 +115,19 @@ void batadv_bonding_candidate_del(struct batadv_orig_node *orig_node,
return; return;
} }
void batadv_bonding_candidate_add(struct batadv_orig_node *orig_node, /**
* batadv_bonding_candidate_add - consider a new link for bonding mode towards
* the given originator
* @bat_priv: the bat priv with all the soft interface information
* @orig_node: the target node
* @neigh_node: the neighbor representing the new link to consider for bonding
* mode
*/
void batadv_bonding_candidate_add(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig_node,
struct batadv_neigh_node *neigh_node) struct batadv_neigh_node *neigh_node)
{ {
struct batadv_algo_ops *bao = bat_priv->bat_algo_ops;
struct batadv_neigh_node *tmp_neigh_node, *router = NULL; struct batadv_neigh_node *tmp_neigh_node, *router = NULL;
uint8_t interference_candidate = 0; uint8_t interference_candidate = 0;
...@@ -132,8 +142,9 @@ void batadv_bonding_candidate_add(struct batadv_orig_node *orig_node, ...@@ -132,8 +142,9 @@ void batadv_bonding_candidate_add(struct batadv_orig_node *orig_node,
if (!router) if (!router)
goto candidate_del; goto candidate_del;
/* ... and is good enough to be considered */ /* ... and is good enough to be considered */
if (neigh_node->tq_avg < router->tq_avg - BATADV_BONDING_TQ_THRESHOLD) if (bao->bat_neigh_is_equiv_or_better(neigh_node, router))
goto candidate_del; goto candidate_del;
/* check if we have another candidate with the same mac address or /* check if we have another candidate with the same mac address or
...@@ -249,29 +260,42 @@ bool batadv_check_management_packet(struct sk_buff *skb, ...@@ -249,29 +260,42 @@ bool batadv_check_management_packet(struct sk_buff *skb,
return true; return true;
} }
/**
* batadv_recv_my_icmp_packet - receive an icmp packet locally
* @bat_priv: the bat priv with all the soft interface information
* @skb: icmp packet to process
*
* Returns NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP
* otherwise.
*/
static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv, static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv,
struct sk_buff *skb, size_t icmp_len) struct sk_buff *skb)
{ {
struct batadv_hard_iface *primary_if = NULL; struct batadv_hard_iface *primary_if = NULL;
struct batadv_orig_node *orig_node = NULL; struct batadv_orig_node *orig_node = NULL;
struct batadv_icmp_packet_rr *icmp_packet; struct batadv_icmp_header *icmph;
int ret = NET_RX_DROP; int res, ret = NET_RX_DROP;
icmp_packet = (struct batadv_icmp_packet_rr *)skb->data; icmph = (struct batadv_icmp_header *)skb->data;
/* add data to device queue */ switch (icmph->msg_type) {
if (icmp_packet->icmph.msg_type != BATADV_ECHO_REQUEST) { case BATADV_ECHO_REPLY:
batadv_socket_receive_packet(icmp_packet, icmp_len); case BATADV_DESTINATION_UNREACHABLE:
goto out; case BATADV_TTL_EXCEEDED:
} /* receive the packet */
if (skb_linearize(skb) < 0)
break;
batadv_socket_receive_packet(icmph, skb->len);
break;
case BATADV_ECHO_REQUEST:
/* answer echo request (ping) */
primary_if = batadv_primary_if_get_selected(bat_priv); primary_if = batadv_primary_if_get_selected(bat_priv);
if (!primary_if) if (!primary_if)
goto out; goto out;
/* answer echo request (ping) */
/* get routing information */ /* get routing information */
orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->icmph.orig); orig_node = batadv_orig_hash_find(bat_priv, icmph->orig);
if (!orig_node) if (!orig_node)
goto out; goto out;
...@@ -279,17 +303,22 @@ static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv, ...@@ -279,17 +303,22 @@ static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv,
if (skb_cow(skb, ETH_HLEN) < 0) if (skb_cow(skb, ETH_HLEN) < 0)
goto out; goto out;
icmp_packet = (struct batadv_icmp_packet_rr *)skb->data; icmph = (struct batadv_icmp_header *)skb->data;
memcpy(icmp_packet->icmph.dst, icmp_packet->icmph.orig, ETH_ALEN); memcpy(icmph->dst, icmph->orig, ETH_ALEN);
memcpy(icmp_packet->icmph.orig, primary_if->net_dev->dev_addr, memcpy(icmph->orig, primary_if->net_dev->dev_addr, ETH_ALEN);
ETH_ALEN); icmph->msg_type = BATADV_ECHO_REPLY;
icmp_packet->icmph.msg_type = BATADV_ECHO_REPLY; icmph->header.ttl = BATADV_TTL;
icmp_packet->icmph.header.ttl = BATADV_TTL;
if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP) res = batadv_send_skb_to_orig(skb, orig_node, NULL);
if (res != NET_XMIT_DROP)
ret = NET_RX_SUCCESS; ret = NET_RX_SUCCESS;
break;
default:
/* drop unknown type */
goto out;
}
out: out:
if (primary_if) if (primary_if)
batadv_hardif_free_ref(primary_if); batadv_hardif_free_ref(primary_if);
...@@ -352,16 +381,13 @@ int batadv_recv_icmp_packet(struct sk_buff *skb, ...@@ -352,16 +381,13 @@ int batadv_recv_icmp_packet(struct sk_buff *skb,
struct batadv_hard_iface *recv_if) struct batadv_hard_iface *recv_if)
{ {
struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
struct batadv_icmp_packet_rr *icmp_packet; struct batadv_icmp_header *icmph;
struct batadv_icmp_packet_rr *icmp_packet_rr;
struct ethhdr *ethhdr; struct ethhdr *ethhdr;
struct batadv_orig_node *orig_node = NULL; struct batadv_orig_node *orig_node = NULL;
int hdr_size = sizeof(struct batadv_icmp_packet); int hdr_size = sizeof(struct batadv_icmp_header);
int ret = NET_RX_DROP; int ret = NET_RX_DROP;
/* we truncate all incoming icmp packets if they don't match our size */
if (skb->len >= sizeof(struct batadv_icmp_packet_rr))
hdr_size = sizeof(struct batadv_icmp_packet_rr);
/* drop packet if it has not necessary minimum size */ /* drop packet if it has not necessary minimum size */
if (unlikely(!pskb_may_pull(skb, hdr_size))) if (unlikely(!pskb_may_pull(skb, hdr_size)))
goto out; goto out;
...@@ -380,28 +406,39 @@ int batadv_recv_icmp_packet(struct sk_buff *skb, ...@@ -380,28 +406,39 @@ int batadv_recv_icmp_packet(struct sk_buff *skb,
if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest)) if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest))
goto out; goto out;
icmp_packet = (struct batadv_icmp_packet_rr *)skb->data; icmph = (struct batadv_icmp_header *)skb->data;
/* add record route information if not full */ /* add record route information if not full */
if ((icmp_packet->icmph.msg_type == BATADV_ECHO_REPLY || if ((icmph->msg_type == BATADV_ECHO_REPLY ||
icmp_packet->icmph.msg_type == BATADV_ECHO_REQUEST) && icmph->msg_type == BATADV_ECHO_REQUEST) &&
(hdr_size == sizeof(struct batadv_icmp_packet_rr)) && (skb->len >= sizeof(struct batadv_icmp_packet_rr))) {
(icmp_packet->rr_cur < BATADV_RR_LEN)) { if (skb_linearize(skb) < 0)
memcpy(&(icmp_packet->rr[icmp_packet->rr_cur]), goto out;
/* create a copy of the skb, if needed, to modify it. */
if (skb_cow(skb, ETH_HLEN) < 0)
goto out;
icmph = (struct batadv_icmp_header *)skb->data;
icmp_packet_rr = (struct batadv_icmp_packet_rr *)icmph;
if (icmp_packet_rr->rr_cur >= BATADV_RR_LEN)
goto out;
memcpy(&(icmp_packet_rr->rr[icmp_packet_rr->rr_cur]),
ethhdr->h_dest, ETH_ALEN); ethhdr->h_dest, ETH_ALEN);
icmp_packet->rr_cur++; icmp_packet_rr->rr_cur++;
} }
/* packet for me */ /* packet for me */
if (batadv_is_my_mac(bat_priv, icmp_packet->icmph.dst)) if (batadv_is_my_mac(bat_priv, icmph->dst))
return batadv_recv_my_icmp_packet(bat_priv, skb, hdr_size); return batadv_recv_my_icmp_packet(bat_priv, skb);
/* TTL exceeded */ /* TTL exceeded */
if (icmp_packet->icmph.header.ttl < 2) if (icmph->header.ttl < 2)
return batadv_recv_icmp_ttl_exceeded(bat_priv, skb); return batadv_recv_icmp_ttl_exceeded(bat_priv, skb);
/* get routing information */ /* get routing information */
orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->icmph.dst); orig_node = batadv_orig_hash_find(bat_priv, icmph->dst);
if (!orig_node) if (!orig_node)
goto out; goto out;
...@@ -409,10 +446,10 @@ int batadv_recv_icmp_packet(struct sk_buff *skb, ...@@ -409,10 +446,10 @@ int batadv_recv_icmp_packet(struct sk_buff *skb,
if (skb_cow(skb, ETH_HLEN) < 0) if (skb_cow(skb, ETH_HLEN) < 0)
goto out; goto out;
icmp_packet = (struct batadv_icmp_packet_rr *)skb->data; icmph = (struct batadv_icmp_header *)skb->data;
/* decrement ttl */ /* decrement ttl */
icmp_packet->icmph.header.ttl--; icmph->header.ttl--;
/* route it */ /* route it */
if (batadv_send_skb_to_orig(skb, orig_node, recv_if) != NET_XMIT_DROP) if (batadv_send_skb_to_orig(skb, orig_node, recv_if) != NET_XMIT_DROP)
...@@ -479,18 +516,25 @@ batadv_find_bond_router(struct batadv_orig_node *primary_orig, ...@@ -479,18 +516,25 @@ batadv_find_bond_router(struct batadv_orig_node *primary_orig,
return router; return router;
} }
/* Interface Alternating: Use the best of the /**
* remaining candidates which are not using * batadv_find_ifalter_router - find the best of the remaining candidates which
* this interface. * are not using this interface
* @bat_priv: the bat priv with all the soft interface information
* @primary_orig: the destination
* @recv_if: the interface that the router returned by this function has to not
* use
* *
* Increases the returned router's refcount * Returns the best candidate towards primary_orig that is not using recv_if.
* Increases the returned neighbor's refcount
*/ */
static struct batadv_neigh_node * static struct batadv_neigh_node *
batadv_find_ifalter_router(struct batadv_orig_node *primary_orig, batadv_find_ifalter_router(struct batadv_priv *bat_priv,
struct batadv_orig_node *primary_orig,
const struct batadv_hard_iface *recv_if) const struct batadv_hard_iface *recv_if)
{ {
struct batadv_neigh_node *tmp_neigh_node;
struct batadv_neigh_node *router = NULL, *first_candidate = NULL; struct batadv_neigh_node *router = NULL, *first_candidate = NULL;
struct batadv_algo_ops *bao = bat_priv->bat_algo_ops;
struct batadv_neigh_node *tmp_neigh_node;
rcu_read_lock(); rcu_read_lock();
list_for_each_entry_rcu(tmp_neigh_node, &primary_orig->bond_list, list_for_each_entry_rcu(tmp_neigh_node, &primary_orig->bond_list,
...@@ -502,7 +546,7 @@ batadv_find_ifalter_router(struct batadv_orig_node *primary_orig, ...@@ -502,7 +546,7 @@ batadv_find_ifalter_router(struct batadv_orig_node *primary_orig,
if (tmp_neigh_node->if_incoming == recv_if) if (tmp_neigh_node->if_incoming == recv_if)
continue; continue;
if (router && tmp_neigh_node->tq_avg <= router->tq_avg) if (router && bao->bat_neigh_cmp(tmp_neigh_node, router))
continue; continue;
if (!atomic_inc_not_zero(&tmp_neigh_node->refcount)) if (!atomic_inc_not_zero(&tmp_neigh_node->refcount))
...@@ -636,7 +680,8 @@ batadv_find_router(struct batadv_priv *bat_priv, ...@@ -636,7 +680,8 @@ batadv_find_router(struct batadv_priv *bat_priv,
if (bonding_enabled) if (bonding_enabled)
router = batadv_find_bond_router(primary_orig_node, recv_if); router = batadv_find_bond_router(primary_orig_node, recv_if);
else else
router = batadv_find_ifalter_router(primary_orig_node, recv_if); router = batadv_find_ifalter_router(bat_priv, primary_orig_node,
recv_if);
return_router: return_router:
if (router && router->if_incoming->if_status != BATADV_IF_ACTIVE) if (router && router->if_incoming->if_status != BATADV_IF_ACTIVE)
......
...@@ -48,7 +48,8 @@ batadv_find_router(struct batadv_priv *bat_priv, ...@@ -48,7 +48,8 @@ batadv_find_router(struct batadv_priv *bat_priv,
const struct batadv_hard_iface *recv_if); const struct batadv_hard_iface *recv_if);
void batadv_bonding_candidate_del(struct batadv_orig_node *orig_node, void batadv_bonding_candidate_del(struct batadv_orig_node *orig_node,
struct batadv_neigh_node *neigh_node); struct batadv_neigh_node *neigh_node);
void batadv_bonding_candidate_add(struct batadv_orig_node *orig_node, void batadv_bonding_candidate_add(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig_node,
struct batadv_neigh_node *neigh_node); struct batadv_neigh_node *neigh_node);
void batadv_bonding_save_primary(const struct batadv_orig_node *orig_node, void batadv_bonding_save_primary(const struct batadv_orig_node *orig_node,
struct batadv_orig_node *orig_neigh_node, struct batadv_orig_node *orig_neigh_node,
......
...@@ -166,7 +166,7 @@ static int batadv_interface_tx(struct sk_buff *skb, ...@@ -166,7 +166,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
unsigned int header_len = 0; unsigned int header_len = 0;
int data_len = skb->len, ret; int data_len = skb->len, ret;
unsigned long brd_delay = 1; unsigned long brd_delay = 1;
bool do_bcast = false; bool do_bcast = false, client_added;
unsigned short vid; unsigned short vid;
uint32_t seqno; uint32_t seqno;
...@@ -196,9 +196,12 @@ static int batadv_interface_tx(struct sk_buff *skb, ...@@ -196,9 +196,12 @@ static int batadv_interface_tx(struct sk_buff *skb,
ethhdr = (struct ethhdr *)skb->data; ethhdr = (struct ethhdr *)skb->data;
/* Register the client MAC in the transtable */ /* Register the client MAC in the transtable */
if (!is_multicast_ether_addr(ethhdr->h_source)) if (!is_multicast_ether_addr(ethhdr->h_source)) {
batadv_tt_local_add(soft_iface, ethhdr->h_source, vid, client_added = batadv_tt_local_add(soft_iface, ethhdr->h_source,
skb->skb_iif); vid, skb->skb_iif);
if (!client_added)
goto dropped;
}
/* don't accept stp packets. STP does not help in meshes. /* don't accept stp packets. STP does not help in meshes.
* better use the bridge loop avoidance ... * better use the bridge loop avoidance ...
...@@ -674,6 +677,7 @@ static int batadv_softif_init_late(struct net_device *dev) ...@@ -674,6 +677,7 @@ static int batadv_softif_init_late(struct net_device *dev)
atomic_set(&bat_priv->log_level, 0); atomic_set(&bat_priv->log_level, 0);
#endif #endif
atomic_set(&bat_priv->fragmentation, 1); atomic_set(&bat_priv->fragmentation, 1);
atomic_set(&bat_priv->packet_size_max, ETH_DATA_LEN);
atomic_set(&bat_priv->bcast_queue_left, BATADV_BCAST_QUEUE_LEN); atomic_set(&bat_priv->bcast_queue_left, BATADV_BCAST_QUEUE_LEN);
atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN); atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
......
This diff is collapsed.
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#define _NET_BATMAN_ADV_TRANSLATION_TABLE_H_ #define _NET_BATMAN_ADV_TRANSLATION_TABLE_H_
int batadv_tt_init(struct batadv_priv *bat_priv); int batadv_tt_init(struct batadv_priv *bat_priv);
void batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr, bool batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr,
unsigned short vid, int ifindex); unsigned short vid, int ifindex);
uint16_t batadv_tt_local_remove(struct batadv_priv *bat_priv, uint16_t batadv_tt_local_remove(struct batadv_priv *bat_priv,
const uint8_t *addr, unsigned short vid, const uint8_t *addr, unsigned short vid,
...@@ -45,6 +45,7 @@ bool batadv_tt_global_client_is_roaming(struct batadv_priv *bat_priv, ...@@ -45,6 +45,7 @@ bool batadv_tt_global_client_is_roaming(struct batadv_priv *bat_priv,
uint8_t *addr, unsigned short vid); uint8_t *addr, unsigned short vid);
bool batadv_tt_local_client_is_roaming(struct batadv_priv *bat_priv, bool batadv_tt_local_client_is_roaming(struct batadv_priv *bat_priv,
uint8_t *addr, unsigned short vid); uint8_t *addr, unsigned short vid);
void batadv_tt_local_resize_to_mtu(struct net_device *soft_iface);
bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv, bool batadv_tt_add_temporary_global_entry(struct batadv_priv *bat_priv,
struct batadv_orig_node *orig_node, struct batadv_orig_node *orig_node,
const unsigned char *addr, const unsigned char *addr,
......
...@@ -35,6 +35,18 @@ ...@@ -35,6 +35,18 @@
#endif /* CONFIG_BATMAN_ADV_DAT */ #endif /* CONFIG_BATMAN_ADV_DAT */
/**
* BATADV_TT_REMOTE_MASK - bitmask selecting the flags that are sent over the
* wire only
*/
#define BATADV_TT_REMOTE_MASK 0x00FF
/**
* BATADV_TT_SYNC_MASK - bitmask of the flags that need to be kept in sync
* among the nodes. These flags are used to compute the global/local CRC
*/
#define BATADV_TT_SYNC_MASK 0x00F0
/** /**
* struct batadv_hard_iface_bat_iv - per hard interface B.A.T.M.A.N. IV data * struct batadv_hard_iface_bat_iv - per hard interface B.A.T.M.A.N. IV data
* @ogm_buff: buffer holding the OGM packet * @ogm_buff: buffer holding the OGM packet
...@@ -132,15 +144,29 @@ struct batadv_orig_node_vlan { ...@@ -132,15 +144,29 @@ struct batadv_orig_node_vlan {
struct rcu_head rcu; struct rcu_head rcu;
}; };
/**
* struct batadv_orig_bat_iv - B.A.T.M.A.N. IV private orig_node members
* @bcast_own: bitfield containing the number of our OGMs this orig_node
* rebroadcasted "back" to us (relative to last_real_seqno)
* @bcast_own_sum: counted result of bcast_own
* @ogm_cnt_lock: lock protecting bcast_own, bcast_own_sum,
* neigh_node->bat_iv.real_bits & neigh_node->bat_iv.real_packet_count
*/
struct batadv_orig_bat_iv {
unsigned long *bcast_own;
uint8_t *bcast_own_sum;
/* ogm_cnt_lock protects: bcast_own, bcast_own_sum,
* neigh_node->bat_iv.real_bits & neigh_node->bat_iv.real_packet_count
*/
spinlock_t ogm_cnt_lock;
};
/** /**
* struct batadv_orig_node - structure for orig_list maintaining nodes of mesh * struct batadv_orig_node - structure for orig_list maintaining nodes of mesh
* @orig: originator ethernet address * @orig: originator ethernet address
* @primary_addr: hosts primary interface address * @primary_addr: hosts primary interface address
* @router: router that should be used to reach this originator * @router: router that should be used to reach this originator
* @batadv_dat_addr_t: address of the orig node in the distributed hash * @batadv_dat_addr_t: address of the orig node in the distributed hash
* @bcast_own: bitfield containing the number of our OGMs this orig_node
* rebroadcasted "back" to us (relative to last_real_seqno)
* @bcast_own_sum: counted result of bcast_own
* @last_seen: time when last packet from this node was received * @last_seen: time when last packet from this node was received
* @bcast_seqno_reset: time when the broadcast seqno window was reset * @bcast_seqno_reset: time when the broadcast seqno window was reset
* @batman_seqno_reset: time when the batman seqno window was reset * @batman_seqno_reset: time when the batman seqno window was reset
...@@ -166,8 +192,6 @@ struct batadv_orig_node_vlan { ...@@ -166,8 +192,6 @@ struct batadv_orig_node_vlan {
* @neigh_list_lock: lock protecting neigh_list, router and bonding_list * @neigh_list_lock: lock protecting neigh_list, router and bonding_list
* @hash_entry: hlist node for batadv_priv::orig_hash * @hash_entry: hlist node for batadv_priv::orig_hash
* @bat_priv: pointer to soft_iface this orig node belongs to * @bat_priv: pointer to soft_iface this orig node belongs to
* @ogm_cnt_lock: lock protecting bcast_own, bcast_own_sum,
* neigh_node->real_bits & neigh_node->real_packet_count
* @bcast_seqno_lock: lock protecting bcast_bits & last_bcast_seqno * @bcast_seqno_lock: lock protecting bcast_bits & last_bcast_seqno
* @bond_candidates: how many candidates are available * @bond_candidates: how many candidates are available
* @bond_list: list of bonding candidates * @bond_list: list of bonding candidates
...@@ -181,6 +205,7 @@ struct batadv_orig_node_vlan { ...@@ -181,6 +205,7 @@ struct batadv_orig_node_vlan {
* @vlan_list: a list of orig_node_vlan structs, one per VLAN served by the * @vlan_list: a list of orig_node_vlan structs, one per VLAN served by the
* originator represented by this object * originator represented by this object
* @vlan_list_lock: lock protecting vlan_list * @vlan_list_lock: lock protecting vlan_list
* @bat_iv: B.A.T.M.A.N. IV private structure
*/ */
struct batadv_orig_node { struct batadv_orig_node {
uint8_t orig[ETH_ALEN]; uint8_t orig[ETH_ALEN];
...@@ -189,8 +214,6 @@ struct batadv_orig_node { ...@@ -189,8 +214,6 @@ struct batadv_orig_node {
#ifdef CONFIG_BATMAN_ADV_DAT #ifdef CONFIG_BATMAN_ADV_DAT
batadv_dat_addr_t dat_addr; batadv_dat_addr_t dat_addr;
#endif #endif
unsigned long *bcast_own;
uint8_t *bcast_own_sum;
unsigned long last_seen; unsigned long last_seen;
unsigned long bcast_seqno_reset; unsigned long bcast_seqno_reset;
unsigned long batman_seqno_reset; unsigned long batman_seqno_reset;
...@@ -211,10 +234,6 @@ struct batadv_orig_node { ...@@ -211,10 +234,6 @@ struct batadv_orig_node {
spinlock_t neigh_list_lock; spinlock_t neigh_list_lock;
struct hlist_node hash_entry; struct hlist_node hash_entry;
struct batadv_priv *bat_priv; struct batadv_priv *bat_priv;
/* ogm_cnt_lock protects: bcast_own, bcast_own_sum,
* neigh_node->real_bits & neigh_node->real_packet_count
*/
spinlock_t ogm_cnt_lock;
/* bcast_seqno_lock protects: bcast_bits & last_bcast_seqno */ /* bcast_seqno_lock protects: bcast_bits & last_bcast_seqno */
spinlock_t bcast_seqno_lock; spinlock_t bcast_seqno_lock;
atomic_t bond_candidates; atomic_t bond_candidates;
...@@ -230,6 +249,7 @@ struct batadv_orig_node { ...@@ -230,6 +249,7 @@ struct batadv_orig_node {
struct batadv_frag_table_entry fragments[BATADV_FRAG_BUFFER_COUNT]; struct batadv_frag_table_entry fragments[BATADV_FRAG_BUFFER_COUNT];
struct list_head vlan_list; struct list_head vlan_list;
spinlock_t vlan_list_lock; /* protects vlan_list */ spinlock_t vlan_list_lock; /* protects vlan_list */
struct batadv_orig_bat_iv bat_iv;
}; };
/** /**
...@@ -263,40 +283,49 @@ struct batadv_gw_node { ...@@ -263,40 +283,49 @@ struct batadv_gw_node {
}; };
/** /**
* struct batadv_neigh_node - structure for single hop neighbors * struct batadv_neigh_bat_iv - B.A.T.M.A.N. IV specific structure for single
* @list: list node for batadv_orig_node::neigh_list * hop neighbors
* @addr: mac address of neigh node
* @tq_recv: ring buffer of received TQ values from this neigh node * @tq_recv: ring buffer of received TQ values from this neigh node
* @tq_index: ring buffer index * @tq_index: ring buffer index
* @tq_avg: averaged tq of all tq values in the ring buffer (tq_recv) * @tq_avg: averaged tq of all tq values in the ring buffer (tq_recv)
* @last_ttl: last received ttl from this neigh node
* @bonding_list: list node for batadv_orig_node::bond_list
* @last_seen: when last packet via this neighbor was received
* @real_bits: bitfield containing the number of OGMs received from this neigh * @real_bits: bitfield containing the number of OGMs received from this neigh
* node (relative to orig_node->last_real_seqno) * node (relative to orig_node->last_real_seqno)
* @real_packet_count: counted result of real_bits * @real_packet_count: counted result of real_bits
* @lq_update_lock: lock protecting tq_recv & tq_index
*/
struct batadv_neigh_bat_iv {
uint8_t tq_recv[BATADV_TQ_GLOBAL_WINDOW_SIZE];
uint8_t tq_index;
uint8_t tq_avg;
DECLARE_BITMAP(real_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
uint8_t real_packet_count;
spinlock_t lq_update_lock; /* protects tq_recv & tq_index */
};
/**
* struct batadv_neigh_node - structure for single hops neighbors
* @list: list node for batadv_orig_node::neigh_list
* @orig_node: pointer to corresponding orig_node * @orig_node: pointer to corresponding orig_node
* @addr: the MAC address of the neighboring interface
* @if_incoming: pointer to incoming hard interface * @if_incoming: pointer to incoming hard interface
* @lq_update_lock: lock protecting tq_recv & tq_index * @last_seen: when last packet via this neighbor was received
* @last_ttl: last received ttl from this neigh node
* @bonding_list: list node for batadv_orig_node::bond_list
* @refcount: number of contexts the object is used * @refcount: number of contexts the object is used
* @rcu: struct used for freeing in an RCU-safe manner * @rcu: struct used for freeing in an RCU-safe manner
* @bat_iv: B.A.T.M.A.N. IV private structure
*/ */
struct batadv_neigh_node { struct batadv_neigh_node {
struct hlist_node list; struct hlist_node list;
struct batadv_orig_node *orig_node;
uint8_t addr[ETH_ALEN]; uint8_t addr[ETH_ALEN];
uint8_t tq_recv[BATADV_TQ_GLOBAL_WINDOW_SIZE]; struct batadv_hard_iface *if_incoming;
uint8_t tq_index; unsigned long last_seen;
uint8_t tq_avg;
uint8_t last_ttl; uint8_t last_ttl;
struct list_head bonding_list; struct list_head bonding_list;
unsigned long last_seen;
DECLARE_BITMAP(real_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
uint8_t real_packet_count;
struct batadv_orig_node *orig_node;
struct batadv_hard_iface *if_incoming;
spinlock_t lq_update_lock; /* protects tq_recv & tq_index */
atomic_t refcount; atomic_t refcount;
struct rcu_head rcu; struct rcu_head rcu;
struct batadv_neigh_bat_iv bat_iv;
}; };
/** /**
...@@ -595,6 +624,8 @@ struct batadv_softif_vlan { ...@@ -595,6 +624,8 @@ struct batadv_softif_vlan {
* @aggregated_ogms: bool indicating whether OGM aggregation is enabled * @aggregated_ogms: bool indicating whether OGM aggregation is enabled
* @bonding: bool indicating whether traffic bonding is enabled * @bonding: bool indicating whether traffic bonding is enabled
* @fragmentation: bool indicating whether traffic fragmentation is enabled * @fragmentation: bool indicating whether traffic fragmentation is enabled
* @packet_size_max: max packet size that can be transmitted via
* multiple fragmented skbs or a single frame if fragmentation is disabled
* @frag_seqno: incremental counter to identify chains of egress fragments * @frag_seqno: incremental counter to identify chains of egress fragments
* @bridge_loop_avoidance: bool indicating whether bridge loop avoidance is * @bridge_loop_avoidance: bool indicating whether bridge loop avoidance is
* enabled * enabled
...@@ -641,6 +672,7 @@ struct batadv_priv { ...@@ -641,6 +672,7 @@ struct batadv_priv {
atomic_t aggregated_ogms; atomic_t aggregated_ogms;
atomic_t bonding; atomic_t bonding;
atomic_t fragmentation; atomic_t fragmentation;
atomic_t packet_size_max;
atomic_t frag_seqno; atomic_t frag_seqno;
#ifdef CONFIG_BATMAN_ADV_BLA #ifdef CONFIG_BATMAN_ADV_BLA
atomic_t bridge_loop_avoidance; atomic_t bridge_loop_avoidance;
...@@ -717,7 +749,7 @@ struct batadv_socket_client { ...@@ -717,7 +749,7 @@ struct batadv_socket_client {
struct batadv_socket_packet { struct batadv_socket_packet {
struct list_head list; struct list_head list;
size_t icmp_len; size_t icmp_len;
struct batadv_icmp_packet_rr icmp_packet; uint8_t icmp_packet[BATADV_ICMP_MAX_PACKET_SIZE];
}; };
/** /**
...@@ -975,6 +1007,16 @@ struct batadv_forw_packet { ...@@ -975,6 +1007,16 @@ struct batadv_forw_packet {
* @bat_primary_iface_set: called when primary interface is selected / changed * @bat_primary_iface_set: called when primary interface is selected / changed
* @bat_ogm_schedule: prepare a new outgoing OGM for the send queue * @bat_ogm_schedule: prepare a new outgoing OGM for the send queue
* @bat_ogm_emit: send scheduled OGM * @bat_ogm_emit: send scheduled OGM
* @bat_neigh_cmp: compare the metrics of two neighbors
* @bat_neigh_is_equiv_or_better: check if neigh1 is equally good or
* better than neigh2 from the metric prospective
* @bat_orig_print: print the originator table (optional)
* @bat_orig_free: free the resources allocated by the routing algorithm for an
* orig_node object
* @bat_orig_add_if: ask the routing algorithm to apply the needed changes to
* the orig_node due to a new hard-interface being added into the mesh
* @bat_orig_del_if: ask the routing algorithm to apply the needed changes to
* the orig_node due to an hard-interface being removed from the mesh
*/ */
struct batadv_algo_ops { struct batadv_algo_ops {
struct hlist_node list; struct hlist_node list;
...@@ -985,6 +1027,17 @@ struct batadv_algo_ops { ...@@ -985,6 +1027,17 @@ struct batadv_algo_ops {
void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface); void (*bat_primary_iface_set)(struct batadv_hard_iface *hard_iface);
void (*bat_ogm_schedule)(struct batadv_hard_iface *hard_iface); void (*bat_ogm_schedule)(struct batadv_hard_iface *hard_iface);
void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet); void (*bat_ogm_emit)(struct batadv_forw_packet *forw_packet);
int (*bat_neigh_cmp)(struct batadv_neigh_node *neigh1,
struct batadv_neigh_node *neigh2);
bool (*bat_neigh_is_equiv_or_better)(struct batadv_neigh_node *neigh1,
struct batadv_neigh_node *neigh2);
/* orig_node handling API */
void (*bat_orig_print)(struct batadv_priv *priv, struct seq_file *seq);
void (*bat_orig_free)(struct batadv_orig_node *orig_node);
int (*bat_orig_add_if)(struct batadv_orig_node *orig_node,
int max_if_num);
int (*bat_orig_del_if)(struct batadv_orig_node *orig_node,
int max_if_num, int del_if_num);
}; };
/** /**
......
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