xref: /freebsd/sys/netlink/route/neigh.c (revision a57ca37dd1848cd42844d9082c4a74c2ed57f68a)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2022 Alexander V. Chernikov <melifaro@FreeBSD.org>
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #include "opt_netlink.h"
29 
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
32 #include "opt_inet.h"
33 #include "opt_inet6.h"
34 #include <sys/types.h>
35 #include <sys/eventhandler.h>
36 #include <sys/kernel.h>
37 #include <sys/malloc.h>
38 #include <sys/socket.h>
39 #include <sys/syslog.h>
40 
41 #include <net/if.h>
42 #include <net/if_llatbl.h>
43 #include <netlink/netlink.h>
44 #include <netlink/netlink_ctl.h>
45 #include <netlink/netlink_route.h>
46 #include <netlink/route/route_var.h>
47 
48 #include <netinet6/in6_var.h>		/* nd6.h requires this */
49 #include <netinet6/nd6.h>		/* nd6 state machine */
50 #include <netinet6/scope6_var.h>	/* scope deembedding */
51 
52 #define	DEBUG_MOD_NAME	nl_neigh
53 #define	DEBUG_MAX_LEVEL	LOG_DEBUG3
54 #include <netlink/netlink_debug.h>
55 _DECLARE_DEBUG(LOG_INFO);
56 
57 static int lle_families[] = { AF_INET, AF_INET6 };
58 
59 static eventhandler_tag lle_event_p;
60 
61 struct netlink_walkargs {
62 	struct nl_writer *nw;
63 	struct nlmsghdr hdr;
64 	struct nlpcb *so;
65 	struct ifnet *ifp;
66 	int family;
67 	int error;
68 	int count;
69 	int dumped;
70 };
71 
72 static int
73 lle_state_to_nl_state(int family, struct llentry *lle)
74 {
75 	int state = lle->ln_state;
76 
77 	switch (family) {
78 	case AF_INET:
79 		if (lle->la_flags & (LLE_STATIC | LLE_IFADDR))
80 			state = 1;
81 		switch (state) {
82 		case 0: /* ARP_LLINFO_INCOMPLETE */
83 			return (NUD_INCOMPLETE);
84 		case 1: /* ARP_LLINFO_REACHABLE  */
85 			return (NUD_REACHABLE);
86 		case 2: /* ARP_LLINFO_VERIFY */
87 			return (NUD_PROBE);
88 		}
89 		break;
90 	case AF_INET6:
91 		switch (state) {
92 		case ND6_LLINFO_INCOMPLETE:
93 			return (NUD_INCOMPLETE);
94 		case ND6_LLINFO_REACHABLE:
95 			return (NUD_REACHABLE);
96 		case ND6_LLINFO_STALE:
97 			return (NUD_STALE);
98 		case ND6_LLINFO_DELAY:
99 			return (NUD_DELAY);
100 		case ND6_LLINFO_PROBE:
101 			return (NUD_PROBE);
102 		}
103 		break;
104 	}
105 
106 	return (NUD_NONE);
107 }
108 
109 static uint32_t
110 lle_flags_to_nl_flags(const struct llentry *lle)
111 {
112 	uint32_t nl_flags = 0;
113 
114 	if (lle->la_flags & LLE_IFADDR)
115 		nl_flags |= NTF_SELF;
116 	if (lle->la_flags & LLE_PUB)
117 		nl_flags |= NTF_PROXY;
118 	if (lle->la_flags & LLE_STATIC)
119 		nl_flags |= NTF_STICKY;
120 	if (lle->ln_router != 0)
121 		nl_flags |= NTF_ROUTER;
122 
123 	return (nl_flags);
124 }
125 
126 static uint32_t
127 get_lle_next_ts(const struct llentry *lle)
128 {
129 	if (lle->la_expire == 0)
130 		return (0);
131 	return (lle->la_expire + lle->lle_remtime / hz + time_second - time_uptime);
132 }
133 
134 static int
135 dump_lle_locked(struct llentry *lle, void *arg)
136 {
137 	struct netlink_walkargs *wa = (struct netlink_walkargs *)arg;
138 	struct nlmsghdr *hdr = &wa->hdr;
139 	struct nl_writer *nw = wa->nw;
140 	struct ndmsg *ndm;
141 #if defined(INET) || defined(INET6)
142 	union {
143 		struct in_addr	in;
144 		struct in6_addr	in6;
145 	} addr;
146 #endif
147 
148 	IF_DEBUG_LEVEL(LOG_DEBUG2) {
149 		char llebuf[NHOP_PRINT_BUFSIZE];
150 		llentry_print_buf_lltable(lle, llebuf, sizeof(llebuf));
151 		NL_LOG(LOG_DEBUG2, "dumping %s", llebuf);
152 	}
153 
154 	if (!nlmsg_reply(nw, hdr, sizeof(struct ndmsg)))
155 		goto enomem;
156 
157 	ndm = nlmsg_reserve_object(nw, struct ndmsg);
158 	ndm->ndm_family = wa->family;
159 	ndm->ndm_ifindex = wa->ifp->if_index;
160 	ndm->ndm_state = lle_state_to_nl_state(wa->family, lle);
161 	ndm->ndm_flags = lle_flags_to_nl_flags(lle);
162 
163 	switch (wa->family) {
164 #ifdef INET
165 	case AF_INET:
166 		addr.in = lle->r_l3addr.addr4;
167 		nlattr_add(nw, NDA_DST, 4, &addr);
168 		break;
169 #endif
170 #ifdef INET6
171 	case AF_INET6:
172 		addr.in6 = lle->r_l3addr.addr6;
173 		in6_clearscope(&addr.in6);
174 		nlattr_add(nw, NDA_DST, 16, &addr);
175 		break;
176 #endif
177 	}
178 
179 	if (lle->r_flags & RLLE_VALID) {
180 		/* Has L2 */
181 		int addrlen = wa->ifp->if_addrlen;
182 		nlattr_add(nw, NDA_LLADDR, addrlen, lle->ll_addr);
183 	}
184 
185 	nlattr_add_u32(nw, NDA_PROBES, lle->la_asked);
186 
187 	struct nda_cacheinfo *cache;
188 	cache = nlmsg_reserve_attr(nw, NDA_CACHEINFO, struct nda_cacheinfo);
189 	if (cache == NULL)
190 		goto enomem;
191 	/* TODO: provide confirmed/updated */
192 	cache->ndm_refcnt = lle->lle_refcnt;
193 
194 	int off = nlattr_add_nested(nw, NDA_FREEBSD);
195 	if (off != 0) {
196 		nlattr_add_u32(nw, NDAF_NEXT_STATE_TS, get_lle_next_ts(lle));
197 
198 		nlattr_set_len(nw, off);
199 	}
200 
201         if (nlmsg_end(nw))
202 		return (0);
203 enomem:
204         NL_LOG(LOG_DEBUG, "unable to dump lle state (ENOMEM)");
205         nlmsg_abort(nw);
206         return (ENOMEM);
207 }
208 
209 static int
210 dump_lle(struct lltable *llt, struct llentry *lle, void *arg)
211 {
212 	int error;
213 
214 	LLE_RLOCK(lle);
215 	error = dump_lle_locked(lle, arg);
216 	LLE_RUNLOCK(lle);
217 	return (error);
218 }
219 
220 static bool
221 dump_llt(struct lltable *llt, struct netlink_walkargs *wa)
222 {
223 	lltable_foreach_lle(llt, dump_lle, wa);
224 
225 	return (true);
226 }
227 
228 static int
229 dump_llts_iface(struct netlink_walkargs *wa, struct ifnet *ifp, int family)
230 {
231 	int error = 0;
232 
233 	wa->ifp = ifp;
234 	for (int i = 0; i < sizeof(lle_families) / sizeof(int); i++) {
235 		int fam = lle_families[i];
236 		struct lltable *llt = lltable_get(ifp, fam);
237 		if (llt != NULL && (family == 0 || family == fam)) {
238 			wa->count++;
239 			wa->family = fam;
240 			if (!dump_llt(llt, wa)) {
241 				error = ENOMEM;
242 				break;
243 			}
244 			wa->dumped++;
245 		}
246 	}
247 	return (error);
248 }
249 
250 static int
251 dump_llts(struct netlink_walkargs *wa, struct ifnet *ifp, int family)
252 {
253 	NL_LOG(LOG_DEBUG, "Start dump ifp=%s family=%d", ifp ? if_name(ifp) : "NULL", family);
254 
255 	wa->hdr.nlmsg_flags |= NLM_F_MULTI;
256 
257 	if (ifp != NULL) {
258 		dump_llts_iface(wa, ifp, family);
259 	} else {
260 		CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link) {
261 			dump_llts_iface(wa, ifp, family);
262 		}
263 	}
264 
265 	NL_LOG(LOG_DEBUG, "End dump, iterated %d dumped %d", wa->count, wa->dumped);
266 
267 	if (!nlmsg_end_dump(wa->nw, wa->error, &wa->hdr)) {
268                 NL_LOG(LOG_DEBUG, "Unable to add new message");
269                 return (ENOMEM);
270         }
271 
272 	return (0);
273 }
274 
275 static int
276 get_lle(struct netlink_walkargs *wa, struct ifnet *ifp, int family, struct sockaddr *dst)
277 {
278 	struct lltable *llt = lltable_get(ifp, family);
279 	if (llt == NULL)
280 		return (ESRCH);
281 
282 	struct llentry *lle = lla_lookup(llt, LLE_UNLOCKED, dst);
283 	if (lle == NULL)
284 		return (ESRCH);
285 
286 	wa->ifp = ifp;
287 	wa->family = family;
288 
289 	return (dump_lle(llt, lle, wa));
290 }
291 
292 static void
293 set_scope6(struct sockaddr *sa, struct ifnet *ifp)
294 {
295 #ifdef INET6
296 	if (sa != NULL && sa->sa_family == AF_INET6 && ifp != NULL) {
297 		struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)sa;
298 
299 		if (IN6_IS_ADDR_LINKLOCAL(&sa6->sin6_addr))
300 			in6_set_unicast_scopeid(&sa6->sin6_addr, if_getindex(ifp));
301 	}
302 #endif
303 }
304 
305 struct nl_parsed_neigh {
306 	struct sockaddr	*nda_dst;
307 	struct ifnet	*nda_ifp;
308 	struct nlattr	*nda_lladdr;
309 	uint32_t	ndaf_next_ts;
310 	uint32_t	ndm_flags;
311 	uint16_t	ndm_state;
312 	uint8_t		ndm_family;
313 };
314 
315 #define	_IN(_field)	offsetof(struct ndmsg, _field)
316 #define	_OUT(_field)	offsetof(struct nl_parsed_neigh, _field)
317 static const struct nlattr_parser nla_p_neigh_fbsd[] = {
318 	{ .type = NDAF_NEXT_STATE_TS, .off = _OUT(ndaf_next_ts), .cb = nlattr_get_uint32 },
319 };
320 NL_DECLARE_ATTR_PARSER(neigh_fbsd_parser, nla_p_neigh_fbsd);
321 
322 static const struct nlfield_parser nlf_p_neigh[] = {
323 	{ .off_in = _IN(ndm_family), .off_out = _OUT(ndm_family), .cb = nlf_get_u8 },
324 	{ .off_in = _IN(ndm_flags), .off_out = _OUT(ndm_flags), .cb = nlf_get_u8_u32 },
325 	{ .off_in = _IN(ndm_state), .off_out = _OUT(ndm_state), .cb = nlf_get_u16 },
326 	{ .off_in = _IN(ndm_ifindex), .off_out = _OUT(nda_ifp), .cb = nlf_get_ifpz },
327 };
328 
329 static const struct nlattr_parser nla_p_neigh[] = {
330 	{ .type = NDA_DST, .off = _OUT(nda_dst), .cb = nlattr_get_ip },
331 	{ .type = NDA_LLADDR, .off = _OUT(nda_lladdr), .cb = nlattr_get_nla },
332 	{ .type = NDA_IFINDEX, .off = _OUT(nda_ifp), .cb = nlattr_get_ifp },
333 	{ .type = NDA_FLAGS_EXT, .off = _OUT(ndm_flags), .cb = nlattr_get_uint32 },
334 	{ .type = NDA_FREEBSD, .arg = &neigh_fbsd_parser, .cb = nlattr_get_nested },
335 };
336 #undef _IN
337 #undef _OUT
338 
339 static bool
340 post_p_neigh(void *_attrs, struct nl_pstate *npt __unused)
341 {
342 	struct nl_parsed_neigh *attrs = (struct nl_parsed_neigh *)_attrs;
343 
344 	set_scope6(attrs->nda_dst, attrs->nda_ifp);
345 	return (true);
346 }
347 NL_DECLARE_PARSER_EXT(ndmsg_parser, struct ndmsg, NULL, nlf_p_neigh, nla_p_neigh, post_p_neigh);
348 
349 
350 /*
351  * type=RTM_NEWNEIGH, flags=NLM_F_REQUEST|NLM_F_ACK|NLM_F_EXCL|NLM_F_CREATE, seq=1661941473, pid=0},
352  * {ndm_family=AF_INET6, ndm_ifindex=if_nametoindex("enp0s31f6"), ndm_state=NUD_PERMANENT, ndm_flags=0, ndm_type=RTN_UNSPEC},
353  * [
354  *  {{nla_len=20, nla_type=NDA_DST}, inet_pton(AF_INET6, "2a01:4f8:13a:70c::3")},
355  *  {{nla_len=10, nla_type=NDA_LLADDR}, 20:4e:71:62:ae:f2}]}, iov_len=60}
356  */
357 
358 static int
359 rtnl_handle_newneigh(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_pstate *npt)
360 {
361 	int error;
362 
363 	struct nl_parsed_neigh attrs = {};
364 	error = nl_parse_nlmsg(hdr, &ndmsg_parser, npt, &attrs);
365 	if (error != 0)
366 		return (error);
367 
368 	if (attrs.nda_ifp == NULL || attrs.nda_dst == NULL || attrs.nda_lladdr == NULL) {
369 		if (attrs.nda_ifp == NULL)
370 			NLMSG_REPORT_ERR_MSG(npt, "NDA_IFINDEX / ndm_ifindex not set");
371 		if (attrs.nda_dst == NULL)
372 			NLMSG_REPORT_ERR_MSG(npt, "NDA_DST not set");
373 		if (attrs.nda_lladdr == NULL)
374 			NLMSG_REPORT_ERR_MSG(npt, "NDA_LLADDR not set");
375 		return (EINVAL);
376 	}
377 
378 	if (attrs.nda_dst->sa_family != attrs.ndm_family) {
379 		NLMSG_REPORT_ERR_MSG(npt,
380 		    "NDA_DST family (%d) is different from ndm_family (%d)",
381 		    attrs.nda_dst->sa_family, attrs.ndm_family);
382 		return (EINVAL);
383 	}
384 
385 	int addrlen = attrs.nda_ifp->if_addrlen;
386 	if (attrs.nda_lladdr->nla_len != sizeof(struct nlattr) + addrlen) {
387 		NLMSG_REPORT_ERR_MSG(npt,
388 		    "NDA_LLADDR address length (%d) is different from expected (%d)",
389 		    (int)attrs.nda_lladdr->nla_len - (int)sizeof(struct nlattr), addrlen);
390 		return (EINVAL);
391 	}
392 
393 	const uint16_t supported_flags = NTF_PROXY | NTF_STICKY;
394 	if ((attrs.ndm_flags & supported_flags) != attrs.ndm_flags) {
395 		NLMSG_REPORT_ERR_MSG(npt, "ndm_flags %X not supported",
396 		    attrs.ndm_flags &~ supported_flags);
397 		return (ENOTSUP);
398 	}
399 
400 	/* Replacement requires new entry creation anyway */
401 	if ((hdr->nlmsg_flags & (NLM_F_CREATE | NLM_F_REPLACE)) == 0)
402 		return (ENOTSUP);
403 
404 	struct lltable *llt = lltable_get(attrs.nda_ifp, attrs.ndm_family);
405 	if (llt == NULL)
406 		return (EAFNOSUPPORT);
407 
408 
409 	uint8_t linkhdr[LLE_MAX_LINKHDR];
410 	size_t linkhdrsize = sizeof(linkhdr);
411 	int lladdr_off = 0;
412 	if (lltable_calc_llheader(attrs.nda_ifp, attrs.ndm_family,
413 	    (char *)(attrs.nda_lladdr + 1), linkhdr, &linkhdrsize, &lladdr_off) != 0) {
414 		NLMSG_REPORT_ERR_MSG(npt, "unable to calculate lle prepend data");
415 		return (EINVAL);
416 	}
417 
418 	int lle_flags = (attrs.ndm_flags & NTF_PROXY) ? LLE_PUB : 0;
419 	if (attrs.ndm_flags & NTF_STICKY)
420 		lle_flags |= LLE_STATIC;
421 	struct llentry *lle = lltable_alloc_entry(llt, lle_flags, attrs.nda_dst);
422 	if (lle == NULL)
423 		return (ENOMEM);
424 	lltable_set_entry_addr(attrs.nda_ifp, lle, linkhdr, linkhdrsize, lladdr_off);
425 
426 	if (attrs.ndm_flags & NTF_STICKY)
427 		lle->la_expire = 0;
428 	else
429 		lle->la_expire = attrs.ndaf_next_ts - time_second + time_uptime;
430 
431 	/* llentry created, try to insert or update */
432 	IF_AFDATA_WLOCK(attrs.nda_ifp);
433 	LLE_WLOCK(lle);
434 	struct llentry *lle_tmp = lla_lookup(llt, LLE_EXCLUSIVE, attrs.nda_dst);
435 	if (lle_tmp != NULL) {
436 		error = EEXIST;
437 		if (hdr->nlmsg_flags & NLM_F_EXCL) {
438 			LLE_WUNLOCK(lle_tmp);
439 			lle_tmp = NULL;
440 		} else if (hdr->nlmsg_flags & NLM_F_REPLACE) {
441 			if ((lle_tmp->la_flags & LLE_IFADDR) == 0) {
442 				lltable_unlink_entry(llt, lle_tmp);
443 				lltable_link_entry(llt, lle);
444 				error = 0;
445 			} else
446 				error = EPERM;
447 		}
448 	} else {
449 		if (hdr->nlmsg_flags & NLM_F_CREATE)
450 			lltable_link_entry(llt, lle);
451 		else
452 			error = ENOENT;
453 	}
454 	IF_AFDATA_WUNLOCK(attrs.nda_ifp);
455 
456 	if (error != 0) {
457 		if (lle != NULL)
458 			llentry_free(lle);
459 		return (error);
460 	}
461 
462 	if (lle_tmp != NULL)
463 		llentry_free(lle_tmp);
464 
465 	/* XXX: We're inside epoch */
466 	EVENTHANDLER_INVOKE(lle_event, lle, LLENTRY_RESOLVED);
467 	LLE_WUNLOCK(lle);
468 	llt->llt_post_resolved(llt, lle);
469 
470 	return (0);
471 }
472 
473 static int
474 rtnl_handle_delneigh(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_pstate *npt)
475 {
476 	int error;
477 
478 	struct nl_parsed_neigh attrs = {};
479 	error = nl_parse_nlmsg(hdr, &ndmsg_parser, npt, &attrs);
480 	if (error != 0)
481 		return (error);
482 
483 	if (attrs.nda_dst == NULL) {
484 		NLMSG_REPORT_ERR_MSG(npt, "NDA_DST not set");
485 		return (EINVAL);
486 	}
487 
488 	if (attrs.nda_ifp == NULL) {
489 		NLMSG_REPORT_ERR_MSG(npt, "no ifindex provided");
490 		return (EINVAL);
491 	}
492 
493 	struct lltable *llt = lltable_get(attrs.nda_ifp, attrs.ndm_family);
494 	if (llt == NULL)
495 		return (EAFNOSUPPORT);
496 
497 	return (lltable_delete_addr(llt, 0, attrs.nda_dst));
498 }
499 
500 static int
501 rtnl_handle_getneigh(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_pstate *npt)
502 {
503 	int error;
504 
505 	struct nl_parsed_neigh attrs = {};
506 	error = nl_parse_nlmsg(hdr, &ndmsg_parser, npt, &attrs);
507 	if (error != 0)
508 		return (error);
509 
510 	if (attrs.nda_dst != NULL && attrs.nda_ifp == NULL) {
511 		NLMSG_REPORT_ERR_MSG(npt, "has NDA_DST but no ifindex provided");
512 		return (EINVAL);
513 	}
514 
515 	struct netlink_walkargs wa = {
516 		.so = nlp,
517 		.nw = npt->nw,
518 		.hdr.nlmsg_pid = hdr->nlmsg_pid,
519 		.hdr.nlmsg_seq = hdr->nlmsg_seq,
520 		.hdr.nlmsg_flags = hdr->nlmsg_flags,
521 		.hdr.nlmsg_type = NL_RTM_NEWNEIGH,
522 	};
523 
524 	if (attrs.nda_dst == NULL)
525 		error = dump_llts(&wa, attrs.nda_ifp, attrs.ndm_family);
526 	else
527 		error = get_lle(&wa, attrs.nda_ifp, attrs.ndm_family, attrs.nda_dst);
528 
529 	return (error);
530 }
531 
532 static const struct rtnl_cmd_handler cmd_handlers[] = {
533 	{
534 		.cmd = NL_RTM_NEWNEIGH,
535 		.name = "RTM_NEWNEIGH",
536 		.cb = &rtnl_handle_newneigh,
537 		.priv = PRIV_NET_ROUTE,
538 	},
539 	{
540 		.cmd = NL_RTM_DELNEIGH,
541 		.name = "RTM_DELNEIGH",
542 		.cb = &rtnl_handle_delneigh,
543 		.priv = PRIV_NET_ROUTE,
544 	},
545 	{
546 		.cmd = NL_RTM_GETNEIGH,
547 		.name = "RTM_GETNEIGH",
548 		.cb = &rtnl_handle_getneigh,
549 	}
550 };
551 
552 static void
553 rtnl_lle_event(void *arg __unused, struct llentry *lle, int evt)
554 {
555 	struct ifnet *ifp;
556 	int family;
557 
558 	LLE_WLOCK_ASSERT(lle);
559 
560 	ifp = lltable_get_ifp(lle->lle_tbl);
561 	family = lltable_get_af(lle->lle_tbl);
562 
563 	if (family != AF_INET && family != AF_INET6)
564 		return;
565 
566 	int nlmsgs_type = evt == LLENTRY_RESOLVED ? NL_RTM_NEWNEIGH : NL_RTM_DELNEIGH;
567 
568 	struct nl_writer nw = {};
569 	if (!nlmsg_get_group_writer(&nw, NLMSG_SMALL, NETLINK_ROUTE, RTNLGRP_NEIGH)) {
570 		NL_LOG(LOG_DEBUG, "error allocating group writer");
571 		return;
572 	}
573 
574 	struct netlink_walkargs wa = {
575 		.hdr.nlmsg_type = nlmsgs_type,
576 		.nw = &nw,
577 		.ifp = ifp,
578 		.family = family,
579 	};
580 
581 	dump_lle_locked(lle, &wa);
582 	nlmsg_flush(&nw);
583 }
584 
585 static const struct nlhdr_parser *all_parsers[] = { &ndmsg_parser, &neigh_fbsd_parser };
586 
587 void
588 rtnl_neighs_init(void)
589 {
590 	NL_VERIFY_PARSERS(all_parsers);
591 	rtnl_register_messages(cmd_handlers, NL_ARRAY_LEN(cmd_handlers));
592 	lle_event_p = EVENTHANDLER_REGISTER(lle_event, rtnl_lle_event, NULL,
593 	    EVENTHANDLER_PRI_ANY);
594 }
595 
596 void
597 rtnl_neighs_destroy(void)
598 {
599 	EVENTHANDLER_DEREGISTER(lle_event, lle_event_p);
600 }
601