Commit 3ccdca77 authored by David S. Miller's avatar David S. Miller

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

parents 71cc7c37 ea3d2fd1
...@@ -65,6 +65,13 @@ Description: ...@@ -65,6 +65,13 @@ Description:
Defines the penalty which will be applied to an Defines the penalty which will be applied to an
originator message's tq-field on every hop. originator message's tq-field on every hop.
What: /sys/class/net/<mesh_iface>/mesh/routing_algo
Date: Dec 2011
Contact: Marek Lindner <lindner_marek@yahoo.de>
Description:
Defines the routing procotol this mesh instance
uses to find the optimal paths through the mesh.
What: /sys/class/net/<mesh_iface>/mesh/vis_mode What: /sys/class/net/<mesh_iface>/mesh/vis_mode
Date: May 2010 Date: May 2010
Contact: Marek Lindner <lindner_marek@yahoo.de> Contact: Marek Lindner <lindner_marek@yahoo.de>
......
/* /*
* Copyright (C) 2007-2011 B.A.T.M.A.N. contributors: * Copyright (C) 2011 B.A.T.M.A.N. contributors:
* *
* Marek Lindner, Simon Wunderlich * Marek Lindner
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public * modify it under the terms of version 2 of the GNU General Public
...@@ -19,17 +19,9 @@ ...@@ -19,17 +19,9 @@
* *
*/ */
#ifndef _NET_BATMAN_ADV_OGM_H_ #ifndef _NET_BATMAN_ADV_BAT_ALGO_H_
#define _NET_BATMAN_ADV_OGM_H_ #define _NET_BATMAN_ADV_BAT_ALGO_H_
#include "main.h" int bat_iv_init(void);
void bat_ogm_init(struct hard_iface *hard_iface); #endif /* _NET_BATMAN_ADV_BAT_ALGO_H_ */
void bat_ogm_init_primary(struct hard_iface *hard_iface);
void bat_ogm_update_mac(struct hard_iface *hard_iface);
void bat_ogm_schedule(struct hard_iface *hard_iface, int tt_num_changes);
void bat_ogm_emit(struct forw_packet *forw_packet);
void bat_ogm_receive(const struct ethhdr *ethhdr, unsigned char *packet_buff,
int packet_len, struct hard_iface *if_incoming);
#endif /* _NET_BATMAN_ADV_OGM_H_ */
...@@ -221,6 +221,11 @@ static void debug_log_cleanup(struct bat_priv *bat_priv) ...@@ -221,6 +221,11 @@ static void debug_log_cleanup(struct bat_priv *bat_priv)
} }
#endif #endif
static int bat_algorithms_open(struct inode *inode, struct file *file)
{
return single_open(file, bat_algo_seq_print_text, NULL);
}
static int originators_open(struct inode *inode, struct file *file) static int originators_open(struct inode *inode, struct file *file)
{ {
struct net_device *net_dev = (struct net_device *)inode->i_private; struct net_device *net_dev = (struct net_device *)inode->i_private;
...@@ -274,6 +279,7 @@ struct bat_debuginfo bat_debuginfo_##_name = { \ ...@@ -274,6 +279,7 @@ struct bat_debuginfo bat_debuginfo_##_name = { \
} \ } \
}; };
static BAT_DEBUGINFO(routing_algos, S_IRUGO, bat_algorithms_open);
static BAT_DEBUGINFO(originators, S_IRUGO, originators_open); static BAT_DEBUGINFO(originators, S_IRUGO, originators_open);
static BAT_DEBUGINFO(gateways, S_IRUGO, gateways_open); static BAT_DEBUGINFO(gateways, S_IRUGO, gateways_open);
static BAT_DEBUGINFO(softif_neigh, S_IRUGO, softif_neigh_open); static BAT_DEBUGINFO(softif_neigh, S_IRUGO, softif_neigh_open);
...@@ -293,9 +299,25 @@ static struct bat_debuginfo *mesh_debuginfos[] = { ...@@ -293,9 +299,25 @@ static struct bat_debuginfo *mesh_debuginfos[] = {
void debugfs_init(void) void debugfs_init(void)
{ {
struct bat_debuginfo *bat_debug;
struct dentry *file;
bat_debugfs = debugfs_create_dir(DEBUGFS_BAT_SUBDIR, NULL); bat_debugfs = debugfs_create_dir(DEBUGFS_BAT_SUBDIR, NULL);
if (bat_debugfs == ERR_PTR(-ENODEV)) if (bat_debugfs == ERR_PTR(-ENODEV))
bat_debugfs = NULL; bat_debugfs = NULL;
if (!bat_debugfs)
goto out;
bat_debug = &bat_debuginfo_routing_algos;
file = debugfs_create_file(bat_debug->attr.name,
S_IFREG | bat_debug->attr.mode,
bat_debugfs, NULL, &bat_debug->fops);
if (!file)
pr_err("Can't add debugfs file: %s\n", bat_debug->attr.name);
out:
return;
} }
void debugfs_destroy(void) void debugfs_destroy(void)
......
This diff is collapsed.
...@@ -272,6 +272,13 @@ static ssize_t store_vis_mode(struct kobject *kobj, struct attribute *attr, ...@@ -272,6 +272,13 @@ static ssize_t store_vis_mode(struct kobject *kobj, struct attribute *attr,
return count; return count;
} }
static ssize_t show_bat_algo(struct kobject *kobj, struct attribute *attr,
char *buff)
{
struct bat_priv *bat_priv = kobj_to_batpriv(kobj);
return sprintf(buff, "%s\n", bat_priv->bat_algo_ops->name);
}
static void post_gw_deselect(struct net_device *net_dev) static void post_gw_deselect(struct net_device *net_dev)
{ {
struct bat_priv *bat_priv = netdev_priv(net_dev); struct bat_priv *bat_priv = netdev_priv(net_dev);
...@@ -382,6 +389,7 @@ BAT_ATTR_BOOL(bonding, S_IRUGO | S_IWUSR, NULL); ...@@ -382,6 +389,7 @@ BAT_ATTR_BOOL(bonding, S_IRUGO | S_IWUSR, NULL);
BAT_ATTR_BOOL(fragmentation, S_IRUGO | S_IWUSR, update_min_mtu); BAT_ATTR_BOOL(fragmentation, S_IRUGO | S_IWUSR, update_min_mtu);
BAT_ATTR_BOOL(ap_isolation, S_IRUGO | S_IWUSR, NULL); BAT_ATTR_BOOL(ap_isolation, S_IRUGO | S_IWUSR, NULL);
static BAT_ATTR(vis_mode, S_IRUGO | S_IWUSR, show_vis_mode, store_vis_mode); static BAT_ATTR(vis_mode, S_IRUGO | S_IWUSR, show_vis_mode, store_vis_mode);
static BAT_ATTR(routing_algo, S_IRUGO, show_bat_algo, NULL);
static BAT_ATTR(gw_mode, S_IRUGO | S_IWUSR, show_gw_mode, store_gw_mode); static BAT_ATTR(gw_mode, S_IRUGO | S_IWUSR, show_gw_mode, store_gw_mode);
BAT_ATTR_UINT(orig_interval, S_IRUGO | S_IWUSR, 2 * JITTER, INT_MAX, NULL); BAT_ATTR_UINT(orig_interval, S_IRUGO | S_IWUSR, 2 * JITTER, INT_MAX, NULL);
BAT_ATTR_UINT(hop_penalty, S_IRUGO | S_IWUSR, 0, TQ_MAX_VALUE, NULL); BAT_ATTR_UINT(hop_penalty, S_IRUGO | S_IWUSR, 0, TQ_MAX_VALUE, NULL);
...@@ -399,6 +407,7 @@ static struct bat_attribute *mesh_attrs[] = { ...@@ -399,6 +407,7 @@ static struct bat_attribute *mesh_attrs[] = {
&bat_attr_fragmentation, &bat_attr_fragmentation,
&bat_attr_ap_isolation, &bat_attr_ap_isolation,
&bat_attr_vis_mode, &bat_attr_vis_mode,
&bat_attr_routing_algo,
&bat_attr_gw_mode, &bat_attr_gw_mode,
&bat_attr_orig_interval, &bat_attr_orig_interval,
&bat_attr_hop_penalty, &bat_attr_hop_penalty,
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "bat_sysfs.h" #include "bat_sysfs.h"
#include "originator.h" #include "originator.h"
#include "hash.h" #include "hash.h"
#include "bat_ogm.h"
#include <linux/if_arp.h> #include <linux/if_arp.h>
...@@ -147,7 +146,7 @@ static void primary_if_select(struct bat_priv *bat_priv, ...@@ -147,7 +146,7 @@ static void primary_if_select(struct bat_priv *bat_priv,
if (!new_hard_iface) if (!new_hard_iface)
return; return;
bat_ogm_init_primary(new_hard_iface); bat_priv->bat_algo_ops->bat_ogm_init_primary(new_hard_iface);
primary_if_update_addr(bat_priv); primary_if_update_addr(bat_priv);
} }
...@@ -233,7 +232,7 @@ static void hardif_activate_interface(struct hard_iface *hard_iface) ...@@ -233,7 +232,7 @@ static void hardif_activate_interface(struct hard_iface *hard_iface)
bat_priv = netdev_priv(hard_iface->soft_iface); bat_priv = netdev_priv(hard_iface->soft_iface);
bat_ogm_update_mac(hard_iface); bat_priv->bat_algo_ops->bat_ogm_update_mac(hard_iface);
hard_iface->if_status = IF_TO_BE_ACTIVATED; hard_iface->if_status = IF_TO_BE_ACTIVATED;
/** /**
...@@ -281,6 +280,14 @@ int hardif_enable_interface(struct hard_iface *hard_iface, ...@@ -281,6 +280,14 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
if (!atomic_inc_not_zero(&hard_iface->refcount)) if (!atomic_inc_not_zero(&hard_iface->refcount))
goto out; goto out;
/* hard-interface is part of a bridge */
if (hard_iface->net_dev->priv_flags & IFF_BRIDGE_PORT)
pr_err("You are about to enable batman-adv on '%s' which "
"already is part of a bridge. Unless you know exactly "
"what you are doing this is probably wrong and won't "
"work the way you think it would.\n",
hard_iface->net_dev->name);
soft_iface = dev_get_by_name(&init_net, iface_name); soft_iface = dev_get_by_name(&init_net, iface_name);
if (!soft_iface) { if (!soft_iface) {
...@@ -307,7 +314,7 @@ int hardif_enable_interface(struct hard_iface *hard_iface, ...@@ -307,7 +314,7 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
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_ogm_init(hard_iface); bat_priv->bat_algo_ops->bat_ogm_init(hard_iface);
if (!hard_iface->packet_buff) { if (!hard_iface->packet_buff) {
bat_err(hard_iface->soft_iface, "Can't add interface packet " bat_err(hard_iface->soft_iface, "Can't add interface packet "
...@@ -527,9 +534,10 @@ static int hard_if_event(struct notifier_block *this, ...@@ -527,9 +534,10 @@ static int hard_if_event(struct notifier_block *this,
goto hardif_put; goto hardif_put;
check_known_mac_addr(hard_iface->net_dev); check_known_mac_addr(hard_iface->net_dev);
bat_ogm_update_mac(hard_iface);
bat_priv = netdev_priv(hard_iface->soft_iface); bat_priv = netdev_priv(hard_iface->soft_iface);
bat_priv->bat_algo_ops->bat_ogm_update_mac(hard_iface);
primary_if = primary_if_get_selected(bat_priv); primary_if = primary_if_get_selected(bat_priv);
if (!primary_if) if (!primary_if)
goto hardif_put; goto hardif_put;
...@@ -590,17 +598,17 @@ static int batman_skb_recv(struct sk_buff *skb, struct net_device *dev, ...@@ -590,17 +598,17 @@ static int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
batman_ogm_packet = (struct batman_ogm_packet *)skb->data; batman_ogm_packet = (struct batman_ogm_packet *)skb->data;
if (batman_ogm_packet->version != COMPAT_VERSION) { if (batman_ogm_packet->header.version != COMPAT_VERSION) {
bat_dbg(DBG_BATMAN, bat_priv, bat_dbg(DBG_BATMAN, bat_priv,
"Drop packet: incompatible batman version (%i)\n", "Drop packet: incompatible batman version (%i)\n",
batman_ogm_packet->version); batman_ogm_packet->header.version);
goto err_free; goto err_free;
} }
/* all receive handlers return whether they received or reused /* all receive handlers return whether they received or reused
* the supplied skb. if not, we have to free the skb. */ * the supplied skb. if not, we have to free the skb. */
switch (batman_ogm_packet->packet_type) { switch (batman_ogm_packet->header.packet_type) {
/* batman originator packet */ /* batman originator packet */
case BAT_OGM: case BAT_OGM:
ret = recv_bat_ogm_packet(skb, hard_iface); ret = recv_bat_ogm_packet(skb, hard_iface);
......
...@@ -191,7 +191,7 @@ static ssize_t bat_socket_write(struct file *file, const char __user *buff, ...@@ -191,7 +191,7 @@ static ssize_t bat_socket_write(struct file *file, const char __user *buff,
goto free_skb; goto free_skb;
} }
if (icmp_packet->packet_type != BAT_ICMP) { if (icmp_packet->header.packet_type != BAT_ICMP) {
bat_dbg(DBG_BATMAN, bat_priv, bat_dbg(DBG_BATMAN, bat_priv,
"Error - can't send packet from char device: " "Error - can't send packet from char device: "
"got bogus packet type (expected: BAT_ICMP)\n"); "got bogus packet type (expected: BAT_ICMP)\n");
...@@ -209,9 +209,9 @@ static ssize_t bat_socket_write(struct file *file, const char __user *buff, ...@@ -209,9 +209,9 @@ static ssize_t bat_socket_write(struct file *file, const char __user *buff,
icmp_packet->uid = socket_client->index; icmp_packet->uid = socket_client->index;
if (icmp_packet->version != COMPAT_VERSION) { if (icmp_packet->header.version != COMPAT_VERSION) {
icmp_packet->msg_type = PARAMETER_PROBLEM; icmp_packet->msg_type = PARAMETER_PROBLEM;
icmp_packet->version = COMPAT_VERSION; icmp_packet->header.version = COMPAT_VERSION;
bat_socket_add_packet(socket_client, icmp_packet, packet_len); bat_socket_add_packet(socket_client, icmp_packet, packet_len);
goto free_skb; goto free_skb;
} }
......
...@@ -32,11 +32,14 @@ ...@@ -32,11 +32,14 @@
#include "gateway_client.h" #include "gateway_client.h"
#include "vis.h" #include "vis.h"
#include "hash.h" #include "hash.h"
#include "bat_algo.h"
/* List manipulations on hardif_list have to be rtnl_lock()'ed, /* List manipulations on hardif_list have to be rtnl_lock()'ed,
* list traversals just rcu-locked */ * list traversals just rcu-locked */
struct list_head hardif_list; struct list_head hardif_list;
char bat_routing_algo[20] = "BATMAN IV";
static struct hlist_head bat_algo_list;
unsigned char broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; unsigned char broadcast_addr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
...@@ -45,6 +48,9 @@ struct workqueue_struct *bat_event_workqueue; ...@@ -45,6 +48,9 @@ struct workqueue_struct *bat_event_workqueue;
static int __init batman_init(void) static int __init batman_init(void)
{ {
INIT_LIST_HEAD(&hardif_list); INIT_LIST_HEAD(&hardif_list);
INIT_HLIST_HEAD(&bat_algo_list);
bat_iv_init();
/* the name should not be longer than 10 chars - see /* the name should not be longer than 10 chars - see
* http://lwn.net/Articles/23634/ */ * http://lwn.net/Articles/23634/ */
...@@ -170,9 +176,110 @@ int is_my_mac(const uint8_t *addr) ...@@ -170,9 +176,110 @@ int is_my_mac(const uint8_t *addr)
} }
rcu_read_unlock(); rcu_read_unlock();
return 0; return 0;
}
static struct bat_algo_ops *bat_algo_get(char *name)
{
struct bat_algo_ops *bat_algo_ops = NULL, *bat_algo_ops_tmp;
struct hlist_node *node;
hlist_for_each_entry(bat_algo_ops_tmp, node, &bat_algo_list, list) {
if (strcmp(bat_algo_ops_tmp->name, name) != 0)
continue;
bat_algo_ops = bat_algo_ops_tmp;
break;
}
return bat_algo_ops;
}
int bat_algo_register(struct bat_algo_ops *bat_algo_ops)
{
struct bat_algo_ops *bat_algo_ops_tmp;
int ret = -1;
bat_algo_ops_tmp = bat_algo_get(bat_algo_ops->name);
if (bat_algo_ops_tmp) {
pr_info("Trying to register already registered routing "
"algorithm: %s\n", bat_algo_ops->name);
goto out;
}
/* all algorithms must implement all ops (for now) */
if (!bat_algo_ops->bat_ogm_init ||
!bat_algo_ops->bat_ogm_init_primary ||
!bat_algo_ops->bat_ogm_update_mac ||
!bat_algo_ops->bat_ogm_schedule ||
!bat_algo_ops->bat_ogm_emit ||
!bat_algo_ops->bat_ogm_receive) {
pr_info("Routing algo '%s' does not implement required ops\n",
bat_algo_ops->name);
goto out;
}
INIT_HLIST_NODE(&bat_algo_ops->list);
hlist_add_head(&bat_algo_ops->list, &bat_algo_list);
ret = 0;
out:
return ret;
}
int bat_algo_select(struct bat_priv *bat_priv, char *name)
{
struct bat_algo_ops *bat_algo_ops;
int ret = -1;
bat_algo_ops = bat_algo_get(name);
if (!bat_algo_ops)
goto out;
bat_priv->bat_algo_ops = bat_algo_ops;
ret = 0;
out:
return ret;
}
int bat_algo_seq_print_text(struct seq_file *seq, void *offset)
{
struct bat_algo_ops *bat_algo_ops;
struct hlist_node *node;
seq_printf(seq, "Available routing algorithms:\n");
hlist_for_each_entry(bat_algo_ops, node, &bat_algo_list, list) {
seq_printf(seq, "%s\n", bat_algo_ops->name);
}
return 0;
}
static int param_set_ra(const char *val, const struct kernel_param *kp)
{
struct bat_algo_ops *bat_algo_ops;
bat_algo_ops = bat_algo_get((char *)val);
if (!bat_algo_ops) {
pr_err("Routing algorithm '%s' is not supported\n", val);
return -EINVAL;
}
return param_set_copystring(val, kp);
} }
static const struct kernel_param_ops param_ops_ra = {
.set = param_set_ra,
.get = param_get_string,
};
static struct kparam_string __param_string_ra = {
.maxlen = sizeof(bat_routing_algo),
.string = bat_routing_algo,
};
module_param_cb(routing_algo, &param_ops_ra, &__param_string_ra, 0644);
module_init(batman_init); module_init(batman_init);
module_exit(batman_exit); module_exit(batman_exit);
......
...@@ -147,6 +147,7 @@ enum dbg_level { ...@@ -147,6 +147,7 @@ enum dbg_level {
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include "types.h" #include "types.h"
extern char bat_routing_algo[];
extern struct list_head hardif_list; extern struct list_head hardif_list;
extern unsigned char broadcast_addr[]; extern unsigned char broadcast_addr[];
...@@ -157,6 +158,9 @@ void mesh_free(struct net_device *soft_iface); ...@@ -157,6 +158,9 @@ void mesh_free(struct net_device *soft_iface);
void inc_module_count(void); void inc_module_count(void);
void dec_module_count(void); void dec_module_count(void);
int is_my_mac(const uint8_t *addr); int is_my_mac(const uint8_t *addr);
int bat_algo_register(struct bat_algo_ops *bat_algo_ops);
int bat_algo_select(struct bat_priv *bat_priv, char *name);
int bat_algo_seq_print_text(struct seq_file *seq, void *offset);
#ifdef CONFIG_BATMAN_ADV_DEBUG #ifdef CONFIG_BATMAN_ADV_DEBUG
int debug_log(struct bat_priv *bat_priv, const char *fmt, ...) __printf(2, 3); int debug_log(struct bat_priv *bat_priv, const char *fmt, ...) __printf(2, 3);
...@@ -202,6 +206,17 @@ static inline int compare_eth(const void *data1, const void *data2) ...@@ -202,6 +206,17 @@ static inline int compare_eth(const void *data1, const void *data2)
return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0); return (memcmp(data1, data2, ETH_ALEN) == 0 ? 1 : 0);
} }
/**
* has_timed_out - compares current time (jiffies) and timestamp + timeout
* @timestamp: base value to compare with (in jiffies)
* @timeout: added to base value before comparing (in milliseconds)
*
* Returns true if current time is after timestamp + timeout
*/
static inline bool has_timed_out(unsigned long timestamp, unsigned int timeout)
{
return time_is_before_jiffies(timestamp + msecs_to_jiffies(timeout));
}
#define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0) #define atomic_dec_not_zero(v) atomic_add_unless((v), -1, 0)
......
...@@ -219,6 +219,7 @@ struct orig_node *get_orig_node(struct bat_priv *bat_priv, const uint8_t *addr) ...@@ -219,6 +219,7 @@ struct orig_node *get_orig_node(struct bat_priv *bat_priv, const uint8_t *addr)
/* extra reference for return */ /* extra reference for return */
atomic_set(&orig_node->refcount, 2); atomic_set(&orig_node->refcount, 2);
orig_node->tt_initialised = false;
orig_node->tt_poss_change = false; orig_node->tt_poss_change = false;
orig_node->bat_priv = bat_priv; orig_node->bat_priv = bat_priv;
memcpy(orig_node->orig, addr, ETH_ALEN); memcpy(orig_node->orig, addr, ETH_ALEN);
......
...@@ -90,10 +90,14 @@ enum tt_client_flags { ...@@ -90,10 +90,14 @@ enum tt_client_flags {
TT_CLIENT_PENDING = 1 << 10 TT_CLIENT_PENDING = 1 << 10
}; };
struct batman_ogm_packet { struct batman_header {
uint8_t packet_type; uint8_t packet_type;
uint8_t version; /* batman version field */ uint8_t version; /* batman version field */
uint8_t ttl; uint8_t ttl;
} __packed;
struct batman_ogm_packet {
struct batman_header header;
uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */ uint8_t flags; /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
uint32_t seqno; uint32_t seqno;
uint8_t orig[6]; uint8_t orig[6];
...@@ -108,9 +112,7 @@ struct batman_ogm_packet { ...@@ -108,9 +112,7 @@ struct batman_ogm_packet {
#define BATMAN_OGM_LEN sizeof(struct batman_ogm_packet) #define BATMAN_OGM_LEN sizeof(struct batman_ogm_packet)
struct icmp_packet { struct icmp_packet {
uint8_t packet_type; struct batman_header header;
uint8_t version; /* batman version field */
uint8_t ttl;
uint8_t msg_type; /* see ICMP message types above */ uint8_t msg_type; /* see ICMP message types above */
uint8_t dst[6]; uint8_t dst[6];
uint8_t orig[6]; uint8_t orig[6];
...@@ -124,9 +126,7 @@ struct icmp_packet { ...@@ -124,9 +126,7 @@ struct icmp_packet {
/* icmp_packet_rr must start with all fields from imcp_packet /* icmp_packet_rr must start with all fields from imcp_packet
* as this is assumed by code that handles ICMP packets */ * as this is assumed by code that handles ICMP packets */
struct icmp_packet_rr { struct icmp_packet_rr {
uint8_t packet_type; struct batman_header header;
uint8_t version; /* batman version field */
uint8_t ttl;
uint8_t msg_type; /* see ICMP message types above */ uint8_t msg_type; /* see ICMP message types above */
uint8_t dst[6]; uint8_t dst[6];
uint8_t orig[6]; uint8_t orig[6];
...@@ -137,17 +137,13 @@ struct icmp_packet_rr { ...@@ -137,17 +137,13 @@ struct icmp_packet_rr {
} __packed; } __packed;
struct unicast_packet { struct unicast_packet {
uint8_t packet_type; struct batman_header header;
uint8_t version; /* batman version field */
uint8_t ttl;
uint8_t ttvn; /* destination translation table version number */ uint8_t ttvn; /* destination translation table version number */
uint8_t dest[6]; uint8_t dest[6];
} __packed; } __packed;
struct unicast_frag_packet { struct unicast_frag_packet {
uint8_t packet_type; struct batman_header header;
uint8_t version; /* batman version field */
uint8_t ttl;
uint8_t ttvn; /* destination translation table version number */ uint8_t ttvn; /* destination translation table version number */
uint8_t dest[6]; uint8_t dest[6];
uint8_t flags; uint8_t flags;
...@@ -157,18 +153,14 @@ struct unicast_frag_packet { ...@@ -157,18 +153,14 @@ struct unicast_frag_packet {
} __packed; } __packed;
struct bcast_packet { struct bcast_packet {
uint8_t packet_type; struct batman_header header;
uint8_t version; /* batman version field */
uint8_t ttl;
uint8_t reserved; uint8_t reserved;
uint32_t seqno; uint32_t seqno;
uint8_t orig[6]; uint8_t orig[6];
} __packed; } __packed;
struct vis_packet { struct vis_packet {
uint8_t packet_type; struct batman_header header;
uint8_t version; /* batman version field */
uint8_t ttl; /* TTL */
uint8_t vis_type; /* which type of vis-participant sent this? */ uint8_t vis_type; /* which type of vis-participant sent this? */
uint32_t seqno; /* sequence number */ uint32_t seqno; /* sequence number */
uint8_t entries; /* number of entries behind this struct */ uint8_t entries; /* number of entries behind this struct */
...@@ -179,9 +171,7 @@ struct vis_packet { ...@@ -179,9 +171,7 @@ struct vis_packet {
} __packed; } __packed;
struct tt_query_packet { struct tt_query_packet {
uint8_t packet_type; struct batman_header header;
uint8_t version; /* batman version field */
uint8_t ttl;
/* the flag field is a combination of: /* the flag field is a combination of:
* - TT_REQUEST or TT_RESPONSE * - TT_REQUEST or TT_RESPONSE
* - TT_FULL_TABLE */ * - TT_FULL_TABLE */
...@@ -202,9 +192,7 @@ struct tt_query_packet { ...@@ -202,9 +192,7 @@ struct tt_query_packet {
} __packed; } __packed;
struct roam_adv_packet { struct roam_adv_packet {
uint8_t packet_type; struct batman_header header;
uint8_t version;
uint8_t ttl;
uint8_t reserved; uint8_t reserved;
uint8_t dst[ETH_ALEN]; uint8_t dst[ETH_ALEN];
uint8_t src[ETH_ALEN]; uint8_t src[ETH_ALEN];
......
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "originator.h" #include "originator.h"
#include "vis.h" #include "vis.h"
#include "unicast.h" #include "unicast.h"
#include "bat_ogm.h"
void slide_own_bcast_window(struct hard_iface *hard_iface) void slide_own_bcast_window(struct hard_iface *hard_iface)
{ {
...@@ -248,6 +247,7 @@ int window_protected(struct bat_priv *bat_priv, int32_t seq_num_diff, ...@@ -248,6 +247,7 @@ int window_protected(struct bat_priv *bat_priv, int32_t seq_num_diff,
int recv_bat_ogm_packet(struct sk_buff *skb, struct hard_iface *hard_iface) int recv_bat_ogm_packet(struct sk_buff *skb, struct hard_iface *hard_iface)
{ {
struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
struct ethhdr *ethhdr; struct ethhdr *ethhdr;
/* drop packet if it has not necessary minimum size */ /* drop packet if it has not necessary minimum size */
...@@ -272,9 +272,7 @@ int recv_bat_ogm_packet(struct sk_buff *skb, struct hard_iface *hard_iface) ...@@ -272,9 +272,7 @@ int recv_bat_ogm_packet(struct sk_buff *skb, struct hard_iface *hard_iface)
if (skb_linearize(skb) < 0) if (skb_linearize(skb) < 0)
return NET_RX_DROP; return NET_RX_DROP;
ethhdr = (struct ethhdr *)skb_mac_header(skb); bat_priv->bat_algo_ops->bat_ogm_receive(hard_iface, skb);
bat_ogm_receive(ethhdr, skb->data, skb_headlen(skb), hard_iface);
kfree_skb(skb); kfree_skb(skb);
return NET_RX_SUCCESS; return NET_RX_SUCCESS;
...@@ -320,7 +318,7 @@ static int recv_my_icmp_packet(struct bat_priv *bat_priv, ...@@ -320,7 +318,7 @@ static int recv_my_icmp_packet(struct bat_priv *bat_priv,
memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN); memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN);
memcpy(icmp_packet->orig, primary_if->net_dev->dev_addr, ETH_ALEN); memcpy(icmp_packet->orig, primary_if->net_dev->dev_addr, ETH_ALEN);
icmp_packet->msg_type = ECHO_REPLY; icmp_packet->msg_type = ECHO_REPLY;
icmp_packet->ttl = TTL; icmp_packet->header.ttl = TTL;
send_skb_packet(skb, router->if_incoming, router->addr); send_skb_packet(skb, router->if_incoming, router->addr);
ret = NET_RX_SUCCESS; ret = NET_RX_SUCCESS;
...@@ -376,7 +374,7 @@ static int recv_icmp_ttl_exceeded(struct bat_priv *bat_priv, ...@@ -376,7 +374,7 @@ static int recv_icmp_ttl_exceeded(struct bat_priv *bat_priv,
memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN); memcpy(icmp_packet->dst, icmp_packet->orig, ETH_ALEN);
memcpy(icmp_packet->orig, primary_if->net_dev->dev_addr, ETH_ALEN); memcpy(icmp_packet->orig, primary_if->net_dev->dev_addr, ETH_ALEN);
icmp_packet->msg_type = TTL_EXCEEDED; icmp_packet->msg_type = TTL_EXCEEDED;
icmp_packet->ttl = TTL; icmp_packet->header.ttl = TTL;
send_skb_packet(skb, router->if_incoming, router->addr); send_skb_packet(skb, router->if_incoming, router->addr);
ret = NET_RX_SUCCESS; ret = NET_RX_SUCCESS;
...@@ -441,7 +439,7 @@ int recv_icmp_packet(struct sk_buff *skb, struct hard_iface *recv_if) ...@@ -441,7 +439,7 @@ int recv_icmp_packet(struct sk_buff *skb, struct hard_iface *recv_if)
return recv_my_icmp_packet(bat_priv, skb, hdr_size); return recv_my_icmp_packet(bat_priv, skb, hdr_size);
/* TTL exceeded */ /* TTL exceeded */
if (icmp_packet->ttl < 2) if (icmp_packet->header.ttl < 2)
return recv_icmp_ttl_exceeded(bat_priv, skb); return recv_icmp_ttl_exceeded(bat_priv, skb);
/* get routing information */ /* get routing information */
...@@ -460,7 +458,7 @@ int recv_icmp_packet(struct sk_buff *skb, struct hard_iface *recv_if) ...@@ -460,7 +458,7 @@ int recv_icmp_packet(struct sk_buff *skb, struct hard_iface *recv_if)
icmp_packet = (struct icmp_packet_rr *)skb->data; icmp_packet = (struct icmp_packet_rr *)skb->data;
/* decrement ttl */ /* decrement ttl */
icmp_packet->ttl--; icmp_packet->header.ttl--;
/* route it */ /* route it */
send_skb_packet(skb, router->if_incoming, router->addr); send_skb_packet(skb, router->if_incoming, router->addr);
...@@ -815,7 +813,7 @@ int route_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if) ...@@ -815,7 +813,7 @@ int route_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if)
unicast_packet = (struct unicast_packet *)skb->data; unicast_packet = (struct unicast_packet *)skb->data;
/* TTL exceeded */ /* TTL exceeded */
if (unicast_packet->ttl < 2) { if (unicast_packet->header.ttl < 2) {
pr_debug("Warning - can't forward unicast packet from %pM to " pr_debug("Warning - can't forward unicast packet from %pM to "
"%pM: ttl exceeded\n", ethhdr->h_source, "%pM: ttl exceeded\n", ethhdr->h_source,
unicast_packet->dest); unicast_packet->dest);
...@@ -840,7 +838,7 @@ int route_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if) ...@@ -840,7 +838,7 @@ int route_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if)
unicast_packet = (struct unicast_packet *)skb->data; unicast_packet = (struct unicast_packet *)skb->data;
if (unicast_packet->packet_type == BAT_UNICAST && if (unicast_packet->header.packet_type == BAT_UNICAST &&
atomic_read(&bat_priv->fragmentation) && atomic_read(&bat_priv->fragmentation) &&
skb->len > neigh_node->if_incoming->net_dev->mtu) { skb->len > neigh_node->if_incoming->net_dev->mtu) {
ret = frag_send_skb(skb, bat_priv, ret = frag_send_skb(skb, bat_priv,
...@@ -848,7 +846,7 @@ int route_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if) ...@@ -848,7 +846,7 @@ int route_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if)
goto out; goto out;
} }
if (unicast_packet->packet_type == BAT_UNICAST_FRAG && if (unicast_packet->header.packet_type == BAT_UNICAST_FRAG &&
frag_can_reassemble(skb, neigh_node->if_incoming->net_dev->mtu)) { frag_can_reassemble(skb, neigh_node->if_incoming->net_dev->mtu)) {
ret = frag_reassemble_skb(skb, bat_priv, &new_skb); ret = frag_reassemble_skb(skb, bat_priv, &new_skb);
...@@ -867,7 +865,7 @@ int route_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if) ...@@ -867,7 +865,7 @@ int route_unicast_packet(struct sk_buff *skb, struct hard_iface *recv_if)
} }
/* decrement ttl */ /* decrement ttl */
unicast_packet->ttl--; unicast_packet->header.ttl--;
/* route it */ /* route it */
send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr); send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr);
...@@ -1041,7 +1039,7 @@ int recv_bcast_packet(struct sk_buff *skb, struct hard_iface *recv_if) ...@@ -1041,7 +1039,7 @@ int recv_bcast_packet(struct sk_buff *skb, struct hard_iface *recv_if)
if (is_my_mac(bcast_packet->orig)) if (is_my_mac(bcast_packet->orig))
goto out; goto out;
if (bcast_packet->ttl < 2) if (bcast_packet->header.ttl < 2)
goto out; goto out;
orig_node = orig_hash_find(bat_priv, bcast_packet->orig); orig_node = orig_hash_find(bat_priv, bcast_packet->orig);
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include "vis.h" #include "vis.h"
#include "gateway_common.h" #include "gateway_common.h"
#include "originator.h" #include "originator.h"
#include "bat_ogm.h"
static void send_outstanding_bcast_packet(struct work_struct *work); static void send_outstanding_bcast_packet(struct work_struct *work);
...@@ -168,7 +167,7 @@ void schedule_bat_ogm(struct hard_iface *hard_iface) ...@@ -168,7 +167,7 @@ void schedule_bat_ogm(struct hard_iface *hard_iface)
if (primary_if) if (primary_if)
hardif_free_ref(primary_if); hardif_free_ref(primary_if);
bat_ogm_schedule(hard_iface, tt_num_changes); bat_priv->bat_algo_ops->bat_ogm_schedule(hard_iface, tt_num_changes);
} }
static void forw_packet_free(struct forw_packet *forw_packet) static void forw_packet_free(struct forw_packet *forw_packet)
...@@ -234,7 +233,7 @@ int add_bcast_packet_to_list(struct bat_priv *bat_priv, ...@@ -234,7 +233,7 @@ int add_bcast_packet_to_list(struct bat_priv *bat_priv,
/* as we have a copy now, it is safe to decrease the TTL */ /* as we have a copy now, it is safe to decrease the TTL */
bcast_packet = (struct bcast_packet *)newskb->data; bcast_packet = (struct bcast_packet *)newskb->data;
bcast_packet->ttl--; bcast_packet->header.ttl--;
skb_reset_mac_header(newskb); skb_reset_mac_header(newskb);
...@@ -318,7 +317,7 @@ void send_outstanding_bat_ogm_packet(struct work_struct *work) ...@@ -318,7 +317,7 @@ void send_outstanding_bat_ogm_packet(struct work_struct *work)
if (atomic_read(&bat_priv->mesh_state) == MESH_DEACTIVATING) if (atomic_read(&bat_priv->mesh_state) == MESH_DEACTIVATING)
goto out; goto out;
bat_ogm_emit(forw_packet); bat_priv->bat_algo_ops->bat_ogm_emit(forw_packet);
/** /**
* we have to have at least one packet in the queue * we have to have at least one packet in the queue
......
...@@ -457,10 +457,10 @@ static void softif_batman_recv(struct sk_buff *skb, struct net_device *dev, ...@@ -457,10 +457,10 @@ static void softif_batman_recv(struct sk_buff *skb, struct net_device *dev,
batman_ogm_packet = (struct batman_ogm_packet *) batman_ogm_packet = (struct batman_ogm_packet *)
(skb->data + ETH_HLEN); (skb->data + ETH_HLEN);
if (batman_ogm_packet->version != COMPAT_VERSION) if (batman_ogm_packet->header.version != COMPAT_VERSION)
goto out; goto out;
if (batman_ogm_packet->packet_type != BAT_OGM) if (batman_ogm_packet->header.packet_type != BAT_OGM)
goto out; goto out;
if (!(batman_ogm_packet->flags & PRIMARIES_FIRST_HOP)) if (!(batman_ogm_packet->flags & PRIMARIES_FIRST_HOP))
...@@ -632,11 +632,11 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface) ...@@ -632,11 +632,11 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
goto dropped; goto dropped;
bcast_packet = (struct bcast_packet *)skb->data; bcast_packet = (struct bcast_packet *)skb->data;
bcast_packet->version = COMPAT_VERSION; bcast_packet->header.version = COMPAT_VERSION;
bcast_packet->ttl = TTL; bcast_packet->header.ttl = TTL;
/* batman packet type: broadcast */ /* batman packet type: broadcast */
bcast_packet->packet_type = BAT_BCAST; bcast_packet->header.packet_type = BAT_BCAST;
/* hw address of first interface is the orig mac because only /* hw address of first interface is the orig mac because only
* this mac is known throughout the mesh */ * this mac is known throughout the mesh */
...@@ -725,8 +725,8 @@ void interface_rx(struct net_device *soft_iface, ...@@ -725,8 +725,8 @@ void interface_rx(struct net_device *soft_iface,
skb_push(skb, hdr_size); skb_push(skb, hdr_size);
unicast_packet = (struct unicast_packet *)skb->data; unicast_packet = (struct unicast_packet *)skb->data;
if ((unicast_packet->packet_type != BAT_UNICAST) && if ((unicast_packet->header.packet_type != BAT_UNICAST) &&
(unicast_packet->packet_type != BAT_UNICAST_FRAG)) (unicast_packet->header.packet_type != BAT_UNICAST_FRAG))
goto dropped; goto dropped;
skb_reset_mac_header(skb); skb_reset_mac_header(skb);
...@@ -855,6 +855,10 @@ struct net_device *softif_create(const char *name) ...@@ -855,6 +855,10 @@ struct net_device *softif_create(const char *name)
bat_priv->primary_if = NULL; bat_priv->primary_if = NULL;
bat_priv->num_ifaces = 0; bat_priv->num_ifaces = 0;
ret = bat_algo_select(bat_priv, bat_routing_algo);
if (ret < 0)
goto unreg_soft_iface;
ret = sysfs_add_meshif(soft_iface); ret = sysfs_add_meshif(soft_iface);
if (ret < 0) if (ret < 0)
goto unreg_soft_iface; goto unreg_soft_iface;
......
...@@ -108,14 +108,6 @@ static struct tt_global_entry *tt_global_hash_find(struct bat_priv *bat_priv, ...@@ -108,14 +108,6 @@ static struct tt_global_entry *tt_global_hash_find(struct bat_priv *bat_priv,
} }
static bool is_out_of_time(unsigned long starting_time, unsigned long timeout)
{
unsigned long deadline;
deadline = starting_time + msecs_to_jiffies(timeout);
return time_after(jiffies, deadline);
}
static void tt_local_entry_free_ref(struct tt_local_entry *tt_local_entry) static void tt_local_entry_free_ref(struct tt_local_entry *tt_local_entry)
{ {
if (atomic_dec_and_test(&tt_local_entry->common.refcount)) if (atomic_dec_and_test(&tt_local_entry->common.refcount))
...@@ -420,7 +412,7 @@ static void tt_local_purge(struct bat_priv *bat_priv) ...@@ -420,7 +412,7 @@ static void tt_local_purge(struct bat_priv *bat_priv)
if (tt_local_entry->common.flags & TT_CLIENT_PENDING) if (tt_local_entry->common.flags & TT_CLIENT_PENDING)
continue; continue;
if (!is_out_of_time(tt_local_entry->last_seen, if (!has_timed_out(tt_local_entry->last_seen,
TT_LOCAL_TIMEOUT * 1000)) TT_LOCAL_TIMEOUT * 1000))
continue; continue;
...@@ -733,6 +725,7 @@ void tt_global_del_orig(struct bat_priv *bat_priv, ...@@ -733,6 +725,7 @@ void tt_global_del_orig(struct bat_priv *bat_priv,
spin_unlock_bh(list_lock); spin_unlock_bh(list_lock);
} }
atomic_set(&orig_node->tt_size, 0); atomic_set(&orig_node->tt_size, 0);
orig_node->tt_initialised = false;
} }
static void tt_global_roam_purge(struct bat_priv *bat_priv) static void tt_global_roam_purge(struct bat_priv *bat_priv)
...@@ -757,7 +750,7 @@ static void tt_global_roam_purge(struct bat_priv *bat_priv) ...@@ -757,7 +750,7 @@ static void tt_global_roam_purge(struct bat_priv *bat_priv)
common); common);
if (!(tt_global_entry->common.flags & TT_CLIENT_ROAM)) if (!(tt_global_entry->common.flags & TT_CLIENT_ROAM))
continue; continue;
if (!is_out_of_time(tt_global_entry->roam_at, if (!has_timed_out(tt_global_entry->roam_at,
TT_CLIENT_ROAM_TIMEOUT * 1000)) TT_CLIENT_ROAM_TIMEOUT * 1000))
continue; continue;
...@@ -977,7 +970,7 @@ static void tt_req_purge(struct bat_priv *bat_priv) ...@@ -977,7 +970,7 @@ static void tt_req_purge(struct bat_priv *bat_priv)
spin_lock_bh(&bat_priv->tt_req_list_lock); spin_lock_bh(&bat_priv->tt_req_list_lock);
list_for_each_entry_safe(node, safe, &bat_priv->tt_req_list, list) { list_for_each_entry_safe(node, safe, &bat_priv->tt_req_list, list) {
if (is_out_of_time(node->issued_at, if (has_timed_out(node->issued_at,
TT_REQUEST_TIMEOUT * 1000)) { TT_REQUEST_TIMEOUT * 1000)) {
list_del(&node->list); list_del(&node->list);
kfree(node); kfree(node);
...@@ -996,7 +989,7 @@ static struct tt_req_node *new_tt_req_node(struct bat_priv *bat_priv, ...@@ -996,7 +989,7 @@ static struct tt_req_node *new_tt_req_node(struct bat_priv *bat_priv,
spin_lock_bh(&bat_priv->tt_req_list_lock); spin_lock_bh(&bat_priv->tt_req_list_lock);
list_for_each_entry(tt_req_node_tmp, &bat_priv->tt_req_list, list) { list_for_each_entry(tt_req_node_tmp, &bat_priv->tt_req_list, list) {
if (compare_eth(tt_req_node_tmp, orig_node) && if (compare_eth(tt_req_node_tmp, orig_node) &&
!is_out_of_time(tt_req_node_tmp->issued_at, !has_timed_out(tt_req_node_tmp->issued_at,
TT_REQUEST_TIMEOUT * 1000)) TT_REQUEST_TIMEOUT * 1000))
goto unlock; goto unlock;
} }
...@@ -1134,11 +1127,11 @@ static int send_tt_request(struct bat_priv *bat_priv, ...@@ -1134,11 +1127,11 @@ static int send_tt_request(struct bat_priv *bat_priv,
tt_request = (struct tt_query_packet *)skb_put(skb, tt_request = (struct tt_query_packet *)skb_put(skb,
sizeof(struct tt_query_packet)); sizeof(struct tt_query_packet));
tt_request->packet_type = BAT_TT_QUERY; tt_request->header.packet_type = BAT_TT_QUERY;
tt_request->version = COMPAT_VERSION; tt_request->header.version = COMPAT_VERSION;
memcpy(tt_request->src, primary_if->net_dev->dev_addr, ETH_ALEN); memcpy(tt_request->src, primary_if->net_dev->dev_addr, ETH_ALEN);
memcpy(tt_request->dst, dst_orig_node->orig, ETH_ALEN); memcpy(tt_request->dst, dst_orig_node->orig, ETH_ALEN);
tt_request->ttl = TTL; tt_request->header.ttl = TTL;
tt_request->ttvn = ttvn; tt_request->ttvn = ttvn;
tt_request->tt_data = tt_crc; tt_request->tt_data = tt_crc;
tt_request->flags = TT_REQUEST; tt_request->flags = TT_REQUEST;
...@@ -1264,9 +1257,9 @@ static bool send_other_tt_response(struct bat_priv *bat_priv, ...@@ -1264,9 +1257,9 @@ static bool send_other_tt_response(struct bat_priv *bat_priv,
tt_response = (struct tt_query_packet *)skb->data; tt_response = (struct tt_query_packet *)skb->data;
} }
tt_response->packet_type = BAT_TT_QUERY; tt_response->header.packet_type = BAT_TT_QUERY;
tt_response->version = COMPAT_VERSION; tt_response->header.version = COMPAT_VERSION;
tt_response->ttl = TTL; tt_response->header.ttl = TTL;
memcpy(tt_response->src, req_dst_orig_node->orig, ETH_ALEN); memcpy(tt_response->src, req_dst_orig_node->orig, ETH_ALEN);
memcpy(tt_response->dst, tt_request->src, ETH_ALEN); memcpy(tt_response->dst, tt_request->src, ETH_ALEN);
tt_response->flags = TT_RESPONSE; tt_response->flags = TT_RESPONSE;
...@@ -1381,9 +1374,9 @@ static bool send_my_tt_response(struct bat_priv *bat_priv, ...@@ -1381,9 +1374,9 @@ static bool send_my_tt_response(struct bat_priv *bat_priv,
tt_response = (struct tt_query_packet *)skb->data; tt_response = (struct tt_query_packet *)skb->data;
} }
tt_response->packet_type = BAT_TT_QUERY; tt_response->header.packet_type = BAT_TT_QUERY;
tt_response->version = COMPAT_VERSION; tt_response->header.version = COMPAT_VERSION;
tt_response->ttl = TTL; tt_response->header.ttl = TTL;
memcpy(tt_response->src, primary_if->net_dev->dev_addr, ETH_ALEN); memcpy(tt_response->src, primary_if->net_dev->dev_addr, ETH_ALEN);
memcpy(tt_response->dst, tt_request->src, ETH_ALEN); memcpy(tt_response->dst, tt_request->src, ETH_ALEN);
tt_response->flags = TT_RESPONSE; tt_response->flags = TT_RESPONSE;
...@@ -1450,6 +1443,7 @@ static void _tt_update_changes(struct bat_priv *bat_priv, ...@@ -1450,6 +1443,7 @@ static void _tt_update_changes(struct bat_priv *bat_priv,
*/ */
return; return;
} }
orig_node->tt_initialised = true;
} }
static void tt_fill_gtable(struct bat_priv *bat_priv, static void tt_fill_gtable(struct bat_priv *bat_priv,
...@@ -1589,7 +1583,7 @@ static void tt_roam_purge(struct bat_priv *bat_priv) ...@@ -1589,7 +1583,7 @@ static void tt_roam_purge(struct bat_priv *bat_priv)
spin_lock_bh(&bat_priv->tt_roam_list_lock); spin_lock_bh(&bat_priv->tt_roam_list_lock);
list_for_each_entry_safe(node, safe, &bat_priv->tt_roam_list, list) { list_for_each_entry_safe(node, safe, &bat_priv->tt_roam_list, list) {
if (!is_out_of_time(node->first_time, if (!has_timed_out(node->first_time,
ROAMING_MAX_TIME * 1000)) ROAMING_MAX_TIME * 1000))
continue; continue;
...@@ -1617,7 +1611,7 @@ static bool tt_check_roam_count(struct bat_priv *bat_priv, ...@@ -1617,7 +1611,7 @@ static bool tt_check_roam_count(struct bat_priv *bat_priv,
if (!compare_eth(tt_roam_node->addr, client)) if (!compare_eth(tt_roam_node->addr, client))
continue; continue;
if (is_out_of_time(tt_roam_node->first_time, if (has_timed_out(tt_roam_node->first_time,
ROAMING_MAX_TIME * 1000)) ROAMING_MAX_TIME * 1000))
continue; continue;
...@@ -1669,9 +1663,9 @@ void send_roam_adv(struct bat_priv *bat_priv, uint8_t *client, ...@@ -1669,9 +1663,9 @@ void send_roam_adv(struct bat_priv *bat_priv, uint8_t *client,
roam_adv_packet = (struct roam_adv_packet *)skb_put(skb, roam_adv_packet = (struct roam_adv_packet *)skb_put(skb,
sizeof(struct roam_adv_packet)); sizeof(struct roam_adv_packet));
roam_adv_packet->packet_type = BAT_ROAM_ADV; roam_adv_packet->header.packet_type = BAT_ROAM_ADV;
roam_adv_packet->version = COMPAT_VERSION; roam_adv_packet->header.version = COMPAT_VERSION;
roam_adv_packet->ttl = TTL; roam_adv_packet->header.ttl = TTL;
primary_if = primary_if_get_selected(bat_priv); primary_if = primary_if_get_selected(bat_priv);
if (!primary_if) if (!primary_if)
goto out; goto out;
...@@ -1854,8 +1848,10 @@ void tt_update_orig(struct bat_priv *bat_priv, struct orig_node *orig_node, ...@@ -1854,8 +1848,10 @@ void tt_update_orig(struct bat_priv *bat_priv, struct orig_node *orig_node,
uint8_t orig_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn); uint8_t orig_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn);
bool full_table = true; bool full_table = true;
/* the ttvn increased by one -> we can apply the attached changes */ /* orig table not initialised AND first diff is in the OGM OR the ttvn
if (ttvn - orig_ttvn == 1) { * increased by one -> we can apply the attached changes */
if ((!orig_node->tt_initialised && ttvn == 1) ||
ttvn - orig_ttvn == 1) {
/* the OGM could not contain the changes due to their size or /* the OGM could not contain the changes due to their size or
* because they have already been sent TT_OGM_APPEND_MAX times. * because they have already been sent TT_OGM_APPEND_MAX times.
* In this case send a tt request */ * In this case send a tt request */
...@@ -1889,7 +1885,8 @@ void tt_update_orig(struct bat_priv *bat_priv, struct orig_node *orig_node, ...@@ -1889,7 +1885,8 @@ void tt_update_orig(struct bat_priv *bat_priv, struct orig_node *orig_node,
} else { } else {
/* if we missed more than one change or our tables are not /* if we missed more than one change or our tables are not
* in sync anymore -> request fresh tt data */ * in sync anymore -> request fresh tt data */
if (ttvn != orig_ttvn || orig_node->tt_crc != tt_crc) { if (!orig_node->tt_initialised || ttvn != orig_ttvn ||
orig_node->tt_crc != tt_crc) {
request_table: request_table:
bat_dbg(DBG_TT, bat_priv, "TT inconsistency for %pM. " bat_dbg(DBG_TT, bat_priv, "TT inconsistency for %pM. "
"Need to retrieve the correct information " "Need to retrieve the correct information "
......
...@@ -81,6 +81,7 @@ struct orig_node { ...@@ -81,6 +81,7 @@ struct orig_node {
int16_t tt_buff_len; int16_t tt_buff_len;
spinlock_t tt_buff_lock; /* protects tt_buff */ spinlock_t tt_buff_lock; /* protects tt_buff */
atomic_t tt_size; atomic_t tt_size;
bool tt_initialised;
/* The tt_poss_change flag is used to detect an ongoing roaming phase. /* The tt_poss_change flag is used to detect an ongoing roaming phase.
* If true, then I sent a Roaming_adv to this orig_node and I have to * If true, then I sent a Roaming_adv to this orig_node and I have to
* inspect every packet directed to it to check whether it is still * inspect every packet directed to it to check whether it is still
...@@ -205,6 +206,7 @@ struct bat_priv { ...@@ -205,6 +206,7 @@ struct bat_priv {
atomic_t gw_reselect; atomic_t gw_reselect;
struct hard_iface __rcu *primary_if; /* rcu protected pointer */ struct hard_iface __rcu *primary_if; /* rcu protected pointer */
struct vis_info *my_vis_info; struct vis_info *my_vis_info;
struct bat_algo_ops *bat_algo_ops;
}; };
struct socket_client { struct socket_client {
...@@ -343,4 +345,23 @@ struct softif_neigh { ...@@ -343,4 +345,23 @@ struct softif_neigh {
struct rcu_head rcu; struct rcu_head rcu;
}; };
struct bat_algo_ops {
struct hlist_node list;
char *name;
/* init OGM when hard-interface is enabled */
void (*bat_ogm_init)(struct hard_iface *hard_iface);
/* init primary OGM when primary interface is selected */
void (*bat_ogm_init_primary)(struct hard_iface *hard_iface);
/* init mac addresses of the OGM belonging to this hard-interface */
void (*bat_ogm_update_mac)(struct hard_iface *hard_iface);
/* prepare a new outgoing OGM for the send queue */
void (*bat_ogm_schedule)(struct hard_iface *hard_iface,
int tt_num_changes);
/* send scheduled OGM */
void (*bat_ogm_emit)(struct forw_packet *forw_packet);
/* receive incoming OGM */
void (*bat_ogm_receive)(struct hard_iface *if_incoming,
struct sk_buff *skb);
};
#endif /* _NET_BATMAN_ADV_TYPES_H_ */ #endif /* _NET_BATMAN_ADV_TYPES_H_ */
...@@ -67,7 +67,7 @@ static struct sk_buff *frag_merge_packet(struct list_head *head, ...@@ -67,7 +67,7 @@ static struct sk_buff *frag_merge_packet(struct list_head *head,
memmove(skb->data + uni_diff, skb->data, hdr_len); memmove(skb->data + uni_diff, skb->data, hdr_len);
unicast_packet = (struct unicast_packet *) skb_pull(skb, uni_diff); unicast_packet = (struct unicast_packet *) skb_pull(skb, uni_diff);
unicast_packet->packet_type = BAT_UNICAST; unicast_packet->header.packet_type = BAT_UNICAST;
return skb; return skb;
...@@ -251,9 +251,9 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, ...@@ -251,9 +251,9 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
memcpy(frag1, &tmp_uc, sizeof(tmp_uc)); memcpy(frag1, &tmp_uc, sizeof(tmp_uc));
frag1->ttl--; frag1->header.ttl--;
frag1->version = COMPAT_VERSION; frag1->header.version = COMPAT_VERSION;
frag1->packet_type = BAT_UNICAST_FRAG; frag1->header.packet_type = BAT_UNICAST_FRAG;
memcpy(frag1->orig, primary_if->net_dev->dev_addr, ETH_ALEN); memcpy(frag1->orig, primary_if->net_dev->dev_addr, ETH_ALEN);
memcpy(frag2, frag1, sizeof(*frag2)); memcpy(frag2, frag1, sizeof(*frag2));
...@@ -320,11 +320,11 @@ int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv) ...@@ -320,11 +320,11 @@ int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv)
unicast_packet = (struct unicast_packet *)skb->data; unicast_packet = (struct unicast_packet *)skb->data;
unicast_packet->version = COMPAT_VERSION; unicast_packet->header.version = COMPAT_VERSION;
/* batman packet type: unicast */ /* batman packet type: unicast */
unicast_packet->packet_type = BAT_UNICAST; unicast_packet->header.packet_type = BAT_UNICAST;
/* set unicast ttl */ /* set unicast ttl */
unicast_packet->ttl = TTL; unicast_packet->header.ttl = TTL;
/* copy the destination for faster routing */ /* copy the destination for faster routing */
memcpy(unicast_packet->dest, orig_node->orig, ETH_ALEN); memcpy(unicast_packet->dest, orig_node->orig, ETH_ALEN);
/* set the destination tt version number */ /* set the destination tt version number */
...@@ -335,7 +335,7 @@ int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv) ...@@ -335,7 +335,7 @@ int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv)
data_len + sizeof(*unicast_packet) > data_len + sizeof(*unicast_packet) >
neigh_node->if_incoming->net_dev->mtu) { neigh_node->if_incoming->net_dev->mtu) {
/* send frag skb decreases ttl */ /* send frag skb decreases ttl */
unicast_packet->ttl++; unicast_packet->header.ttl++;
ret = frag_send_skb(skb, bat_priv, ret = frag_send_skb(skb, bat_priv,
neigh_node->if_incoming, neigh_node->addr); neigh_node->if_incoming, neigh_node->addr);
goto out; goto out;
......
...@@ -617,7 +617,7 @@ static int generate_vis_packet(struct bat_priv *bat_priv) ...@@ -617,7 +617,7 @@ static int generate_vis_packet(struct bat_priv *bat_priv)
packet->vis_type = atomic_read(&bat_priv->vis_mode); packet->vis_type = atomic_read(&bat_priv->vis_mode);
memcpy(packet->target_orig, broadcast_addr, ETH_ALEN); memcpy(packet->target_orig, broadcast_addr, ETH_ALEN);
packet->ttl = TTL; packet->header.ttl = TTL;
packet->seqno = htonl(ntohl(packet->seqno) + 1); packet->seqno = htonl(ntohl(packet->seqno) + 1);
packet->entries = 0; packet->entries = 0;
skb_trim(info->skb_packet, sizeof(*packet)); skb_trim(info->skb_packet, sizeof(*packet));
...@@ -818,19 +818,19 @@ static void send_vis_packet(struct bat_priv *bat_priv, struct vis_info *info) ...@@ -818,19 +818,19 @@ static void send_vis_packet(struct bat_priv *bat_priv, struct vis_info *info)
goto out; goto out;
packet = (struct vis_packet *)info->skb_packet->data; packet = (struct vis_packet *)info->skb_packet->data;
if (packet->ttl < 2) { if (packet->header.ttl < 2) {
pr_debug("Error - can't send vis packet: ttl exceeded\n"); pr_debug("Error - can't send vis packet: ttl exceeded\n");
goto out; goto out;
} }
memcpy(packet->sender_orig, primary_if->net_dev->dev_addr, ETH_ALEN); memcpy(packet->sender_orig, primary_if->net_dev->dev_addr, ETH_ALEN);
packet->ttl--; packet->header.ttl--;
if (is_broadcast_ether_addr(packet->target_orig)) if (is_broadcast_ether_addr(packet->target_orig))
broadcast_vis_packet(bat_priv, info); broadcast_vis_packet(bat_priv, info);
else else
unicast_vis_packet(bat_priv, info); unicast_vis_packet(bat_priv, info);
packet->ttl++; /* restore TTL */ packet->header.ttl++; /* restore TTL */
out: out:
if (primary_if) if (primary_if)
...@@ -910,9 +910,9 @@ int vis_init(struct bat_priv *bat_priv) ...@@ -910,9 +910,9 @@ int vis_init(struct bat_priv *bat_priv)
INIT_LIST_HEAD(&bat_priv->my_vis_info->send_list); INIT_LIST_HEAD(&bat_priv->my_vis_info->send_list);
kref_init(&bat_priv->my_vis_info->refcount); kref_init(&bat_priv->my_vis_info->refcount);
bat_priv->my_vis_info->bat_priv = bat_priv; bat_priv->my_vis_info->bat_priv = bat_priv;
packet->version = COMPAT_VERSION; packet->header.version = COMPAT_VERSION;
packet->packet_type = BAT_VIS; packet->header.packet_type = BAT_VIS;
packet->ttl = TTL; packet->header.ttl = TTL;
packet->seqno = 0; packet->seqno = 0;
packet->entries = 0; packet->entries = 0;
......
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