1 /* Kernel communication using netlink interface.
2 * Copyright (C) 1999 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
28 #include "connected.h"
31 #include "zebra_memory.h"
39 #include "zebra/zserv.h"
40 #include "zebra/zebra_ns.h"
41 #include "zebra/zebra_vrf.h"
42 #include "zebra/debug.h"
43 #include "zebra/kernel_netlink.h"
44 #include "zebra/rt_netlink.h"
45 #include "zebra/if_netlink.h"
47 #ifndef SO_RCVBUFFORCE
48 #define SO_RCVBUFFORCE (33)
51 /* Hack for GNU libc version 2. */
53 #define MSG_TRUNC 0x20
54 #endif /* MSG_TRUNC */
57 #define NLMSG_TAIL(nmsg) \
58 ((struct rtattr *) (((u_char *) (nmsg)) + NLMSG_ALIGN((nmsg)->nlmsg_len)))
62 #define RTA_TAIL(rta) \
63 ((struct rtattr *) (((u_char *) (rta)) + RTA_ALIGN((rta)->rta_len)))
66 #ifndef RTNL_FAMILY_IP6MR
67 #define RTNL_FAMILY_IP6MR 129
70 #ifndef RTPROT_MROUTED
71 #define RTPROT_MROUTED 17
74 static const struct message nlmsg_str
[] = {
75 {RTM_NEWROUTE
, "RTM_NEWROUTE"},
76 {RTM_DELROUTE
, "RTM_DELROUTE"},
77 {RTM_GETROUTE
, "RTM_GETROUTE"},
78 {RTM_NEWLINK
, "RTM_NEWLINK"},
79 {RTM_DELLINK
, "RTM_DELLINK"},
80 {RTM_GETLINK
, "RTM_GETLINK"},
81 {RTM_NEWADDR
, "RTM_NEWADDR"},
82 {RTM_DELADDR
, "RTM_DELADDR"},
83 {RTM_GETADDR
, "RTM_GETADDR"},
84 {RTM_NEWNEIGH
, "RTM_NEWNEIGH"},
85 {RTM_DELNEIGH
, "RTM_DELNEIGH"},
86 {RTM_GETNEIGH
, "RTM_GETNEIGH"},
90 static const struct message rtproto_str
[] = {
91 {RTPROT_REDIRECT
, "redirect"},
92 {RTPROT_KERNEL
, "kernel"},
93 {RTPROT_BOOT
, "boot"},
94 {RTPROT_STATIC
, "static"},
95 {RTPROT_GATED
, "GateD"},
96 {RTPROT_RA
, "router advertisement"},
98 {RTPROT_ZEBRA
, "Zebra"},
100 {RTPROT_BIRD
, "BIRD"},
101 #endif /* RTPROT_BIRD */
102 {RTPROT_MROUTED
, "mroute"},
104 {RTPROT_OSPF
, "OSPF"},
105 {RTPROT_ISIS
, "IS-IS"},
107 {RTPROT_RIPNG
, "RIPNG"},
111 static const struct message family_str
[] = {
114 {AF_BRIDGE
, "bridge"},
115 {RTNL_FAMILY_IPMR
, "ipv4MR"},
116 {RTNL_FAMILY_IP6MR
, "ipv6MR"},
120 static const struct message rttype_str
[] = {
121 {RTN_UNICAST
, "unicast"},
122 {RTN_MULTICAST
, "multicast"},
126 extern struct thread_master
*master
;
127 extern u_int32_t nl_rcvbufsize
;
129 extern struct zebra_privs_t zserv_privs
;
132 netlink_talk_filter (struct sockaddr_nl
*snl
, struct nlmsghdr
*h
,
133 ns_id_t ns_id
, int startup
)
135 zlog_warn ("netlink_talk: ignoring message type 0x%04x NS %u", h
->nlmsg_type
,
141 netlink_recvbuf (struct nlsock
*nl
, uint32_t newsize
)
144 socklen_t newlen
= sizeof(newsize
);
145 socklen_t oldlen
= sizeof(oldsize
);
148 ret
= getsockopt(nl
->sock
, SOL_SOCKET
, SO_RCVBUF
, &oldsize
, &oldlen
);
151 zlog_err("Can't get %s receive buffer size: %s", nl
->name
,
152 safe_strerror(errno
));
156 /* Try force option (linux >= 2.6.14) and fall back to normal set */
157 if ( zserv_privs
.change (ZPRIVS_RAISE
) )
158 zlog_err ("routing_socket: Can't raise privileges");
159 ret
= setsockopt(nl
->sock
, SOL_SOCKET
, SO_RCVBUFFORCE
, &nl_rcvbufsize
,
160 sizeof(nl_rcvbufsize
));
161 if ( zserv_privs
.change (ZPRIVS_LOWER
) )
162 zlog_err ("routing_socket: Can't lower privileges");
164 ret
= setsockopt(nl
->sock
, SOL_SOCKET
, SO_RCVBUF
, &nl_rcvbufsize
,
165 sizeof(nl_rcvbufsize
));
168 zlog_err("Can't set %s receive buffer size: %s", nl
->name
,
169 safe_strerror(errno
));
173 ret
= getsockopt(nl
->sock
, SOL_SOCKET
, SO_RCVBUF
, &newsize
, &newlen
);
176 zlog_err("Can't get %s receive buffer size: %s", nl
->name
,
177 safe_strerror(errno
));
181 zlog_info("Setting netlink socket receive buffer size: %u -> %u", oldsize
,
186 /* Make socket for Linux netlink interface. */
188 netlink_socket (struct nlsock
*nl
, unsigned long groups
, ns_id_t ns_id
)
191 struct sockaddr_nl snl
;
196 if (zserv_privs
.change (ZPRIVS_RAISE
))
198 zlog_err("Can't raise privileges");
202 sock
= socket (AF_NETLINK
, SOCK_RAW
, NETLINK_ROUTE
);
205 zlog_err("Can't open %s socket: %s", nl
->name
, safe_strerror(errno
));
209 memset (&snl
, 0, sizeof snl
);
210 snl
.nl_family
= AF_NETLINK
;
211 snl
.nl_groups
= groups
;
213 /* Bind the socket to the netlink structure for anything. */
214 ret
= bind (sock
, (struct sockaddr
*) &snl
, sizeof snl
);
216 if (zserv_privs
.change (ZPRIVS_LOWER
))
217 zlog_err("Can't lower privileges");
221 zlog_err("Can't bind %s socket to group 0x%x: %s", nl
->name
,
222 snl
.nl_groups
, safe_strerror(save_errno
));
227 /* multiple netlink sockets will have different nl_pid */
228 namelen
= sizeof snl
;
229 ret
= getsockname (sock
, (struct sockaddr
*) &snl
, (socklen_t
*) &namelen
);
230 if (ret
< 0 || namelen
!= sizeof snl
)
232 zlog_err("Can't get %s socket name: %s", nl
->name
, safe_strerror(errno
));
243 netlink_information_fetch (struct sockaddr_nl
*snl
, struct nlmsghdr
*h
,
244 ns_id_t ns_id
, int startup
)
246 /* JF: Ignore messages that aren't from the kernel */
247 if ( snl
->nl_pid
!= 0 )
249 zlog_err("Ignoring message from pid %u", snl
->nl_pid
);
253 switch (h
->nlmsg_type
)
256 return netlink_route_change (snl
, h
, ns_id
, startup
);
259 return netlink_route_change (snl
, h
, ns_id
, startup
);
262 return netlink_link_change (snl
, h
, ns_id
, startup
);
265 return netlink_link_change (snl
, h
, ns_id
, startup
);
268 return netlink_interface_addr (snl
, h
, ns_id
, startup
);
271 return netlink_interface_addr (snl
, h
, ns_id
, startup
);
274 zlog_warn ("Unknown netlink nlmsg_type %d vrf %u\n", h
->nlmsg_type
,
282 kernel_read (struct thread
*thread
)
284 struct zebra_ns
*zns
= (struct zebra_ns
*)THREAD_ARG (thread
);
285 netlink_parse_info (netlink_information_fetch
, &zns
->netlink
, zns
, 5, 0);
286 zns
->t_netlink
= NULL
;
287 thread_add_read(zebrad
.master
, kernel_read
, zns
, zns
->netlink
.sock
,
293 /* Filter out messages from self that occur on listener socket,
294 * caused by our actions on the command socket
296 static void netlink_install_filter (int sock
, __u32 pid
)
298 struct sock_filter filter
[] = {
300 BPF_STMT(BPF_LD
|BPF_ABS
|BPF_H
, offsetof(struct nlmsghdr
, nlmsg_type
)),
301 /* 1: jeq 0x18 jt 3 jf 6 */
302 BPF_JUMP(BPF_JMP
|BPF_JEQ
|BPF_K
, htons(RTM_NEWROUTE
), 1, 0),
303 /* 2: jeq 0x19 jt 3 jf 6 */
304 BPF_JUMP(BPF_JMP
|BPF_JEQ
|BPF_K
, htons(RTM_DELROUTE
), 0, 3),
306 BPF_STMT(BPF_LD
|BPF_ABS
|BPF_W
, offsetof(struct nlmsghdr
, nlmsg_pid
)),
307 /* 4: jeq XX jt 5 jf 6 */
308 BPF_JUMP(BPF_JMP
|BPF_JEQ
|BPF_K
, htonl(pid
), 0, 1),
309 /* 5: ret 0 (skip) */
310 BPF_STMT(BPF_RET
|BPF_K
, 0),
311 /* 6: ret 0xffff (keep) */
312 BPF_STMT(BPF_RET
|BPF_K
, 0xffff),
315 struct sock_fprog prog
= {
316 .len
= array_size(filter
),
320 if (setsockopt(sock
, SOL_SOCKET
, SO_ATTACH_FILTER
, &prog
, sizeof(prog
)) < 0)
321 zlog_warn ("Can't install socket filter: %s\n", safe_strerror(errno
));
325 netlink_parse_rtattr (struct rtattr
**tb
, int max
, struct rtattr
*rta
,
328 while (RTA_OK (rta
, len
))
330 if (rta
->rta_type
<= max
)
331 tb
[rta
->rta_type
] = rta
;
332 rta
= RTA_NEXT (rta
, len
);
337 addattr_l (struct nlmsghdr
*n
, unsigned int maxlen
, int type
,
338 void *data
, unsigned int alen
)
343 len
= RTA_LENGTH (alen
);
345 if (NLMSG_ALIGN (n
->nlmsg_len
) + RTA_ALIGN (len
) > maxlen
)
348 rta
= (struct rtattr
*) (((char *) n
) + NLMSG_ALIGN (n
->nlmsg_len
));
349 rta
->rta_type
= type
;
353 memcpy (RTA_DATA (rta
), data
, alen
);
357 n
->nlmsg_len
= NLMSG_ALIGN (n
->nlmsg_len
) + RTA_ALIGN (len
);
363 rta_addattr_l (struct rtattr
*rta
, unsigned int maxlen
, int type
,
364 void *data
, unsigned int alen
)
367 struct rtattr
*subrta
;
369 len
= RTA_LENGTH (alen
);
371 if (RTA_ALIGN (rta
->rta_len
) + RTA_ALIGN (len
) > maxlen
)
374 subrta
= (struct rtattr
*) (((char *) rta
) + RTA_ALIGN (rta
->rta_len
));
375 subrta
->rta_type
= type
;
376 subrta
->rta_len
= len
;
379 memcpy (RTA_DATA (subrta
), data
, alen
);
383 rta
->rta_len
= NLMSG_ALIGN (rta
->rta_len
) + RTA_ALIGN (len
);
389 addattr32 (struct nlmsghdr
*n
, unsigned int maxlen
, int type
, int data
)
391 return addattr_l(n
, maxlen
, type
, &data
, sizeof(u_int32_t
));
395 addattr_nest(struct nlmsghdr
*n
, int maxlen
, int type
)
397 struct rtattr
*nest
= NLMSG_TAIL(n
);
399 addattr_l(n
, maxlen
, type
, NULL
, 0);
404 addattr_nest_end(struct nlmsghdr
*n
, struct rtattr
*nest
)
406 nest
->rta_len
= (u_char
*)NLMSG_TAIL(n
) - (u_char
*)nest
;
411 rta_nest(struct rtattr
*rta
, int maxlen
, int type
)
413 struct rtattr
*nest
= RTA_TAIL(rta
);
415 rta_addattr_l(rta
, maxlen
, type
, NULL
, 0);
420 rta_nest_end(struct rtattr
*rta
, struct rtattr
*nest
)
422 nest
->rta_len
= (u_char
*)RTA_TAIL(rta
) - (u_char
*)nest
;
427 nl_msg_type_to_str (uint16_t msg_type
)
429 return lookup (nlmsg_str
, msg_type
);
433 nl_rtproto_to_str (u_char rtproto
)
435 return lookup (rtproto_str
, rtproto
);
439 nl_family_to_str (u_char family
)
441 return lookup (family_str
, family
);
445 nl_rttype_to_str (u_char rttype
)
447 return lookup (rttype_str
, rttype
);
453 * Receive message from netlink interface and pass those information
454 * to the given function.
456 * filter -> Function to call to read the results
457 * nl -> netlink socket information
458 * zns -> The zebra namespace data
459 * count -> How many we should read in, 0 means as much as possible
460 * startup -> Are we reading in under startup conditions? passed to
464 netlink_parse_info (int (*filter
) (struct sockaddr_nl
*, struct nlmsghdr
*,
466 struct nlsock
*nl
, struct zebra_ns
*zns
, int count
, int startup
)
475 char buf
[NL_PKT_BUF_SIZE
];
478 .iov_len
= sizeof buf
480 struct sockaddr_nl snl
;
481 struct msghdr msg
= {
482 .msg_name
= (void *) &snl
,
483 .msg_namelen
= sizeof snl
,
489 if (count
&& read_in
>= count
)
492 status
= recvmsg (nl
->sock
, &msg
, 0);
497 if (errno
== EWOULDBLOCK
|| errno
== EAGAIN
)
499 zlog_err("%s recvmsg overrun: %s", nl
->name
, safe_strerror(errno
));
501 * In this case we are screwed.
502 * There is no good way to
503 * recover zebra at this point.
511 zlog_err("%s EOF", nl
->name
);
515 if (msg
.msg_namelen
!= sizeof snl
)
517 zlog_err("%s sender address length error: length %d", nl
->name
,
522 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV
)
524 zlog_debug("%s: << netlink message dump [recv]", __func__
);
525 zlog_hexdump(buf
, status
);
529 for (h
= (struct nlmsghdr
*) buf
; NLMSG_OK (h
, (unsigned int) status
);
530 h
= NLMSG_NEXT (h
, status
))
532 /* Finish of reading. */
533 if (h
->nlmsg_type
== NLMSG_DONE
)
536 /* Error handling. */
537 if (h
->nlmsg_type
== NLMSG_ERROR
)
539 struct nlmsgerr
*err
= (struct nlmsgerr
*) NLMSG_DATA (h
);
540 int errnum
= err
->error
;
541 int msg_type
= err
->msg
.nlmsg_type
;
543 /* If the error field is zero, then this is an ACK */
546 if (IS_ZEBRA_DEBUG_KERNEL
)
548 zlog_debug ("%s: %s ACK: type=%s(%u), seq=%u, pid=%u",
549 __FUNCTION__
, nl
->name
,
550 nl_msg_type_to_str (err
->msg
.nlmsg_type
),
551 err
->msg
.nlmsg_type
, err
->msg
.nlmsg_seq
,
555 /* return if not a multipart message, otherwise continue */
556 if (!(h
->nlmsg_flags
& NLM_F_MULTI
))
561 if (h
->nlmsg_len
< NLMSG_LENGTH (sizeof (struct nlmsgerr
)))
563 zlog_err("%s error: message truncated", nl
->name
);
567 /* Deal with errors that occur because of races in link handling */
568 if (nl
== &zns
->netlink_cmd
569 && ((msg_type
== RTM_DELROUTE
&&
570 (-errnum
== ENODEV
|| -errnum
== ESRCH
))
571 || (msg_type
== RTM_NEWROUTE
&&
572 (-errnum
== ENETDOWN
|| -errnum
== EEXIST
))))
574 if (IS_ZEBRA_DEBUG_KERNEL
)
575 zlog_debug ("%s: error: %s type=%s(%u), seq=%u, pid=%u",
576 nl
->name
, safe_strerror (-errnum
),
577 nl_msg_type_to_str (msg_type
),
578 msg_type
, err
->msg
.nlmsg_seq
, err
->msg
.nlmsg_pid
);
582 /* We see RTM_DELNEIGH when shutting down an interface with an IPv4
583 * link-local. The kernel should have already deleted the neighbor
584 * so do not log these as an error.
586 if (msg_type
== RTM_DELNEIGH
||
587 (nl
== &zns
->netlink_cmd
&& msg_type
== RTM_NEWROUTE
&&
588 (-errnum
== ESRCH
|| -errnum
== ENETUNREACH
)))
590 /* This is known to happen in some situations, don't log
593 if (IS_ZEBRA_DEBUG_KERNEL
)
594 zlog_debug ("%s error: %s, type=%s(%u), seq=%u, pid=%u",
595 nl
->name
, safe_strerror (-errnum
),
596 nl_msg_type_to_str (msg_type
),
597 msg_type
, err
->msg
.nlmsg_seq
, err
->msg
.nlmsg_pid
);
600 zlog_err ("%s error: %s, type=%s(%u), seq=%u, pid=%u",
601 nl
->name
, safe_strerror (-errnum
),
602 nl_msg_type_to_str (msg_type
),
603 msg_type
, err
->msg
.nlmsg_seq
, err
->msg
.nlmsg_pid
);
608 /* OK we got netlink message. */
609 if (IS_ZEBRA_DEBUG_KERNEL
)
610 zlog_debug ("netlink_parse_info: %s type %s(%u), len=%d, seq=%u, pid=%u",
612 nl_msg_type_to_str (h
->nlmsg_type
), h
->nlmsg_type
,
613 h
->nlmsg_len
, h
->nlmsg_seq
, h
->nlmsg_pid
);
615 /* skip unsolicited messages originating from command socket
616 * linux sets the originators port-id for {NEW|DEL}ADDR messages,
617 * so this has to be checked here. */
618 if (nl
!= &zns
->netlink_cmd
619 && h
->nlmsg_pid
== zns
->netlink_cmd
.snl
.nl_pid
620 && (h
->nlmsg_type
!= RTM_NEWADDR
&& h
->nlmsg_type
!= RTM_DELADDR
))
622 if (IS_ZEBRA_DEBUG_KERNEL
)
623 zlog_debug ("netlink_parse_info: %s packet comes from %s",
624 zns
->netlink_cmd
.name
, nl
->name
);
628 error
= (*filter
) (&snl
, h
, zns
->ns_id
, startup
);
631 zlog_err("%s filter function error", nl
->name
);
636 /* After error care. */
637 if (msg
.msg_flags
& MSG_TRUNC
)
639 zlog_err("%s error: message truncated", nl
->name
);
644 zlog_err("%s error: data remnant size %d", nl
->name
, status
);
654 * sendmsg() to netlink socket then recvmsg().
655 * Calls netlink_parse_info to parse returned data
657 * filter -> The filter to read final results from kernel
658 * nlmsghdr -> The data to send to the kernel
659 * nl -> The netlink socket information
660 * zns -> The zebra namespace information
661 * startup -> Are we reading in under startup conditions
662 * This is passed through eventually to filter.
665 netlink_talk (int (*filter
) (struct sockaddr_nl
*, struct nlmsghdr
*,
666 ns_id_t
, int startup
),
667 struct nlmsghdr
*n
, struct nlsock
*nl
, struct zebra_ns
*zns
, int startup
)
670 struct sockaddr_nl snl
;
672 .iov_base
= (void *) n
,
673 .iov_len
= n
->nlmsg_len
675 struct msghdr msg
= {
676 .msg_name
= (void *) &snl
,
677 .msg_namelen
= sizeof snl
,
683 memset (&snl
, 0, sizeof snl
);
684 snl
.nl_family
= AF_NETLINK
;
686 n
->nlmsg_seq
= ++nl
->seq
;
688 /* Request an acknowledgement by setting NLM_F_ACK */
689 n
->nlmsg_flags
|= NLM_F_ACK
;
691 if (IS_ZEBRA_DEBUG_KERNEL
)
692 zlog_debug ("netlink_talk: %s type %s(%u), len=%d seq=%u flags 0x%x",
694 nl_msg_type_to_str (n
->nlmsg_type
), n
->nlmsg_type
,
695 n
->nlmsg_len
, n
->nlmsg_seq
, n
->nlmsg_flags
);
697 /* Send message to netlink interface. */
698 if (zserv_privs
.change (ZPRIVS_RAISE
))
699 zlog_err("Can't raise privileges");
700 status
= sendmsg (nl
->sock
, &msg
, 0);
702 if (zserv_privs
.change (ZPRIVS_LOWER
))
703 zlog_err("Can't lower privileges");
705 if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND
)
707 zlog_debug("%s: >> netlink message dump [sent]", __func__
);
708 zlog_hexdump(n
, n
->nlmsg_len
);
713 zlog_err("netlink_talk sendmsg() error: %s", safe_strerror(save_errno
));
719 * Get reply from netlink socket.
720 * The reply should either be an acknowlegement or an error.
722 return netlink_parse_info (filter
, nl
, zns
, 0, startup
);
725 /* Get type specified information from netlink. */
727 netlink_request (int family
, int type
, struct nlsock
*nl
)
730 struct sockaddr_nl snl
;
739 /* Check netlink socket. */
742 zlog_err("%s socket isn't active.", nl
->name
);
746 memset (&snl
, 0, sizeof snl
);
747 snl
.nl_family
= AF_NETLINK
;
749 memset (&req
, 0, sizeof req
);
750 req
.nlh
.nlmsg_len
= sizeof req
;
751 req
.nlh
.nlmsg_type
= type
;
752 req
.nlh
.nlmsg_flags
= NLM_F_ROOT
| NLM_F_MATCH
| NLM_F_REQUEST
;
753 req
.nlh
.nlmsg_pid
= nl
->snl
.nl_pid
;
754 req
.nlh
.nlmsg_seq
= ++nl
->seq
;
755 req
.g
.rtgen_family
= family
;
757 /* linux appears to check capabilities on every message
758 * have to raise caps for every message sent
760 if (zserv_privs
.change (ZPRIVS_RAISE
))
762 zlog_err("Can't raise privileges");
766 ret
= sendto (nl
->sock
, (void *) &req
, sizeof req
, 0,
767 (struct sockaddr
*) &snl
, sizeof snl
);
770 if (zserv_privs
.change (ZPRIVS_LOWER
))
771 zlog_err("Can't lower privileges");
775 zlog_err("%s sendto failed: %s", nl
->name
, safe_strerror(save_errno
));
782 /* Exported interface function. This function simply calls
783 netlink_socket (). */
785 kernel_init (struct zebra_ns
*zns
)
787 unsigned long groups
;
789 /* Initialize netlink sockets */
790 groups
= RTMGRP_LINK
| RTMGRP_IPV4_ROUTE
| RTMGRP_IPV4_IFADDR
|
791 RTMGRP_IPV6_ROUTE
| RTMGRP_IPV6_IFADDR
|
794 snprintf (zns
->netlink
.name
, sizeof (zns
->netlink
.name
),
795 "netlink-listen (NS %u)", zns
->ns_id
);
796 zns
->netlink
.sock
= -1;
797 netlink_socket (&zns
->netlink
, groups
, zns
->ns_id
);
799 snprintf (zns
->netlink_cmd
.name
, sizeof (zns
->netlink_cmd
.name
),
800 "netlink-cmd (NS %u)", zns
->ns_id
);
801 zns
->netlink_cmd
.sock
= -1;
802 netlink_socket (&zns
->netlink_cmd
, 0, zns
->ns_id
);
804 /* Register kernel socket. */
805 if (zns
->netlink
.sock
> 0)
807 /* Only want non-blocking on the netlink event socket */
808 if (fcntl (zns
->netlink
.sock
, F_SETFL
, O_NONBLOCK
) < 0)
809 zlog_err ("Can't set %s socket flags: %s", zns
->netlink
.name
,
810 safe_strerror (errno
));
812 /* Set receive buffer size if it's set from command line */
814 netlink_recvbuf (&zns
->netlink
, nl_rcvbufsize
);
816 netlink_install_filter (zns
->netlink
.sock
, zns
->netlink_cmd
.snl
.nl_pid
);
817 zns
->t_netlink
= NULL
;
818 thread_add_read(zebrad
.master
, kernel_read
, zns
, zns
->netlink
.sock
,
824 kernel_terminate (struct zebra_ns
*zns
)
826 THREAD_READ_OFF (zns
->t_netlink
);
828 if (zns
->netlink
.sock
>= 0)
830 close (zns
->netlink
.sock
);
831 zns
->netlink
.sock
= -1;
834 if (zns
->netlink_cmd
.sock
>= 0)
836 close (zns
->netlink_cmd
.sock
);
837 zns
->netlink_cmd
.sock
= -1;