check if IPv6 address ip[] match the rule with IPv6 address ip_rule[] * and depth. if matched, return 0, else return -1. */
| 1068 | * and depth. if matched, return 0, else return -1. |
| 1069 | */ |
| 1070 | static inline int check_lpm6_rule(uint8_t *ip, |
| 1071 | const uint8_t *ip_rule, uint8_t depth) |
| 1072 | { |
| 1073 | int k; |
| 1074 | uint8_t mask; |
| 1075 | |
| 1076 | for (k = 0; k < 16; k++) { |
| 1077 | if (depth >= 8) { |
| 1078 | if (ip[k] != ip_rule[k]) |
| 1079 | return -1; |
| 1080 | } else if (depth > 0) { |
| 1081 | mask = (uint8_t)((unsigned int)(-1) << (8 - depth)); |
| 1082 | if ((ip[k] & mask) == (ip_rule[k] & mask)) |
| 1083 | return 0; |
| 1084 | else |
| 1085 | return -1; |
| 1086 | } else |
| 1087 | return 0; |
| 1088 | |
| 1089 | depth -= 8; |
| 1090 | } |
| 1091 | |
| 1092 | return 0; |
| 1093 | } |
| 1094 | |
| 1095 | /* check input IPv6 address ip[] with each one in rule[] and |
| 1096 | * output the *next_hop from the matched item in rule[] with |