3 Copyright (C) 2008 Everton da Silva Marques
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file COPYING; if not, write to the
17 Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
37 #include "memory_vty.h"
47 #include "pim_version.h"
48 #include "pim_signals.h"
49 #include "pim_zebra.h"
51 #include "pim_iface.h"
54 extern struct host host
;
56 char config_default
[] = SYSCONFDIR PIMD_DEFAULT_CONFIG
;
58 struct option longopts
[] = {
59 { "daemon", no_argument
, NULL
, 'd'},
60 { "config_file", required_argument
, NULL
, 'f'},
61 { "pid_file", required_argument
, NULL
, 'i'},
62 { "vty_addr", required_argument
, NULL
, 'A'},
63 { "vty_port", required_argument
, NULL
, 'P'},
64 { "version", no_argument
, NULL
, 'v'},
65 { "debug_zclient", no_argument
, NULL
, 'Z'},
66 { "help", no_argument
, NULL
, 'h'},
71 zebra_capabilities_t _caps_p
[] =
79 /* pimd privileges to run with */
80 struct zebra_privs_t pimd_privs
=
82 #if defined(FRR_USER) && defined(FRR_GROUP)
87 .vty_group
= VTY_GROUP
,
90 .cap_num_p
= sizeof(_caps_p
)/sizeof(_caps_p
[0]),
95 const char *pid_file
= PATH_PIMD_PID
;
97 static void usage(int status
)
100 fprintf (stderr
, "Try `%s --help' for more information.\n", progname
);
102 printf ("Usage : %s [OPTION...]\n\
103 Daemon which manages PIM.\n\n\
104 -d, --daemon Run in daemon mode\n\
105 -f, --config_file Set configuration file name\n\
106 -i, --pid_file Set process identifier file name\n\
107 -z, --socket Set path of zebra socket\n\
108 -A, --vty_addr Set vty's bind address\n\
109 -P, --vty_port Set vty's port number\n\
110 -v, --version Print program version\n\
111 -h, --help Display this help and exit\n\
113 Report bugs to %s\n", progname
, PACKAGE_BUGREPORT
);
120 int main(int argc
, char** argv
, char** envp
) {
122 char *vty_addr
= NULL
;
125 char *config_file
= NULL
;
126 char *zebra_sock_path
= NULL
;
127 struct thread thread
;
131 progname
= ((p
= strrchr(argv
[0], '/')) ? ++p
: argv
[0]);
133 zlog_default
= openzlog(progname
, ZLOG_PIM
, 0,
134 LOG_CONS
|LOG_NDELAY
|LOG_PID
, LOG_DAEMON
);
135 zprivs_init (&pimd_privs
);
136 #if defined(HAVE_CUMULUS)
137 zlog_set_level (NULL
, ZLOG_DEST_SYSLOG
, zlog_default
->default_lvl
);
140 /* this while just reads the options */
144 opt
= getopt_long (argc
, argv
, "df:i:z:A:P:vZh", longopts
, 0);
156 config_file
= optarg
;
162 zebra_sock_path
= optarg
;
168 vty_port
= atoi (optarg
);
171 printf(PIMD_PROGNAME
" version %s\n", PIMD_VERSION
);
172 print_version(progname
);
184 master
= thread_master_create();
186 zlog_notice("Quagga %s " PIMD_PROGNAME
" %s starting",
187 FRR_VERSION
, PIMD_VERSION
);
199 prefix_list_add_hook (pim_rp_prefix_list_update
);
200 prefix_list_delete_hook (pim_rp_prefix_list_update
);
202 pim_route_map_init ();
204 pim_msdp_init (master
);
207 * Initialize zclient "update" and "lookup" sockets
209 pim_zebra_init(zebra_sock_path
);
211 zlog_notice("Loading configuration - begin");
213 /* Get configuration file. */
214 vty_read_config(config_file
, config_default
);
217 Starting from here zlog_* functions will log according configuration
220 zlog_notice("Loading configuration - end");
222 /* Change to the daemon program. */
225 zlog_warn("failed to daemonize");
229 /* Process ID file creation. */
230 pid_output(pid_file
);
232 /* Create pimd VTY socket */
234 vty_port
= PIMD_VTY_PORT
;
235 vty_serv_sock(vty_addr
, vty_port
, PIM_VTYSH_PATH
);
237 zlog_notice("Quagga %s " PIMD_PROGNAME
" %s starting, VTY interface at port TCP %d",
238 FRR_VERSION
, PIMD_VERSION
, vty_port
);
240 #ifdef PIM_DEBUG_BYDEFAULT
241 zlog_notice("PIM_DEBUG_BYDEFAULT: Enabling all debug commands");
242 PIM_DO_DEBUG_PIM_EVENTS
;
243 PIM_DO_DEBUG_PIM_PACKETS
;
244 PIM_DO_DEBUG_PIM_TRACE
;
245 PIM_DO_DEBUG_IGMP_EVENTS
;
246 PIM_DO_DEBUG_IGMP_PACKETS
;
247 PIM_DO_DEBUG_IGMP_TRACE
;
251 #ifdef PIM_CHECK_RECV_IFINDEX_SANITY
252 zlog_notice("PIM_CHECK_RECV_IFINDEX_SANITY: will match sock/recv ifindex");
253 #ifdef PIM_REPORT_RECV_IFINDEX_MISMATCH
254 zlog_notice("PIM_REPORT_RECV_IFINDEX_MISMATCH: will report sock/recv ifindex mismatch");
258 #ifdef PIM_UNEXPECTED_KERNEL_UPCALL
259 zlog_notice("PIM_UNEXPECTED_KERNEL_UPCALL: report unexpected kernel upcall");
262 while (thread_fetch(master
, &thread
))
263 thread_call(&thread
);
265 zlog_err("%s %s: thread_fetch() returned NULL, exiting",
266 __FILE__
, __PRETTY_FUNCTION__
);