external-tests: add keepalive packet
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
a1e931f9dc
commit
19c89f3c3a
|
@ -172,4 +172,16 @@ func main() {
|
|||
if echo.ID != 921 || echo.Seq != 438 || string(echo.Data) != "WireGuard" {
|
||||
log.Fatalf("incorrect echo response: %#v", echo)
|
||||
}
|
||||
|
||||
keepalivePacket := make([]byte, 16)
|
||||
keepalivePacket[0] = 4 // Type: Data
|
||||
keepalivePacket[1] = 0 // Reserved
|
||||
keepalivePacket[2] = 0 // Reserved
|
||||
keepalivePacket[3] = 0 // Reserved
|
||||
binary.LittleEndian.PutUint32(keepalivePacket[4:], theirIndex)
|
||||
binary.LittleEndian.PutUint64(keepalivePacket[8:], 1) // Nonce
|
||||
keepalivePacket = sendCipher.Encrypt(keepalivePacket, nil, nil) // Empty data means keepalive
|
||||
if _, err := conn.Write(keepalivePacket); err != nil {
|
||||
log.Fatalf("error writing keepalive message: %s", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,4 +123,15 @@ fn main() {
|
|||
assert!(icmp_reply.get_icmp_type() == IcmpTypes::EchoReply && icmp_reply.get_icmp_code() == echo_reply::IcmpCodes::NoCode);
|
||||
assert!(icmp_reply.get_identifier() == 921 && icmp_reply.get_sequence_number() == 438);
|
||||
assert!(icmp_reply.payload() == b"WireGuard");
|
||||
|
||||
let mut keepalive_packet = [0; 32];
|
||||
keepalive_packet[0] = 4; /* Type: Data */
|
||||
keepalive_packet[1] = 0; /* Reserved */
|
||||
keepalive_packet[2] = 0; /* Reserved */
|
||||
keepalive_packet[3] = 0; /* Reserved */
|
||||
LittleEndian::write_u32(&mut keepalive_packet[4..], their_index);
|
||||
LittleEndian::write_u64(&mut keepalive_packet[8..], 1);
|
||||
let empty_payload = [0; 0]; /* Empty payload means keepalive */
|
||||
noise.write_message(&empty_payload, &mut keepalive_packet[16..]).unwrap();
|
||||
socket.send_to(&keepalive_packet, TEST_SERVER).unwrap();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue