]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: factor out TTL setting
authorDavid Lamparter <equinox@opensourcerouting.org>
Mon, 19 May 2014 20:52:04 +0000 (22:52 +0200)
committerDavid Lamparter <equinox@opensourcerouting.org>
Mon, 19 May 2014 21:25:46 +0000 (23:25 +0200)
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 <ddutt@cumulusnetworks.com>,
     split off from the next commit]
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
bgpd/bgp_network.c

index d86db3c8ac48cfd41066f60577e0675a39a81cf2..93bb1d9b5bb3c8741745834bba396cb8c4c937eb 100644 (file)
@@ -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);