route-manager_kcom.c

Go to the documentation of this file.
00001 /*
00002  * $Id$
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) 2010, Juniper Networks, Inc.
00011  * All rights reserved.
00012  */
00013 
00020 #include <stdlib.h>
00021 #include <string.h>
00022 #include <sys/types.h>
00023 #include <isc/eventlib.h>
00024 #include <sys/queue.h>
00025 #include <jnx/ssd_ipc_msg.h>
00026 #include <jnx/junos_kcom.h>
00027 #include <jnx/junos_trace.h>
00028 #include "route-manager.h"
00029 
00030 #include OUT_H
00031 
00042 int
00043 kcom_ifl_get_idx_by_name (char *name)
00044 {
00045     int rc;
00046     char *unit_str;
00047     int unit;
00048     kcom_ifl_t ifl;
00049 
00050     unit_str = strdup(name);
00051     name = strsep(&unit_str, ".");
00052     if (unit_str) {
00053         unit = (int)strtol(unit_str, NULL, 10);
00054     } else {
00055         unit = 0;
00056     }
00057     if (junos_kcom_ifl_get_by_name(name, unit, &ifl) < 0) {
00058         rc = -1;
00059     } else {
00060         rc = ifl_idx_t_getval(ifl.ifl_index);
00061     }
00062     free(name);
00063     return rc;
00064 }
00065 
00076 int
00077 kcom_client_id_save (int id)
00078 {
00079     junos_kcom_gencfg_t gencfg;
00080 
00081     JUNOS_KCOM_GENCFG_INIT(&gencfg);
00082     gencfg.opcode = JUNOS_KCOM_GENCFG_OPCODE_BLOB_ADD;
00083     gencfg.blob_id = RM_BLOB_ID_CLIENT_ID;
00084     gencfg.dest = JUNOS_KCOM_GENCFG_DEST_RE_LOCAL_ONLY;
00085     gencfg.key.size = sizeof(gencfg.blob_id);
00086     gencfg.key.data_p = &gencfg.blob_id;
00087     gencfg.blob.size = sizeof(id);
00088     gencfg.blob.data_p = &id;
00089     if (junos_kcom_gencfg(&gencfg) < 0) {
00090         RM_LOG(LOG_ERR, "%s: Save GENCFG blob ERROR!", __func__);
00091         return -1;
00092     } else {
00093         RM_TRACE(TF_KCOM, "%s: Saved ID %d", __func__, id);
00094         return 0;
00095     }
00096 }
00097 
00105 int
00106 kcom_client_id_restore (void)
00107 {
00108     junos_kcom_gencfg_t gencfg;
00109 
00110     JUNOS_KCOM_GENCFG_INIT(&gencfg);
00111     gencfg.opcode = JUNOS_KCOM_GENCFG_OPCODE_BLOB_GET;
00112     gencfg.blob_id = RM_BLOB_ID_CLIENT_ID;
00113     gencfg.key.size = sizeof(gencfg.blob_id);
00114     gencfg.key.data_p = &gencfg.blob_id;
00115     if (junos_kcom_gencfg(&gencfg) < 0) {
00116         RM_LOG(LOG_ERR, "%s: Get GENCFG blob ERROR!", __func__);
00117         return -1;
00118     } else {
00119         if (!gencfg.blob.size) {
00120             RM_TRACE(TF_KCOM, "%s: Didn't get the blob", __func__);
00121             return -1;
00122         } else {
00123             RM_TRACE(TF_KCOM, "%s: Got ID %d", __func__,
00124                     *((int *)gencfg.blob.data_p));
00125             return *((int *)gencfg.blob.data_p);
00126         }
00127     }
00128 }
00129 
00140 static int
00141 kcom_gencfg_async_hdlr (junos_kcom_gencfg_t *gencfg)
00142 {
00143 
00144     gencfg->opcode = JUNOS_KCOM_GENCFG_OPCODE_GET_FREE;
00145 
00146     /* Set get_p to NULL. Otherwise junos_kcom_gencfg() will
00147      * free the data to which get_p points to. The data will be
00148      * freed later (in kcom_msg_handler())
00149      */
00150     gencfg->get_p = NULL;
00151     junos_kcom_gencfg(gencfg);
00152     junos_kcom_msg_free(gencfg);
00153     return 0;
00154 }
00155 
00161 void
00162 kcom_close (void)
00163 {
00164     junos_kcom_shutdown();
00165 }
00166 
00177 int
00178 kcom_init (evContext ev_ctx)
00179 {
00180     junos_kcom_gencfg_t gencfg_req;
00181 
00182     if (junos_kcom_init(255, ev_ctx) != KCOM_OK) {
00183         RM_LOG(LOG_ERR, "%s: KCOM init ERROR!", __func__);
00184         return -1;
00185     }
00186 
00187     JUNOS_KCOM_GENCFG_INIT(&gencfg_req);
00188     gencfg_req.opcode = JUNOS_KCOM_GENCFG_OPCODE_INIT;
00189     gencfg_req.user_handler = kcom_gencfg_async_hdlr;
00190     if (junos_kcom_gencfg(&gencfg_req) != KCOM_OK) {
00191         RM_LOG(LOG_ERR, "%s: KCOM GENCFG init ERROR!", __func__);
00192         return -1;
00193     }
00194     return 0;
00195 }
00196 

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 Route Manager: route-manager 1.0 by Doxygen 1.5.1