ipprobe-mt_config.c

Go to the documentation of this file.
00001 /*
00002  * $Id: ipprobe-mt_config.c 347265 2009-11-19 13:55:39Z kdickman $
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 <sys/types.h>
00024 #include <sys/queue.h>
00025 #include <isc/eventlib.h>
00026 #include <netinet/in.h>
00027 #include <netinet/in_systm.h>
00028 #include <netinet/ip.h>
00029 #include <netinet/udp.h>
00030 #include <netinet/ip_icmp.h>
00031 #include <jnx/aux_types.h>
00032 #include <jnx/bits.h>
00033 #include <jnx/patricia.h>
00034 #include <jnx/pconn.h>
00035 #include <jnx/junos_trace.h>
00036 #include <ddl/dax.h>
00037 #include "ipprobe-mt.h"
00038 #include IPPROBE_MT_OUT_H
00039 
00040 /*** Data Structures ***/
00041 
00042 static uint16_t probe_mngr_port;   
00043 static uint16_t rspd_mngr_port;    
00046 static LIST_HEAD(, probe_params_s)  probe_params_list;
00047 
00048 /*** STATIC/INTERNAL Functions ***/
00049 
00053 static void
00054 config_post_proc (void)
00055 {
00056     probe_mngr_open(probe_mngr_port);
00057     rspd_mngr_open(rspd_mngr_port);
00058 }
00059 
00060 static void
00061 probe_params_clear (void)
00062 {
00063     probe_params_t *params;
00064 
00065     while ((params = LIST_FIRST(&probe_params_list))) {
00066         LIST_REMOVE(params, entry);
00067         free(params);
00068     }
00069 }
00070 
00071 
00072 /*** GLOBAL/EXTERNAL Functions ***/
00073 
00074 probe_params_t *
00075 probe_params_get (char *name)
00076 {
00077     probe_params_t *params;
00078 
00079     LIST_FOREACH(params, &probe_params_list, entry) {
00080         if (strncmp(params->name, name, sizeof(params->name)) == 0) {
00081             return params;
00082         }
00083     }
00084     return NULL;
00085 }
00086 
00097 int
00098 config_read (int check)
00099 {
00100     const char *rspd_mngr_config[] = { "sync", "ipprobe-mt",
00101             "responder-manager", NULL };
00102     const char *probe_mngr_config[] = { "sync", "ipprobe-mt",
00103             "probe-manager", NULL };
00104     const char *probe_params_config[] = { "sync", "ipprobe-mt",
00105             "probe", NULL };
00106     ddl_handle_t *top = NULL;
00107     ddl_handle_t *cop = NULL;
00108     ddl_handle_t *dop = NULL;
00109     probe_params_t *params;
00110 
00111     PROBE_TRACE(PROBE_TF_CONFIG, "%s: Loading probe configuration.", __func__);
00112 
00113     probe_mngr_port = PROBE_MNGR_PORT_DEFAULT;
00114     rspd_mngr_port = RSPD_MNGR_PORT_DEFAULT;
00115 
00116     /* Read probe manager port. */
00117     if (dax_get_object_by_path(NULL, probe_mngr_config, &top, TRUE)) {
00118         dax_get_ushort_by_aid(top, PROBE_MNGR_PORT, &probe_mngr_port);
00119         PROBE_TRACE(PROBE_TF_CONFIG, "%s: Probe manager port %d.",
00120                 __func__, probe_mngr_port);
00121         dax_release_object(&top);
00122     }
00123 
00124     /* Read responder manager port. */
00125     if (dax_get_object_by_path(NULL, rspd_mngr_config, &top, TRUE)) {
00126         dax_get_ushort_by_aid(top, RSPD_MNGR_PORT, &rspd_mngr_port);
00127         PROBE_TRACE(PROBE_TF_CONFIG, "%s: Responder manager port %d.",
00128                 __func__, rspd_mngr_port);
00129         dax_release_object(&top);
00130     }
00131 
00132     if (dax_get_object_by_path(NULL, probe_params_config, &cop, FALSE)) {
00133         if (dax_is_changed(cop)) {
00134             probe_params_clear();
00135             while (dax_visit_container(cop, &dop)) {
00136                 params = calloc(1, sizeof(*params));
00137                 if (!params) {
00138                     dax_error(dop, "Allocate memory ERROR!");
00139                     dax_release_object(&dop);
00140                     break;
00141                 }
00142                 if (!dax_get_stringr_by_aid(dop, PROBE_NAME,
00143                         params->name, sizeof(params->name))) {
00144 
00145                     /* Probe name is mandatory. */
00146                     dax_error(dop, "Read probe name ERROR!");
00147                     dax_release_object(&dop);
00148                     break;
00149                 }
00150                 PROBE_TRACE(PROBE_TF_CONFIG, "%s: Probe name %s.",
00151                         __func__, params->name);
00152                 dax_get_ubyte_by_aid(dop, PROBE_PROTOCOL, &params->proto);
00153                 PROBE_TRACE(PROBE_TF_CONFIG, "%s: Probe protocol %d.",
00154                         __func__, params->proto);
00155                 dax_get_ubyte_by_aid(dop, PROBE_TOS, &params->tos);
00156                 PROBE_TRACE(PROBE_TF_CONFIG, "%s: Probe TOS %d.",
00157                         __func__, params->tos);
00158                 dax_get_ushort_by_aid(dop, PROBE_SRC_PORT, &params->src_port);
00159                 PROBE_TRACE(PROBE_TF_CONFIG, "%s: Probe source port %d.",
00160                         __func__, params->src_port);
00161                 dax_get_ushort_by_aid(dop, PROBE_DST_PORT, &params->dst_port);
00162                 PROBE_TRACE(PROBE_TF_CONFIG, "%s: Probe destination port %d.",
00163                         __func__, params->dst_port);
00164                 dax_get_ushort_by_aid(dop, PACKET_SIZE, &params->pkt_size);
00165                 PROBE_TRACE(PROBE_TF_CONFIG, "%s: Probe packet size %d.",
00166                         __func__, params->pkt_size);
00167                 dax_get_ushort_by_aid(dop, PACKET_COUNT, &params->pkt_count);
00168                 PROBE_TRACE(PROBE_TF_CONFIG, "%s: Probe packet count %d.",
00169                         __func__, params->pkt_count);
00170                 dax_get_ushort_by_aid(dop, PACKET_INTERVAL,
00171                         &params->pkt_interval);
00172                 PROBE_TRACE(PROBE_TF_CONFIG, "%s: Probe packet interval %d.",
00173                         __func__, params->pkt_interval);
00174 
00175                 LIST_INSERT_HEAD(&probe_params_list, params, entry);
00176             }
00177         }
00178     } else {
00179         PROBE_TRACE(PROBE_TF_CONFIG, "%s: No probe parameters!", __func__);
00180         probe_params_clear();
00181     }
00182 
00183     if (check == 0) {
00184         config_post_proc();
00185     }
00186 
00187     return 0;
00188 }
00189 

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:00 2010 for SDK Your Net Corporation IP Probe MT: ipprobe-mt 1.0 by Doxygen 1.5.1