Commit e300d314664ef6746e697d5b581f85114ab1f843

Authored by Linus Lüssing
Committed by Antonio Quartulli
1 parent b8cbd81d09

batman-adv: refine API calls for unicast transmissions of SKBs

With this patch the functions batadv_send_skb_unicast() and
batadv_send_skb_unicast_4addr() are further refined into
batadv_send_skb_via_tt(), batadv_send_skb_via_tt_4addr() and
batadv_send_skb_via_gw(). This way we avoid any "guessing" about where to send
a packet in the unicast forwarding methods and let the callers decide.

This is going to be useful for the upcoming multicast related patches in
particular.

Further, the return values were polished a little to use the more
appropriate NET_XMIT_* defines.

Signed-off-by: Linus Lüssing <linus.luessing@web.de>
Acked-by: Antonio Quartulli <antonio@meshcoding.com>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Signed-off-by: Antonio Quartulli <antonio@meshcoding.com>

Showing 4 changed files with 108 additions and 48 deletions Side-by-side Diff

net/batman-adv/distributed-arp-table.c
... ... @@ -1037,13 +1037,13 @@
1037 1037 * that a node not using the 4addr packet format doesn't support it.
1038 1038 */
1039 1039 if (hdr_size == sizeof(struct batadv_unicast_4addr_packet))
1040   - err = batadv_send_skb_unicast_4addr(bat_priv, skb_new,
1041   - BATADV_P_DAT_CACHE_REPLY,
1042   - vid);
  1040 + err = batadv_send_skb_via_tt_4addr(bat_priv, skb_new,
  1041 + BATADV_P_DAT_CACHE_REPLY,
  1042 + vid);
1043 1043 else
1044   - err = batadv_send_skb_unicast(bat_priv, skb_new, vid);
  1044 + err = batadv_send_skb_via_tt(bat_priv, skb_new, vid);
1045 1045  
1046   - if (!err) {
  1046 + if (err != NET_XMIT_DROP) {
1047 1047 batadv_inc_counter(bat_priv, BATADV_CNT_DAT_CACHED_REPLY_TX);
1048 1048 ret = true;
1049 1049 }
net/batman-adv/send.c
... ... @@ -234,36 +234,32 @@
234 234 }
235 235  
236 236 /**
237   - * batadv_send_generic_unicast_skb - send an skb as unicast
  237 + * batadv_send_skb_unicast - encapsulate and send an skb via unicast
238 238 * @bat_priv: the bat priv with all the soft interface information
239 239 * @skb: payload to send
240 240 * @packet_type: the batman unicast packet type to use
241 241 * @packet_subtype: the unicast 4addr packet subtype (only relevant for unicast
242 242 * 4addr packets)
  243 + * @orig_node: the originator to send the packet to
243 244 * @vid: the vid to be used to search the translation table
244 245 *
245   - * Returns 1 in case of error or 0 otherwise.
  246 + * Wrap the given skb into a batman-adv unicast or unicast-4addr header
  247 + * depending on whether BATADV_UNICAST or BATADV_UNICAST_4ADDR was supplied
  248 + * as packet_type. Then send this frame to the given orig_node and release a
  249 + * reference to this orig_node.
  250 + *
  251 + * Returns NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise.
246 252 */
247   -int batadv_send_skb_generic_unicast(struct batadv_priv *bat_priv,
248   - struct sk_buff *skb, int packet_type,
249   - int packet_subtype,
250   - unsigned short vid)
  253 +static int batadv_send_skb_unicast(struct batadv_priv *bat_priv,
  254 + struct sk_buff *skb, int packet_type,
  255 + int packet_subtype,
  256 + struct batadv_orig_node *orig_node,
  257 + unsigned short vid)
251 258 {
252 259 struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
253 260 struct batadv_unicast_packet *unicast_packet;
254   - struct batadv_orig_node *orig_node;
255   - int ret = NET_RX_DROP;
  261 + int ret = NET_XMIT_DROP;
256 262  
257   - /* get routing information */
258   - if (is_multicast_ether_addr(ethhdr->h_dest))
259   - orig_node = batadv_gw_get_selected_orig(bat_priv);
260   - else
261   - /* check for tt host - increases orig_node refcount.
262   - * returns NULL in case of AP isolation
263   - */
264   - orig_node = batadv_transtable_search(bat_priv, ethhdr->h_source,
265   - ethhdr->h_dest, vid);
266   -
267 263 if (!orig_node)
268 264 goto out;
269 265  
270 266  
271 267  
... ... @@ -296,14 +292,65 @@
296 292 unicast_packet->ttvn = unicast_packet->ttvn - 1;
297 293  
298 294 if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP)
299   - ret = 0;
  295 + ret = NET_XMIT_SUCCESS;
300 296  
301 297 out:
302 298 if (orig_node)
303 299 batadv_orig_node_free_ref(orig_node);
304   - if (ret == NET_RX_DROP)
  300 + if (ret == NET_XMIT_DROP)
305 301 kfree_skb(skb);
306 302 return ret;
  303 +}
  304 +
  305 +/**
  306 + * batadv_send_skb_via_tt_generic - send an skb via TT lookup
  307 + * @bat_priv: the bat priv with all the soft interface information
  308 + * @skb: payload to send
  309 + * @packet_type: the batman unicast packet type to use
  310 + * @packet_subtype: the unicast 4addr packet subtype (only relevant for unicast
  311 + * 4addr packets)
  312 + * @vid: the vid to be used to search the translation table
  313 + *
  314 + * Look up the recipient node for the destination address in the ethernet
  315 + * header via the translation table. Wrap the given skb into a batman-adv
  316 + * unicast or unicast-4addr header depending on whether BATADV_UNICAST or
  317 + * BATADV_UNICAST_4ADDR was supplied as packet_type. Then send this frame
  318 + * to the according destination node.
  319 + *
  320 + * Returns NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise.
  321 + */
  322 +int batadv_send_skb_via_tt_generic(struct batadv_priv *bat_priv,
  323 + struct sk_buff *skb, int packet_type,
  324 + int packet_subtype, unsigned short vid)
  325 +{
  326 + struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
  327 + struct batadv_orig_node *orig_node;
  328 +
  329 + orig_node = batadv_transtable_search(bat_priv, ethhdr->h_source,
  330 + ethhdr->h_dest, vid);
  331 + return batadv_send_skb_unicast(bat_priv, skb, packet_type,
  332 + packet_subtype, orig_node, vid);
  333 +}
  334 +
  335 +/**
  336 + * batadv_send_skb_via_gw - send an skb via gateway lookup
  337 + * @bat_priv: the bat priv with all the soft interface information
  338 + * @skb: payload to send
  339 + * @vid: the vid to be used to search the translation table
  340 + *
  341 + * Look up the currently selected gateway. Wrap the given skb into a batman-adv
  342 + * unicast header and send this frame to this gateway node.
  343 + *
  344 + * Returns NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise.
  345 + */
  346 +int batadv_send_skb_via_gw(struct batadv_priv *bat_priv, struct sk_buff *skb,
  347 + unsigned short vid)
  348 +{
  349 + struct batadv_orig_node *orig_node;
  350 +
  351 + orig_node = batadv_gw_get_selected_orig(bat_priv);
  352 + return batadv_send_skb_unicast(bat_priv, skb, BATADV_UNICAST, 0,
  353 + orig_node, vid);
307 354 }
308 355  
309 356 void batadv_schedule_bat_ogm(struct batadv_hard_iface *hard_iface)
net/batman-adv/send.h
... ... @@ -38,45 +38,54 @@
38 38 struct sk_buff *skb,
39 39 struct batadv_orig_node *orig_node,
40 40 int packet_subtype);
41   -int batadv_send_skb_generic_unicast(struct batadv_priv *bat_priv,
42   - struct sk_buff *skb, int packet_type,
43   - int packet_subtype,
44   - unsigned short vid);
  41 +int batadv_send_skb_via_tt_generic(struct batadv_priv *bat_priv,
  42 + struct sk_buff *skb, int packet_type,
  43 + int packet_subtype, unsigned short vid);
  44 +int batadv_send_skb_via_gw(struct batadv_priv *bat_priv, struct sk_buff *skb,
  45 + unsigned short vid);
45 46  
46 47 /**
47   - * batadv_send_unicast_skb - send the skb encapsulated in a unicast packet
  48 + * batadv_send_skb_via_tt - send an skb via TT lookup
48 49 * @bat_priv: the bat priv with all the soft interface information
49 50 * @skb: the payload to send
50 51 * @vid: the vid to be used to search the translation table
51 52 *
52   - * Returns 1 in case of error or 0 otherwise.
  53 + * Look up the recipient node for the destination address in the ethernet
  54 + * header via the translation table. Wrap the given skb into a batman-adv
  55 + * unicast header. Then send this frame to the according destination node.
  56 + *
  57 + * Returns NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise.
53 58 */
54   -static inline int batadv_send_skb_unicast(struct batadv_priv *bat_priv,
55   - struct sk_buff *skb,
56   - unsigned short vid)
  59 +static inline int batadv_send_skb_via_tt(struct batadv_priv *bat_priv,
  60 + struct sk_buff *skb,
  61 + unsigned short vid)
57 62 {
58   - return batadv_send_skb_generic_unicast(bat_priv, skb, BATADV_UNICAST,
59   - 0, vid);
  63 + return batadv_send_skb_via_tt_generic(bat_priv, skb, BATADV_UNICAST, 0,
  64 + vid);
60 65 }
61 66  
62 67 /**
63   - * batadv_send_4addr_unicast_skb - send the skb encapsulated in a unicast 4addr
64   - * packet
  68 + * batadv_send_skb_via_tt_4addr - send an skb via TT lookup
65 69 * @bat_priv: the bat priv with all the soft interface information
66 70 * @skb: the payload to send
67 71 * @packet_subtype: the unicast 4addr packet subtype to use
68 72 * @vid: the vid to be used to search the translation table
69 73 *
70   - * Returns 1 in case of error or 0 otherwise.
  74 + * Look up the recipient node for the destination address in the ethernet
  75 + * header via the translation table. Wrap the given skb into a batman-adv
  76 + * unicast-4addr header. Then send this frame to the according destination
  77 + * node.
  78 + *
  79 + * Returns NET_XMIT_DROP in case of error or NET_XMIT_SUCCESS otherwise.
71 80 */
72   -static inline int batadv_send_skb_unicast_4addr(struct batadv_priv *bat_priv,
73   - struct sk_buff *skb,
74   - int packet_subtype,
75   - unsigned short vid)
  81 +static inline int batadv_send_skb_via_tt_4addr(struct batadv_priv *bat_priv,
  82 + struct sk_buff *skb,
  83 + int packet_subtype,
  84 + unsigned short vid)
76 85 {
77   - return batadv_send_skb_generic_unicast(bat_priv, skb,
78   - BATADV_UNICAST_4ADDR,
79   - packet_subtype, vid);
  86 + return batadv_send_skb_via_tt_generic(bat_priv, skb,
  87 + BATADV_UNICAST_4ADDR,
  88 + packet_subtype, vid);
80 89 }
81 90  
82 91 #endif /* _NET_BATMAN_ADV_SEND_H_ */
net/batman-adv/soft-interface.c
... ... @@ -298,8 +298,12 @@
298 298  
299 299 batadv_dat_snoop_outgoing_arp_reply(bat_priv, skb);
300 300  
301   - ret = batadv_send_skb_unicast(bat_priv, skb, vid);
302   - if (ret != 0)
  301 + if (is_multicast_ether_addr(ethhdr->h_dest))
  302 + ret = batadv_send_skb_via_gw(bat_priv, skb, vid);
  303 + else
  304 + ret = batadv_send_skb_via_tt(bat_priv, skb, vid);
  305 +
  306 + if (ret == NET_XMIT_DROP)
303 307 goto dropped_freed;
304 308 }
305 309