2 * Copyright (C) 2017 Hans Dedecker <dedeckeh@gmail.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License v2 as published by
6 * the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
19 #include <linux/netlink.h>
20 #include <linux/if_addr.h>
21 #include <linux/neighbour.h>
22 #include <linux/rtnetlink.h>
24 #include <netlink/msg.h>
25 #include <netlink/socket.h>
26 #include <netlink/attr.h>
28 #include <arpa/inet.h>
29 #include <libubox/list.h>
34 struct odhcpd_event ev
;
39 static void handle_rtnl_event(struct odhcpd_event
*ev
);
40 static int cb_rtnl_valid(struct nl_msg
*msg
, void *arg
);
41 static void catch_rtnl_err(struct odhcpd_event
*e
, int error
);
42 static struct nl_sock
*create_socket(int protocol
);
44 static struct nl_sock
*rtnl_socket
= NULL
;
45 struct list_head netevent_handler_list
= LIST_HEAD_INIT(netevent_handler_list
);
46 static struct event_socket rtnl_event
= {
48 .uloop
= {.fd
= - 1, },
50 .handle_error
= catch_rtnl_err
,
51 .recv_msgs
= handle_rtnl_event
,
54 .sock_bufsize
= 133120,
57 int netlink_init(void)
59 rtnl_socket
= create_socket(NETLINK_ROUTE
);
61 syslog(LOG_ERR
, "Unable to open nl socket: %m");
65 rtnl_event
.sock
= create_socket(NETLINK_ROUTE
);
66 if (!rtnl_event
.sock
) {
67 syslog(LOG_ERR
, "Unable to open nl event socket: %m");
71 rtnl_event
.ev
.uloop
.fd
= nl_socket_get_fd(rtnl_event
.sock
);
73 if (nl_socket_set_buffer_size(rtnl_event
.sock
, rtnl_event
.sock_bufsize
, 0))
76 nl_socket_disable_seq_check(rtnl_event
.sock
);
78 nl_socket_modify_cb(rtnl_event
.sock
, NL_CB_VALID
, NL_CB_CUSTOM
,
81 /* Receive IPv4 address, IPv6 address, IPv6 routes and neighbor events */
82 if (nl_socket_add_memberships(rtnl_event
.sock
, RTNLGRP_IPV4_IFADDR
,
83 RTNLGRP_IPV6_IFADDR
, RTNLGRP_IPV6_ROUTE
,
84 RTNLGRP_NEIGH
, RTNLGRP_LINK
, 0))
87 odhcpd_register(&rtnl_event
.ev
);
93 nl_socket_free(rtnl_socket
);
97 if (rtnl_event
.sock
) {
98 nl_socket_free(rtnl_event
.sock
);
99 rtnl_event
.sock
= NULL
;
100 rtnl_event
.ev
.uloop
.fd
= -1;
107 int netlink_add_netevent_handler(struct netevent_handler
*handler
)
112 list_add(&handler
->head
, &netevent_handler_list
);
117 static void call_netevent_handler_list(unsigned long event
, struct netevent_handler_info
*info
)
119 struct netevent_handler
*handler
;
121 list_for_each_entry(handler
, &netevent_handler_list
, head
)
122 handler
->cb(event
, info
);
125 static void handle_rtnl_event(struct odhcpd_event
*e
)
127 struct event_socket
*ev_sock
= container_of(e
, struct event_socket
, ev
);
129 nl_recvmsgs_default(ev_sock
->sock
);
132 static void refresh_iface_addr4(int ifindex
)
134 struct odhcpd_ipaddr
*addr
= NULL
;
135 struct interface
*iface
;
136 ssize_t len
= netlink_get_interface_addrs(ifindex
, false, &addr
);
142 avl_for_each_element(&interfaces
, iface
, avl
) {
143 if (iface
->ifindex
!= ifindex
)
146 change
= len
!= (ssize_t
)iface
->addr4_len
;
147 for (ssize_t i
= 0; !change
&& i
< len
; ++i
) {
148 if (addr
[i
].addr
.in
.s_addr
!= iface
->addr4
[i
].addr
.in
.s_addr
)
159 avl_for_element_range(iface
, avl_last_element(&interfaces
, iface
, avl
), iface
, avl
) {
160 struct netevent_handler_info event_info
;
162 if (iface
->ifindex
!= ifindex
)
165 memset(&event_info
, 0, sizeof(event_info
));
166 event_info
.iface
= iface
;
167 event_info
.addrs_old
.addrs
= iface
->addr4
;
168 event_info
.addrs_old
.len
= iface
->addr4_len
;
171 iface
->addr4_len
= len
;
173 call_netevent_handler_list(NETEV_ADDRLIST_CHANGE
, &event_info
);
175 free(event_info
.addrs_old
.addrs
);
178 addr
= malloc(len
* sizeof(*addr
));
182 memcpy(addr
, iface
->addr4
, len
* sizeof(*addr
));
189 static void refresh_iface_addr6(int ifindex
)
191 struct odhcpd_ipaddr
*addr
= NULL
;
192 struct interface
*iface
;
193 ssize_t len
= netlink_get_interface_addrs(ifindex
, true, &addr
);
194 time_t now
= odhcpd_time();
200 avl_for_each_element(&interfaces
, iface
, avl
) {
201 if (iface
->ifindex
!= ifindex
)
204 change
= len
!= (ssize_t
)iface
->addr6_len
;
205 for (ssize_t i
= 0; !change
&& i
< len
; ++i
) {
206 if (!IN6_ARE_ADDR_EQUAL(&addr
[i
].addr
.in6
, &iface
->addr6
[i
].addr
.in6
) ||
207 (addr
[i
].preferred
> (uint32_t)now
) != (iface
->addr6
[i
].preferred
> (uint32_t)now
) ||
208 addr
[i
].valid
< iface
->addr6
[i
].valid
|| addr
[i
].preferred
< iface
->addr6
[i
].preferred
)
217 iface
->addr6_len
= len
;
221 avl_for_element_range(iface
, avl_last_element(&interfaces
, iface
, avl
), iface
, avl
) {
222 struct netevent_handler_info event_info
;
224 if (iface
->ifindex
!= ifindex
)
227 memset(&event_info
, 0, sizeof(event_info
));
228 event_info
.iface
= iface
;
229 event_info
.addrs_old
.addrs
= iface
->addr6
;
230 event_info
.addrs_old
.len
= iface
->addr6_len
;
233 iface
->addr6_len
= len
;
235 call_netevent_handler_list(NETEV_ADDR6LIST_CHANGE
, &event_info
);
237 free(event_info
.addrs_old
.addrs
);
240 addr
= malloc(len
* sizeof(*addr
));
244 memcpy(addr
, iface
->addr6
, len
* sizeof(*addr
));
251 static int handle_rtm_link(struct nlmsghdr
*hdr
)
253 struct ifinfomsg
*ifi
= nlmsg_data(hdr
);
254 struct nlattr
*nla
[__IFLA_MAX
];
255 struct interface
*iface
;
256 struct netevent_handler_info event_info
;
259 memset(&event_info
, 0, sizeof(event_info
));
261 if (!nlmsg_valid_hdr(hdr
, sizeof(*ifi
)) || ifi
->ifi_family
!= AF_UNSPEC
)
264 nlmsg_parse(hdr
, sizeof(*ifi
), nla
, __IFLA_MAX
- 1, NULL
);
265 if (!nla
[IFLA_IFNAME
])
268 ifname
= nla_get_string(nla
[IFLA_IFNAME
]);
270 avl_for_each_element(&interfaces
, iface
, avl
) {
271 if (strcmp(iface
->ifname
, ifname
) || iface
->ifindex
== ifi
->ifi_index
)
274 iface
->ifindex
= ifi
->ifi_index
;
275 event_info
.iface
= iface
;
276 call_netevent_handler_list(NETEV_IFINDEX_CHANGE
, &event_info
);
282 static int handle_rtm_route(struct nlmsghdr
*hdr
, bool add
)
284 struct rtmsg
*rtm
= nlmsg_data(hdr
);
285 struct nlattr
*nla
[__RTA_MAX
];
286 struct interface
*iface
;
287 struct netevent_handler_info event_info
;
290 if (!nlmsg_valid_hdr(hdr
, sizeof(*rtm
)) || rtm
->rtm_family
!= AF_INET6
)
293 nlmsg_parse(hdr
, sizeof(*rtm
), nla
, __RTA_MAX
- 1, NULL
);
295 memset(&event_info
, 0, sizeof(event_info
));
296 event_info
.rt
.dst_len
= rtm
->rtm_dst_len
;
299 nla_memcpy(&event_info
.rt
.dst
, nla
[RTA_DST
],
300 sizeof(event_info
.rt
.dst
));
303 ifindex
= nla_get_u32(nla
[RTA_OIF
]);
305 if (nla
[RTA_GATEWAY
])
306 nla_memcpy(&event_info
.rt
.gateway
, nla
[RTA_GATEWAY
],
307 sizeof(event_info
.rt
.gateway
));
309 avl_for_each_element(&interfaces
, iface
, avl
) {
310 if (ifindex
&& iface
->ifindex
!= ifindex
)
313 event_info
.iface
= ifindex
? iface
: NULL
;
314 call_netevent_handler_list(add
? NETEV_ROUTE6_ADD
: NETEV_ROUTE6_DEL
,
321 static int handle_rtm_addr(struct nlmsghdr
*hdr
, bool add
)
323 struct ifaddrmsg
*ifa
= nlmsg_data(hdr
);
324 struct nlattr
*nla
[__IFA_MAX
];
325 struct interface
*iface
;
326 struct netevent_handler_info event_info
;
327 char buf
[INET6_ADDRSTRLEN
];
329 if (!nlmsg_valid_hdr(hdr
, sizeof(*ifa
)) ||
330 (ifa
->ifa_family
!= AF_INET6
&&
331 ifa
->ifa_family
!= AF_INET
))
334 memset(&event_info
, 0, sizeof(event_info
));
336 nlmsg_parse(hdr
, sizeof(*ifa
), nla
, __IFA_MAX
- 1, NULL
);
338 if (ifa
->ifa_family
== AF_INET6
) {
339 if (!nla
[IFA_ADDRESS
])
342 nla_memcpy(&event_info
.addr
, nla
[IFA_ADDRESS
], sizeof(event_info
.addr
));
344 if (IN6_IS_ADDR_LINKLOCAL(&event_info
.addr
) || IN6_IS_ADDR_MULTICAST(&event_info
.addr
))
347 inet_ntop(AF_INET6
, &event_info
.addr
, buf
, sizeof(buf
));
349 avl_for_each_element(&interfaces
, iface
, avl
) {
350 if (iface
->ifindex
!= (int)ifa
->ifa_index
)
353 syslog(LOG_DEBUG
, "Netlink %s %s on %s", add
? "newaddr" : "deladdr",
356 event_info
.iface
= iface
;
357 call_netevent_handler_list(add
? NETEV_ADDR6_ADD
: NETEV_ADDR6_DEL
,
361 refresh_iface_addr6(ifa
->ifa_index
);
366 nla_memcpy(&event_info
.addr
, nla
[IFA_LOCAL
], sizeof(event_info
.addr
));
368 inet_ntop(AF_INET
, &event_info
.addr
, buf
, sizeof(buf
));
370 avl_for_each_element(&interfaces
, iface
, avl
) {
371 if (iface
->ifindex
!= (int)ifa
->ifa_index
)
374 syslog(LOG_DEBUG
, "Netlink %s %s on %s", add
? "newaddr" : "deladdr",
377 event_info
.iface
= iface
;
378 call_netevent_handler_list(add
? NETEV_ADDR_ADD
: NETEV_ADDR_DEL
,
382 refresh_iface_addr4(ifa
->ifa_index
);
388 static int handle_rtm_neigh(struct nlmsghdr
*hdr
, bool add
)
390 struct ndmsg
*ndm
= nlmsg_data(hdr
);
391 struct nlattr
*nla
[__NDA_MAX
];
392 struct interface
*iface
;
393 struct netevent_handler_info event_info
;
394 char buf
[INET6_ADDRSTRLEN
];
396 if (!nlmsg_valid_hdr(hdr
, sizeof(*ndm
)) ||
397 ndm
->ndm_family
!= AF_INET6
)
400 nlmsg_parse(hdr
, sizeof(*ndm
), nla
, __NDA_MAX
- 1, NULL
);
404 memset(&event_info
, 0, sizeof(event_info
));
406 nla_memcpy(&event_info
.neigh
.dst
, nla
[NDA_DST
], sizeof(event_info
.neigh
.dst
));
408 if (IN6_IS_ADDR_LINKLOCAL(&event_info
.neigh
.dst
) ||
409 IN6_IS_ADDR_MULTICAST(&event_info
.neigh
.dst
))
412 inet_ntop(AF_INET6
, &event_info
.neigh
.dst
, buf
, sizeof(buf
));
414 avl_for_each_element(&interfaces
, iface
, avl
) {
415 if (iface
->ifindex
!= ndm
->ndm_ifindex
)
418 syslog(LOG_DEBUG
, "Netlink %s %s on %s", true ? "newneigh" : "delneigh",
421 event_info
.iface
= iface
;
422 event_info
.neigh
.state
= ndm
->ndm_state
;
423 event_info
.neigh
.flags
= ndm
->ndm_flags
;
425 call_netevent_handler_list(add
? NETEV_NEIGH6_ADD
: NETEV_NEIGH6_DEL
,
432 /* Handler for neighbor cache entries from the kernel. This is our source
433 * to learn and unlearn hosts on interfaces. */
434 static int cb_rtnl_valid(struct nl_msg
*msg
, _unused
void *arg
)
436 struct nlmsghdr
*hdr
= nlmsg_hdr(msg
);
440 switch (hdr
->nlmsg_type
) {
442 ret
= handle_rtm_link(hdr
);
449 ret
= handle_rtm_route(hdr
, add
);
456 ret
= handle_rtm_addr(hdr
, add
);
463 ret
= handle_rtm_neigh(hdr
, add
);
473 static void catch_rtnl_err(struct odhcpd_event
*e
, int error
)
475 struct event_socket
*ev_sock
= container_of(e
, struct event_socket
, ev
);
477 if (error
!= ENOBUFS
)
480 /* Double netlink event buffer size */
481 ev_sock
->sock_bufsize
*= 2;
483 if (nl_socket_set_buffer_size(ev_sock
->sock
, ev_sock
->sock_bufsize
, 0))
486 netlink_dump_addr_table(true);
490 odhcpd_deregister(e
);
493 static struct nl_sock
*create_socket(int protocol
)
495 struct nl_sock
*nl_sock
;
497 nl_sock
= nl_socket_alloc();
501 if (nl_connect(nl_sock
, protocol
) < 0)
508 nl_socket_free(nl_sock
);
517 struct odhcpd_ipaddr
**addrs
;
523 static int cb_valid_handler(struct nl_msg
*msg
, void *arg
)
525 struct addr_info
*ctxt
= (struct addr_info
*)arg
;
526 struct odhcpd_ipaddr
*addrs
= *(ctxt
->addrs
);
527 struct nlmsghdr
*hdr
= nlmsg_hdr(msg
);
528 struct ifaddrmsg
*ifa
;
529 struct nlattr
*nla
[__IFA_MAX
], *nla_addr
= NULL
;
531 if (hdr
->nlmsg_type
!= RTM_NEWADDR
)
534 ifa
= NLMSG_DATA(hdr
);
535 if (ifa
->ifa_scope
!= RT_SCOPE_UNIVERSE
||
536 (ctxt
->af
!= ifa
->ifa_family
) ||
537 (ctxt
->ifindex
&& ifa
->ifa_index
!= (unsigned)ctxt
->ifindex
))
540 nlmsg_parse(hdr
, sizeof(*ifa
), nla
, __IFA_MAX
- 1, NULL
);
542 switch (ifa
->ifa_family
) {
544 if (nla
[IFA_ADDRESS
])
545 nla_addr
= nla
[IFA_ADDRESS
];
550 nla_addr
= nla
[IFA_LOCAL
];
559 addrs
= realloc(addrs
, sizeof(*addrs
)*(ctxt
->ret
+ 1));
563 memset(&addrs
[ctxt
->ret
], 0, sizeof(addrs
[ctxt
->ret
]));
564 addrs
[ctxt
->ret
].prefix
= ifa
->ifa_prefixlen
;
566 nla_memcpy(&addrs
[ctxt
->ret
].addr
, nla_addr
,
567 sizeof(addrs
[ctxt
->ret
].addr
));
569 if (nla
[IFA_BROADCAST
])
570 nla_memcpy(&addrs
[ctxt
->ret
].broadcast
, nla
[IFA_BROADCAST
],
571 sizeof(addrs
[ctxt
->ret
].broadcast
));
573 if (nla
[IFA_CACHEINFO
]) {
574 struct ifa_cacheinfo
*ifc
= nla_data(nla
[IFA_CACHEINFO
]);
576 addrs
[ctxt
->ret
].preferred
= ifc
->ifa_prefered
;
577 addrs
[ctxt
->ret
].valid
= ifc
->ifa_valid
;
580 if (ifa
->ifa_flags
& IFA_F_DEPRECATED
)
581 addrs
[ctxt
->ret
].preferred
= 0;
584 *(ctxt
->addrs
) = addrs
;
590 static int cb_finish_handler(_unused
struct nl_msg
*msg
, void *arg
)
592 struct addr_info
*ctxt
= (struct addr_info
*)arg
;
600 static int cb_error_handler(_unused
struct sockaddr_nl
*nla
, struct nlmsgerr
*err
,
603 struct addr_info
*ctxt
= (struct addr_info
*)arg
;
606 ctxt
->ret
= err
->error
;
612 static int prefix_cmp(const void *va
, const void *vb
)
614 const struct odhcpd_ipaddr
*a
= va
, *b
= vb
;
617 if (a
->prefix
== b
->prefix
) {
618 ret
= (ntohl(a
->addr
.in
.s_addr
) < ntohl(b
->addr
.in
.s_addr
)) ? 1 :
619 (ntohl(a
->addr
.in
.s_addr
) > ntohl(b
->addr
.in
.s_addr
)) ? -1 : 0;
621 ret
= a
->prefix
< b
->prefix
? 1 : -1;
627 /* compare IPv6 prefixes */
628 static int prefix6_cmp(const void *va
, const void *vb
)
630 const struct odhcpd_ipaddr
*a
= va
, *b
= vb
;
631 uint32_t a_pref
= IN6_IS_ADDR_ULA(&a
->addr
.in6
) ? 1 : a
->preferred
;
632 uint32_t b_pref
= IN6_IS_ADDR_ULA(&b
->addr
.in6
) ? 1 : b
->preferred
;
633 return (a_pref
< b_pref
) ? 1 : (a_pref
> b_pref
) ? -1 : 0;
637 /* Detect an IPV6-address currently assigned to the given interface */
638 ssize_t
netlink_get_interface_addrs(int ifindex
, bool v6
, struct odhcpd_ipaddr
**addrs
)
641 struct ifaddrmsg ifa
= {
642 .ifa_family
= v6
? AF_INET6
: AF_INET
,
646 .ifa_index
= ifindex
, };
647 struct nl_cb
*cb
= nl_cb_alloc(NL_CB_DEFAULT
);
648 struct addr_info ctxt
= {
650 .af
= v6
? AF_INET6
: AF_INET
,
661 msg
= nlmsg_alloc_simple(RTM_GETADDR
, NLM_F_REQUEST
| NLM_F_DUMP
);
668 nlmsg_append(msg
, &ifa
, sizeof(ifa
), 0);
670 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
, cb_valid_handler
, &ctxt
);
671 nl_cb_set(cb
, NL_CB_FINISH
, NL_CB_CUSTOM
, cb_finish_handler
, &ctxt
);
672 nl_cb_err(cb
, NL_CB_CUSTOM
, cb_error_handler
, &ctxt
);
674 nl_send_auto_complete(rtnl_socket
, msg
);
675 while (ctxt
.pending
> 0)
676 nl_recvmsgs(rtnl_socket
, cb
);
683 time_t now
= odhcpd_time();
684 struct odhcpd_ipaddr
*addr
= *addrs
;
686 qsort(addr
, ctxt
.ret
, sizeof(*addr
), v6
? prefix6_cmp
: prefix_cmp
);
688 for (ssize_t i
= 0; i
< ctxt
.ret
; ++i
) {
689 if (addr
[i
].preferred
< UINT32_MAX
- now
)
690 addr
[i
].preferred
+= now
;
692 if (addr
[i
].valid
< UINT32_MAX
- now
)
693 addr
[i
].valid
+= now
;
703 int netlink_setup_route(const struct in6_addr
*addr
, const int prefixlen
,
704 const int ifindex
, const struct in6_addr
*gw
,
705 const uint32_t metric
, const bool add
)
709 .rtm_family
= AF_INET6
,
710 .rtm_dst_len
= prefixlen
,
712 .rtm_table
= RT_TABLE_MAIN
,
713 .rtm_protocol
= (add
? RTPROT_STATIC
: RTPROT_UNSPEC
),
714 .rtm_scope
= (add
? (gw
? RT_SCOPE_UNIVERSE
: RT_SCOPE_LINK
) : RT_SCOPE_NOWHERE
),
715 .rtm_type
= (add
? RTN_UNICAST
: RTN_UNSPEC
),
719 msg
= nlmsg_alloc_simple(add
? RTM_NEWROUTE
: RTM_DELROUTE
,
720 add
? NLM_F_CREATE
| NLM_F_REPLACE
: 0);
724 nlmsg_append(msg
, &rtm
, sizeof(rtm
), 0);
726 nla_put(msg
, RTA_DST
, sizeof(*addr
), addr
);
727 nla_put_u32(msg
, RTA_OIF
, ifindex
);
728 nla_put_u32(msg
, RTA_PRIORITY
, metric
);
731 nla_put(msg
, RTA_GATEWAY
, sizeof(*gw
), gw
);
733 ret
= nl_send_auto_complete(rtnl_socket
, msg
);
739 return nl_wait_for_ack(rtnl_socket
);
743 int netlink_setup_proxy_neigh(const struct in6_addr
*addr
,
744 const int ifindex
, const bool add
)
748 .ndm_family
= AF_INET6
,
749 .ndm_flags
= NTF_PROXY
,
750 .ndm_ifindex
= ifindex
,
752 int ret
= 0, flags
= NLM_F_REQUEST
;
755 flags
|= NLM_F_REPLACE
| NLM_F_CREATE
;
757 msg
= nlmsg_alloc_simple(add
? RTM_NEWNEIGH
: RTM_DELNEIGH
, flags
);
761 nlmsg_append(msg
, &ndm
, sizeof(ndm
), 0);
763 nla_put(msg
, NDA_DST
, sizeof(*addr
), addr
);
765 ret
= nl_send_auto_complete(rtnl_socket
, msg
);
771 return nl_wait_for_ack(rtnl_socket
);
775 int netlink_setup_addr(struct odhcpd_ipaddr
*addr
,
776 const int ifindex
, const bool v6
, const bool add
)
779 struct ifaddrmsg ifa
= {
780 .ifa_family
= v6
? AF_INET6
: AF_INET
,
781 .ifa_prefixlen
= addr
->prefix
,
784 .ifa_index
= ifindex
, };
785 int ret
= 0, flags
= NLM_F_REQUEST
;
788 flags
|= NLM_F_REPLACE
| NLM_F_CREATE
;
790 msg
= nlmsg_alloc_simple(add
? RTM_NEWADDR
: RTM_DELADDR
, 0);
794 nlmsg_append(msg
, &ifa
, sizeof(ifa
), flags
);
795 nla_put(msg
, IFA_LOCAL
, v6
? 16 : 4, &addr
->addr
);
797 struct ifa_cacheinfo cinfo
= { .ifa_prefered
= 0xffffffffU
,
798 .ifa_valid
= 0xffffffffU
,
801 time_t now
= odhcpd_time();
803 if (addr
->preferred
) {
804 int64_t preferred
= addr
->preferred
- now
;
807 else if (preferred
> UINT32_MAX
)
808 preferred
= UINT32_MAX
;
810 cinfo
.ifa_prefered
= preferred
;
814 int64_t valid
= addr
->valid
- now
;
819 else if (valid
> UINT32_MAX
)
822 cinfo
.ifa_valid
= valid
;
825 nla_put(msg
, IFA_CACHEINFO
, sizeof(cinfo
), &cinfo
);
827 nla_put_u32(msg
, IFA_FLAGS
, IFA_F_NOPREFIXROUTE
);
829 if (addr
->broadcast
.s_addr
)
830 nla_put_u32(msg
, IFA_BROADCAST
, addr
->broadcast
.s_addr
);
833 ret
= nl_send_auto_complete(rtnl_socket
, msg
);
839 return nl_wait_for_ack(rtnl_socket
);
842 void netlink_dump_neigh_table(const bool proxy
)
846 .ndm_family
= AF_INET6
,
847 .ndm_flags
= proxy
? NTF_PROXY
: 0,
850 msg
= nlmsg_alloc_simple(RTM_GETNEIGH
, NLM_F_REQUEST
| NLM_F_DUMP
);
854 nlmsg_append(msg
, &ndm
, sizeof(ndm
), 0);
856 nl_send_auto_complete(rtnl_event
.sock
, msg
);
861 void netlink_dump_addr_table(const bool v6
)
864 struct ifaddrmsg ifa
= {
865 .ifa_family
= v6
? AF_INET6
: AF_INET
,
868 msg
= nlmsg_alloc_simple(RTM_GETADDR
, NLM_F_REQUEST
| NLM_F_DUMP
);
872 nlmsg_append(msg
, &ifa
, sizeof(ifa
), 0);
874 nl_send_auto_complete(rtnl_event
.sock
, msg
);