pfd_main.c

Go to the documentation of this file.
00001 /*
00002  * $Id: pfd_main.c 346460 2009-11-14 05:06:47Z ssiano $
00003  *
00004  * This code is provided as is by Juniper Networks SDK Developer Support.
00005  * It is provided with no warranties or guarantees, and Juniper Networks
00006  * will not provide support or maintenance of this code in any fashion.
00007  * The code is provided only to help a developer better understand how
00008  * the SDK can be used.
00009  *
00010  * Copyright (c) 2007-2008, Juniper Networks, Inc.
00011  * All rights reserved.
00012  */
00013 
00021 /* The Application and This Daemon's Documentation: */
00022 
00124 #include <signal.h>
00125 #include <string.h>
00126 #include <sys/types.h>
00127 #include <isc/eventlib.h>
00128 #include <jnx/mpsdk.h>
00129 #include <jnx/aux_types.h>
00130 #include <sync/policy_ipc.h>
00131 #include "pfd_conn.h"
00132 #include "pfd_kcom.h"
00133 #include "pfd_logging.h"
00134 #include "pfd_packet.h"
00135 #include "pfd_config.h"
00136 #include "pfd_nat.h"
00137 #include "pfd_main.h"
00138 
00139 /*** Constants ***/
00140 
00144 #define DNAME_PFD    "pfd"
00145 
00146 /*** Data Structures ***/
00147 
00148 
00149 /*** STATIC/INTERNAL Functions ***/
00150 
00151 
00155 static void 
00156 pfd_quit(int signo __unused)
00157 {
00158     LOG(LOG_INFO, "PFD shutting down.");
00159     stop_packet_loops();
00160     close_connections();
00161     clear_config();
00162     destroy_packet_loops_config();
00163     terminate_nat();
00164     msp_exit();
00165     exit(0);
00166 }
00167 
00168 
00177 static int
00178 pfd_init(evContext ctx)
00179 {
00180     int rc;
00181 
00182     msp_init();
00183     
00184     // Handle some signals that we may receive:
00185     signal(SIGTERM, pfd_quit); // call quit fnc
00186     signal(SIGHUP, SIG_IGN); // ignore
00187     signal(SIGPIPE, SIG_IGN); // ignore
00188     
00189     // call init function for modules:
00190     
00191     rc = init_config(ctx);
00192     if(rc != SUCCESS) {
00193         LOG(LOG_ALERT, "%s: Failed to initialize the PFD. "
00194             "See error log for details ", __func__);
00195         pfd_shutdown();
00196     }
00197     
00198     init_packet_loops_config();
00199     init_nat();
00200     pfd_kcom_init(ctx);
00201     
00202     rc = init_connections(ctx);
00203     if(rc != SUCCESS) {
00204         LOG(LOG_ALERT, "%s: Failed to initialize the PFD. "
00205             "See error log for details ", __func__);
00206         pfd_shutdown();
00207     }
00208 
00209     return SUCCESS;
00210 }
00211 
00212 
00213 /*** GLOBAL/EXTERNAL Functions ***/
00214 
00215 
00219 void
00220 pfd_shutdown(void)
00221 {
00222     LOG(LOG_INFO, "PFD shutting down.");
00223     stop_packet_loops();
00224     close_connections();
00225     clear_config();
00226     destroy_packet_loops_config();
00227     terminate_nat();
00228     msp_exit();
00229     exit(1);
00230 }
00231 
00244 int
00245 main(int32_t argc , char **argv)
00246 {
00247     mp_sdk_app_ctx_t app_ctx;
00248     int rc;
00249 
00250     app_ctx = msp_create_app_ctx(argc, argv, DNAME_PFD);
00251     msp_set_app_cb_init(app_ctx, pfd_init);
00252 
00253     rc = msp_app_init(app_ctx);
00254 
00255     /* Should never reach this point */
00256     msp_destroy_app_ctx(app_ctx);
00257     return rc;
00258 }
00259 

2007-2009 Juniper Networks, Inc. All rights reserved. The information contained herein is confidential information of Juniper Networks, Inc., and may not be used, disclosed, distributed, modified, or copied without the prior written consent of Juniper Networks, Inc. in an express license. This information is subject to change by Juniper Networks, Inc. Juniper Networks, the Juniper Networks logo, and JUNOS are registered trademarks of Juniper Networks, Inc. in the United States and other countries. All other trademarks, service marks, registered trademarks, or registered service marks are the property of their respective owners.
Generated on Sun May 30 20:27:07 2010 for SDK Your Net Corporation Policy Manager Example: Packet Filtering Daemon (pfd) 1.0 by Doxygen 1.5.1