abstracting out port validation because shared between udp and tcp.

This commit is contained in:
Zakir Durumeric
2013-08-18 23:36:57 -04:00
parent 37630d7325
commit b70a2835b9
3 changed files with 44 additions and 45 deletions

View File

@@ -79,4 +79,25 @@ static __attribute__((unused)) uint16_t tcp_checksum(unsigned short len_tcp,
return (unsigned short) (~sum);
}
// Returns 0 if dst_port is outside the expected valid range, non-zero otherwise
static __attribute__((unused)) inline int check_dst_port(uint16_t port,
int num_ports, uint32_t *validation)
{
if (port > zconf.source_port_last
|| port < zconf.source_port_first) {
return -1;
}
int32_t to_validate = port - zconf.source_port_first;
int32_t min = validation[1] % num_ports;
int32_t max = (validation[1] + zconf.packet_streams - 1) % num_ports;
return (((max - min) % num_ports) >= ((to_validate - min) % num_ports));
}
static __attribute__((unused)) inline uint16_t get_src_port(int num_ports,
int probe_num, uint32_t *validation)
{
return zconf.source_port_first + ((validation[1] + probe_num) % num_ports);
}
#endif