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
+3
View File
@@ -85,6 +85,8 @@ struct ifaddrmsg
*
* IFA_FLAGS is a u32 attribute that extends the u8 field ifa_flags.
* If present, the value from struct ifaddrmsg will be ignored.
*
* IFA_RT_PRIORITY is a u32 attribute, priority/metric for prefix route
*/
enum
@@ -98,6 +100,7 @@ enum
IFA_CACHEINFO,
IFA_MULTICAST,
IFA_FLAGS,
IFA_RT_PRIORITY,
__IFA_MAX,
};
+54
View File
@@ -389,6 +389,25 @@
#define RTNLGRP_NSID 28
#define RTNLGRP_MAX 29
/**
* nla_type (16 bits)
* +---+---+-------------------------------+
* | N | O | Attribute Type |
* +---+---+-------------------------------+
* N := Carries nested attributes
* O := Payload stored in network byte order
*
* Note: The N and O flag are mutually exclusive.
*/
#define NLA_F_NET_BYTEORDER (1 << 14)
#define NLA_F_NESTED (1 << 15)
#define NLA_TYPE_MASK ~(NLA_F_NESTED | NLA_F_NET_BYTEORDER)
#define NLA_ALIGNTO 4
#define NLA_ALIGN(len) (((len) + NLA_ALIGNTO - 1) & ~(NLA_ALIGNTO - 1))
#define NLA_HDRLEN (NLA_ALIGN(sizeof(struct nlattr)))
/****************************************************************************
* Public Type Definitions
****************************************************************************/
@@ -503,6 +522,41 @@ struct rtmsg
uint32_t rtm_flags;
};
/**
* <------- NLA_HDRLEN ------> <-- NLA_ALIGN(payload)-->
* +---------------------+- - -+- - - - - - - - - -+- - -+
* | Header | Pad | Payload | Pad |
* | (struct nlattr) | ing | | ing |
* +---------------------+- - -+- - - - - - - - - -+- - -+
* <-------------- nlattr->nla_len -------------->
*/
struct nlattr
{
uint16_t nla_len;
uint16_t nla_type;
};
/* Generic 32 bitflags attribute content sent to the kernel.
*
* The value is a bitmap that defines the values being set
* The selector is a bitmask that defines which value is legit
*
* Examples:
* value = 0x0, and selector = 0x1
* implies we are selecting bit 1 and we want to set its value to 0.
*
* value = 0x2, and selector = 0x2
* implies we are selecting bit 2 and we want to set its value to 1.
*
*/
struct nla_bitfield32
{
uint32_t value;
uint32_t selector;
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/