lib/security/cc_ipsec.pm

SYNOPSIS

Helpers for the tests in tests/security/cc/ipsec.

ipsec_ip_pair_for_job_id

my ($server_ip, $client_ip) = ipsec_ip_pair_for_job_id($server_job_id);

Return a pair of addresses in the same /24 network. The pair is derived from the job id of the IPsec server. Jobs with consecutive ids get different pairs.

ipsec_peer_ips

my ($server_ip, $client_ip) = ipsec_peer_ips();

Return the addresses of the IPsec server and client.

If SERVER_IP and CLIENT_IP are set, use them. On s390x, all multi-machine guests share one network. Thus a static pair causes address conflicts when more than one cluster runs at the same time (poo#201363). On s390x the pair is derived from the job id of the server, see "ipsec_ip_pair_for_job_id". On the other architectures the function returns the addresses that setup_multimachine sets.

add_ipsec_mm_ip

add_ipsec_mm_ip($ip, $netdev);

Add $ip/24 to $netdev. Before that, do a duplicate address detection with arping. If an other host uses the address, die with a clear message.

wait_ipsec_conn

wait_ipsec_conn($conn_name [, retry => 30] [, die => 1]);

Wait until charon is up and has loaded the connection $conn_name. ipsec start and ipsec restart return before this occurs. With die => 0, return 1 if the connection is loaded, else 0.

upload_ipsec_diagnostics

upload_ipsec_diagnostics();

Collect the IPsec, xfrm and network state, and the strongSwan logs. Upload them. Use this in post_fail_hook, it does not die.

check_ipsec_traffic

my ($ok, $message) = check_ipsec_traffic($conn, $virtual_ip);

Send ping requests from the virtual IP of the client to the server address in the ipip tunnel. Only the CHILD_SA of $conn protects this traffic. Then make sure that the CHILD_SA counted bytes in both directions.

Do not ping the virtual IP itself: it is an address of the client, thus the ping works also without an SA.

run_ipsec_case

my $ok = run_ipsec_case(
    name => 'ESP: aes128-sha512-modp2048!',
    conf => {keyexchange => 'ikev2', ike => 'aes256ctr-sha256-modp2048', esp => 'aes128-sha512-modp2048!'},
    expect => 'pass',
    proposal => qr{ESP:AES_CBC_128/HMAC_SHA2_512_256/},
);

Set the keys in conf in the ikev2suse connection of /etc/ipsec.conf, start strongSwan, bring up the connection and compare the result with expect:

Record the result and the output of ipsec up, then stop strongSwan. Return 1 if the result is as expected, else 0.

gmac_refused_by_kernel

my $refused = gmac_refused_by_kernel($server_log);

$server_log holds the charon log of the server. Return 1 if the server selected the ESP AES-GMAC proposal and the next ESP selection or kernel error in the log is the netlink error ENOSYS (38), that is the kernel refused the algorithm. Newer kernels log it as "Requested AEAD algorithm not found (38)", older kernels as "Function not implemented (38)". Other log lines between the two do not matter. Return 0 in all other cases, for example when the server rejected the proposal because its proposals did not match.