batman-adv: handle routing code initialization properly

Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
This commit is contained in:
Marek Lindner 2012-02-07 17:20:48 +08:00 коммит произвёл Antonio Quartulli
Родитель 00a50076a3
Коммит 77af7575c4
3 изменённых файлов: 17 добавлений и 11 удалений

Просмотреть файл

@ -30,10 +30,11 @@
#include "send.h" #include "send.h"
#include "bat_algo.h" #include "bat_algo.h"
static void bat_iv_ogm_iface_enable(struct hard_iface *hard_iface) static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
{ {
struct batman_ogm_packet *batman_ogm_packet; struct batman_ogm_packet *batman_ogm_packet;
uint32_t random_seqno; uint32_t random_seqno;
int res = -1;
/* randomize initial seqno to avoid collision */ /* randomize initial seqno to avoid collision */
get_random_bytes(&random_seqno, sizeof(random_seqno)); get_random_bytes(&random_seqno, sizeof(random_seqno));
@ -42,6 +43,9 @@ static void bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
hard_iface->packet_len = BATMAN_OGM_LEN; hard_iface->packet_len = BATMAN_OGM_LEN;
hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC); hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
if (!hard_iface->packet_buff)
goto out;
batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff; batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff;
batman_ogm_packet->header.packet_type = BAT_OGM; batman_ogm_packet->header.packet_type = BAT_OGM;
batman_ogm_packet->header.version = COMPAT_VERSION; batman_ogm_packet->header.version = COMPAT_VERSION;
@ -50,6 +54,11 @@ static void bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
batman_ogm_packet->tq = TQ_MAX_VALUE; batman_ogm_packet->tq = TQ_MAX_VALUE;
batman_ogm_packet->tt_num_changes = 0; batman_ogm_packet->tt_num_changes = 0;
batman_ogm_packet->ttvn = 0; batman_ogm_packet->ttvn = 0;
res = 0;
out:
return res;
} }
static void bat_iv_ogm_iface_disable(struct hard_iface *hard_iface) static void bat_iv_ogm_iface_disable(struct hard_iface *hard_iface)

Просмотреть файл

@ -304,22 +304,17 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
if (!softif_is_valid(soft_iface)) { if (!softif_is_valid(soft_iface)) {
pr_err("Can't create batman mesh interface %s: already exists as regular interface\n", pr_err("Can't create batman mesh interface %s: already exists as regular interface\n",
soft_iface->name); soft_iface->name);
dev_put(soft_iface);
ret = -EINVAL; ret = -EINVAL;
goto err; goto err_dev;
} }
hard_iface->soft_iface = soft_iface; hard_iface->soft_iface = soft_iface;
bat_priv = netdev_priv(hard_iface->soft_iface); bat_priv = netdev_priv(hard_iface->soft_iface);
bat_priv->bat_algo_ops->bat_iface_enable(hard_iface); ret = bat_priv->bat_algo_ops->bat_iface_enable(hard_iface);
if (ret < 0) {
if (!hard_iface->packet_buff) {
bat_err(hard_iface->soft_iface,
"Can't add interface packet (%s): out of memory\n",
hard_iface->net_dev->name);
ret = -ENOMEM; ret = -ENOMEM;
goto err; goto err_dev;
} }
hard_iface->if_num = bat_priv->num_ifaces; hard_iface->if_num = bat_priv->num_ifaces;
@ -363,6 +358,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
out: out:
return 0; return 0;
err_dev:
dev_put(soft_iface);
err: err:
hardif_free_ref(hard_iface); hardif_free_ref(hard_iface);
return ret; return ret;

Просмотреть файл

@ -378,7 +378,7 @@ struct bat_algo_ops {
struct hlist_node list; struct hlist_node list;
char *name; char *name;
/* init routing info when hard-interface is enabled */ /* init routing info when hard-interface is enabled */
void (*bat_iface_enable)(struct hard_iface *hard_iface); int (*bat_iface_enable)(struct hard_iface *hard_iface);
/* de-init routing info when hard-interface is disabled */ /* de-init routing info when hard-interface is disabled */
void (*bat_iface_disable)(struct hard_iface *hard_iface); void (*bat_iface_disable)(struct hard_iface *hard_iface);
/* init primary OGM when primary interface is selected */ /* init primary OGM when primary interface is selected */