diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2008-08-20 13:21:55 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2008-08-20 17:46:54 +0200 |
commit | 51b4de421e0f98182e999f857619dcf3f4ceb7e8 (patch) | |
tree | b43f9906d20d3c92556f100240b2a3dc6fcc4c85 /net | |
parent | c0d02ffc3d11e96977b549563f679c5bfe30f359 (diff) | |
download | barebox-51b4de421e0f98182e999f857619dcf3f4ceb7e8.tar.gz barebox-51b4de421e0f98182e999f857619dcf3f4ceb7e8.tar.xz |
eth: check for valid parameters for ethaddr, ipaddr, ...
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'net')
-rw-r--r-- | net/eth.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -28,6 +28,7 @@ #include <net.h> #include <miiphy.h> #include <errno.h> +#include <malloc.h> static struct eth_device *eth_current; @@ -83,6 +84,32 @@ int eth_rx(void) return eth_current->recv(eth_current); } +static int eth_set_ethaddr(struct device_d *dev, struct param_d *param, const char *val) +{ + char ethaddr[sizeof("xx:xx:xx:xx:xx:xx")]; + + if (string_to_ethaddr(val, ethaddr) < 0) + return -EINVAL; + + free(param->value); + param->value = strdup(val); + + return 0; +} + +static int eth_set_ipaddr(struct device_d *dev, struct param_d *param, const char *val) +{ + IPaddr_t ip; + + if (string_to_ip(val, &ip)) + return -EINVAL; + + free(param->value); + param->value = strdup(val); + + return 0; +} + int eth_register(struct eth_device *edev) { struct device_d *dev = edev->dev; @@ -95,10 +122,15 @@ int eth_register(struct eth_device *edev) } edev->param_ip.name = "ipaddr"; + edev->param_ip.set = ð_set_ipaddr; edev->param_ethaddr.name = "ethaddr"; + edev->param_ethaddr.set = ð_set_ethaddr; edev->param_gateway.name = "gateway"; + edev->param_gateway.set = ð_set_ipaddr; edev->param_netmask.name = "netmask"; + edev->param_netmask.set = ð_set_ipaddr; edev->param_serverip.name = "serverip"; + edev->param_serverip.set = ð_set_ipaddr; dev_add_param(dev, &edev->param_ip); dev_add_param(dev, &edev->param_ethaddr); dev_add_param(dev, &edev->param_gateway); |