0003-batman-adv-introduce-no_rebroadcast-option.patch 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. From: Matthias Schiffer <mschiffer@universe-factory.net>
  2. Date: Thu, 2 Apr 2015 20:24:14 +0200
  3. Subject: batman-adv: introduce 'no_rebroadcast' option
  4. diff --git a/batman-adv/files/lib/netifd/proto/batadv.sh b/batman-adv/files/lib/netifd/proto/batadv.sh
  5. index 632a209..01f567f 100644
  6. --- a/batman-adv/files/lib/netifd/proto/batadv.sh
  7. +++ b/batman-adv/files/lib/netifd/proto/batadv.sh
  8. @@ -6,16 +6,19 @@ init_proto "$@"
  9. proto_batadv_init_config() {
  10. proto_config_add_string "mesh"
  11. + proto_config_add_string "mesh_no_rebroadcast"
  12. }
  13. proto_batadv_setup() {
  14. local config="$1"
  15. local iface="$2"
  16. - local mesh
  17. - json_get_vars mesh
  18. + local mesh mesh_no_rebroadcast
  19. + json_get_vars mesh mesh_no_rebroadcast
  20. echo "$mesh" > "/sys/class/net/$iface/batman_adv/mesh_iface"
  21. + [ -n "$mesh_no_rebroadcast" ] && echo "$mesh_no_rebroadcast" > "/sys/class/net/$iface/batman_adv/no_rebroadcast"
  22. +
  23. proto_init_update "$iface" 1
  24. proto_send_update "$config"
  25. }
  26. diff --git a/batman-adv/patches/0001-batman-adv-introduce-no_rebroadcast-option.patch b/batman-adv/patches/0001-batman-adv-introduce-no_rebroadcast-option.patch
  27. new file mode 100644
  28. index 0000000..cd79917
  29. --- /dev/null
  30. +++ b/batman-adv/patches/0001-batman-adv-introduce-no_rebroadcast-option.patch
  31. @@ -0,0 +1,185 @@
  32. +From 5ba3f1eac041857deabe39432fdfe1a584bbdd81 Mon Sep 17 00:00:00 2001
  33. +Message-Id: <5ba3f1eac041857deabe39432fdfe1a584bbdd81.1420645650.git.mschiffer@universe-factory.net>
  34. +From: =?UTF-8?q?Linus=20L=C3=BCssing?= <linus.luessing@web.de>
  35. +Date: Tue, 24 Sep 2013 04:36:27 +0200
  36. +Subject: [PATCH] batman-adv: introduce 'no_rebroadcast' option
  37. +MIME-Version: 1.0
  38. +Content-Type: text/plain; charset=UTF-8
  39. +Content-Transfer-Encoding: 8bit
  40. +
  41. +This patch introduces a new sysfs option named "no_rebroadcast" on
  42. +a per hard interface basis. It allows manually enabling a split-horizon
  43. +like behaviour for the layer 2 multicast payload frames, in that
  44. +incoming multicast payload frames on such a hard interface are only
  45. +being rebroadcasted on all interfaces except the incoming one instead
  46. +of being rebroadcasted on all interfaces.
  47. +
  48. +Such an option should only be enabled if you are certain that these
  49. +rebroadcasts are unnecessary. This is usually the case for instance
  50. +for point-to-point wifi longshots or wired links.
  51. +
  52. +This option can especially safe a significant amount of upload overhead
  53. +if the neighbourhood on a link is rather large, for instance in some
  54. +transitive, symmetric VPN configurations.
  55. +
  56. +Using this option wrongly will break your mesh network, use this option
  57. +wisely and at your own risk!
  58. +
  59. +Signed-off-by: Linus Lüssing <linus.luessing@web.de>
  60. +---
  61. + hard-interface.c | 2 ++
  62. + send.c | 4 ++++
  63. + sysfs-class-net-batman-adv | 10 ++++++++
  64. + sysfs.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++
  65. + types.h | 1 +
  66. + 5 files changed, 76 insertions(+)
  67. +
  68. +diff --git a/hard-interface.c b/hard-interface.c
  69. +index fbda6b5..3997f9c 100644
  70. +--- a/hard-interface.c
  71. ++++ b/hard-interface.c
  72. +@@ -591,6 +591,8 @@ batadv_hardif_add_interface(struct net_device *net_dev)
  73. + /* extra reference for return */
  74. + atomic_set(&hard_iface->refcount, 2);
  75. +
  76. ++ atomic_set(&hard_iface->no_rebroadcast, 0);
  77. ++
  78. + batadv_check_known_mac_addr(hard_iface->net_dev);
  79. + list_add_tail_rcu(&hard_iface->list, &batadv_hardif_list);
  80. +
  81. +diff --git a/send.c b/send.c
  82. +index d27161e..4383a66 100644
  83. +--- a/send.c
  84. ++++ b/send.c
  85. +@@ -513,6 +513,10 @@ static void batadv_send_outstanding_bcast_packet(struct work_struct *work)
  86. + if (forw_packet->num_packets >= hard_iface->num_bcasts)
  87. + continue;
  88. +
  89. ++ if (atomic_read(&hard_iface->no_rebroadcast) &&
  90. ++ forw_packet->skb->dev == hard_iface->net_dev)
  91. ++ continue;
  92. ++
  93. + /* send a copy of the saved skb */
  94. + skb1 = skb_clone(forw_packet->skb, GFP_ATOMIC);
  95. + if (skb1)
  96. +diff --git a/sysfs-class-net-batman-adv b/sysfs-class-net-batman-adv
  97. +index 7f34a95..cf7fe00 100644
  98. +--- a/sysfs-class-net-batman-adv
  99. ++++ b/sysfs-class-net-batman-adv
  100. +@@ -13,3 +13,13 @@ Description:
  101. + displays the batman mesh interface this <iface>
  102. + currently is associated with.
  103. +
  104. ++What: /sys/class/net/<iface>/batman-adv/no_rebroadcast
  105. ++Date: Sep 2013
  106. ++Contact: Linus Lüssing <linus.luessing@web.de>
  107. ++Description:
  108. ++ With this option set incoming multicast payload frames on
  109. ++ <iface> are not being rebroadcasted on <iface> again. This
  110. ++ option should be set on links which are known to be transitive
  111. ++ and symmetric only, for instance point-to-point wifi longshots
  112. ++ or wired links. Using this option wrongly is going to
  113. ++ break your mesh network, use at your own risk!
  114. +diff --git a/sysfs.c b/sysfs.c
  115. +index fc47baa..adaeca4 100644
  116. +--- a/sysfs.c
  117. ++++ b/sysfs.c
  118. +@@ -110,6 +110,17 @@ struct batadv_attribute batadv_attr_vlan_##_name = { \
  119. + .store = _store, \
  120. + }
  121. +
  122. ++/* Use this, if you have customized show and store functions
  123. ++ * for hard interface attrs
  124. ++ */
  125. ++#define BATADV_ATTR_HIF(_name, _mode, _show, _store) \
  126. ++struct batadv_attribute batadv_attr_hif_##_name = { \
  127. ++ .attr = {.name = __stringify(_name), \
  128. ++ .mode = _mode }, \
  129. ++ .show = _show, \
  130. ++ .store = _store, \
  131. ++};
  132. ++
  133. + /* Use this, if you have customized show and store functions */
  134. + #define BATADV_ATTR(_name, _mode, _show, _store) \
  135. + struct batadv_attribute batadv_attr_##_name = { \
  136. +@@ -221,6 +232,52 @@ ssize_t batadv_show_vlan_##_name(struct kobject *kobj, \
  137. + static BATADV_ATTR_VLAN(_name, _mode, batadv_show_vlan_##_name, \
  138. + batadv_store_vlan_##_name)
  139. +
  140. ++#define BATADV_ATTR_HIF_STORE_BOOL(_name, _post_func) \
  141. ++ssize_t batadv_store_hif_##_name(struct kobject *kobj, \
  142. ++ struct attribute *attr, char *buff, \
  143. ++ size_t count) \
  144. ++{ \
  145. ++ struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
  146. ++ struct batadv_hard_iface *hard_iface; \
  147. ++ size_t res; \
  148. ++ \
  149. ++ hard_iface = batadv_hardif_get_by_netdev(net_dev); \
  150. ++ if (!hard_iface) \
  151. ++ return 0; \
  152. ++ \
  153. ++ res = __batadv_store_bool_attr(buff, count, _post_func, \
  154. ++ attr, &hard_iface->_name, \
  155. ++ hard_iface->soft_iface); \
  156. ++ batadv_hardif_free_ref(hard_iface); \
  157. ++ return res; \
  158. ++}
  159. ++
  160. ++#define BATADV_ATTR_HIF_SHOW_BOOL(_name) \
  161. ++ssize_t batadv_show_hif_##_name(struct kobject *kobj, \
  162. ++ struct attribute *attr, char *buff) \
  163. ++{ \
  164. ++ struct net_device *net_dev = batadv_kobj_to_netdev(kobj); \
  165. ++ struct batadv_hard_iface *hard_iface; \
  166. ++ size_t res; \
  167. ++ \
  168. ++ hard_iface = batadv_hardif_get_by_netdev(net_dev); \
  169. ++ if (!hard_iface) \
  170. ++ return 0; \
  171. ++ \
  172. ++ res = sprintf(buff, "%s\n", \
  173. ++ atomic_read(&hard_iface->_name) == 0 ? \
  174. ++ "disabled" : "enabled"); \
  175. ++ batadv_hardif_free_ref(hard_iface); \
  176. ++ return res; \
  177. ++}
  178. ++
  179. ++/* Use this, if you are going to turn a [name] in the vlan struct on or off */
  180. ++#define BATADV_ATTR_HIF_BOOL(_name, _mode, _post_func) \
  181. ++ static BATADV_ATTR_HIF_STORE_BOOL(_name, _post_func) \
  182. ++ static BATADV_ATTR_HIF_SHOW_BOOL(_name) \
  183. ++ static BATADV_ATTR_HIF(_name, _mode, batadv_show_hif_##_name, \
  184. ++ batadv_store_hif_##_name)
  185. ++
  186. + static int batadv_store_bool_attr(char *buff, size_t count,
  187. + struct net_device *net_dev,
  188. + const char *attr_name, atomic_t *attr)
  189. +@@ -844,10 +901,12 @@ static ssize_t batadv_show_iface_status(struct kobject *kobj,
  190. + static BATADV_ATTR(mesh_iface, S_IRUGO | S_IWUSR, batadv_show_mesh_iface,
  191. + batadv_store_mesh_iface);
  192. + static BATADV_ATTR(iface_status, S_IRUGO, batadv_show_iface_status, NULL);
  193. ++BATADV_ATTR_HIF_BOOL(no_rebroadcast, S_IRUGO | S_IWUSR, NULL);
  194. +
  195. + static struct batadv_attribute *batadv_batman_attrs[] = {
  196. + &batadv_attr_mesh_iface,
  197. + &batadv_attr_iface_status,
  198. ++ &batadv_attr_hif_no_rebroadcast,
  199. + NULL,
  200. + };
  201. +
  202. +diff --git a/types.h b/types.h
  203. +index 8854c05..39619fb 100644
  204. +--- a/types.h
  205. ++++ b/types.h
  206. +@@ -101,6 +101,7 @@ struct batadv_hard_iface {
  207. + struct batadv_hard_iface_bat_iv bat_iv;
  208. + struct work_struct cleanup_work;
  209. + struct dentry *debug_dir;
  210. ++ atomic_t no_rebroadcast;
  211. + };
  212. +
  213. + /**
  214. +--
  215. +2.2.1
  216. +