0001-batman-adv-Add-no-rebroadcast-patch.patch 8.1 KB

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