Staging: batman-adv: depend on NET instead of PACKET in Kconfig
PATCH 1/8 Staging: batman-adv: depend on NET instead of PACKET in Kconfig
From: Sven Eckelmann <[email protected]>
The code which uses the raw packet sockets was removed. The only related dependencies are the skb and netdev handling code. This is provided by NET in Kconfig.
--- drivers/staging/batman-adv/Kconfig | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/staging/batman-adv/Kconfig +1 -1
@@ -4,7 +4,7 @@ config BATMAN_ADV tristate "B.A.T.M.A.N. Advanced Meshing Protocol" - depends on PROC_FS && PACKET + depends on PROC_FS && NET default n ---help---
Signature · 1 line
1.6.6.2
PATCH 2/8 Staging: batman-adv: don't lock while sending packets
From: Simon Wunderlich <[email protected]>
As in other parts of batman-adv, we should not lock while sending a packet but keep the lock held for as short as possible. Additionally, we should check whether the interface is active, otherwise batman_if->net_dev might not be available ...
--- drivers/staging/batman-adv/device.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-)
drivers/staging/batman-adv/device.c +10 -3
@@ -25,6 +25,7 @@#include "send.h" #include "types.h" #include "hash.h" +#include "hard-interface.h" static struct class *batman_class;
@@ -206,6 +207,7 @@ ssize_t bat_device_write(struct file *file, const char __user *buff,struct icmp_packet icmp_packet;struct orig_node *orig_node;struct batman_if *batman_if; +uint8_t dstaddr[ETH_ALEN ];unsigned long flags;if (len <sizeof (struct icmp_packet )) {
@@ -251,9 +253,15 @@ ssize_t bat_device_write(struct file *file, const char __user *buff, goto unlock; batman_if = orig_node->batman_if; +memcpy (dstaddr, orig_node->router->addr,ETH_ALEN ); + +spin_unlock_irqrestore (&orig_hash_lock, flags);if (!batman_if) - goto unlock; + goto dst_unreach; + +if (batman_if->if_active !=IF_ACTIVE ) + goto dst_unreach; memcpy(icmp_packet.orig, batman_if->net_dev->dev_addr,
@@ -261,9 +269,8 @@ ssize_t bat_device_write(struct file *file, const char __user *buff,send_raw_packet ((unsigned char *)&icmp_packet,sizeof (struct icmp_packet ), - batman_if, orig_node->router->addr); + batman_if, dstaddr); -spin_unlock_irqrestore (&orig_hash_lock, flags); goto out; unlock:
Signature · 1 line
1.6.6.2
PATCH 3/8 Staging: batman-adv: avoid having the same error message more than once
From: Marek Lindner <[email protected]>
The routing code has 2 sections which warn about ttl exceeded. The corresponding warnings were identical which makes it hard to debug. In addition, batman-adv does not need to warn about ttl exceeded in case we encountered an echo request as this is commonly used to generate traceroute graphs.
--- drivers/staging/batman-adv/routing.c | 14 ++++++++------ 1 files changed, 8 insertions(+), 6 deletions(-)
drivers/staging/batman-adv/routing.c +8 -6
@@ -655,14 +655,15 @@ static int recv_icmp_ttl_exceeded(struct sk_buff *skb)unsigned long flags;uint8_t dstaddr[ETH_ALEN ]; - icmp_packet = (struct icmp_packet *) skb->data; - ethhdr = (struct ethhdr *)skb_mac_header (skb); - -printk (KERN_WARNING "batman-adv:Warning - can't send packet from %pM to %pM: ttl exceeded\n" , icmp_packet->orig, icmp_packet->dst); + icmp_packet = (struct icmp_packet *)skb->data; + ethhdr = (struct ethhdr *)skb_mac_header (skb);/* send TTL exceeded if packet is an echo request (traceroute) */ -if (icmp_packet->msg_type !=ECHO_REQUEST ) +if (icmp_packet->msg_type !=ECHO_REQUEST ) { +printk (KERN_WARNING "batman-adv:Warning - can't forward icmp packet from %pM to %pM: ttl exceeded\n" , + icmp_packet->orig, icmp_packet->dst);return NET_RX_DROP ; + }/* get routing information */ spin_lock_irqsave (&orig_hash_lock, flags);
@@ -825,7 +826,8 @@ int recv_unicast_packet(struct sk_buff *skb)/* TTL exceeded */ if (unicast_packet->ttl <2 ) { -printk (KERN_WARNING "batman-adv:Warning - can't send packet from %pM to %pM: ttl exceeded\n" , ethhdr->h_source, unicast_packet->dest); +printk (KERN_WARNING "batman-adv:Warning - can't forward unicast packet from %pM to %pM: ttl exceeded\n" , + ethhdr->h_source, unicast_packet->dest);return NET_RX_DROP ; }
Signature · 1 line
1.6.6.2
PATCH 4/8 Staging: batman-adv: remove obsolete variables
From: Marek Lindner <[email protected]>
This patch removes a variable that became obsolete since the skb handling replaced the packet handling thread.
--- drivers/staging/batman-adv/routing.c | 2 -- drivers/staging/batman-adv/routing.h | 1 - 2 files changed, 0 insertions(+), 3 deletions(-)
drivers/staging/batman-adv/routing.c +0 -2
@@ -35,8 +35,6 @@DECLARE_WAIT_QUEUE_HEAD (thread_wait); -atomic_t exit_cond; -void slide_own_bcast_window (struct batman_if *batman_if) {HASHIT (hashit);
drivers/staging/batman-adv/routing.h +0 -1
@@ -22,7 +22,6 @@#include "types.h" extern wait_queue_head_t thread_wait; -extern atomic_t exit_cond;void slide_own_bcast_window (struct batman_if *batman_if); void receive_bat_packet(struct ethhdr *ethhdr,
Signature · 1 line
1.6.6.2
PATCH 5/8 Staging: batman-adv: atomic variable for vis-srv activation
From: Linus Luessing <[email protected]>
This fixes the bug discovered by Marek Lindner which did not allow turning on the vis-server before an interface has been added. With this patch we are using a global atomic variable for activating and deactiating the vis-server-mode, which can be used before inserting an interface.
--- drivers/staging/batman-adv/main.c | 2 + drivers/staging/batman-adv/main.h | 1 + drivers/staging/batman-adv/proc.c | 15 +++++------ drivers/staging/batman-adv/send.c | 3 +- drivers/staging/batman-adv/vis.c | 46 +++++-------------------------------- drivers/staging/batman-adv/vis.h | 2 - 6 files changed, 18 insertions(+), 51 deletions(-)
drivers/staging/batman-adv/main.c +2 -0
@@ -43,6 +43,7 @@ DEFINE_SPINLOCK(forw_bcast_list_lock);atomic_t originator_interval;atomic_t vis_interval; +atomic_t vis_mode;atomic_t aggregation_enabled;int16_t num_hna;int16_t num_ifs;
@@ -83,6 +84,7 @@ int init_module(void)atomic_set (&originator_interval,1000 );atomic_set (&vis_interval,1000 );/* TODO: raise this later, this is only * for debugging now. */ +atomic_set (&vis_mode,VIS_TYPE_CLIENT_UPDATE );atomic_set (&aggregation_enabled,1 );/* the name should not be longer than 10 chars - see
drivers/staging/batman-adv/main.h +1 -0
@@ -130,6 +130,7 @@ extern spinlock_t forw_bcast_list_lock;extern atomic_t originator_interval;extern atomic_t vis_interval; +extern atomic_t vis_mode;extern atomic_t aggregation_enabled;extern int16_t num_hna;extern int16_t num_ifs;
drivers/staging/batman-adv/proc.c +7 -8
@@ -338,11 +338,11 @@ static ssize_t proc_vis_srv_write(struct file *file, const char __user * buffer,if ((strcmp (vis_mode_string,"client" ) ==0 ) || (strcmp (vis_mode_string,"disabled" ) ==0 )) {printk (KERN_INFO "batman-adv:Setting VIS mode to client (disabling vis server)\n" ); -vis_set_mode (VIS_TYPE_CLIENT_UPDATE ); +atomic_set (&vis_mode,VIS_TYPE_CLIENT_UPDATE ); }else if ((strcmp (vis_mode_string,"server" ) ==0 ) || (strcmp (vis_mode_string,"enabled" ) ==0 )) {printk (KERN_INFO "batman-adv:Setting VIS mode to server (enabling vis server)\n" ); -vis_set_mode (VIS_TYPE_SERVER_SYNC ); +atomic_set (&vis_mode,VIS_TYPE_SERVER_SYNC ); }else printk (KERN_ERR "batman-adv:Unknown VIS mode: %s\n" , vis_mode_string);
@@ -353,12 +353,12 @@ static ssize_t proc_vis_srv_write(struct file *file, const char __user * buffer,static int proc_vis_srv_read (struct seq_file *seq,void *offset) { -int vis_server =is_vis_server (); +int vis_server =atomic_read (&vis_mode);seq_printf (seq,"[%c] client mode (server disabled) \n" , - (!vis_server) ?'x' :' ' ); + (vis_server ==VIS_TYPE_CLIENT_UPDATE ) ?'x' :' ' );seq_printf (seq,"[%c] server mode (server enabled) \n" , - (vis_server) ?'x' :' ' ); + (vis_server ==VIS_TYPE_SERVER_SYNC ) ?'x' :' ' );return 0 ; }
@@ -377,9 +377,10 @@ static int proc_vis_data_read(struct seq_file *seq, void *offset)int i;char tmp_addr_str[ETH_STR_LEN ];unsigned long flags; +int vis_server =atomic_read (&vis_mode);rcu_read_lock (); -if (list_empty (&if_list) || (!is_vis_server ())) { +if (list_empty (&if_list) || (vis_server ==VIS_TYPE_CLIENT_UPDATE )) {rcu_read_unlock (); goto end; }
@@ -672,5 +673,3 @@ int setup_procfs(void)return 0 ; } - -
drivers/staging/batman-adv/send.c +2 -1
@@ -248,6 +248,7 @@ void schedule_own_packet(struct batman_if *batman_if) {unsigned long send_time;struct batman_packet *batman_packet; +int vis_server =atomic_read (&vis_mode);/** * the interface gets activated here to avoid race conditions between
@@ -272,7 +273,7 @@ void schedule_own_packet(struct batman_if *batman_if)/* change sequence number to network order */ batman_packet->seqno =htons ((uint16_t )atomic_read (&batman_if->seqno)); -if (is_vis_server ()) +if (vis_server ==VIS_TYPE_SERVER_SYNC ) batman_packet->flags =VIS_SERVER ;else batman_packet->flags =0 ;
drivers/staging/batman-adv/vis.c +6 -40
97 lines not on this page · raw message
drivers/staging/batman-adv/vis.h +0 -2
@@ -48,8 +48,6 @@ struct recvlist_node {extern struct hashtable_t *vis_hash;extern spinlock_t vis_hash_lock; -void vis_set_mode (int mode); -int is_vis_server (void ); void proc_vis_read_entry(struct seq_file *seq, struct vis_info_entry *entry, struct hlist_head *if_list,
Signature · 1 line
1.6.6.2
PATCH 6/8 Staging: batman-adv: Fix skbuff leak in VIS code.
The vis code takes a copy of the data inside the skbuf if it is interesting for us, so we always need to release the skbuf.
--- drivers/staging/batman-adv/routing.c | 9 ++++----- 1 files changed, 4 insertions(+), 5 deletions(-)
drivers/staging/batman-adv/routing.c +4 -5
@@ -939,7 +939,6 @@ int recv_vis_packet(struct sk_buff *skb)struct vis_packet *vis_packet;struct ethhdr *ethhdr;int hdr_size =sizeof (struct vis_packet ); -int ret;if (skb_headlen (skb) < hdr_size)return NET_RX_DROP ;
@@ -962,18 +961,18 @@ int recv_vis_packet(struct sk_buff *skb)case VIS_TYPE_SERVER_SYNC :/* TODO: handle fragmented skbs properly */ receive_server_sync_packet (vis_packet,skb_headlen (skb)); - ret =NET_RX_SUCCESS ;break ;case VIS_TYPE_CLIENT_UPDATE :/* TODO: handle fragmented skbs properly */ receive_client_update_packet (vis_packet,skb_headlen (skb)); - ret =NET_RX_SUCCESS ;break ;default :/* ignore unknown packet */ - ret =NET_RX_DROP ;break ; } -return ret; + +/* We take a copy of the data in the packet, so we should +always free the skbuf. */ +return NET_RX_DROP ; }
Signature · 1 line
1.6.6.2
PATCH 7/8 Staging: batman-adv: avoid crash on memory allocation error
From: Marek Lindner <[email protected]>
skb_share_check() returns NULL if it can't allocate more memory but it still frees the skbuff.
--- drivers/staging/batman-adv/hard-interface.c | 16 +++++++++------- 1 files changed, 9 insertions(+), 7 deletions(-)
drivers/staging/batman-adv/hard-interface.c +9 -7
@@ -426,10 +426,11 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,struct net_device_stats *stats;int ret; - skb =skb_share_check (skb,GFP_ATOMIC ); + skb =skb_share_check (skb,GFP_ATOMIC ); -if (skb ==NULL ) - goto err_free; +/* skb was released by skb_share_check() */ +if (!skb) + goto err_out;/* packet should hold at least type and version */ if (unlikely (skb_headlen (skb) <2 ))
@@ -444,7 +445,7 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,if (!batman_if) goto err_free; - stats = (struct net_device_stats *)dev_get_stats (skb->dev); + stats = (struct net_device_stats *)dev_get_stats (skb->dev);if (stats) { stats->rx_packets++; stats->rx_bytes += skb->len;
@@ -490,6 +491,7 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,default : ret =NET_RX_DROP ; } +if (ret ==NET_RX_DROP )kfree_skb (skb);
@@ -500,9 +502,9 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,return NET_RX_SUCCESS ; err_free: -kfree_skb (skb); -return NET_RX_DROP ; - +kfree_skb (skb); +err_out: +return NET_RX_DROP ; }
Signature · 1 line
1.6.6.2
PATCH 8/8 Staging: batman-adv: fix module initialization
From: Marek Lindner <[email protected]>
Make sure that batman-adv does not process packets before its initialization is complete. Some sanity checks added to the receiver function.
--- drivers/staging/batman-adv/hard-interface.c | 7 +++++++ drivers/staging/batman-adv/proc.c | 17 ++++++----------- 2 files changed, 13 insertions(+), 11 deletions(-)
drivers/staging/batman-adv/hard-interface.c +7 -0
@@ -432,6 +432,9 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,if (!skb) goto err_out; +if (atomic_read (&module_state) !=MODULE_ACTIVE ) + goto err_free; +/* packet should hold at least type and version */ if (unlikely (skb_headlen (skb) <2 )) goto err_free;
@@ -445,6 +448,10 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,if (!batman_if) goto err_free; +/* discard frames on not active interfaces */ +if (batman_if->if_active !=IF_ACTIVE ) + goto err_free; + stats = (struct net_device_stats *)dev_get_stats (skb->dev);if (stats) { stats->rx_packets++;
drivers/staging/batman-adv/proc.c +6 -11
@@ -63,7 +63,7 @@ static ssize_t proc_interfaces_write(struct file *instance, size_t count, loff_t *data) { char *if_string, *colon_ptr = NULL, *cr_ptr = NULL; -int not_copied =0 , if_num =0 ; +int not_copied =0 , if_num =0 , add_success;struct batman_if *batman_if =NULL ; if_string =kmalloc (count,GFP_KERNEL );
@@ -109,22 +109,17 @@ static ssize_t proc_interfaces_write(struct file *instance, }rcu_read_unlock (); -hardif_add_interface (if_string, if_num); + add_success =hardif_add_interface (if_string, if_num); +if (add_success <0 ) + goto end; + + num_ifs = if_num +1 ;if ((atomic_read (&module_state) ==MODULE_INACTIVE ) && (hardif_get_active_if_num () >0 ))activate_module (); -rcu_read_lock (); -if (list_empty (&if_list)) { -rcu_read_unlock (); - goto end; - } -rcu_read_unlock (); - - num_ifs = if_num +1 ;return count; - end:kfree (if_string);return count;
Signature · 1 line
1.6.6.2