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 martin@hundeboll.net ---
This is a patch to prepare for the merge of the next fragmentation patches, as these will remove the current lookup of the next-hop in route_unicast_packet().
network-coding.c | 5 ++--- network-coding.h | 6 ++---- routing.c | 9 +++------ send.c | 17 +++++++++++------ 4 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/network-coding.c b/network-coding.c index c93df9e..dc94b76 100644 --- a/network-coding.c +++ b/network-coding.c @@ -1359,18 +1359,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..a241a79 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);
@@ -122,8 +127,8 @@ void batadv_schedule_bat_ogm(struct batadv_hard_iface *hard_iface) { struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface);
- if ((hard_iface->if_status == BATADV_IF_NOT_IN_USE) || - (hard_iface->if_status == BATADV_IF_TO_BE_REMOVED)) + if ((hard_iface->if_status == batadv_if_not_in_use) || + (hard_iface->if_status == batadv_if_to_be_removed)) return;
/* the interface gets activated here to avoid race conditions between @@ -132,8 +137,8 @@ void batadv_schedule_bat_ogm(struct batadv_hard_iface *hard_iface) * outdated packets (especially uninitialized mac addresses) in the * packet queue */ - if (hard_iface->if_status == BATADV_IF_TO_BE_ACTIVATED) - hard_iface->if_status = BATADV_IF_ACTIVE; + if (hard_iface->if_status == batadv_if_to_be_activated) + hard_iface->if_status = batadv_if_active;
bat_priv->bat_algo_ops->bat_ogm_schedule(hard_iface); }