Skip to content

Commit

Permalink
Merge tag 'batman-adv-for-davem' of git://git.open-mesh.org/linux-merge
Browse files Browse the repository at this point in the history
Antonio Quartulli says:

====================
Included changes:
- increase internal module version
- increase BLA wait periods to 6
- purge BLA backbone table when it is disabled
- make sure post function is invoked only if sysfs value is changed
- simplify code by removing useless NULL checks
- various corrections to existing kerneldoc
- minor cleanups
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Jan 10, 2016
2 parents 12f1501 + ed21d17 commit c9c9931
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 116 deletions.
9 changes: 6 additions & 3 deletions Documentation/networking/batman-adv.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,17 @@ The "bat0" interface can be used like any other regular inter-
face. It needs an IP address which can be either statically con-
figured or dynamically (by using DHCP or similar services):

# NodeA: ifconfig bat0 192.168.0.1
# NodeB: ifconfig bat0 192.168.0.2
# NodeA: ip link set up dev bat0
# NodeA: ip addr add 192.168.0.1/24 dev bat0

# NodeB: ip link set up dev bat0
# NodeB: ip addr add 192.168.0.2/24 dev bat0
# NodeB: ping 192.168.0.1

Note: In order to avoid problems remove all IP addresses previ-
ously assigned to interfaces now used by batman advanced, e.g.

# ifconfig eth0 0.0.0.0
# ip addr flush dev eth0


LOGGING/DEBUGGING
Expand Down
3 changes: 0 additions & 3 deletions net/batman-adv/bat_iv_ogm.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,6 @@ batadv_iv_ogm_primary_iface_set(struct batadv_hard_iface *hard_iface)
unsigned char *ogm_buff = hard_iface->bat_iv.ogm_buff;

batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff;
batadv_ogm_packet->flags = BATADV_PRIMARIES_FIRST_HOP;
batadv_ogm_packet->ttl = BATADV_TTL;
}

Expand Down Expand Up @@ -842,8 +841,6 @@ static void batadv_iv_ogm_forward(struct batadv_orig_node *orig_node,
"Forwarding packet: tq: %i, ttl: %i\n",
batadv_ogm_packet->tq, batadv_ogm_packet->ttl);

/* switch of primaries first hop flag when forwarding */
batadv_ogm_packet->flags &= ~BATADV_PRIMARIES_FIRST_HOP;
if (is_single_hop_neigh)
batadv_ogm_packet->flags |= BATADV_DIRECTLINK;
else
Expand Down
20 changes: 20 additions & 0 deletions net/batman-adv/bridge_loop_avoidance.c
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,26 @@ void batadv_bla_update_orig_address(struct batadv_priv *bat_priv,
}
}

/**
* batadv_bla_status_update - purge bla interfaces if necessary
* @net_dev: the soft interface net device
*/
void batadv_bla_status_update(struct net_device *net_dev)
{
struct batadv_priv *bat_priv = netdev_priv(net_dev);
struct batadv_hard_iface *primary_if;

primary_if = batadv_primary_if_get_selected(bat_priv);
if (!primary_if)
return;

/* this function already purges everything when bla is disabled,
* so just call that one.
*/
batadv_bla_update_orig_address(bat_priv, primary_if, primary_if);
batadv_hardif_free_ref(primary_if);
}

/* periodic work to do:
* * purge structures when they are too old
* * send announcements
Expand Down
2 changes: 2 additions & 0 deletions net/batman-adv/bridge_loop_avoidance.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <linux/types.h>

struct net_device;
struct seq_file;
struct sk_buff;

Expand All @@ -42,6 +43,7 @@ int batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv,
void batadv_bla_update_orig_address(struct batadv_priv *bat_priv,
struct batadv_hard_iface *primary_if,
struct batadv_hard_iface *oldif);
void batadv_bla_status_update(struct net_device *net_dev);
int batadv_bla_init(struct batadv_priv *bat_priv);
void batadv_bla_free(struct batadv_priv *bat_priv);

Expand Down
117 changes: 49 additions & 68 deletions net/batman-adv/gateway_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,23 @@
#include "packet.h"

/**
* batadv_parse_gw_bandwidth - parse supplied string buffer to extract download
* and upload bandwidth information
* batadv_parse_throughput - parse supplied string buffer to extract throughput
* information
* @net_dev: the soft interface net device
* @buff: string buffer to parse
* @down: pointer holding the returned download bandwidth information
* @up: pointer holding the returned upload bandwidth information
* @description: text shown when throughput string cannot be parsed
* @throughput: pointer holding the returned throughput information
*
* Returns false on parse error and true otherwise.
*/
static bool batadv_parse_gw_bandwidth(struct net_device *net_dev, char *buff,
u32 *down, u32 *up)
static bool batadv_parse_throughput(struct net_device *net_dev, char *buff,
const char *description, u32 *throughput)
{
enum batadv_bandwidth_units bw_unit_type = BATADV_BW_UNIT_KBIT;
char *slash_ptr, *tmp_ptr;
u64 ldown, lup;
u64 lthroughput;
char *tmp_ptr;
int ret;

slash_ptr = strchr(buff, '/');
if (slash_ptr)
*slash_ptr = 0;

if (strlen(buff) > 4) {
tmp_ptr = buff + strlen(buff) - 4;

Expand All @@ -63,90 +59,75 @@ static bool batadv_parse_gw_bandwidth(struct net_device *net_dev, char *buff,
*tmp_ptr = '\0';
}

ret = kstrtou64(buff, 10, &ldown);
ret = kstrtou64(buff, 10, &lthroughput);
if (ret) {
batadv_err(net_dev,
"Download speed of gateway mode invalid: %s\n",
buff);
"Invalid throughput speed for %s: %s\n",
description, buff);
return false;
}

switch (bw_unit_type) {
case BATADV_BW_UNIT_MBIT:
/* prevent overflow */
if (U64_MAX / 10 < ldown) {
if (U64_MAX / 10 < lthroughput) {
batadv_err(net_dev,
"Download speed of gateway mode too large: %s\n",
buff);
"Throughput speed for %s too large: %s\n",
description, buff);
return false;
}

ldown *= 10;
lthroughput *= 10;
break;
case BATADV_BW_UNIT_KBIT:
default:
ldown = div_u64(ldown, 100);
lthroughput = div_u64(lthroughput, 100);
break;
}

if (U32_MAX < ldown) {
if (lthroughput > U32_MAX) {
batadv_err(net_dev,
"Download speed of gateway mode too large: %s\n",
buff);
"Throughput speed for %s too large: %s\n",
description, buff);
return false;
}

*down = ldown;

/* we also got some upload info */
if (slash_ptr) {
bw_unit_type = BATADV_BW_UNIT_KBIT;

if (strlen(slash_ptr + 1) > 4) {
tmp_ptr = slash_ptr + 1 - 4 + strlen(slash_ptr + 1);
*throughput = lthroughput;

if (strncasecmp(tmp_ptr, "mbit", 4) == 0)
bw_unit_type = BATADV_BW_UNIT_MBIT;
return true;
}

if ((strncasecmp(tmp_ptr, "kbit", 4) == 0) ||
(bw_unit_type == BATADV_BW_UNIT_MBIT))
*tmp_ptr = '\0';
}
/**
* batadv_parse_gw_bandwidth - parse supplied string buffer to extract download
* and upload bandwidth information
* @net_dev: the soft interface net device
* @buff: string buffer to parse
* @down: pointer holding the returned download bandwidth information
* @up: pointer holding the returned upload bandwidth information
*
* Return: false on parse error and true otherwise.
*/
static bool batadv_parse_gw_bandwidth(struct net_device *net_dev, char *buff,
u32 *down, u32 *up)
{
char *slash_ptr;
bool ret;

ret = kstrtou64(slash_ptr + 1, 10, &lup);
if (ret) {
batadv_err(net_dev,
"Upload speed of gateway mode invalid: %s\n",
slash_ptr + 1);
return false;
}
slash_ptr = strchr(buff, '/');
if (slash_ptr)
*slash_ptr = 0;

switch (bw_unit_type) {
case BATADV_BW_UNIT_MBIT:
/* prevent overflow */
if (U64_MAX / 10 < lup) {
batadv_err(net_dev,
"Upload speed of gateway mode too large: %s\n",
slash_ptr + 1);
return false;
}

lup *= 10;
break;
case BATADV_BW_UNIT_KBIT:
default:
lup = div_u64(lup, 100);
break;
}
ret = batadv_parse_throughput(net_dev, buff, "download gateway speed",
down);
if (!ret)
return false;

if (U32_MAX < lup) {
batadv_err(net_dev,
"Upload speed of gateway mode too large: %s\n",
slash_ptr + 1);
/* we also got some upload info */
if (slash_ptr) {
ret = batadv_parse_throughput(net_dev, slash_ptr + 1,
"upload gateway speed", up);
if (!ret)
return false;
}

*up = lup;
}

return true;
Expand Down
17 changes: 6 additions & 11 deletions net/batman-adv/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ static u16 batadv_tvlv_container_list_size(struct batadv_priv *bat_priv)
static void batadv_tvlv_container_remove(struct batadv_priv *bat_priv,
struct batadv_tvlv_container *tvlv)
{
lockdep_assert_held(&bat_priv->tvlv.handler_list_lock);
lockdep_assert_held(&bat_priv->tvlv.container_list_lock);

if (!tvlv)
return;
Expand Down Expand Up @@ -1143,15 +1143,14 @@ void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src,
struct batadv_unicast_tvlv_packet *unicast_tvlv_packet;
struct batadv_tvlv_hdr *tvlv_hdr;
struct batadv_orig_node *orig_node;
struct sk_buff *skb = NULL;
struct sk_buff *skb;
unsigned char *tvlv_buff;
unsigned int tvlv_len;
ssize_t hdr_len = sizeof(*unicast_tvlv_packet);
bool ret = false;

orig_node = batadv_orig_hash_find(bat_priv, dst);
if (!orig_node)
goto out;
return;

tvlv_len = sizeof(*tvlv_hdr) + tvlv_value_len;

Expand Down Expand Up @@ -1180,14 +1179,10 @@ void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src,
tvlv_buff += sizeof(*tvlv_hdr);
memcpy(tvlv_buff, tvlv_value, tvlv_value_len);

if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP)
ret = true;

out:
if (skb && !ret)
if (batadv_send_skb_to_orig(skb, orig_node, NULL) == NET_XMIT_DROP)
kfree_skb(skb);
if (orig_node)
batadv_orig_node_free_ref(orig_node);
out:
batadv_orig_node_free_ref(orig_node);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions net/batman-adv/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#define BATADV_DRIVER_DEVICE "batman-adv"

#ifndef BATADV_SOURCE_VERSION
#define BATADV_SOURCE_VERSION "2015.2"
#define BATADV_SOURCE_VERSION "2016.0"
#endif

/* B.A.T.M.A.N. parameters */
Expand Down Expand Up @@ -109,7 +109,7 @@
#define BATADV_MAX_AGGREGATION_MS 100

#define BATADV_BLA_PERIOD_LENGTH 10000 /* 10 seconds */
#define BATADV_BLA_BACKBONE_TIMEOUT (BATADV_BLA_PERIOD_LENGTH * 3)
#define BATADV_BLA_BACKBONE_TIMEOUT (BATADV_BLA_PERIOD_LENGTH * 6)
#define BATADV_BLA_CLAIM_TIMEOUT (BATADV_BLA_PERIOD_LENGTH * 10)
#define BATADV_BLA_WAIT_PERIODS 3

Expand Down
4 changes: 1 addition & 3 deletions net/batman-adv/network-coding.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,7 @@ static void batadv_nc_path_free_ref(struct batadv_nc_path *nc_path)
*/
static void batadv_nc_packet_free(struct batadv_nc_packet *nc_packet)
{
if (nc_packet->skb)
kfree_skb(nc_packet->skb);

kfree_skb(nc_packet->skb);
batadv_nc_path_free_ref(nc_packet->nc_path);
kfree(nc_packet);
}
Expand Down
3 changes: 1 addition & 2 deletions net/batman-adv/packet.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ enum batadv_subtype {
* enum batadv_iv_flags - flags used in B.A.T.M.A.N. IV OGM packets
* @BATADV_NOT_BEST_NEXT_HOP: flag is set when ogm packet is forwarded and was
* previously received from someone else than the best neighbor.
* @BATADV_PRIMARIES_FIRST_HOP: flag is set when the primary interface address
* is used, and the packet travels its first hop.
* @BATADV_PRIMARIES_FIRST_HOP: flag unused.
* @BATADV_DIRECTLINK: flag is for the first hop or if rebroadcasted from a
* one hop neighbor on the interface where it was originally received.
*/
Expand Down
3 changes: 1 addition & 2 deletions net/batman-adv/send.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,7 @@ void batadv_schedule_bat_ogm(struct batadv_hard_iface *hard_iface)

static void batadv_forw_packet_free(struct batadv_forw_packet *forw_packet)
{
if (forw_packet->skb)
kfree_skb(forw_packet->skb);
kfree_skb(forw_packet->skb);
if (forw_packet->if_incoming)
batadv_hardif_free_ref(forw_packet->if_incoming);
if (forw_packet->if_outgoing)
Expand Down
16 changes: 12 additions & 4 deletions net/batman-adv/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "distributed-arp-table.h"
#include "gateway_client.h"
#include "gateway_common.h"
#include "bridge_loop_avoidance.h"
#include "hard-interface.h"
#include "network-coding.h"
#include "packet.h"
Expand Down Expand Up @@ -241,10 +242,13 @@ ssize_t batadv_show_vlan_##_name(struct kobject *kobj, \

static int batadv_store_bool_attr(char *buff, size_t count,
struct net_device *net_dev,
const char *attr_name, atomic_t *attr)
const char *attr_name, atomic_t *attr,
bool *changed)
{
int enabled = -1;

*changed = false;

if (buff[count - 1] == '\n')
buff[count - 1] = '\0';

Expand All @@ -271,6 +275,8 @@ static int batadv_store_bool_attr(char *buff, size_t count,
atomic_read(attr) == 1 ? "enabled" : "disabled",
enabled == 1 ? "enabled" : "disabled");

*changed = true;

atomic_set(attr, (unsigned int)enabled);
return count;
}
Expand All @@ -281,11 +287,12 @@ __batadv_store_bool_attr(char *buff, size_t count,
struct attribute *attr,
atomic_t *attr_store, struct net_device *net_dev)
{
bool changed;
int ret;

ret = batadv_store_bool_attr(buff, count, net_dev, attr->name,
attr_store);
if (post_func && ret)
attr_store, &changed);
if (post_func && changed)
post_func(net_dev);

return ret;
Expand Down Expand Up @@ -549,7 +556,8 @@ static ssize_t batadv_store_isolation_mark(struct kobject *kobj,
BATADV_ATTR_SIF_BOOL(aggregated_ogms, S_IRUGO | S_IWUSR, NULL);
BATADV_ATTR_SIF_BOOL(bonding, S_IRUGO | S_IWUSR, NULL);
#ifdef CONFIG_BATMAN_ADV_BLA
BATADV_ATTR_SIF_BOOL(bridge_loop_avoidance, S_IRUGO | S_IWUSR, NULL);
BATADV_ATTR_SIF_BOOL(bridge_loop_avoidance, S_IRUGO | S_IWUSR,
batadv_bla_status_update);
#endif
#ifdef CONFIG_BATMAN_ADV_DAT
BATADV_ATTR_SIF_BOOL(distributed_arp_table, S_IRUGO | S_IWUSR,
Expand Down
Loading

0 comments on commit c9c9931

Please sign in to comment.