00001
00002
00003
00004
00005
00006
00007 #ifndef _NMF_CFG
00008 #define _NMF_CFG
00009 #include <pthread.h>
00010 #include <nm/nm_list.h>
00011 #include <nm/nm_rbt.h>
00012 #include <nmf/nmf_slot.h>
00013
00014 #ifdef __cplusplus
00015 NM_CDECL_BEGIN
00016 #endif
00017
00031 enum nmf_cfg_obj_type {
00032 NMF_CFG_SLOT = 1,
00033 NMF_CFG_VLAN,
00034 NMF_CFG_LAG,
00035 NMF_CFG_LBG,
00036 NMF_CFG_MIRROR,
00037 NMF_CFG_POLICER,
00038 NMF_CFG_ACL,
00039 NMF_CFG_MCGRP,
00040 NMF_CFG_PORT,
00041 };
00042 #define NMF_CFG_TYPE_COUNT (NMF_CFG_PORT+1)
00043 static inline int nmf_cfg_type_is_valid(enum nmf_cfg_obj_type t) {
00044 return (t >= NMF_CFG_SLOT && t <= NMF_CFG_PORT);
00045 }
00046
00047 struct nmf_cfg {
00048 char *path;
00051 char *save_date;
00053 struct nm_list obj_list;
00054 struct tree_root {
00055 struct nm_rbt name;
00056 struct nm_rbt id;
00057 } root[NMF_CFG_TYPE_COUNT];
00058 };
00059
00060 struct nmf_cfg_obj {
00061 char *name;
00062 char *description;
00063 enum nmf_cfg_obj_type type;
00064 struct nm_list obj_list;
00065 struct nm_rbn name_node;
00066 struct nm_rbn id_node;
00068 struct nmf_slot *slot;
00069 u_int id;
00070 };
00071
00072 struct nmf_cfg_obj *
00073 nmf_cfg_obj_find_or_create(struct nmf_cfg *cfg, enum nmf_cfg_obj_type type,
00074 int id, const char *name, const char *desc);
00075 struct nmf_cfg_obj *
00076 nmf_cfg_obj_create(struct nmf_cfg *cfg, enum nmf_cfg_obj_type type,
00077 int id, const char *name, const char *desc);
00078 void nmf_cfg_obj_destroy(struct nmf_cfg *cfg, struct nmf_cfg_obj *obj);
00079
00080 static inline struct nmf_cfg_obj *__nmf_cfg_obj_find_by_name(struct nm_rbt *rbt, void *key)
00081 {
00082 struct nmf_cfg_obj *obj = NULL;
00083 struct nm_rbn *z = nm_rbt_find(rbt, key);
00084 if (z)
00085 obj = nm_container_of(z, struct nmf_cfg_obj, name_node);
00086 return obj;
00087 }
00088
00089 static inline struct nmf_cfg_obj *
00090 nmf_cfg_obj_find_by_name(struct nmf_cfg *cfg,
00091 enum nmf_cfg_obj_type type, void *key)
00092 {
00093 if (!nmf_cfg_type_is_valid(type))
00094 return NULL;
00095
00096 return __nmf_cfg_obj_find_by_name(&cfg->root[type].name, key);
00097 }
00098
00099 static inline struct nmf_cfg_obj *__nmf_cfg_obj_find_by_id(struct nm_rbt *rbt, void *key)
00100 {
00101 struct nmf_cfg_obj *obj = NULL;
00102 struct nm_rbn *z = nm_rbt_find(rbt, key);
00103 if (z)
00104 obj = nm_container_of(z, struct nmf_cfg_obj, id_node);
00105 return obj;
00106 }
00107
00108 static inline struct nmf_cfg_obj *
00109 nmf_cfg_obj_find_by_id(struct nmf_cfg *cfg,
00110 enum nmf_cfg_obj_type type, void *key)
00111 {
00112 if (!nmf_cfg_type_is_valid(type))
00113 return NULL;
00114
00115 return __nmf_cfg_obj_find_by_id(&cfg->root[type].id, key);
00116 }
00117
00118 struct nmf_cfg *nmf_cfg_create(void);
00119 extern int nmf_cfg_destroy(struct nmf_cfg *cfg);
00120 extern int nmf_srv_cfg_restore(struct nmf_cfg *, char *path);
00121 extern int nmf_cfg_restore(char *path);
00122 extern int nmf_srv_cfg_save(struct nmf_cfg *, char *path);
00123 extern int nmf_cfg_save(char *path);
00124 extern struct nmf_cfg *nmf_cfg_get(void);
00125 extern struct nmf_cfg_obj *nmf_cfg_obj_get_by_name(struct nmf_cfg *cfg,
00126 enum nmf_cfg_obj_type type,
00127 char *name);
00128 extern struct nmf_cfg_obj *nmf_cfg_obj_get_by_id(struct nmf_cfg *cfg,
00129 enum nmf_cfg_obj_type type,
00130 u_int id);
00131 #ifdef __cplusplus
00132 NM_CDECL_END
00133 #endif
00134
00135 #endif