]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Make socket init separate, so unit tests work again.
authorPaul Jakma <paul@quagga.net>
Tue, 1 May 2012 15:24:35 +0000 (16:24 +0100)
committerPaul Jakma <paul@quagga.net>
Wed, 2 May 2012 10:02:11 +0000 (11:02 +0100)
* Separate out BGP socket initialisation from bgp_get, and make it an
  explicit function. Allows unit tests to work again and probably also
  benefits dry-run.
* bgpd.c: (bgp_get) move socket init out...
  (bgp_socket_init) to here
* bgp_main.c: and call it after dry-run.
* bgpd.h: (bgp_socket_init) add prototype

bgpd/bgp_main.c
bgpd/bgpd.c
bgpd/bgpd.h

index 0f1d4829c17630aa3ce10e323455f5288aec33e1..5abc875652d824ea50bab96a006b755b4673e1ea 100644 (file)
@@ -441,6 +441,12 @@ main (int argc, char **argv)
   if(dryrun)
     return(0);
   
+  if (bgp_socket_init ())
+    {
+      zlog_err ("BGP socket creation failed");
+      return 1;
+    }
+  
   /* Turn into daemon if daemon_mode is set. */
   if (daemon_mode && daemon (0, 0) < 0)
     {
index 9c8eda8894b8e17bb95c1d89eb54a851adf94778..ab27783fa84439dd6f41e3cb3bd46c0796de18b7 100644 (file)
@@ -2055,13 +2055,6 @@ bgp_get (struct bgp **bgp_val, as_t *as, const char *name)
   bgp_router_id_set(bgp, &router_id_zebra);
   *bgp_val = bgp;
 
-  /* Create BGP server socket, if first instance.  */
-  if (list_isempty(bm->bgp))
-    {
-      if (bgp_socket (bm->port, bm->address) < 0)
-       return BGP_ERR_INVALID_VALUE;
-    }
-
   listnode_add (bm->bgp, bgp);
 
   return 0;
@@ -5341,6 +5334,15 @@ bgp_master_init (void)
 }
 
 \f
+int
+bgp_socket_init (void)
+{
+  /* Create BGP server socket */
+  if (bgp_socket (bm->port, bm->address) < 0)
+    return BGP_ERR_INVALID_VALUE;
+  return 0;
+}
+
 void
 bgp_init (void)
 {
index 09a3435c3bfbe9cc3f0d710161bf2becf26cc6be..d1e4f8e96adc8a4baa6e50d1d3fa4fe02d22d6df 100644 (file)
@@ -844,6 +844,7 @@ extern void bgp_config_write_family_header (struct vty *, afi_t, safi_t, int *);
 extern void bgp_master_init (void);
 
 extern void bgp_init (void);
+extern int bgp_socket_init (void);
 extern void bgp_route_map_init (void);
 
 extern int bgp_option_set (int);