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:
zhanghongyu
2023-01-30 16:50:11 +08:00
committed by Xiang Xiao
parent 873abcb9ab
commit fdc6dbf176
8 changed files with 1209 additions and 2 deletions
+4
View File
@@ -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;