本文整理汇总了C++中IFA_RTA函数的典型用法代码示例。如果您正苦于以下问题:C++ IFA_RTA函数的具体用法?C++ IFA_RTA怎么用?C++ IFA_RTA使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了IFA_RTA函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: g_pn_nl_addr
static void g_pn_nl_addr(GPhonetNetlink *self, struct nlmsghdr *nlh)
{
int len;
uint8_t local = 0xff;
uint8_t remote = 0xff;
const struct ifaddrmsg *ifa;
const struct rtattr *rta;
ifa = NLMSG_DATA(nlh);
len = IFA_PAYLOAD(nlh);
/* If Phonet is absent, kernel transmits other families... */
if (ifa->ifa_family != AF_PHONET)
return;
if (ifa->ifa_index != self->interface)
return;
for (rta = IFA_RTA(ifa); RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) {
if (rta->rta_type == IFA_LOCAL)
local = *(uint8_t *)RTA_DATA(rta);
else if (rta->rta_type == IFA_ADDRESS)
remote = *(uint8_t *)RTA_DATA(rta);
}
}
示例2: memset
void linux_unicast_router::handle_addr_event(bool isnew, nlmsghdr *hdr) {
ifaddrmsg *ifa = (ifaddrmsg *)NLMSG_DATA(hdr);
if (ifa->ifa_family == AF_INET6) {
rtattr *tb[IFA_MAX + 1];
memset(tb, 0, sizeof(tb));
netlink_msg::parse_rtatable(tb, IFA_MAX, IFA_RTA(ifa),
hdr->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa)));
rtattr *arta = tb[IFA_LOCAL];
if (!arta)
arta = tb[IFA_ADDRESS];
if (arta) {
inet6_addr addr;
memcpy(&addr.addr, RTA_DATA(arta), RTA_PAYLOAD(arta));
addr.prefixlen = ifa->ifa_prefixlen;
if (addr.type() & (inet6_addr::multicast | inet6_addr::network))
return;
if (addr.is_any())
return;
interface *intf = g_mrd->get_interface_by_index(ifa->ifa_index);
if (intf) {
intf->address_added_or_removed(isnew, addr);
}
}
}
}
示例3: buffer_len
int
TunnelIPv6Interface::process(void)
{
uint8_t buffer[1024];
ssize_t buffer_len(-1);
if (mNetlinkFD >= 0) {
buffer_len = recv(mNetlinkFD, buffer, sizeof(buffer), 0);
}
if (buffer_len > 0) {
struct nlmsghdr *nlp;
struct rtmsg *rtp;
int rta_len;
struct rtattr *rta;
nlp = (struct nlmsghdr *)buffer;
for (;NLMSG_OK(nlp, buffer_len); nlp=NLMSG_NEXT(nlp, buffer_len))
{
if (nlp->nlmsg_type == RTM_NEWADDR || nlp->nlmsg_type == RTM_DELADDR) {
struct ifaddrmsg *ifaddr = (struct ifaddrmsg *)NLMSG_DATA(nlp);
char ifnamebuf[IF_NAMESIZE];
const char *ifname = if_indextoname(ifaddr->ifa_index, ifnamebuf);
struct in6_addr addr;
if ((ifname == NULL) || (get_interface_name() != ifname)) {
continue;
}
// get RTNETLINK message header
// get start of attributes
rta = (struct rtattr *) IFA_RTA(ifaddr);
// get length of attributes
rta_len = IFA_PAYLOAD(nlp);
for(;RTA_OK(rta, rta_len); rta = RTA_NEXT(rta, rta_len)) {
switch(rta->rta_type) {
case IFA_ADDRESS:
case IFA_LOCAL:
case IFA_BROADCAST:
case IFA_ANYCAST:
memcpy(addr.s6_addr, RTA_DATA(rta), sizeof(addr));
if (nlp->nlmsg_type == RTM_NEWADDR) {
mAddressWasAdded(addr, ifaddr->ifa_prefixlen);
} else if (nlp->nlmsg_type == RTM_DELADDR) {
mAddressWasRemoved(addr, ifaddr->ifa_prefixlen);
}
break;
default:
break;
}
}
}
}
}
return nl::UnixSocket::process();
}
示例4: parse_addr_rta
static int
parse_addr_rta(struct ifaddrmsg *addr, int len, struct in6_addr *res)
{
struct rtattr *rta;
len -= NLMSG_ALIGN(sizeof(*addr));
rta = IFA_RTA(addr);
while (RTA_OK(rta, len)) {
switch(rta->rta_type) {
case IFA_LOCAL:
case IFA_ADDRESS:
switch (addr->ifa_family) {
case AF_INET:
if (res)
v4tov6(res->s6_addr, RTA_DATA(rta));
break;
case AF_INET6:
if (res)
memcpy(res->s6_addr, RTA_DATA(rta), 16);
break;
default:
kdebugf("ifaddr: unexpected address family %d\n", addr->ifa_family);
return -1;
break;
}
break;
default:
break;
}
rta = RTA_NEXT(rta, len);
}
return 0;
}
示例5: netlink_addroute
/* Add remote address */
static int netlink_addroute(uint32_t ifa_index, uint8_t remote)
{
struct rtmsg *rtm;
struct rtattr *rta;
uint32_t reqlen = NLMSG_LENGTH(NLMSG_ALIGN(sizeof(*rtm)) +
RTA_SPACE(1) +
RTA_SPACE(sizeof(ifa_index)));
struct req {
struct nlmsghdr nlh;
char buf[512];
} req = {
.nlh = {
.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK
| NLM_F_CREATE | NLM_F_APPEND,
.nlmsg_type = RTM_NEWROUTE,
.nlmsg_pid = getpid(),
.nlmsg_len = reqlen,
},
};
size_t buflen = sizeof(req.buf) - sizeof(*rtm);
int fd;
int error;
struct sockaddr_nl addr = { .nl_family = AF_NETLINK, };
rtm = NLMSG_DATA(&req.nlh);
rtm->rtm_family = AF_PHONET;
rtm->rtm_dst_len = 6;
rtm->rtm_src_len = 0;
rtm->rtm_tos = 0;
rtm->rtm_table = RT_TABLE_MAIN;
rtm->rtm_protocol = RTPROT_STATIC;
rtm->rtm_scope = RT_SCOPE_UNIVERSE;
rtm->rtm_type = RTN_UNICAST;
rtm->rtm_flags = 0;
rta = IFA_RTA(rtm);
rta->rta_type = RTA_DST;
rta->rta_len = RTA_LENGTH(1);
*(uint8_t *)RTA_DATA(rta) = remote;
rta = RTA_NEXT(rta, buflen);
rta->rta_type = RTA_OIF;
rta->rta_len = RTA_LENGTH(sizeof(ifa_index));
*(uint32_t *)RTA_DATA(rta) = ifa_index;
fd = netlink_socket();
if (fd == -1)
return -errno;
if (sendto(fd, &req, reqlen, 0, (void *)&addr, sizeof(addr)) == -1)
error = -errno;
else
error = netlink_getack(fd);
close(fd);
return error;
}
示例6: addr_do
int addr_do(const struct in6_addr *addr, int plen, int ifindex, void *arg,
int (*do_callback)(struct ifaddrmsg *ifa,
struct rtattr *rta_tb[], void *arg))
{
uint8_t sbuf[256];
uint8_t rbuf[256];
struct nlmsghdr *sn, *rn;
struct ifaddrmsg *ifa;
int err;
struct rtattr *rta_tb[IFA_MAX+1];
memset(sbuf, 0, sizeof(sbuf));
sn = (struct nlmsghdr *)sbuf;
sn->nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
sn->nlmsg_flags = NLM_F_REQUEST;
sn->nlmsg_type = RTM_GETADDR;
ifa = NLMSG_DATA(sn);
ifa->ifa_family = AF_INET6;
ifa->ifa_prefixlen = plen;
ifa->ifa_scope = RT_SCOPE_UNIVERSE;
ifa->ifa_index = ifindex;
addattr_l(sn, sizeof(sbuf), IFA_LOCAL, addr, sizeof(*addr));
memset(rbuf, 0, sizeof(rbuf));
rn = (struct nlmsghdr *)rbuf;
err = rtnl_route_do(sn, rn);
if (err < 0) {
rn = sn;
ifa = NLMSG_DATA(rn);
} else {
ifa = NLMSG_DATA(rn);
if (rn->nlmsg_type != RTM_NEWADDR ||
rn->nlmsg_len < NLMSG_LENGTH(sizeof(*ifa)) ||
ifa->ifa_family != AF_INET6) {
return -EINVAL;
}
}
memset(rta_tb, 0, sizeof(rta_tb));
parse_rtattr(rta_tb, IFA_MAX, IFA_RTA(ifa),
rn->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa)));
if (!rta_tb[IFA_ADDRESS])
rta_tb[IFA_ADDRESS] = rta_tb[IFA_LOCAL];
if (!rta_tb[IFA_ADDRESS] ||
!IN6_ARE_ADDR_EQUAL(RTA_DATA(rta_tb[IFA_ADDRESS]), addr)) {
return -EINVAL;
}
if (do_callback)
err = do_callback(ifa, rta_tb, arg);
return err;
}
示例7: read_iface_prefix
static int read_iface_prefix(const char *ip_str, int is_ipv6)
{
uint8_t family = is_ipv6 ? AF_INET6 : AF_INET;
char buf[16384];
unsigned int len;
struct {
struct nlmsghdr nlhdr;
struct ifaddrmsg addrmsg;
} msg;
struct nlmsghdr *retmsg;
int sock = SAFE_SOCKET(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
memset(&msg, 0, sizeof(msg));
msg.nlhdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
msg.nlhdr.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT;
msg.nlhdr.nlmsg_type = RTM_GETADDR;
msg.addrmsg.ifa_family = family;
SAFE_SEND(1, sock, &msg, msg.nlhdr.nlmsg_len, 0);
len = recv(sock, buf, sizeof(buf), 0);
retmsg = (struct nlmsghdr *)buf;
while NLMSG_OK(retmsg, len) {
char ifname[IFNAMSIZ];
struct ifaddrmsg *retaddr;
struct rtattr *retrta;
char pradd[128];
int attlen;
retaddr = (struct ifaddrmsg *)NLMSG_DATA(retmsg);
retrta = (struct rtattr *)IFA_RTA(retaddr);
attlen = IFA_PAYLOAD(retmsg);
while RTA_OK(retrta, attlen) {
if (retrta->rta_type == IFA_ADDRESS) {
inet_ntop(family, RTA_DATA(retrta), pradd,
sizeof(pradd));
if_indextoname(retaddr->ifa_index, ifname);
if (!strcmp(pradd, ip_str)) {
prefix = retaddr->ifa_prefixlen;
iface = strdup(ifname);
return 0;
}
}
retrta = RTA_NEXT(retrta, attlen);
}
retmsg = NLMSG_NEXT(retmsg, len);
}
return -1;
}
示例8: nextAddr
// Returns AF_MAX (with errno set) if error, AF_UNSPEC if no more addrs (socket closed)
struct IPAddr nextAddr(struct AddrFilter const filter, struct MonitorState * const state){
// NLMSG_OK checks length first, so safe to call with state->nlh == NULL iff
// state->nlmsg_len < (int) sizeof(struct nlmsghdr)
if (NLMSG_OK(state->nlh, state->nlmsg_len) && (state->nlh->nlmsg_type != NLMSG_DONE)){
struct nlmsghdr * nlh = state->nlh;
state->nlh = NLMSG_NEXT(state->nlh, state->nlmsg_len);
switch(nlh->nlmsg_type){
case NLMSG_ERROR:
errno = -((struct nlmsgerr *) NLMSG_DATA(nlh))->error;
struct IPAddr addr = {.af = AF_MAX};
return addr;
case RTM_NEWADDR: {
struct ifaddrmsg * ifa = (struct ifaddrmsg *) NLMSG_DATA(nlh);
if (!filterIfAddrMsg(*ifa, filter))
return nextAddr(filter, state);
{
struct rtattr * rth;
size_t rtmsg_len;
for (rth = IFA_RTA(ifa), rtmsg_len = IFA_PAYLOAD(nlh);
RTA_OK(rth, rtmsg_len); RTA_NEXT(rth, rtmsg_len)){
if (rth->rta_type != IFA_ADDRESS)
continue;
// family checked in filterIfAddrMsg, so always valid.
struct IPAddr addr = {.af = ifa->ifa_family};
switch (ifa->ifa_family) {
case AF_INET:
addr.ipv4 = *((struct in_addr *) RTA_DATA(rth));
break;
case AF_INET6:
addr.ipv6 = *((struct in6_addr *) RTA_DATA(rth));
break;
}
if (addrIsPrivate(addr) && !filter.allow_private)
return nextAddr(filter, state);
else
return addr;
}
}
// Recieved RTM_NEWADDR without any address.
errno = EBADMSG;
struct IPAddr addr = {.af = AF_MAX};
return addr;
}
default:
return nextAddr(filter, state);
}
} else {
state->nlmsg_len = nextMessage(filter, state->socket, &state->buf, &state->buf_len);
if (state->nlmsg_len == 0) {
// Socket closed by kernel
struct IPAddr addr = {.af = AF_UNSPEC};
return addr;
} else if (state->nlmsg_len < 0) {
// Socket error
struct IPAddr addr = {.af = AF_MAX};
return addr;
} else {
示例9: get_ipv6_address
boost::asio::ip::address_v6 get_ipv6_address(const nlmsghdr *in, const nlmsghdr *an)
{
boost::asio::ip::address_v6 unspec;
if (in->nlmsg_type != RTM_NEWLINK)
return unspec;
if (an->nlmsg_type != RTM_NEWADDR)
return unspec;
ifinfomsg* ifi = (ifinfomsg*)NLMSG_DATA(in);
ifaddrmsg* ifa = (ifaddrmsg*)NLMSG_DATA(an);
__u32 ilen = in->nlmsg_len;
if (ilen < NLMSG_LENGTH(sizeof(*ifi)))
return unspec;
ilen -= NLMSG_LENGTH(sizeof(*ifi));
__u32 alen = an->nlmsg_len;
if (alen < NLMSG_LENGTH(sizeof(*ifa)))
return unspec;
alen -= NLMSG_LENGTH(sizeof(*ifa));
/* NOTE: ifi_index and ifa_index should have the same type (int), but for
* some reason they are not... So instead of a normal (in)equality comparison
* we do a bit-wise compare.
*/
if (ifi->ifi_index ^ ifa->ifa_index)
return unspec;
if (ifi->ifi_family != AF_INET6 || ifa->ifa_family != AF_INET6)
return unspec;
rtattr* tbi[IFLA_MAX+1];
memset(tbi, 0, sizeof(tbi));
parse_rtattr(tbi, IFLA_MAX, IFLA_RTA(ifi), ilen);
if (tbi[IFLA_IFNAME] == NULL)
return unspec;
rtattr* tba[IFA_MAX+1];
memset(tba, 0, sizeof(tba));
parse_rtattr(tba, IFA_MAX, IFA_RTA(ifa), alen);
char abuf[256];
rt_addr_n2a(ifa->ifa_family,
RTA_PAYLOAD(tba[IFA_ADDRESS]),
RTA_DATA(tba[IFA_ADDRESS]),
abuf, sizeof(abuf));
std::string ipaddr = abuf;
try {
boost::asio::ip::address_v6 addr(boost::asio::ip::address_v6::from_string(ipaddr));
addr.scope_id(ifi->ifi_index);
return addr;
} catch(...) {
return unspec;
}
}
示例10: netlink_if_address_filter
/*
* Netlink interface address lookup filter
* We need to handle multiple primary address and
* multiple secondary address to the same interface.
*/
static int
netlink_if_address_filter(struct sockaddr_nl *snl, struct nlmsghdr *h)
{
struct ifaddrmsg *ifa;
struct rtattr *tb[IFA_MAX + 1];
interface_t *ifp;
int len;
void *addr;
ifa = NLMSG_DATA(h);
/* Only IPV4 are valid us */
if (ifa->ifa_family != AF_INET && ifa->ifa_family != AF_INET6)
return 0;
if (h->nlmsg_type != RTM_NEWADDR && h->nlmsg_type != RTM_DELADDR)
return 0;
len = h->nlmsg_len - NLMSG_LENGTH(sizeof (struct ifaddrmsg));
if (len < 0)
return -1;
memset(tb, 0, sizeof (tb));
parse_rtattr(tb, IFA_MAX, IFA_RTA(ifa), len);
/* Fetch interface_t */
ifp = if_get_by_ifindex(ifa->ifa_index);
if (!ifp)
return 0;
if (tb[IFA_LOCAL] == NULL)
tb[IFA_LOCAL] = tb[IFA_ADDRESS];
if (tb[IFA_ADDRESS] == NULL)
tb[IFA_ADDRESS] = tb[IFA_LOCAL];
/* local interface address */
addr = (tb[IFA_LOCAL] ? RTA_DATA(tb[IFA_LOCAL]) : NULL);
if (addr == NULL)
return -1;
/* If no address is set on interface then set the first time */
if (ifa->ifa_family == AF_INET) {
if (!ifp->sin_addr.s_addr)
ifp->sin_addr = *(struct in_addr *) addr;
} else {
if (!ifp->sin6_addr.s6_addr16[0] && ifa->ifa_scope == RT_SCOPE_LINK)
ifp->sin6_addr = *(struct in6_addr *) addr;
}
#ifdef _WITH_LVS_
/* Refresh checkers state */
update_checker_activity(ifa->ifa_family, addr,
(h->nlmsg_type == RTM_NEWADDR) ? 1 : 0);
#endif
return 0;
}
示例11: handle_addr_msg
static int handle_addr_msg(struct nlmsghdr *nlh, int n)
{
struct ifaddrmsg *ifa_msg = NLMSG_DATA(nlh);
struct rtattr *tb[IFA_MAX];
parse_rt_attrs(tb, IFA_MAX, IFA_RTA(ifa_msg), IFA_PAYLOAD(nlh));
handle_addr_attrs(ifa_msg, tb, nlh->nlmsg_type);
return 0;
}
示例12: process_nl_del_address
void process_nl_del_address (struct nlmsghdr *nlh)
{
struct ifaddrmsg *ifa = NULL;
struct rtattr *rth = NULL;
int iface_index = 0;
int rt_length = 0;
lispd_iface_elt *iface = NULL;
lisp_addr_t new_addr;
char iface_name[IF_NAMESIZE];
ifa = (struct ifaddrmsg *) NLMSG_DATA (nlh);
iface_index = ifa->ifa_index;
iface = get_interface_from_index(iface_index);
if (iface == NULL) {
if_indextoname(iface_index, iface_name);
lispd_log_msg(LISP_LOG_DEBUG_2, "process_nl_add_address: the netlink message is not for any interface associated with RLOCs (%s)",
iface_name);
return;
}
rth = IFA_RTA (ifa);
rth = IFA_RTA (ifa);
rt_length = IFA_PAYLOAD (nlh);
for (; rt_length && RTA_OK (rth, rt_length); rth = RTA_NEXT (rth,rt_length))
{
if (rth->rta_type == IFA_ADDRESS) {
if (ifa->ifa_family == AF_INET) {
memcpy (&(new_addr.address),(struct in_addr *)RTA_DATA(rth),sizeof(struct in_addr));
new_addr.afi = AF_INET;
} else if (ifa->ifa_family == AF_INET6) {
memcpy (&(new_addr.address),(struct in6_addr *)RTA_DATA(rth),sizeof(struct in6_addr));
new_addr.afi = AF_INET6;
}
break;
}
}
/* Actions to be done when address is removed */
lispd_log_msg(LISP_LOG_DEBUG_2," deleted address: %s\n", get_char_from_lisp_addr_t(new_addr));
}
示例13: main
int
main()
{
struct sockaddr_nl addr;
int sock, len;
char buffer[4096];
struct nlmsghdr *nlh;
if ((sock = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) == -1) {
perror("couldn't open NETLINK_ROUTE socket");
return 1;
}
fprintf(stderr,"socket: f%d\n",sock);
memset(&addr, 0, sizeof(addr));
addr.nl_family = AF_NETLINK;
addr.nl_groups = RTMGRP_IPV4_IFADDR;
if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
perror("couldn't bind");
return 1;
}
fprintf(stderr,"bound\n");
nlh = (struct nlmsghdr *)buffer;
while ((len = recv(sock, nlh, 4096, 0)) > 0) {
fprintf(stderr,"recv returned %db (%d %s)\n",len,errno,strerror(errno));
while ((NLMSG_OK(nlh, len)) && (nlh->nlmsg_type != NLMSG_DONE)) {
if (nlh->nlmsg_type == RTM_NEWADDR) {
struct ifaddrmsg *ifa = (struct ifaddrmsg *) NLMSG_DATA(nlh);
struct rtattr *rth = IFA_RTA(ifa);
int rtl = IFA_PAYLOAD(nlh);
while (rtl && RTA_OK(rth, rtl)) {
if (rth->rta_type == IFA_LOCAL) {
uint32_t ipaddr = htonl(*((uint32_t *)RTA_DATA(rth)));
char name[IFNAMSIZ];
if_indextoname(ifa->ifa_index, name);
printf("%s is now %d.%d.%d.%d\n",
name,
(ipaddr >> 24) & 0xff,
(ipaddr >> 16) & 0xff,
(ipaddr >> 8) & 0xff,
ipaddr & 0xff);
}
rth = RTA_NEXT(rth, rtl);
}
}
nlh = NLMSG_NEXT(nlh, len);
}
}
示例14: easycwmp_netlink_interface
static void easycwmp_netlink_interface(struct nlmsghdr *nlh)
{
struct ifaddrmsg *ifa = (struct ifaddrmsg *) NLMSG_DATA(nlh);
struct rtattr *rth = IFA_RTA(ifa);
int rtl = IFA_PAYLOAD(nlh);
char if_name[IFNAMSIZ], if_addr[INET_ADDRSTRLEN];
static old_addr=0;
memset(&if_name, 0, sizeof(if_name));
memset(&if_addr, 0, sizeof(if_addr));
while (rtl && RTA_OK(rth, rtl)) {
if (rth->rta_type != IFA_LOCAL) {
rth = RTA_NEXT(rth, rtl);
continue;
}
uint32_t addr = htonl(* (uint32_t *)RTA_DATA(rth));
if (htonl(13) == 13) {
// running on big endian system
} else {
// running on little endian system
addr = __bswap_32(addr);
}
if_indextoname(ifa->ifa_index, if_name);
if (strncmp(config->local->interface, if_name, IFNAMSIZ)) {
rth = RTA_NEXT(rth, rtl);
continue;
}
if ((addr != old_addr) && (old_addr != 0)) {
log_message(NAME, L_DEBUG, "ip address of the interface %s is changed\n", if_name);
cwmp_add_event(EVENT_VALUE_CHANGE, NULL, 0, EVENT_NO_BACKUP);
cwmp_add_inform_timer();
}
old_addr = addr;
inet_ntop(AF_INET, &(addr), if_addr, INET_ADDRSTRLEN);
if (config->local) FREE(config->local->ip);
config->local->ip = strdup(if_addr);
break;
}
if (strlen(if_addr) == 0) return;
log_message(NAME, L_DEBUG, "interface %s has ip %s\n",
if_name, if_addr);
}
示例15: dcs_local_ip_monitor_process
/*
******************************************************************************
* dcs_local_ip_monitor_process *//**
*
* \brief - Called by the polling thread that gets an indication that the local
* IP address has changed. The function sets the Local IP Address in
* the dcs_local_ip variable
*
* \param[in] socket - The socket on which the information arrived
* \param[in] context - NULL
*
* \retval DOVE_STATUS_OK
*
******************************************************************************
*/
static int dcs_local_ip_monitor_process(int socket, void *context)
{
struct nlmsghdr *nlh;
char buf[4096];
int len;
dove_status status = DOVE_STATUS_OK;
while ((len = recv(dps_monitor_socket, buf, sizeof(buf), 0)) > 0)
{
nlh = (struct nlmsghdr *)buf;
while ((NLMSG_OK(nlh, (uint32_t)len)) && (nlh->nlmsg_type != NLMSG_DONE))
{
if (nlh->nlmsg_type == RTM_NEWADDR || nlh->nlmsg_type == RTM_DELADDR)
{
struct ifaddrmsg *ifa = (struct ifaddrmsg *)NLMSG_DATA(nlh);
struct rtattr *rth = IFA_RTA(ifa);
int rtl = IFA_PAYLOAD(nlh);
while (rtl && RTA_OK(rth, rtl))
{
if (rth->rta_type == IFA_LOCAL)
{
char ifname[IFNAMSIZ];
if_indextoname(ifa->ifa_index, ifname);
if (!strcmp(ifname, SVA_INTERFACE_NAME) && (nlh->nlmsg_type == RTM_NEWADDR))
{
status = set_local_ip();
if (status != DOVE_STATUS_OK)
{
log_warn(PythonDataHandlerLogLevel,
"Cannot get IP Address of SVA");
break;
}
// Register the Local DPS Node with the Cluster
dcs_set_service_role(dcs_role_assigned);
}
}
rth = RTA_NEXT(rth, rtl);
}
}
nlh = NLMSG_NEXT(nlh, len);
}
}
return DOVE_STATUS_OK;
}