The call to batadv_nc_skb_forward() fits better in
batadv_send_skb_to_orig(), as this is where the actual next hop is
looked up.

Signed-off-by: Martin Hundebøll <[email protected]>
---

v2: I should make random defines lowercase :)
v3: Do git add before committing and sending patches :|
v4: Don't count non-coded packets twice

network-coding.c | 8 ++------
 network-coding.h | 6 ++----
 routing.c        | 9 +++------
 send.c           | 9 +++++++--
 4 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/network-coding.c b/network-coding.c
index c93df9e..3435729 100644
--- a/network-coding.c
+++ b/network-coding.c
@@ -542,9 +542,6 @@ static bool batadv_nc_fwd_flush(struct batadv_priv 
*bat_priv,
                return false;
 
        /* Send packet */
-       batadv_inc_counter(bat_priv, BATADV_CNT_FORWARD);
-       batadv_add_counter(bat_priv, BATADV_CNT_FORWARD_BYTES,
-                          nc_packet->skb->len + ETH_HLEN);
        list_del(&nc_packet->list);
        batadv_nc_send_packet(nc_packet);
 
@@ -1359,18 +1356,17 @@ static bool batadv_nc_skb_add_to_path(struct sk_buff 
*skb,
  *  buffer
  * @skb: data skb to forward
  * @neigh_node: next hop to forward packet to
- * @ethhdr: pointer to the ethernet header inside the skb
  *
  * Returns true if the skb was consumed (encoded packet sent) or false 
otherwise
  */
 bool batadv_nc_skb_forward(struct sk_buff *skb,
-                          struct batadv_neigh_node *neigh_node,
-                          struct ethhdr *ethhdr)
+                          struct batadv_neigh_node *neigh_node)
 {
        const struct net_device *netdev = neigh_node->if_incoming->soft_iface;
        struct batadv_priv *bat_priv = netdev_priv(netdev);
        struct batadv_unicast_packet *packet;
        struct batadv_nc_path *nc_path;
+       struct ethhdr *ethhdr = eth_hdr(skb);
        __be32 packet_id;
        u8 *payload;
 
diff --git a/network-coding.h b/network-coding.h
index 4fa6d0c..85a4ec8 100644
--- a/network-coding.h
+++ b/network-coding.h
@@ -36,8 +36,7 @@ void batadv_nc_purge_orig(struct batadv_priv *bat_priv,
 void batadv_nc_init_bat_priv(struct batadv_priv *bat_priv);
 void batadv_nc_init_orig(struct batadv_orig_node *orig_node);
 bool batadv_nc_skb_forward(struct sk_buff *skb,
-                          struct batadv_neigh_node *neigh_node,
-                          struct ethhdr *ethhdr);
+                          struct batadv_neigh_node *neigh_node);
 void batadv_nc_skb_store_for_decoding(struct batadv_priv *bat_priv,
                                      struct sk_buff *skb);
 void batadv_nc_skb_store_sniffed_unicast(struct batadv_priv *bat_priv,
@@ -87,8 +86,7 @@ static inline void batadv_nc_init_orig(struct 
batadv_orig_node *orig_node)
 }
 
 static inline bool batadv_nc_skb_forward(struct sk_buff *skb,
-                                        struct batadv_neigh_node *neigh_node,
-                                        struct ethhdr *ethhdr)
+                                        struct batadv_neigh_node *neigh_node)
 {
        return false;
 }
diff --git a/routing.c b/routing.c
index 0e10720..19cf8b6 100644
--- a/routing.c
+++ b/routing.c
@@ -835,16 +835,13 @@ static int batadv_route_unicast_packet(struct sk_buff 
*skb,
        /* decrement ttl */
        unicast_packet->header.ttl--;
 
-       /* network code packet if possible */
-       if (batadv_nc_skb_forward(skb, neigh_node, ethhdr)) {
-               ret = NET_RX_SUCCESS;
-       } else if (batadv_send_skb_to_orig(skb, orig_node, recv_if)) {
-               ret = NET_RX_SUCCESS;
-
+       if (batadv_send_skb_to_orig(skb, orig_node, recv_if)) {
                /* Update stats counter */
                batadv_inc_counter(bat_priv, BATADV_CNT_FORWARD);
                batadv_add_counter(bat_priv, BATADV_CNT_FORWARD_BYTES,
                                   skb->len + ETH_HLEN);
+
+               ret = NET_RX_SUCCESS;
        }
 
 out:
diff --git a/send.c b/send.c
index ed7072a..fa8077a 100644
--- a/send.c
+++ b/send.c
@@ -110,8 +110,13 @@ bool batadv_send_skb_to_orig(struct sk_buff *skb,
        if (!neigh_node)
                return false;
 
-       /* route it */
-       batadv_send_skb_packet(skb, neigh_node->if_incoming, neigh_node->addr);
+       /* try to network code the packet, if it is received on an interface
+        * (i.e. being forwarded). If the packet originates from this node or if
+        * network coding fails, then send the packet as usual.
+        */
+       if (!recv_if || !batadv_nc_skb_forward(skb, neigh_node))
+               batadv_send_skb_packet(skb, neigh_node->if_incoming, 
+                                      neigh_node->addr);
 
        batadv_neigh_node_free_ref(neigh_node);
 
-- 
1.8.2.1

Reply via email to