pfd_kcom.c

00001 /*
00002  * $Id: pfd_kcom.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 
00022 #include <string.h>
00023 #include <jnx/aux_types.h>
00024 #include <netinet/in.h>
00025 #include <arpa/inet.h>
00026 #include <isc/eventlib.h>
00027 #include <jnx/junos_kcom.h>
00028 #include "pfd_kcom.h"
00029 #include "pfd_conn.h"
00030 #include "pfd_config.h"
00031 #include "pfd_packet.h"
00032 #include "pfd_logging.h"
00033 #include "pfd_main.h"
00034 
00035 /*** Constants ***/
00036 
00037 #define KCOM_ID_PFD   78  
00038 
00039 /*** Data Structures ***/
00040 
00041 boolean vrf_ready = FALSE; 
00042 
00043 static evContext ev_ctx; 
00044 
00045 /*** STATIC/INTERNAL Functions ***/
00046 
00062 static void
00063 stop_kcom(evContext ctx UNUSED, void * uap UNUSED,
00064             struct timespec due UNUSED, struct timespec inter UNUSED)
00065 {
00066     junos_kcom_shutdown();
00067 }
00068 
00080 static int
00081 rtb_async_handler(kcom_rtb_t * msg, void * user_info UNUSED)
00082 {    
00083     if(strcmp(msg->rtb_name, RI_PFD_FORWARDING) == 0) {
00084         
00085         if(msg->rtb_op == KCOM_ADD || msg->rtb_op == KCOM_GET) {
00086             
00087             // the one we're waiting for
00088             
00089             LOG(LOG_INFO, "%s: Found needed VRF %s", __func__,
00090                     RI_PFD_FORWARDING);
00091             
00092             vrf_ready = TRUE;
00093             
00094             // shutdown kcom (fires once)
00095             if(evSetTimer(ev_ctx, stop_kcom, NULL, evConsTime(0, 0), 
00096                     evConsTime(0, 0), NULL)) {
00097                 LOG(LOG_EMERG, "Initialize the stop kcom timer error");
00098                 return 1;
00099             }
00100             
00101             if(msg->rtb_op == KCOM_GET) {
00102                 junos_kcom_msg_free(msg);
00103                 
00104                 if(cpd_ready && get_cpd_address() && get_pfd_address()) {
00105                     init_packet_loops();
00106                 }
00107                 return KCOM_ITER_END;
00108                 
00109             } else {
00110                 junos_kcom_msg_free(msg);
00111                 
00112                 if(cpd_ready && get_cpd_address() && get_pfd_address()) {
00113                     init_packet_loops();
00114                 }
00115                 return 0;
00116             }
00117         } else if(msg->rtb_op == KCOM_DELETE) {
00118             // It shouldn't be deleted while running, we need it.
00119             
00120             LOG(LOG_ALERT, "%s: Stopping service because of VRF delete (%s)",
00121                     __func__, RI_PFD_FORWARDING);
00122             
00123             junos_kcom_msg_free(msg);
00124             junos_kcom_shutdown(); // stop kcom
00125             pfd_shutdown(); // exits
00126             return 0;
00127         }
00128     }
00129             
00130     junos_kcom_msg_free(msg);
00131 
00132     return 0;
00133 }
00134 
00135 
00136 /*** GLOBAL/EXTERNAL Functions ***/
00137 
00138 
00142 void
00143 check_pfd_vrf_status(void)
00144 {
00145     junos_kcom_rtb_get_all(rtb_async_handler, AF_INET, NULL);
00146 }
00147 
00148 
00156 int
00157 pfd_kcom_init(evContext ctx)
00158 {
00159     int status;
00160     
00161     ev_ctx = ctx;
00162 
00163     // We cannot get the origin ID on the PIC to feed to kcom init
00164     status = junos_kcom_init(KCOM_ID_PFD, ctx); // any number will do
00165     INSIST(status == KCOM_OK);
00166 
00167     if((status = junos_kcom_register_rtb_handler(NULL, rtb_async_handler))) {
00168         LOG(LOG_ERR, "%s: Register rtb handler FAILED!", __func__);
00169     }
00170     
00171     check_pfd_vrf_status();
00172     
00173     return status;
00174 }

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