| 142 | |
| 143 | |
| 144 | rt_info_t* |
| 145 | get_prefix( |
| 146 | ptree_t *ptree, |
| 147 | str* prefix, |
| 148 | unsigned int rgid, |
| 149 | unsigned int *matched_len, |
| 150 | int *rgidx |
| 151 | ) |
| 152 | { |
| 153 | rt_info_t *rt = NULL; |
| 154 | char *tmp=NULL; |
| 155 | char local=0; |
| 156 | int idx=0; |
| 157 | |
| 158 | if(NULL == ptree) |
| 159 | goto err_exit; |
| 160 | if(NULL == prefix || prefix->len == 0) |
| 161 | goto err_exit; |
| 162 | tmp = prefix->s; |
| 163 | if (tmp == NULL) |
| 164 | goto err_exit; |
| 165 | /* go the tree down to the last digit in the |
| 166 | * prefix string or down to a leaf */ |
| 167 | while(tmp< (prefix->s+prefix->len)) { |
| 168 | local=*tmp; |
| 169 | if( !IS_VALID_PREFIX_CHAR(local) ) { |
| 170 | /* unknown character in the prefix string */ |
| 171 | goto err_exit; |
| 172 | } |
| 173 | if( tmp == (prefix->s+prefix->len-1) ) { |
| 174 | /* last digit in the prefix string */ |
| 175 | break; |
| 176 | } |
| 177 | idx = IDX_OF_CHAR(local); |
| 178 | if( NULL == ptree->ptnode[idx].next) { |
| 179 | /* this is a leaf */ |
| 180 | break; |
| 181 | } |
| 182 | ptree = ptree->ptnode[idx].next; |
| 183 | tmp++; |
| 184 | } |
| 185 | /* go in the tree up to the root trying to match the |
| 186 | * prefix */ |
| 187 | while(ptree !=NULL ) { |
| 188 | /* is it a real node or an intermediate one */ |
| 189 | idx = IDX_OF_CHAR(*tmp); |
| 190 | if(NULL != ptree->ptnode[idx].rg) { |
| 191 | /* real node; check the constraints on the routing info*/ |
| 192 | if( NULL != (rt = internal_check_rt( &(ptree->ptnode[idx]), rgid, rgidx))) |
| 193 | break; |
| 194 | } |
| 195 | tmp--; |
| 196 | ptree = ptree->bp; |
| 197 | } |
| 198 | if (matched_len) *matched_len = tmp + 1 - prefix->s ; |
| 199 | return rt; |
| 200 | |
| 201 | err_exit: |
no test coverage detected