From: Murali Karicheri <m-karicheri2@ti.com>
To: <davem@davemloft.net>, <kuba@kernel.org>,
<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-api@vger.kernel.org>, <nsekhar@ti.com>,
<grygorii.strashko@ti.com>, <vinicius.gomes@intel.com>
Subject: [net-next PATCH v2 4/9] net: hsr: introduce common code for skb initialization
Date: Wed, 15 Jul 2020 12:40:05 -0400 [thread overview]
Message-ID: <20200715164012.1222-5-m-karicheri2@ti.com> (raw)
In-Reply-To: <20200715164012.1222-1-m-karicheri2@ti.com>
As a preparatory patch to introduce PRP protocol support in the
driver, refactor the skb init code to a separate function.
Signed-off-by: Murali Karicheri <m-karicheri2@ti.com>
---
net/hsr/hsr_device.c | 41 ++++++++++++++++++++++++++++-------------
1 file changed, 28 insertions(+), 13 deletions(-)
diff --git a/net/hsr/hsr_device.c b/net/hsr/hsr_device.c
index ddc6582a89be..b1effa8b2403 100644
--- a/net/hsr/hsr_device.c
+++ b/net/hsr/hsr_device.c
@@ -230,15 +230,11 @@ static const struct header_ops hsr_header_ops = {
.parse = eth_header_parse,
};
-static void send_hsr_supervision_frame(struct hsr_port *master,
- u8 type, u8 hsr_ver)
+static struct sk_buff *hsr_init_skb(struct hsr_port *master, u8 hsr_ver)
{
+ struct hsr_priv *hsr = master->hsr;
struct sk_buff *skb;
int hlen, tlen;
- struct hsr_tag *hsr_tag;
- struct hsr_sup_tag *hsr_stag;
- struct hsr_sup_payload *hsr_sp;
- unsigned long irqflags;
hlen = LL_RESERVED_SPACE(master->dev);
tlen = master->dev->needed_tailroom;
@@ -247,22 +243,44 @@ static void send_hsr_supervision_frame(struct hsr_port *master,
sizeof(struct hsr_sup_payload) + hlen + tlen);
if (!skb)
- return;
+ return skb;
skb_reserve(skb, hlen);
-
skb->dev = master->dev;
skb->protocol = htons(hsr_ver ? ETH_P_HSR : ETH_P_PRP);
skb->priority = TC_PRIO_CONTROL;
if (dev_hard_header(skb, skb->dev, (hsr_ver ? ETH_P_HSR : ETH_P_PRP),
- master->hsr->sup_multicast_addr,
+ hsr->sup_multicast_addr,
skb->dev->dev_addr, skb->len) <= 0)
goto out;
+
skb_reset_mac_header(skb);
skb_reset_network_header(skb);
skb_reset_transport_header(skb);
+ return skb;
+out:
+ kfree_skb(skb);
+
+ return NULL;
+}
+
+static void send_hsr_supervision_frame(struct hsr_port *master,
+ u8 type, u8 hsr_ver)
+{
+ struct sk_buff *skb;
+ struct hsr_tag *hsr_tag;
+ struct hsr_sup_tag *hsr_stag;
+ struct hsr_sup_payload *hsr_sp;
+ unsigned long irqflags;
+
+ skb = hsr_init_skb(master, hsr_ver);
+ if (!skb) {
+ WARN_ONCE(1, "HSR: Could not send supervision frame\n");
+ return;
+ }
+
if (hsr_ver > 0) {
hsr_tag = skb_put(skb, sizeof(struct hsr_tag));
hsr_tag->encap_proto = htons(ETH_P_PRP);
@@ -299,11 +317,8 @@ static void send_hsr_supervision_frame(struct hsr_port *master,
return;
hsr_forward_skb(skb, master);
- return;
-out:
- WARN_ONCE(1, "HSR: Could not send supervision frame\n");
- kfree_skb(skb);
+ return;
}
/* Announce (supervision frame) timer function
--
2.17.1
next prev parent reply other threads:[~2020-07-15 16:41 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-15 16:40 [net-next PATCH v2 0/9] Add PRP driver and bug fixes Murali Karicheri
2020-07-15 16:40 ` [net-next PATCH v2 1/9] net: hsr: fix incorrect lsdu size in the tag of HSR frames for small frames Murali Karicheri
2020-07-15 16:40 ` [net-next PATCH v2 2/9] net: hsr/prp: validate address B before copying to skb Murali Karicheri
2020-07-15 16:40 ` [net-next PATCH v2 3/9] hsr: enhance netlink socket interface to support PRP Murali Karicheri
2020-07-15 16:40 ` Murali Karicheri [this message]
2020-07-15 16:40 ` [net-next PATCH v2 5/9] net: hsr: introduce protocol specific function pointers Murali Karicheri
2020-07-15 16:40 ` [net-next PATCH v2 6/9] net: prp: add supervision frame generation utility function Murali Karicheri
2020-07-15 16:40 ` [net-next PATCH v2 7/9] net: hsr: define and use proto_ops ptrs to handle hsr specific frames Murali Karicheri
2020-07-15 16:40 ` [net-next PATCH v2 8/9] net: prp: add packet handling support Murali Karicheri
2020-07-15 16:40 ` [net-next PATCH v2 9/9] net: prp: enhance debugfs to display PRP info Murali Karicheri
2020-07-15 16:40 ` [net-next iproute2 PATCH v2 1/2] iplink: hsr: add support for creating PRP device similar to HSR Murali Karicheri
2020-07-15 16:40 ` [net-next iproute2 PATCH v2 2/2] ip: iplink: prp: update man page for new parameter Murali Karicheri
2020-07-16 23:56 ` [net-next PATCH v2 0/9] Add PRP driver and bug fixes Jakub Kicinski
2020-07-17 14:19 ` Murali Karicheri
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=20200715164012.1222-5-m-karicheri2@ti.com \
--to=m-karicheri2@ti.com \
--cc=davem@davemloft.net \
--cc=grygorii.strashko@ti.com \
--cc=kuba@kernel.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nsekhar@ti.com \
--cc=vinicius.gomes@intel.com \
/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;
as well as URLs for NNTP newsgroup(s).