mirror of
https://github.com/apache/nuttx.git
synced 2026-05-20 12:33:27 +08:00
netlink: add RTM_NEWADDR, RTM_DELADDR and RTM_GETADDR
We have projects that need to sense ip address changes in time, and set ip address or clear ip address through netlink so the relevant implementation is added. The usage and command structure are consistent with linux Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
@@ -839,6 +839,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
|
||||
|
||||
case SIOCSIFADDR: /* Set IP address */
|
||||
ioctl_set_ipv4addr(&dev->d_ipaddr, &req->ifr_addr);
|
||||
netlink_device_notify_ipaddr(dev, RTM_NEWADDR, AF_INET);
|
||||
break;
|
||||
|
||||
case SIOCGIFDSTADDR: /* Get P-to-P address */
|
||||
@@ -879,6 +880,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
|
||||
{
|
||||
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
||||
ioctl_set_ipv6addr(dev->d_ipv6addr, &lreq->lifr_addr);
|
||||
netlink_device_notify_ipaddr(dev, RTM_NEWADDR, AF_INET6);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1040,9 +1042,11 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
|
||||
case SIOCDIFADDR: /* Delete IP address */
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
dev->d_ipaddr = 0;
|
||||
netlink_device_notify_ipaddr(dev, RTM_DELADDR, AF_INET);
|
||||
#endif
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
memset(&dev->d_ipv6addr, 0, sizeof(net_ipv6addr_t));
|
||||
netlink_device_notify_ipaddr(dev, RTM_DELADDR, AF_INET6);
|
||||
#endif
|
||||
break;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user