batman-adv gateway handling
Hi,
the batman-adv gateway functionality has been available in the trunk for quite some time but was never able to enter an official release because the sysfs API did not follow the Linux kernel guidelines.
I wrote a series of patches meant to address these style issues. A comprehensive documentation of the gateway handling is on my todo list and will follow shortly.
Regards,
Marek
PATCH 1/8 batman-adv: remove redundant gw_node_list_free() function
--- batman-adv/gateway_client.c | 30 +++++++++--------------------- batman-adv/gateway_client.h | 3 +-- batman-adv/main.c | 2 +- batman-adv/originator.c | 2 +- 4 files changed, 12 insertions(+), 25 deletions(-)
batman-adv/gateway_client.c +9 -21
@@ -306,7 +306,7 @@ void gw_node_delete(struct bat_priv *bat_priv, struct orig_node *orig_node)return gw_node_update (bat_priv, orig_node,0 ); } -void gw_node_purge_deleted (struct bat_priv *bat_priv) +void gw_node_purge (struct bat_priv *bat_priv) {struct gw_node *gw_node;struct hlist_node *node, *node_tmp;
@@ -315,32 +315,20 @@ void gw_node_purge_deleted(struct bat_priv *bat_priv)spin_lock_bh (&bat_priv->gw_list_lock);hlist_for_each_entry_safe (gw_node, node, node_tmp, - &bat_priv->gw_list, list) { -if ((gw_node->deleted) && - (time_after (jiffies, gw_node->deleted + timeout))) { - -hlist_del_rcu (&gw_node->list); -call_rcu (&gw_node->rcu, gw_node_free_rcu); - } - } - -spin_unlock_bh (&bat_priv->gw_list_lock); -} - -void gw_node_list_free (struct bat_priv *bat_priv) -{ -struct gw_node *gw_node; -struct hlist_node *node, *node_tmp; + &bat_priv->gw_list, list) { +if (((!gw_node->deleted) || + (time_after (jiffies, gw_node->deleted + timeout))) && +atomic_read (&bat_priv->mesh_state) ==MESH_ACTIVE ) +continue ; -spin_lock_bh (&bat_priv->gw_list_lock); +if (bat_priv->curr_gw == gw_node) +gw_deselect (bat_priv); -hlist_for_each_entry_safe (gw_node, node, node_tmp, - &bat_priv->gw_list, list) {hlist_del_rcu (&gw_node->list);call_rcu (&gw_node->rcu, gw_node_free_rcu); } -gw_deselect (bat_priv); +spin_unlock_bh (&bat_priv->gw_list_lock); }
batman-adv/gateway_client.h +1 -2
@@ -29,8 +29,7 @@ void gw_check_election(struct bat_priv *bat_priv, struct orig_node *orig_node);void gw_node_update (struct bat_priv *bat_priv,struct orig_node *orig_node,uint8_t new_gwflags);void gw_node_delete (struct bat_priv *bat_priv,struct orig_node *orig_node); -void gw_node_purge_deleted (struct bat_priv *bat_priv); -void gw_node_list_free (struct bat_priv *bat_priv); +void gw_node_purge (struct bat_priv *bat_priv);int gw_client_seq_print_text (struct seq_file *seq,void *offset);bool gw_is_target (struct bat_priv *bat_priv,struct sk_buff *skb);
batman-adv/main.c +1 -1
@@ -133,7 +133,7 @@ void mesh_free(struct net_device *soft_iface)vis_quit (bat_priv); -gw_node_list_free (bat_priv); +gw_node_purge (bat_priv);originator_free (bat_priv);hna_local_free (bat_priv);
batman-adv/originator.c +1 -1
@@ -294,7 +294,7 @@ static void _purge_orig(struct bat_priv *bat_priv)spin_unlock_bh (&bat_priv->orig_hash_lock); -gw_node_purge_deleted (bat_priv); +gw_node_purge (bat_priv);gw_election (bat_priv);softif_neigh_purge (bat_priv);
Signature · 1 line
1.7.1
PATCH 2/8 batman-adv: gateways silently drop DHCP requests
In reply to Marek Lindner--- batman-adv/gateway_client.c | 31 +++++++++++++++++-------------- batman-adv/gateway_client.h | 2 +- batman-adv/soft-interface.c | 16 ++++++++++------ 3 files changed, 28 insertions(+), 21 deletions(-)
batman-adv/gateway_client.c +17 -14
@@ -400,54 +400,57 @@ int gw_client_seq_print_text(struct seq_file *seq, void *offset)return 0 ; } -bool gw_is_target (struct bat_priv *bat_priv,struct sk_buff *skb) +int gw_is_target (struct bat_priv *bat_priv,struct sk_buff *skb) {struct ethhdr *ethhdr;struct iphdr *iphdr;struct udphdr *udphdr;unsigned int header_len =0 ; -if (atomic_read (&bat_priv->gw_mode) !=GW_MODE_CLIENT ) -return false; - -if (!bat_priv->curr_gw) -return false; +if (atomic_read (&bat_priv->gw_mode) ==GW_MODE_OFF ) +return 0 ;/* check for ethernet header */ if (!pskb_may_pull (skb, header_len +ETH_HLEN )) -return false; +return 0 ; ethhdr = (struct ethhdr *)skb->data; header_len +=ETH_HLEN ;/* check for initial vlan header */ if (ntohs (ethhdr->h_proto) ==ETH_P_8021Q ) {if (!pskb_may_pull (skb, header_len +VLAN_HLEN )) -return false; +return 0 ; ethhdr = (struct ethhdr *)(skb->data +VLAN_HLEN ); header_len +=VLAN_HLEN ; }/* check for ip header */ if (ntohs (ethhdr->h_proto) !=ETH_P_IP ) -return false; +return 0 ;if (!pskb_may_pull (skb, header_len +sizeof (struct iphdr ))) -return false; +return 0 ; iphdr = (struct iphdr *)(skb->data + header_len); header_len += iphdr->ihl *4 ;/* check for udp header */ if (iphdr->protocol !=IPPROTO_UDP ) -return false; +return 0 ;if (!pskb_may_pull (skb, header_len +sizeof (struct udphdr ))) -return false; +return 0 ; udphdr = (struct udphdr *)(skb->data + header_len); header_len +=sizeof (struct udphdr );/* check for bootp port */ if (ntohs (udphdr->dest) !=67 ) -return false; +return 0 ; + +if (atomic_read (&bat_priv->gw_mode) ==GW_MODE_SERVER ) +return -1 ; + +if (!bat_priv->curr_gw) +return 0 ; -return true; +return 1 ; }
batman-adv/gateway_client.h +1 -1
@@ -31,6 +31,6 @@ void gw_node_update(struct bat_priv *bat_priv,void gw_node_delete (struct bat_priv *bat_priv,struct orig_node *orig_node);void gw_node_purge (struct bat_priv *bat_priv);int gw_client_seq_print_text (struct seq_file *seq,void *offset); -bool gw_is_target (struct bat_priv *bat_priv,struct sk_buff *skb); +int gw_is_target (struct bat_priv *bat_priv,struct sk_buff *skb);#endif /* _NET_BATMAN_ADV_GATEWAY_CLIENT_H_ */
batman-adv/soft-interface.c +10 -6
@@ -349,7 +349,7 @@ int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)struct vlan_ethhdr *vhdr;int data_len = skb->len, ret;short vid =-1 ; -bool bcast_dst = false, do_bcast = true; +bool do_bcast = false;if (atomic_read (&bat_priv->mesh_state) !=MESH_ACTIVE ) goto dropped;
@@ -380,14 +380,18 @@ int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)/* TODO: check this for locks */ hna_local_add (soft_iface, ethhdr->h_source); -if (is_bcast (ethhdr->h_dest) ||is_mcast (ethhdr->h_dest)) - bcast_dst = true; +if (is_bcast (ethhdr->h_dest) ||is_mcast (ethhdr->h_dest)) { + ret =gw_is_target (bat_priv, skb); -if ((bcast_dst) &&gw_is_target (bat_priv, skb)) - do_bcast = false; +if (ret <0 ) + goto dropped; + +if (ret ==0 ) + do_bcast = true; + }/* ethernet packet should be broadcasted */ -if (bcast_dst && do_bcast) { +if (do_bcast) {if (!bat_priv->primary_if) goto dropped;
Signature · 1 line
1.7.1
PATCH 3/8 batman-adv: move gateway selection class into its own sysfs file
In reply to Marek LindnerThe Linux kernel guidelines require each sysfs file to have a single value / purpose, therefore it is necessary to split up the sysfs gateway files.
--- batman-adv/bat_sysfs.c | 10 ++++++++++ batman-adv/gateway_client.c | 6 +++--- batman-adv/gateway_common.c | 5 ++++- batman-adv/routing.c | 5 ++++- batman-adv/soft-interface.c | 1 + batman-adv/types.h | 1 + 6 files changed, 23 insertions(+), 5 deletions(-)
batman-adv/bat_sysfs.c +10 -0
@@ -252,6 +252,12 @@ static ssize_t store_vis_mode(struct kobject *kobj, struct attribute *attr,return count; } +static void post_gw_deselect (struct net_device *net_dev) +{ +struct bat_priv *bat_priv =netdev_priv (net_dev); +gw_deselect (bat_priv); +} +static ssize_t show_gw_mode (struct kobject *kobj,struct attribute *attr,char *buff) {
@@ -262,6 +268,7 @@ static ssize_t show_gw_mode(struct kobject *kobj, struct attribute *attr,switch (gw_mode) {case GW_MODE_CLIENT : + gw_class =atomic_read (&bat_priv->gw_sel_class); bytes_written =sprintf (buff,"%s (gw_class: %i)\n" ,GW_MODE_CLIENT_NAME , gw_class);break ;
@@ -299,6 +306,8 @@ static BAT_ATTR(vis_mode, S_IRUGO | S_IWUSR, show_vis_mode, store_vis_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 (hop_penalty,S_IRUGO |S_IWUSR ,0 ,TQ_MAX_VALUE ,NULL ); +BAT_ATTR_UINT (gw_sel_class,S_IRUGO |S_IWUSR ,1 ,TQ_MAX_VALUE , + post_gw_deselect);#ifdef CONFIG_BATMAN_ADV_DEBUG BAT_ATTR_UINT (log_level,S_IRUGO |S_IWUSR ,0 ,3 ,NULL );#endif
@@ -311,6 +320,7 @@ static struct bat_attribute *mesh_attrs[] = { &bat_attr_gw_mode, &bat_attr_orig_interval, &bat_attr_hop_penalty, + &bat_attr_gw_sel_class, #ifdef CONFIG_BATMAN_ADV_DEBUG &bat_attr_log_level, #endif
batman-adv/gateway_client.c +3 -3
@@ -117,7 +117,7 @@ void gw_election(struct bat_priv *bat_priv)if (gw_node->deleted)continue ; -switch (atomic_read (&bat_priv->gw_class)) { +switch (atomic_read (&bat_priv->gw_sel_class)) {case 1 :/* fast connection */ gw_srv_class_to_kbit (gw_node->orig_node->gw_flags, &down, &up);
@@ -216,8 +216,8 @@ void gw_check_election(struct bat_priv *bat_priv, struct orig_node *orig_node)* if the routing class is greater than 3 the value tells us how much * greater the TQ value of the new gateway must be **/ -if ((atomic_read (&bat_priv->gw_class) >3 ) && - (orig_tq_avg - gw_tq_avg <atomic_read (&bat_priv->gw_class))) +if ((atomic_read (&bat_priv->gw_sel_class) >3 ) && + (orig_tq_avg - gw_tq_avg <atomic_read (&bat_priv->gw_sel_class)))return ; bat_dbg(DBG_BATMAN, bat_priv,
batman-adv/gateway_common.c +4 -1
@@ -237,12 +237,15 @@ next:switch (gw_mode_tmp) {case GW_MODE_CLIENT : + gw_class_tmp =atomic_read (&bat_priv->gw_sel_class);if ((gw_mode_tmp ==GW_MODE_CLIENT ) && (!gw_class_tmp)) gw_class_tmp =20 ;bat_info (net_dev,"Changing gateway mode from: '%s' to: '%s' " -"(gw_class: %ld)\n" , +"(gw_sel_class: %ld)\n" , gw_mode_curr_str, gw_mode_tmp_str, gw_class_tmp); + +atomic_set (&bat_priv->gw_sel_class, gw_class_tmp);break ;case GW_MODE_SERVER :if (!down)
batman-adv/routing.c +4 -1
@@ -33,6 +33,7 @@#include "vis.h" #include "aggregation.h" #include "compat.h" +#include "gateway_common.h" #include "gateway_client.h" #include "unicast.h"
@@ -331,7 +332,9 @@ update_gw: orig_node->gw_flags = batman_packet->gw_flags;/* restart gateway selection if fast or late switching was enabled */ -if ((orig_node->gw_flags) && (atomic_read (&bat_priv->gw_class) >2 )) +if ((orig_node->gw_flags) && + (atomic_read (&bat_priv->gw_mode) ==GW_MODE_CLIENT ) && + (atomic_read (&bat_priv->gw_sel_class) >2 ))gw_check_election (bat_priv, orig_node); }
batman-adv/soft-interface.c +1 -0
@@ -593,6 +593,7 @@ struct net_device *softif_create(char *name)atomic_set (&bat_priv->bonding,0 );atomic_set (&bat_priv->vis_mode,VIS_TYPE_CLIENT_UPDATE );atomic_set (&bat_priv->gw_mode,GW_MODE_OFF ); +atomic_set (&bat_priv->gw_sel_class,0 );atomic_set (&bat_priv->gw_class,0 );atomic_set (&bat_priv->orig_interval,1000 );atomic_set (&bat_priv->hop_penalty,10 );
batman-adv/types.h +1 -0
@@ -128,6 +128,7 @@ struct bat_priv {atomic_t fragmentation;/* boolean */ atomic_t vis_mode;/* VIS_TYPE_* */ atomic_t gw_mode;/* GW_MODE_* */ +atomic_t gw_sel_class;/* uint */ atomic_t gw_class;/* uint */ atomic_t orig_interval;/* uint */ atomic_t hop_penalty;/* uint */
Signature · 1 line
1.7.1
PATCH 4/8 batman-adv: move gateway bandwidth into its own sysfs file
In reply to Marek LindnerThe Linux kernel guidelines require each sysfs file to have a single value / purpose, therefore it is necessary to split up the sysfs gateway files.
--- batman-adv/bat_sysfs.c | 37 +++++++++++++-- batman-adv/gateway_client.c | 6 +- batman-adv/gateway_common.c | 112 +++++++++++++++++++++++++++++++++++++++++-- batman-adv/gateway_common.h | 3 +- batman-adv/send.c | 2 +- batman-adv/soft-interface.c | 2 +- batman-adv/types.h | 2 +- 7 files changed, 148 insertions(+), 16 deletions(-)
batman-adv/bat_sysfs.c +33 -4
@@ -263,8 +263,7 @@ static ssize_t show_gw_mode(struct kobject *kobj, struct attribute *attr, {struct bat_priv *bat_priv =kobj_to_batpriv (kobj);int down, up, bytes_written; -int gw_mode =atomic_read (&bat_priv->gw_mode); -int gw_class =atomic_read (&bat_priv->gw_class); +int gw_class, gw_mode =atomic_read (&bat_priv->gw_mode);switch (gw_mode) {case GW_MODE_CLIENT :
@@ -273,7 +272,8 @@ static ssize_t show_gw_mode(struct kobject *kobj, struct attribute *attr, GW_MODE_CLIENT_NAME, gw_class);break ;case GW_MODE_SERVER : -gw_srv_class_to_kbit (gw_class, &down, &up); + gw_class =atomic_read (&bat_priv->gw_bandwidth); +gw_bandwidth_to_kbit (gw_class, &down, &up); bytes_written = sprintf(buff, "%s (gw_class: %i " "-> propagating: %i%s/%i%s)\n",
@@ -293,12 +293,38 @@ static ssize_t show_gw_mode(struct kobject *kobj, struct attribute *attr, }static ssize_t store_gw_mode (struct kobject *kobj,struct attribute *attr, -char *buff,size_t count) +char *buff,size_t count) {struct net_device *net_dev =kobj_to_netdev (kobj);return gw_mode_set (net_dev, buff, count); } +static ssize_t show_gw_bwidth (struct kobject *kobj,struct attribute *attr, +char *buff) +{ +struct bat_priv *bat_priv =kobj_to_batpriv (kobj); +int down, up; +int gw_bandwidth =atomic_read (&bat_priv->gw_bandwidth); + +gw_bandwidth_to_kbit (gw_bandwidth, &down, &up); +return sprintf (buff,"%i%s/%i%s\n" , + (down >2048 ? down /1024 : down), + (down >2048 ?"MBit" :"KBit" ), + (up >2048 ? up /1024 : up), + (up >2048 ?"MBit" :"KBit" )); +} + +static ssize_t store_gw_bwidth (struct kobject *kobj,struct attribute *attr, +char *buff,size_t count) +{ +struct net_device *net_dev =kobj_to_netdev (kobj); + +if (buff[count -1 ] =='\n' ) + buff[count -1 ] ='\0' ; + +return gw_bandwidth_set (net_dev, buff, count); +} +BAT_ATTR_BOOL (aggregated_ogms,S_IRUGO |S_IWUSR ,NULL );BAT_ATTR_BOOL (bonding,S_IRUGO |S_IWUSR ,NULL );BAT_ATTR_BOOL (fragmentation,S_IRUGO |S_IWUSR , update_min_mtu);
@@ -308,6 +334,8 @@ 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 (gw_sel_class,S_IRUGO |S_IWUSR ,1 ,TQ_MAX_VALUE , post_gw_deselect); +static BAT_ATTR(gw_bandwidth, S_IRUGO | S_IWUSR, show_gw_bwidth, + store_gw_bwidth);#ifdef CONFIG_BATMAN_ADV_DEBUG BAT_ATTR_UINT (log_level,S_IRUGO |S_IWUSR ,0 ,3 ,NULL );#endif
@@ -321,6 +349,7 @@ static struct bat_attribute *mesh_attrs[] = { &bat_attr_orig_interval, &bat_attr_hop_penalty, &bat_attr_gw_sel_class, + &bat_attr_gw_bandwidth, #ifdef CONFIG_BATMAN_ADV_DEBUG &bat_attr_log_level, #endif
batman-adv/gateway_client.c +3 -3
@@ -119,7 +119,7 @@ void gw_election(struct bat_priv *bat_priv)switch (atomic_read (&bat_priv->gw_sel_class)) {case 1 :/* fast connection */ -gw_srv_class_to_kbit (gw_node->orig_node->gw_flags, +gw_bandwidth_to_kbit (gw_node->orig_node->gw_flags, &down, &up); tmp_gw_factor = (gw_node->orig_node->router->tq_avg *
@@ -248,7 +248,7 @@ static void gw_node_add(struct bat_priv *bat_priv,hlist_add_head_rcu (&gw_node->list, &bat_priv->gw_list);spin_unlock_bh (&bat_priv->gw_list_lock); -gw_srv_class_to_kbit (new_gwflags, &down, &up); +gw_bandwidth_to_kbit (new_gwflags, &down, &up); bat_dbg(DBG_BATMAN, bat_priv, "Found new gateway %pM -> gw_class: %i - %i%s/%i%s\n", orig_node->orig, new_gwflags,
@@ -337,7 +337,7 @@ static int _write_buffer_text(struct bat_priv *bat_priv, {int down, up; -gw_srv_class_to_kbit (gw_node->orig_node->gw_flags, &down, &up); +gw_bandwidth_to_kbit (gw_node->orig_node->gw_flags, &down, &up); return seq_printf(seq, "%s %pM (%3i) %pM [%10s]: %3i - %i%s/%i%s\n", (bat_priv->curr_gw == gw_node ? "=>" : " "),
batman-adv/gateway_common.c +107 -5
151 lines not on this page · raw message
batman-adv/gateway_common.h +2 -1
@@ -32,7 +32,8 @@ enum gw_modes {#define GW_MODE_CLIENT_NAME "client"#define GW_MODE_SERVER_NAME "server" -void gw_srv_class_to_kbit (uint8_t gw_class,int *down,int *up); +void gw_bandwidth_to_kbit (uint8_t gw_class,int *down,int *up);ssize_t gw_mode_set (struct net_device *net_dev,char *buff,size_t count); +ssize_t gw_bandwidth_set (struct net_device *net_dev,char *buff,size_t count);#endif /* _NET_BATMAN_ADV_GATEWAY_COMMON_H_ */
batman-adv/send.c +1 -1
@@ -289,7 +289,7 @@ void schedule_own_packet(struct batman_if *batman_if)if ((batman_if == bat_priv->primary_if) && (atomic_read (&bat_priv->gw_mode) ==GW_MODE_SERVER )) batman_packet->gw_flags = - (uint8_t )atomic_read (&bat_priv->gw_class); + (uint8_t )atomic_read (&bat_priv->gw_bandwidth);else batman_packet->gw_flags =0 ;
batman-adv/soft-interface.c +1 -1
@@ -594,7 +594,7 @@ struct net_device *softif_create(char *name)atomic_set (&bat_priv->vis_mode,VIS_TYPE_CLIENT_UPDATE );atomic_set (&bat_priv->gw_mode,GW_MODE_OFF );atomic_set (&bat_priv->gw_sel_class,0 ); -atomic_set (&bat_priv->gw_class,0 ); +atomic_set (&bat_priv->gw_bandwidth,0 );atomic_set (&bat_priv->orig_interval,1000 );atomic_set (&bat_priv->hop_penalty,10 );atomic_set (&bat_priv->log_level,0 );
batman-adv/types.h +1 -1
@@ -129,7 +129,7 @@ struct bat_priv {atomic_t vis_mode;/* VIS_TYPE_* */ atomic_t gw_mode;/* GW_MODE_* */ atomic_t gw_sel_class;/* uint */ -atomic_t gw_class;/* uint */ +atomic_t gw_bandwidth;/* gw bandwidth */ atomic_t orig_interval;/* uint */ atomic_t hop_penalty;/* uint */ atomic_t log_level;/* uint */
Signature · 1 line
1.7.1
PATCH 5/8 batman-adv: cleanup gw mode sysfs file to only accept one value
In reply to Marek LindnerThe Linux kernel guidelines require each sysfs file to have a single value / purpose, therefore it is necessary to split up the sysfs gateway files.
--- batman-adv/bat_sysfs.c | 78 ++++++++++++---- batman-adv/gateway_common.c | 214 ------------------------------------------- batman-adv/gateway_common.h | 1 - 3 files changed, 59 insertions(+), 234 deletions(-)
batman-adv/bat_sysfs.c +59 -19
@@ -262,30 +262,17 @@ static ssize_t show_gw_mode(struct kobject *kobj, struct attribute *attr, char *buff) {struct bat_priv *bat_priv =kobj_to_batpriv (kobj); -int down, up, bytes_written; -int gw_class, gw_mode =atomic_read (&bat_priv->gw_mode); +int bytes_written; -switch (gw_mode) { +switch (atomic_read (&bat_priv->gw_mode)) {case GW_MODE_CLIENT : - gw_class =atomic_read (&bat_priv->gw_sel_class); - bytes_written =sprintf (buff,"%s (gw_class: %i)\n" , -GW_MODE_CLIENT_NAME , gw_class); + bytes_written =sprintf (buff,"%s\n" ,GW_MODE_CLIENT_NAME );break ;case GW_MODE_SERVER : - gw_class =atomic_read (&bat_priv->gw_bandwidth); -gw_bandwidth_to_kbit (gw_class, &down, &up); - bytes_written =sprintf (buff, -"%s (gw_class: %i " -"-> propagating: %i%s/%i%s)\n" , -GW_MODE_SERVER_NAME , gw_class, - (down >2048 ? down /1024 : down), - (down >2048 ?"MBit" :"KBit" ), - (up >2048 ? up /1024 : up), - (up >2048 ?"MBit" :"KBit" )); + bytes_written =sprintf (buff,"%s\n" ,GW_MODE_SERVER_NAME );break ;default : - bytes_written =sprintf (buff,"%s\n" , -GW_MODE_OFF_NAME ); + bytes_written =sprintf (buff,"%s\n" ,GW_MODE_OFF_NAME );break ; }
@@ -296,7 +283,60 @@ static ssize_t store_gw_mode(struct kobject *kobj, struct attribute *attr, char *buff, size_t count) {struct net_device *net_dev =kobj_to_netdev (kobj); -return gw_mode_set (net_dev, buff, count); +struct bat_priv *bat_priv =netdev_priv (net_dev); +char *curr_gw_mode_str; +int gw_mode_tmp =-1 ; + +if (buff[count -1 ] =='\n' ) + buff[count -1 ] ='\0' ; + +if (strncmp (buff,GW_MODE_OFF_NAME ,strlen (GW_MODE_OFF_NAME )) ==0 ) + gw_mode_tmp =GW_MODE_OFF ; + +if (strncmp (buff,GW_MODE_CLIENT_NAME , +strlen (GW_MODE_CLIENT_NAME )) ==0 ) + gw_mode_tmp =GW_MODE_CLIENT ; + +if (strncmp (buff,GW_MODE_SERVER_NAME , +strlen (GW_MODE_SERVER_NAME )) ==0 ) + gw_mode_tmp =GW_MODE_SERVER ; + +if (gw_mode_tmp <0 ) { +bat_info (net_dev, +"Invalid parameter for 'gw mode' setting received: " +"%s\n" , buff); +return -EINVAL ; + } + +if (atomic_read (&bat_priv->gw_mode) == gw_mode_tmp) +return count; + +switch (atomic_read (&bat_priv->gw_mode)) { +case GW_MODE_CLIENT : + curr_gw_mode_str =GW_MODE_CLIENT_NAME ; +break ; +case GW_MODE_SERVER : + curr_gw_mode_str =GW_MODE_SERVER_NAME ; +break ; +default : + curr_gw_mode_str =GW_MODE_OFF_NAME ; +break ; + } + +bat_info (net_dev,"Changing gw mode from: %s to: %s\n" , + curr_gw_mode_str, buff); + +if ((gw_mode_tmp ==GW_MODE_CLIENT ) && + (atomic_read (&bat_priv->gw_sel_class) ==0 )) +atomic_set (&bat_priv->gw_sel_class,20 ); + +if ((gw_mode_tmp ==GW_MODE_SERVER ) && + (atomic_read (&bat_priv->gw_bandwidth) ==0 )) +atomic_set (&bat_priv->gw_bandwidth,41 ); + +gw_deselect (bat_priv); +atomic_set (&bat_priv->gw_mode, (unsigned )gw_mode_tmp); +return count; } static ssize_t show_gw_bwidth(struct kobject *kobj, struct attribute *attr,
batman-adv/gateway_common.c +0 -214
220 lines not on this page · raw message
batman-adv/gateway_common.h +0 -1
@@ -33,7 +33,6 @@ enum gw_modes {#define GW_MODE_SERVER_NAME "server"void gw_bandwidth_to_kbit (uint8_t gw_class,int *down,int *up); -ssize_t gw_mode_set (struct net_device *net_dev,char *buff,size_t count);ssize_t gw_bandwidth_set (struct net_device *net_dev,char *buff,size_t count);#endif /* _NET_BATMAN_ADV_GATEWAY_COMMON_H_ */
Signature · 1 line
1.7.1
PATCH 6/8 batctl: support new gateway sysfs API
In reply to Marek Lindner--- batctl/main.c | 3 +- batctl/man/batctl.8 | 4 +- batctl/sys.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++- batctl/sys.h | 9 ++++ 4 files changed, 128 insertions(+), 5 deletions(-)
batctl/main.c +1 -2
@@ -166,8 +166,7 @@ int main(int argc, char **argv) }else if ((strcmp (argv[1 ],"gw_mode" ) ==0 ) || (strcmp (argv[1 ],"gw" ) ==0 )) { - ret =handle_sys_setting (mesh_iface, argc -1 , argv +1 , -SYS_GW_MODE , gw_mode_usage, sysfs_param_server); + ret =handle_gw_setting (mesh_iface, argc -1 , argv +1 ); }else if ((strcmp (argv[1 ],"gateways" ) ==0 ) || (strcmp (argv[1 ],"gwl" ) ==0 )) {
batctl/man/batctl.8 +2 -2
@@ -70,8 +70,8 @@ If no parameter is given the current log level settings are displayed otherwise .IP "\fBlog\fP|\fBl\fP [\fB\-n\fP]\fP" batctl will read the batman-adv debug log which has to be compiled into the kernel module. If "\-n" is given batctl will not replace the MAC addresses with bat\-host names in the output. .br -.IP "\fBgw_mode|gw\fP [\fBoff\fP|\fBclient\fP|\fBserver\fP] [\fBgw_class\fP]\fP" -If no parameter is given the current gateway mode is displayed otherwise the parameter is used to set the gateway mode. The second (optional) argument specifies the gateway class. Its function depends on whether the node is a server or a client. If the node is a server this parameter is used to inform other nodes in the network about this node's internet connection bandwidth. Just enter any number (optionally followed by "kbit" or "mbit") and the batman-adv module will guess your appropriate gateway class. Use "/" to separate the down\(hy and upload rates. You can omit the upload rate and the module will assume an upload of download / 5. +.IP "\fBgw_mode|gw\fP [\fBoff\fP|\fBclient\fP|\fBserver\fP] [\fBsel_class|bandwidth\fP]\fP" +If no parameter is given the current gateway mode is displayed otherwise the parameter is used to set the gateway mode. The second (optional) argument specifies the selection class (if 'client' was the first argument) or the gateway bandwidth (if 'server' was the first argument). If the node is a server this parameter is used to inform other nodes in the network about this node's internet connection bandwidth. Just enter any number (optionally followed by "kbit" or "mbit") and the batman-adv module will guess your appropriate gateway class. Use "/" to separate the down\(hy and upload rates. You can omit the upload rate and the module will assume an upload of download / 5. .RS 17 default: 2000 \-> gateway class 20 .RE
batctl/sys.c +116 -1
126 lines not on this page · raw message
batctl/sys.h +9 -0
@@ -26,6 +26,8 @@#define SYS_AGGR "aggregated_ogms"#define SYS_BONDING "bonding"#define SYS_GW_MODE "gw_mode" +#define SYS_GW_SEL "gw_sel_class" +#define SYS_GW_BW "gw_bandwidth"#define SYS_VIS_MODE "vis_mode"#define SYS_ORIG_INTERVAL "orig_interval"#define SYS_IFACE_PATH "/sys/class/net"
@@ -33,6 +35,12 @@#define SYS_IFACE_STATUS_FMT SYS_IFACE_PATH"/%s/batman_adv/iface_status"#define SYS_FRAG "fragmentation" +enum gw_modes { +GW_MODE_OFF , +GW_MODE_CLIENT , +GW_MODE_SERVER , +}; +extern const char *sysfs_param_enable[];extern const char *sysfs_param_server[];
@@ -47,3 +55,4 @@ int handle_loglevel(char *mesh_iface, int argc, char **argv);int handle_sys_setting (char *mesh_iface,int argc,char **argv,char *file_path,void setting_usage (void ),const char *sysfs_param[]); +int handle_gw_setting (char *mesh_iface,int argc,char **argv);
Signature · 1 line
1.7.1
PATCH 7/8 batman-adv: document gateway sysfs ABI
In reply to Marek Lindner--- batman-adv/sysfs-class-net-mesh | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-)
batman-adv/sysfs-class-net-mesh +21 -0
@@ -22,6 +22,27 @@ Description: mesh will be fragmented or silently discarded if the packet size exceeds the outgoing interface MTU. +What: /sys/class/net/<mesh_iface>/mesh/gw_bandwidth +Date: October 2010 +Contact: Marek Lindner <[email protected]> +Description: + Defines the bandwidth which is propagated by this + node if gw_mode was set to 'server'. + +What: /sys/class/net/<mesh_iface>/mesh/gw_mode +Date: October 2010 +Contact: Marek Lindner <[email protected]> +Description: + Defines the state of the gateway features. Can be + either 'off', 'client' or 'server'. + +What: /sys/class/net/<mesh_iface>/mesh/gw_sel_class +Date: October 2010 +Contact: Marek Lindner <[email protected]> +Description: + Defines the selection criteria this node will use + to choose a gateway if gw_mode was set to 'client'. + What: /sys/class/net/<mesh_iface>/mesh/orig_interval Date: May 2010 Contact: Marek Lindner <[email protected]>
Signature · 1 line
1.7.1
PATCH 8/8 batman-adv: add gateway IPv6 support by filtering DHCPv6 messages
In reply to Marek Lindner--- batman-adv/gateway_client.c | 40 +++++++++++++++++++++++++++++++--------- 1 files changed, 31 insertions(+), 9 deletions(-)
batman-adv/gateway_client.c +31 -9
@@ -25,6 +25,7 @@#include "hard-interface.h" #include "compat.h" #include <linux/ip.h> +#include <linux/ipv6.h> #include <linux/udp.h> #include <linux/if_vlan.h>
@@ -404,6 +405,7 @@ int gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb) {struct ethhdr *ethhdr;struct iphdr *iphdr; +struct ipv6hdr *ipv6hdr;struct udphdr *udphdr;unsigned int header_len =0 ;
@@ -425,17 +427,32 @@ int gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb) }/* check for ip header */ -if (ntohs (ethhdr->h_proto) !=ETH_P_IP ) -return 0 ; +switch (ntohs (ethhdr->h_proto)) { +case ETH_P_IP : +if (!pskb_may_pull (skb, header_len +sizeof (struct iphdr ))) +return 0 ; + iphdr = (struct iphdr *)(skb->data + header_len); + header_len += iphdr->ihl *4 ; -if (!pskb_may_pull (skb, header_len +sizeof (struct iphdr ))) -return 0 ; - iphdr = (struct iphdr *)(skb->data + header_len); - header_len += iphdr->ihl *4 ; +/* check for udp header */ +if (iphdr->protocol !=IPPROTO_UDP ) +return 0 ; + +break ; +case ETH_P_IPV6 : +if (!pskb_may_pull (skb, header_len +sizeof (struct ipv6hdr ))) +return 0 ; + ipv6hdr = (struct ipv6hdr *)(skb->data + header_len); + header_len +=sizeof (struct ipv6hdr ); -/* check for udp header */ -if (iphdr->protocol !=IPPROTO_UDP ) +/* check for udp header */ +if (ipv6hdr->nexthdr !=IPPROTO_UDP ) +return 0 ; + +break ; +default :return 0 ; + }if (!pskb_may_pull (skb, header_len +sizeof (struct udphdr )))return 0 ;
@@ -443,7 +460,12 @@ int gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb) header_len +=sizeof (struct udphdr );/* check for bootp port */ -if (ntohs (udphdr->dest) !=67 ) +if ((ntohs (ethhdr->h_proto) ==ETH_P_IP ) && + (ntohs (udphdr->dest) !=67 )) +return 0 ; + +if ((ntohs (ethhdr->h_proto) ==ETH_P_IPV6 ) && + (ntohs (udphdr->dest) !=547 ))return 0 ;if (atomic_read (&bat_priv->gw_mode) ==GW_MODE_SERVER )
Signature · 1 line
1.7.1
Re: [B.A.T.M.A.N.] [PATCH 8/8] batman-adv: add gateway IPv6 support by filtering DHCPv6 messages
Just gave it a go on a basic dhcpv6 setup and works fine. Though some additional checks will be needed in case of extension headers like the fragmentation or hop-by-hop (for jumbo frames for example) headers or ipsec stuff. But this patch should do for most people for now, the rest can be added with a later one.
Cheers, Linus
Quoted 83 lines · Marek Lindner
Signed-off-by Marek Lindner <[email protected]>--- batman-adv/gateway_client.c | 40 +++++++++++++++++++++++++++++++--------- 1 files changed, 31 insertions(+), 9 deletions(-)batman-adv/gateway_client.c +31
-9@@ -25,6 +25,7 @@#include "hard-interface.h" #include "compat.h" #include <linux/ip.h> +#include <linux/ipv6.h> #include <linux/udp.h> #include <linux/if_vlan.h> @@ -404,6 +405,7 @@ int gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb) {struct ethhdr *ethhdr;struct iphdr *iphdr; +struct ipv6hdr *ipv6hdr;struct udphdr *udphdr;unsigned int header_len =0 ;@@ -425,17 +427,32 @@ int gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb) }/* check for ip header */ -if (ntohs (ethhdr->h_proto) !=ETH_P_IP ) -return 0 ; +switch (ntohs (ethhdr->h_proto)) { +case ETH_P_IP : +if (!pskb_may_pull (skb, header_len +sizeof (struct iphdr ))) +return 0 ; + iphdr = (struct iphdr *)(skb->data + header_len); + header_len += iphdr->ihl *4 ; -if (!pskb_may_pull (skb, header_len +sizeof (struct iphdr ))) -return 0 ; - iphdr = (struct iphdr *)(skb->data + header_len); - header_len += iphdr->ihl *4 ; +/* check for udp header */ +if (iphdr->protocol !=IPPROTO_UDP ) +return 0 ; + +break ; +case ETH_P_IPV6 : +if (!pskb_may_pull (skb, header_len +sizeof (struct ipv6hdr ))) +return 0 ; + ipv6hdr = (struct ipv6hdr *)(skb->data + header_len); + header_len +=sizeof (struct ipv6hdr ); -/* check for udp header */ -if (iphdr->protocol !=IPPROTO_UDP ) +/* check for udp header */ +if (ipv6hdr->nexthdr !=IPPROTO_UDP ) +return 0 ; + +break ; +default :return 0 ; + }if (!pskb_may_pull (skb, header_len +sizeof (struct udphdr )))return 0 ;@@ -443,7 +460,12 @@ int gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb) header_len +=sizeof (struct udphdr );/* check for bootp port */ -if (ntohs (udphdr->dest) !=67 ) +if ((ntohs (ethhdr->h_proto) ==ETH_P_IP ) && + (ntohs (udphdr->dest) !=67 )) +return 0 ; + +if ((ntohs (ethhdr->h_proto) ==ETH_P_IPV6 ) && + (ntohs (udphdr->dest) !=547 ))return 0 ;if (atomic_read (&bat_priv->gw_mode) ==GW_MODE_SERVER )Signature · 1 line
1.7.1
[PATCH 1/8] batman-adv: remove redundant gw_node_list_free() function
Quoted 15 lines
(quoted diff) +0
-11@@ -315,32 +315,20 @@ void gw_node_purge_deleted(struct bat_priv *bat_priv) spin_lock_bh(&bat_priv->gw_list_lock); hlist_for_each_entry_safe(gw_node, node, node_tmp, - &bat_priv->gw_list, list) { - if ((gw_node->deleted) && - (time_after(jiffies, gw_node->deleted + timeout))) { - - hlist_del_rcu(&gw_node->list); - call_rcu(&gw_node->rcu, gw_node_free_rcu); - } - } - - spin_unlock_bh(&bat_priv->gw_list_lock); -}
Review void gw_node_purge_deleted(struct bat_priv *bat_priv) · line 322
Quoted 10 lines
(quoted diff) +5
-5- -void gw_node_list_free(struct bat_priv *bat_priv) -{ - struct gw_node *gw_node; - struct hlist_node *node, *node_tmp; + &bat_priv->gw_list, list) { + if (((!gw_node->deleted) || + (time_after(jiffies, gw_node->deleted + timeout))) && + atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE) + continue;
This should be time_before.
[PATCH 4/8] batman-adv: move gateway bandwidth into its own sysfs file
Review static ssize_t show_gw_mode(struct kobject *kobj, · line 296
Quoted 6 lines
(quoted diff) +1
-1@@ -293,12 +293,38 @@ static ssize_t show_gw_mode(struct kobject *kobj, struct attribute *attr, } static ssize_t store_gw_mode(struct kobject *kobj, struct attribute *attr, - char *buff, size_t count) + char *buff, size_t count)
Why was the space removed?
Review static ssize_t show_gw_mode(struct kobject *kobj, · line 298
Quoted 2 lines
(quoted diff) +2
-0+ if ((strnicmp(tmp_ptr, "kbit", 4) == 0) || + (multi > 1))
Why this indentation? And This should be on a single line (or I count wrong).
[PATCH 5/8] batman-adv: cleanup gw mode sysfs file to only accept one value
Review static ssize_t show_gw_mode(struct kobject *kobj, · line 305
Quoted 7 lines
(quoted diff) +7
-0+ if ((gw_mode_tmp == GW_MODE_CLIENT) && + (atomic_read(&bat_priv->gw_sel_class) == 0)) + atomic_set(&bat_priv->gw_sel_class, 20); + + if ((gw_mode_tmp == GW_MODE_SERVER) && + (atomic_read(&bat_priv->gw_bandwidth) == 0)) + atomic_set(&bat_priv->gw_bandwidth, 41);
Why setting that here? And why do you set gw_sel_class here to 20 (if it is 0 before) and in softif_create to 0? Shouldn't it be set to 20 in softif_create instead?
I don't see a big problem at the moment.
Best regards,
Sven
Quoted 9 lines · On Saturday 30 October 2010 14:14:02 Sven Eckelmann wrote:
Quoted 7 lines
(quoted diff) +3
-2- struct gw_node *gw_node; - struct hlist_node *node, *node_tmp; + &bat_priv->gw_list, list) { + if (((!gw_node->deleted) || + (time_after(jiffies, gw_node->deleted + timeout)))&& +
atomic_read(&bat_priv->mesh_state)==MESH_ACTIVE) + continue;This should be
time_before.
Agreed.
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +1
-1- char *buff, size_t count) + char *buff, size_t count)Why was the space removed?
Should I move this into a separate patch ?
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if ((strnicmp(tmp_ptr, "kbit", 4) == 0) || + (multi > 1))Why this indentation? And This should be on a single line (or I count wrong).
No, you are right. Will be fixed.
Quoted 11 lines
Review
Quoted 7 lines
(quoted diff) +7
-0+ if ((gw_mode_tmp == GW_MODE_CLIENT) && + (atomic_read(&bat_priv->gw_sel_class) == 0)) + atomic_set(&bat_priv->gw_sel_class, 20); + + if ((gw_mode_tmp == GW_MODE_SERVER) && + (atomic_read(&bat_priv->gw_bandwidth) == 0)) + atomic_set(&bat_priv->gw_bandwidth, 41);Why setting that here? And why do you set
gw_sel_classhere to 20 (if it is 0 before) and insoftif_createto 0? Shouldn't it be set to 20 insoftif_createinstead?
The general idea was that if somebody activated client or gateway mode without setting gw_sel_class or gw_bandwidth to any value, it would use some default values.
Moving these checks into softif_create() would only solve half of the problem because a user could set these variables to 0 and then start the client or server. At least the client mode requires the gw_sel_class variable value to be greater than 0.
Thanks for the comments,
Marek
Quoted 6 lines · Marek Lindner
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +1
-1- char *buff, size_t count) + char *buff, size_t count)Why was the space removed?
Should I move this into a separate patch ?
Sry, my fault. just forget it :)
Quoted 20 lines
Quoted 5 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if ((strnicmp(tmp_ptr, "kbit", 4) == 0) || + (multi > 1))Why this indentation? And This should be on a single line (or I count wrong).
No, you are right. Will be fixed.
Quoted 11 lines
Review
Quoted 7 lines
(quoted diff) +7
-0+ if ((gw_mode_tmp == GW_MODE_CLIENT) && + (atomic_read(&bat_priv->gw_sel_class) == 0)) + atomic_set(&bat_priv->gw_sel_class, 20); + + if ((gw_mode_tmp == GW_MODE_SERVER) && + (atomic_read(&bat_priv->gw_bandwidth) == 0)) + atomic_set(&bat_priv->gw_bandwidth, 41);Why setting that here? And why do you set
gw_sel_classhere to 20 (if it is 0 before) and insoftif_createto 0? Shouldn't it be set to 20 insoftif_createinstead?
Quoted 7 lines
The general idea was that if somebody activated client or gateway mode without setting
gw_sel_classorgw_bandwidthto any value, it would use some default values.
Moving these checks intosoftif_create()would only solve half of the problem because a user could set these variables to 0 and then start the client or server. At least the client mode requires thegw_sel_classvariable value to be greater than 0.
Isn't it limited to 1 by BAT_ATTR_UINT? And if not (which I doubt) wouldn't be the user still be able to set it to 0 after he changed it to client mode?
Best regards,
Sven
Quoted 3 lines · On Sunday 31 October 2010 16:55:40 Sven Eckelmann wrote:
Isn't it limited to 1 by
BAT_ATTR_UINT? And if not (which I doubt) wouldn't be the user still be able to set it to 0 after he changed it to client mode?
You got a point here. I'll come up with another solution.
Cheers,
Marek