batman-adv: make is_my_mac() check for the current mesh only
[openwrt/svn-archive/archive.git] / net / batman-adv / patches / 0003-batman-adv-make-is_my_mac-check-for-the-current-mesh.patch
1 From 647d23f3e358d9fa4b1a8f0bb67a3e6bff30d4a1 Mon Sep 17 00:00:00 2001
2 From: Antonio Quartulli <ordex@autistici.org>
3 Date: Wed, 3 Apr 2013 19:10:26 +0200
4 Subject: [PATCH 3/3] batman-adv: make is_my_mac() check for the current mesh
5 only
6
7 On a multi-mesh node (a node running more than one batman-adv
8 virtual interface) batadv_is_my_mac() has to check MAC
9 addresses of hard interfaces belonging to the current mesh
10 only.
11
12 Signed-off-by: Antonio Quartulli <ordex@autistici.org>
13 Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
14 ---
15 main.c | 5 ++++-
16 main.h | 2 +-
17 routing.c | 38 ++++++++++++++++++++------------------
18 translation-table.c | 2 +-
19 vis.c | 4 ++--
20 5 files changed, 28 insertions(+), 23 deletions(-)
21
22 diff --git a/main.c b/main.c
23 index 0488d70..fa563e4 100644
24 --- a/main.c
25 +++ b/main.c
26 @@ -169,7 +169,7 @@ void batadv_mesh_free(struct net_device *soft_iface)
27 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
28 }
29
30 -int batadv_is_my_mac(const uint8_t *addr)
31 +int batadv_is_my_mac(struct batadv_priv *bat_priv, const uint8_t *addr)
32 {
33 const struct batadv_hard_iface *hard_iface;
34
35 @@ -178,6 +178,9 @@ int batadv_is_my_mac(const uint8_t *addr)
36 if (hard_iface->if_status != BATADV_IF_ACTIVE)
37 continue;
38
39 + if (hard_iface->soft_iface != bat_priv->soft_iface)
40 + continue;
41 +
42 if (batadv_compare_eth(hard_iface->net_dev->dev_addr, addr)) {
43 rcu_read_unlock();
44 return 1;
45 diff --git a/main.h b/main.h
46 index 08c5dd1..fcb5d65 100644
47 --- a/main.h
48 +++ b/main.h
49 @@ -164,7 +164,7 @@ extern struct workqueue_struct *batadv_event_workqueue;
50
51 int batadv_mesh_init(struct net_device *soft_iface);
52 void batadv_mesh_free(struct net_device *soft_iface);
53 -int batadv_is_my_mac(const uint8_t *addr);
54 +int batadv_is_my_mac(struct batadv_priv *bat_priv, const uint8_t *addr);
55 struct batadv_hard_iface *
56 batadv_seq_print_text_primary_if_get(struct seq_file *seq);
57 int batadv_batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
58 diff --git a/routing.c b/routing.c
59 index 5ee21ce..319f290 100644
60 --- a/routing.c
61 +++ b/routing.c
62 @@ -402,7 +402,7 @@ int batadv_recv_icmp_packet(struct sk_buff *skb,
63 goto out;
64
65 /* not for me */
66 - if (!batadv_is_my_mac(ethhdr->h_dest))
67 + if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest))
68 goto out;
69
70 icmp_packet = (struct batadv_icmp_packet_rr *)skb->data;
71 @@ -416,7 +416,7 @@ int batadv_recv_icmp_packet(struct sk_buff *skb,
72 }
73
74 /* packet for me */
75 - if (batadv_is_my_mac(icmp_packet->dst))
76 + if (batadv_is_my_mac(bat_priv, icmp_packet->dst))
77 return batadv_recv_my_icmp_packet(bat_priv, skb, hdr_size);
78
79 /* TTL exceeded */
80 @@ -548,7 +548,8 @@ batadv_find_ifalter_router(struct batadv_orig_node *primary_orig,
81 return router;
82 }
83
84 -static int batadv_check_unicast_packet(struct sk_buff *skb, int hdr_size)
85 +static int batadv_check_unicast_packet(struct batadv_priv *bat_priv,
86 + struct sk_buff *skb, int hdr_size)
87 {
88 struct ethhdr *ethhdr;
89
90 @@ -567,7 +568,7 @@ static int batadv_check_unicast_packet(struct sk_buff *skb, int hdr_size)
91 return -1;
92
93 /* not for me */
94 - if (!batadv_is_my_mac(ethhdr->h_dest))
95 + if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest))
96 return -1;
97
98 return 0;
99 @@ -582,7 +583,7 @@ int batadv_recv_tt_query(struct sk_buff *skb, struct batadv_hard_iface *recv_if)
100 char tt_flag;
101 size_t packet_size;
102
103 - if (batadv_check_unicast_packet(skb, hdr_size) < 0)
104 + if (batadv_check_unicast_packet(bat_priv, skb, hdr_size) < 0)
105 return NET_RX_DROP;
106
107 /* I could need to modify it */
108 @@ -614,7 +615,7 @@ int batadv_recv_tt_query(struct sk_buff *skb, struct batadv_hard_iface *recv_if)
109 case BATADV_TT_RESPONSE:
110 batadv_inc_counter(bat_priv, BATADV_CNT_TT_RESPONSE_RX);
111
112 - if (batadv_is_my_mac(tt_query->dst)) {
113 + if (batadv_is_my_mac(bat_priv, tt_query->dst)) {
114 /* packet needs to be linearized to access the TT
115 * changes
116 */
117 @@ -657,14 +658,15 @@ int batadv_recv_roam_adv(struct sk_buff *skb, struct batadv_hard_iface *recv_if)
118 struct batadv_roam_adv_packet *roam_adv_packet;
119 struct batadv_orig_node *orig_node;
120
121 - if (batadv_check_unicast_packet(skb, sizeof(*roam_adv_packet)) < 0)
122 + if (batadv_check_unicast_packet(bat_priv, skb,
123 + sizeof(*roam_adv_packet)) < 0)
124 goto out;
125
126 batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_RX);
127
128 roam_adv_packet = (struct batadv_roam_adv_packet *)skb->data;
129
130 - if (!batadv_is_my_mac(roam_adv_packet->dst))
131 + if (!batadv_is_my_mac(bat_priv, roam_adv_packet->dst))
132 return batadv_route_unicast_packet(skb, recv_if);
133
134 /* check if it is a backbone gateway. we don't accept
135 @@ -967,7 +969,7 @@ static int batadv_check_unicast_ttvn(struct batadv_priv *bat_priv,
136 * last time) the packet had an updated information or not
137 */
138 curr_ttvn = (uint8_t)atomic_read(&bat_priv->tt.vn);
139 - if (!batadv_is_my_mac(unicast_packet->dest)) {
140 + if (!batadv_is_my_mac(bat_priv, unicast_packet->dest)) {
141 orig_node = batadv_orig_hash_find(bat_priv,
142 unicast_packet->dest);
143 /* if it is not possible to find the orig_node representing the
144 @@ -1044,14 +1046,14 @@ int batadv_recv_unicast_packet(struct sk_buff *skb,
145 if (is4addr)
146 hdr_size = sizeof(*unicast_4addr_packet);
147
148 - if (batadv_check_unicast_packet(skb, hdr_size) < 0)
149 + if (batadv_check_unicast_packet(bat_priv, skb, hdr_size) < 0)
150 return NET_RX_DROP;
151
152 if (!batadv_check_unicast_ttvn(bat_priv, skb))
153 return NET_RX_DROP;
154
155 /* packet for me */
156 - if (batadv_is_my_mac(unicast_packet->dest)) {
157 + if (batadv_is_my_mac(bat_priv, unicast_packet->dest)) {
158 if (is4addr) {
159 batadv_dat_inc_counter(bat_priv,
160 unicast_4addr_packet->subtype);
161 @@ -1088,7 +1090,7 @@ int batadv_recv_ucast_frag_packet(struct sk_buff *skb,
162 struct sk_buff *new_skb = NULL;
163 int ret;
164
165 - if (batadv_check_unicast_packet(skb, hdr_size) < 0)
166 + if (batadv_check_unicast_packet(bat_priv, skb, hdr_size) < 0)
167 return NET_RX_DROP;
168
169 if (!batadv_check_unicast_ttvn(bat_priv, skb))
170 @@ -1097,7 +1099,7 @@ int batadv_recv_ucast_frag_packet(struct sk_buff *skb,
171 unicast_packet = (struct batadv_unicast_frag_packet *)skb->data;
172
173 /* packet for me */
174 - if (batadv_is_my_mac(unicast_packet->dest)) {
175 + if (batadv_is_my_mac(bat_priv, unicast_packet->dest)) {
176 ret = batadv_frag_reassemble_skb(skb, bat_priv, &new_skb);
177
178 if (ret == NET_RX_DROP)
179 @@ -1151,13 +1153,13 @@ int batadv_recv_bcast_packet(struct sk_buff *skb,
180 goto out;
181
182 /* ignore broadcasts sent by myself */
183 - if (batadv_is_my_mac(ethhdr->h_source))
184 + if (batadv_is_my_mac(bat_priv, ethhdr->h_source))
185 goto out;
186
187 bcast_packet = (struct batadv_bcast_packet *)skb->data;
188
189 /* ignore broadcasts originated by myself */
190 - if (batadv_is_my_mac(bcast_packet->orig))
191 + if (batadv_is_my_mac(bat_priv, bcast_packet->orig))
192 goto out;
193
194 if (bcast_packet->header.ttl < 2)
195 @@ -1243,14 +1245,14 @@ int batadv_recv_vis_packet(struct sk_buff *skb,
196 ethhdr = (struct ethhdr *)skb_mac_header(skb);
197
198 /* not for me */
199 - if (!batadv_is_my_mac(ethhdr->h_dest))
200 + if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest))
201 return NET_RX_DROP;
202
203 /* ignore own packets */
204 - if (batadv_is_my_mac(vis_packet->vis_orig))
205 + if (batadv_is_my_mac(bat_priv, vis_packet->vis_orig))
206 return NET_RX_DROP;
207
208 - if (batadv_is_my_mac(vis_packet->sender_orig))
209 + if (batadv_is_my_mac(bat_priv, vis_packet->sender_orig))
210 return NET_RX_DROP;
211
212 switch (vis_packet->vis_type) {
213 diff --git a/translation-table.c b/translation-table.c
214 index 98a66a0..7abee19 100644
215 --- a/translation-table.c
216 +++ b/translation-table.c
217 @@ -1953,7 +1953,7 @@ out:
218 bool batadv_send_tt_response(struct batadv_priv *bat_priv,
219 struct batadv_tt_query_packet *tt_request)
220 {
221 - if (batadv_is_my_mac(tt_request->dst)) {
222 + if (batadv_is_my_mac(bat_priv, tt_request->dst)) {
223 /* don't answer backbone gws! */
224 if (batadv_bla_is_backbone_gw_orig(bat_priv, tt_request->src))
225 return true;
226 diff --git a/vis.c b/vis.c
227 index c053244..6a1e646 100644
228 --- a/vis.c
229 +++ b/vis.c
230 @@ -477,7 +477,7 @@ void batadv_receive_client_update_packet(struct batadv_priv *bat_priv,
231
232 /* Are we the target for this VIS packet? */
233 if (vis_server == BATADV_VIS_TYPE_SERVER_SYNC &&
234 - batadv_is_my_mac(vis_packet->target_orig))
235 + batadv_is_my_mac(bat_priv, vis_packet->target_orig))
236 are_target = 1;
237
238 spin_lock_bh(&bat_priv->vis.hash_lock);
239 @@ -496,7 +496,7 @@ void batadv_receive_client_update_packet(struct batadv_priv *bat_priv,
240 batadv_send_list_add(bat_priv, info);
241
242 /* ... we're not the recipient (and thus need to forward). */
243 - } else if (!batadv_is_my_mac(packet->target_orig)) {
244 + } else if (!batadv_is_my_mac(bat_priv, packet->target_orig)) {
245 batadv_send_list_add(bat_priv, info);
246 }
247
248 --
249 1.7.10.4
250