mirror of
https://github.com/apache/nuttx.git
synced 2026-10-07 14:25:25 +00:00
net/arp/arp_send.c: replace net_lock with netdev_lock
use netdev_lock to protect the arp process Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
parent
eb2bd58640
commit
51743c55b2
1 changed files with 27 additions and 16 deletions
|
|
@ -219,8 +219,7 @@ int arp_send(in_addr_t ipaddr)
|
|||
if (!dev)
|
||||
{
|
||||
nerr("ERROR: Unreachable: %08lx\n", (unsigned long)ipaddr);
|
||||
ret = -EHOSTUNREACH;
|
||||
goto errout;
|
||||
return -EHOSTUNREACH;
|
||||
}
|
||||
|
||||
/* ARP support is only built if the Ethernet link layer is supported.
|
||||
|
|
@ -284,19 +283,11 @@ int arp_send(in_addr_t ipaddr)
|
|||
* want anything to happen until we are ready.
|
||||
*/
|
||||
|
||||
net_lock();
|
||||
state.snd_cb = arp_callback_alloc(dev);
|
||||
if (!state.snd_cb)
|
||||
{
|
||||
nerr("ERROR: Failed to allocate a callback\n");
|
||||
ret = -ENOMEM;
|
||||
goto errout_with_lock;
|
||||
}
|
||||
|
||||
nxsem_init(&state.snd_sem, 0, 0); /* Doesn't really fail */
|
||||
|
||||
state.snd_retries = 0; /* No retries yet */
|
||||
state.snd_ipaddr = ipaddr; /* IP address to query */
|
||||
state.snd_cb = NULL; /* No callback allocated yet */
|
||||
|
||||
/* Remember the routing device name */
|
||||
|
||||
|
|
@ -316,11 +307,13 @@ int arp_send(in_addr_t ipaddr)
|
|||
* issue.
|
||||
*/
|
||||
|
||||
netdev_lock(dev);
|
||||
ret = arp_find(ipaddr, NULL, dev, true);
|
||||
if (ret >= 0)
|
||||
{
|
||||
/* We have it! Break out with success */
|
||||
|
||||
netdev_unlock(dev);
|
||||
goto out;
|
||||
}
|
||||
else if (ret == -ENETUNREACH)
|
||||
|
|
@ -329,6 +322,7 @@ int arp_send(in_addr_t ipaddr)
|
|||
* to try to update the ARP table.
|
||||
*/
|
||||
|
||||
netdev_unlock(dev);
|
||||
arp_send_async(ipaddr, NULL);
|
||||
goto out;
|
||||
}
|
||||
|
|
@ -337,6 +331,23 @@ int arp_send(in_addr_t ipaddr)
|
|||
|
||||
arp_wait_setup(ipaddr, ¬ify);
|
||||
|
||||
/* Allocate resources to receive a callback. This and the following
|
||||
* initialization is performed with the network lock because we don't
|
||||
* want anything to happen until we are ready.
|
||||
*/
|
||||
|
||||
if (state.snd_cb == NULL)
|
||||
{
|
||||
state.snd_cb = arp_callback_alloc(dev);
|
||||
if (!state.snd_cb)
|
||||
{
|
||||
nerr("ERROR: Failed to allocate a callback\n");
|
||||
netdev_unlock(dev);
|
||||
ret = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/* Arm/re-arm the callback */
|
||||
|
||||
state.snd_sent = false;
|
||||
|
|
@ -346,6 +357,8 @@ int arp_send(in_addr_t ipaddr)
|
|||
state.snd_cb->event = arp_send_eventhandler;
|
||||
state.finish_cb = NULL;
|
||||
|
||||
netdev_unlock(dev);
|
||||
|
||||
/* Notify the device driver that new TX data is available. */
|
||||
|
||||
netdev_txnotify_dev(dev);
|
||||
|
|
@ -413,9 +426,7 @@ timeout:
|
|||
out:
|
||||
nxsem_destroy(&state.snd_sem);
|
||||
arp_callback_free(dev, state.snd_cb);
|
||||
errout_with_lock:
|
||||
net_unlock();
|
||||
errout:
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -463,7 +474,7 @@ int arp_send_async(in_addr_t ipaddr, arp_send_finish_cb_t cb)
|
|||
goto errout;
|
||||
}
|
||||
|
||||
net_lock();
|
||||
netdev_lock(dev);
|
||||
state->snd_cb = arp_callback_alloc(dev);
|
||||
if (!state->snd_cb)
|
||||
{
|
||||
|
|
@ -492,7 +503,7 @@ int arp_send_async(in_addr_t ipaddr, arp_send_finish_cb_t cb)
|
|||
netdev_txnotify_dev(dev);
|
||||
|
||||
errout_with_lock:
|
||||
net_unlock();
|
||||
netdev_unlock(dev);
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue