mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 4/5] net: establish single code path for setting edev parameters
Date: Mon, 10 Jun 2024 09:51:04 +0200	[thread overview]
Message-ID: <20240610075105.812496-5-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20240610075105.812496-1-s.hauer@pengutronix.de>

We have net_set_ip(), net_set_gateway() and net_set_netmask() to set the
IP parameters of a network device. Most code pathes go through these
functions with the exception of setting the parameters through
globalvars on the command line. Explicitly call the accessors for this
code path as well so that all IP parameter settings go through them.
This is done in preparation to integrate a real network stack later.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 net/eth.c | 33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/net/eth.c b/net/eth.c
index 98567d8d3f..e81018c69b 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -393,6 +393,33 @@ static const char * const eth_mode_names[] = {
 	[ETH_MODE_DISABLED] = "disabled",
 };
 
+static int eth_param_set_ip(struct param_d *p, void *priv)
+{
+	struct eth_device *edev = priv;
+
+	net_set_ip(edev, edev->ipaddr);
+
+	return 0;
+}
+
+static int eth_param_set_gw(struct param_d *p, void *priv)
+{
+	struct eth_device *edev = priv;
+
+	net_set_gateway(edev, net_get_gateway());
+
+	return 0;
+}
+
+static int eth_param_set_nm(struct param_d *p, void *priv)
+{
+	struct eth_device *edev = priv;
+
+	net_set_netmask(edev, edev->netmask);
+
+	return 0;
+}
+
 int eth_register(struct eth_device *edev)
 {
 	struct device *dev = &edev->dev;
@@ -428,10 +455,10 @@ int eth_register(struct eth_device *edev)
 
 	edev->devname = xstrdup(dev_name(&edev->dev));
 
-	dev_add_param_ip(dev, "ipaddr", NULL, NULL, &edev->ipaddr, edev);
+	dev_add_param_ip(dev, "ipaddr", eth_param_set_ip, NULL, &edev->ipaddr, edev);
 	dev_add_param_string(dev, "serverip", NULL, NULL, &net_server, edev);
-	dev_add_param_ip(dev, "gateway", NULL, NULL, &net_gateway, edev);
-	dev_add_param_ip(dev, "netmask", NULL, NULL, &edev->netmask, edev);
+	dev_add_param_ip(dev, "gateway", eth_param_set_gw, NULL, &net_gateway, edev);
+	dev_add_param_ip(dev, "netmask", eth_param_set_nm, NULL, &edev->netmask, edev);
 	dev_add_param_mac(dev, "ethaddr", eth_param_set_ethaddr, NULL,
 			edev->ethaddr, edev);
 	edev->bootarg = xstrdup("");
-- 
2.39.2




  parent reply	other threads:[~2024-06-10  7:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-10  7:51 [PATCH 0/5] net: preparations for integrating a network stack Sascha Hauer
2024-06-10  7:51 ` [PATCH 1/5] net: virtio-net: allow to set current MAC address Sascha Hauer
2024-06-10  7:51 ` [PATCH 2/5] net: ifup: use accessor to set network device ip/netmask Sascha Hauer
2024-06-10  7:51 ` [PATCH 3/5] net: add edev argument to net_set_gateway() Sascha Hauer
2024-06-10  7:51 ` Sascha Hauer [this message]
2024-06-10  7:51 ` [PATCH 5/5] net: host command: move to commands/ Sascha Hauer
2024-06-13  6:41 ` [PATCH 0/5] net: preparations for integrating a network stack Sascha Hauer

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=20240610075105.812496-5-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --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