blob: 4cb6f7d848d787d33ca40151202138b401d85f43 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP network related fucntions
2 Copyright (C) 1999 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "thread.h"
24#include "sockunion.h"
Paul Jakma0df7c912008-07-21 21:02:49 +000025#include "sockopt.h"
paul718e3742002-12-13 20:15:29 +000026#include "memory.h"
27#include "log.h"
28#include "if.h"
29#include "prefix.h"
30#include "command.h"
pauledd7c242003-06-04 13:59:38 +000031#include "privs.h"
Paul Jakma0df7c912008-07-21 21:02:49 +000032#include "linklist.h"
paul718e3742002-12-13 20:15:29 +000033
34#include "bgpd/bgpd.h"
35#include "bgpd/bgp_fsm.h"
36#include "bgpd/bgp_attr.h"
37#include "bgpd/bgp_debug.h"
38#include "bgpd/bgp_network.h"
pauledd7c242003-06-04 13:59:38 +000039
40extern struct zebra_privs_t bgpd_privs;
41
Stephen Hemmingerd023aec2009-07-21 16:27:21 -070042/* BGP listening socket. */
43struct bgp_listener
44{
45 int fd;
46 union sockunion su;
47 struct thread *thread;
48};
paul718e3742002-12-13 20:15:29 +000049
Paul Jakma0df7c912008-07-21 21:02:49 +000050/*
51 * Set MD5 key for the socket, for the given IPv4 peer address.
52 * If the password is NULL or zero-length, the option will be disabled.
53 */
54static int
55bgp_md5_set_socket (int socket, union sockunion *su, const char *password)
56{
57 int ret = -1;
58 int en = ENOSYS;
59
60 assert (socket >= 0);
61
62#if HAVE_DECL_TCP_MD5SIG
63 ret = sockopt_tcp_signature (socket, su, password);
64 en = errno;
65#endif /* HAVE_TCP_MD5SIG */
66
67 if (ret < 0)
68 zlog (NULL, LOG_WARNING, "can't set TCP_MD5SIG option on socket %d: %s",
69 socket, safe_strerror (en));
70
71 return ret;
72}
73
74/* Helper for bgp_connect */
75static int
76bgp_md5_set_connect (int socket, union sockunion *su, const char *password)
77{
78 int ret = -1;
79
80#if HAVE_DECL_TCP_MD5SIG
81 if ( bgpd_privs.change (ZPRIVS_RAISE) )
82 {
83 zlog_err ("%s: could not raise privs", __func__);
84 return ret;
85 }
86
87 ret = bgp_md5_set_socket (socket, su, password);
88
89 if (bgpd_privs.change (ZPRIVS_LOWER) )
90 zlog_err ("%s: could not lower privs", __func__);
91#endif /* HAVE_TCP_MD5SIG */
92
93 return ret;
94}
95
96int
97bgp_md5_set (struct peer *peer)
98{
99 struct listnode *node;
100 int fret = 0, ret;
101 int *socket;
102
103 if ( bgpd_privs.change (ZPRIVS_RAISE) )
104 {
105 zlog_err ("%s: could not raise privs", __func__);
106 return -1;
107 }
108
109 /* Just set the password on the listen socket(s). Outbound connections
110 * are taken care of in bgp_connect() below.
111 */
112 for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, socket))
113 {
Chris Caputo54a15182009-07-18 05:42:34 +0000114 ret = bgp_md5_set_socket ((int)(long)socket, &peer->su, peer->password);
Paul Jakma0df7c912008-07-21 21:02:49 +0000115 if (ret < 0)
116 fret = ret;
117 }
118 if (bgpd_privs.change (ZPRIVS_LOWER) )
119 zlog_err ("%s: could not lower privs", __func__);
120
121 return fret;
122}
123
paul718e3742002-12-13 20:15:29 +0000124/* Accept bgp connection. */
125static int
126bgp_accept (struct thread *thread)
127{
128 int bgp_sock;
129 int accept_sock;
130 union sockunion su;
Stephen Hemminger5bd58812009-08-06 21:05:47 -0700131 struct bgp_listener *listener = THREAD_ARG(thread);
paul718e3742002-12-13 20:15:29 +0000132 struct peer *peer;
pauleb821182004-05-01 08:44:08 +0000133 struct peer *peer1;
paul718e3742002-12-13 20:15:29 +0000134 char buf[SU_ADDRSTRLEN];
135
Stephen Hemminger5bd58812009-08-06 21:05:47 -0700136 /* Register accept thread. */
paul718e3742002-12-13 20:15:29 +0000137 accept_sock = THREAD_FD (thread);
paul718e3742002-12-13 20:15:29 +0000138 if (accept_sock < 0)
139 {
140 zlog_err ("accept_sock is nevative value %d", accept_sock);
141 return -1;
142 }
Stephen Hemminger5bd58812009-08-06 21:05:47 -0700143 listener->thread = thread_add_read (master, bgp_accept, listener, accept_sock);
paul718e3742002-12-13 20:15:29 +0000144
145 /* Accept client connection. */
146 bgp_sock = sockunion_accept (accept_sock, &su);
147 if (bgp_sock < 0)
148 {
ajs6099b3b2004-11-20 02:06:59 +0000149 zlog_err ("[Error] BGP socket accept failed (%s)", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +0000150 return -1;
151 }
152
153 if (BGP_DEBUG (events, EVENTS))
ajs478ba052004-12-08 20:41:23 +0000154 zlog_debug ("[Event] BGP connection from host %s", inet_sutop (&su, buf));
paul718e3742002-12-13 20:15:29 +0000155
156 /* Check remote IP address */
Stephen Hemminger5bd58812009-08-06 21:05:47 -0700157 peer1 = peer_lookup (NULL, &su);
pauleb821182004-05-01 08:44:08 +0000158 if (! peer1 || peer1->status == Idle)
paul718e3742002-12-13 20:15:29 +0000159 {
160 if (BGP_DEBUG (events, EVENTS))
161 {
pauleb821182004-05-01 08:44:08 +0000162 if (! peer1)
ajs478ba052004-12-08 20:41:23 +0000163 zlog_debug ("[Event] BGP connection IP address %s is not configured",
paul718e3742002-12-13 20:15:29 +0000164 inet_sutop (&su, buf));
165 else
ajs478ba052004-12-08 20:41:23 +0000166 zlog_debug ("[Event] BGP connection IP address %s is Idle state",
paul718e3742002-12-13 20:15:29 +0000167 inet_sutop (&su, buf));
168 }
169 close (bgp_sock);
170 return -1;
171 }
172
173 /* In case of peer is EBGP, we should set TTL for this connection. */
pauleb821182004-05-01 08:44:08 +0000174 if (peer_sort (peer1) == BGP_PEER_EBGP)
175 sockopt_ttl (peer1->su.sa.sa_family, bgp_sock, peer1->ttl);
paul718e3742002-12-13 20:15:29 +0000176
pauleb821182004-05-01 08:44:08 +0000177 /* Make dummy peer until read Open packet. */
178 if (BGP_DEBUG (events, EVENTS))
ajs478ba052004-12-08 20:41:23 +0000179 zlog_debug ("[Event] Make dummy peer structure until read Open packet");
pauleb821182004-05-01 08:44:08 +0000180
181 {
182 char buf[SU_ADDRSTRLEN + 1];
183
Stephen Hemminger5bd58812009-08-06 21:05:47 -0700184 peer = peer_create_accept (peer1->bgp);
pauleb821182004-05-01 08:44:08 +0000185 SET_FLAG (peer->sflags, PEER_STATUS_ACCEPT_PEER);
186 peer->su = su;
187 peer->fd = bgp_sock;
188 peer->status = Active;
189 peer->local_id = peer1->local_id;
Timo Teräse8eb0002009-02-17 12:14:23 +0200190 peer->v_holdtime = peer1->v_holdtime;
191 peer->v_keepalive = peer1->v_keepalive;
pauleb821182004-05-01 08:44:08 +0000192
193 /* Make peer's address string. */
194 sockunion2str (&su, buf, SU_ADDRSTRLEN);
paule83e2082005-05-19 02:12:25 +0000195 peer->host = XSTRDUP (MTYPE_BGP_PEER_HOST, buf);
pauleb821182004-05-01 08:44:08 +0000196 }
paul718e3742002-12-13 20:15:29 +0000197
198 BGP_EVENT_ADD (peer, TCP_connection_open);
199
200 return 0;
201}
202
203/* BGP socket bind. */
paul94f2b392005-06-28 12:44:16 +0000204static int
paul718e3742002-12-13 20:15:29 +0000205bgp_bind (struct peer *peer)
206{
207#ifdef SO_BINDTODEVICE
208 int ret;
209 struct ifreq ifreq;
210
211 if (! peer->ifname)
212 return 0;
213
214 strncpy ((char *)&ifreq.ifr_name, peer->ifname, sizeof (ifreq.ifr_name));
215
paul98f51632004-10-25 14:19:15 +0000216 if ( bgpd_privs.change (ZPRIVS_RAISE) )
217 zlog_err ("bgp_bind: could not raise privs");
218
pauleb821182004-05-01 08:44:08 +0000219 ret = setsockopt (peer->fd, SOL_SOCKET, SO_BINDTODEVICE,
paul718e3742002-12-13 20:15:29 +0000220 &ifreq, sizeof (ifreq));
paul98f51632004-10-25 14:19:15 +0000221
222 if (bgpd_privs.change (ZPRIVS_LOWER) )
223 zlog_err ("bgp_bind: could not lower privs");
224
paul718e3742002-12-13 20:15:29 +0000225 if (ret < 0)
226 {
227 zlog (peer->log, LOG_INFO, "bind to interface %s failed", peer->ifname);
228 return ret;
229 }
230#endif /* SO_BINDTODEVICE */
231 return 0;
232}
233
paul94f2b392005-06-28 12:44:16 +0000234static int
paul718e3742002-12-13 20:15:29 +0000235bgp_bind_address (int sock, struct in_addr *addr)
236{
237 int ret;
238 struct sockaddr_in local;
239
240 memset (&local, 0, sizeof (struct sockaddr_in));
241 local.sin_family = AF_INET;
Paul Jakma6f0e3f62007-05-10 02:38:51 +0000242#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
paul718e3742002-12-13 20:15:29 +0000243 local.sin_len = sizeof(struct sockaddr_in);
Paul Jakma6f0e3f62007-05-10 02:38:51 +0000244#endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
paul718e3742002-12-13 20:15:29 +0000245 memcpy (&local.sin_addr, addr, sizeof (struct in_addr));
246
pauledd7c242003-06-04 13:59:38 +0000247 if ( bgpd_privs.change (ZPRIVS_RAISE) )
248 zlog_err ("bgp_bind_address: could not raise privs");
249
paul718e3742002-12-13 20:15:29 +0000250 ret = bind (sock, (struct sockaddr *)&local, sizeof (struct sockaddr_in));
251 if (ret < 0)
252 ;
pauledd7c242003-06-04 13:59:38 +0000253
254 if (bgpd_privs.change (ZPRIVS_LOWER) )
255 zlog_err ("bgp_bind_address: could not lower privs");
256
paul718e3742002-12-13 20:15:29 +0000257 return 0;
258}
259
paul94f2b392005-06-28 12:44:16 +0000260static struct in_addr *
paul718e3742002-12-13 20:15:29 +0000261bgp_update_address (struct interface *ifp)
262{
263 struct prefix_ipv4 *p;
264 struct connected *connected;
hasso52dc7ee2004-09-23 19:18:23 +0000265 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000266
paul1eb8ef22005-04-07 07:30:20 +0000267 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected))
paul718e3742002-12-13 20:15:29 +0000268 {
paul718e3742002-12-13 20:15:29 +0000269 p = (struct prefix_ipv4 *) connected->address;
270
271 if (p->family == AF_INET)
272 return &p->prefix;
273 }
274 return NULL;
275}
276
277/* Update source selection. */
paul94f2b392005-06-28 12:44:16 +0000278static void
paul718e3742002-12-13 20:15:29 +0000279bgp_update_source (struct peer *peer)
280{
281 struct interface *ifp;
282 struct in_addr *addr;
283
284 /* Source is specified with interface name. */
285 if (peer->update_if)
286 {
287 ifp = if_lookup_by_name (peer->update_if);
288 if (! ifp)
289 return;
290
291 addr = bgp_update_address (ifp);
292 if (! addr)
293 return;
294
pauleb821182004-05-01 08:44:08 +0000295 bgp_bind_address (peer->fd, addr);
paul718e3742002-12-13 20:15:29 +0000296 }
297
298 /* Source is specified with IP address. */
299 if (peer->update_source)
pauleb821182004-05-01 08:44:08 +0000300 sockunion_bind (peer->fd, peer->update_source, 0, peer->update_source);
paul718e3742002-12-13 20:15:29 +0000301}
302
303/* BGP try to connect to the peer. */
304int
305bgp_connect (struct peer *peer)
306{
307 unsigned int ifindex = 0;
308
309 /* Make socket for the peer. */
pauleb821182004-05-01 08:44:08 +0000310 peer->fd = sockunion_socket (&peer->su);
311 if (peer->fd < 0)
paul718e3742002-12-13 20:15:29 +0000312 return -1;
313
314 /* If we can get socket for the peer, adjest TTL and make connection. */
315 if (peer_sort (peer) == BGP_PEER_EBGP)
pauleb821182004-05-01 08:44:08 +0000316 sockopt_ttl (peer->su.sa.sa_family, peer->fd, peer->ttl);
paul718e3742002-12-13 20:15:29 +0000317
pauleb821182004-05-01 08:44:08 +0000318 sockopt_reuseaddr (peer->fd);
319 sockopt_reuseport (peer->fd);
Paul Jakma0df7c912008-07-21 21:02:49 +0000320
Stephen Hemminger1423c802008-08-14 17:59:25 +0100321#ifdef IPTOS_PREC_INTERNETCONTROL
322 if (sockunion_family (&peer->su) == AF_INET)
323 setsockopt_ipv4_tos (peer->fd, IPTOS_PREC_INTERNETCONTROL);
324#endif
325
Paul Jakma0df7c912008-07-21 21:02:49 +0000326 if (peer->password)
327 bgp_md5_set_connect (peer->fd, &peer->su, peer->password);
paul718e3742002-12-13 20:15:29 +0000328
329 /* Bind socket. */
330 bgp_bind (peer);
331
332 /* Update source bind. */
333 bgp_update_source (peer);
334
335#ifdef HAVE_IPV6
336 if (peer->ifname)
337 ifindex = if_nametoindex (peer->ifname);
338#endif /* HAVE_IPV6 */
339
340 if (BGP_DEBUG (events, EVENTS))
ajs478ba052004-12-08 20:41:23 +0000341 plog_debug (peer->log, "%s [Event] Connect start to %s fd %d",
pauleb821182004-05-01 08:44:08 +0000342 peer->host, peer->host, peer->fd);
paul718e3742002-12-13 20:15:29 +0000343
344 /* Connect to the remote peer. */
pauleb821182004-05-01 08:44:08 +0000345 return sockunion_connect (peer->fd, &peer->su, htons (peer->port), ifindex);
paul718e3742002-12-13 20:15:29 +0000346}
347
348/* After TCP connection is established. Get local address and port. */
349void
350bgp_getsockname (struct peer *peer)
351{
352 if (peer->su_local)
353 {
paul22db9de2005-05-19 01:50:11 +0000354 sockunion_free (peer->su_local);
paul718e3742002-12-13 20:15:29 +0000355 peer->su_local = NULL;
356 }
357
358 if (peer->su_remote)
359 {
paul22db9de2005-05-19 01:50:11 +0000360 sockunion_free (peer->su_remote);
paul718e3742002-12-13 20:15:29 +0000361 peer->su_remote = NULL;
362 }
363
pauleb821182004-05-01 08:44:08 +0000364 peer->su_local = sockunion_getsockname (peer->fd);
365 peer->su_remote = sockunion_getpeername (peer->fd);
paul718e3742002-12-13 20:15:29 +0000366
367 bgp_nexthop_set (peer->su_local, peer->su_remote, &peer->nexthop, peer);
368}
369
Stephen Hemmingerd023aec2009-07-21 16:27:21 -0700370
371static int
372bgp_listener (int sock, struct sockaddr *sa, socklen_t salen)
373{
374 struct bgp_listener *listener;
375 int ret, en;
376
377 sockopt_reuseaddr (sock);
378 sockopt_reuseport (sock);
379
380#ifdef IPTOS_PREC_INTERNETCONTROL
381 if (sa->sa_family == AF_INET)
382 setsockopt_ipv4_tos (sock, IPTOS_PREC_INTERNETCONTROL);
383#endif
384
385#ifdef IPV6_V6ONLY
386 /* Want only IPV6 on ipv6 socket (not mapped addresses) */
387 if (sa->sa_family == AF_INET6) {
388 int on = 1;
389 setsockopt (sock, IPPROTO_IPV6, IPV6_V6ONLY,
390 (void *) &on, sizeof (on));
391 }
392#endif
393
394 if (bgpd_privs.change (ZPRIVS_RAISE) )
395 zlog_err ("bgp_socket: could not raise privs");
396
397 ret = bind (sock, sa, salen);
398 en = errno;
399 if (bgpd_privs.change (ZPRIVS_LOWER) )
400 zlog_err ("bgp_bind_address: could not lower privs");
401
402 if (ret < 0)
403 {
404 zlog_err ("bind: %s", safe_strerror (en));
405 return ret;
406 }
407
408 ret = listen (sock, 3);
409 if (ret < 0)
410 {
411 zlog_err ("listen: %s", safe_strerror (errno));
412 return ret;
413 }
414
415 listener = XMALLOC (MTYPE_BGP_LISTENER, sizeof(*listener));
416 listener->fd = sock;
417 memcpy(&listener->su, sa, salen);
418 listener->thread = thread_add_read (master, bgp_accept, listener, sock);
419 listnode_add (bm->listen_sockets, listener);
420
421 return 0;
422}
423
paul718e3742002-12-13 20:15:29 +0000424/* IPv6 supported version of BGP server socket setup. */
425#if defined (HAVE_IPV6) && ! defined (NRL)
426int
Stephen Hemmingerd023aec2009-07-21 16:27:21 -0700427bgp_socket (unsigned short port, const char *address)
paul718e3742002-12-13 20:15:29 +0000428{
paul718e3742002-12-13 20:15:29 +0000429 struct addrinfo *ainfo;
430 struct addrinfo *ainfo_save;
Stephen Hemmingerd023aec2009-07-21 16:27:21 -0700431 static const struct addrinfo req = {
432 .ai_family = AF_UNSPEC,
433 .ai_flags = AI_PASSIVE,
434 .ai_socktype = SOCK_STREAM,
435 };
436 int ret, count;
paul718e3742002-12-13 20:15:29 +0000437 char port_str[BUFSIZ];
438
Paul Jakma90b68762008-01-29 17:26:34 +0000439 snprintf (port_str, sizeof(port_str), "%d", port);
paul718e3742002-12-13 20:15:29 +0000440 port_str[sizeof (port_str) - 1] = '\0';
441
Stephen Hemmingerd023aec2009-07-21 16:27:21 -0700442 ret = getaddrinfo (address, port_str, &req, &ainfo_save);
paul718e3742002-12-13 20:15:29 +0000443 if (ret != 0)
444 {
445 zlog_err ("getaddrinfo: %s", gai_strerror (ret));
446 return -1;
447 }
448
Stephen Hemmingerd023aec2009-07-21 16:27:21 -0700449 count = 0;
450 for (ainfo = ainfo_save; ainfo; ainfo = ainfo->ai_next)
paul718e3742002-12-13 20:15:29 +0000451 {
Stephen Hemmingerd023aec2009-07-21 16:27:21 -0700452 int sock;
453
paul718e3742002-12-13 20:15:29 +0000454 if (ainfo->ai_family != AF_INET && ainfo->ai_family != AF_INET6)
455 continue;
456
457 sock = socket (ainfo->ai_family, ainfo->ai_socktype, ainfo->ai_protocol);
458 if (sock < 0)
459 {
ajs6099b3b2004-11-20 02:06:59 +0000460 zlog_err ("socket: %s", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +0000461 continue;
462 }
463
Stephen Hemmingerd023aec2009-07-21 16:27:21 -0700464 ret = bgp_listener (sock, ainfo->ai_addr, ainfo->ai_addrlen);
465 if (ret == 0)
466 ++count;
467 else
468 close(sock);
paul718e3742002-12-13 20:15:29 +0000469 }
paul718e3742002-12-13 20:15:29 +0000470 freeaddrinfo (ainfo_save);
Stephen Hemmingerd023aec2009-07-21 16:27:21 -0700471 if (count == 0)
472 {
473 zlog_err ("%s: no usable addresses", __func__);
474 return -1;
475 }
paul718e3742002-12-13 20:15:29 +0000476
Stephen Hemmingerd023aec2009-07-21 16:27:21 -0700477 return 0;
paul718e3742002-12-13 20:15:29 +0000478}
479#else
480/* Traditional IPv4 only version. */
481int
Stephen Hemmingerd023aec2009-07-21 16:27:21 -0700482bgp_socket (unsigned short port, const char *address)
paul718e3742002-12-13 20:15:29 +0000483{
484 int sock;
485 int socklen;
486 struct sockaddr_in sin;
hasso4a1a2712004-02-12 15:41:38 +0000487 int ret, en;
paul718e3742002-12-13 20:15:29 +0000488
489 sock = socket (AF_INET, SOCK_STREAM, 0);
490 if (sock < 0)
491 {
ajs6099b3b2004-11-20 02:06:59 +0000492 zlog_err ("socket: %s", safe_strerror (errno));
paul718e3742002-12-13 20:15:29 +0000493 return sock;
494 }
495
paul718e3742002-12-13 20:15:29 +0000496 memset (&sin, 0, sizeof (struct sockaddr_in));
paul718e3742002-12-13 20:15:29 +0000497 sin.sin_family = AF_INET;
498 sin.sin_port = htons (port);
499 socklen = sizeof (struct sockaddr_in);
Paul Jakma3a02d1f2007-11-01 14:29:11 +0000500
Paul Jakma90b68762008-01-29 17:26:34 +0000501 if (address && ((ret = inet_aton(address, &sin.sin_addr)) < 1))
Paul Jakma3a02d1f2007-11-01 14:29:11 +0000502 {
Paul Jakma90b68762008-01-29 17:26:34 +0000503 zlog_err("bgp_socket: could not parse ip address %s: %s",
504 address, safe_strerror (errno));
Paul Jakma3a02d1f2007-11-01 14:29:11 +0000505 return ret;
506 }
Paul Jakma6f0e3f62007-05-10 02:38:51 +0000507#ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
paul718e3742002-12-13 20:15:29 +0000508 sin.sin_len = socklen;
Paul Jakma6f0e3f62007-05-10 02:38:51 +0000509#endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
paul718e3742002-12-13 20:15:29 +0000510
Stephen Hemmingerd023aec2009-07-21 16:27:21 -0700511 ret = bgp_listener (sock, (struct sockaddr *) &sin, socklen);
paul718e3742002-12-13 20:15:29 +0000512 if (ret < 0)
513 {
paul718e3742002-12-13 20:15:29 +0000514 close (sock);
515 return ret;
516 }
paul718e3742002-12-13 20:15:29 +0000517 return sock;
518}
519#endif /* HAVE_IPV6 && !NRL */
Stephen Hemmingerd023aec2009-07-21 16:27:21 -0700520
521void
522bgp_close (void)
523{
524 struct listnode *node, *next;
525 struct bgp_listener *listener;
526
527 for (ALL_LIST_ELEMENTS (bm->listen_sockets, node, next, listener))
528 {
529 thread_cancel (listener->thread);
530 close (listener->fd);
531 listnode_delete (bm->listen_sockets, listener);
532 XFREE (MTYPE_BGP_LISTENER, listener);
533 }
534}