1 /* BGP network related fucntions
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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "sockunion.h"
38 #include "lib_errors.h"
41 #include "bgpd/bgpd.h"
42 #include "bgpd/bgp_open.h"
43 #include "bgpd/bgp_fsm.h"
44 #include "bgpd/bgp_attr.h"
45 #include "bgpd/bgp_debug.h"
46 #include "bgpd/bgp_errors.h"
47 #include "bgpd/bgp_network.h"
48 #include "bgpd/bgp_zebra.h"
50 extern struct zebra_privs_t bgpd_privs
;
52 static char *bgp_get_bound_name(struct peer
*peer
);
54 /* BGP listening socket. */
58 struct thread
*thread
;
63 * Set MD5 key for the socket, for the given IPv4 peer address.
64 * If the password is NULL or zero-length, the option will be disabled.
66 static int bgp_md5_set_socket(int socket
, union sockunion
*su
,
67 uint16_t prefixlen
, const char *password
)
71 #if HAVE_DECL_TCP_MD5SIG
73 #endif /* HAVE_TCP_MD5SIG */
77 #if HAVE_DECL_TCP_MD5SIG
78 /* Ensure there is no extraneous port information. */
79 memcpy(&su2
, su
, sizeof(union sockunion
));
80 if (su2
.sa
.sa_family
== AF_INET
)
83 su2
.sin6
.sin6_port
= 0;
85 /* For addresses, use the non-extended signature functionality */
86 if ((su2
.sa
.sa_family
== AF_INET
&& prefixlen
== IPV4_MAX_PREFIXLEN
)
87 || (su2
.sa
.sa_family
== AF_INET6
88 && prefixlen
== IPV6_MAX_PREFIXLEN
))
89 ret
= sockopt_tcp_signature(socket
, &su2
, password
);
91 ret
= sockopt_tcp_signature_ext(socket
, &su2
, prefixlen
,
94 #endif /* HAVE_TCP_MD5SIG */
97 char sabuf
[SU_ADDRSTRLEN
];
98 sockunion2str(su
, sabuf
, sizeof(sabuf
));
104 "Unable to set TCP MD5 option on socket for peer %s (sock=%d): This platform does not support MD5 auth for prefixes",
110 "Unable to set TCP MD5 option on socket for peer %s (sock=%d): %s",
111 sabuf
, socket
, safe_strerror(en
));
118 /* Helper for bgp_connect */
119 static int bgp_md5_set_connect(int socket
, union sockunion
*su
,
120 uint16_t prefixlen
, const char *password
)
124 #if HAVE_DECL_TCP_MD5SIG
125 frr_with_privs(&bgpd_privs
) {
126 ret
= bgp_md5_set_socket(socket
, su
, prefixlen
, password
);
128 #endif /* HAVE_TCP_MD5SIG */
133 static int bgp_md5_set_password(struct peer
*peer
, const char *password
)
135 struct listnode
*node
;
137 struct bgp_listener
*listener
;
140 * Set or unset the password on the listen socket(s). Outbound
141 * connections are taken care of in bgp_connect() below.
143 frr_with_privs(&bgpd_privs
) {
144 for (ALL_LIST_ELEMENTS_RO(bm
->listen_sockets
, node
, listener
))
145 if (listener
->su
.sa
.sa_family
146 == peer
->su
.sa
.sa_family
) {
148 peer
->su
.sa
.sa_family
== AF_INET
150 : IPV6_MAX_PREFIXLEN
;
152 ret
= bgp_md5_set_socket(listener
->fd
,
153 &peer
->su
, prefixlen
,
161 int bgp_md5_set_prefix(struct prefix
*p
, const char *password
)
165 struct listnode
*node
;
166 struct bgp_listener
*listener
;
168 /* Set or unset the password on the listen socket(s). */
169 frr_with_privs(&bgpd_privs
) {
170 for (ALL_LIST_ELEMENTS_RO(bm
->listen_sockets
, node
, listener
))
171 if (listener
->su
.sa
.sa_family
== p
->family
) {
172 prefix2sockunion(p
, &su
);
173 ret
= bgp_md5_set_socket(listener
->fd
, &su
,
183 int bgp_md5_unset_prefix(struct prefix
*p
)
185 return bgp_md5_set_prefix(p
, NULL
);
188 int bgp_md5_set(struct peer
*peer
)
190 /* Set the password from listen socket. */
191 return bgp_md5_set_password(peer
, peer
->password
);
194 int bgp_md5_unset(struct peer
*peer
)
196 /* Unset the password from listen socket. */
197 return bgp_md5_set_password(peer
, NULL
);
200 int bgp_set_socket_ttl(struct peer
*peer
, int bgp_sock
)
202 char buf
[INET_ADDRSTRLEN
];
205 /* In case of peer is EBGP, we should set TTL for this connection. */
206 if (!peer
->gtsm_hops
&& (peer_sort(peer
) == BGP_PEER_EBGP
)) {
207 ret
= sockopt_ttl(peer
->su
.sa
.sa_family
, bgp_sock
, peer
->ttl
);
211 "%s: Can't set TxTTL on peer (rtrid %s) socket, err = %d",
213 inet_ntop(AF_INET
, &peer
->remote_id
, buf
,
218 } else if (peer
->gtsm_hops
) {
219 /* On Linux, setting minttl without setting ttl seems to mess
221 outgoing ttl. Therefore setting both.
223 ret
= sockopt_ttl(peer
->su
.sa
.sa_family
, bgp_sock
, MAXTTL
);
227 "%s: Can't set TxTTL on peer (rtrid %s) socket, err = %d",
229 inet_ntop(AF_INET
, &peer
->remote_id
, buf
,
234 ret
= sockopt_minttl(peer
->su
.sa
.sa_family
, bgp_sock
,
235 MAXTTL
+ 1 - peer
->gtsm_hops
);
239 "%s: Can't set MinTTL on peer (rtrid %s) socket, err = %d",
241 inet_ntop(AF_INET
, &peer
->remote_id
, buf
,
252 * Obtain the BGP instance that the incoming connection should be processed
253 * against. This is important because more than one VRF could be using the
254 * same IP address space. The instance is got by obtaining the device to
255 * which the incoming connection is bound to. This could either be a VRF
256 * or it could be an interface, which in turn determines the VRF.
258 static int bgp_get_instance_for_inc_conn(int sock
, struct bgp
**bgp_inst
)
260 #ifndef SO_BINDTODEVICE
261 /* only Linux has SO_BINDTODEVICE, but we're in Linux-specific code here
262 * anyway since the assumption is that the interface name returned by
263 * getsockopt() is useful in identifying the VRF, particularly with
265 * VRF l3master device. The whole mechanism is specific to Linux, so...
266 * when other platforms add VRF support, this will need handling here as
267 * well. (or, some restructuring) */
268 *bgp_inst
= bgp_get_default();
272 char name
[VRF_NAMSIZ
+ 1];
273 socklen_t name_len
= VRF_NAMSIZ
;
276 struct listnode
*node
, *nnode
;
280 rc
= getsockopt(sock
, SOL_SOCKET
, SO_BINDTODEVICE
, name
, &name_len
);
282 #if defined(HAVE_CUMULUS)
283 flog_err(EC_LIB_SOCKET
,
284 "[Error] BGP SO_BINDTODEVICE get failed (%s), sock %d",
285 safe_strerror(errno
), sock
);
291 *bgp_inst
= bgp_get_default();
292 return 0; /* default instance. */
295 /* First try match to instance; if that fails, check for interfaces. */
296 bgp
= bgp_lookup_by_name(name
);
298 if (!bgp
->vrf_id
) // unexpected
304 /* TODO - This will be optimized once interfaces move into the NS */
305 for (ALL_LIST_ELEMENTS(bm
->bgp
, node
, nnode
, bgp
)) {
306 struct interface
*ifp
;
308 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_VIEW
)
311 ifp
= if_lookup_by_name(name
, bgp
->vrf_id
);
318 /* We didn't match to either an instance or an interface. */
323 static void bgp_socket_set_buffer_size(const int fd
)
325 if (getsockopt_so_sendbuf(fd
) < (int)bm
->socket_buffer
)
326 setsockopt_so_sendbuf(fd
, bm
->socket_buffer
);
327 if (getsockopt_so_recvbuf(fd
) < (int)bm
->socket_buffer
)
328 setsockopt_so_recvbuf(fd
, bm
->socket_buffer
);
331 /* Accept bgp connection. */
332 static int bgp_accept(struct thread
*thread
)
337 struct bgp_listener
*listener
= THREAD_ARG(thread
);
340 char buf
[SU_ADDRSTRLEN
];
341 struct bgp
*bgp
= NULL
;
345 /* Register accept thread. */
346 accept_sock
= THREAD_FD(thread
);
347 if (accept_sock
< 0) {
348 flog_err_sys(EC_LIB_SOCKET
, "accept_sock is nevative value %d",
352 listener
->thread
= NULL
;
354 thread_add_read(bm
->master
, bgp_accept
, listener
, accept_sock
,
357 /* Accept client connection. */
358 bgp_sock
= sockunion_accept(accept_sock
, &su
);
360 flog_err_sys(EC_LIB_SOCKET
,
361 "[Error] BGP socket accept failed (%s)",
362 safe_strerror(errno
));
365 set_nonblocking(bgp_sock
);
367 /* Obtain BGP instance this connection is meant for.
368 * - if it is a VRF netns sock, then BGP is in listener structure
369 * - otherwise, the bgp instance need to be demultiplexed
373 else if (bgp_get_instance_for_inc_conn(bgp_sock
, &bgp
)) {
374 if (bgp_debug_neighbor_events(NULL
))
376 "[Event] Could not get instance for incoming conn from %s",
377 inet_sutop(&su
, buf
));
382 bgp_socket_set_buffer_size(bgp_sock
);
384 /* Check remote IP address */
385 peer1
= peer_lookup(bgp
, &su
);
388 peer1
= peer_lookup_dynamic_neighbor(bgp
, &su
);
390 /* Dynamic neighbor has been created, let it proceed */
391 peer1
->fd
= bgp_sock
;
392 bgp_fsm_change_status(peer1
, Active
);
394 peer1
->t_start
); /* created in peer_create() */
396 if (peer_active(peer1
))
397 BGP_EVENT_ADD(peer1
, TCP_connection_open
);
404 if (bgp_debug_neighbor_events(NULL
)) {
406 "[Event] %s connection rejected - not configured"
407 " and not valid for dynamic",
408 inet_sutop(&su
, buf
));
414 if (CHECK_FLAG(peer1
->flags
, PEER_FLAG_SHUTDOWN
)) {
415 if (bgp_debug_neighbor_events(peer1
))
417 "[Event] connection from %s rejected due to admin shutdown",
418 inet_sutop(&su
, buf
));
424 * Do not accept incoming connections in Clearing state. This can result
425 * in incorect state transitions - e.g., the connection goes back to
426 * Established and then the Clearing_Completed event is generated. Also,
427 * block incoming connection in Deleted state.
429 if (peer1
->status
== Clearing
|| peer1
->status
== Deleted
) {
430 if (bgp_debug_neighbor_events(peer1
))
432 "[Event] Closing incoming conn for %s (%p) state %d",
433 peer1
->host
, peer1
, peer1
->status
);
438 /* Check that at least one AF is activated for the peer. */
439 if (!peer_active(peer1
)) {
440 if (bgp_debug_neighbor_events(peer1
))
442 "%s - incoming conn rejected - no AF activated for peer",
448 /* Do not try to reconnect if the peer reached maximum
449 * prefixes, restart timer is still running or the peer
452 if (BGP_PEER_START_SUPPRESSED(peer1
)) {
453 if (bgp_debug_neighbor_events(peer1
))
455 "[Event] Incoming BGP connection rejected from %s "
456 "due to maximum-prefix or shutdown",
462 if (bgp_debug_neighbor_events(peer1
))
463 zlog_debug("[Event] BGP connection from host %s fd %d",
464 inet_sutop(&su
, buf
), bgp_sock
);
466 if (peer1
->doppelganger
) {
467 /* We have an existing connection. Kill the existing one and run
470 if (bgp_debug_neighbor_events(peer1
))
472 "[Event] New active connection from peer %s, Killing"
473 " previous active connection",
475 peer_delete(peer1
->doppelganger
);
478 if (bgp_set_socket_ttl(peer1
, bgp_sock
) < 0)
479 if (bgp_debug_neighbor_events(peer1
))
481 "[Event] Unable to set min/max TTL on peer %s, Continuing",
484 peer
= peer_create(&su
, peer1
->conf_if
, peer1
->bgp
, peer1
->local_as
,
485 peer1
->as
, peer1
->as_type
, 0, 0, NULL
);
486 hash_release(peer
->bgp
->peerhash
, peer
);
487 hash_get(peer
->bgp
->peerhash
, peer
, hash_alloc_intern
);
489 peer_xfer_config(peer
, peer1
);
490 bgp_peer_gr_flags_update(peer
);
492 BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(peer
->bgp
,
495 if (bgp_peer_gr_mode_get(peer
) == PEER_DISABLE
) {
497 UNSET_FLAG(peer
->sflags
, PEER_STATUS_NSF_MODE
);
499 if (CHECK_FLAG(peer
->sflags
, PEER_STATUS_NSF_WAIT
)) {
504 UNSET_FLAG(peer
->flags
, PEER_FLAG_CONFIG_NODE
);
506 peer
->doppelganger
= peer1
;
507 peer1
->doppelganger
= peer
;
509 vrf_bind(peer
->bgp
->vrf_id
, bgp_sock
, bgp_get_bound_name(peer
));
510 bgp_fsm_change_status(peer
, Active
);
511 BGP_TIMER_OFF(peer
->t_start
); /* created in peer_create() */
513 SET_FLAG(peer
->sflags
, PEER_STATUS_ACCEPT_PEER
);
514 /* Make dummy peer until read Open packet. */
515 if (peer1
->status
== Established
516 && CHECK_FLAG(peer1
->sflags
, PEER_STATUS_NSF_MODE
)) {
517 /* If we have an existing established connection with graceful
519 * capability announced with one or more address families, then
521 * existing established connection and move state to connect.
523 peer1
->last_reset
= PEER_DOWN_NSF_CLOSE_SESSION
;
525 if (CHECK_FLAG(peer1
->flags
, PEER_FLAG_GRACEFUL_RESTART
)
526 || CHECK_FLAG(peer1
->flags
,
527 PEER_FLAG_GRACEFUL_RESTART_HELPER
))
528 SET_FLAG(peer1
->sflags
, PEER_STATUS_NSF_WAIT
);
530 bgp_event_update(peer1
, TCP_connection_closed
);
533 if (peer_active(peer
)) {
534 BGP_EVENT_ADD(peer
, TCP_connection_open
);
540 /* BGP socket bind. */
541 static char *bgp_get_bound_name(struct peer
*peer
)
548 if ((peer
->bgp
->vrf_id
== VRF_DEFAULT
) && !peer
->ifname
552 if (peer
->su
.sa
.sa_family
!= AF_INET
553 && peer
->su
.sa
.sa_family
!= AF_INET6
)
554 return NULL
; // unexpected
556 /* For IPv6 peering, interface (unnumbered or link-local with interface)
557 * takes precedence over VRF. For IPv4 peering, explicit interface or
558 * VRF are the situations to bind.
560 if (peer
->su
.sa
.sa_family
== AF_INET6
)
561 name
= (peer
->conf_if
? peer
->conf_if
562 : (peer
->ifname
? peer
->ifname
565 name
= peer
->ifname
? peer
->ifname
: peer
->bgp
->name
;
570 static int bgp_update_address(struct interface
*ifp
, const union sockunion
*dst
,
571 union sockunion
*addr
)
573 struct prefix
*p
, *sel
, d
;
574 struct connected
*connected
;
575 struct listnode
*node
;
578 sockunion2hostprefix(dst
, &d
);
582 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, connected
)) {
583 p
= connected
->address
;
584 if (p
->family
!= d
.family
)
586 if (prefix_common_bits(p
, &d
) > common
) {
588 common
= prefix_common_bits(sel
, &d
);
595 prefix2sockunion(sel
, addr
);
599 /* Update source selection. */
600 static int bgp_update_source(struct peer
*peer
)
602 struct interface
*ifp
;
603 union sockunion addr
;
606 sockunion_init(&addr
);
608 /* Source is specified with interface name. */
609 if (peer
->update_if
) {
610 ifp
= if_lookup_by_name(peer
->update_if
, peer
->bgp
->vrf_id
);
614 if (bgp_update_address(ifp
, &peer
->su
, &addr
))
617 ret
= sockunion_bind(peer
->fd
, &addr
, 0, &addr
);
620 /* Source is specified with IP address. */
621 if (peer
->update_source
)
622 ret
= sockunion_bind(peer
->fd
, peer
->update_source
, 0,
623 peer
->update_source
);
628 /* BGP try to connect to the peer. */
629 int bgp_connect(struct peer
*peer
)
631 assert(!CHECK_FLAG(peer
->thread_flags
, PEER_THREAD_WRITES_ON
));
632 assert(!CHECK_FLAG(peer
->thread_flags
, PEER_THREAD_READS_ON
));
633 ifindex_t ifindex
= 0;
635 if (peer
->conf_if
&& BGP_PEER_SU_UNSPEC(peer
)) {
636 zlog_debug("Peer address not learnt: Returning from connect");
639 frr_with_privs(&bgpd_privs
) {
640 /* Make socket for the peer. */
641 peer
->fd
= vrf_sockunion_socket(&peer
->su
, peer
->bgp
->vrf_id
,
642 bgp_get_bound_name(peer
));
647 set_nonblocking(peer
->fd
);
649 bgp_socket_set_buffer_size(peer
->fd
);
651 if (bgp_set_socket_ttl(peer
, peer
->fd
) < 0)
654 sockopt_reuseaddr(peer
->fd
);
655 sockopt_reuseport(peer
->fd
);
657 #ifdef IPTOS_PREC_INTERNETCONTROL
658 frr_with_privs(&bgpd_privs
) {
659 if (sockunion_family(&peer
->su
) == AF_INET
)
660 setsockopt_ipv4_tos(peer
->fd
,
661 IPTOS_PREC_INTERNETCONTROL
);
662 else if (sockunion_family(&peer
->su
) == AF_INET6
)
663 setsockopt_ipv6_tclass(peer
->fd
,
664 IPTOS_PREC_INTERNETCONTROL
);
668 if (peer
->password
) {
669 uint16_t prefixlen
= peer
->su
.sa
.sa_family
== AF_INET
671 : IPV6_MAX_PREFIXLEN
;
673 bgp_md5_set_connect(peer
->fd
, &peer
->su
, prefixlen
,
677 /* Update source bind. */
678 if (bgp_update_source(peer
) < 0) {
679 return connect_error
;
682 if (peer
->conf_if
|| peer
->ifname
)
683 ifindex
= ifname2ifindex(peer
->conf_if
? peer
->conf_if
687 if (bgp_debug_neighbor_events(peer
))
688 zlog_debug("%s [Event] Connect start to %s fd %d", peer
->host
,
689 peer
->host
, peer
->fd
);
691 /* Connect to the remote peer. */
692 return sockunion_connect(peer
->fd
, &peer
->su
, htons(peer
->port
),
696 /* After TCP connection is established. Get local address and port. */
697 int bgp_getsockname(struct peer
*peer
)
699 if (peer
->su_local
) {
700 sockunion_free(peer
->su_local
);
701 peer
->su_local
= NULL
;
704 if (peer
->su_remote
) {
705 sockunion_free(peer
->su_remote
);
706 peer
->su_remote
= NULL
;
709 peer
->su_local
= sockunion_getsockname(peer
->fd
);
712 peer
->su_remote
= sockunion_getpeername(peer
->fd
);
713 if (!peer
->su_remote
)
716 if (!bgp_zebra_nexthop_set(peer
->su_local
, peer
->su_remote
,
717 &peer
->nexthop
, peer
)) {
718 flog_err(EC_BGP_NH_UPD
,
719 "%s: nexthop_set failed, resetting connection - intf %p",
720 peer
->host
, peer
->nexthop
.ifp
);
727 static int bgp_listener(int sock
, struct sockaddr
*sa
, socklen_t salen
,
730 struct bgp_listener
*listener
;
733 sockopt_reuseaddr(sock
);
734 sockopt_reuseport(sock
);
736 frr_with_privs(&bgpd_privs
) {
738 #ifdef IPTOS_PREC_INTERNETCONTROL
739 if (sa
->sa_family
== AF_INET
)
740 setsockopt_ipv4_tos(sock
, IPTOS_PREC_INTERNETCONTROL
);
741 else if (sa
->sa_family
== AF_INET6
)
742 setsockopt_ipv6_tclass(sock
,
743 IPTOS_PREC_INTERNETCONTROL
);
746 sockopt_v6only(sa
->sa_family
, sock
);
748 ret
= bind(sock
, sa
, salen
);
753 flog_err_sys(EC_LIB_SOCKET
, "bind: %s", safe_strerror(en
));
757 ret
= listen(sock
, SOMAXCONN
);
759 flog_err_sys(EC_LIB_SOCKET
, "listen: %s", safe_strerror(errno
));
763 listener
= XCALLOC(MTYPE_BGP_LISTENER
, sizeof(*listener
));
766 /* this socket needs a change of ns. record bgp back pointer */
767 if (bgp
->vrf_id
!= VRF_DEFAULT
&& vrf_is_backend_netns())
770 memcpy(&listener
->su
, sa
, salen
);
771 listener
->thread
= NULL
;
772 thread_add_read(bm
->master
, bgp_accept
, listener
, sock
,
774 listnode_add(bm
->listen_sockets
, listener
);
779 /* IPv6 supported version of BGP server socket setup. */
780 int bgp_socket(struct bgp
*bgp
, unsigned short port
, const char *address
)
782 struct addrinfo
*ainfo
;
783 struct addrinfo
*ainfo_save
;
784 static const struct addrinfo req
= {
785 .ai_family
= AF_UNSPEC
,
786 .ai_flags
= AI_PASSIVE
,
787 .ai_socktype
= SOCK_STREAM
,
790 char port_str
[BUFSIZ
];
792 snprintf(port_str
, sizeof(port_str
), "%d", port
);
793 port_str
[sizeof(port_str
) - 1] = '\0';
795 frr_with_privs(&bgpd_privs
) {
796 ret
= vrf_getaddrinfo(address
, port_str
, &req
, &ainfo_save
,
800 flog_err_sys(EC_LIB_SOCKET
, "getaddrinfo: %s",
804 if (bgp_option_check(BGP_OPT_NO_ZEBRA
) &&
805 bgp
->vrf_id
!= VRF_DEFAULT
) {
806 freeaddrinfo(ainfo_save
);
810 for (ainfo
= ainfo_save
; ainfo
; ainfo
= ainfo
->ai_next
) {
813 if (ainfo
->ai_family
!= AF_INET
&& ainfo
->ai_family
!= AF_INET6
)
816 frr_with_privs(&bgpd_privs
) {
817 sock
= vrf_socket(ainfo
->ai_family
,
819 ainfo
->ai_protocol
, bgp
->vrf_id
,
821 == BGP_INSTANCE_TYPE_VRF
822 ? bgp
->name
: NULL
));
825 flog_err_sys(EC_LIB_SOCKET
, "socket: %s",
826 safe_strerror(errno
));
830 /* if we intend to implement ttl-security, this socket needs
832 sockopt_ttl(ainfo
->ai_family
, sock
, MAXTTL
);
834 ret
= bgp_listener(sock
, ainfo
->ai_addr
, ainfo
->ai_addrlen
,
841 freeaddrinfo(ainfo_save
);
842 if (count
== 0 && bgp
->inst_type
!= BGP_INSTANCE_TYPE_VRF
) {
845 "%s: no usable addresses please check other programs usage of specified port %d",
847 flog_err_sys(EC_LIB_SOCKET
, "%s: Program cannot continue",
855 /* this function closes vrf socket
856 * this should be called only for vrf socket with netns backend
858 void bgp_close_vrf_socket(struct bgp
*bgp
)
860 struct listnode
*node
, *next
;
861 struct bgp_listener
*listener
;
866 if (bm
->listen_sockets
== NULL
)
869 for (ALL_LIST_ELEMENTS(bm
->listen_sockets
, node
, next
, listener
)) {
870 if (listener
->bgp
== bgp
) {
871 thread_cancel(listener
->thread
);
873 listnode_delete(bm
->listen_sockets
, listener
);
874 XFREE(MTYPE_BGP_LISTENER
, listener
);
879 /* this function closes main socket
883 struct listnode
*node
, *next
;
884 struct bgp_listener
*listener
;
886 if (bm
->listen_sockets
== NULL
)
889 for (ALL_LIST_ELEMENTS(bm
->listen_sockets
, node
, next
, listener
)) {
892 thread_cancel(listener
->thread
);
894 listnode_delete(bm
->listen_sockets
, listener
);
895 XFREE(MTYPE_BGP_LISTENER
, listener
);