From: "Daniel Glöckner" <dg@emlix.com>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH v3 08/14] net: reply to ping requests
Date: Mon, 15 Jun 2020 19:20:41 +0200 [thread overview]
Message-ID: <af19083f2e3f47344220207682ac141e518d7398.1592241105.git.dg@emlix.com> (raw)
In-Reply-To: <cover.1592241105.git.dg@emlix.com>
In-Reply-To: <cover.1592241105.git.dg@emlix.com>
From: Sascha Hauer <s.hauer@pengutronix.de>
Now that we have the network receive function running in a poller we
can reasonably well answer to ping requests. Implement this feature.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
net/net.c | 46 ++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 44 insertions(+), 2 deletions(-)
diff --git a/net/net.c b/net/net.c
index 197b551e7..cb0013519 100644
--- a/net/net.c
+++ b/net/net.c
@@ -570,12 +570,54 @@ static int net_handle_udp(unsigned char *pkt, int len)
return -EINVAL;
}
-static int net_handle_icmp(unsigned char *pkt, int len)
+static int ping_reply(struct eth_device *edev, unsigned char *pkt, int len)
+{
+ struct ethernet *et = (struct ethernet *)pkt;
+ struct icmphdr *icmp;
+ struct iphdr *ip = (struct iphdr *)(pkt + ETHER_HDR_SIZE);
+ unsigned char *packet;
+ int ret;
+
+ memcpy(et->et_dest, et->et_src, 6);
+ memcpy(et->et_src, edev->ethaddr, 6);
+ et->et_protlen = htons(PROT_IP);
+
+ icmp = net_eth_to_icmphdr(pkt);
+
+ icmp->type = ICMP_ECHO_REPLY;
+ icmp->checksum = 0;
+ icmp->checksum = ~net_checksum((unsigned char *)icmp,
+ len - sizeof(struct iphdr) - ETHER_HDR_SIZE);
+ ip->check = 0;
+ ip->frag_off = 0;
+ net_copy_ip((void *)&ip->daddr, &ip->saddr);
+ net_copy_ip((void *)&ip->saddr, &edev->ipaddr);
+ ip->check = ~net_checksum((unsigned char *)ip, sizeof(struct iphdr));
+
+ packet = net_alloc_packet();
+ if (!packet)
+ return 0;
+
+ memcpy(packet, pkt, ETHER_HDR_SIZE + len);
+
+ ret = eth_send(edev, packet, ETHER_HDR_SIZE + len);
+
+ free(packet);
+
+ return 0;
+}
+
+static int net_handle_icmp(struct eth_device *edev, unsigned char *pkt, int len)
{
struct net_connection *con;
+ struct icmphdr *icmp;
pr_debug("%s\n", __func__);
+ icmp = net_eth_to_icmphdr(pkt);
+ if (icmp->type == ICMP_ECHO_REQUEST)
+ ping_reply(edev, pkt, len);
+
list_for_each_entry(con, &connection_list, list) {
if (con->proto == IPPROTO_ICMP) {
con->handler(con->priv, pkt, len);
@@ -612,7 +654,7 @@ static int net_handle_ip(struct eth_device *edev, unsigned char *pkt, int len)
switch (ip->protocol) {
case IPPROTO_ICMP:
- return net_handle_icmp(pkt, len);
+ return net_handle_icmp(edev, pkt, len);
case IPPROTO_UDP:
return net_handle_udp(pkt, len);
}
--
2.17.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2020-06-15 17:21 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-15 17:20 [PATCH v3 00/14] Slices and fastboot over UDP Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 01/14] Introduce slices Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 02/14] Introduce idle slice Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 03/14] net: Add a slice to struct eth_device Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 04/14] net: mdiobus: Add slice Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 05/14] usb: Add a slice to usb host controllers Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 06/14] usbnet: Add slice Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 07/14] net: Call net_poll() in a poller Daniel Glöckner
2020-06-15 17:20 ` Daniel Glöckner [this message]
2020-06-15 17:20 ` [PATCH v3 09/14] usbnet: Be more friendly in the receive path Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 10/14] poller: Allow to run pollers inside of pollers Daniel Glöckner
2020-06-17 7:00 ` Sascha Hauer
2020-06-15 17:20 ` [PATCH v3 11/14] defconfigs: update renamed fastboot options Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 12/14] globalvar: Add helper for deprecated variable names Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 13/14] fastboot: rename usbgadget.fastboot_* variables to fastboot.* Daniel Glöckner
2020-06-15 17:20 ` [PATCH v3 14/14] fastboot net: implement fastboot over UDP Daniel Glöckner
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=af19083f2e3f47344220207682ac141e518d7398.1592241105.git.dg@emlix.com \
--to=dg@emlix.com \
--cc=barebox@lists.infradead.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