Commit e7017195 authored by Simon Wunderlich's avatar Simon Wunderlich Committed by Greg Kroah-Hartman

Staging: batman-adv: receive packets directly using skbs

This patch removes the (ugly and racy) packet receiving thread and the
kernel socket usage. Instead, packets are received directly by registering
the ethernet type and handling skbs instead of self-allocated buffers.

Some consequences and comments:

 * we don't copy the payload data when forwarding/sending/receiving data
   anymore. This should boost performance.
 * packets from/to different interfaces can be (theoretically) processed
   simultaneously. Only the big originator hash lock might be in the way.
 * no more polling or sleeping/wakeup/scheduling issues when receiving
   packets
 * this might introduce new race conditions.
 * aggregation and vis code still use packet buffers and are not (yet)
   converted.
 * all spinlocks were converted to irqsave/restore versions to solve
   some lifelock issues when preempted. This might be overkill, some
   of these locks might be reverted later.
 * skb copies are only done if neccesary to avoid overhead

performance differences:

 * we made some "benchmarks" with intel laptops.
 * bandwidth on Gigabit Ethernet increased from ~500 MBit/s to ~920 MBit/s
 * ping latency decresed from ~2ms to ~0.2 ms

I did some tests on my 9 node qemu environment and could confirm that
usual sending/receiving, forwarding, vis, batctl ping etc works.
Signed-off-by: default avatarSimon Wunderlich <siwu@hrz.tu-chemnitz.de>
Acked-by: default avatarSven Eckelmann <sven.eckelmann@gmx.de>
Acked-by: default avatarMarek Lindner <lindner_marek@yahoo.de>
Acked-by: default avatarLinus Lüssing <linus.luessing@web.de>
Signed-off-by: default avatarAndrew Lunn <andrew@lunn.ch>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent c4bf05d3
...@@ -96,6 +96,7 @@ static void new_aggregated_packet(unsigned char *packet_buff, ...@@ -96,6 +96,7 @@ static void new_aggregated_packet(unsigned char *packet_buff,
int own_packet) int own_packet)
{ {
struct forw_packet *forw_packet_aggr; struct forw_packet *forw_packet_aggr;
unsigned long flags;
forw_packet_aggr = kmalloc(sizeof(struct forw_packet), GFP_ATOMIC); forw_packet_aggr = kmalloc(sizeof(struct forw_packet), GFP_ATOMIC);
if (!forw_packet_aggr) if (!forw_packet_aggr)
...@@ -115,6 +116,7 @@ static void new_aggregated_packet(unsigned char *packet_buff, ...@@ -115,6 +116,7 @@ static void new_aggregated_packet(unsigned char *packet_buff,
packet_buff, packet_buff,
forw_packet_aggr->packet_len); forw_packet_aggr->packet_len);
forw_packet_aggr->skb = NULL;
forw_packet_aggr->own = own_packet; forw_packet_aggr->own = own_packet;
forw_packet_aggr->if_incoming = if_incoming; forw_packet_aggr->if_incoming = if_incoming;
forw_packet_aggr->num_packets = 0; forw_packet_aggr->num_packets = 0;
...@@ -126,9 +128,9 @@ static void new_aggregated_packet(unsigned char *packet_buff, ...@@ -126,9 +128,9 @@ static void new_aggregated_packet(unsigned char *packet_buff,
forw_packet_aggr->direct_link_flags |= 1; forw_packet_aggr->direct_link_flags |= 1;
/* add new packet to packet list */ /* add new packet to packet list */
spin_lock(&forw_bat_list_lock); spin_lock_irqsave(&forw_bat_list_lock, flags);
hlist_add_head(&forw_packet_aggr->list, &forw_bat_list); hlist_add_head(&forw_packet_aggr->list, &forw_bat_list);
spin_unlock(&forw_bat_list_lock); spin_unlock_irqrestore(&forw_bat_list_lock, flags);
/* start timer for this packet */ /* start timer for this packet */
INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work, INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work,
...@@ -168,9 +170,10 @@ void add_bat_packet_to_list(unsigned char *packet_buff, int packet_len, ...@@ -168,9 +170,10 @@ void add_bat_packet_to_list(unsigned char *packet_buff, int packet_len,
struct batman_packet *batman_packet = struct batman_packet *batman_packet =
(struct batman_packet *)packet_buff; (struct batman_packet *)packet_buff;
bool direct_link = batman_packet->flags & DIRECTLINK ? 1 : 0; bool direct_link = batman_packet->flags & DIRECTLINK ? 1 : 0;
unsigned long flags;
/* find position for the packet in the forward queue */ /* find position for the packet in the forward queue */
spin_lock(&forw_bat_list_lock); spin_lock_irqsave(&forw_bat_list_lock, flags);
/* own packets are not to be aggregated */ /* own packets are not to be aggregated */
if ((atomic_read(&aggregation_enabled)) && (!own_packet)) { if ((atomic_read(&aggregation_enabled)) && (!own_packet)) {
hlist_for_each_entry(forw_packet_pos, tmp_node, &forw_bat_list, hlist_for_each_entry(forw_packet_pos, tmp_node, &forw_bat_list,
...@@ -191,7 +194,7 @@ void add_bat_packet_to_list(unsigned char *packet_buff, int packet_len, ...@@ -191,7 +194,7 @@ void add_bat_packet_to_list(unsigned char *packet_buff, int packet_len,
* suitable aggregation packet found */ * suitable aggregation packet found */
if (forw_packet_aggr == NULL) { if (forw_packet_aggr == NULL) {
/* the following section can run without the lock */ /* the following section can run without the lock */
spin_unlock(&forw_bat_list_lock); spin_unlock_irqrestore(&forw_bat_list_lock, flags);
new_aggregated_packet(packet_buff, packet_len, new_aggregated_packet(packet_buff, packet_len,
send_time, direct_link, send_time, direct_link,
if_incoming, own_packet); if_incoming, own_packet);
...@@ -199,7 +202,7 @@ void add_bat_packet_to_list(unsigned char *packet_buff, int packet_len, ...@@ -199,7 +202,7 @@ void add_bat_packet_to_list(unsigned char *packet_buff, int packet_len,
aggregate(forw_packet_aggr, aggregate(forw_packet_aggr,
packet_buff, packet_len, packet_buff, packet_len,
direct_link); direct_link);
spin_unlock(&forw_bat_list_lock); spin_unlock_irqrestore(&forw_bat_list_lock, flags);
} }
} }
......
...@@ -133,8 +133,9 @@ int bat_device_release(struct inode *inode, struct file *file) ...@@ -133,8 +133,9 @@ int bat_device_release(struct inode *inode, struct file *file)
(struct device_client *)file->private_data; (struct device_client *)file->private_data;
struct device_packet *device_packet; struct device_packet *device_packet;
struct list_head *list_pos, *list_pos_tmp; struct list_head *list_pos, *list_pos_tmp;
unsigned long flags;
spin_lock(&device_client->lock); spin_lock_irqsave(&device_client->lock, flags);
/* for all packets in the queue ... */ /* for all packets in the queue ... */
list_for_each_safe(list_pos, list_pos_tmp, &device_client->queue_list) { list_for_each_safe(list_pos, list_pos_tmp, &device_client->queue_list) {
...@@ -146,7 +147,7 @@ int bat_device_release(struct inode *inode, struct file *file) ...@@ -146,7 +147,7 @@ int bat_device_release(struct inode *inode, struct file *file)
} }
device_client_hash[device_client->index] = NULL; device_client_hash[device_client->index] = NULL;
spin_unlock(&device_client->lock); spin_unlock_irqrestore(&device_client->lock, flags);
kfree(device_client); kfree(device_client);
dec_module_count(); dec_module_count();
...@@ -161,6 +162,7 @@ ssize_t bat_device_read(struct file *file, char __user *buf, size_t count, ...@@ -161,6 +162,7 @@ ssize_t bat_device_read(struct file *file, char __user *buf, size_t count,
(struct device_client *)file->private_data; (struct device_client *)file->private_data;
struct device_packet *device_packet; struct device_packet *device_packet;
int error; int error;
unsigned long flags;
if ((file->f_flags & O_NONBLOCK) && (device_client->queue_len == 0)) if ((file->f_flags & O_NONBLOCK) && (device_client->queue_len == 0))
return -EAGAIN; return -EAGAIN;
...@@ -177,14 +179,14 @@ ssize_t bat_device_read(struct file *file, char __user *buf, size_t count, ...@@ -177,14 +179,14 @@ ssize_t bat_device_read(struct file *file, char __user *buf, size_t count,
if (error) if (error)
return error; return error;
spin_lock(&device_client->lock); spin_lock_irqsave(&device_client->lock, flags);
device_packet = list_first_entry(&device_client->queue_list, device_packet = list_first_entry(&device_client->queue_list,
struct device_packet, list); struct device_packet, list);
list_del(&device_packet->list); list_del(&device_packet->list);
device_client->queue_len--; device_client->queue_len--;
spin_unlock(&device_client->lock); spin_unlock_irqrestore(&device_client->lock, flags);
error = __copy_to_user(buf, &device_packet->icmp_packet, error = __copy_to_user(buf, &device_packet->icmp_packet,
sizeof(struct icmp_packet)); sizeof(struct icmp_packet));
...@@ -205,6 +207,7 @@ ssize_t bat_device_write(struct file *file, const char __user *buff, ...@@ -205,6 +207,7 @@ ssize_t bat_device_write(struct file *file, const char __user *buff,
struct icmp_packet icmp_packet; struct icmp_packet icmp_packet;
struct orig_node *orig_node; struct orig_node *orig_node;
struct batman_if *batman_if; struct batman_if *batman_if;
unsigned long flags;
if (len < sizeof(struct icmp_packet)) { if (len < sizeof(struct icmp_packet)) {
bat_dbg(DBG_BATMAN, "batman-adv:Error - can't send packet from char device: invalid packet size\n"); bat_dbg(DBG_BATMAN, "batman-adv:Error - can't send packet from char device: invalid packet size\n");
...@@ -239,7 +242,7 @@ ssize_t bat_device_write(struct file *file, const char __user *buff, ...@@ -239,7 +242,7 @@ ssize_t bat_device_write(struct file *file, const char __user *buff,
if (atomic_read(&module_state) != MODULE_ACTIVE) if (atomic_read(&module_state) != MODULE_ACTIVE)
goto dst_unreach; goto dst_unreach;
spin_lock(&orig_hash_lock); spin_lock_irqsave(&orig_hash_lock, flags);
orig_node = ((struct orig_node *)hash_find(orig_hash, icmp_packet.dst)); orig_node = ((struct orig_node *)hash_find(orig_hash, icmp_packet.dst));
if (!orig_node) if (!orig_node)
...@@ -261,11 +264,11 @@ ssize_t bat_device_write(struct file *file, const char __user *buff, ...@@ -261,11 +264,11 @@ ssize_t bat_device_write(struct file *file, const char __user *buff,
sizeof(struct icmp_packet), sizeof(struct icmp_packet),
batman_if, orig_node->router->addr); batman_if, orig_node->router->addr);
spin_unlock(&orig_hash_lock); spin_unlock_irqrestore(&orig_hash_lock, flags);
goto out; goto out;
unlock: unlock:
spin_unlock(&orig_hash_lock); spin_unlock_irqrestore(&orig_hash_lock, flags);
dst_unreach: dst_unreach:
icmp_packet.msg_type = DESTINATION_UNREACHABLE; icmp_packet.msg_type = DESTINATION_UNREACHABLE;
bat_device_add_packet(device_client, &icmp_packet); bat_device_add_packet(device_client, &icmp_packet);
...@@ -290,6 +293,7 @@ void bat_device_add_packet(struct device_client *device_client, ...@@ -290,6 +293,7 @@ void bat_device_add_packet(struct device_client *device_client,
struct icmp_packet *icmp_packet) struct icmp_packet *icmp_packet)
{ {
struct device_packet *device_packet; struct device_packet *device_packet;
unsigned long flags;
device_packet = kmalloc(sizeof(struct device_packet), GFP_KERNEL); device_packet = kmalloc(sizeof(struct device_packet), GFP_KERNEL);
...@@ -300,12 +304,12 @@ void bat_device_add_packet(struct device_client *device_client, ...@@ -300,12 +304,12 @@ void bat_device_add_packet(struct device_client *device_client,
memcpy(&device_packet->icmp_packet, icmp_packet, memcpy(&device_packet->icmp_packet, icmp_packet,
sizeof(struct icmp_packet)); sizeof(struct icmp_packet));
spin_lock(&device_client->lock); spin_lock_irqsave(&device_client->lock, flags);
/* while waiting for the lock the device_client could have been /* while waiting for the lock the device_client could have been
* deleted */ * deleted */
if (!device_client_hash[icmp_packet->uid]) { if (!device_client_hash[icmp_packet->uid]) {
spin_unlock(&device_client->lock); spin_unlock_irqrestore(&device_client->lock, flags);
kfree(device_packet); kfree(device_packet);
return; return;
} }
...@@ -322,7 +326,7 @@ void bat_device_add_packet(struct device_client *device_client, ...@@ -322,7 +326,7 @@ void bat_device_add_packet(struct device_client *device_client,
device_client->queue_len--; device_client->queue_len--;
} }
spin_unlock(&device_client->lock); spin_unlock_irqrestore(&device_client->lock, flags);
wake_up(&device_client->queue_wait); wake_up(&device_client->queue_wait);
} }
......
...@@ -153,9 +153,6 @@ void hardif_deactivate_interface(struct batman_if *batman_if) ...@@ -153,9 +153,6 @@ void hardif_deactivate_interface(struct batman_if *batman_if)
if (batman_if->if_active != IF_ACTIVE) if (batman_if->if_active != IF_ACTIVE)
return; return;
if (batman_if->raw_sock)
sock_release(batman_if->raw_sock);
/** /**
* batman_if->net_dev has been acquired by dev_get_by_name() in * batman_if->net_dev has been acquired by dev_get_by_name() in
* proc_interfaces_write() and has to be unreferenced. * proc_interfaces_write() and has to be unreferenced.
...@@ -164,9 +161,6 @@ void hardif_deactivate_interface(struct batman_if *batman_if) ...@@ -164,9 +161,6 @@ void hardif_deactivate_interface(struct batman_if *batman_if)
if (batman_if->net_dev) if (batman_if->net_dev)
dev_put(batman_if->net_dev); dev_put(batman_if->net_dev);
batman_if->raw_sock = NULL;
batman_if->net_dev = NULL;
batman_if->if_active = IF_INACTIVE; batman_if->if_active = IF_INACTIVE;
active_ifs--; active_ifs--;
...@@ -177,9 +171,6 @@ void hardif_deactivate_interface(struct batman_if *batman_if) ...@@ -177,9 +171,6 @@ void hardif_deactivate_interface(struct batman_if *batman_if)
/* (re)activate given interface. */ /* (re)activate given interface. */
static void hardif_activate_interface(struct batman_if *batman_if) static void hardif_activate_interface(struct batman_if *batman_if)
{ {
struct sockaddr_ll bind_addr;
int retval;
if (batman_if->if_active != IF_INACTIVE) if (batman_if->if_active != IF_INACTIVE)
return; return;
...@@ -191,35 +182,8 @@ static void hardif_activate_interface(struct batman_if *batman_if) ...@@ -191,35 +182,8 @@ static void hardif_activate_interface(struct batman_if *batman_if)
if (!batman_if->net_dev) if (!batman_if->net_dev)
goto dev_err; goto dev_err;
retval = sock_create_kern(PF_PACKET, SOCK_RAW,
__constant_htons(ETH_P_BATMAN),
&batman_if->raw_sock);
if (retval < 0) {
printk(KERN_ERR "batman-adv:Can't create raw socket: %i\n",
retval);
goto sock_err;
}
bind_addr.sll_family = AF_PACKET;
bind_addr.sll_ifindex = batman_if->net_dev->ifindex;
bind_addr.sll_protocol = 0; /* is set by the kernel */
retval = kernel_bind(batman_if->raw_sock,
(struct sockaddr *)&bind_addr, sizeof(bind_addr));
if (retval < 0) {
printk(KERN_ERR "batman-adv:Can't create bind raw socket: %i\n",
retval);
goto bind_err;
}
check_known_mac_addr(batman_if->net_dev->dev_addr); check_known_mac_addr(batman_if->net_dev->dev_addr);
batman_if->raw_sock->sk->sk_user_data =
batman_if->raw_sock->sk->sk_data_ready;
batman_if->raw_sock->sk->sk_data_ready = batman_data_ready;
addr_to_string(batman_if->addr_str, batman_if->net_dev->dev_addr); addr_to_string(batman_if->addr_str, batman_if->net_dev->dev_addr);
memcpy(((struct batman_packet *)(batman_if->packet_buff))->orig, memcpy(((struct batman_packet *)(batman_if->packet_buff))->orig,
...@@ -239,12 +203,7 @@ static void hardif_activate_interface(struct batman_if *batman_if) ...@@ -239,12 +203,7 @@ static void hardif_activate_interface(struct batman_if *batman_if)
return; return;
bind_err:
sock_release(batman_if->raw_sock);
sock_err:
dev_put(batman_if->net_dev);
dev_err: dev_err:
batman_if->raw_sock = NULL;
batman_if->net_dev = NULL; batman_if->net_dev = NULL;
} }
...@@ -318,6 +277,7 @@ int hardif_add_interface(char *dev, int if_num) ...@@ -318,6 +277,7 @@ int hardif_add_interface(char *dev, int if_num)
struct batman_if *batman_if; struct batman_if *batman_if;
struct batman_packet *batman_packet; struct batman_packet *batman_packet;
struct orig_node *orig_node; struct orig_node *orig_node;
unsigned long flags;
HASHIT(hashit); HASHIT(hashit);
batman_if = kmalloc(sizeof(struct batman_if), GFP_KERNEL); batman_if = kmalloc(sizeof(struct batman_if), GFP_KERNEL);
...@@ -327,7 +287,6 @@ int hardif_add_interface(char *dev, int if_num) ...@@ -327,7 +287,6 @@ int hardif_add_interface(char *dev, int if_num)
return -1; return -1;
} }
batman_if->raw_sock = NULL;
batman_if->net_dev = NULL; batman_if->net_dev = NULL;
if ((if_num == 0) && (num_hna > 0)) if ((if_num == 0) && (num_hna > 0))
...@@ -375,17 +334,17 @@ int hardif_add_interface(char *dev, int if_num) ...@@ -375,17 +334,17 @@ int hardif_add_interface(char *dev, int if_num)
/* resize all orig nodes because orig_node->bcast_own(_sum) depend on /* resize all orig nodes because orig_node->bcast_own(_sum) depend on
* if_num */ * if_num */
spin_lock(&orig_hash_lock); spin_lock_irqsave(&orig_hash_lock, flags);
while (hash_iterate(orig_hash, &hashit)) { while (hash_iterate(orig_hash, &hashit)) {
orig_node = hashit.bucket->data; orig_node = hashit.bucket->data;
if (resize_orig(orig_node, if_num) == -1) { if (resize_orig(orig_node, if_num) == -1) {
spin_unlock(&orig_hash_lock); spin_unlock_irqrestore(&orig_hash_lock, flags);
goto out; goto out;
} }
} }
spin_unlock(&orig_hash_lock); spin_unlock_irqrestore(&orig_hash_lock, flags);
if (!hardif_is_interface_up(batman_if->dev)) if (!hardif_is_interface_up(batman_if->dev))
printk(KERN_ERR "batman-adv:Not using interface %s (retrying later): interface not active\n", batman_if->dev); printk(KERN_ERR "batman-adv:Not using interface %s (retrying later): interface not active\n", batman_if->dev);
...@@ -443,6 +402,111 @@ static int hard_if_event(struct notifier_block *this, ...@@ -443,6 +402,111 @@ static int hard_if_event(struct notifier_block *this,
return NOTIFY_DONE; return NOTIFY_DONE;
} }
/* find batman interface by netdev. assumes rcu_read_lock on */
static struct batman_if *find_batman_if(struct net_device *dev)
{
struct batman_if *batman_if;
rcu_read_lock();
list_for_each_entry_rcu(batman_if, &if_list, list) {
if (batman_if->net_dev == dev) {
rcu_read_unlock();
return batman_if;
}
}
rcu_read_unlock();
return NULL;
}
/* receive a packet with the batman ethertype coming on a hard
* interface */
int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *ptype, struct net_device *orig_dev)
{
struct batman_packet *batman_packet;
struct batman_if *batman_if;
struct net_device_stats *stats;
int ret;
skb = skb_share_check(skb, GFP_ATOMIC);
if (skb == NULL)
goto err_free;
/* packet should hold at least type and version */
if (unlikely(skb_headlen(skb) < 2))
goto err_free;
/* expect a valid ethernet header here. */
if (unlikely(skb->mac_len != sizeof(struct ethhdr)
|| !skb_mac_header(skb)))
goto err_free;
batman_if = find_batman_if(skb->dev);
if (!batman_if)
goto err_free;
stats = &skb->dev->stats;
stats->rx_packets++;
stats->rx_bytes += skb->len;
batman_packet = (struct batman_packet *)skb->data;
if (batman_packet->version != COMPAT_VERSION) {
bat_dbg(DBG_BATMAN,
"Drop packet: incompatible batman version (%i)\n",
batman_packet->version);
goto err_free;
}
/* all receive handlers return whether they received or reused
* the supplied skb. if not, we have to free the skb. */
switch (batman_packet->packet_type) {
/* batman originator packet */
case BAT_PACKET:
ret = recv_bat_packet(skb, batman_if);
break;
/* batman icmp packet */
case BAT_ICMP:
ret = recv_icmp_packet(skb);
break;
/* unicast packet */
case BAT_UNICAST:
ret = recv_unicast_packet(skb);
break;
/* broadcast packet */
case BAT_BCAST:
ret = recv_bcast_packet(skb);
break;
/* vis packet */
case BAT_VIS:
ret = recv_vis_packet(skb);
break;
default:
ret = NET_RX_DROP;
}
if (ret == NET_RX_DROP)
kfree_skb(skb);
/* return NET_RX_SUCCESS in any case as we
* most probably dropped the packet for
* routing-logical reasons. */
return NET_RX_SUCCESS;
err_free:
kfree_skb(skb);
return NET_RX_DROP;
}
struct notifier_block hard_if_notifier = { struct notifier_block hard_if_notifier = {
.notifier_call = hard_if_event, .notifier_call = hard_if_event,
}; };
...@@ -32,5 +32,9 @@ void hardif_deactivate_interface(struct batman_if *batman_if); ...@@ -32,5 +32,9 @@ void hardif_deactivate_interface(struct batman_if *batman_if);
char hardif_get_active_if_num(void); char hardif_get_active_if_num(void);
void hardif_check_interfaces_status(void); void hardif_check_interfaces_status(void);
void hardif_check_interfaces_status_wq(struct work_struct *work); void hardif_check_interfaces_status_wq(struct work_struct *work);
int batman_skb_recv(struct sk_buff *skb,
struct net_device *dev,
struct packet_type *ptype,
struct net_device *orig_dev);
int hardif_min_mtu(void); int hardif_min_mtu(void);
void update_min_mtu(void); void update_min_mtu(void);
...@@ -50,11 +50,14 @@ int16_t num_ifs; ...@@ -50,11 +50,14 @@ int16_t num_ifs;
struct net_device *soft_device; struct net_device *soft_device;
static struct task_struct *kthread_task;
unsigned char broadcastAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; unsigned char broadcastAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
atomic_t module_state; atomic_t module_state;
static struct packet_type batman_adv_packet_type __read_mostly = {
.type = cpu_to_be16(ETH_P_BATMAN),
.func = batman_skb_recv,
};
struct workqueue_struct *bat_event_workqueue; struct workqueue_struct *bat_event_workqueue;
#ifdef CONFIG_BATMAN_ADV_DEBUG #ifdef CONFIG_BATMAN_ADV_DEBUG
...@@ -113,6 +116,7 @@ int init_module(void) ...@@ -113,6 +116,7 @@ int init_module(void)
} }
register_netdevice_notifier(&hard_if_notifier); register_netdevice_notifier(&hard_if_notifier);
dev_add_pack(&batman_adv_packet_type);
printk(KERN_INFO "batman-adv:B.A.T.M.A.N. advanced %s%s (compatibility version %i) loaded \n", printk(KERN_INFO "batman-adv:B.A.T.M.A.N. advanced %s%s (compatibility version %i) loaded \n",
SOURCE_VERSION, REVISION_VERSION_STR, COMPAT_VERSION); SOURCE_VERSION, REVISION_VERSION_STR, COMPAT_VERSION);
...@@ -135,6 +139,8 @@ void cleanup_module(void) ...@@ -135,6 +139,8 @@ void cleanup_module(void)
soft_device = NULL; soft_device = NULL;
} }
dev_remove_pack(&batman_adv_packet_type);
unregister_netdevice_notifier(&hard_if_notifier); unregister_netdevice_notifier(&hard_if_notifier);
cleanup_procfs(); cleanup_procfs();
...@@ -162,16 +168,6 @@ void activate_module(void) ...@@ -162,16 +168,6 @@ void activate_module(void)
if (vis_init() < 1) if (vis_init() < 1)
goto err; goto err;
/* (re)start kernel thread for packet processing */
if (!kthread_task) {
kthread_task = kthread_run(packet_recv_thread, NULL, "batman-adv");
if (IS_ERR(kthread_task)) {
printk(KERN_ERR "batman-adv:Unable to start packet receive thread\n");
kthread_task = NULL;
}
}
update_min_mtu(); update_min_mtu();
atomic_set(&module_state, MODULE_ACTIVE); atomic_set(&module_state, MODULE_ACTIVE);
goto end; goto end;
...@@ -193,14 +189,7 @@ void shutdown_module(void) ...@@ -193,14 +189,7 @@ void shutdown_module(void)
vis_quit(); vis_quit();
/* deactivate kernel thread for packet processing (if running) */ /* TODO: unregister BATMAN pack */
if (kthread_task) {
atomic_set(&exit_cond, 1);
wake_up_interruptible(&thread_wait);
kthread_stop(kthread_task);
kthread_task = NULL;
}
originator_free(); originator_free();
......
...@@ -37,35 +37,38 @@ static void start_purge_timer(void) ...@@ -37,35 +37,38 @@ static void start_purge_timer(void)
int originator_init(void) int originator_init(void)
{ {
unsigned long flags;
if (orig_hash) if (orig_hash)
return 1; return 1;
spin_lock(&orig_hash_lock); spin_lock_irqsave(&orig_hash_lock, flags);
orig_hash = hash_new(128, compare_orig, choose_orig); orig_hash = hash_new(128, compare_orig, choose_orig);
if (!orig_hash) if (!orig_hash)
goto err; goto err;
spin_unlock(&orig_hash_lock); spin_unlock_irqrestore(&orig_hash_lock, flags);
start_purge_timer(); start_purge_timer();
return 1; return 1;
err: err:
spin_unlock(&orig_hash_lock); spin_unlock_irqrestore(&orig_hash_lock, flags);
return 0; return 0;
} }
void originator_free(void) void originator_free(void)
{ {
unsigned long flags;
if (!orig_hash) if (!orig_hash)
return; return;
cancel_delayed_work_sync(&purge_orig_wq); cancel_delayed_work_sync(&purge_orig_wq);
spin_lock(&orig_hash_lock); spin_lock_irqsave(&orig_hash_lock, flags);
hash_delete(orig_hash, free_orig_node); hash_delete(orig_hash, free_orig_node);
orig_hash = NULL; orig_hash = NULL;
spin_unlock(&orig_hash_lock); spin_unlock_irqrestore(&orig_hash_lock, flags);
} }
struct neigh_node * struct neigh_node *
...@@ -243,8 +246,9 @@ void purge_orig(struct work_struct *work) ...@@ -243,8 +246,9 @@ void purge_orig(struct work_struct *work)
{ {
HASHIT(hashit); HASHIT(hashit);
struct orig_node *orig_node; struct orig_node *orig_node;
unsigned long flags;
spin_lock(&orig_hash_lock); spin_lock_irqsave(&orig_hash_lock, flags);
/* for all origins... */ /* for all origins... */
while (hash_iterate(orig_hash, &hashit)) { while (hash_iterate(orig_hash, &hashit)) {
...@@ -255,7 +259,7 @@ void purge_orig(struct work_struct *work) ...@@ -255,7 +259,7 @@ void purge_orig(struct work_struct *work)
} }
} }
spin_unlock(&orig_hash_lock); spin_unlock_irqrestore(&orig_hash_lock, flags);
start_purge_timer(); start_purge_timer();
} }
......
...@@ -189,6 +189,7 @@ static int proc_originators_read(struct seq_file *seq, void *offset) ...@@ -189,6 +189,7 @@ static int proc_originators_read(struct seq_file *seq, void *offset)
struct neigh_node *neigh_node; struct neigh_node *neigh_node;
int batman_count = 0; int batman_count = 0;
char orig_str[ETH_STR_LEN], router_str[ETH_STR_LEN]; char orig_str[ETH_STR_LEN], router_str[ETH_STR_LEN];
unsigned long flags;
rcu_read_lock(); rcu_read_lock();
if (list_empty(&if_list)) { if (list_empty(&if_list)) {
...@@ -211,7 +212,7 @@ static int proc_originators_read(struct seq_file *seq, void *offset) ...@@ -211,7 +212,7 @@ static int proc_originators_read(struct seq_file *seq, void *offset)
((struct batman_if *)if_list.next)->addr_str); ((struct batman_if *)if_list.next)->addr_str);
rcu_read_unlock(); rcu_read_unlock();
spin_lock(&orig_hash_lock); spin_lock_irqsave(&orig_hash_lock, flags);
while (hash_iterate(orig_hash, &hashit)) { while (hash_iterate(orig_hash, &hashit)) {
...@@ -242,7 +243,7 @@ static int proc_originators_read(struct seq_file *seq, void *offset) ...@@ -242,7 +243,7 @@ static int proc_originators_read(struct seq_file *seq, void *offset)
} }
spin_unlock(&orig_hash_lock); spin_unlock_irqrestore(&orig_hash_lock, flags);
if (batman_count == 0) if (batman_count == 0)
seq_printf(seq, "No batman nodes in range ... \n"); seq_printf(seq, "No batman nodes in range ... \n");
...@@ -376,6 +377,7 @@ static int proc_vis_data_read(struct seq_file *seq, void *offset) ...@@ -376,6 +377,7 @@ static int proc_vis_data_read(struct seq_file *seq, void *offset)
HLIST_HEAD(vis_if_list); HLIST_HEAD(vis_if_list);
int i; int i;
char tmp_addr_str[ETH_STR_LEN]; char tmp_addr_str[ETH_STR_LEN];
unsigned long flags;
rcu_read_lock(); rcu_read_lock();
if (list_empty(&if_list) || (!is_vis_server())) { if (list_empty(&if_list) || (!is_vis_server())) {
...@@ -385,7 +387,7 @@ static int proc_vis_data_read(struct seq_file *seq, void *offset) ...@@ -385,7 +387,7 @@ static int proc_vis_data_read(struct seq_file *seq, void *offset)
rcu_read_unlock(); rcu_read_unlock();
spin_lock(&vis_hash_lock); spin_lock_irqsave(&vis_hash_lock, flags);
while (hash_iterate(vis_hash, &hashit)) { while (hash_iterate(vis_hash, &hashit)) {
info = hashit.bucket->data; info = hashit.bucket->data;
entries = (struct vis_info_entry *) entries = (struct vis_info_entry *)
...@@ -402,7 +404,7 @@ static int proc_vis_data_read(struct seq_file *seq, void *offset) ...@@ -402,7 +404,7 @@ static int proc_vis_data_read(struct seq_file *seq, void *offset)
proc_vis_read_prim_sec(seq, &vis_if_list); proc_vis_read_prim_sec(seq, &vis_if_list);
seq_printf(seq, "\n"); seq_printf(seq, "\n");
} }
spin_unlock(&vis_hash_lock); spin_unlock_irqrestore(&vis_hash_lock, flags);
end: end:
return 0; return 0;
......
This diff is collapsed.
...@@ -25,8 +25,6 @@ extern wait_queue_head_t thread_wait; ...@@ -25,8 +25,6 @@ extern wait_queue_head_t thread_wait;
extern atomic_t exit_cond; extern atomic_t exit_cond;
void slide_own_bcast_window(struct batman_if *batman_if); void slide_own_bcast_window(struct batman_if *batman_if);
void batman_data_ready(struct sock *sk, int len);
int packet_recv_thread(void *data);
void receive_bat_packet(struct ethhdr *ethhdr, void receive_bat_packet(struct ethhdr *ethhdr,
struct batman_packet *batman_packet, struct batman_packet *batman_packet,
unsigned char *hna_buff, int hna_buff_len, unsigned char *hna_buff, int hna_buff_len,
...@@ -34,3 +32,9 @@ void receive_bat_packet(struct ethhdr *ethhdr, ...@@ -34,3 +32,9 @@ void receive_bat_packet(struct ethhdr *ethhdr,
void update_routes(struct orig_node *orig_node, void update_routes(struct orig_node *orig_node,
struct neigh_node *neigh_node, struct neigh_node *neigh_node,
unsigned char *hna_buff, int hna_buff_len); unsigned char *hna_buff, int hna_buff_len);
int recv_icmp_packet(struct sk_buff *skb);
int recv_unicast_packet(struct sk_buff *skb);
int recv_bcast_packet(struct sk_buff *skb);
int recv_vis_packet(struct sk_buff *skb);
int recv_bat_packet(struct sk_buff *skb,
struct batman_if *batman_if);
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "send.h" #include "send.h"
#include "routing.h" #include "routing.h"
#include "translation-table.h" #include "translation-table.h"
#include "soft-interface.h"
#include "hard-interface.h" #include "hard-interface.h"
#include "types.h" #include "types.h"
#include "vis.h" #include "vis.h"
...@@ -58,51 +59,69 @@ static unsigned long forward_send_time(void) ...@@ -58,51 +59,69 @@ static unsigned long forward_send_time(void)
return send_time; return send_time;
} }
/* sends a raw packet. */ /* send out an already prepared packet to the given address via the
void send_raw_packet(unsigned char *pack_buff, int pack_buff_len, * specified batman interface */
struct batman_if *batman_if, uint8_t *dst_addr) int send_skb_packet(struct sk_buff *skb,
struct batman_if *batman_if,
uint8_t *dst_addr)
{ {
struct ethhdr *ethhdr; struct ethhdr *ethhdr;
struct sk_buff *skb;
int retval;
char *data;
if (batman_if->if_active != IF_ACTIVE) if (batman_if->if_active != IF_ACTIVE)
return; goto send_skb_err;
if (unlikely(!batman_if->net_dev))
goto send_skb_err;
if (!(batman_if->net_dev->flags & IFF_UP)) { if (!(batman_if->net_dev->flags & IFF_UP)) {
printk(KERN_WARNING printk(KERN_WARNING
"batman-adv:Interface %s is not up - can't send packet via that interface!\n", "batman-adv:Interface %s is not up - can't send packet via that interface!\n",
batman_if->dev); batman_if->dev);
return; goto send_skb_err;
} }
skb = dev_alloc_skb(pack_buff_len + sizeof(struct ethhdr)); /* push to the ethernet header. */
if (!skb) if (my_skb_push(skb, sizeof(struct ethhdr)) < 0)
return; goto send_skb_err;
data = skb_put(skb, pack_buff_len + sizeof(struct ethhdr));
memcpy(data + sizeof(struct ethhdr), pack_buff, pack_buff_len); skb_reset_mac_header(skb);
ethhdr = (struct ethhdr *) data; ethhdr = (struct ethhdr *) skb_mac_header(skb);
memcpy(ethhdr->h_source, batman_if->net_dev->dev_addr, ETH_ALEN); memcpy(ethhdr->h_source, batman_if->net_dev->dev_addr, ETH_ALEN);
memcpy(ethhdr->h_dest, dst_addr, ETH_ALEN); memcpy(ethhdr->h_dest, dst_addr, ETH_ALEN);
ethhdr->h_proto = __constant_htons(ETH_P_BATMAN); ethhdr->h_proto = __constant_htons(ETH_P_BATMAN);
skb_reset_mac_header(skb);
skb_set_network_header(skb, ETH_HLEN); skb_set_network_header(skb, ETH_HLEN);
skb->priority = TC_PRIO_CONTROL; skb->priority = TC_PRIO_CONTROL;
skb->protocol = __constant_htons(ETH_P_BATMAN); skb->protocol = __constant_htons(ETH_P_BATMAN);
skb->dev = batman_if->net_dev; skb->dev = batman_if->net_dev;
/* dev_queue_xmit() returns a negative result on error. However on /* dev_queue_xmit() returns a negative result on error. However on
* congestion and traffic shaping, it drops and returns NET_XMIT_DROP * congestion and traffic shaping, it drops and returns NET_XMIT_DROP
* (which is > 0). This will not be treated as an error. */ * (which is > 0). This will not be treated as an error. */
retval = dev_queue_xmit(skb);
if (retval < 0) return dev_queue_xmit(skb);
printk(KERN_WARNING send_skb_err:
"batman-adv:Can't write to raw socket: %i\n", kfree_skb(skb);
retval); return NET_XMIT_DROP;
}
/* sends a raw packet. */
void send_raw_packet(unsigned char *pack_buff, int pack_buff_len,
struct batman_if *batman_if, uint8_t *dst_addr)
{
struct sk_buff *skb;
char *data;
skb = dev_alloc_skb(pack_buff_len + sizeof(struct ethhdr));
if (!skb)
return;
data = skb_put(skb, pack_buff_len + sizeof(struct ethhdr));
memcpy(data + sizeof(struct ethhdr), pack_buff, pack_buff_len);
/* pull back to the batman "network header" */
skb_pull(skb, sizeof(struct ethhdr));
send_skb_packet(skb, batman_if, dst_addr);
} }
/* Send a packet to a given interface */ /* Send a packet to a given interface */
...@@ -331,6 +350,8 @@ void schedule_forward_packet(struct orig_node *orig_node, ...@@ -331,6 +350,8 @@ void schedule_forward_packet(struct orig_node *orig_node,
static void forw_packet_free(struct forw_packet *forw_packet) static void forw_packet_free(struct forw_packet *forw_packet)
{ {
if (forw_packet->skb)
kfree_skb(forw_packet->skb);
kfree(forw_packet->packet_buff); kfree(forw_packet->packet_buff);
kfree(forw_packet); kfree(forw_packet);
} }
...@@ -353,7 +374,7 @@ static void _add_bcast_packet_to_list(struct forw_packet *forw_packet, ...@@ -353,7 +374,7 @@ static void _add_bcast_packet_to_list(struct forw_packet *forw_packet,
send_time); send_time);
} }
void add_bcast_packet_to_list(unsigned char *packet_buff, int packet_len) void add_bcast_packet_to_list(struct sk_buff *skb)
{ {
struct forw_packet *forw_packet; struct forw_packet *forw_packet;
...@@ -361,14 +382,16 @@ void add_bcast_packet_to_list(unsigned char *packet_buff, int packet_len) ...@@ -361,14 +382,16 @@ void add_bcast_packet_to_list(unsigned char *packet_buff, int packet_len)
if (!forw_packet) if (!forw_packet)
return; return;
forw_packet->packet_buff = kmalloc(packet_len, GFP_ATOMIC); skb = skb_copy(skb, GFP_ATOMIC);
if (!forw_packet->packet_buff) { if (!skb) {
kfree(forw_packet); kfree(forw_packet);
return; return;
} }
forw_packet->packet_len = packet_len; skb_reset_mac_header(skb);
memcpy(forw_packet->packet_buff, packet_buff, forw_packet->packet_len);
forw_packet->skb = skb;
forw_packet->packet_buff = NULL;
/* how often did we send the bcast packet ? */ /* how often did we send the bcast packet ? */
forw_packet->num_packets = 0; forw_packet->num_packets = 0;
...@@ -384,6 +407,7 @@ void send_outstanding_bcast_packet(struct work_struct *work) ...@@ -384,6 +407,7 @@ void send_outstanding_bcast_packet(struct work_struct *work)
struct forw_packet *forw_packet = struct forw_packet *forw_packet =
container_of(delayed_work, struct forw_packet, delayed_work); container_of(delayed_work, struct forw_packet, delayed_work);
unsigned long flags; unsigned long flags;
struct sk_buff *skb1;
spin_lock_irqsave(&forw_bcast_list_lock, flags); spin_lock_irqsave(&forw_bcast_list_lock, flags);
hlist_del(&forw_packet->list); hlist_del(&forw_packet->list);
...@@ -392,8 +416,10 @@ void send_outstanding_bcast_packet(struct work_struct *work) ...@@ -392,8 +416,10 @@ void send_outstanding_bcast_packet(struct work_struct *work)
/* rebroadcast packet */ /* rebroadcast packet */
rcu_read_lock(); rcu_read_lock();
list_for_each_entry_rcu(batman_if, &if_list, list) { list_for_each_entry_rcu(batman_if, &if_list, list) {
send_raw_packet(forw_packet->packet_buff, /* send a copy of the saved skb */
forw_packet->packet_len, skb1 = skb_copy(forw_packet->skb, GFP_ATOMIC);
if (skb1)
send_skb_packet(skb1,
batman_if, broadcastAddr); batman_if, broadcastAddr);
} }
rcu_read_unlock(); rcu_read_unlock();
...@@ -415,10 +441,11 @@ void send_outstanding_bat_packet(struct work_struct *work) ...@@ -415,10 +441,11 @@ void send_outstanding_bat_packet(struct work_struct *work)
container_of(work, struct delayed_work, work); container_of(work, struct delayed_work, work);
struct forw_packet *forw_packet = struct forw_packet *forw_packet =
container_of(delayed_work, struct forw_packet, delayed_work); container_of(delayed_work, struct forw_packet, delayed_work);
unsigned long flags;
spin_lock(&forw_bat_list_lock); spin_lock_irqsave(&forw_bat_list_lock, flags);
hlist_del(&forw_packet->list); hlist_del(&forw_packet->list);
spin_unlock(&forw_bat_list_lock); spin_unlock_irqrestore(&forw_bat_list_lock, flags);
send_packet(forw_packet); send_packet(forw_packet);
...@@ -459,18 +486,18 @@ void purge_outstanding_packets(void) ...@@ -459,18 +486,18 @@ void purge_outstanding_packets(void)
spin_unlock_irqrestore(&forw_bcast_list_lock, flags); spin_unlock_irqrestore(&forw_bcast_list_lock, flags);
/* free batman packet list */ /* free batman packet list */
spin_lock(&forw_bat_list_lock); spin_lock_irqsave(&forw_bat_list_lock, flags);
hlist_for_each_entry_safe(forw_packet, tmp_node, safe_tmp_node, hlist_for_each_entry_safe(forw_packet, tmp_node, safe_tmp_node,
&forw_bat_list, list) { &forw_bat_list, list) {
spin_unlock(&forw_bat_list_lock); spin_unlock_irqrestore(&forw_bat_list_lock, flags);
/** /**
* send_outstanding_bat_packet() will lock the list to * send_outstanding_bat_packet() will lock the list to
* delete the item from the list * delete the item from the list
*/ */
cancel_delayed_work_sync(&forw_packet->delayed_work); cancel_delayed_work_sync(&forw_packet->delayed_work);
spin_lock(&forw_bat_list_lock); spin_lock_irqsave(&forw_bat_list_lock, flags);
} }
spin_unlock(&forw_bat_list_lock); spin_unlock_irqrestore(&forw_bat_list_lock, flags);
} }
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
#include "types.h" #include "types.h"
void send_own_packet_work(struct work_struct *work); void send_own_packet_work(struct work_struct *work);
int send_skb_packet(struct sk_buff *skb,
struct batman_if *batman_if,
uint8_t *dst_addr);
void send_raw_packet(unsigned char *pack_buff, int pack_buff_len, void send_raw_packet(unsigned char *pack_buff, int pack_buff_len,
struct batman_if *batman_if, uint8_t *dst_addr); struct batman_if *batman_if, uint8_t *dst_addr);
void schedule_own_packet(struct batman_if *batman_if); void schedule_own_packet(struct batman_if *batman_if);
...@@ -30,7 +33,7 @@ void schedule_forward_packet(struct orig_node *orig_node, ...@@ -30,7 +33,7 @@ void schedule_forward_packet(struct orig_node *orig_node,
struct batman_packet *batman_packet, struct batman_packet *batman_packet,
uint8_t directlink, int hna_buff_len, uint8_t directlink, int hna_buff_len,
struct batman_if *if_outgoing); struct batman_if *if_outgoing);
void add_bcast_packet_to_list(unsigned char *packet_buff, int packet_len); void add_bcast_packet_to_list(struct sk_buff *skb);
void send_outstanding_bcast_packet(struct work_struct *work); void send_outstanding_bcast_packet(struct work_struct *work);
void send_outstanding_bat_packet(struct work_struct *work); void send_outstanding_bat_packet(struct work_struct *work);
void purge_outstanding_packets(void); void purge_outstanding_packets(void);
...@@ -34,7 +34,6 @@ static uint16_t bcast_seqno = 1; /* give own bcast messages seq numbers to avoid ...@@ -34,7 +34,6 @@ static uint16_t bcast_seqno = 1; /* give own bcast messages seq numbers to avoid
* broadcast storms */ * broadcast storms */
static int32_t skb_packets; static int32_t skb_packets;
static int32_t skb_bad_packets; static int32_t skb_bad_packets;
static int32_t lock_dropped;
unsigned char mainIfAddr[ETH_ALEN]; unsigned char mainIfAddr[ETH_ALEN];
static unsigned char mainIfAddr_default[ETH_ALEN]; static unsigned char mainIfAddr_default[ETH_ALEN];
...@@ -67,12 +66,12 @@ int main_if_was_up(void) ...@@ -67,12 +66,12 @@ int main_if_was_up(void)
return (memcmp(mainIfAddr, mainIfAddr_default, ETH_ALEN) != 0 ? 1 : 0); return (memcmp(mainIfAddr, mainIfAddr_default, ETH_ALEN) != 0 ? 1 : 0);
} }
static int my_skb_push(struct sk_buff *skb, unsigned int len) int my_skb_push(struct sk_buff *skb, unsigned int len)
{ {
int result = 0; int result = 0;
skb_packets++; skb_packets++;
if (skb->data - len < skb->head) { if (skb_headroom(skb) < len) {
skb_bad_packets++; skb_bad_packets++;
result = pskb_expand_head(skb, len, 0, GFP_ATOMIC); result = pskb_expand_head(skb, len, 0, GFP_ATOMIC);
...@@ -169,7 +168,10 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev) ...@@ -169,7 +168,10 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev)
struct orig_node *orig_node; struct orig_node *orig_node;
struct ethhdr *ethhdr = (struct ethhdr *)skb->data; struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
struct bat_priv *priv = netdev_priv(dev); struct bat_priv *priv = netdev_priv(dev);
struct batman_if *batman_if;
uint8_t dstaddr[6];
int data_len = skb->len; int data_len = skb->len;
unsigned long flags;
if (atomic_read(&module_state) != MODULE_ACTIVE) if (atomic_read(&module_state) != MODULE_ACTIVE)
goto dropped; goto dropped;
...@@ -185,7 +187,6 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev) ...@@ -185,7 +187,6 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev)
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->version = COMPAT_VERSION;
/* batman packet type: broadcast */ /* batman packet type: broadcast */
...@@ -194,27 +195,21 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev) ...@@ -194,27 +195,21 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev)
/* 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 */
memcpy(bcast_packet->orig, mainIfAddr, ETH_ALEN); memcpy(bcast_packet->orig, mainIfAddr, ETH_ALEN);
/* set broadcast sequence number */ /* set broadcast sequence number */
bcast_packet->seqno = htons(bcast_seqno); bcast_packet->seqno = htons(bcast_seqno);
bcast_seqno++; bcast_seqno++;
/* broadcast packet */ /* broadcast packet */
add_bcast_packet_to_list(skb->data, skb->len); add_bcast_packet_to_list(skb);
/* a copy is stored in the bcast list, therefore removing
* the original skb. */
kfree_skb(skb);
/* unicast packet */ /* unicast packet */
} else { } else {
spin_lock_irqsave(&orig_hash_lock, flags);
/* simply spin_lock()ing can deadlock when the lock is already
* hold. */
/* TODO: defer the work in a working queue instead of
* dropping */
if (!spin_trylock(&orig_hash_lock)) {
lock_dropped++;
printk(KERN_WARNING "batman-adv:%d packets dropped because lock was hold\n", lock_dropped);
goto dropped;
}
/* get routing information */ /* get routing information */
orig_node = ((struct orig_node *)hash_find(orig_hash, orig_node = ((struct orig_node *)hash_find(orig_hash,
ethhdr->h_dest)); ethhdr->h_dest));
...@@ -243,14 +238,17 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev) ...@@ -243,14 +238,17 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev)
if (orig_node->batman_if->if_active != IF_ACTIVE) if (orig_node->batman_if->if_active != IF_ACTIVE)
goto unlock; goto unlock;
send_raw_packet(skb->data, skb->len, /* don't lock while sending the packets ... we therefore
orig_node->batman_if, * copy the required data before sending */
orig_node->router->addr);
batman_if = orig_node->batman_if;
memcpy(dstaddr, orig_node->router->addr, ETH_ALEN);
spin_unlock_irqrestore(&orig_hash_lock, flags);
send_skb_packet(skb, batman_if, dstaddr);
} else { } else {
goto unlock; goto unlock;
} }
spin_unlock(&orig_hash_lock);
} }
priv->stats.tx_packets++; priv->stats.tx_packets++;
...@@ -258,42 +256,44 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev) ...@@ -258,42 +256,44 @@ int interface_tx(struct sk_buff *skb, struct net_device *dev)
goto end; goto end;
unlock: unlock:
spin_unlock(&orig_hash_lock); spin_unlock_irqrestore(&orig_hash_lock, flags);
dropped: dropped:
priv->stats.tx_dropped++; priv->stats.tx_dropped++;
end: end:
kfree_skb(skb);
return 0; return 0;
} }
void interface_rx(struct net_device *dev, void *packet, int packet_len) void interface_rx(struct sk_buff *skb, int hdr_size)
{ {
struct sk_buff *skb; struct net_device *dev = soft_device;
struct bat_priv *priv = netdev_priv(dev); struct bat_priv *priv = netdev_priv(dev);
skb = dev_alloc_skb(packet_len); /* check if enough space is available for pulling, and pull */
if (!pskb_may_pull(skb, hdr_size)) {
if (!skb) { kfree_skb(skb);
priv->stats.rx_dropped++; return;
goto out;
} }
skb_pull_rcsum(skb, hdr_size);
/* skb_set_mac_header(skb, -sizeof(struct ethhdr));*/
memcpy(skb_put(skb, packet_len), packet, packet_len);
/* Write metadata, and then pass to the receive level */
skb->dev = dev; skb->dev = dev;
skb->protocol = eth_type_trans(skb, dev); skb->protocol = eth_type_trans(skb, dev);
skb->ip_summed = CHECKSUM_UNNECESSARY;
/* should not be neccesary anymore as we use skb_pull_rcsum()
* TODO: please verify this and remove this TODO
* -- Dec 21st 2009, Simon Wunderlich */
/* skb->ip_summed = CHECKSUM_UNNECESSARY;*/
/* TODO: set skb->pkt_type to PACKET_BROADCAST, PACKET_MULTICAST,
* PACKET_OTHERHOST or PACKET_HOST */
priv->stats.rx_packets++; priv->stats.rx_packets++;
priv->stats.rx_bytes += packet_len; priv->stats.rx_bytes += skb->len;
dev->last_rx = jiffies; dev->last_rx = jiffies;
netif_rx(skb); netif_rx(skb);
out:
return;
} }
/* ethtool */ /* ethtool */
......
...@@ -28,6 +28,7 @@ struct net_device_stats *interface_stats(struct net_device *dev); ...@@ -28,6 +28,7 @@ struct net_device_stats *interface_stats(struct net_device *dev);
int interface_set_mac_addr(struct net_device *dev, void *addr); int interface_set_mac_addr(struct net_device *dev, void *addr);
int interface_change_mtu(struct net_device *dev, int new_mtu); int interface_change_mtu(struct net_device *dev, int new_mtu);
int interface_tx(struct sk_buff *skb, struct net_device *dev); int interface_tx(struct sk_buff *skb, struct net_device *dev);
void interface_rx(struct net_device *dev, void *packet, int packet_len); void interface_rx(struct sk_buff *skb, int hdr_size);
int my_skb_push(struct sk_buff *skb, unsigned int len);
extern unsigned char mainIfAddr[]; extern unsigned char mainIfAddr[];
...@@ -39,7 +39,6 @@ struct batman_if { ...@@ -39,7 +39,6 @@ struct batman_if {
char if_active; char if_active;
char addr_str[ETH_STR_LEN]; char addr_str[ETH_STR_LEN];
struct net_device *net_dev; struct net_device *net_dev;
struct socket *raw_sock;
atomic_t seqno; atomic_t seqno;
unsigned char *packet_buff; unsigned char *packet_buff;
int packet_len; int packet_len;
...@@ -113,6 +112,7 @@ struct forw_packet { /* structure for forw_list maintaining packet ...@@ -113,6 +112,7 @@ struct forw_packet { /* structure for forw_list maintaining packet
struct hlist_node list; struct hlist_node list;
unsigned long send_time; unsigned long send_time;
uint8_t own; uint8_t own;
struct sk_buff *skb;
unsigned char *packet_buff; unsigned char *packet_buff;
uint16_t packet_len; uint16_t packet_len;
uint32_t direct_link_flags; uint32_t direct_link_flags;
......
...@@ -52,12 +52,13 @@ static void free_info(void *data) ...@@ -52,12 +52,13 @@ static void free_info(void *data)
/* set the mode of the visualization to client or server */ /* set the mode of the visualization to client or server */
void vis_set_mode(int mode) void vis_set_mode(int mode)
{ {
spin_lock(&vis_hash_lock); unsigned long flags;
spin_lock_irqsave(&vis_hash_lock, flags);
if (my_vis_info != NULL) if (my_vis_info != NULL)
my_vis_info->packet.vis_type = mode; my_vis_info->packet.vis_type = mode;
spin_unlock(&vis_hash_lock); spin_unlock_irqrestore(&vis_hash_lock, flags);
} }
/* is_vis_server(), locked outside */ /* is_vis_server(), locked outside */
...@@ -74,10 +75,11 @@ static int is_vis_server_locked(void) ...@@ -74,10 +75,11 @@ static int is_vis_server_locked(void)
int is_vis_server(void) int is_vis_server(void)
{ {
int ret = 0; int ret = 0;
unsigned long flags;
spin_lock(&vis_hash_lock); spin_lock_irqsave(&vis_hash_lock, flags);
ret = is_vis_server_locked(); ret = is_vis_server_locked();
spin_unlock(&vis_hash_lock); spin_unlock_irqrestore(&vis_hash_lock, flags);
return ret; return ret;
} }
...@@ -269,8 +271,9 @@ void receive_server_sync_packet(struct vis_packet *vis_packet, int vis_info_len) ...@@ -269,8 +271,9 @@ void receive_server_sync_packet(struct vis_packet *vis_packet, int vis_info_len)
{ {
struct vis_info *info; struct vis_info *info;
int is_new; int is_new;
unsigned long flags;
spin_lock(&vis_hash_lock); spin_lock_irqsave(&vis_hash_lock, flags);
info = add_packet(vis_packet, vis_info_len, &is_new); info = add_packet(vis_packet, vis_info_len, &is_new);
if (info == NULL) if (info == NULL)
goto end; goto end;
...@@ -283,7 +286,7 @@ void receive_server_sync_packet(struct vis_packet *vis_packet, int vis_info_len) ...@@ -283,7 +286,7 @@ void receive_server_sync_packet(struct vis_packet *vis_packet, int vis_info_len)
list_add_tail(&info->send_list, &send_list); list_add_tail(&info->send_list, &send_list);
} }
end: end:
spin_unlock(&vis_hash_lock); spin_unlock_irqrestore(&vis_hash_lock, flags);
} }
/* handle an incoming client update packet and schedule forward if needed. */ /* handle an incoming client update packet and schedule forward if needed. */
...@@ -292,12 +295,13 @@ void receive_client_update_packet(struct vis_packet *vis_packet, ...@@ -292,12 +295,13 @@ void receive_client_update_packet(struct vis_packet *vis_packet,
{ {
struct vis_info *info; struct vis_info *info;
int is_new; int is_new;
unsigned long flags;
/* clients shall not broadcast. */ /* clients shall not broadcast. */
if (is_bcast(vis_packet->target_orig)) if (is_bcast(vis_packet->target_orig))
return; return;
spin_lock(&vis_hash_lock); spin_lock_irqsave(&vis_hash_lock, flags);
info = add_packet(vis_packet, vis_info_len, &is_new); info = add_packet(vis_packet, vis_info_len, &is_new);
if (info == NULL) if (info == NULL)
goto end; goto end;
...@@ -319,7 +323,7 @@ void receive_client_update_packet(struct vis_packet *vis_packet, ...@@ -319,7 +323,7 @@ void receive_client_update_packet(struct vis_packet *vis_packet,
list_add_tail(&info->send_list, &send_list); list_add_tail(&info->send_list, &send_list);
} }
end: end:
spin_unlock(&vis_hash_lock); spin_unlock_irqrestore(&vis_hash_lock, flags);
} }
/* Walk the originators and find the VIS server with the best tq. Set the packet /* Walk the originators and find the VIS server with the best tq. Set the packet
...@@ -370,7 +374,7 @@ static int generate_vis_packet(void) ...@@ -370,7 +374,7 @@ static int generate_vis_packet(void)
info->first_seen = jiffies; info->first_seen = jiffies;
spin_lock(&orig_hash_lock); spin_lock_irqsave(&orig_hash_lock, flags);
memcpy(info->packet.target_orig, broadcastAddr, ETH_ALEN); memcpy(info->packet.target_orig, broadcastAddr, ETH_ALEN);
info->packet.ttl = TTL; info->packet.ttl = TTL;
info->packet.seqno++; info->packet.seqno++;
...@@ -379,7 +383,7 @@ static int generate_vis_packet(void) ...@@ -379,7 +383,7 @@ static int generate_vis_packet(void)
if (!is_vis_server_locked()) { if (!is_vis_server_locked()) {
best_tq = find_best_vis_server(info); best_tq = find_best_vis_server(info);
if (best_tq < 0) { if (best_tq < 0) {
spin_unlock(&orig_hash_lock); spin_unlock_irqrestore(&orig_hash_lock, flags);
return -1; return -1;
} }
} }
...@@ -403,13 +407,13 @@ static int generate_vis_packet(void) ...@@ -403,13 +407,13 @@ static int generate_vis_packet(void)
info->packet.entries++; info->packet.entries++;
if (vis_packet_full(info)) { if (vis_packet_full(info)) {
spin_unlock(&orig_hash_lock); spin_unlock_irqrestore(&orig_hash_lock, flags);
return 0; return 0;
} }
} }
} }
spin_unlock(&orig_hash_lock); spin_unlock_irqrestore(&orig_hash_lock, flags);
spin_lock_irqsave(&hna_local_hash_lock, flags); spin_lock_irqsave(&hna_local_hash_lock, flags);
while (hash_iterate(hna_local_hash, &hashit_local)) { while (hash_iterate(hna_local_hash, &hashit_local)) {
...@@ -450,8 +454,9 @@ static void broadcast_vis_packet(struct vis_info *info, int packet_length) ...@@ -450,8 +454,9 @@ static void broadcast_vis_packet(struct vis_info *info, int packet_length)
{ {
HASHIT(hashit); HASHIT(hashit);
struct orig_node *orig_node; struct orig_node *orig_node;
unsigned long flags;
spin_lock(&orig_hash_lock); spin_lock_irqsave(&orig_hash_lock, flags);
/* send to all routers in range. */ /* send to all routers in range. */
while (hash_iterate(orig_hash, &hashit)) { while (hash_iterate(orig_hash, &hashit)) {
...@@ -478,14 +483,15 @@ static void broadcast_vis_packet(struct vis_info *info, int packet_length) ...@@ -478,14 +483,15 @@ static void broadcast_vis_packet(struct vis_info *info, int packet_length)
} }
} }
memcpy(info->packet.target_orig, broadcastAddr, ETH_ALEN); memcpy(info->packet.target_orig, broadcastAddr, ETH_ALEN);
spin_unlock(&orig_hash_lock); spin_unlock_irqrestore(&orig_hash_lock, flags);
} }
static void unicast_vis_packet(struct vis_info *info, int packet_length) static void unicast_vis_packet(struct vis_info *info, int packet_length)
{ {
struct orig_node *orig_node; struct orig_node *orig_node;
unsigned long flags;
spin_lock(&orig_hash_lock); spin_lock_irqsave(&orig_hash_lock, flags);
orig_node = ((struct orig_node *) orig_node = ((struct orig_node *)
hash_find(orig_hash, info->packet.target_orig)); hash_find(orig_hash, info->packet.target_orig));
...@@ -496,7 +502,7 @@ static void unicast_vis_packet(struct vis_info *info, int packet_length) ...@@ -496,7 +502,7 @@ static void unicast_vis_packet(struct vis_info *info, int packet_length)
orig_node->batman_if, orig_node->batman_if,
orig_node->router->addr); orig_node->router->addr);
} }
spin_unlock(&orig_hash_lock); spin_unlock_irqrestore(&orig_hash_lock, flags);
} }
/* only send one vis packet. called from send_vis_packets() */ /* only send one vis packet. called from send_vis_packets() */
...@@ -526,8 +532,9 @@ static void send_vis_packet(struct vis_info *info) ...@@ -526,8 +532,9 @@ static void send_vis_packet(struct vis_info *info)
static void send_vis_packets(struct work_struct *work) static void send_vis_packets(struct work_struct *work)
{ {
struct vis_info *info, *temp; struct vis_info *info, *temp;
unsigned long flags;
spin_lock(&vis_hash_lock); spin_lock_irqsave(&vis_hash_lock, flags);
purge_vis_packets(); purge_vis_packets();
if (generate_vis_packet() == 0) if (generate_vis_packet() == 0)
...@@ -538,7 +545,7 @@ static void send_vis_packets(struct work_struct *work) ...@@ -538,7 +545,7 @@ static void send_vis_packets(struct work_struct *work)
list_del_init(&info->send_list); list_del_init(&info->send_list);
send_vis_packet(info); send_vis_packet(info);
} }
spin_unlock(&vis_hash_lock); spin_unlock_irqrestore(&vis_hash_lock, flags);
start_vis_timer(); start_vis_timer();
} }
static DECLARE_DELAYED_WORK(vis_timer_wq, send_vis_packets); static DECLARE_DELAYED_WORK(vis_timer_wq, send_vis_packets);
...@@ -547,10 +554,11 @@ static DECLARE_DELAYED_WORK(vis_timer_wq, send_vis_packets); ...@@ -547,10 +554,11 @@ static DECLARE_DELAYED_WORK(vis_timer_wq, send_vis_packets);
* initialized (e.g. bat0 is initialized, interfaces have been added) */ * initialized (e.g. bat0 is initialized, interfaces have been added) */
int vis_init(void) int vis_init(void)
{ {
unsigned long flags;
if (vis_hash) if (vis_hash)
return 1; return 1;
spin_lock(&vis_hash_lock); spin_lock_irqsave(&vis_hash_lock, flags);
vis_hash = hash_new(256, vis_info_cmp, vis_info_choose); vis_hash = hash_new(256, vis_info_cmp, vis_info_choose);
if (!vis_hash) { if (!vis_hash) {
...@@ -588,12 +596,12 @@ int vis_init(void) ...@@ -588,12 +596,12 @@ int vis_init(void)
goto err; goto err;
} }
spin_unlock(&vis_hash_lock); spin_unlock_irqrestore(&vis_hash_lock, flags);
start_vis_timer(); start_vis_timer();
return 1; return 1;
err: err:
spin_unlock(&vis_hash_lock); spin_unlock_irqrestore(&vis_hash_lock, flags);
vis_quit(); vis_quit();
return 0; return 0;
} }
...@@ -601,17 +609,18 @@ int vis_init(void) ...@@ -601,17 +609,18 @@ int vis_init(void)
/* shutdown vis-server */ /* shutdown vis-server */
void vis_quit(void) void vis_quit(void)
{ {
unsigned long flags;
if (!vis_hash) if (!vis_hash)
return; return;
cancel_delayed_work_sync(&vis_timer_wq); cancel_delayed_work_sync(&vis_timer_wq);
spin_lock(&vis_hash_lock); spin_lock_irqsave(&vis_hash_lock, flags);
/* properly remove, kill timers ... */ /* properly remove, kill timers ... */
hash_delete(vis_hash, free_info); hash_delete(vis_hash, free_info);
vis_hash = NULL; vis_hash = NULL;
my_vis_info = NULL; my_vis_info = NULL;
spin_unlock(&vis_hash_lock); spin_unlock_irqrestore(&vis_hash_lock, flags);
} }
/* schedule packets for (re)transmission */ /* schedule packets for (re)transmission */
......
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