| 1449 | } |
| 1450 | |
| 1451 | static int |
| 1452 | LibAliasOutLocked(struct libalias *la, struct ip *pip, /* valid IP packet */ |
| 1453 | int maxpacketsize, /* How much the packet data may grow (FTP |
| 1454 | * and IRC inline changes) */ |
| 1455 | int create /* Create new entries ? */ |
| 1456 | ) |
| 1457 | { |
| 1458 | int iresult; |
| 1459 | struct in_addr addr_save; |
| 1460 | |
| 1461 | if (la->packetAliasMode & PKT_ALIAS_REVERSE) { |
| 1462 | la->packetAliasMode &= ~PKT_ALIAS_REVERSE; |
| 1463 | iresult = LibAliasInLocked(la, pip, maxpacketsize); |
| 1464 | la->packetAliasMode |= PKT_ALIAS_REVERSE; |
| 1465 | goto getout; |
| 1466 | } |
| 1467 | HouseKeeping(la); |
| 1468 | ClearCheckNewLink(la); |
| 1469 | |
| 1470 | /* Defense against mangled packets */ |
| 1471 | if (ntohs(pip->ip_len) > maxpacketsize |
| 1472 | || (pip->ip_hl << 2) > maxpacketsize) { |
| 1473 | iresult = PKT_ALIAS_IGNORED; |
| 1474 | goto getout; |
| 1475 | } |
| 1476 | |
| 1477 | addr_save = GetDefaultAliasAddress(la); |
| 1478 | if (la->packetAliasMode & PKT_ALIAS_UNREGISTERED_ONLY || |
| 1479 | la->packetAliasMode & PKT_ALIAS_UNREGISTERED_CGN) { |
| 1480 | u_long addr; |
| 1481 | int iclass; |
| 1482 | |
| 1483 | iclass = 0; |
| 1484 | addr = ntohl(pip->ip_src.s_addr); |
| 1485 | if (addr >= UNREG_ADDR_C_LOWER && addr <= UNREG_ADDR_C_UPPER) |
| 1486 | iclass = 3; |
| 1487 | else if (addr >= UNREG_ADDR_B_LOWER && addr <= UNREG_ADDR_B_UPPER) |
| 1488 | iclass = 2; |
| 1489 | else if (addr >= UNREG_ADDR_A_LOWER && addr <= UNREG_ADDR_A_UPPER) |
| 1490 | iclass = 1; |
| 1491 | else if (addr >= UNREG_ADDR_CGN_LOWER && addr <= UNREG_ADDR_CGN_UPPER && |
| 1492 | la->packetAliasMode & PKT_ALIAS_UNREGISTERED_CGN) |
| 1493 | iclass = 4; |
| 1494 | |
| 1495 | if (iclass == 0) { |
| 1496 | SetDefaultAliasAddress(la, pip->ip_src); |
| 1497 | } |
| 1498 | } else if (la->packetAliasMode & PKT_ALIAS_PROXY_ONLY) { |
| 1499 | SetDefaultAliasAddress(la, pip->ip_src); |
| 1500 | } |
| 1501 | iresult = PKT_ALIAS_IGNORED; |
| 1502 | if ((ntohs(pip->ip_off) & IP_OFFMASK) == 0) { |
| 1503 | switch (pip->ip_p) { |
| 1504 | case IPPROTO_ICMP: |
| 1505 | iresult = IcmpAliasOut(la, pip, create); |
| 1506 | break; |
| 1507 | case IPPROTO_UDP: |
| 1508 | iresult = UdpAliasOut(la, pip, maxpacketsize, create); |
no test coverage detected