From: David Lamparter Date: Mon, 19 May 2014 20:52:04 +0000 (+0200) Subject: bgpd: factor out TTL setting X-Git-Tag: frr-2.0-rc1~1592 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=ef0b0c3e95a1f30d6f338100c689feef8ad5cd6e;p=mirror%2Ffrr.git bgpd: factor out TTL setting TTL/min TTL are set from both bgp_accept() and bgp_connect(). Factor them out so the following change to enable iBGP GTSM becomes more readable. [DL: originally by Dinesh G Dutt , split off from the next commit] Signed-off-by: David Lamparter --- diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index d86db3c8ac..93bb1d9b5b 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -145,6 +145,16 @@ bgp_update_sock_send_buffer_size (int fd) } } +static void +bgp_set_socket_ttl (struct peer *peer, int bgp_sock) +{ + if (peer->sort == BGP_PEER_EBGP) { + sockopt_ttl (peer->su.sa.sa_family, bgp_sock, peer->ttl); + if (peer->gtsm_hops) + sockopt_minttl (peer->su.sa.sa_family, bgp_sock, MAXTTL + 1 - peer->gtsm_hops); + } +} + /* Accept bgp connection. */ static int bgp_accept (struct thread *thread) @@ -198,12 +208,7 @@ bgp_accept (struct thread *thread) return -1; } - /* In case of peer is EBGP, we should set TTL for this connection. */ - if (peer1->sort == BGP_PEER_EBGP) { - sockopt_ttl (peer1->su.sa.sa_family, bgp_sock, peer1->ttl); - if (peer1->gtsm_hops) - sockopt_minttl (peer1->su.sa.sa_family, bgp_sock, MAXTTL + 1 - peer1->gtsm_hops); - } + bgp_set_socket_ttl (peer1, bgp_sock); /* Make dummy peer until read Open packet. */ if (BGP_DEBUG (events, EVENTS)) @@ -336,12 +341,7 @@ bgp_connect (struct peer *peer) /* Set socket send buffer size */ bgp_update_sock_send_buffer_size(peer->fd); - /* If we can get socket for the peer, adjest TTL and make connection. */ - if (peer->sort == BGP_PEER_EBGP) { - sockopt_ttl (peer->su.sa.sa_family, peer->fd, peer->ttl); - if (peer->gtsm_hops) - sockopt_minttl (peer->su.sa.sa_family, peer->fd, MAXTTL + 1 - peer->gtsm_hops); - } + bgp_set_socket_ttl (peer, peer->fd); sockopt_reuseaddr (peer->fd); sockopt_reuseport (peer->fd);