ped_kcom.c

Go to the documentation of this file.
00001 /*
00002  * $Id: ped_kcom.c 366303 2010-03-05 13:14:01Z taoliu $
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 #include <sync/common.h>
00022 #include <jnx/provider_info.h>
00023 #include "ped_services.h"
00024 #include "ped_kcom.h"
00025 #include "ped_config.h"
00026 #include "ped_conn.h"
00027 #include "ped_policy_table.h"
00028 #include "ped_service_route.h"
00029 #include "ped_logging.h"
00030 
00031 #include PE_OUT_H
00032 
00033 /*** Constants ***/
00034 
00035 #define KCOM_ID_PED             77  
00036 
00037 #define MSP_IFD_NAME_PATTERN "ms-"  
00038 
00039 #define INT_NAME_STR_SIZE       64  
00040 
00041 
00042 /*** Data Structures ***/
00043 
00044 extern evContext ped_ctx;      
00045 
00046 static int if_count;           
00047 static int if_total = 0;       
00048 
00049 /*** STATIC/INTERNAL Functions ***/
00050 
00051 
00064 static int
00065 iff_async_handler(kcom_iff_t * msg, void * user_info __unused)
00066 {
00067     INSIST(msg != NULL);
00068 
00069     switch(msg->iff_op) {
00070         
00071         case KCOM_ADD:
00072             
00073             junos_trace(PED_TRACEFLAG_KCOM, "%s: %s.%d, af: %d, (ADD)",
00074                 __func__, msg->iff_name, msg->iff_subunit, msg->iff_af);
00075             
00076             update_interface(msg->iff_name, msg->iff_subunit,
00077                     msg->iff_af, INTERFACE_ADD);
00078 
00079             break;
00080             
00081         case KCOM_DELETE:
00082             
00083             junos_trace(PED_TRACEFLAG_KCOM, "%s: %s.%d, af: %d, (DELETE)",
00084                 __func__, msg->iff_name, msg->iff_subunit, msg->iff_af);
00085             
00086             update_interface(msg->iff_name, msg->iff_subunit,
00087                     msg->iff_af, INTERFACE_DELETE);
00088             break;
00089             
00090         case KCOM_CHANGE:
00091         case KCOM_GET:
00092             // ignore
00093             break;
00094         
00095         default:
00096             ERRMSG(PED, TRACE_LOG_ERR,
00097                 "%s: Got an unknown operation type", __func__);
00098         
00099     }
00100     
00101     junos_kcom_msg_free(msg);
00102     
00103     return 0;
00104 }
00105 
00117 static int
00118 iff_manage_handler(kcom_iff_t * msg, void * user_info __unused)
00119 {
00120     junos_trace(PED_TRACEFLAG_KCOM,
00121             "%s: Handling iff %s with family %d",
00122             __func__, msg->iff_name, msg->iff_af);
00123     
00124     ++if_count;
00125     
00126     update_interface(msg->iff_name, msg->iff_subunit,
00127             msg->iff_af, INTERFACE_REFRESH);
00128 
00129     junos_kcom_msg_free(msg);
00130 
00131     return 0;
00132 }
00133 
00134 
00146 static int
00147 ifd_async_handler(kcom_ifdev_t * msg, void * user_info __unused)
00148 {
00149     char * name = msg->ifdev_name;
00150 
00151     if((msg->ifdev_op == KCOM_DELETE || junos_kcom_ifd_down(msg)) &&
00152        strstr(name, MSP_IFD_NAME_PATTERN)) {
00153         
00154         junos_trace(PED_TRACEFLAG_KCOM, "%s: Handling ifd %s", __func__, name);
00155         
00156         // An MS PIC is going down and may be one we're connected to
00157         mspic_offline(name);
00158     }
00159     
00160     junos_kcom_msg_free(msg);
00161 
00162     return 0;
00163 }
00164 
00165 
00166 /*** GLOBAL/EXTERNAL Functions ***/
00167 
00168 
00173 int
00174 get_interface_total(void)
00175 {
00176     return if_total;
00177 }
00178 
00183 void
00184 update_all_interfaces(void)
00185 {
00186     ifl_idx_t idx;
00187 
00188     junos_trace(PED_TRACEFLAG_KCOM, "%s", __func__);
00189 
00190     // Set interface index to 0.
00191     ifl_idx_t_setval(idx, 0);
00192 
00193     if_count = 0;
00194     // Walk through all interfaces and families (note set idx to 0).
00195     junos_kcom_iff_get_all(iff_manage_handler, idx, NULL);
00196     if_total = if_count;
00197 }
00198 
00199 
00207 int
00208 ped_kcom_init(void)
00209 {
00210     int status;
00211     provider_origin_id_t origin_id;
00212 
00213     status = provider_info_get_origin_id(&origin_id);
00214     
00215     if (status) {
00216         ERRMSG(PED, TRACE_LOG_ERR,
00217             "%s: Retrieving origin ID failed: %m", __func__);
00218         return status;
00219     }
00220 
00221     junos_trace(PED_TRACEFLAG_KCOM, "%s", __func__);
00222 
00223     status = junos_kcom_init(origin_id, ped_ctx);
00224     INSIST(status == KCOM_OK);
00225 
00226     if((status = junos_kcom_register_iff_handler(NULL, iff_async_handler))) {
00227         ERRMSG(PED, TRACE_LOG_ERR,
00228                 "%s: Register iff handler FAILED!", __func__);
00229     }
00230     
00231     if((status = junos_kcom_register_ifd_handler(NULL, ifd_async_handler))) {
00232         ERRMSG(PED, TRACE_LOG_ERR,
00233                 "%s: Register ifd handler FAILED!", __func__);
00234     }
00235     
00236     return status;
00237 }

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:06 2010 for SDK Your Net Corporation Policy Manager Example: Policy Enforcement Daemon 1.0 by Doxygen 1.5.1