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 04/17] batman-adv: Add wrapper for ARP reply creation
Date: Tue, 8 Nov 2016 17:45:13 +0100 [thread overview]
Message-ID: <20161108164526.7518-5-sw@simonwunderlich.de> (raw)
In-Reply-To: <20161108164526.7518-1-sw@simonwunderlich.de>
From: Linus Lüssing <linus.luessing@c0d3.blue>
Removing duplicate code.
Signed-off-by: Linus Lüssing <linus.luessing@c0d3.blue>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
Signed-off-by: Simon Wunderlich <sw@simonwunderlich.de>
---
net/batman-adv/distributed-arp-table.c | 67 ++++++++++++++++++++--------------
1 file changed, 40 insertions(+), 27 deletions(-)
diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c
index cbb4f32..49576c5 100644
--- a/net/batman-adv/distributed-arp-table.c
+++ b/net/batman-adv/distributed-arp-table.c
@@ -949,6 +949,41 @@ static unsigned short batadv_dat_get_vid(struct sk_buff *skb, int *hdr_size)
}
/**
+ * batadv_dat_arp_create_reply - create an ARP Reply
+ * @bat_priv: the bat priv with all the soft interface information
+ * @ip_src: ARP sender IP
+ * @ip_dst: ARP target IP
+ * @hw_src: Ethernet source and ARP sender MAC
+ * @hw_dst: Ethernet destination and ARP target MAC
+ * @vid: VLAN identifier (optional, set to zero otherwise)
+ *
+ * Creates an ARP Reply from the given values, optionally encapsulated in a
+ * VLAN header.
+ *
+ * Return: An skb containing an ARP Reply.
+ */
+static struct sk_buff *
+batadv_dat_arp_create_reply(struct batadv_priv *bat_priv, __be32 ip_src,
+ __be32 ip_dst, u8 *hw_src, u8 *hw_dst,
+ unsigned short vid)
+{
+ struct sk_buff *skb;
+
+ skb = arp_create(ARPOP_REPLY, ETH_P_ARP, ip_dst, bat_priv->soft_iface,
+ ip_src, hw_dst, hw_src, hw_dst);
+ if (!skb)
+ return NULL;
+
+ skb_reset_mac_header(skb);
+
+ if (vid & BATADV_VLAN_HAS_TAG)
+ skb = vlan_insert_tag(skb, htons(ETH_P_8021Q),
+ vid & VLAN_VID_MASK);
+
+ return skb;
+}
+
+/**
* batadv_dat_snoop_outgoing_arp_request - snoop the ARP request and try to
* answer using DAT
* @bat_priv: the bat priv with all the soft interface information
@@ -1005,20 +1040,12 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv,
goto out;
}
- skb_new = arp_create(ARPOP_REPLY, ETH_P_ARP, ip_src,
- bat_priv->soft_iface, ip_dst, hw_src,
- dat_entry->mac_addr, hw_src);
+ skb_new = batadv_dat_arp_create_reply(bat_priv, ip_dst, ip_src,
+ dat_entry->mac_addr,
+ hw_src, vid);
if (!skb_new)
goto out;
- if (vid & BATADV_VLAN_HAS_TAG) {
- skb_new = vlan_insert_tag(skb_new, htons(ETH_P_8021Q),
- vid & VLAN_VID_MASK);
- if (!skb_new)
- goto out;
- }
-
- skb_reset_mac_header(skb_new);
skb_new->protocol = eth_type_trans(skb_new,
bat_priv->soft_iface);
bat_priv->stats.rx_packets++;
@@ -1081,25 +1108,11 @@ bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv,
if (!dat_entry)
goto out;
- skb_new = arp_create(ARPOP_REPLY, ETH_P_ARP, ip_src,
- bat_priv->soft_iface, ip_dst, hw_src,
- dat_entry->mac_addr, hw_src);
-
+ skb_new = batadv_dat_arp_create_reply(bat_priv, ip_dst, ip_src,
+ dat_entry->mac_addr, hw_src, vid);
if (!skb_new)
goto out;
- /* the rest of the TX path assumes that the mac_header offset pointing
- * to the inner Ethernet header has been set, therefore reset it now.
- */
- skb_reset_mac_header(skb_new);
-
- if (vid & BATADV_VLAN_HAS_TAG) {
- skb_new = vlan_insert_tag(skb_new, htons(ETH_P_8021Q),
- vid & VLAN_VID_MASK);
- if (!skb_new)
- goto out;
- }
-
/* To preserve backwards compatibility, the node has choose the outgoing
* format based on the incoming request packet type. The assumption is
* that a node not using the 4addr packet format doesn't support it.
--
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 ` Simon Wunderlich [this message]
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 ` [B.A.T.M.A.N.] [PATCH 12/17] batman-adv: Consume skb in batadv_send_skb_to_orig Simon Wunderlich
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:25 ` [B.A.T.M.A.N.] [PATCH 04/17] batman-adv: Add wrapper for ARP reply creation 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-5-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