From patchwork Sat May 16 20:07:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ruben Wisniewski X-Patchwork-Id: 4384 Return-Path: Received-SPF: None (no SPF record) identity=mailfrom; client-ip=46.38.231.10; helo=we70a.netcup.net; envelope-from=ruben@freifunk-nrw.de; receiver=b.a.t.m.a.n@lists.open-mesh.org X-Greylist: delayed 320 seconds by postgrey-1.34 at open-mesh.org; Sat, 16 May 2015 22:13:04 CEST Received: from we70a.netcup.net (we70a.netcup.net [46.38.231.10]) by open-mesh.org (Postfix) with ESMTPS id 394D36007AD for ; Sat, 16 May 2015 22:13:04 +0200 (CEST) Received: from i3.local (unknown [77.87.49.91]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by we70a.netcup.net (Postfix) with ESMTPSA id C052F47468 for ; Sat, 16 May 2015 22:07:43 +0200 (CEST) Date: Sat, 16 May 2015 22:07:36 +0200 From: Ruben Wisniewski To: b.a.t.m.a.n@lists.open-mesh.org Message-ID: <20150516220736.2d896b4b@i3.local> Organization: Verbund freier Netzwerke NRW e.V. X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.28; x86_64-unknown-linux-gnu) MIME-Version: 1.0 Subject: [B.A.T.M.A.N.] Patch to add mesh_no_rebroadcast X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 16 May 2015 20:13:04 -0000 Signed-off-by: Linus Lüssing --- hard-interface.c | 2 ++ send.c | 4 ++++ sysfs-class-net-batman-adv | 10 ++++++++ sysfs.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++ types.h | 1 + 5 files changed, 76 insertions(+) diff --git a/hard-interface.c b/hard-interface.c index fbda6b5..3997f9c 100644 --- a/hard-interface.c +++ b/hard-interface.c @@ -591,6 +591,8 @@ batadv_hardif_add_interface(struct net_device *net_dev) /* extra reference for return */ atomic_set(&hard_iface->refcount, 2); + atomic_set(&hard_iface->no_rebroadcast, 0); + batadv_check_known_mac_addr(hard_iface->net_dev); list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list); diff --git a/send.c b/send.c index d27161e..4383a66 100644 --- a/send.c +++ b/send.c @@ -513,6 +513,10 @@ static void batadv_send_outstanding_bcast_packet(struct work_struct *work) if (forw_packet->num_packets >= hard_iface->num_bcasts) continue; + if (atomic_read(&hard_iface->no_rebroadcast) && + forw_packet->skb->dev == hard_iface->net_dev) + continue; + /* send a copy of the saved skb */ skb1 = skb_clone(forw_packet->skb, GFP_ATOMIC); if (skb1) diff --git a/sysfs-class-net-batman-adv b/sysfs-class-net-batman-adv index 7f34a95..cf7fe00 100644 --- a/sysfs-class-net-batman-adv +++ b/sysfs-class-net-batman-adv @@ -13,3 +13,13 @@ Description: displays the batman mesh interface this currently is associated with. +What: /sys/class/net//batman-adv/no_rebroadcast +Date: Sep 2013 +Contact: Linus Lüssing +Description: + With this option set incoming multicast payload frames on + are not being rebroadcasted on again. This + option should be set on links which are known to be transitive + and symmetric only, for instance point-to-point wifi longshots + or wired links. Using this option wrongly is going to + break your mesh network, use at your own risk! diff --git a/sysfs.c b/sysfs.c index fc47baa..adaeca4 100644 --- a/sysfs.c +++ b/sysfs.c @@ -110,6 +110,17 @@ struct batadv_attribute batadv_attr_vlan_##_name = { \ .store = _store, \ } +/* Use this, if you have customized show and store functions + * for hard interface attrs + */ +#define BATADV_ATTR_HIF(_name, _mode, _show, _store) \ +struct batadv_attribute batadv_attr_hif_##_name = { \ + .attr = {.name = __stringify(_name), \ + .mode = _mode }, \ + .show = _show, \ + .store = _store, \ +}; + /* Use this, if you have customized show and store functions */ #define BATADV_ATTR(_name, _mode, _show, _store) \ struct batadv_attribute batadv_attr_##_name = { \ @@ -221,6 +232,52 @@ ssize_t batadv_show_vlan_##_name(struct kobject *kobj, \ static BATADV_ATTR_VLAN(_name, _mode, batadv_show_vlan_##_name, \ batadv_store_vlan_##_name) +#define BATADV_ATTR_HIF_STORE_BOOL(_name, _post_func) \ +ssize_t batadv_store_hif_##_name(struct kobject *kobj, \ + struct attribute *attr, char *buff, \ + size_t count) \ +{ \ + struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \ + struct batadv_hard_iface *hard_iface; \ + size_t res; \ + \ + hard_iface = batadv_hardif_get_by_netdev(net_dev); \ + if (!hard_iface) \ + return 0; \ + \ + res = __batadv_store_bool_attr(buff, count, _post_func, \ + attr, &hard_iface->_name, \ + hard_iface->soft_iface); \ + batadv_hardif_free_ref(hard_iface); \ + return res; \ +} + +#define BATADV_ATTR_HIF_SHOW_BOOL(_name) \ +ssize_t batadv_show_hif_##_name(struct kobject *kobj, \ + struct attribute *attr, char *buff) \ +{ \ + struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \ + struct batadv_hard_iface *hard_iface; \ + size_t res; \ + \ + hard_iface = batadv_hardif_get_by_netdev(net_dev); \ + if (!hard_iface) \ + return 0; \ + \ + res = sprintf(buff, "%s\n", \ + atomic_read(&hard_iface->_name) == 0 ? \ + "disabled" : "enabled"); \ + batadv_hardif_free_ref(hard_iface); \ + return res; \ +} + +/* Use this, if you are going to turn a [name] in the vlan struct on or off */ +#define BATADV_ATTR_HIF_BOOL(_name, _mode, _post_func) \ + static BATADV_ATTR_HIF_STORE_BOOL(_name, _post_func) \ + static BATADV_ATTR_HIF_SHOW_BOOL(_name) \ + static BATADV_ATTR_HIF(_name, _mode, batadv_show_hif_##_name, \ + batadv_store_hif_##_name) + static int batadv_store_bool_attr(char *buff, size_t count, struct net_device *net_dev, const char *attr_name, atomic_t *attr) @@ -844,10 +901,12 @@ static ssize_t batadv_show_iface_status(struct kobject *kobj, static BATADV_ATTR(mesh_iface, S_IRUGO | S_IWUSR, batadv_show_mesh_iface, batadv_store_mesh_iface); static BATADV_ATTR(iface_status, S_IRUGO, batadv_show_iface_status, NULL); +BATADV_ATTR_HIF_BOOL(no_rebroadcast, S_IRUGO | S_IWUSR, NULL); static struct batadv_attribute *batadv_batman_attrs[] = { &batadv_attr_mesh_iface, &batadv_attr_iface_status, + &batadv_attr_hif_no_rebroadcast, NULL, }; diff --git a/types.h b/types.h index 8854c05..39619fb 100644 --- a/types.h +++ b/types.h @@ -101,6 +101,7 @@ struct batadv_hard_iface { struct batadv_hard_iface_bat_iv bat_iv; struct work_struct cleanup_work; struct dentry *debug_dir; + atomic_t no_rebroadcast; }; /**