abstracting out port validation because shared between udp and tcp.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user