xref: /freebsd/sys/netlink/route/neigh.c (revision d09a955a605d03471c5ab7bd17b8a6186fdc148c)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
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_DEBUG);
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 #ifdef INET6
283 	if (dst->sa_family == AF_INET6) {
284 		struct sockaddr_in6 *dst6 = (struct sockaddr_in6 *)dst;
285 
286 		if (IN6_IS_SCOPE_LINKLOCAL(&dst6->sin6_addr))
287 			in6_set_unicast_scopeid(&dst6->sin6_addr, ifp->if_index);
288 	}
289 #endif
290 	struct llentry *lle = lla_lookup(llt, LLE_UNLOCKED, dst);
291 	if (lle == NULL)
292 		return (ESRCH);
293 
294 	wa->ifp = ifp;
295 	wa->family = family;
296 
297 	return (dump_lle(llt, lle, wa));
298 }
299 
300 struct nl_parsed_neigh {
301 	struct sockaddr	*nda_dst;
302 	struct ifnet	*nda_ifp;
303 	struct nlattr	*nda_lladdr;
304 	uint32_t	ndaf_next_ts;
305 	uint32_t	ndm_flags;
306 	uint16_t	ndm_state;
307 	uint8_t		ndm_family;
308 };
309 
310 #define	_IN(_field)	offsetof(struct ndmsg, _field)
311 #define	_OUT(_field)	offsetof(struct nl_parsed_neigh, _field)
312 static const struct nlattr_parser nla_p_neigh_fbsd[] = {
313 	{ .type = NDAF_NEXT_STATE_TS, .off = _OUT(ndaf_next_ts), .cb = nlattr_get_uint32 },
314 };
315 NL_DECLARE_ATTR_PARSER(neigh_fbsd_parser, nla_p_neigh_fbsd);
316 
317 static const struct nlfield_parser nlf_p_neigh[] = {
318 	{ .off_in = _IN(ndm_family), .off_out = _OUT(ndm_family), .cb = nlf_get_u8 },
319 	{ .off_in = _IN(ndm_flags), .off_out = _OUT(ndm_flags), .cb = nlf_get_u8_u32 },
320 	{ .off_in = _IN(ndm_state), .off_out = _OUT(ndm_state), .cb = nlf_get_u16 },
321 	{ .off_in = _IN(ndm_ifindex), .off_out = _OUT(nda_ifp), .cb = nlf_get_ifpz },
322 };
323 
324 static const struct nlattr_parser nla_p_neigh[] = {
325 	{ .type = NDA_DST, .off = _OUT(nda_dst), .cb = nlattr_get_ip },
326 	{ .type = NDA_LLADDR, .off = _OUT(nda_lladdr), .cb = nlattr_get_nla },
327 	{ .type = NDA_IFINDEX, .off = _OUT(nda_ifp), .cb = nlattr_get_ifp },
328 	{ .type = NDA_FLAGS_EXT, .off = _OUT(ndm_flags), .cb = nlattr_get_uint32 },
329 	{ .type = NDA_FREEBSD, .arg = &neigh_fbsd_parser, .cb = nlattr_get_nested },
330 };
331 #undef _IN
332 #undef _OUT
333 NL_DECLARE_PARSER(ndmsg_parser, struct ndmsg, nlf_p_neigh, nla_p_neigh);
334 
335 
336 /*
337  * type=RTM_NEWNEIGH, flags=NLM_F_REQUEST|NLM_F_ACK|NLM_F_EXCL|NLM_F_CREATE, seq=1661941473, pid=0},
338  * {ndm_family=AF_INET6, ndm_ifindex=if_nametoindex("enp0s31f6"), ndm_state=NUD_PERMANENT, ndm_flags=0, ndm_type=RTN_UNSPEC},
339  * [
340  *  {{nla_len=20, nla_type=NDA_DST}, inet_pton(AF_INET6, "2a01:4f8:13a:70c::3")},
341  *  {{nla_len=10, nla_type=NDA_LLADDR}, 20:4e:71:62:ae:f2}]}, iov_len=60}
342  */
343 
344 static int
345 rtnl_handle_newneigh(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_pstate *npt)
346 {
347 	int error;
348 
349 	struct nl_parsed_neigh attrs = {};
350 	error = nl_parse_nlmsg(hdr, &ndmsg_parser, npt, &attrs);
351 	if (error != 0)
352 		return (error);
353 
354 	if (attrs.nda_ifp == NULL || attrs.nda_dst == NULL || attrs.nda_lladdr == NULL) {
355 		if (attrs.nda_ifp == NULL)
356 			NLMSG_REPORT_ERR_MSG(npt, "NDA_IFINDEX / ndm_ifindex not set");
357 		if (attrs.nda_dst == NULL)
358 			NLMSG_REPORT_ERR_MSG(npt, "NDA_DST not set");
359 		if (attrs.nda_lladdr == NULL)
360 			NLMSG_REPORT_ERR_MSG(npt, "NDA_LLADDR not set");
361 		return (EINVAL);
362 	}
363 
364 	if (attrs.nda_dst->sa_family != attrs.ndm_family) {
365 		NLMSG_REPORT_ERR_MSG(npt,
366 		    "NDA_DST family (%d) is different from ndm_family (%d)",
367 		    attrs.nda_dst->sa_family, attrs.ndm_family);
368 		return (EINVAL);
369 	}
370 
371 	int addrlen = attrs.nda_ifp->if_addrlen;
372 	if (attrs.nda_lladdr->nla_len != sizeof(struct nlattr) + addrlen) {
373 		NLMSG_REPORT_ERR_MSG(npt,
374 		    "NDA_LLADDR address length (%d) is different from expected (%d)",
375 		    (int)attrs.nda_lladdr->nla_len - (int)sizeof(struct nlattr), addrlen);
376 		return (EINVAL);
377 	}
378 
379 	const uint16_t supported_flags = NTF_PROXY | NTF_STICKY;
380 	if ((attrs.ndm_flags & supported_flags) != attrs.ndm_flags) {
381 		NLMSG_REPORT_ERR_MSG(npt, "ndm_flags %X not supported",
382 		    attrs.ndm_flags &~ supported_flags);
383 		return (ENOTSUP);
384 	}
385 
386 	/* Replacement requires new entry creation anyway */
387 	if ((hdr->nlmsg_flags & (NLM_F_CREATE | NLM_F_REPLACE)) == 0)
388 		return (ENOTSUP);
389 
390 	struct lltable *llt = lltable_get(attrs.nda_ifp, attrs.ndm_family);
391 	if (llt == NULL)
392 		return (EAFNOSUPPORT);
393 
394 
395 	uint8_t linkhdr[LLE_MAX_LINKHDR];
396 	size_t linkhdrsize = sizeof(linkhdr);
397 	int lladdr_off = 0;
398 	if (lltable_calc_llheader(attrs.nda_ifp, attrs.ndm_family,
399 	    (char *)(attrs.nda_lladdr + 1), linkhdr, &linkhdrsize, &lladdr_off) != 0) {
400 		NLMSG_REPORT_ERR_MSG(npt, "unable to calculate lle prepend data");
401 		return (EINVAL);
402 	}
403 
404 	int lle_flags = (attrs.ndm_flags & NTF_PROXY) ? LLE_PUB : 0;
405 	if (attrs.ndm_flags & NTF_STICKY)
406 		lle_flags |= LLE_STATIC;
407 	struct llentry *lle = lltable_alloc_entry(llt, lle_flags, attrs.nda_dst);
408 	if (lle == NULL)
409 		return (ENOMEM);
410 	lltable_set_entry_addr(attrs.nda_ifp, lle, linkhdr, linkhdrsize, lladdr_off);
411 
412 	if (attrs.ndm_flags & NTF_STICKY)
413 		lle->la_expire = 0;
414 	else
415 		lle->la_expire = attrs.ndaf_next_ts - time_second + time_uptime;
416 
417 	/* llentry created, try to insert or update */
418 	IF_AFDATA_WLOCK(attrs.nda_ifp);
419 	LLE_WLOCK(lle);
420 	struct llentry *lle_tmp = lla_lookup(llt, LLE_EXCLUSIVE, attrs.nda_dst);
421 	if (lle_tmp != NULL) {
422 		error = EEXIST;
423 		if (hdr->nlmsg_flags & NLM_F_EXCL) {
424 			LLE_WUNLOCK(lle_tmp);
425 			lle_tmp = NULL;
426 		} else if (hdr->nlmsg_flags & NLM_F_REPLACE) {
427 			if ((lle_tmp->la_flags & LLE_IFADDR) == 0) {
428 				lltable_unlink_entry(llt, lle_tmp);
429 				lltable_link_entry(llt, lle);
430 				error = 0;
431 			} else
432 				error = EPERM;
433 		}
434 	} else {
435 		if (hdr->nlmsg_flags & NLM_F_CREATE)
436 			lltable_link_entry(llt, lle);
437 		else
438 			error = ENOENT;
439 	}
440 	IF_AFDATA_WUNLOCK(attrs.nda_ifp);
441 
442 	if (error != 0) {
443 		if (lle != NULL)
444 			llentry_free(lle);
445 		return (error);
446 	}
447 
448 	if (lle_tmp != NULL)
449 		llentry_free(lle_tmp);
450 
451 	/* XXX: We're inside epoch */
452 	EVENTHANDLER_INVOKE(lle_event, lle, LLENTRY_RESOLVED);
453 	LLE_WUNLOCK(lle);
454 	llt->llt_post_resolved(llt, lle);
455 
456 	return (0);
457 }
458 
459 static int
460 rtnl_handle_delneigh(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_pstate *npt)
461 {
462 	int error;
463 
464 	struct nl_parsed_neigh attrs = {};
465 	error = nl_parse_nlmsg(hdr, &ndmsg_parser, npt, &attrs);
466 	if (error != 0)
467 		return (error);
468 
469 	if (attrs.nda_dst == NULL) {
470 		NLMSG_REPORT_ERR_MSG(npt, "NDA_DST not set");
471 		return (EINVAL);
472 	}
473 
474 	if (attrs.nda_ifp == NULL) {
475 		NLMSG_REPORT_ERR_MSG(npt, "no ifindex provided");
476 		return (EINVAL);
477 	}
478 
479 	struct lltable *llt = lltable_get(attrs.nda_ifp, attrs.ndm_family);
480 	if (llt == NULL)
481 		return (EAFNOSUPPORT);
482 
483 	return (lltable_delete_addr(llt, 0, attrs.nda_dst));
484 }
485 
486 static int
487 rtnl_handle_getneigh(struct nlmsghdr *hdr, struct nlpcb *nlp, struct nl_pstate *npt)
488 {
489 	int error;
490 
491 	struct nl_parsed_neigh attrs = {};
492 	error = nl_parse_nlmsg(hdr, &ndmsg_parser, npt, &attrs);
493 	if (error != 0)
494 		return (error);
495 
496 	if (attrs.nda_dst != NULL && attrs.nda_ifp == NULL) {
497 		NLMSG_REPORT_ERR_MSG(npt, "has NDA_DST but no ifindex provided");
498 		return (EINVAL);
499 	}
500 
501 	struct netlink_walkargs wa = {
502 		.so = nlp,
503 		.nw = npt->nw,
504 		.hdr.nlmsg_pid = hdr->nlmsg_pid,
505 		.hdr.nlmsg_seq = hdr->nlmsg_seq,
506 		.hdr.nlmsg_flags = hdr->nlmsg_flags,
507 		.hdr.nlmsg_type = NL_RTM_NEWNEIGH,
508 	};
509 
510 	if (attrs.nda_dst == NULL)
511 		error = dump_llts(&wa, attrs.nda_ifp, attrs.ndm_family);
512 	else
513 		error = get_lle(&wa, attrs.nda_ifp, attrs.ndm_family, attrs.nda_dst);
514 
515 	return (error);
516 }
517 
518 static const struct rtnl_cmd_handler cmd_handlers[] = {
519 	{
520 		.cmd = NL_RTM_NEWNEIGH,
521 		.name = "RTM_NEWNEIGH",
522 		.cb = &rtnl_handle_newneigh,
523 		.priv = PRIV_NET_ROUTE,
524 	},
525 	{
526 		.cmd = NL_RTM_DELNEIGH,
527 		.name = "RTM_DELNEIGH",
528 		.cb = &rtnl_handle_delneigh,
529 		.priv = PRIV_NET_ROUTE,
530 	},
531 	{
532 		.cmd = NL_RTM_GETNEIGH,
533 		.name = "RTM_GETNEIGH",
534 		.cb = &rtnl_handle_getneigh,
535 	}
536 };
537 
538 static void
539 rtnl_lle_event(void *arg __unused, struct llentry *lle, int evt)
540 {
541 	struct ifnet *ifp;
542 	int family;
543 
544 	LLE_WLOCK_ASSERT(lle);
545 
546 	ifp = lltable_get_ifp(lle->lle_tbl);
547 	family = lltable_get_af(lle->lle_tbl);
548 
549 	if (family != AF_INET && family != AF_INET6)
550 		return;
551 
552 	int nlmsgs_type = evt == LLENTRY_RESOLVED ? NL_RTM_NEWNEIGH : NL_RTM_DELNEIGH;
553 
554 	struct nl_writer nw = {};
555 	if (!nlmsg_get_group_writer(&nw, NLMSG_SMALL, NETLINK_ROUTE, RTNLGRP_NEIGH)) {
556 		NL_LOG(LOG_DEBUG, "error allocating group writer");
557 		return;
558 	}
559 
560 	struct netlink_walkargs wa = {
561 		.hdr.nlmsg_type = nlmsgs_type,
562 		.nw = &nw,
563 		.ifp = ifp,
564 		.family = family,
565 	};
566 
567 	dump_lle_locked(lle, &wa);
568 	nlmsg_flush(&nw);
569 }
570 
571 static const struct nlhdr_parser *all_parsers[] = { &ndmsg_parser, &neigh_fbsd_parser };
572 
573 void
574 rtnl_neighs_init(void)
575 {
576 	NL_VERIFY_PARSERS(all_parsers);
577 	rtnl_register_messages(cmd_handlers, NL_ARRAY_LEN(cmd_handlers));
578 	lle_event_p = EVENTHANDLER_REGISTER(lle_event, rtnl_lle_event, NULL,
579 	    EVENTHANDLER_PRI_ANY);
580 }
581 
582 void
583 rtnl_neighs_destroy(void)
584 {
585 	EVENTHANDLER_DEREGISTER(lle_event, lle_event_p);
586 }
587