reassembler_main.c

Go to the documentation of this file.
00001 /*
00002  * $Id: reassembler_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) 2009, Juniper Networks, Inc.
00011  * All rights reserved.
00012  */
00013 
00021 /* The Application and This Daemon's Documentation: */
00022 
00139 #include <signal.h>
00140 #include <stdbool.h>
00141 #include <stdlib.h>
00142 #include <unistd.h>
00143 #include <getopt.h>
00144 #include <isc/eventlib.h>
00145 #include <jnx/aux_types.h>
00146 #include <jnx/bits.h>
00147 #include <jnx/mpsdk.h>
00148 #include <sys/jnx/jbuf.h>
00149 #include "reassembler_logging.h"
00150 #include "reassembler_packet.h"
00151 
00152 
00153 /*** Constants ***/
00154 
00155 #define DNAME_REASSEMBLER  "reassembler"      
00156 
00157 #define MIN_MTU            576                
00158 
00159 #define MAX_MTU            JBUF_MAX_SEND_LEN  
00160 
00161 
00162 /*** Data Structures ***/
00163 
00164 uint16_t reassembler_mtu; 
00165 
00166 static bool invalid_mtu;  
00167 
00168 static evContext mainctx; 
00169 
00170 
00171 /*** STATIC/INTERNAL Functions ***/
00172 
00173 
00177 static void
00178 reassembler_quit(int signo __unused)
00179 {
00180     LOG(LOG_INFO, "%s: Reassmebler is exiting", __func__);
00181     
00182     stop_packet_loops(mainctx);
00183     msp_exit();
00184     exit(0);
00185 }
00186 
00187 
00196 static int
00197 reassembler_init(evContext ctx)
00198 {
00199     msp_init();
00200     
00201     mainctx = ctx;
00202     
00203 
00204     // Handle some signals that we may receive
00205     
00206     signal(SIGTERM, reassembler_quit); // call quit fnc
00207     signal(SIGHUP, SIG_IGN); // ignore
00208     signal(SIGPIPE, SIG_IGN); // ignore
00209     
00210     if(invalid_mtu) { // tell them what MTU we're using
00211         LOG(LOG_WARNING, "Did not parse an MTU in the valid range [%d-%d]. "
00212               "Using %d as the MTU", MIN_MTU, MAX_MTU, reassembler_mtu);
00213     } else {
00214         LOG(LOG_INFO, "Using %d as the configured MTU", reassembler_mtu);
00215     }
00216     
00217     // Start processing
00218 
00219     if(init_packet_loops(ctx)) {
00220         // exit
00221         LOG(LOG_EMERG, "Reassembler could not initialize. See error log.");
00222         return EFAIL;
00223     }
00224 
00225     return SUCCESS;
00226 }
00227 
00228 static int
00229 cmd_opt_hdlr (char c, char *args)
00230 {
00231     reassembler_mtu = MAX_MTU;
00232 
00233     invalid_mtu = true;
00234     if (c == 'm') {
00235         // optarg contains our MTU
00236         reassembler_mtu = (int)strtol(args, NULL, 10);
00237 
00238         if(reassembler_mtu > MAX_MTU || reassembler_mtu < MIN_MTU) {
00239             reassembler_mtu = MAX_MTU;
00240         } else {
00241             invalid_mtu = false;
00242         }
00243     }
00244     return 0;
00245 }
00246 
00247 /*** GLOBAL/EXTERNAL Functions ***/
00248 
00249 
00262 int
00263 main(int32_t argc , char ** argv)
00264 {
00265     mp_sdk_app_ctx_t app_ctx;
00266     int rc;
00267     struct option opts[] = {
00268         {"mtu", 1, NULL, 'm' },
00269         { NULL, 0, NULL, 0}
00270     };
00271 
00272     app_ctx = msp_create_app_ctx(argc, argv, DNAME_REASSEMBLER);
00273     msp_set_app_cb_init(app_ctx, reassembler_init);
00274     msp_set_app_cb_cmd_line_opts(app_ctx, cmd_opt_hdlr);
00275     msp_reg_cmd_line_opts(app_ctx, opts);
00276 
00277     rc = msp_app_init(app_ctx);
00278 
00279     /* Should never reach this point */
00280     msp_destroy_app_ctx(app_ctx);
00281     LOG(LOG_ERR, "Reassembler exiting unexpectedly");
00282     return rc;
00283 }
00284 

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 IP Fragment Reassembly Example: reassembler 1.0 by Doxygen 1.5.1