back to topotato report
topotato coverage report
Current view: top level - ospf6d - ospf6_main.c (source / functions) Hit Total Coverage
Test: test_ospf_topo1.py::OSPFTopo1Test Lines: 48 65 73.8 %
Date: 2023-02-24 18:38:32 Functions: 4 7 57.1 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (C) 1999 Yasuhiro Ohara
       3             :  *
       4             :  * This file is part of GNU Zebra.
       5             :  *
       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
       9             :  * later version.
      10             :  *
      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.
      15             :  *
      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
      19             :  */
      20             : 
      21             : #include <zebra.h>
      22             : #include <lib/version.h>
      23             : #include <lib/keychain.h>
      24             : #include <stdlib.h>
      25             : 
      26             : #include "getopt.h"
      27             : #include "thread.h"
      28             : #include "log.h"
      29             : #include "command.h"
      30             : #include "vty.h"
      31             : #include "memory.h"
      32             : #include "if.h"
      33             : #include "filter.h"
      34             : #include "prefix.h"
      35             : #include "plist.h"
      36             : #include "privs.h"
      37             : #include "sigevent.h"
      38             : #include "zclient.h"
      39             : #include "vrf.h"
      40             : #include "bfd.h"
      41             : #include "libfrr.h"
      42             : 
      43             : #include "ospf6d.h"
      44             : #include "ospf6_top.h"
      45             : #include "ospf6_message.h"
      46             : #include "ospf6_network.h"
      47             : #include "ospf6_asbr.h"
      48             : #include "ospf6_lsa.h"
      49             : #include "ospf6_interface.h"
      50             : #include "ospf6_zebra.h"
      51             : #include "ospf6_routemap_nb.h"
      52             : 
      53             : /* Default configuration file name for ospf6d. */
      54             : #define OSPF6_DEFAULT_CONFIG       "ospf6d.conf"
      55             : 
      56             : /* Default port values. */
      57             : #define OSPF6_VTY_PORT             2606
      58             : 
      59             : /* ospf6d privileges */
      60             : zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_SYS_ADMIN};
      61             : 
      62             : struct zebra_privs_t ospf6d_privs = {
      63             : #if defined(FRR_USER)
      64             :         .user = FRR_USER,
      65             : #endif
      66             : #if defined FRR_GROUP
      67             :         .group = FRR_GROUP,
      68             : #endif
      69             : #ifdef VTY_GROUP
      70             :         .vty_group = VTY_GROUP,
      71             : #endif
      72             :         .caps_p = _caps_p,
      73             :         .cap_num_p = array_size(_caps_p),
      74             :         .cap_num_i = 0};
      75             : 
      76             : /* ospf6d options, we use GNU getopt library. */
      77             : struct option longopts[] = {{0}};
      78             : 
      79             : /* Master of threads. */
      80             : struct thread_master *master;
      81             : 
      82           4 : static void __attribute__((noreturn)) ospf6_exit(int status)
      83             : {
      84           4 :         struct vrf *vrf;
      85           4 :         struct interface *ifp;
      86           4 :         struct ospf6 *ospf6;
      87           4 :         struct listnode *node, *nnode;
      88             : 
      89           4 :         frr_early_fini();
      90             : 
      91           4 :         bfd_protocol_integration_set_shutdown(true);
      92             : 
      93          12 :         for (ALL_LIST_ELEMENTS(om6->ospf6, node, nnode, ospf6)) {
      94           4 :                 vrf = vrf_lookup_by_id(ospf6->vrf_id);
      95           4 :                 ospf6_delete(ospf6);
      96           4 :                 ospf6 = NULL;
      97          21 :                 FOR_ALL_INTERFACES (vrf, ifp)
      98          13 :                         if (ifp->info != NULL)
      99           9 :                                 ospf6_interface_delete(ifp->info);
     100             :         }
     101             : 
     102           4 :         ospf6_message_terminate();
     103           4 :         ospf6_asbr_terminate();
     104           4 :         ospf6_lsa_terminate();
     105             : 
     106             :         /* reverse access_list_init */
     107           4 :         access_list_reset();
     108             : 
     109             :         /* reverse prefix_list_init */
     110           4 :         prefix_list_add_hook(NULL);
     111           4 :         prefix_list_delete_hook(NULL);
     112           4 :         prefix_list_reset();
     113             : 
     114           4 :         vrf_terminate();
     115             : 
     116           4 :         if (zclient) {
     117           4 :                 zclient_stop(zclient);
     118           4 :                 zclient_free(zclient);
     119             :         }
     120             : 
     121           4 :         frr_fini();
     122           4 :         exit(status);
     123             : }
     124             : 
     125             : /* SIGHUP handler. */
     126           0 : static void sighup(void)
     127             : {
     128           0 :         zlog_info("SIGHUP received");
     129           0 : }
     130             : 
     131             : /* SIGINT handler. */
     132           0 : static void sigint(void)
     133             : {
     134           0 :         zlog_notice("Terminating on signal SIGINT");
     135           0 :         ospf6_exit(0);
     136             : }
     137             : 
     138             : /* SIGTERM handler. */
     139           4 : static void sigterm(void)
     140             : {
     141           4 :         zlog_notice("Terminating on signal SIGTERM");
     142           4 :         ospf6_exit(0);
     143             : }
     144             : 
     145             : /* SIGUSR1 handler. */
     146           0 : static void sigusr1(void)
     147             : {
     148           0 :         zlog_info("SIGUSR1 received");
     149           0 :         zlog_rotate();
     150           0 : }
     151             : 
     152             : struct frr_signal_t ospf6_signals[] = {
     153             :         {
     154             :                 .signal = SIGHUP,
     155             :                 .handler = &sighup,
     156             :         },
     157             :         {
     158             :                 .signal = SIGINT,
     159             :                 .handler = &sigint,
     160             :         },
     161             :         {
     162             :                 .signal = SIGTERM,
     163             :                 .handler = &sigterm,
     164             :         },
     165             :         {
     166             :                 .signal = SIGUSR1,
     167             :                 .handler = &sigusr1,
     168             :         },
     169             : };
     170             : 
     171             : static const struct frr_yang_module_info *const ospf6d_yang_modules[] = {
     172             :         &frr_filter_info,
     173             :         &frr_interface_info,
     174             :         &frr_route_map_info,
     175             :         &frr_vrf_info,
     176             :         &frr_ospf_route_map_info,
     177             :         &frr_ospf6_route_map_info,
     178             : };
     179             : 
     180           4 : FRR_DAEMON_INFO(ospf6d, OSPF6, .vty_port = OSPF6_VTY_PORT,
     181             : 
     182             :                 .proghelp = "Implementation of the OSPFv3 routing protocol.",
     183             : 
     184             :                 .signals = ospf6_signals,
     185             :                 .n_signals = array_size(ospf6_signals),
     186             : 
     187             :                 .privs = &ospf6d_privs, .yang_modules = ospf6d_yang_modules,
     188             :                 .n_yang_modules = array_size(ospf6d_yang_modules),
     189             : );
     190             : 
     191             : /* Main routine of ospf6d. Treatment of argument and starting ospf finite
     192             :    state machine is handled here. */
     193           4 : int main(int argc, char *argv[], char *envp[])
     194             : {
     195           4 :         int opt;
     196             : 
     197           4 :         frr_preinit(&ospf6d_di, argc, argv);
     198           4 :         frr_opt_add("", longopts, "");
     199             : 
     200             :         /* Command line argument treatment. */
     201           4 :         while (1) {
     202           4 :                 opt = frr_getopt(argc, argv, NULL);
     203             : 
     204           4 :                 if (opt == EOF)
     205             :                         break;
     206             : 
     207           0 :                 switch (opt) {
     208             :                 case 0:
     209             :                         break;
     210           0 :                 default:
     211           0 :                         frr_help_exit(1);
     212             :                 }
     213             :         }
     214             : 
     215           4 :         if (geteuid() != 0) {
     216           0 :                 errno = EPERM;
     217           0 :                 perror(ospf6d_di.progname);
     218           0 :                 exit(1);
     219             :         }
     220             : 
     221             :         /* OSPF6 master init. */
     222           4 :         ospf6_master_init(frr_init());
     223             : 
     224             :         /* thread master */
     225           4 :         master = om6->master;
     226             : 
     227           4 :         keychain_init();
     228           4 :         ospf6_vrf_init();
     229           4 :         access_list_init();
     230           4 :         prefix_list_init();
     231             : 
     232             :         /* initialize ospf6 */
     233           4 :         ospf6_init(master);
     234             : 
     235           4 :         frr_config_fork();
     236           4 :         frr_run(master);
     237             : 
     238             :         /* Not reached. */
     239           0 :         ospf6_exit(0);
     240             : }

Generated by: LCOV version v1.16-topotato