pike_mi.c
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "ip_tree.h"
00030 #include "pike_mi.h"
00031
00032 #define IPv6_LEN 16
00033 #define IPv4_LEN 4
00034 #define MAX_IP_LEN IPv6_LEN
00035
00036
00037 static struct ip_node *ip_stack[MAX_IP_LEN];
00038
00039
00040 static inline void print_ip_stack( int level, struct mi_node *node)
00041 {
00042 if (level==IPv6_LEN) {
00043
00044 addf_mi_node_child( node, 0, 0, 0,
00045 "%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x:%x%x",
00046 ip_stack[0]->byte, ip_stack[1]->byte,
00047 ip_stack[2]->byte, ip_stack[3]->byte,
00048 ip_stack[4]->byte, ip_stack[5]->byte,
00049 ip_stack[6]->byte, ip_stack[7]->byte,
00050 ip_stack[8]->byte, ip_stack[9]->byte,
00051 ip_stack[10]->byte, ip_stack[11]->byte,
00052 ip_stack[12]->byte, ip_stack[13]->byte,
00053 ip_stack[14]->byte, ip_stack[15]->byte );
00054 } else if (level==IPv4_LEN) {
00055
00056 addf_mi_node_child( node, 0, 0, 0, "%d.%d.%d.%d",
00057 ip_stack[0]->byte,
00058 ip_stack[1]->byte,
00059 ip_stack[2]->byte,
00060 ip_stack[3]->byte );
00061 } else {
00062 LM_CRIT("leaf node at depth %d!!!\n", level);
00063 return;
00064 }
00065 }
00066
00067
00068 static void print_red_ips( struct ip_node *ip, int level, struct mi_node *node)
00069 {
00070 struct ip_node *foo;
00071
00072 if (level==MAX_IP_LEN) {
00073 LM_CRIT("tree deeper than %d!!!\n", MAX_IP_LEN);
00074 return;
00075 }
00076 ip_stack[level] = ip;
00077
00078
00079 if ( ip->flags&NODE_ISRED_FLAG)
00080 print_ip_stack(level+1,node);
00081
00082
00083 foo = ip->kids;
00084 while(foo){
00085 print_red_ips( foo, level+1, node);
00086 foo = foo->next;
00087 }
00088
00089 }
00090
00091
00092
00093
00094
00095
00096
00097 struct mi_root* mi_pike_list(struct mi_root* cmd_tree, void* param)
00098 {
00099 struct mi_root* rpl_tree;
00100 struct ip_node *ip;
00101 int i;
00102
00103 rpl_tree = init_mi_tree( 200, MI_OK_S, MI_OK_LEN);
00104 if (rpl_tree==0)
00105 return 0;
00106
00107 for( i=0 ; i<MAX_IP_BRANCHES ; i++ ) {
00108
00109 if (get_tree_branch(i)==0)
00110 continue;
00111
00112 lock_tree_branch(i);
00113
00114 if ( (ip=get_tree_branch(i))!=NULL )
00115 print_red_ips( ip, 0, &rpl_tree->node );
00116
00117 unlock_tree_branch(i);
00118 }
00119
00120 return rpl_tree;
00121 }
00122
00123