From: Simon Wunderlich <sw@simonwunderlich.de>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH 12/17] batman-adv: Consume skb in batadv_send_skb_to_orig
Date: Tue, 8 Nov 2016 17:45:21 +0100 [thread overview]
Message-ID: <20161108164526.7518-13-sw@simonwunderlich.de> (raw)
In-Reply-To: <20161108164526.7518-1-sw@simonwunderlich.de>
From: Sven Eckelmann <sven@narfation.org>
Sending functions in Linux consume the supplied skbuff. Doing the same in
batadv_send_skb_to_orig avoids the hack of returning -1 (-EPERM) to signal
the caller that he is responsible for cleaning up the skb.
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
net/batman-adv/routing.c | 11 ++---------
net/batman-adv/send.c | 39 ++++++++++++++++++++++-----------------
net/batman-adv/tp_meter.c | 6 ------
net/batman-adv/tvlv.c | 5 +----
4 files changed, 25 insertions(+), 36 deletions(-)
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c
index a4cb157..4d2679a 100644
--- a/net/batman-adv/routing.c
+++ b/net/batman-adv/routing.c
@@ -262,9 +262,6 @@ static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv,
icmph->ttl = BATADV_TTL;
res = batadv_send_skb_to_orig(skb, orig_node, NULL);
- if (res == -1)
- goto out;
-
ret = NET_RX_SUCCESS;
break;
@@ -325,8 +322,7 @@ static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv,
icmp_packet->ttl = BATADV_TTL;
res = batadv_send_skb_to_orig(skb, orig_node, NULL);
- if (res != -1)
- ret = NET_RX_SUCCESS;
+ ret = NET_RX_SUCCESS;
out:
if (primary_if)
@@ -413,8 +409,7 @@ int batadv_recv_icmp_packet(struct sk_buff *skb,
/* route it */
res = batadv_send_skb_to_orig(skb, orig_node, recv_if);
- if (res != -1)
- ret = NET_RX_SUCCESS;
+ ret = NET_RX_SUCCESS;
out:
if (orig_node)
@@ -702,8 +697,6 @@ static int batadv_route_unicast_packet(struct sk_buff *skb,
len = skb->len;
res = batadv_send_skb_to_orig(skb, orig_node, recv_if);
- if (res == -1)
- goto out;
/* translate transmit result into receive result */
if (res == NET_XMIT_SUCCESS) {
diff --git a/net/batman-adv/send.c b/net/batman-adv/send.c
index 0f86293..b00aac7 100644
--- a/net/batman-adv/send.c
+++ b/net/batman-adv/send.c
@@ -165,11 +165,9 @@ int batadv_send_unicast_skb(struct sk_buff *skb,
* host, NULL can be passed as recv_if and no interface alternating is
* attempted.
*
- * Return: -1 on failure (and the skb is not consumed), -EINPROGRESS if the
- * skb is buffered for later transmit or the NET_XMIT status returned by the
+ * Return: negative errno code on a failure, -EINPROGRESS if the skb is
+ * buffered for later transmit or the NET_XMIT status returned by the
* lower routine if the packet has been passed down.
- *
- * If the returning value is not -1 the skb has been consumed.
*/
int batadv_send_skb_to_orig(struct sk_buff *skb,
struct batadv_orig_node *orig_node,
@@ -177,12 +175,14 @@ int batadv_send_skb_to_orig(struct sk_buff *skb,
{
struct batadv_priv *bat_priv = orig_node->bat_priv;
struct batadv_neigh_node *neigh_node;
- int ret = -1;
+ int ret;
/* batadv_find_router() increases neigh_nodes refcount if found. */
neigh_node = batadv_find_router(bat_priv, orig_node, recv_if);
- if (!neigh_node)
- goto out;
+ if (!neigh_node) {
+ ret = -EINVAL;
+ goto free_skb;
+ }
/* Check if the skb is too large to send in one piece and fragment
* it if needed.
@@ -191,8 +191,10 @@ int batadv_send_skb_to_orig(struct sk_buff *skb,
skb->len > neigh_node->if_incoming->net_dev->mtu) {
/* Fragment and send packet. */
ret = batadv_frag_send_packet(skb, orig_node, neigh_node);
+ /* skb was consumed */
+ skb = NULL;
- goto out;
+ goto put_neigh_node;
}
/* try to network code the packet, if it is received on an interface
@@ -204,9 +206,13 @@ int batadv_send_skb_to_orig(struct sk_buff *skb,
else
ret = batadv_send_unicast_skb(skb, neigh_node);
-out:
- if (neigh_node)
- batadv_neigh_node_put(neigh_node);
+ /* skb was consumed */
+ skb = NULL;
+
+put_neigh_node:
+ batadv_neigh_node_put(neigh_node);
+free_skb:
+ kfree_skb(skb);
return ret;
}
@@ -327,7 +333,7 @@ int batadv_send_skb_unicast(struct batadv_priv *bat_priv,
{
struct batadv_unicast_packet *unicast_packet;
struct ethhdr *ethhdr;
- int res, ret = NET_XMIT_DROP;
+ int ret = NET_XMIT_DROP;
if (!orig_node)
goto out;
@@ -364,13 +370,12 @@ int batadv_send_skb_unicast(struct batadv_priv *bat_priv,
if (batadv_tt_global_client_is_roaming(bat_priv, ethhdr->h_dest, vid))
unicast_packet->ttvn = unicast_packet->ttvn - 1;
- res = batadv_send_skb_to_orig(skb, orig_node, NULL);
- if (res != -1)
- ret = NET_XMIT_SUCCESS;
+ ret = batadv_send_skb_to_orig(skb, orig_node, NULL);
+ /* skb was consumed */
+ skb = NULL;
out:
- if (ret == NET_XMIT_DROP)
- kfree_skb(skb);
+ kfree_skb(skb);
return ret;
}
diff --git a/net/batman-adv/tp_meter.c b/net/batman-adv/tp_meter.c
index 2333777..f156452 100644
--- a/net/batman-adv/tp_meter.c
+++ b/net/batman-adv/tp_meter.c
@@ -615,9 +615,6 @@ static int batadv_tp_send_msg(struct batadv_tp_vars *tp_vars, const u8 *src,
batadv_tp_fill_prerandom(tp_vars, data, data_len);
r = batadv_send_skb_to_orig(skb, orig_node, NULL);
- if (r == -1)
- kfree_skb(skb);
-
if (r == NET_XMIT_SUCCESS)
return 0;
@@ -1206,9 +1203,6 @@ static int batadv_tp_send_ack(struct batadv_priv *bat_priv, const u8 *dst,
/* send the ack */
r = batadv_send_skb_to_orig(skb, orig_node, NULL);
- if (r == -1)
- kfree_skb(skb);
-
if (unlikely(r < 0) || (r == NET_XMIT_DROP)) {
ret = BATADV_TP_REASON_DST_UNREACHABLE;
goto out;
diff --git a/net/batman-adv/tvlv.c b/net/batman-adv/tvlv.c
index 77654f0..a783420 100644
--- a/net/batman-adv/tvlv.c
+++ b/net/batman-adv/tvlv.c
@@ -600,7 +600,6 @@ void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src,
unsigned char *tvlv_buff;
unsigned int tvlv_len;
ssize_t hdr_len = sizeof(*unicast_tvlv_packet);
- int res;
orig_node = batadv_orig_hash_find(bat_priv, dst);
if (!orig_node)
@@ -633,9 +632,7 @@ void batadv_tvlv_unicast_send(struct batadv_priv *bat_priv, u8 *src,
tvlv_buff += sizeof(*tvlv_hdr);
memcpy(tvlv_buff, tvlv_value, tvlv_value_len);
- res = batadv_send_skb_to_orig(skb, orig_node, NULL);
- if (res == -1)
- kfree_skb(skb);
+ batadv_send_skb_to_orig(skb, orig_node, NULL);
out:
batadv_orig_node_put(orig_node);
}
--
2.10.1
next prev parent reply other threads:[~2016-11-08 16:45 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-08 16:45 [B.A.T.M.A.N.] [PATCH 00/17] pull request for net-next: batman-adv 2016-11-08 Simon Wunderlich
2016-11-08 16:45 ` [B.A.T.M.A.N.] [PATCH 01/17] batman-adv: Introduce missing headers for genetlink restructure Simon Wunderlich
2016-11-08 16:45 ` [B.A.T.M.A.N.] [PATCH 02/17] batman-adv: Mark batadv_netlink_ops as const Simon Wunderlich
2016-11-08 16:45 ` [B.A.T.M.A.N.] [PATCH 03/17] batman-adv: Close two alignment holes in batadv_hard_iface Simon Wunderlich
2016-11-08 16:45 ` [B.A.T.M.A.N.] [PATCH 04/17] batman-adv: Add wrapper for ARP reply creation Simon Wunderlich
2016-11-08 16:45 ` [B.A.T.M.A.N.] [PATCH 05/17] batman-adv: Remove unnecessary lockdep in batadv_mcast_mla_list_free Simon Wunderlich
2016-11-08 16:45 ` [B.A.T.M.A.N.] [PATCH 06/17] batman-adv: Remove unused skb_reset_mac_header() Simon Wunderlich
2016-11-08 16:45 ` [B.A.T.M.A.N.] [PATCH 07/17] batman-adv: Use own timer for multicast TT and TVLV updates Simon Wunderlich
2016-11-08 16:45 ` [B.A.T.M.A.N.] [PATCH 08/17] batman-adv: Simple (re)broadcast avoidance Simon Wunderlich
2016-11-08 16:45 ` [B.A.T.M.A.N.] [PATCH 09/17] batman-adv: use consume_skb for non-dropped packets Simon Wunderlich
2016-11-08 16:45 ` [B.A.T.M.A.N.] [PATCH 10/17] batman-adv: Count all non-success TX packets as dropped Simon Wunderlich
2016-11-08 16:45 ` [B.A.T.M.A.N.] [PATCH 11/17] batman-adv: Consume skb in batadv_frag_send_packet Simon Wunderlich
2016-11-08 16:45 ` Simon Wunderlich [this message]
2016-11-08 16:45 ` [B.A.T.M.A.N.] [PATCH 13/17] batman-adv: Consume skb in receive handlers Simon Wunderlich
2016-11-08 16:59 ` Eric Dumazet
2016-11-08 17:28 ` Sven Eckelmann
2016-11-08 17:43 ` Eric Dumazet
2016-11-08 19:05 ` Sven Eckelmann
2016-11-08 16:45 ` [B.A.T.M.A.N.] [PATCH 14/17] batman-adv: Remove dev_queue_xmit return code exception Simon Wunderlich
2016-11-08 16:45 ` [B.A.T.M.A.N.] [PATCH 15/17] batman-adv: Disallow mcast src address for data frames Simon Wunderlich
2016-11-08 16:45 ` [B.A.T.M.A.N.] [PATCH 16/17] batman-adv: Disallow zero and mcast src address for mgmt frames Simon Wunderlich
2016-11-08 16:45 ` [B.A.T.M.A.N.] [PATCH 17/17] batman-adv: Reject unicast packet with zero/mcast dst address Simon Wunderlich
-- strict thread matches above, loose matches on Subject: below --
2016-11-09 22:25 [B.A.T.M.A.N.] [PATCH 00/17] pull request for net-next: batman-adv 2016-11-08 v2 Simon Wunderlich
2016-11-09 22:26 ` [B.A.T.M.A.N.] [PATCH 12/17] batman-adv: Consume skb in batadv_send_skb_to_orig Simon Wunderlich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161108164526.7518-13-sw@simonwunderlich.de \
--to=sw@simonwunderlich.de \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox