* Print the ip address contained in a command. */
| 1202 | * Print the ip address contained in a command. |
| 1203 | */ |
| 1204 | static void |
| 1205 | print_ip(struct buf_pr *bp, const struct format_opts *fo, |
| 1206 | const ipfw_insn_ip *cmd) |
| 1207 | { |
| 1208 | struct hostent *he = NULL; |
| 1209 | const struct in_addr *ia; |
| 1210 | const uint32_t *a = ((const ipfw_insn_u32 *)cmd)->d; |
| 1211 | uint32_t len = F_LEN((const ipfw_insn *)cmd); |
| 1212 | char *t; |
| 1213 | |
| 1214 | bprintf(bp, " "); |
| 1215 | if (cmd->o.opcode == O_IP_DST_LOOKUP && len > F_INSN_SIZE(ipfw_insn_u32)) { |
| 1216 | uint32_t d = a[1]; |
| 1217 | const char *arg = "<invalid>"; |
| 1218 | |
| 1219 | if (d < sizeof(lookup_key)/sizeof(lookup_key[0])) |
| 1220 | arg = match_value(rule_options, lookup_key[d]); |
| 1221 | t = table_search_ctlv(fo->tstate, |
| 1222 | ((const ipfw_insn *)cmd)->arg1); |
| 1223 | bprintf(bp, "lookup %s %s", arg, t); |
| 1224 | return; |
| 1225 | } |
| 1226 | if (cmd->o.opcode == O_IP_SRC_ME || cmd->o.opcode == O_IP_DST_ME) { |
| 1227 | bprintf(bp, "me"); |
| 1228 | return; |
| 1229 | } |
| 1230 | if (cmd->o.opcode == O_IP_SRC_LOOKUP || |
| 1231 | cmd->o.opcode == O_IP_DST_LOOKUP) { |
| 1232 | t = table_search_ctlv(fo->tstate, |
| 1233 | ((const ipfw_insn *)cmd)->arg1); |
| 1234 | bprintf(bp, "table(%s", t); |
| 1235 | if (len == F_INSN_SIZE(ipfw_insn_u32)) |
| 1236 | bprintf(bp, ",%u", *a); |
| 1237 | bprintf(bp, ")"); |
| 1238 | return; |
| 1239 | } |
| 1240 | if (cmd->o.opcode == O_IP_SRC_SET || cmd->o.opcode == O_IP_DST_SET) { |
| 1241 | const uint32_t *map = (const uint32_t *)&cmd->mask; |
| 1242 | struct in_addr addr; |
| 1243 | uint32_t x; |
| 1244 | int i, j; |
| 1245 | char comma = '{'; |
| 1246 | |
| 1247 | x = cmd->o.arg1 - 1; |
| 1248 | x = htonl(~x); |
| 1249 | addr.s_addr = htonl(cmd->addr.s_addr); |
| 1250 | bprintf(bp, "%s/%d", inet_ntoa(addr), |
| 1251 | contigmask((uint8_t *)&x, 32)); |
| 1252 | x = cmd->addr.s_addr; |
| 1253 | x &= 0xff; /* base */ |
| 1254 | /* |
| 1255 | * Print bits and ranges. |
| 1256 | * Locate first bit set (i), then locate first bit unset (j). |
| 1257 | * If we have 3+ consecutive bits set, then print them as a |
| 1258 | * range, otherwise only print the initial bit and rescan. |
| 1259 | */ |
| 1260 | for (i=0; i < cmd->o.arg1; i++) |
| 1261 | if (map[i/32] & (1<<(i & 31))) { |
no test coverage detected