This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "".
The branch, next has been updated discards 008a23fcbc95191f7569df8e0deb4228e32b82cb (commit) discards ca5dce2a7988212c5c409ea5e6c73614e6856536 (commit) discards 7dd6b62bd918a3c9c48b45fa3a8fc4057bba9ee0 (commit) discards 6c49c6e8b2201e41213b5399c9fc1b4203df6612 (commit) discards dbed4b92dd4431c43271167ff8bf84f5e2877ced (commit) discards 3187310d67e8810c67168e004bd9e056ae0dc213 (commit) discards c8b13fd727910b4606d0712c5116006aed1792d8 (commit) discards 67e3173ae6c966c5d722cc89c838126385f77fec (commit) discards 2e59669a8746a54f04b9036ec8c2758f1a4c18c8 (commit) discards e6396aa4d737fdce41c22628f9f77bb5a4ef3d3e (commit) discards 95696c71a245dc045953a7d75dfc209ac1692ffe (commit) discards 7f13493f5b8c41c8a83c65ecc6bb5763b84d4225 (commit) discards af566ae11d48162d21c1e2648fa0b32d189067f8 (commit) discards df537d430d94f85de8d6e1d0643e4c65387cf392 (commit) discards 2d25eca61e25d099017ec2924278dcea6c4b821f (commit) discards 71cfbe6fe938f7351b0c7637f290ae823132c207 (commit) discards 30bf39b9afb2ee5703bac4227effc5808bb337d7 (commit) discards aeb33071432c5d4d3c83f4556199fabdbc540164 (commit) discards f0968cf3a4281cd45f7c490e1cfc84f93d2a37b6 (commit) discards 798182b6930bc70fb759516dd8a3964bcf1812a8 (commit) discards 0ee8b0ec8668734a43b57b3d76f37a1bdddf03fb (commit) discards 196521caf9adb8eea4e0b2c79d6aa2f3240c3944 (commit) discards 60b2c5a0bb2595f7ef5ca3bbc59097674a28ae1d (commit) discards 562059f5d7841f30eab228ac218a46d1c3110010 (commit) discards 14bebe8bac40b2b0f4a00cce4ef9a7031cc1b8cc (commit) discards f0483afab9c4a75210e1bd9a66b37432eafa6e3a (commit) discards dbec145ddcf4a7362785cd15462ac561d8fe7a5b (commit) discards a38cda50644887b62091e35df82501d08afeddfb (commit) discards fe338dbae8bcc7ef4494d687aa75daaa037229f4 (commit) discards 12c027befdddae5c94d3965e80678a28fe6643d2 (commit) discards 37a6847e26c1ad9a20e29ff528a5a56bd460ce34 (commit) discards 6821be78596aee4ef8c5484a6ea67790a667f5de (commit) discards 5ceb481e02ec84af4537eee51b28ebbc7037d115 (commit) discards 6865706a3ddf84793a17385f23097de74be66388 (commit) discards dc0fb9e2e6d6e0ecdd7d131a9f2f491ff3d3f8f2 (commit) discards 275b837ca639d52745004c66c497f85a1fe4fc12 (commit) discards 473789f52ec383ee2caf1124af0866e7c8b81968 (commit) discards abfda4861d5dbcfcd636f82ddbdc140f46d22c58 (commit) discards cc162128ebcda9068c80016d2979780db7c46f0d (commit) discards bd31f839f8d64ca475c88ef075ccc3be4d142027 (commit) discards edccba8e41c67909f2485ec483252dc9193618a6 (commit) discards 10f655cbef0dd7237f2ae49d8b2cd35a963ca1ec (commit) discards 60e950dbd1a26ff18db663b6b9fb5f4fc17c6785 (commit) discards 1973794053d956b90e4fd0cddcb922f2ac29c2e4 (commit) discards 31eac29b5767df7eeb72ce0e099567f05a8093fe (commit) discards 329ad2cc86f87ce96ab8eeabbf113500bce64b50 (commit) discards fce41954cef8512050b829fd726a41584f3216f5 (commit) discards 99733f4463b297fc7913be83cfb2cc7fea372137 (commit) discards b57ea8ad55a879b6ef5ec1a2ae4e4c25fb90a5d3 (commit) discards 5132040a52da2d7d7b4f16648d04d379f2a990ba (commit) discards 1fd68e4cb742c241177d49f8c0ee9d60afba7297 (commit) discards 86bee4260c6d6e8cdb2fb652dfafa9fbc27bd4f1 (commit) discards 6110797199e7e253659352d31011450b9b13410d (commit) discards e78e597cd45d9e6fd5b36b8efa5e046dde5f3190 (commit) discards 656272a80373740140d983213c6336b982633f22 (commit) discards f7e7ba1373522283c313c7ceebce5e8454f43e09 (commit) discards f1bc34659c87405f1b9bf29695aa75d00be0e140 (commit) discards 42117d5a3400b9f0e364eb6bc4670d145afc4dbe (commit) discards d9efed317ef9900ef5a89f5ecf7a71344dbc3e04 (commit) discards 9959f0d04d83eebd9bb0a4520e1cce1626343772 (commit) discards cf495ab4fea270115aaf0f9c6be8e3c6f2ec4524 (commit) discards e89884f30208ad5751c687713e6cad38d573b4f5 (commit) discards cfcd4b990d1825fbedca00fd38cac981dbaa5951 (commit) discards 413813b897c15e430699f9f06b78633cd9f9536f (commit) discards aad1266fd6517118e7f115f7e97d638313c8903b (commit) discards 3214a1a34e3639903c18e4a99346261d9d5d39a0 (commit) discards f97abebd29b5c4c90d24bda7bcfec48f7abcf28a (commit) discards 0c1675e93796897a5d358635697068dc81c1e763 (commit) discards bc2f82e41e517d8c379eb753fd8379479a5e8b7c (commit) discards 6d3ff54693d7e62ac1163a78c8df9cb66496eaf0 (commit) discards 320d1f3195e7aa75e899506392632a7dab72bdac (commit) discards d8f38f6d14ef0e966d06dd8630b75eb4db3f01d6 (commit) discards 77a9d1e16d8a6d35d71aa0f8450c00c98295fb0f (commit) discards a1afe8ff10bcb000ac69fc61eeae1acd14f8e4bd (commit) discards ed17c2117dd80b100182d60f29c74735fd65e85c (commit) discards 605b00a21e1d979a124980ad25bc32539bd00139 (commit) discards 7c8cbb741d3c2b9e4e05ce1296ba9d2690f643f4 (commit) discards 73d26f022e59c6e93f09545470d6e2e67eda6e86 (commit) discards 9f38efb09731b5f03b2eaf787a066620e778127e (commit) via 25bd197e560d88049d8e0b1d296cc74460a04757 (commit) via 020905b66246d905819ca11bc5b7c59ecfd65b43 (commit) via c429651a6bb10b9b385af0c72364c8577b6d41c7 (commit) via 4f5ea1db6464b0fe7f0e293b4a2073dc429844f8 (commit) via 056ac3ba35f5b56ed82303a5b5264a8a39680e33 (commit) via c9bccf19bba3723045b42a6af8e277940dcbebbc (commit) via c59f8f3ed2ca25f4bcba377ad4ceeab7a925b0e9 (commit) via 3e02b93a568c2868010403cffe3abad3b630aeb3 (commit) via 39c4846842c9245bde78a94922bfa68092cf6833 (commit) via 3d51c15b438a506b3051f90b37e4062b414c894e (commit) via 22b39a5c05cf034a02819ec11b1bd8066a3bb035 (commit) via 61c1b98d10d6c56f43dbea4b148c79c3a4f93a79 (commit) via afc3177b0a31866fb94c86bf07d80bf3db38c0a1 (commit) via 2a84a9e1667a712683164e2c58dc4c70c6be6f01 (commit) via c8c9190abb8e36657e4df21bd59956adc94f666d (commit) via 8fde3a28dfe89f1ef46de7787cbd4157bb0f46f3 (commit) via d3d3a149a49ee3b4fc47471394c2d84a8935e537 (commit) via 8745e588ad3b297e29ee89ea1e88af86bc54b490 (commit) via 70c666d8dd8079b02295868e595249b5a55bc4bd (commit) via 6be68162f5ee79c61028183998c0a07def6c214c (commit) via d57b60970a685d17c9d1b056d7114cb49e285a7f (commit) via ad89a906dc6363668bdf1bddaaae7031c6d8e948 (commit) via 5b3b92e776df783a756c493ca757d7ddbd108bb6 (commit) via a82a5d922b8c1f023a68f9e6618e498c8bde01db (commit) via 5056151ea74434572609808b546ab0363b900866 (commit) via 9a66396a86a8f34afe69eff9ae764b54a62968c5 (commit) via da07245508f60344de56a54227271cbf225f4063 (commit) via e49f352b8cc8dd8077999e38799ba5627212ef33 (commit) via 3c3dd1ac11c311d478183667a5ac6df4192ef4ec (commit) via 5dee060187c2dbda51a18e28b3691bfc50bd1882 (commit) via 7adadc917984a3e7d101a8e9d5e4f690780e8c90 (commit) via 85bcdeacd7631d1fa532a67ffdd47d60394a2726 (commit) via 31db23d6ed4116c1fd37bfef5c6e95c952e7d7d0 (commit) via 125fb2967f412934e7162d86630437cfa08c2397 (commit) via 86f1e0fb0cbb938875b273dab3d396ecd8634a17 (commit) via b9946c8372014ddce127cf2c74ef825ab80ff0aa (commit) via 6e651715d36571b884cb4d272f4a91bbc1ba9beb (commit) via 2133fde4a61f46666d365dbecc61da8311299b3b (commit) via 73ae15cdb4bc6b46bc4a81f711a0f5a069ed889b (commit) via e20e7877c6a5062754a1deddbabab7f3d55dff80 (commit) via aafbf4394c9d4d63baa3f750baf6ac19137d6ab2 (commit) via 9d5b473fcb86d61391d519b7cf2fa398017ce468 (commit) via 476b52c41e17940c39368a7bd81149e2780303ac (commit) via e167796e4bcb8c3f19737acb5358b5edabcdfa56 (commit) via 88e3d6b326a4c84f1b5a1e4c099a3a2519efb1f2 (commit) via 83031014c51be27b9b64cf5fda10efc7fa1d3ed1 (commit) via bae7f03986f3c62f86f4d794cd0fa17924b3f424 (commit) via 5d4492900724ac7df931f57416c0d93c05d9d25d (commit) via 75709852a7bc8a9f4856d9b182f6265d6cc098cc (commit) via b5c9093ac785f9b68b123d0e15629609a297bbcb (commit) via b563a8d681c1fa8c208c51bf83f545cfe28f4a7e (commit) via cbba67aab7235a2c78a1a29cd0870498bd5ba897 (commit) via f982a0d5793970f379ddcba78278363208f37e86 (commit) via 91b26ee0ef846979b8a2bfdfb44076a497611d5a (commit) via d4983d155f3172344dd55196b3918fc14b1c5d8b (commit) via b40c6127cb52c6d33719f9ff923b6b8ee7f38f21 (commit) via 41fd88bcac110322424f1418c751707f9b40409c (commit) via fe831783bda53ec4f883cb7f42e585cf37d282db (commit) via d305e9182802c0522c759ec80b55404ada8ac627 (commit) via 705ed6cbd52911ccc439dd43230ac4cf6aee4d5f (commit)
This update added new revisions after undoing existing revisions. That is to say, the old revision is not a strict subset of the new revision. This situation occurs when you --force push a change and generate a repository containing something like this:
* -- * -- B -- O -- O -- O (008a23fcbc95191f7569df8e0deb4228e32b82cb) \ N -- N -- N (25bd197e560d88049d8e0b1d296cc74460a04757)
When this happens we assume that you've already had alert emails for all of the O revisions, and so we here report only the revisions in the N branch from the common base, B.
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- commit 25bd197e560d88049d8e0b1d296cc74460a04757 Author: Maxim Uvarov maxim.uvarov@linaro.org Date: Fri Jun 2 15:58:52 2017 +0300
update API version number from v1.14.0.0 to v1.15.0.0
Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/configure.ac b/configure.ac index 58682564..bea4e1f3 100644 --- a/configure.ac +++ b/configure.ac @@ -3,7 +3,7 @@ AC_PREREQ([2.5]) # Set correct API version ########################################################################## m4_define([odpapi_generation_version], [1]) -m4_define([odpapi_major_version], [14]) +m4_define([odpapi_major_version], [15]) m4_define([odpapi_minor_version], [0]) m4_define([odpapi_point_version], [0]) m4_define([odpapi_version], @@ -39,10 +39,10 @@ AM_SILENT_RULES([yes]) # 3. if interfaces were removed, then use C+1:0:0 ##########################################################################
-ODP_LIBSO_VERSION=114:0:1 +ODP_LIBSO_VERSION=115:0:2 AC_SUBST(ODP_LIBSO_VERSION)
-ODPHELPER_LIBSO_VERSION=112:0:0 +ODPHELPER_LIBSO_VERSION=112:1:0 AC_SUBST(ODPHELPER_LIBSO_VERSION)
# Checks for programs.
commit 020905b66246d905819ca11bc5b7c59ecfd65b43 Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:39 2017 +0300
linux-generic: crypto: add HMAC-SHA-512 authentication support
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 3117f65d..6fc1907d 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -69,6 +69,10 @@ static const odp_crypto_auth_capability_t auth_capa_sha256_hmac[] = { {.digest_len = 16, .key_len = 32, .aad_len = {.min = 0, .max = 0, .inc = 0} }, {.digest_len = 32, .key_len = 32, .aad_len = {.min = 0, .max = 0, .inc = 0} } };
+static const odp_crypto_auth_capability_t auth_capa_sha512_hmac[] = { +{.digest_len = 32, .key_len = 64, .aad_len = {.min = 0, .max = 0, .inc = 0} }, +{.digest_len = 64, .key_len = 64, .aad_len = {.min = 0, .max = 0, .inc = 0} } }; + static const odp_crypto_auth_capability_t auth_capa_aes_gcm[] = { {.digest_len = 16, .key_len = 0, .aad_len = {.min = 8, .max = 12, .inc = 4} } };
@@ -555,7 +559,7 @@ int odp_crypto_capability(odp_crypto_capability_t *capa) capa->auths.bit.md5_hmac = 1; capa->auths.bit.sha1_hmac = 1; capa->auths.bit.sha256_hmac = 1; - capa->auths.bit.sha512_hmac = 0; + capa->auths.bit.sha512_hmac = 1; capa->auths.bit.aes_gcm = 1;
#if ODP_DEPRECATED_API @@ -636,6 +640,10 @@ int odp_crypto_auth_capability(odp_auth_alg_t auth, src = auth_capa_sha256_hmac; num = sizeof(auth_capa_sha256_hmac) / size; break; + case ODP_AUTH_ALG_SHA512_HMAC: + src = auth_capa_sha512_hmac; + num = sizeof(auth_capa_sha512_hmac) / size; + break; case ODP_AUTH_ALG_AES_GCM: src = auth_capa_aes_gcm; num = sizeof(auth_capa_aes_gcm) / size; @@ -761,6 +769,9 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, case ODP_AUTH_ALG_SHA256_HMAC: rc = process_auth_param(session, 32, EVP_sha256()); break; + case ODP_AUTH_ALG_SHA512_HMAC: + rc = process_auth_param(session, 64, EVP_sha512()); + break; #if ODP_DEPRECATED_API case ODP_AUTH_ALG_AES128_GCM: if (param->cipher_alg == ODP_CIPHER_ALG_AES128_GCM)
commit c429651a6bb10b9b385af0c72364c8577b6d41c7 Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:38 2017 +0300
linux-generic: crypto: add SHA-1 authentication support
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 9e5a1190..3117f65d 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -61,6 +61,10 @@ static const odp_crypto_auth_capability_t auth_capa_md5_hmac[] = { {.digest_len = 12, .key_len = 16, .aad_len = {.min = 0, .max = 0, .inc = 0} }, {.digest_len = 16, .key_len = 16, .aad_len = {.min = 0, .max = 0, .inc = 0} } };
+static const odp_crypto_auth_capability_t auth_capa_sha1_hmac[] = { +{.digest_len = 12, .key_len = 20, .aad_len = {.min = 0, .max = 0, .inc = 0} }, +{.digest_len = 20, .key_len = 20, .aad_len = {.min = 0, .max = 0, .inc = 0} } }; + static const odp_crypto_auth_capability_t auth_capa_sha256_hmac[] = { {.digest_len = 16, .key_len = 32, .aad_len = {.min = 0, .max = 0, .inc = 0} }, {.digest_len = 32, .key_len = 32, .aad_len = {.min = 0, .max = 0, .inc = 0} } }; @@ -549,7 +553,7 @@ int odp_crypto_capability(odp_crypto_capability_t *capa)
capa->auths.bit.null = 1; capa->auths.bit.md5_hmac = 1; - capa->auths.bit.sha1_hmac = 0; + capa->auths.bit.sha1_hmac = 1; capa->auths.bit.sha256_hmac = 1; capa->auths.bit.sha512_hmac = 0; capa->auths.bit.aes_gcm = 1; @@ -624,6 +628,10 @@ int odp_crypto_auth_capability(odp_auth_alg_t auth, src = auth_capa_md5_hmac; num = sizeof(auth_capa_md5_hmac) / size; break; + case ODP_AUTH_ALG_SHA1_HMAC: + src = auth_capa_sha1_hmac; + num = sizeof(auth_capa_sha1_hmac) / size; + break; case ODP_AUTH_ALG_SHA256_HMAC: src = auth_capa_sha256_hmac; num = sizeof(auth_capa_sha256_hmac) / size; @@ -741,6 +749,9 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, case ODP_AUTH_ALG_MD5_HMAC: rc = process_auth_param(session, 16, EVP_md5()); break; + case ODP_AUTH_ALG_SHA1_HMAC: + rc = process_auth_param(session, 20, EVP_sha1()); + break; #if ODP_DEPRECATED_API case ODP_AUTH_ALG_SHA256_128: /* Fixed digest tag length with deprecated algo */
commit 4f5ea1db6464b0fe7f0e293b4a2073dc429844f8 Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:37 2017 +0300
validation: crypto: add HMAC-SHA-512 test cases
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/validation/api/crypto/crypto.h b/test/common_plat/validation/api/crypto/crypto.h index 84e67379..dd15b448 100644 --- a/test/common_plat/validation/api/crypto/crypto.h +++ b/test/common_plat/validation/api/crypto/crypto.h @@ -30,7 +30,8 @@ void crypto_test_gen_alg_hmac_sha1(void); void crypto_test_check_alg_hmac_sha1(void); void crypto_test_gen_alg_hmac_sha256(void); void crypto_test_check_alg_hmac_sha256(void); -void crypto_test_alg_hmac_sha512(void); +void crypto_test_gen_alg_hmac_sha512(void); +void crypto_test_check_alg_hmac_sha512(void);
/* test arrays: */ extern odp_testinfo_t crypto_suite[]; diff --git a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c index 6129d82d..ae600e23 100644 --- a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c @@ -32,6 +32,8 @@ static const char *auth_alg_name(odp_auth_alg_t auth) return "ODP_AUTH_ALG_SHA1_HMAC"; case ODP_AUTH_ALG_SHA256_HMAC: return "ODP_AUTH_ALG_SHA256_HMAC"; + case ODP_AUTH_ALG_SHA512_HMAC: + return "ODP_AUTH_ALG_SHA512_HMAC"; case ODP_AUTH_ALG_AES_GCM: return "ODP_AUTH_ALG_AES_GCM"; default: @@ -139,6 +141,9 @@ static void alg_test(odp_crypto_op_t op, if (auth_alg == ODP_AUTH_ALG_SHA256_HMAC && !(capa.auths.bit.sha256_hmac)) rc = -1; + if (auth_alg == ODP_AUTH_ALG_SHA512_HMAC && + !(capa.auths.bit.sha512_hmac)) + rc = -1;
CU_ASSERT(!rc); CU_ASSERT((~capa.auths.all_bits & capa.hw_auths.all_bits) == 0); @@ -1391,9 +1396,106 @@ static int check_alg_hmac_sha512(void) return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA512_HMAC); }
-void crypto_test_alg_hmac_sha512(void) +/* This test verifies the correctness of HMAC_SHA512 digest operation. + * The output check length is truncated to 32 bytes (256 bits) as + * returned by the crypto operation API call. + * Note that hash digest is a one-way operation. + * In addition the test verifies if the implementation can use the + * packet buffer as completion event buffer. + * */ +void crypto_test_gen_alg_hmac_sha512(void) { - printf(" TEST NOT IMPLEMENTED YET "); + odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 }, + auth_key = { .data = NULL, .length = 0 }; + odp_crypto_iv_t iv = { .data = NULL, .length = 0 }; + + unsigned int test_vec_num = (sizeof(hmac_sha512_reference_length) / + sizeof(hmac_sha512_reference_length[0])); + + unsigned int i; + + for (i = 0; i < test_vec_num; i++) { + auth_key.data = hmac_sha512_reference_key[i]; + auth_key.length = sizeof(hmac_sha512_reference_key[i]); + + if (!check_auth_options(ODP_AUTH_ALG_SHA512_HMAC, + auth_key.length, + HMAC_SHA512_256_CHECK_LEN)) + continue; + + alg_test(ODP_CRYPTO_OP_ENCODE, + 0, + ODP_CIPHER_ALG_NULL, + iv, + iv.data, + cipher_key, + ODP_AUTH_ALG_SHA512_HMAC, + auth_key, + NULL, NULL, + NULL, 0, + hmac_sha512_reference_plaintext[i], + hmac_sha512_reference_length[i], + NULL, 0, + hmac_sha512_reference_digest[i], + HMAC_SHA512_256_CHECK_LEN); + } +} + +void crypto_test_check_alg_hmac_sha512(void) +{ + odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 }, + auth_key = { .data = NULL, .length = 0 }; + odp_crypto_iv_t iv = { .data = NULL, .length = 0 }; + uint8_t wrong_digest[HMAC_SHA512_DIGEST_LEN]; + + unsigned int test_vec_num = (sizeof(hmac_sha512_reference_length) / + sizeof(hmac_sha512_reference_length[0])); + + unsigned int i; + + memset(wrong_digest, 0xa5, sizeof(wrong_digest)); + + for (i = 0; i < test_vec_num; i++) { + auth_key.data = hmac_sha512_reference_key[i]; + auth_key.length = sizeof(hmac_sha512_reference_key[i]); + + if (!check_auth_options(ODP_AUTH_ALG_SHA512_HMAC, + auth_key.length, + HMAC_SHA512_256_CHECK_LEN)) + continue; + + alg_test(ODP_CRYPTO_OP_DECODE, + 0, + ODP_CIPHER_ALG_NULL, + iv, + iv.data, + cipher_key, + ODP_AUTH_ALG_SHA512_HMAC, + auth_key, + NULL, NULL, + NULL, 0, + hmac_sha512_reference_plaintext[i], + hmac_sha512_reference_length[i], + NULL, 0, + hmac_sha512_reference_digest[i], + HMAC_SHA512_256_CHECK_LEN); + + alg_test(ODP_CRYPTO_OP_DECODE, + 1, + ODP_CIPHER_ALG_NULL, + iv, + iv.data, + cipher_key, + ODP_AUTH_ALG_SHA512_HMAC, + auth_key, + NULL, NULL, + NULL, 0, + hmac_sha512_reference_plaintext[i], + hmac_sha512_reference_length[i], + NULL, 0, + wrong_digest, + HMAC_SHA512_256_CHECK_LEN); + } }
int crypto_suite_sync_init(void) @@ -1461,7 +1563,9 @@ odp_testinfo_t crypto_suite[] = { check_alg_hmac_sha256), ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_hmac_sha256, check_alg_hmac_sha256), - ODP_TEST_INFO_CONDITIONAL(crypto_test_alg_hmac_sha512, + ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_hmac_sha512, + check_alg_hmac_sha512), + ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_hmac_sha512, check_alg_hmac_sha512), ODP_TEST_INFO_NULL, }; diff --git a/test/common_plat/validation/api/crypto/test_vectors.h b/test/common_plat/validation/api/crypto/test_vectors.h index 1de54964..bd8bf347 100644 --- a/test/common_plat/validation/api/crypto/test_vectors.h +++ b/test/common_plat/validation/api/crypto/test_vectors.h @@ -397,4 +397,54 @@ static uint8_t hmac_sha1_reference_digest[][HMAC_SHA1_DIGEST_LEN] = { 0x11, 0xcd, 0x91, 0xa3, 0x9a, 0xf4 }, };
+static uint8_t hmac_sha512_reference_key[][HMAC_SHA512_KEY_LEN] = { + { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b }, + + /* "Jefe" */ + { 0x4a, 0x65, 0x66, 0x65 }, + + { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa } +}; + +static uint32_t hmac_sha512_reference_length[] = { 8, 28, 50 }; + +static uint8_t +hmac_sha512_reference_plaintext[][HMAC_SHA512_MAX_DATA_LEN] = { + /* "Hi There" */ + { 0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65}, + + /* what do ya want for nothing?*/ + { 0x77, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6f, 0x20, + 0x79, 0x61, 0x20, 0x77, 0x61, 0x6e, 0x74, 0x20, + 0x66, 0x6f, 0x72, 0x20, 0x6e, 0x6f, 0x74, 0x68, + 0x69, 0x6e, 0x67, 0x3f }, + + { 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd } +}; + +static uint8_t hmac_sha512_reference_digest[][HMAC_SHA512_DIGEST_LEN] = { + { 0x87, 0xaa, 0x7c, 0xde, 0xa5, 0xef, 0x61, 0x9d, + 0x4f, 0xf0, 0xb4, 0x24, 0x1a, 0x1d, 0x6c, 0xb0, + 0x23, 0x79, 0xf4, 0xe2, 0xce, 0x4e, 0xc2, 0x78, + 0x7a, 0xd0, 0xb3, 0x05, 0x45, 0xe1, 0x7c, 0xde }, + + { 0x16, 0x4b, 0x7a, 0x7b, 0xfc, 0xf8, 0x19, 0xe2, + 0xe3, 0x95, 0xfb, 0xe7, 0x3b, 0x56, 0xe0, 0xa3, + 0x87, 0xbd, 0x64, 0x22, 0x2e, 0x83, 0x1f, 0xd6, + 0x10, 0x27, 0x0c, 0xd7, 0xea, 0x25, 0x05, 0x54 }, + + { 0xfa, 0x73, 0xb0, 0x08, 0x9d, 0x56, 0xa2, 0x84, + 0xef, 0xb0, 0xf0, 0x75, 0x6c, 0x89, 0x0b, 0xe9, + 0xb1, 0xb5, 0xdb, 0xdd, 0x8e, 0xe8, 0x1a, 0x36, + 0x55, 0xf8, 0x3e, 0x33, 0xb2, 0x27, 0x9d, 0x39 } +}; + #endif diff --git a/test/common_plat/validation/api/crypto/test_vectors_len.h b/test/common_plat/validation/api/crypto/test_vectors_len.h index 5c3ddcee..20a7ddba 100644 --- a/test/common_plat/validation/api/crypto/test_vectors_len.h +++ b/test/common_plat/validation/api/crypto/test_vectors_len.h @@ -41,4 +41,10 @@ #define HMAC_SHA1_DIGEST_LEN 20 #define HMAC_SHA1_96_CHECK_LEN 12
+/* HMAC-SHA512 */ +#define HMAC_SHA512_KEY_LEN 64 +#define HMAC_SHA512_MAX_DATA_LEN 128 +#define HMAC_SHA512_DIGEST_LEN 64 +#define HMAC_SHA512_256_CHECK_LEN 32 + #endif
commit 056ac3ba35f5b56ed82303a5b5264a8a39680e33 Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:36 2017 +0300
validation: crypto: add HMAC-SHA-1 test cases
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/validation/api/crypto/crypto.h b/test/common_plat/validation/api/crypto/crypto.h index 2a491c3c..84e67379 100644 --- a/test/common_plat/validation/api/crypto/crypto.h +++ b/test/common_plat/validation/api/crypto/crypto.h @@ -26,7 +26,8 @@ void crypto_test_dec_alg_aes128_gcm(void); void crypto_test_dec_alg_aes128_gcm_ovr_iv(void); void crypto_test_gen_alg_hmac_md5(void); void crypto_test_check_alg_hmac_md5(void); -void crypto_test_alg_hmac_sha1(void); +void crypto_test_gen_alg_hmac_sha1(void); +void crypto_test_check_alg_hmac_sha1(void); void crypto_test_gen_alg_hmac_sha256(void); void crypto_test_check_alg_hmac_sha256(void); void crypto_test_alg_hmac_sha512(void); diff --git a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c index 4d8f7b54..6129d82d 100644 --- a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c @@ -28,6 +28,8 @@ static const char *auth_alg_name(odp_auth_alg_t auth) return "ODP_AUTH_ALG_NULL"; case ODP_AUTH_ALG_MD5_HMAC: return "ODP_AUTH_ALG_MD5_HMAC"; + case ODP_AUTH_ALG_SHA1_HMAC: + return "ODP_AUTH_ALG_SHA1_HMAC"; case ODP_AUTH_ALG_SHA256_HMAC: return "ODP_AUTH_ALG_SHA256_HMAC"; case ODP_AUTH_ALG_AES_GCM: @@ -131,6 +133,9 @@ static void alg_test(odp_crypto_op_t op, if (auth_alg == ODP_AUTH_ALG_NULL && !(capa.auths.bit.null)) rc = -1; + if (auth_alg == ODP_AUTH_ALG_SHA1_HMAC && + !(capa.auths.bit.sha1_hmac)) + rc = -1; if (auth_alg == ODP_AUTH_ALG_SHA256_HMAC && !(capa.auths.bit.sha256_hmac)) rc = -1; @@ -1167,6 +1172,113 @@ void crypto_test_check_alg_hmac_md5(void) } }
+static int check_alg_hmac_sha1(void) +{ + return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA1_HMAC); +} + +/* This test verifies the correctness of HMAC_SHA1 digest operation. + * The output check length is truncated to 12 bytes (96 bits) as + * returned by the crypto operation API call. + * Note that hash digest is a one-way operation. + * In addition the test verifies if the implementation can use the + * packet buffer as completion event buffer. + * */ +void crypto_test_gen_alg_hmac_sha1(void) +{ + odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 }, + auth_key = { .data = NULL, .length = 0 }; + odp_crypto_iv_t iv = { .data = NULL, .length = 0 }; + + unsigned int test_vec_num = (sizeof(hmac_sha1_reference_length) / + sizeof(hmac_sha1_reference_length[0])); + + unsigned int i; + + for (i = 0; i < test_vec_num; i++) { + auth_key.data = hmac_sha1_reference_key[i]; + auth_key.length = sizeof(hmac_sha1_reference_key[i]); + + if (!check_auth_options(ODP_AUTH_ALG_SHA1_HMAC, + auth_key.length, + HMAC_SHA1_96_CHECK_LEN)) + continue; + + alg_test(ODP_CRYPTO_OP_ENCODE, + 0, + ODP_CIPHER_ALG_NULL, + iv, + iv.data, + cipher_key, + ODP_AUTH_ALG_SHA1_HMAC, + auth_key, + NULL, NULL, + NULL, 0, + hmac_sha1_reference_plaintext[i], + hmac_sha1_reference_length[i], + NULL, 0, + hmac_sha1_reference_digest[i], + HMAC_SHA1_96_CHECK_LEN); + } +} + +void crypto_test_check_alg_hmac_sha1(void) +{ + odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 }, + auth_key = { .data = NULL, .length = 0 }; + odp_crypto_iv_t iv = { .data = NULL, .length = 0 }; + uint8_t wrong_digest[HMAC_SHA1_DIGEST_LEN]; + + unsigned int test_vec_num = (sizeof(hmac_sha1_reference_length) / + sizeof(hmac_sha1_reference_length[0])); + + unsigned int i; + + memset(wrong_digest, 0xa5, sizeof(wrong_digest)); + + for (i = 0; i < test_vec_num; i++) { + auth_key.data = hmac_sha1_reference_key[i]; + auth_key.length = sizeof(hmac_sha1_reference_key[i]); + + if (!check_auth_options(ODP_AUTH_ALG_SHA1_HMAC, + auth_key.length, + HMAC_SHA1_96_CHECK_LEN)) + continue; + + alg_test(ODP_CRYPTO_OP_DECODE, + 0, + ODP_CIPHER_ALG_NULL, + iv, + iv.data, + cipher_key, + ODP_AUTH_ALG_SHA1_HMAC, + auth_key, + NULL, NULL, + NULL, 0, + hmac_sha1_reference_plaintext[i], + hmac_sha1_reference_length[i], + NULL, 0, + hmac_sha1_reference_digest[i], + HMAC_SHA1_96_CHECK_LEN); + + alg_test(ODP_CRYPTO_OP_DECODE, + 1, + ODP_CIPHER_ALG_NULL, + iv, + iv.data, + cipher_key, + ODP_AUTH_ALG_SHA1_HMAC, + auth_key, + NULL, NULL, + NULL, 0, + hmac_sha1_reference_plaintext[i], + hmac_sha1_reference_length[i], + NULL, 0, + wrong_digest, + HMAC_SHA1_96_CHECK_LEN); + } +} + static int check_alg_hmac_sha256(void) { return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA256_HMAC); @@ -1274,16 +1386,6 @@ void crypto_test_check_alg_hmac_sha256(void) } }
-static int check_alg_hmac_sha1(void) -{ - return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA1_HMAC); -} - -void crypto_test_alg_hmac_sha1(void) -{ - printf(" TEST NOT IMPLEMENTED YET "); -} - static int check_alg_hmac_sha512(void) { return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA512_HMAC); @@ -1351,7 +1453,9 @@ odp_testinfo_t crypto_suite[] = { check_alg_hmac_md5), ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_hmac_md5, check_alg_hmac_md5), - ODP_TEST_INFO_CONDITIONAL(crypto_test_alg_hmac_sha1, + ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_hmac_sha1, + check_alg_hmac_sha1), + ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_hmac_sha1, check_alg_hmac_sha1), ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_hmac_sha256, check_alg_hmac_sha256), diff --git a/test/common_plat/validation/api/crypto/test_vectors.h b/test/common_plat/validation/api/crypto/test_vectors.h index 6d568b91..1de54964 100644 --- a/test/common_plat/validation/api/crypto/test_vectors.h +++ b/test/common_plat/validation/api/crypto/test_vectors.h @@ -353,4 +353,48 @@ static uint32_t hmac_sha256_reference_digest_length[] = { 16, 16, 16 };
+static uint8_t hmac_sha1_reference_key[][HMAC_SHA1_KEY_LEN] = { + { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b }, + + /* "Jefe" */ + { 0x4a, 0x65, 0x66, 0x65 }, + + { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, + 0xaa, 0xaa, 0xaa, 0xaa } +}; + +static uint32_t hmac_sha1_reference_length[] = { 8, 28, 50 }; + +static uint8_t +hmac_sha1_reference_plaintext[][HMAC_SHA1_MAX_DATA_LEN] = { + /* "Hi There" */ + { 0x48, 0x69, 0x20, 0x54, 0x68, 0x65, 0x72, 0x65}, + + /* what do ya want for nothing?*/ + { 0x77, 0x68, 0x61, 0x74, 0x20, 0x64, 0x6f, 0x20, + 0x79, 0x61, 0x20, 0x77, 0x61, 0x6e, 0x74, 0x20, + 0x66, 0x6f, 0x72, 0x20, 0x6e, 0x6f, 0x74, 0x68, + 0x69, 0x6e, 0x67, 0x3f }, + + { 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, + 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd } +}; + +static uint8_t hmac_sha1_reference_digest[][HMAC_SHA1_DIGEST_LEN] = { + { 0xb6, 0x17, 0x31, 0x86, 0x55, 0x05, + 0x72, 0x64, 0xe2, 0x8b, 0xc0, 0xb6 }, + + { 0xef, 0xfc, 0xdf, 0x6a, 0xe5, 0xeb, + 0x2f, 0xa2, 0xd2, 0x74, 0x16, 0xd5 }, + + { 0x12, 0x5d, 0x73, 0x42, 0xb9, 0xac, + 0x11, 0xcd, 0x91, 0xa3, 0x9a, 0xf4 }, +}; + #endif diff --git a/test/common_plat/validation/api/crypto/test_vectors_len.h b/test/common_plat/validation/api/crypto/test_vectors_len.h index c1521dd7..5c3ddcee 100644 --- a/test/common_plat/validation/api/crypto/test_vectors_len.h +++ b/test/common_plat/validation/api/crypto/test_vectors_len.h @@ -35,4 +35,10 @@ #define HMAC_SHA256_MAX_DATA_LEN 128 #define HMAC_SHA256_DIGEST_LEN 32
+/* HMAC-SHA1 */ +#define HMAC_SHA1_KEY_LEN 20 +#define HMAC_SHA1_MAX_DATA_LEN 128 +#define HMAC_SHA1_DIGEST_LEN 20 +#define HMAC_SHA1_96_CHECK_LEN 12 + #endif
commit c9bccf19bba3723045b42a6af8e277940dcbebbc Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:35 2017 +0300
validation: crypto: add tests for NULL cipher
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/validation/api/crypto/crypto.h b/test/common_plat/validation/api/crypto/crypto.h index 4d810f62..2a491c3c 100644 --- a/test/common_plat/validation/api/crypto/crypto.h +++ b/test/common_plat/validation/api/crypto/crypto.h @@ -10,6 +10,8 @@ #include "odp_cunit_common.h"
/* test functions: */ +void crypto_test_enc_alg_null(void); +void crypto_test_dec_alg_null(void); void crypto_test_enc_alg_3des_cbc(void); void crypto_test_enc_alg_3des_cbc_ovr_iv(void); void crypto_test_dec_alg_3des_cbc(void); diff --git a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c index 470c5bc5..4d8f7b54 100644 --- a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c @@ -430,6 +430,73 @@ static int check_auth_options(odp_auth_alg_t auth, uint32_t key_len, return 1; }
+static int check_alg_null(void) +{ + return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_NULL); +} + +void crypto_test_enc_alg_null(void) +{ + odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 }, + auth_key = { .data = NULL, .length = 0 }; + odp_crypto_iv_t iv = { .data = NULL, .length = 0}; + unsigned int test_vec_num = (sizeof(null_reference_length) / + sizeof(null_reference_length[0])); + unsigned int i; + + for (i = 0; i < test_vec_num; i++) { + if (!check_cipher_options(ODP_CIPHER_ALG_NULL, + cipher_key.length, iv.length)) + continue; + + alg_test(ODP_CRYPTO_OP_ENCODE, + 0, + ODP_CIPHER_ALG_NULL, + iv, + NULL, + cipher_key, + ODP_AUTH_ALG_NULL, + auth_key, + NULL, NULL, + NULL, 0, + null_reference_plaintext[i], + null_reference_length[i], + null_reference_plaintext[i], + null_reference_length[i], NULL, 0); + } +} + +void crypto_test_dec_alg_null(void) +{ + odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 }, + auth_key = { .data = NULL, .length = 0 }; + odp_crypto_iv_t iv = { .data = NULL, .length = 0 }; + unsigned int test_vec_num = (sizeof(null_reference_length) / + sizeof(null_reference_length[0])); + unsigned int i; + + for (i = 0; i < test_vec_num; i++) { + if (!check_cipher_options(ODP_CIPHER_ALG_NULL, + cipher_key.length, iv.length)) + continue; + + alg_test(ODP_CRYPTO_OP_DECODE, + 0, + ODP_CIPHER_ALG_NULL, + iv, + NULL, + cipher_key, + ODP_AUTH_ALG_NULL, + auth_key, + NULL, NULL, + NULL, 0, + null_reference_plaintext[i], + null_reference_length[i], + null_reference_plaintext[i], + null_reference_length[i], NULL, 0); + } +} + static int check_alg_3des_cbc(void) { return check_alg_support(ODP_CIPHER_ALG_3DES_CBC, ODP_AUTH_ALG_NULL); @@ -1252,6 +1319,10 @@ int crypto_suite_async_init(void) }
odp_testinfo_t crypto_suite[] = { + ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_null, + check_alg_null), + ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_null, + check_alg_null), ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_3des_cbc, check_alg_3des_cbc), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_3des_cbc, diff --git a/test/common_plat/validation/api/crypto/test_vectors.h b/test/common_plat/validation/api/crypto/test_vectors.h index 0d36c249..6d568b91 100644 --- a/test/common_plat/validation/api/crypto/test_vectors.h +++ b/test/common_plat/validation/api/crypto/test_vectors.h @@ -8,6 +8,18 @@ #define _ODP_TEST_CRYPTO_VECTORS_H_
#include "test_vectors_len.h" + +/** length in bytes */ +static uint32_t null_reference_length[] = { 8, 16 }; + +static uint8_t +null_reference_plaintext[][NULL_MAX_DATA_LEN] = { + {0x32, 0x6a, 0x49, 0x4c, 0xd3, 0x3f, 0xe7, 0x56}, + + {0x84, 0x40, 0x1f, 0x78, 0xfe, 0x6c, 0x10, 0x87, 0x6d, 0x8e, 0xa2, 0x30, + 0x94, 0xea, 0x53, 0x09} +}; + /* TDES-CBC reference vectors, according to * "http://csrc.nist.gov/groups/STM/cavp/documents/des/DESMMT.pdf" */ diff --git a/test/common_plat/validation/api/crypto/test_vectors_len.h b/test/common_plat/validation/api/crypto/test_vectors_len.h index 80fd927b..c1521dd7 100644 --- a/test/common_plat/validation/api/crypto/test_vectors_len.h +++ b/test/common_plat/validation/api/crypto/test_vectors_len.h @@ -6,6 +6,9 @@ #ifndef TEST_VECTORS_LEN_ #define TEST_VECTORS_LEN_
+/* NULL */ +#define NULL_MAX_DATA_LEN 16 + /* TDES-CBC */ #define TDES_CBC_KEY_LEN 24 #define TDES_CBC_IV_LEN 8
commit c59f8f3ed2ca25f4bcba377ad4ceeab7a925b0e9 Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:34 2017 +0300
crypto: linux-generic: add capabilities for CIPHER_NULL and AUTH_NULL
There is no point in having separate cases for NULL algorithms. Add capabilities returning 0 key/digest/iv length.
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 32fece30..9e5a1190 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -34,6 +34,9 @@ * * Keep sorted: first by key length, then by IV length */ +static const odp_crypto_cipher_capability_t cipher_capa_null[] = { +{.key_len = 0, .iv_len = 0} }; + static const odp_crypto_cipher_capability_t cipher_capa_des[] = { {.key_len = 24, .iv_len = 8} };
@@ -51,6 +54,9 @@ static const odp_crypto_cipher_capability_t cipher_capa_aes_gcm[] = { * * Keep sorted: first by digest length, then by key length */ +static const odp_crypto_auth_capability_t auth_capa_null[] = { +{.digest_len = 0, .key_len = 0, .aad_len = {.min = 0, .max = 0, .inc = 0} } }; + static const odp_crypto_auth_capability_t auth_capa_md5_hmac[] = { {.digest_len = 12, .key_len = 16, .aad_len = {.min = 0, .max = 0, .inc = 0} }, {.digest_len = 16, .key_len = 16, .aad_len = {.min = 0, .max = 0, .inc = 0} } }; @@ -571,8 +577,8 @@ int odp_crypto_cipher_capability(odp_cipher_alg_t cipher,
switch (cipher) { case ODP_CIPHER_ALG_NULL: - src = NULL; - num = 0; + src = cipher_capa_null; + num = sizeof(cipher_capa_null) / size; break; case ODP_CIPHER_ALG_DES: src = cipher_capa_des; @@ -611,8 +617,8 @@ int odp_crypto_auth_capability(odp_auth_alg_t auth,
switch (auth) { case ODP_AUTH_ALG_NULL: - src = NULL; - num = 0; + src = auth_capa_null; + num = sizeof(auth_capa_null) / size; break; case ODP_AUTH_ALG_MD5_HMAC: src = auth_capa_md5_hmac; diff --git a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c index c89d04f9..470c5bc5 100644 --- a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c @@ -141,13 +141,8 @@ static void alg_test(odp_crypto_op_t op, num = odp_crypto_cipher_capability(cipher_alg, cipher_capa, MAX_ALG_CAPA);
- if (cipher_alg != ODP_CIPHER_ALG_NULL) { - CU_ASSERT(num > 0); - found = 0; - } else { - CU_ASSERT(num == 0); - found = 1; - } + CU_ASSERT(num > 0); + found = 0;
CU_ASSERT(num <= MAX_ALG_CAPA);
@@ -167,13 +162,8 @@ static void alg_test(odp_crypto_op_t op,
num = odp_crypto_auth_capability(auth_alg, auth_capa, MAX_ALG_CAPA);
- if (auth_alg != ODP_AUTH_ALG_NULL) { - CU_ASSERT(num > 0); - found = 0; - } else { - CU_ASSERT(num == 0); - found = 1; - } + CU_ASSERT(num > 0); + found = 0;
CU_ASSERT(num <= MAX_ALG_CAPA);
commit 3e02b93a568c2868010403cffe3abad3b630aeb3 Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:33 2017 +0300
test: odp_crypto: bail out if odp_crypto_session_create failed
If odp_crypto_session_create() failed, there is no point in checking/freeing session, as it might not have been updated.
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/performance/odp_crypto.c b/test/common_plat/performance/odp_crypto.c index 6a58294a..c3dd6d38 100644 --- a/test/common_plat/performance/odp_crypto.c +++ b/test/common_plat/performance/odp_crypto.c @@ -665,34 +665,32 @@ run_measure_one_config(crypto_args_t *cargs, int rc = 0;
if (create_session_from_config(&session, config, cargs)) - rc = -1; - - if (!rc) { - if (cargs->payload_length) { - rc = run_measure_one(cargs, config, &session, - cargs->payload_length, &result); - if (!rc) { - print_result_header(); - print_result(cargs, cargs->payload_length, - config, &result); - } - } else { - unsigned i; + return -1;
+ if (cargs->payload_length) { + rc = run_measure_one(cargs, config, &session, + cargs->payload_length, &result); + if (!rc) { print_result_header(); - for (i = 0; i < num_payloads; i++) { - rc = run_measure_one(cargs, config, &session, - payloads[i], &result); - if (rc) - break; - print_result(cargs, payloads[i], - config, &result); - } + print_result(cargs, cargs->payload_length, + config, &result); + } + } else { + unsigned i; + + print_result_header(); + for (i = 0; i < num_payloads; i++) { + rc = run_measure_one(cargs, config, &session, + payloads[i], &result); + if (rc) + break; + print_result(cargs, payloads[i], + config, &result); } }
- if (session != ODP_CRYPTO_SESSION_INVALID) - odp_crypto_session_destroy(session); + odp_crypto_session_destroy(session); + return rc; }
commit 39c4846842c9245bde78a94922bfa68092cf6833 Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:32 2017 +0300
linux-generic: crypto: NULL session->next pointer on session allocation
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index ea7c7026..32fece30 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -88,8 +88,10 @@ odp_crypto_generic_session_t *alloc_session(void)
odp_spinlock_lock(&global->lock); session = global->free; - if (session) + if (session) { global->free = session->next; + session->next = NULL; + } odp_spinlock_unlock(&global->lock);
return session;
commit 3d51c15b438a506b3051f90b37e4062b414c894e Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:31 2017 +0300
linux-generic: crypto: make en/decryption work across packet segments
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 7ea90fb9..ea7c7026 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -190,14 +190,122 @@ odp_crypto_alg_err_t auth_check(odp_crypto_op_param_t *param, }
static +int internal_encrypt(EVP_CIPHER_CTX *ctx, odp_crypto_op_param_t *param) +{ + odp_packet_t pkt = param->out_pkt; + unsigned in_pos = param->cipher_range.offset; + unsigned out_pos = param->cipher_range.offset; + unsigned in_len = param->cipher_range.length; + uint8_t block[2 * EVP_MAX_BLOCK_LENGTH]; + unsigned block_len = EVP_CIPHER_block_size(EVP_CIPHER_CTX_cipher(ctx)); + int cipher_len; + int ret; + + while (in_len > 0) { + uint32_t seglen = 0; /* GCC */ + uint8_t *insegaddr = odp_packet_offset(pkt, in_pos, + &seglen, NULL); + unsigned inseglen = in_len < seglen ? in_len : seglen; + + /* There should be at least 1 additional block in out buffer */ + if (inseglen > block_len) { + unsigned part = inseglen - block_len; + + EVP_EncryptUpdate(ctx, insegaddr, &cipher_len, + insegaddr, part); + in_pos += part; + in_len -= part; + insegaddr += part; + inseglen -= part; + + out_pos += cipher_len; + } + + /* Use temporal storage */ + if (inseglen > 0) { + unsigned part = inseglen; + + EVP_EncryptUpdate(ctx, block, &cipher_len, + insegaddr, part); + in_pos += part; + in_len -= part; + insegaddr += part; + inseglen -= part; + + odp_packet_copy_from_mem(pkt, out_pos, + cipher_len, block); + out_pos += cipher_len; + } + } + + ret = EVP_EncryptFinal_ex(ctx, block, &cipher_len); + odp_packet_copy_from_mem(pkt, out_pos, cipher_len, block); + + return ret; +} + +static +int internal_decrypt(EVP_CIPHER_CTX *ctx, odp_crypto_op_param_t *param) +{ + odp_packet_t pkt = param->out_pkt; + unsigned in_pos = param->cipher_range.offset; + unsigned out_pos = param->cipher_range.offset; + unsigned in_len = param->cipher_range.length; + uint8_t block[2 * EVP_MAX_BLOCK_LENGTH]; + unsigned block_len = EVP_CIPHER_block_size(EVP_CIPHER_CTX_cipher(ctx)); + int cipher_len; + int ret; + + while (in_len > 0) { + uint32_t seglen = 0; /* GCC */ + uint8_t *insegaddr = odp_packet_offset(pkt, in_pos, + &seglen, NULL); + unsigned inseglen = in_len < seglen ? in_len : seglen; + + /* There should be at least 1 additional block in out buffer */ + if (inseglen > block_len) { + unsigned part = inseglen - block_len; + + EVP_DecryptUpdate(ctx, insegaddr, &cipher_len, + insegaddr, part); + in_pos += part; + in_len -= part; + insegaddr += part; + inseglen -= part; + + out_pos += cipher_len; + } + + /* Use temporal storage */ + if (inseglen > 0) { + unsigned part = inseglen; + + EVP_DecryptUpdate(ctx, block, &cipher_len, + insegaddr, part); + in_pos += part; + in_len -= part; + insegaddr += part; + inseglen -= part; + + odp_packet_copy_from_mem(pkt, out_pos, + cipher_len, block); + out_pos += cipher_len; + } + } + + ret = EVP_DecryptFinal_ex(ctx, block, &cipher_len); + odp_packet_copy_from_mem(pkt, out_pos, cipher_len, block); + + return ret; +} + +static odp_crypto_alg_err_t cipher_encrypt(odp_crypto_op_param_t *param, odp_crypto_generic_session_t *session) { EVP_CIPHER_CTX *ctx; - uint8_t *data = odp_packet_data(param->out_pkt); - uint32_t plain_len = param->cipher_range.length; void *iv_ptr; - int cipher_len = 0; + int ret;
if (param->override_iv_ptr) iv_ptr = param->override_iv_ptr; @@ -206,9 +314,6 @@ odp_crypto_alg_err_t cipher_encrypt(odp_crypto_op_param_t *param, else return ODP_CRYPTO_ALG_ERR_IV_INVALID;
- /* Adjust pointer for beginning of area to cipher/auth */ - data += param->cipher_range.offset; - /* Encrypt it */ ctx = EVP_CIPHER_CTX_new(); EVP_EncryptInit_ex(ctx, session->cipher.evp_cipher, NULL, @@ -216,13 +321,12 @@ odp_crypto_alg_err_t cipher_encrypt(odp_crypto_op_param_t *param, EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); EVP_CIPHER_CTX_set_padding(ctx, 0);
- EVP_EncryptUpdate(ctx, data, &cipher_len, data, plain_len); - - EVP_EncryptFinal_ex(ctx, data + cipher_len, &cipher_len); + ret = internal_encrypt(ctx, param);
EVP_CIPHER_CTX_free(ctx);
- return ODP_CRYPTO_ALG_ERR_NONE; + return ret <= 0 ? ODP_CRYPTO_ALG_ERR_DATA_SIZE : + ODP_CRYPTO_ALG_ERR_NONE; }
static @@ -230,10 +334,8 @@ odp_crypto_alg_err_t cipher_decrypt(odp_crypto_op_param_t *param, odp_crypto_generic_session_t *session) { EVP_CIPHER_CTX *ctx; - uint8_t *data = odp_packet_data(param->out_pkt); - uint32_t cipher_len = param->cipher_range.length; - int plain_len = 0; void *iv_ptr; + int ret;
if (param->override_iv_ptr) iv_ptr = param->override_iv_ptr; @@ -242,9 +344,6 @@ odp_crypto_alg_err_t cipher_decrypt(odp_crypto_op_param_t *param, else return ODP_CRYPTO_ALG_ERR_IV_INVALID;
- /* Adjust pointer for beginning of area to cipher/auth */ - data += param->cipher_range.offset; - /* Decrypt it */ ctx = EVP_CIPHER_CTX_new(); EVP_DecryptInit_ex(ctx, session->cipher.evp_cipher, NULL, @@ -252,13 +351,12 @@ odp_crypto_alg_err_t cipher_decrypt(odp_crypto_op_param_t *param, EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); EVP_CIPHER_CTX_set_padding(ctx, 0);
- EVP_DecryptUpdate(ctx, data, &plain_len, data, cipher_len); - - EVP_DecryptFinal_ex(ctx, data + plain_len, &plain_len); + ret = internal_decrypt(ctx, param);
EVP_CIPHER_CTX_free(ctx);
- return ODP_CRYPTO_ALG_ERR_NONE; + return ret <= 0 ? ODP_CRYPTO_ALG_ERR_DATA_SIZE : + ODP_CRYPTO_ALG_ERR_NONE; }
static int process_cipher_param(odp_crypto_generic_session_t *session, @@ -293,13 +391,12 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, odp_crypto_generic_session_t *session) { EVP_CIPHER_CTX *ctx; - uint8_t *data = odp_packet_data(param->out_pkt); - uint32_t plain_len = param->cipher_range.length; const uint8_t *aad_head = param->aad.ptr; uint32_t aad_len = param->aad.length; void *iv_ptr; - int cipher_len = 0; - uint8_t *tag = data + param->hash_result_offset; + int dummy_len = 0; + uint8_t block[EVP_MAX_MD_SIZE]; + int ret;
if (param->override_iv_ptr) iv_ptr = param->override_iv_ptr; @@ -308,9 +405,6 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, else return ODP_CRYPTO_ALG_ERR_IV_INVALID;
- /* Adjust pointer for beginning of area to cipher/auth */ - data += param->cipher_range.offset; - /* Encrypt it */ ctx = EVP_CIPHER_CTX_new(); EVP_EncryptInit_ex(ctx, session->cipher.evp_cipher, NULL, @@ -322,18 +416,20 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param,
/* Authenticate header data (if any) without encrypting them */ if (aad_len > 0) - EVP_EncryptUpdate(ctx, NULL, &cipher_len, + EVP_EncryptUpdate(ctx, NULL, &dummy_len, aad_head, aad_len);
- EVP_EncryptUpdate(ctx, data, &cipher_len, data, plain_len); + ret = internal_encrypt(ctx, param);
- EVP_EncryptFinal_ex(ctx, data + cipher_len, &cipher_len); EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, - session->p.auth_digest_len, tag); + session->p.auth_digest_len, block); + odp_packet_copy_from_mem(param->out_pkt, param->hash_result_offset, + session->p.auth_digest_len, block);
EVP_CIPHER_CTX_free(ctx);
- return ODP_CRYPTO_ALG_ERR_NONE; + return ret <= 0 ? ODP_CRYPTO_ALG_ERR_DATA_SIZE : + ODP_CRYPTO_ALG_ERR_NONE; }
static @@ -341,13 +437,12 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, odp_crypto_generic_session_t *session) { EVP_CIPHER_CTX *ctx; - uint8_t *data = odp_packet_data(param->out_pkt); - uint32_t cipher_len = param->cipher_range.length; const uint8_t *aad_head = param->aad.ptr; uint32_t aad_len = param->aad.length; - int plain_len = 0; + int dummy_len = 0; void *iv_ptr; - uint8_t *tag = data + param->hash_result_offset; + uint8_t block[EVP_MAX_MD_SIZE]; + int ret;
if (param->override_iv_ptr) iv_ptr = param->override_iv_ptr; @@ -356,9 +451,6 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, else return ODP_CRYPTO_ALG_ERR_IV_INVALID;
- /* Adjust pointer for beginning of area to cipher/auth */ - data += param->cipher_range.offset; - /* Decrypt it */ ctx = EVP_CIPHER_CTX_new(); EVP_DecryptInit_ex(ctx, session->cipher.evp_cipher, NULL, @@ -368,22 +460,22 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); EVP_CIPHER_CTX_set_padding(ctx, 0);
+ odp_packet_copy_to_mem(param->out_pkt, param->hash_result_offset, + session->p.auth_digest_len, block); EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, - session->p.auth_digest_len, tag); + session->p.auth_digest_len, block);
/* Authenticate header data (if any) without encrypting them */ if (aad_len > 0) - EVP_DecryptUpdate(ctx, NULL, &plain_len, + EVP_DecryptUpdate(ctx, NULL, &dummy_len, aad_head, aad_len);
- EVP_DecryptUpdate(ctx, data, &plain_len, data, cipher_len); - - if (EVP_DecryptFinal_ex(ctx, data + plain_len, &plain_len) <= 0) - return ODP_CRYPTO_ALG_ERR_ICV_CHECK; + ret = internal_decrypt(ctx, param);
EVP_CIPHER_CTX_free(ctx);
- return ODP_CRYPTO_ALG_ERR_NONE; + return ret <= 0 ? ODP_CRYPTO_ALG_ERR_ICV_CHECK : + ODP_CRYPTO_ALG_ERR_NONE; }
static int process_aes_gcm_param(odp_crypto_generic_session_t *session,
commit 22b39a5c05cf034a02819ec11b1bd8066a3bb035 Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:30 2017 +0300
linux-generic: crypto: make HMAC work across segmented packets
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 2ba077f9..7ea90fb9 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -112,29 +112,53 @@ null_crypto_routine(odp_crypto_op_param_t *param ODP_UNUSED, }
static +void packet_hmac(odp_crypto_op_param_t *param, + odp_crypto_generic_session_t *session, + uint8_t *hash) +{ + odp_packet_t pkt = param->out_pkt; + uint32_t offset = param->auth_range.offset; + uint32_t len = param->auth_range.length; + HMAC_CTX ctx; + + ODP_ASSERT(offset + len <= odp_packet_len(pkt)); + + /* Hash it */ + HMAC_CTX_init(&ctx); + HMAC_Init_ex(&ctx, + session->auth.key, + session->auth.key_length, + session->auth.evp_md, + NULL); + + while (len > 0) { + uint32_t seglen = 0; /* GCC */ + void *mapaddr = odp_packet_offset(pkt, offset, &seglen, NULL); + uint32_t maclen = len > seglen ? seglen : len; + + HMAC_Update(&ctx, mapaddr, maclen); + offset += maclen; + len -= maclen; + } + + HMAC_Final(&ctx, hash, NULL); + HMAC_CTX_cleanup(&ctx); +} + +static odp_crypto_alg_err_t auth_gen(odp_crypto_op_param_t *param, odp_crypto_generic_session_t *session) { - uint8_t *data = odp_packet_data(param->out_pkt); - uint8_t *icv = data; - uint32_t len = param->auth_range.length; uint8_t hash[EVP_MAX_MD_SIZE];
- /* Adjust pointer for beginning of area to auth */ - data += param->auth_range.offset; - icv += param->hash_result_offset; - /* Hash it */ - HMAC(session->auth.evp_md, - session->auth.key, - session->auth.key_length, - data, - len, - hash, - NULL); + packet_hmac(param, session, hash);
/* Copy to the output location */ - memcpy(icv, hash, session->auth.bytes); + odp_packet_copy_from_mem(param->out_pkt, + param->hash_result_offset, + session->auth.bytes, + hash);
return ODP_CRYPTO_ALG_ERR_NONE; } @@ -143,31 +167,19 @@ static odp_crypto_alg_err_t auth_check(odp_crypto_op_param_t *param, odp_crypto_generic_session_t *session) { - uint8_t *data = odp_packet_data(param->out_pkt); - uint8_t *icv = data; - uint32_t len = param->auth_range.length; uint32_t bytes = session->auth.bytes; uint8_t hash_in[EVP_MAX_MD_SIZE]; uint8_t hash_out[EVP_MAX_MD_SIZE];
- /* Adjust pointer for beginning of area to auth */ - data += param->auth_range.offset; - icv += param->hash_result_offset; - /* Copy current value out and clear it before authentication */ - memset(hash_in, 0, sizeof(hash_in)); - memcpy(hash_in, icv, bytes); - memset(icv, 0, bytes); - memset(hash_out, 0, sizeof(hash_out)); + odp_packet_copy_to_mem(param->out_pkt, param->hash_result_offset, + bytes, hash_in); + + _odp_packet_set_data(param->out_pkt, param->hash_result_offset, + 0, bytes);
/* Hash it */ - HMAC(session->auth.evp_md, - session->auth.key, - session->auth.key_length, - data, - len, - hash_out, - NULL); + packet_hmac(param, session, hash_out);
/* Verify match */ if (0 != memcmp(hash_in, hash_out, bytes))
commit 61c1b98d10d6c56f43dbea4b148c79c3a4f93a79 Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:29 2017 +0300
linux-generic: crypto: merge AES-CBC and 3DES-CBC support
There is now nearly no difference between AES-CBC and 3DES-CBC code. Merge it into generic 'cipher' support, easing adding support for other ciphers in future.
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/include/odp_crypto_internal.h b/platform/linux-generic/include/odp_crypto_internal.h index f4f1948f..c3b70b23 100644 --- a/platform/linux-generic/include/odp_crypto_internal.h +++ b/platform/linux-generic/include/odp_crypto_internal.h @@ -40,18 +40,9 @@ struct odp_crypto_generic_session { struct { /* Copy of session IV data */ uint8_t iv_data[MAX_IV_LEN]; + uint8_t key_data[EVP_MAX_KEY_LENGTH];
- union { - struct { - uint8_t key[EVP_MAX_KEY_LENGTH]; - } des; - struct { - uint8_t key[EVP_MAX_KEY_LENGTH]; - } aes; - struct { - uint8_t key[EVP_MAX_KEY_LENGTH]; - } aes_gcm; - } data; + const EVP_CIPHER *evp_cipher; crypto_func_t func; } cipher;
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index bff712d1..2ba077f9 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -178,8 +178,8 @@ odp_crypto_alg_err_t auth_check(odp_crypto_op_param_t *param, }
static -odp_crypto_alg_err_t aes_encrypt(odp_crypto_op_param_t *param, - odp_crypto_generic_session_t *session) +odp_crypto_alg_err_t cipher_encrypt(odp_crypto_op_param_t *param, + odp_crypto_generic_session_t *session) { EVP_CIPHER_CTX *ctx; uint8_t *data = odp_packet_data(param->out_pkt); @@ -199,8 +199,8 @@ odp_crypto_alg_err_t aes_encrypt(odp_crypto_op_param_t *param,
/* Encrypt it */ ctx = EVP_CIPHER_CTX_new(); - EVP_EncryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, - session->cipher.data.aes.key, NULL); + EVP_EncryptInit_ex(ctx, session->cipher.evp_cipher, NULL, + session->cipher.key_data, NULL); EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); EVP_CIPHER_CTX_set_padding(ctx, 0);
@@ -214,8 +214,8 @@ odp_crypto_alg_err_t aes_encrypt(odp_crypto_op_param_t *param, }
static -odp_crypto_alg_err_t aes_decrypt(odp_crypto_op_param_t *param, - odp_crypto_generic_session_t *session) +odp_crypto_alg_err_t cipher_decrypt(odp_crypto_op_param_t *param, + odp_crypto_generic_session_t *session) { EVP_CIPHER_CTX *ctx; uint8_t *data = odp_packet_data(param->out_pkt); @@ -235,8 +235,8 @@ odp_crypto_alg_err_t aes_decrypt(odp_crypto_op_param_t *param,
/* Decrypt it */ ctx = EVP_CIPHER_CTX_new(); - EVP_DecryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, - session->cipher.data.aes.key, NULL); + EVP_DecryptInit_ex(ctx, session->cipher.evp_cipher, NULL, + session->cipher.key_data, NULL); EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); EVP_CIPHER_CTX_set_padding(ctx, 0);
@@ -249,20 +249,29 @@ odp_crypto_alg_err_t aes_decrypt(odp_crypto_op_param_t *param, return ODP_CRYPTO_ALG_ERR_NONE; }
-static int process_aes_param(odp_crypto_generic_session_t *session) +static int process_cipher_param(odp_crypto_generic_session_t *session, + const EVP_CIPHER *cipher) { - /* Verify IV len is either 0 or 16 */ - if (!((0 == session->p.iv.length) || (16 == session->p.iv.length))) + /* Verify Key len is valid */ + if ((uint32_t)EVP_CIPHER_key_length(cipher) != + session->p.cipher_key.length) return -1;
- memcpy(session->cipher.data.aes.key, session->p.cipher_key.data, + /* Verify IV len is correct */ + if (!((0 == session->p.iv.length) || + ((uint32_t)EVP_CIPHER_iv_length(cipher) == session->p.iv.length))) + return -1; + + session->cipher.evp_cipher = cipher; + + memcpy(session->cipher.key_data, session->p.cipher_key.data, session->p.cipher_key.length);
/* Set function */ if (ODP_CRYPTO_OP_ENCODE == session->p.op) - session->cipher.func = aes_encrypt; + session->cipher.func = cipher_encrypt; else - session->cipher.func = aes_decrypt; + session->cipher.func = cipher_decrypt;
return 0; } @@ -292,8 +301,8 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param,
/* Encrypt it */ ctx = EVP_CIPHER_CTX_new(); - EVP_EncryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, - session->cipher.data.aes_gcm.key, NULL); + EVP_EncryptInit_ex(ctx, session->cipher.evp_cipher, NULL, + session->cipher.key_data, NULL); EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, session->p.iv.length, NULL); EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); @@ -340,8 +349,8 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param,
/* Decrypt it */ ctx = EVP_CIPHER_CTX_new(); - EVP_DecryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, - session->cipher.data.aes_gcm.key, NULL); + EVP_DecryptInit_ex(ctx, session->cipher.evp_cipher, NULL, + session->cipher.key_data, NULL); EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, session->p.iv.length, NULL); EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); @@ -365,15 +374,19 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, return ODP_CRYPTO_ALG_ERR_NONE; }
-static int process_aes_gcm_param(odp_crypto_generic_session_t *session) +static int process_aes_gcm_param(odp_crypto_generic_session_t *session, + const EVP_CIPHER *cipher) { - /* Verify Key len is 16 */ - if (session->p.cipher_key.length != 16) + /* Verify Key len is valid */ + if ((uint32_t)EVP_CIPHER_key_length(cipher) != + session->p.cipher_key.length) return -1;
- memcpy(session->cipher.data.aes_gcm.key, session->p.cipher_key.data, + memcpy(session->cipher.key_data, session->p.cipher_key.data, session->p.cipher_key.length);
+ session->cipher.evp_cipher = cipher; + /* Set function */ if (ODP_CRYPTO_OP_ENCODE == session->p.op) session->cipher.func = aes_gcm_encrypt; @@ -383,96 +396,6 @@ static int process_aes_gcm_param(odp_crypto_generic_session_t *session) return 0; }
-static -odp_crypto_alg_err_t des_encrypt(odp_crypto_op_param_t *param, - odp_crypto_generic_session_t *session) -{ - EVP_CIPHER_CTX *ctx; - uint8_t *data = odp_packet_data(param->out_pkt); - uint32_t plain_len = param->cipher_range.length; - void *iv_ptr; - int cipher_len = 0; - - if (param->override_iv_ptr) - iv_ptr = param->override_iv_ptr; - else if (session->p.iv.data) - iv_ptr = session->cipher.iv_data; - else - return ODP_CRYPTO_ALG_ERR_IV_INVALID; - - /* Adjust pointer for beginning of area to cipher/auth */ - data += param->cipher_range.offset; - - /* Encrypt it */ - ctx = EVP_CIPHER_CTX_new(); - EVP_EncryptInit_ex(ctx, EVP_des_ede3_cbc(), NULL, - session->cipher.data.des.key, NULL); - EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); - EVP_CIPHER_CTX_set_padding(ctx, 0); - - EVP_EncryptUpdate(ctx, data, &cipher_len, data, plain_len); - - EVP_EncryptFinal_ex(ctx, data + cipher_len, &cipher_len); - - EVP_CIPHER_CTX_cleanup(ctx); - - return ODP_CRYPTO_ALG_ERR_NONE; -} - -static -odp_crypto_alg_err_t des_decrypt(odp_crypto_op_param_t *param, - odp_crypto_generic_session_t *session) -{ - EVP_CIPHER_CTX *ctx; - uint8_t *data = odp_packet_data(param->out_pkt); - uint32_t cipher_len = param->cipher_range.length; - int plain_len = 0; - void *iv_ptr; - - if (param->override_iv_ptr) - iv_ptr = param->override_iv_ptr; - else if (session->p.iv.data) - iv_ptr = session->cipher.iv_data; - else - return ODP_CRYPTO_ALG_ERR_IV_INVALID; - - /* Adjust pointer for beginning of area to cipher/auth */ - data += param->cipher_range.offset; - - /* Decrypt it */ - ctx = EVP_CIPHER_CTX_new(); - EVP_DecryptInit_ex(ctx, EVP_des_ede3_cbc(), NULL, - session->cipher.data.des.key, NULL); - EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); - EVP_CIPHER_CTX_set_padding(ctx, 0); - - EVP_DecryptUpdate(ctx, data, &plain_len, data, cipher_len); - - EVP_DecryptFinal_ex(ctx, data + plain_len, &plain_len); - - EVP_CIPHER_CTX_cleanup(ctx); - - return ODP_CRYPTO_ALG_ERR_NONE; -} - -static int process_des_param(odp_crypto_generic_session_t *session) -{ - /* Verify IV len is either 0 or 8 */ - if (!((0 == session->p.iv.length) || (8 == session->p.iv.length))) - return -1; - - memcpy(session->cipher.data.des.key, session->p.cipher_key.data, - session->p.cipher_key.length); - - /* Set function */ - if (ODP_CRYPTO_OP_ENCODE == session->p.op) - session->cipher.func = des_encrypt; - else - session->cipher.func = des_decrypt; - - return 0; -} - static int process_auth_param(odp_crypto_generic_session_t *session, uint32_t key_length, const EVP_MD *evp_md) @@ -656,13 +579,13 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, break; case ODP_CIPHER_ALG_DES: case ODP_CIPHER_ALG_3DES_CBC: - rc = process_des_param(session); + rc = process_cipher_param(session, EVP_des_ede3_cbc()); break; case ODP_CIPHER_ALG_AES_CBC: #if ODP_DEPRECATED_API case ODP_CIPHER_ALG_AES128_CBC: #endif - rc = process_aes_param(session); + rc = process_cipher_param(session, EVP_aes_128_cbc()); break; #if ODP_DEPRECATED_API case ODP_CIPHER_ALG_AES128_GCM: @@ -674,7 +597,7 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, /* AES-GCM requires to do both auth and * cipher at the same time */ if (param->auth_alg == ODP_AUTH_ALG_AES_GCM || aes_gcm) - rc = process_aes_gcm_param(session); + rc = process_aes_gcm_param(session, EVP_aes_128_gcm()); else rc = -1; break;
commit afc3177b0a31866fb94c86bf07d80bf3db38c0a1 Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:28 2017 +0300
linux-generic: crypto: rewrite 3DES-CBC support using EVP functions
Rewrite 3DES-CBC to use generic EVP interface following AES-GCM implementation.
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/include/odp_crypto_internal.h b/platform/linux-generic/include/odp_crypto_internal.h index d6fd0400..f4f1948f 100644 --- a/platform/linux-generic/include/odp_crypto_internal.h +++ b/platform/linux-generic/include/odp_crypto_internal.h @@ -11,7 +11,6 @@ extern "C" { #endif
-#include <openssl/des.h> #include <openssl/evp.h>
#define MAX_IV_LEN 64 @@ -44,9 +43,7 @@ struct odp_crypto_generic_session {
union { struct { - DES_key_schedule ks1; - DES_key_schedule ks2; - DES_key_schedule ks3; + uint8_t key[EVP_MAX_KEY_LENGTH]; } des; struct { uint8_t key[EVP_MAX_KEY_LENGTH]; diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index f503bd98..bff712d1 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -387,10 +387,11 @@ static odp_crypto_alg_err_t des_encrypt(odp_crypto_op_param_t *param, odp_crypto_generic_session_t *session) { + EVP_CIPHER_CTX *ctx; uint8_t *data = odp_packet_data(param->out_pkt); - uint32_t len = param->cipher_range.length; - DES_cblock iv; + uint32_t plain_len = param->cipher_range.length; void *iv_ptr; + int cipher_len = 0;
if (param->override_iv_ptr) iv_ptr = param->override_iv_ptr; @@ -399,24 +400,21 @@ odp_crypto_alg_err_t des_encrypt(odp_crypto_op_param_t *param, else return ODP_CRYPTO_ALG_ERR_IV_INVALID;
- /* - * Create a copy of the IV. The DES library modifies IV - * and if we are processing packets on parallel threads - * we could get corruption. - */ - memcpy(iv, iv_ptr, sizeof(iv)); - - /* Adjust pointer for beginning of area to cipher */ + /* Adjust pointer for beginning of area to cipher/auth */ data += param->cipher_range.offset; + /* Encrypt it */ - DES_ede3_cbc_encrypt(data, - data, - len, - &session->cipher.data.des.ks1, - &session->cipher.data.des.ks2, - &session->cipher.data.des.ks3, - &iv, - 1); + ctx = EVP_CIPHER_CTX_new(); + EVP_EncryptInit_ex(ctx, EVP_des_ede3_cbc(), NULL, + session->cipher.data.des.key, NULL); + EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); + EVP_CIPHER_CTX_set_padding(ctx, 0); + + EVP_EncryptUpdate(ctx, data, &cipher_len, data, plain_len); + + EVP_EncryptFinal_ex(ctx, data + cipher_len, &cipher_len); + + EVP_CIPHER_CTX_cleanup(ctx);
return ODP_CRYPTO_ALG_ERR_NONE; } @@ -425,9 +423,10 @@ static odp_crypto_alg_err_t des_decrypt(odp_crypto_op_param_t *param, odp_crypto_generic_session_t *session) { + EVP_CIPHER_CTX *ctx; uint8_t *data = odp_packet_data(param->out_pkt); - uint32_t len = param->cipher_range.length; - DES_cblock iv; + uint32_t cipher_len = param->cipher_range.length; + int plain_len = 0; void *iv_ptr;
if (param->override_iv_ptr) @@ -437,25 +436,21 @@ odp_crypto_alg_err_t des_decrypt(odp_crypto_op_param_t *param, else return ODP_CRYPTO_ALG_ERR_IV_INVALID;
- /* - * Create a copy of the IV. The DES library modifies IV - * and if we are processing packets on parallel threads - * we could get corruption. - */ - memcpy(iv, iv_ptr, sizeof(iv)); - - /* Adjust pointer for beginning of area to cipher */ + /* Adjust pointer for beginning of area to cipher/auth */ data += param->cipher_range.offset;
/* Decrypt it */ - DES_ede3_cbc_encrypt(data, - data, - len, - &session->cipher.data.des.ks1, - &session->cipher.data.des.ks2, - &session->cipher.data.des.ks3, - &iv, - 0); + ctx = EVP_CIPHER_CTX_new(); + EVP_DecryptInit_ex(ctx, EVP_des_ede3_cbc(), NULL, + session->cipher.data.des.key, NULL); + EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); + EVP_CIPHER_CTX_set_padding(ctx, 0); + + EVP_DecryptUpdate(ctx, data, &plain_len, data, cipher_len); + + EVP_DecryptFinal_ex(ctx, data + plain_len, &plain_len); + + EVP_CIPHER_CTX_cleanup(ctx);
return ODP_CRYPTO_ALG_ERR_NONE; } @@ -466,20 +461,15 @@ static int process_des_param(odp_crypto_generic_session_t *session) if (!((0 == session->p.iv.length) || (8 == session->p.iv.length))) return -1;
+ memcpy(session->cipher.data.des.key, session->p.cipher_key.data, + session->p.cipher_key.length); + /* Set function */ if (ODP_CRYPTO_OP_ENCODE == session->p.op) session->cipher.func = des_encrypt; else session->cipher.func = des_decrypt;
- /* Convert keys */ - DES_set_key((DES_cblock *)&session->p.cipher_key.data[0], - &session->cipher.data.des.ks1); - DES_set_key((DES_cblock *)&session->p.cipher_key.data[8], - &session->cipher.data.des.ks2); - DES_set_key((DES_cblock *)&session->p.cipher_key.data[16], - &session->cipher.data.des.ks3); - return 0; }
commit 2a84a9e1667a712683164e2c58dc4c70c6be6f01 Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:27 2017 +0300
linux-generic: crypto: rewrite AES-CBC support using EVP functions
Rewrite AES-CBC to use generic EVP interface following AES-GCM implementation.
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/include/odp_crypto_internal.h b/platform/linux-generic/include/odp_crypto_internal.h index d1020dba..d6fd0400 100644 --- a/platform/linux-generic/include/odp_crypto_internal.h +++ b/platform/linux-generic/include/odp_crypto_internal.h @@ -12,7 +12,6 @@ extern "C" { #endif
#include <openssl/des.h> -#include <openssl/aes.h> #include <openssl/evp.h>
#define MAX_IV_LEN 64 @@ -50,7 +49,7 @@ struct odp_crypto_generic_session { DES_key_schedule ks3; } des; struct { - AES_KEY key; + uint8_t key[EVP_MAX_KEY_LENGTH]; } aes; struct { uint8_t key[EVP_MAX_KEY_LENGTH]; diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index ff3f1ac7..f503bd98 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -181,10 +181,11 @@ static odp_crypto_alg_err_t aes_encrypt(odp_crypto_op_param_t *param, odp_crypto_generic_session_t *session) { + EVP_CIPHER_CTX *ctx; uint8_t *data = odp_packet_data(param->out_pkt); - uint32_t len = param->cipher_range.length; - unsigned char iv_enc[AES_BLOCK_SIZE]; + uint32_t plain_len = param->cipher_range.length; void *iv_ptr; + int cipher_len = 0;
if (param->override_iv_ptr) iv_ptr = param->override_iv_ptr; @@ -193,18 +194,21 @@ odp_crypto_alg_err_t aes_encrypt(odp_crypto_op_param_t *param, else return ODP_CRYPTO_ALG_ERR_IV_INVALID;
- /* - * Create a copy of the IV. The DES library modifies IV - * and if we are processing packets on parallel threads - * we could get corruption. - */ - memcpy(iv_enc, iv_ptr, AES_BLOCK_SIZE); - - /* Adjust pointer for beginning of area to cipher */ + /* Adjust pointer for beginning of area to cipher/auth */ data += param->cipher_range.offset; + /* Encrypt it */ - AES_cbc_encrypt(data, data, len, &session->cipher.data.aes.key, - iv_enc, AES_ENCRYPT); + ctx = EVP_CIPHER_CTX_new(); + EVP_EncryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, + session->cipher.data.aes.key, NULL); + EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); + EVP_CIPHER_CTX_set_padding(ctx, 0); + + EVP_EncryptUpdate(ctx, data, &cipher_len, data, plain_len); + + EVP_EncryptFinal_ex(ctx, data + cipher_len, &cipher_len); + + EVP_CIPHER_CTX_free(ctx);
return ODP_CRYPTO_ALG_ERR_NONE; } @@ -213,9 +217,10 @@ static odp_crypto_alg_err_t aes_decrypt(odp_crypto_op_param_t *param, odp_crypto_generic_session_t *session) { + EVP_CIPHER_CTX *ctx; uint8_t *data = odp_packet_data(param->out_pkt); - uint32_t len = param->cipher_range.length; - unsigned char iv_enc[AES_BLOCK_SIZE]; + uint32_t cipher_len = param->cipher_range.length; + int plain_len = 0; void *iv_ptr;
if (param->override_iv_ptr) @@ -225,18 +230,21 @@ odp_crypto_alg_err_t aes_decrypt(odp_crypto_op_param_t *param, else return ODP_CRYPTO_ALG_ERR_IV_INVALID;
- /* - * Create a copy of the IV. The DES library modifies IV - * and if we are processing packets on parallel threads - * we could get corruption. - */ - memcpy(iv_enc, iv_ptr, AES_BLOCK_SIZE); - - /* Adjust pointer for beginning of area to cipher */ + /* Adjust pointer for beginning of area to cipher/auth */ data += param->cipher_range.offset; - /* Encrypt it */ - AES_cbc_encrypt(data, data, len, &session->cipher.data.aes.key, - iv_enc, AES_DECRYPT); + + /* Decrypt it */ + ctx = EVP_CIPHER_CTX_new(); + EVP_DecryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, + session->cipher.data.aes.key, NULL); + EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); + EVP_CIPHER_CTX_set_padding(ctx, 0); + + EVP_DecryptUpdate(ctx, data, &plain_len, data, cipher_len); + + EVP_DecryptFinal_ex(ctx, data + plain_len, &plain_len); + + EVP_CIPHER_CTX_free(ctx);
return ODP_CRYPTO_ALG_ERR_NONE; } @@ -247,16 +255,14 @@ static int process_aes_param(odp_crypto_generic_session_t *session) if (!((0 == session->p.iv.length) || (16 == session->p.iv.length))) return -1;
+ memcpy(session->cipher.data.aes.key, session->p.cipher_key.data, + session->p.cipher_key.length); + /* Set function */ - if (ODP_CRYPTO_OP_ENCODE == session->p.op) { + if (ODP_CRYPTO_OP_ENCODE == session->p.op) session->cipher.func = aes_encrypt; - AES_set_encrypt_key(session->p.cipher_key.data, 128, - &session->cipher.data.aes.key); - } else { + else session->cipher.func = aes_decrypt; - AES_set_decrypt_key(session->p.cipher_key.data, 128, - &session->cipher.data.aes.key); - }
return 0; }
commit c8c9190abb8e36657e4df21bd59956adc94f666d Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:26 2017 +0300
linux-generic: crypto: explicitly disable padding for AES-GCM
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 3deec7de..ff3f1ac7 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -291,6 +291,7 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, session->p.iv.length, NULL); EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); + EVP_CIPHER_CTX_set_padding(ctx, 0);
/* Authenticate header data (if any) without encrypting them */ if (aad_len > 0) @@ -338,6 +339,7 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, session->p.iv.length, NULL); EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr); + EVP_CIPHER_CTX_set_padding(ctx, 0);
EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, session->p.auth_digest_len, tag);
commit 8fde3a28dfe89f1ef46de7787cbd4157bb0f46f3 Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:25 2017 +0300
linux-generic: crypto: make AES-GCM thread safe
Using single context for all operations is not thread safe: multiple threads can access the same context in parallel, affecting its internal state. Make AES-GCM functions use local context for en/decryption operations.
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/include/odp_crypto_internal.h b/platform/linux-generic/include/odp_crypto_internal.h index 515cefaa..d1020dba 100644 --- a/platform/linux-generic/include/odp_crypto_internal.h +++ b/platform/linux-generic/include/odp_crypto_internal.h @@ -53,7 +53,7 @@ struct odp_crypto_generic_session { AES_KEY key; } aes; struct { - EVP_CIPHER_CTX *ctx; + uint8_t key[EVP_MAX_KEY_LENGTH]; } aes_gcm; } data; crypto_func_t func; diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 3f298485..3deec7de 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -265,11 +265,13 @@ static odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, odp_crypto_generic_session_t *session) { + EVP_CIPHER_CTX *ctx; uint8_t *data = odp_packet_data(param->out_pkt); uint32_t plain_len = param->cipher_range.length; const uint8_t *aad_head = param->aad.ptr; uint32_t aad_len = param->aad.length; void *iv_ptr; + int cipher_len = 0; uint8_t *tag = data + param->hash_result_offset;
if (param->override_iv_ptr) @@ -280,12 +282,14 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, return ODP_CRYPTO_ALG_ERR_IV_INVALID;
/* Adjust pointer for beginning of area to cipher/auth */ - uint8_t *plaindata = data + param->cipher_range.offset; + data += param->cipher_range.offset;
/* Encrypt it */ - EVP_CIPHER_CTX *ctx = session->cipher.data.aes_gcm.ctx; - int cipher_len = 0; - + ctx = EVP_CIPHER_CTX_new(); + EVP_EncryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, + session->cipher.data.aes_gcm.key, NULL); + EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, + session->p.iv.length, NULL); EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr);
/* Authenticate header data (if any) without encrypting them */ @@ -293,13 +297,14 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, EVP_EncryptUpdate(ctx, NULL, &cipher_len, aad_head, aad_len);
- EVP_EncryptUpdate(ctx, plaindata, &cipher_len, - plaindata, plain_len); + EVP_EncryptUpdate(ctx, data, &cipher_len, data, plain_len);
- EVP_EncryptFinal_ex(ctx, plaindata + cipher_len, &cipher_len); + EVP_EncryptFinal_ex(ctx, data + cipher_len, &cipher_len); EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, session->p.auth_digest_len, tag);
+ EVP_CIPHER_CTX_free(ctx); + return ODP_CRYPTO_ALG_ERR_NONE; }
@@ -307,10 +312,12 @@ static odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, odp_crypto_generic_session_t *session) { + EVP_CIPHER_CTX *ctx; uint8_t *data = odp_packet_data(param->out_pkt); uint32_t cipher_len = param->cipher_range.length; const uint8_t *aad_head = param->aad.ptr; uint32_t aad_len = param->aad.length; + int plain_len = 0; void *iv_ptr; uint8_t *tag = data + param->hash_result_offset;
@@ -322,11 +329,14 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, return ODP_CRYPTO_ALG_ERR_IV_INVALID;
/* Adjust pointer for beginning of area to cipher/auth */ - uint8_t *cipherdata = data + param->cipher_range.offset; - /* Encrypt it */ - EVP_CIPHER_CTX *ctx = session->cipher.data.aes_gcm.ctx; - int plain_len = 0; + data += param->cipher_range.offset;
+ /* Decrypt it */ + ctx = EVP_CIPHER_CTX_new(); + EVP_DecryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, + session->cipher.data.aes_gcm.key, NULL); + EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, + session->p.iv.length, NULL); EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr);
EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, @@ -337,12 +347,13 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, EVP_DecryptUpdate(ctx, NULL, &plain_len, aad_head, aad_len);
- EVP_DecryptUpdate(ctx, cipherdata, &plain_len, - cipherdata, cipher_len); + EVP_DecryptUpdate(ctx, data, &plain_len, data, cipher_len);
- if (EVP_DecryptFinal_ex(ctx, cipherdata + plain_len, &plain_len) <= 0) + if (EVP_DecryptFinal_ex(ctx, data + plain_len, &plain_len) <= 0) return ODP_CRYPTO_ALG_ERR_ICV_CHECK;
+ EVP_CIPHER_CTX_free(ctx); + return ODP_CRYPTO_ALG_ERR_NONE; }
@@ -352,27 +363,14 @@ static int process_aes_gcm_param(odp_crypto_generic_session_t *session) if (session->p.cipher_key.length != 16) return -1;
- /* Set function */ - EVP_CIPHER_CTX *ctx = - session->cipher.data.aes_gcm.ctx = EVP_CIPHER_CTX_new(); + memcpy(session->cipher.data.aes_gcm.key, session->p.cipher_key.data, + session->p.cipher_key.length);
- if (ODP_CRYPTO_OP_ENCODE == session->p.op) { + /* Set function */ + if (ODP_CRYPTO_OP_ENCODE == session->p.op) session->cipher.func = aes_gcm_encrypt; - EVP_EncryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL); - } else { + else session->cipher.func = aes_gcm_decrypt; - EVP_DecryptInit_ex(ctx, EVP_aes_128_gcm(), NULL, NULL, NULL); - } - - EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, - session->p.iv.length, NULL); - if (ODP_CRYPTO_OP_ENCODE == session->p.op) { - EVP_EncryptInit_ex(ctx, NULL, NULL, - session->p.cipher_key.data, NULL); - } else { - EVP_DecryptInit_ex(ctx, NULL, NULL, - session->p.cipher_key.data, NULL); - }
return 0; } @@ -635,17 +633,16 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, /* Copy parameters */ session->p = *param;
- /* Copy IV data */ - if (session->p.iv.data) { - if (session->p.iv.length > MAX_IV_LEN) { - ODP_DBG("Maximum IV length exceeded\n"); - free_session(session); - return -1; - } + if (session->p.iv.length > MAX_IV_LEN) { + ODP_DBG("Maximum IV length exceeded\n"); + free_session(session); + return -1; + }
+ /* Copy IV data */ + if (session->p.iv.data) memcpy(session->cipher.iv_data, session->p.iv.data, session->p.iv.length); - }
/* Derive order */ if (ODP_CRYPTO_OP_ENCODE == param->op) @@ -757,15 +754,8 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, int odp_crypto_session_destroy(odp_crypto_session_t session) { odp_crypto_generic_session_t *generic; - int aes_gcm = 0;
generic = (odp_crypto_generic_session_t *)(intptr_t)session; -#if ODP_DEPRECATED_API - if (generic->p.cipher_alg == ODP_CIPHER_ALG_AES128_GCM) - aes_gcm = 1; -#endif - if (generic->p.cipher_alg == ODP_CIPHER_ALG_AES_GCM || aes_gcm) - EVP_CIPHER_CTX_free(generic->cipher.data.aes_gcm.ctx); memset(generic, 0, sizeof(*generic)); free_session(generic); return 0;
commit d3d3a149a49ee3b4fc47471394c2d84a8935e537 Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:24 2017 +0300
linux-generic: crypto: remote extra memcpy in AES-GCM
There is no need to memcpy IV if it gets passed to EVP functions.
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 352cfa53..3f298485 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -269,7 +269,6 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, uint32_t plain_len = param->cipher_range.length; const uint8_t *aad_head = param->aad.ptr; uint32_t aad_len = param->aad.length; - unsigned char iv_enc[AES_BLOCK_SIZE]; void *iv_ptr; uint8_t *tag = data + param->hash_result_offset;
@@ -280,13 +279,6 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, else return ODP_CRYPTO_ALG_ERR_IV_INVALID;
- /* - * Create a copy of the IV. The DES library modifies IV - * and if we are processing packets on parallel threads - * we could get corruption. - */ - memcpy(iv_enc, iv_ptr, AES_BLOCK_SIZE); - /* Adjust pointer for beginning of area to cipher/auth */ uint8_t *plaindata = data + param->cipher_range.offset;
@@ -294,7 +286,7 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, EVP_CIPHER_CTX *ctx = session->cipher.data.aes_gcm.ctx; int cipher_len = 0;
- EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv_enc); + EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr);
/* Authenticate header data (if any) without encrypting them */ if (aad_len > 0) @@ -319,7 +311,6 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, uint32_t cipher_len = param->cipher_range.length; const uint8_t *aad_head = param->aad.ptr; uint32_t aad_len = param->aad.length; - unsigned char iv_enc[AES_BLOCK_SIZE]; void *iv_ptr; uint8_t *tag = data + param->hash_result_offset;
@@ -330,20 +321,13 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, else return ODP_CRYPTO_ALG_ERR_IV_INVALID;
- /* - * Create a copy of the IV. The DES library modifies IV - * and if we are processing packets on parallel threads - * we could get corruption. - */ - memcpy(iv_enc, iv_ptr, AES_BLOCK_SIZE); - /* Adjust pointer for beginning of area to cipher/auth */ uint8_t *cipherdata = data + param->cipher_range.offset; /* Encrypt it */ EVP_CIPHER_CTX *ctx = session->cipher.data.aes_gcm.ctx; int plain_len = 0;
- EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv_enc); + EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv_ptr);
EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, session->p.auth_digest_len, tag);
commit 8745e588ad3b297e29ee89ea1e88af86bc54b490 Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:23 2017 +0300
linux-generic: crypto: update AES-GCM support to reflect aad and auth_digest_len
Make AES-GCM use recently introduced aad and auth_digest_len fields.
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 91ef05ae..352cfa53 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -267,10 +267,8 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, { uint8_t *data = odp_packet_data(param->out_pkt); uint32_t plain_len = param->cipher_range.length; - uint8_t *aad_head = data + param->auth_range.offset; - uint8_t *aad_tail = data + param->cipher_range.offset + - param->cipher_range.length; - uint32_t auth_len = param->auth_range.length; + const uint8_t *aad_head = param->aad.ptr; + uint32_t aad_len = param->aad.length; unsigned char iv_enc[AES_BLOCK_SIZE]; void *iv_ptr; uint8_t *tag = data + param->hash_result_offset; @@ -282,12 +280,6 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, else return ODP_CRYPTO_ALG_ERR_IV_INVALID;
- /* All cipher data must be part of the authentication */ - if (param->auth_range.offset > param->cipher_range.offset || - param->auth_range.offset + auth_len < - param->cipher_range.offset + plain_len) - return ODP_CRYPTO_ALG_ERR_DATA_SIZE; - /* * Create a copy of the IV. The DES library modifies IV * and if we are processing packets on parallel threads @@ -305,23 +297,16 @@ odp_crypto_alg_err_t aes_gcm_encrypt(odp_crypto_op_param_t *param, EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv_enc);
/* Authenticate header data (if any) without encrypting them */ - if (aad_head < plaindata) { + if (aad_len > 0) EVP_EncryptUpdate(ctx, NULL, &cipher_len, - aad_head, plaindata - aad_head); - } + aad_head, aad_len);
EVP_EncryptUpdate(ctx, plaindata, &cipher_len, plaindata, plain_len); - cipher_len = plain_len; - - /* Authenticate footer data (if any) without encrypting them */ - if (aad_head + auth_len > plaindata + plain_len) { - EVP_EncryptUpdate(ctx, NULL, NULL, aad_tail, - auth_len - (aad_tail - aad_head)); - }
EVP_EncryptFinal_ex(ctx, plaindata + cipher_len, &cipher_len); - EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, 16, tag); + EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, + session->p.auth_digest_len, tag);
return ODP_CRYPTO_ALG_ERR_NONE; } @@ -332,10 +317,8 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, { uint8_t *data = odp_packet_data(param->out_pkt); uint32_t cipher_len = param->cipher_range.length; - uint8_t *aad_head = data + param->auth_range.offset; - uint8_t *aad_tail = data + param->cipher_range.offset + - param->cipher_range.length; - uint32_t auth_len = param->auth_range.length; + const uint8_t *aad_head = param->aad.ptr; + uint32_t aad_len = param->aad.length; unsigned char iv_enc[AES_BLOCK_SIZE]; void *iv_ptr; uint8_t *tag = data + param->hash_result_offset; @@ -347,12 +330,6 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, else return ODP_CRYPTO_ALG_ERR_IV_INVALID;
- /* All cipher data must be part of the authentication */ - if (param->auth_range.offset > param->cipher_range.offset || - param->auth_range.offset + auth_len < - param->cipher_range.offset + cipher_len) - return ODP_CRYPTO_ALG_ERR_DATA_SIZE; - /* * Create a copy of the IV. The DES library modifies IV * and if we are processing packets on parallel threads @@ -368,25 +345,18 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param,
EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv_enc);
- EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, 16, tag); + EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, + session->p.auth_digest_len, tag);
/* Authenticate header data (if any) without encrypting them */ - if (aad_head < cipherdata) { + if (aad_len > 0) EVP_DecryptUpdate(ctx, NULL, &plain_len, - aad_head, cipherdata - aad_head); - } + aad_head, aad_len);
EVP_DecryptUpdate(ctx, cipherdata, &plain_len, cipherdata, cipher_len); - plain_len = cipher_len; - - /* Authenticate footer data (if any) without encrypting them */ - if (aad_head + auth_len > cipherdata + cipher_len) { - EVP_DecryptUpdate(ctx, NULL, NULL, aad_tail, - auth_len - (aad_tail - aad_head)); - }
- if (EVP_DecryptFinal_ex(ctx, cipherdata + cipher_len, &plain_len) <= 0) + if (EVP_DecryptFinal_ex(ctx, cipherdata + plain_len, &plain_len) <= 0) return ODP_CRYPTO_ALG_ERR_ICV_CHECK;
return ODP_CRYPTO_ALG_ERR_NONE; @@ -770,6 +740,8 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, case ODP_AUTH_ALG_AES128_GCM: if (param->cipher_alg == ODP_CIPHER_ALG_AES128_GCM) aes_gcm = 1; + /* Fixed digest tag length with deprecated algo */ + session->p.auth_digest_len = 16; /* Fallthrough */ #endif case ODP_AUTH_ALG_AES_GCM:
commit 70c666d8dd8079b02295868e595249b5a55bc4bd Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:22 2017 +0300
linux-generic: crypto: add SHA* capabilities for full length digests
In addition to truncated digests (used by IPsec) add full-length capabilities to SHA* algos.
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 472ee310..91ef05ae 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -52,10 +52,12 @@ static const odp_crypto_cipher_capability_t cipher_capa_aes_gcm[] = { * Keep sorted: first by digest length, then by key length */ static const odp_crypto_auth_capability_t auth_capa_md5_hmac[] = { -{.digest_len = 12, .key_len = 16, .aad_len = {.min = 0, .max = 0, .inc = 0} } }; +{.digest_len = 12, .key_len = 16, .aad_len = {.min = 0, .max = 0, .inc = 0} }, +{.digest_len = 16, .key_len = 16, .aad_len = {.min = 0, .max = 0, .inc = 0} } };
static const odp_crypto_auth_capability_t auth_capa_sha256_hmac[] = { -{.digest_len = 16, .key_len = 32, .aad_len = {.min = 0, .max = 0, .inc = 0} } }; +{.digest_len = 16, .key_len = 32, .aad_len = {.min = 0, .max = 0, .inc = 0} }, +{.digest_len = 32, .key_len = 32, .aad_len = {.min = 0, .max = 0, .inc = 0} } };
static const odp_crypto_auth_capability_t auth_capa_aes_gcm[] = { {.digest_len = 16, .key_len = 0, .aad_len = {.min = 8, .max = 12, .inc = 4} } };
commit 6be68162f5ee79c61028183998c0a07def6c214c Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:21 2017 +0300
linux-generic: crypto: use auth_digest_len when calculating HMACs
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index a993542f..472ee310 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -522,7 +522,6 @@ static int process_des_param(odp_crypto_generic_session_t *session) }
static int process_auth_param(odp_crypto_generic_session_t *session, - uint32_t bits, uint32_t key_length, const EVP_MD *evp_md) { @@ -535,7 +534,9 @@ static int process_auth_param(odp_crypto_generic_session_t *session, session->auth.evp_md = evp_md;
/* Number of valid bytes */ - session->auth.bytes = bits / 8; + session->auth.bytes = session->p.auth_digest_len; + if (session->auth.bytes < (unsigned)EVP_MD_size(evp_md) / 2) + return -1;
/* Convert keys */ session->auth.key_length = key_length; @@ -745,17 +746,23 @@ odp_crypto_session_create(odp_crypto_session_param_t *param, session->auth.func = null_crypto_routine; rc = 0; break; - case ODP_AUTH_ALG_MD5_HMAC: #if ODP_DEPRECATED_API case ODP_AUTH_ALG_MD5_96: + /* Fixed digest tag length with deprecated algo */ + session->p.auth_digest_len = 96 / 8; + /* Fallthrough */ #endif - rc = process_auth_param(session, 96, 16, EVP_md5()); + case ODP_AUTH_ALG_MD5_HMAC: + rc = process_auth_param(session, 16, EVP_md5()); break; - case ODP_AUTH_ALG_SHA256_HMAC: #if ODP_DEPRECATED_API case ODP_AUTH_ALG_SHA256_128: + /* Fixed digest tag length with deprecated algo */ + session->p.auth_digest_len = 128 / 8; + /* Fallthrough */ #endif - rc = process_auth_param(session, 128, 32, EVP_sha256()); + case ODP_AUTH_ALG_SHA256_HMAC: + rc = process_auth_param(session, 32, EVP_sha256()); break; #if ODP_DEPRECATED_API case ODP_AUTH_ALG_AES128_GCM:
commit d57b60970a685d17c9d1b056d7114cb49e285a7f Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:20 2017 +0300
example: ipsec: set auth_digest_len
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/example/ipsec/odp_ipsec_cache.c b/example/ipsec/odp_ipsec_cache.c index b2a91c24..dba0ea0a 100644 --- a/example/ipsec/odp_ipsec_cache.c +++ b/example/ipsec/odp_ipsec_cache.c @@ -100,6 +100,7 @@ int create_ipsec_cache_entry(sa_db_entry_t *cipher_sa, params.auth_alg = auth_sa->alg.u.auth; params.auth_key.data = auth_sa->key.data; params.auth_key.length = auth_sa->key.length; + params.auth_digest_len = auth_sa->icv_len; mode = auth_sa->mode; } else { params.auth_alg = ODP_AUTH_ALG_NULL;
commit ad89a906dc6363668bdf1bddaaae7031c6d8e948 Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:19 2017 +0300
test: odp_crypto: update performance test to set auth_digest_length
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/performance/odp_crypto.c b/test/common_plat/performance/odp_crypto.c index b3857973..6a58294a 100644 --- a/test/common_plat/performance/odp_crypto.c +++ b/test/common_plat/performance/odp_crypto.c @@ -50,7 +50,6 @@ static uint8_t test_key24[24] = { 0x01, 0x02, 0x03, 0x04, 0x05, typedef struct { const char *name; /**< Algorithm name */ odp_crypto_session_param_t session; /**< Prefilled crypto session params */ - unsigned int hash_adjust; /**< Size of hash */ } crypto_alg_config_t;
/** @@ -209,9 +208,9 @@ static crypto_alg_config_t algs_config[] = { .auth_key = { .data = test_key16, .length = sizeof(test_key16) - } + }, + .auth_digest_len = 12, }, - .hash_adjust = 12 }, { .name = "null-hmac-md5-96", @@ -221,9 +220,9 @@ static crypto_alg_config_t algs_config[] = { .auth_key = { .data = test_key16, .length = sizeof(test_key16) - } + }, + .auth_digest_len = 12, }, - .hash_adjust = 12 }, };
@@ -578,7 +577,7 @@ run_measure_one(crypto_args_t *cargs, mem = odp_packet_data(params.out_pkt); print_mem("Immediately encrypted packet", mem, payload_length + - config->hash_adjust); + config->session.auth_digest_len); } if (!cargs->in_place) { if (cargs->reuse_packet) { @@ -611,7 +610,8 @@ run_measure_one(crypto_args_t *cargs, print_mem("Receieved encrypted packet", mem, payload_length + - config->hash_adjust); + config-> + session.auth_digest_len); } if (cargs->reuse_packet) { params.pkt = out_pkt;
commit 5b3b92e776df783a756c493ca757d7ddbd108bb6 Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:18 2017 +0300
validation: crypto: explicitly pass AAD to crypto subsystem
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c index 3d09e374..c89d04f9 100644 --- a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c @@ -74,6 +74,8 @@ static void alg_test(odp_crypto_op_t op, odp_crypto_key_t auth_key, odp_packet_data_range_t *cipher_range, odp_packet_data_range_t *auth_range, + uint8_t *aad, + uint32_t aad_len, const uint8_t *plaintext, unsigned int plaintext_len, const uint8_t *ciphertext, @@ -240,6 +242,9 @@ static void alg_test(odp_crypto_op_t op, if (op_iv_ptr) op_params.override_iv_ptr = op_iv_ptr;
+ op_params.aad.ptr = aad; + op_params.aad.length = aad_len; + op_params.hash_result_offset = plaintext_len; if (0 != digest_len) { memcpy(data_addr + op_params.hash_result_offset, @@ -472,6 +477,7 @@ void crypto_test_enc_alg_3des_cbc(void) ODP_AUTH_ALG_NULL, auth_key, NULL, NULL, + NULL, 0, tdes_cbc_reference_plaintext[i], tdes_cbc_reference_length[i], tdes_cbc_reference_ciphertext[i], @@ -508,6 +514,7 @@ void crypto_test_enc_alg_3des_cbc_ovr_iv(void) ODP_AUTH_ALG_NULL, auth_key, NULL, NULL, + NULL, 0, tdes_cbc_reference_plaintext[i], tdes_cbc_reference_length[i], tdes_cbc_reference_ciphertext[i], @@ -548,6 +555,7 @@ void crypto_test_dec_alg_3des_cbc(void) ODP_AUTH_ALG_NULL, auth_key, NULL, NULL, + NULL, 0, tdes_cbc_reference_ciphertext[i], tdes_cbc_reference_length[i], tdes_cbc_reference_plaintext[i], @@ -586,6 +594,7 @@ void crypto_test_dec_alg_3des_cbc_ovr_iv(void) ODP_AUTH_ALG_NULL, auth_key, NULL, NULL, + NULL, 0, tdes_cbc_reference_ciphertext[i], tdes_cbc_reference_length[i], tdes_cbc_reference_plaintext[i], @@ -634,7 +643,9 @@ void crypto_test_enc_alg_aes128_gcm(void) ODP_AUTH_ALG_AES_GCM, auth_key, &aes128_gcm_cipher_range[i], - &aes128_gcm_auth_range[i], + &aes128_gcm_cipher_range[i], + aes128_gcm_reference_aad[i], + aes128_gcm_reference_aad_length[i], aes128_gcm_reference_plaintext[i], aes128_gcm_reference_length[i], aes128_gcm_reference_ciphertext[i], @@ -679,7 +690,9 @@ void crypto_test_enc_alg_aes128_gcm_ovr_iv(void) ODP_AUTH_ALG_AES_GCM, auth_key, &aes128_gcm_cipher_range[i], - &aes128_gcm_auth_range[i], + &aes128_gcm_cipher_range[i], + aes128_gcm_reference_aad[i], + aes128_gcm_reference_aad_length[i], aes128_gcm_reference_plaintext[i], aes128_gcm_reference_length[i], aes128_gcm_reference_ciphertext[i], @@ -730,10 +743,11 @@ void crypto_test_dec_alg_aes128_gcm(void) ODP_AUTH_ALG_AES_GCM, auth_key, &aes128_gcm_cipher_range[i], - &aes128_gcm_auth_range[i], + &aes128_gcm_cipher_range[i], + aes128_gcm_reference_aad[i], + aes128_gcm_reference_aad_length[i], aes128_gcm_reference_ciphertext[i], - aes128_gcm_reference_length[i] + - aes128_gcm_reference_tag_length[i], + aes128_gcm_reference_length[i], aes128_gcm_reference_plaintext[i], aes128_gcm_reference_length[i], aes128_gcm_reference_ciphertext[i] + @@ -749,10 +763,11 @@ void crypto_test_dec_alg_aes128_gcm(void) ODP_AUTH_ALG_AES_GCM, auth_key, &aes128_gcm_cipher_range[i], - &aes128_gcm_auth_range[i], + &aes128_gcm_cipher_range[i], + aes128_gcm_reference_aad[i], + aes128_gcm_reference_aad_length[i], aes128_gcm_reference_ciphertext[i], - aes128_gcm_reference_length[i] + - aes128_gcm_reference_tag_length[i], + aes128_gcm_reference_length[i], aes128_gcm_reference_plaintext[i], aes128_gcm_reference_length[i], wrong_digest, @@ -798,10 +813,11 @@ void crypto_test_dec_alg_aes128_gcm_ovr_iv(void) ODP_AUTH_ALG_AES_GCM, auth_key, &aes128_gcm_cipher_range[i], - &aes128_gcm_auth_range[i], + &aes128_gcm_cipher_range[i], + aes128_gcm_reference_aad[i], + aes128_gcm_reference_aad_length[i], aes128_gcm_reference_ciphertext[i], - aes128_gcm_reference_length[i] + - aes128_gcm_reference_tag_length[i], + aes128_gcm_reference_length[i], aes128_gcm_reference_plaintext[i], aes128_gcm_reference_length[i], aes128_gcm_reference_ciphertext[i] + @@ -817,10 +833,11 @@ void crypto_test_dec_alg_aes128_gcm_ovr_iv(void) ODP_AUTH_ALG_AES_GCM, auth_key, &aes128_gcm_cipher_range[i], - &aes128_gcm_auth_range[i], + &aes128_gcm_cipher_range[i], + aes128_gcm_reference_aad[i], + aes128_gcm_reference_aad_length[i], aes128_gcm_reference_ciphertext[i], - aes128_gcm_reference_length[i] + - aes128_gcm_reference_tag_length[i], + aes128_gcm_reference_length[i], aes128_gcm_reference_plaintext[i], aes128_gcm_reference_length[i], wrong_digest, @@ -865,6 +882,7 @@ void crypto_test_enc_alg_aes128_cbc(void) ODP_AUTH_ALG_NULL, auth_key, NULL, NULL, + NULL, 0, aes128_cbc_reference_plaintext[i], aes128_cbc_reference_length[i], aes128_cbc_reference_ciphertext[i], @@ -901,6 +919,7 @@ void crypto_test_enc_alg_aes128_cbc_ovr_iv(void) ODP_AUTH_ALG_NULL, auth_key, NULL, NULL, + NULL, 0, aes128_cbc_reference_plaintext[i], aes128_cbc_reference_length[i], aes128_cbc_reference_ciphertext[i], @@ -941,6 +960,7 @@ void crypto_test_dec_alg_aes128_cbc(void) ODP_AUTH_ALG_NULL, auth_key, NULL, NULL, + NULL, 0, aes128_cbc_reference_ciphertext[i], aes128_cbc_reference_length[i], aes128_cbc_reference_plaintext[i], @@ -979,6 +999,7 @@ void crypto_test_dec_alg_aes128_cbc_ovr_iv(void) ODP_AUTH_ALG_NULL, auth_key, NULL, NULL, + NULL, 0, aes128_cbc_reference_ciphertext[i], aes128_cbc_reference_length[i], aes128_cbc_reference_plaintext[i], @@ -1025,6 +1046,7 @@ void crypto_test_gen_alg_hmac_md5(void) ODP_AUTH_ALG_MD5_HMAC, auth_key, NULL, NULL, + NULL, 0, hmac_md5_reference_plaintext[i], hmac_md5_reference_length[i], NULL, 0, @@ -1063,6 +1085,7 @@ void crypto_test_check_alg_hmac_md5(void) ODP_AUTH_ALG_MD5_HMAC, auth_key, NULL, NULL, + NULL, 0, hmac_md5_reference_plaintext[i], hmac_md5_reference_length[i], NULL, 0, @@ -1078,6 +1101,7 @@ void crypto_test_check_alg_hmac_md5(void) ODP_AUTH_ALG_MD5_HMAC, auth_key, NULL, NULL, + NULL, 0, hmac_md5_reference_plaintext[i], hmac_md5_reference_length[i], NULL, 0, @@ -1127,6 +1151,7 @@ void crypto_test_gen_alg_hmac_sha256(void) ODP_AUTH_ALG_SHA256_HMAC, auth_key, NULL, NULL, + NULL, 0, hmac_sha256_reference_plaintext[i], hmac_sha256_reference_length[i], NULL, 0, @@ -1167,6 +1192,7 @@ void crypto_test_check_alg_hmac_sha256(void) ODP_AUTH_ALG_SHA256_HMAC, auth_key, NULL, NULL, + NULL, 0, hmac_sha256_reference_plaintext[i], hmac_sha256_reference_length[i], NULL, 0, @@ -1182,6 +1208,7 @@ void crypto_test_check_alg_hmac_sha256(void) ODP_AUTH_ALG_SHA256_HMAC, auth_key, NULL, NULL, + NULL, 0, hmac_sha256_reference_plaintext[i], hmac_sha256_reference_length[i], NULL, 0, diff --git a/test/common_plat/validation/api/crypto/test_vectors.h b/test/common_plat/validation/api/crypto/test_vectors.h index defbda45..0d36c249 100644 --- a/test/common_plat/validation/api/crypto/test_vectors.h +++ b/test/common_plat/validation/api/crypto/test_vectors.h @@ -137,31 +137,31 @@ static uint8_t aes128_gcm_reference_iv[][AES128_GCM_IV_LEN] = { 0xa2, 0xfc, 0xa1, 0xa3 } };
-static uint32_t aes128_gcm_reference_length[] = { 84, 72, 72, 40}; +static uint32_t aes128_gcm_reference_length[] = { 72, 64, 64, 28};
static uint32_t aes128_gcm_reference_tag_length[] = { 16, 16, 16, 16};
+static uint32_t aes128_gcm_reference_aad_length[] = { 12, 8, 8, 12}; + static odp_packet_data_range_t aes128_gcm_cipher_range[] = { - { .offset = 12, .length = 72 }, - { .offset = 8, .length = 64 }, - { .offset = 8, .length = 64 }, - { .offset = 12, .length = 28 }, + { .offset = 0, .length = 72 }, + { .offset = 0, .length = 64 }, + { .offset = 0, .length = 64 }, + { .offset = 0, .length = 28 }, };
-static odp_packet_data_range_t aes128_gcm_auth_range[] = { - { .offset = 0, .length = 84 }, - { .offset = 0, .length = 72 }, - { .offset = 0, .length = 72 }, - { .offset = 0, .length = 40 }, +static uint8_t aes128_gcm_reference_aad[][AES128_GCM_MAX_DATA_LEN] = { + { 0x00, 0x00, 0x43, 0x21, 0x87, 0x65, 0x43, 0x21, + 0x00, 0x00, 0x00, 0x00, }, + { 0x00, 0x00, 0xa5, 0xf8, 0x00, 0x00, 0x00, 0x0a, }, + { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }, + { 0x42, 0xf6, 0x7e, 0x3f, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, }, };
static uint8_t aes128_gcm_reference_plaintext[][AES128_GCM_MAX_DATA_LEN] = { - { /* Aad */ - 0x00, 0x00, 0x43, 0x21, 0x87, 0x65, 0x43, 0x21, - 0x00, 0x00, 0x00, 0x00, - /* Plain */ - 0x45, 0x00, 0x00, 0x48, 0x69, 0x9a, 0x00, 0x00, + { 0x45, 0x00, 0x00, 0x48, 0x69, 0x9a, 0x00, 0x00, 0x80, 0x11, 0x4d, 0xb7, 0xc0, 0xa8, 0x01, 0x02, 0xc0, 0xa8, 0x01, 0x01, 0x0a, 0x9b, 0xf1, 0x56, 0x38, 0xd3, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, @@ -171,10 +171,7 @@ aes128_gcm_reference_plaintext[][AES128_GCM_MAX_DATA_LEN] = { 0x63, 0x69, 0x74, 0x79, 0x02, 0x64, 0x6b, 0x00, 0x00, 0x21, 0x00, 0x01, 0x01, 0x02, 0x02, 0x01 },
- { /* Aad */ - 0x00, 0x00, 0xa5, 0xf8, 0x00, 0x00, 0x00, 0x0a, - /* Plain */ - 0x45, 0x00, 0x00, 0x3e, 0x69, 0x8f, 0x00, 0x00, + { 0x45, 0x00, 0x00, 0x3e, 0x69, 0x8f, 0x00, 0x00, 0x80, 0x11, 0x4d, 0xcc, 0xc0, 0xa8, 0x01, 0x02, 0xc0, 0xa8, 0x01, 0x01, 0x0a, 0x98, 0x00, 0x35, 0x00, 0x2a, 0x23, 0x43, 0xb2, 0xd0, 0x01, 0x00, @@ -183,10 +180,7 @@ aes128_gcm_reference_plaintext[][AES128_GCM_MAX_DATA_LEN] = { 0x65, 0x72, 0x63, 0x69, 0x74, 0x79, 0x02, 0x64, 0x6b, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01 },
- { /* Aad */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - /* Plain */ - 0x45, 0x00, 0x00, 0x3c, 0x99, 0xc5, 0x00, 0x00, + { 0x45, 0x00, 0x00, 0x3c, 0x99, 0xc5, 0x00, 0x00, 0x80, 0x01, 0xcb, 0x7a, 0x40, 0x67, 0x93, 0x18, 0x01, 0x01, 0x01, 0x01, 0x08, 0x00, 0x07, 0x5c, 0x02, 0x00, 0x44, 0x00, 0x61, 0x62, 0x63, 0x64, @@ -195,11 +189,7 @@ aes128_gcm_reference_plaintext[][AES128_GCM_MAX_DATA_LEN] = { 0x75, 0x76, 0x77, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x01, 0x02, 0x02, 0x01 },
- { /* Aad */ - 0x42, 0xf6, 0x7e, 0x3f, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, - /* Plain */ - 0x45, 0x00, 0x00, 0x1c, 0x42, 0xa2, 0x00, 0x00, + { 0x45, 0x00, 0x00, 0x1c, 0x42, 0xa2, 0x00, 0x00, 0x80, 0x01, 0x44, 0x1f, 0x40, 0x67, 0x93, 0xb6, 0xe0, 0x00, 0x00, 0x02, 0x0a, 0x00, 0xf5, 0xff, 0x01, 0x02, 0x02, 0x01 } @@ -207,10 +197,7 @@ aes128_gcm_reference_plaintext[][AES128_GCM_MAX_DATA_LEN] = {
static uint8_t aes128_gcm_reference_ciphertext[][AES128_GCM_MAX_DATA_LEN] = { - { /* Aad */ - 0x00, 0x00, 0x43, 0x21, 0x87, 0x65, 0x43, 0x21, - 0x00, 0x00, 0x00, 0x00, - /* Plain */ + { /* Plain */ 0xfe, 0xcf, 0x53, 0x7e, 0x72, 0x9d, 0x5b, 0x07, 0xdc, 0x30, 0xdf, 0x52, 0x8d, 0xd2, 0x2b, 0x76, 0x8d, 0x1b, 0x98, 0x73, 0x66, 0x96, 0xa6, 0xfd, @@ -224,9 +211,7 @@ aes128_gcm_reference_ciphertext[][AES128_GCM_MAX_DATA_LEN] = { 0x45, 0x90, 0x18, 0x14, 0x8f, 0x6c, 0xbe, 0x72, 0x2f, 0xd0, 0x47, 0x96, 0x56, 0x2d, 0xfd, 0xb4 },
- { /* Aad */ - 0x00, 0x00, 0xa5, 0xf8, 0x00, 0x00, 0x00, 0x0a, - /* Plain */ + { /* Plain */ 0xde, 0xb2, 0x2c, 0xd9, 0xb0, 0x7c, 0x72, 0xc1, 0x6e, 0x3a, 0x65, 0xbe, 0xeb, 0x8d, 0xf3, 0x04, 0xa5, 0xa5, 0x89, 0x7d, 0x33, 0xae, 0x53, 0x0f, @@ -238,9 +223,8 @@ aes128_gcm_reference_ciphertext[][AES128_GCM_MAX_DATA_LEN] = { /* Digest */ 0x83, 0xb7, 0x0d, 0x3a, 0xa8, 0xbc, 0x6e, 0xe4, 0xc3, 0x09, 0xe9, 0xd8, 0x5a, 0x41, 0xad, 0x4a }, - { /* Aad */ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, - /* Plain */ + + { /* Plain */ 0x46, 0x88, 0xda, 0xf2, 0xf9, 0x73, 0xa3, 0x92, 0x73, 0x29, 0x09, 0xc3, 0x31, 0xd5, 0x6d, 0x60, 0xf6, 0x94, 0xab, 0xaa, 0x41, 0x4b, 0x5e, 0x7f, @@ -253,10 +237,7 @@ aes128_gcm_reference_ciphertext[][AES128_GCM_MAX_DATA_LEN] = { 0xf8, 0x21, 0xd4, 0x96, 0xee, 0xb0, 0x96, 0xe9, 0x8a, 0xd2, 0xb6, 0x9e, 0x47, 0x99, 0xc7, 0x1d },
- { /* Aad */ - 0x42, 0xf6, 0x7e, 0x3f, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, - /* Plain */ + { /* Plain */ 0xfb, 0xa2, 0xca, 0x84, 0x5e, 0x5d, 0xf9, 0xf0, 0xf2, 0x2c, 0x3e, 0x6e, 0x86, 0xdd, 0x83, 0x1e, 0x1f, 0xc6, 0x57, 0x92, 0xcd, 0x1a, 0xf9, 0x13,
commit a82a5d922b8c1f023a68f9e6618e498c8bde01db Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Thu Jun 1 12:03:17 2017 +0300
validation: crypto: explicitly pass auth_digest_len to crypto subsystem
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c index bfc9da3c..3d09e374 100644 --- a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c @@ -201,6 +201,7 @@ static void alg_test(odp_crypto_op_t op, ses_params.cipher_key = cipher_key; ses_params.iv = ses_iv; ses_params.auth_key = auth_key; + ses_params.auth_digest_len = digest_len;
rc = odp_crypto_session_create(&ses_params, &session, &status); CU_ASSERT_FATAL(!rc); @@ -620,7 +621,8 @@ void crypto_test_enc_alg_aes128_gcm(void) cipher_key.length, iv.length)) continue; if (!check_auth_options(ODP_AUTH_ALG_AES_GCM, - auth_key.length, AES128_GCM_CHECK_LEN)) + auth_key.length, + aes128_gcm_reference_tag_length[i])) continue;
alg_test(ODP_CRYPTO_OP_ENCODE, @@ -639,7 +641,7 @@ void crypto_test_enc_alg_aes128_gcm(void) aes128_gcm_reference_length[i], aes128_gcm_reference_ciphertext[i] + aes128_gcm_reference_length[i], - AES128_GCM_CHECK_LEN); + aes128_gcm_reference_tag_length[i]); } }
@@ -664,7 +666,8 @@ void crypto_test_enc_alg_aes128_gcm_ovr_iv(void) cipher_key.length, iv.length)) continue; if (!check_auth_options(ODP_AUTH_ALG_AES_GCM, - auth_key.length, AES128_GCM_CHECK_LEN)) + auth_key.length, + aes128_gcm_reference_tag_length[i])) continue;
alg_test(ODP_CRYPTO_OP_ENCODE, @@ -683,7 +686,7 @@ void crypto_test_enc_alg_aes128_gcm_ovr_iv(void) aes128_gcm_reference_length[i], aes128_gcm_reference_ciphertext[i] + aes128_gcm_reference_length[i], - AES128_GCM_CHECK_LEN); + aes128_gcm_reference_tag_length[i]); } }
@@ -714,7 +717,8 @@ void crypto_test_dec_alg_aes128_gcm(void) cipher_key.length, iv.length)) continue; if (!check_auth_options(ODP_AUTH_ALG_AES_GCM, - auth_key.length, AES128_GCM_CHECK_LEN)) + auth_key.length, + aes128_gcm_reference_tag_length[i])) continue;
alg_test(ODP_CRYPTO_OP_DECODE, @@ -728,12 +732,13 @@ void crypto_test_dec_alg_aes128_gcm(void) &aes128_gcm_cipher_range[i], &aes128_gcm_auth_range[i], aes128_gcm_reference_ciphertext[i], - aes128_gcm_reference_length[i] + AES128_GCM_CHECK_LEN, + aes128_gcm_reference_length[i] + + aes128_gcm_reference_tag_length[i], aes128_gcm_reference_plaintext[i], aes128_gcm_reference_length[i], aes128_gcm_reference_ciphertext[i] + aes128_gcm_reference_length[i], - AES128_GCM_CHECK_LEN); + aes128_gcm_reference_tag_length[i]);
alg_test(ODP_CRYPTO_OP_DECODE, 1, @@ -746,11 +751,12 @@ void crypto_test_dec_alg_aes128_gcm(void) &aes128_gcm_cipher_range[i], &aes128_gcm_auth_range[i], aes128_gcm_reference_ciphertext[i], - aes128_gcm_reference_length[i] + AES128_GCM_CHECK_LEN, + aes128_gcm_reference_length[i] + + aes128_gcm_reference_tag_length[i], aes128_gcm_reference_plaintext[i], aes128_gcm_reference_length[i], wrong_digest, - AES128_GCM_CHECK_LEN); + aes128_gcm_reference_tag_length[i]); } }
@@ -779,7 +785,8 @@ void crypto_test_dec_alg_aes128_gcm_ovr_iv(void) cipher_key.length, iv.length)) continue; if (!check_auth_options(ODP_AUTH_ALG_AES_GCM, - auth_key.length, AES128_GCM_CHECK_LEN)) + auth_key.length, + aes128_gcm_reference_tag_length[i])) continue;
alg_test(ODP_CRYPTO_OP_DECODE, @@ -793,12 +800,13 @@ void crypto_test_dec_alg_aes128_gcm_ovr_iv(void) &aes128_gcm_cipher_range[i], &aes128_gcm_auth_range[i], aes128_gcm_reference_ciphertext[i], - aes128_gcm_reference_length[i] + AES128_GCM_CHECK_LEN, + aes128_gcm_reference_length[i] + + aes128_gcm_reference_tag_length[i], aes128_gcm_reference_plaintext[i], aes128_gcm_reference_length[i], aes128_gcm_reference_ciphertext[i] + aes128_gcm_reference_length[i], - AES128_GCM_CHECK_LEN); + aes128_gcm_reference_tag_length[i]);
alg_test(ODP_CRYPTO_OP_DECODE, 1, @@ -811,11 +819,12 @@ void crypto_test_dec_alg_aes128_gcm_ovr_iv(void) &aes128_gcm_cipher_range[i], &aes128_gcm_auth_range[i], aes128_gcm_reference_ciphertext[i], - aes128_gcm_reference_length[i] + AES128_GCM_CHECK_LEN, + aes128_gcm_reference_length[i] + + aes128_gcm_reference_tag_length[i], aes128_gcm_reference_plaintext[i], aes128_gcm_reference_length[i], wrong_digest, - AES128_GCM_CHECK_LEN); + aes128_gcm_reference_tag_length[i]); } }
@@ -1004,7 +1013,7 @@ void crypto_test_gen_alg_hmac_md5(void) auth_key.length = sizeof(hmac_md5_reference_key[i]);
if (!check_auth_options(ODP_AUTH_ALG_MD5_HMAC, auth_key.length, - HMAC_MD5_96_CHECK_LEN)) + hmac_md5_reference_digest_length[i])) continue;
alg_test(ODP_CRYPTO_OP_ENCODE, @@ -1020,7 +1029,7 @@ void crypto_test_gen_alg_hmac_md5(void) hmac_md5_reference_length[i], NULL, 0, hmac_md5_reference_digest[i], - HMAC_MD5_96_CHECK_LEN); + hmac_md5_reference_digest_length[i]); } }
@@ -1042,7 +1051,7 @@ void crypto_test_check_alg_hmac_md5(void) auth_key.length = sizeof(hmac_md5_reference_key[i]);
if (!check_auth_options(ODP_AUTH_ALG_MD5_HMAC, auth_key.length, - HMAC_MD5_96_CHECK_LEN)) + hmac_md5_reference_digest_length[i])) continue;
alg_test(ODP_CRYPTO_OP_DECODE, @@ -1058,7 +1067,7 @@ void crypto_test_check_alg_hmac_md5(void) hmac_md5_reference_length[i], NULL, 0, hmac_md5_reference_digest[i], - HMAC_MD5_96_CHECK_LEN); + hmac_md5_reference_digest_length[i]);
alg_test(ODP_CRYPTO_OP_DECODE, 1, @@ -1073,7 +1082,7 @@ void crypto_test_check_alg_hmac_md5(void) hmac_md5_reference_length[i], NULL, 0, wrong_digest, - HMAC_MD5_96_CHECK_LEN); + hmac_md5_reference_digest_length[i]); } }
@@ -1106,7 +1115,7 @@ void crypto_test_gen_alg_hmac_sha256(void)
if (!check_auth_options(ODP_AUTH_ALG_SHA256_HMAC, auth_key.length, - HMAC_SHA256_128_CHECK_LEN)) + hmac_sha256_reference_digest_length[i])) continue;
alg_test(ODP_CRYPTO_OP_ENCODE, @@ -1122,7 +1131,7 @@ void crypto_test_gen_alg_hmac_sha256(void) hmac_sha256_reference_length[i], NULL, 0, hmac_sha256_reference_digest[i], - HMAC_SHA256_128_CHECK_LEN); + hmac_sha256_reference_digest_length[i]); } }
@@ -1146,7 +1155,7 @@ void crypto_test_check_alg_hmac_sha256(void)
if (!check_auth_options(ODP_AUTH_ALG_SHA256_HMAC, auth_key.length, - HMAC_SHA256_128_CHECK_LEN)) + hmac_sha256_reference_digest_length[i])) continue;
alg_test(ODP_CRYPTO_OP_DECODE, @@ -1162,7 +1171,7 @@ void crypto_test_check_alg_hmac_sha256(void) hmac_sha256_reference_length[i], NULL, 0, hmac_sha256_reference_digest[i], - HMAC_SHA256_128_CHECK_LEN); + hmac_sha256_reference_digest_length[i]);
alg_test(ODP_CRYPTO_OP_DECODE, 1, @@ -1177,7 +1186,7 @@ void crypto_test_check_alg_hmac_sha256(void) hmac_sha256_reference_length[i], NULL, 0, wrong_digest, - HMAC_SHA256_128_CHECK_LEN); + hmac_sha256_reference_digest_length[i]); } }
diff --git a/test/common_plat/validation/api/crypto/test_vectors.h b/test/common_plat/validation/api/crypto/test_vectors.h index a1cf4faf..defbda45 100644 --- a/test/common_plat/validation/api/crypto/test_vectors.h +++ b/test/common_plat/validation/api/crypto/test_vectors.h @@ -139,6 +139,8 @@ static uint8_t aes128_gcm_reference_iv[][AES128_GCM_IV_LEN] = {
static uint32_t aes128_gcm_reference_length[] = { 84, 72, 72, 40};
+static uint32_t aes128_gcm_reference_tag_length[] = { 16, 16, 16, 16}; + static odp_packet_data_range_t aes128_gcm_cipher_range[] = { { .offset = 12, .length = 72 }, { .offset = 8, .length = 64 }, @@ -306,6 +308,10 @@ static uint8_t hmac_md5_reference_digest[][HMAC_MD5_DIGEST_LEN] = { 0xdb, 0xb8, 0xc7, 0x33, 0xf0, 0xe8, 0xb3, 0xf6 } };
+static uint32_t hmac_md5_reference_digest_length[] = { + 12, 12, 12 +}; + static uint8_t hmac_sha256_reference_key[][HMAC_SHA256_KEY_LEN] = { { 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, @@ -350,4 +356,8 @@ static uint8_t hmac_sha256_reference_digest[][HMAC_SHA256_DIGEST_LEN] = { 0x85, 0x4d, 0xb8, 0xeb, 0xd0, 0x91, 0x81, 0xa7 } };
+static uint32_t hmac_sha256_reference_digest_length[] = { + 16, 16, 16 +}; + #endif diff --git a/test/common_plat/validation/api/crypto/test_vectors_len.h b/test/common_plat/validation/api/crypto/test_vectors_len.h index 4fbb5cd7..80fd927b 100644 --- a/test/common_plat/validation/api/crypto/test_vectors_len.h +++ b/test/common_plat/validation/api/crypto/test_vectors_len.h @@ -21,18 +21,15 @@ #define AES128_GCM_IV_LEN 12 #define AES128_GCM_MAX_DATA_LEN 106 #define AES128_GCM_DIGEST_LEN 16 -#define AES128_GCM_CHECK_LEN 16
/* HMAC-MD5 */ #define HMAC_MD5_KEY_LEN 16 #define HMAC_MD5_MAX_DATA_LEN 128 #define HMAC_MD5_DIGEST_LEN 16 -#define HMAC_MD5_96_CHECK_LEN 12
/* HMAC-SHA256 */ #define HMAC_SHA256_KEY_LEN 32 #define HMAC_SHA256_MAX_DATA_LEN 128 #define HMAC_SHA256_DIGEST_LEN 32 -#define HMAC_SHA256_128_CHECK_LEN 16
#endif
commit 5056151ea74434572609808b546ab0363b900866 Author: Maxim Uvarov maxim.uvarov@linaro.org Date: Wed May 31 18:33:25 2017 +0300
test: time: do not fail under gcov
code coverage gcov make test very slow and it does not pass accepted boundaries. Test if env TEST=coverage variable is set and do no generate fail result if some boundaries are missing. https://bugs.linaro.org/show_bug.cgi?id=3017
Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org Reviewed-by: Bill Fischofer bill.fischofer@linaro.org
diff --git a/test/common_plat/validation/api/time/Makefile.am b/test/common_plat/validation/api/time/Makefile.am index 999fcf15..82682dfc 100644 --- a/test/common_plat/validation/api/time/Makefile.am +++ b/test/common_plat/validation/api/time/Makefile.am @@ -1,5 +1,12 @@ include ../Makefile.inc
+TESTS_ENVIRONMENT += TEST_DIR=${builddir} + +TESTSCRIPTS = time.sh +TEST_EXTENSIONS = .sh + +TESTS = $(TESTSCRIPTS) + noinst_LTLIBRARIES = libtesttime.la libtesttime_la_SOURCES = time.c
@@ -7,4 +14,5 @@ test_PROGRAMS = time_main$(EXEEXT) dist_time_main_SOURCES = time_main.c time_main_LDADD = libtesttime.la $(LIBCUNIT_COMMON) $(LIBODP)
-EXTRA_DIST = time_test.h +EXTRA_DIST = time_test.h $(TESTSCRIPTS) +dist_check_SCRIPTS = $(TESTSCRIPTS) diff --git a/test/common_plat/validation/api/time/time.sh b/test/common_plat/validation/api/time/time.sh new file mode 100755 index 00000000..02bf75a7 --- /dev/null +++ b/test/common_plat/validation/api/time/time.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# +# Copyright (c) 2017, Linaro Limited +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause +# + +# directories where time_main binary can be found: +# -in the validation dir when running make check (intree or out of tree) +# -in the script directory, when running after 'make install', or +# -in the validation when running standalone (./time) intree. +# -in the current directory. +# running stand alone out of tree requires setting PATH +PATH=${TEST_DIR}/api/time:$PATH +PATH=$(dirname $0)/../../../../common_plat/validation/api/time:$PATH +PATH=$(dirname $0):$PATH +PATH=`pwd`:$PATH + +time_main_path=$(which time_main${EXEEXT}) +if [ -x "$time_main_path" ] ; then + echo "running with time_main: $time_run_path" +else + echo "cannot find time_main: please set you PATH for it." + exit 1 +fi + +# exit codes expected by automake for skipped tests +TEST_SKIPPED=77 + +time_main${EXEEXT} +ret=$? + +SIGSEGV=139 + +if [ "${TRAVIS}" = "true" ] && [ $ret -ne 0 ] && + [ ${TEST} = "coverage" ] && [ $ret -ne ${SIGSEGV} ]; then + echo "SKIP: skip due significant slowdown under code coverage" + exit ${TEST_SKIPPED} +fi + +exit $ret diff --git a/test/linux-generic/Makefile.am b/test/linux-generic/Makefile.am index 38516a43..f92083d7 100644 --- a/test/linux-generic/Makefile.am +++ b/test/linux-generic/Makefile.am @@ -28,7 +28,7 @@ TESTS = validation/api/pktio/pktio_run.sh \ $(ALL_API_VALIDATION_DIR)/scheduler/scheduler_main$(EXEEXT) \ $(ALL_API_VALIDATION_DIR)/std_clib/std_clib_main$(EXEEXT) \ $(ALL_API_VALIDATION_DIR)/thread/thread_main$(EXEEXT) \ - $(ALL_API_VALIDATION_DIR)/time/time_main$(EXEEXT) \ + $(ALL_API_VALIDATION_DIR)/time/time.sh \ $(ALL_API_VALIDATION_DIR)/timer/timer_main$(EXEEXT) \ $(ALL_API_VALIDATION_DIR)/traffic_mngr/traffic_mngr.sh \ $(ALL_API_VALIDATION_DIR)/shmem/shmem_main$(EXEEXT) \
commit 9a66396a86a8f34afe69eff9ae764b54a62968c5 Author: Petri Savolainen petri.savolainen@linaro.org Date: Wed Feb 22 17:08:25 2017 +0200
validation: crypto: add stubs for sha-1 and sha-512 tests
API enumerations are tested but functional tests are missing still.
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/validation/api/crypto/crypto.h b/test/common_plat/validation/api/crypto/crypto.h index 661fe5df..4d810f62 100644 --- a/test/common_plat/validation/api/crypto/crypto.h +++ b/test/common_plat/validation/api/crypto/crypto.h @@ -24,8 +24,10 @@ void crypto_test_dec_alg_aes128_gcm(void); void crypto_test_dec_alg_aes128_gcm_ovr_iv(void); void crypto_test_gen_alg_hmac_md5(void); void crypto_test_check_alg_hmac_md5(void); +void crypto_test_alg_hmac_sha1(void); void crypto_test_gen_alg_hmac_sha256(void); void crypto_test_check_alg_hmac_sha256(void); +void crypto_test_alg_hmac_sha512(void);
/* test arrays: */ extern odp_testinfo_t crypto_suite[]; diff --git a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c index 9defdbfa..bfc9da3c 100644 --- a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c @@ -340,10 +340,18 @@ static int check_alg_support(odp_cipher_alg_t cipher, odp_auth_alg_t auth) if (!capability.auths.bit.md5_hmac) return ODP_TEST_INACTIVE; break; + case ODP_AUTH_ALG_SHA1_HMAC: + if (!capability.auths.bit.sha1_hmac) + return ODP_TEST_INACTIVE; + break; case ODP_AUTH_ALG_SHA256_HMAC: if (!capability.auths.bit.sha256_hmac) return ODP_TEST_INACTIVE; break; + case ODP_AUTH_ALG_SHA512_HMAC: + if (!capability.auths.bit.sha512_hmac) + return ODP_TEST_INACTIVE; + break; case ODP_AUTH_ALG_AES_GCM: if (!capability.auths.bit.aes_gcm) return ODP_TEST_INACTIVE; @@ -1173,6 +1181,26 @@ void crypto_test_check_alg_hmac_sha256(void) } }
+static int check_alg_hmac_sha1(void) +{ + return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA1_HMAC); +} + +void crypto_test_alg_hmac_sha1(void) +{ + printf(" TEST NOT IMPLEMENTED YET "); +} + +static int check_alg_hmac_sha512(void) +{ + return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_SHA512_HMAC); +} + +void crypto_test_alg_hmac_sha512(void) +{ + printf(" TEST NOT IMPLEMENTED YET "); +} + int crypto_suite_sync_init(void) { suite_context.pool = odp_pool_lookup("packet_pool"); @@ -1226,10 +1254,14 @@ odp_testinfo_t crypto_suite[] = { check_alg_hmac_md5), ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_hmac_md5, check_alg_hmac_md5), + ODP_TEST_INFO_CONDITIONAL(crypto_test_alg_hmac_sha1, + check_alg_hmac_sha1), ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_hmac_sha256, check_alg_hmac_sha256), ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_hmac_sha256, check_alg_hmac_sha256), + ODP_TEST_INFO_CONDITIONAL(crypto_test_alg_hmac_sha512, + check_alg_hmac_sha512), ODP_TEST_INFO_NULL, };
commit da07245508f60344de56a54227271cbf225f4063 Author: Matias Elo matias.elo@nokia.com Date: Tue Apr 4 09:28:19 2017 +0300
linux-gen: packet: remove lazy parsing
Replace old lazy parsing code with a new packet parsing implementation which follows the latest API (parsing level is selected using odp_pktio_config()).
Signed-off-by: Matias Elo matias.elo@nokia.com Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/include/odp/api/plat/packet_types.h b/platform/linux-generic/include/odp/api/plat/packet_types.h index 95cba5eb..a209c759 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_types.h +++ b/platform/linux-generic/include/odp/api/plat/packet_types.h @@ -107,7 +107,6 @@ typedef union {
/** Individual input flags */ struct { - uint64_t parsed_l2:1; /**< L2 parsed */ uint64_t dst_queue:1; /**< Dst queue present */
uint64_t flow_hash:1; /**< Flow hash present */ diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index 4c8d7515..a480a748 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -80,18 +80,6 @@ ODP_STATIC_ASSERT(sizeof(output_flags_t) == sizeof(uint32_t), "OUTPUT_FLAGS_SIZE_ERROR");
/** - * Protocol stack layers - */ -typedef enum { - LAYER_NONE = 0, - LAYER_L1, - LAYER_L2, - LAYER_L3, - LAYER_L4, - LAYER_ALL -} layer_t; - -/** * Packet parser metadata */ typedef struct { @@ -102,14 +90,6 @@ typedef struct { uint32_t l2_offset; /**< offset to L2 hdr, e.g. Eth */ uint32_t l3_offset; /**< offset to L3 hdr, e.g. IPv4, IPv6 */ uint32_t l4_offset; /**< offset to L4 hdr (TCP, UDP, SCTP, also ICMP) */ - - uint32_t l3_len; /**< Layer 3 length */ - uint32_t l4_len; /**< Layer 4 length */ - - uint16_t ethtype; /**< EtherType */ - uint8_t ip_proto; /**< IP protocol */ - uint8_t parsed_layers; /**< Highest parsed protocol stack layer */ - } packet_parser_t;
/** @@ -203,16 +183,6 @@ static inline void packet_set_len(odp_packet_hdr_t *pkt_hdr, uint32_t len) pkt_hdr->frame_len = len; }
-static inline int packet_parse_l2_not_done(packet_parser_t *prs) -{ - return !prs->input_flags.parsed_l2; -} - -static inline int packet_parse_not_complete(odp_packet_hdr_t *pkt_hdr) -{ - return pkt_hdr->p.parsed_layers != LAYER_ALL; -} - /* Forward declarations */ int _odp_packet_copy_md_to_packet(odp_packet_t srcpkt, odp_packet_t dstpkt);
@@ -220,11 +190,9 @@ int _odp_packet_copy_md_to_packet(odp_packet_t srcpkt, odp_packet_t dstpkt); int packet_alloc_multi(odp_pool_t pool_hdl, uint32_t len, odp_packet_t pkt[], int max_num);
-/* Fill in parser metadata for L2 */ -void packet_parse_l2(packet_parser_t *prs, uint32_t frame_len); - /* Perform packet parse up to a given protocol layer */ -int packet_parse_layer(odp_packet_hdr_t *pkt_hdr, layer_t layer); +int packet_parse_layer(odp_packet_hdr_t *pkt_hdr, + odp_pktio_parser_layer_t layer);
/* Reset parser metadata for a new parse */ void packet_parse_reset(odp_packet_hdr_t *pkt_hdr); @@ -264,7 +232,8 @@ static inline void packet_set_ts(odp_packet_hdr_t *pkt_hdr, odp_time_t *ts) }
int packet_parse_common(packet_parser_t *pkt_hdr, const uint8_t *ptr, - uint32_t pkt_len, uint32_t seg_len, layer_t layer); + uint32_t pkt_len, uint32_t seg_len, + odp_pktio_parser_layer_t layer);
int _odp_cls_parse(odp_packet_hdr_t *pkt_hdr, const uint8_t *parseptr);
diff --git a/platform/linux-generic/odp_classification.c b/platform/linux-generic/odp_classification.c index 5d96b00b..7ebc47d7 100644 --- a/platform/linux-generic/odp_classification.c +++ b/platform/linux-generic/odp_classification.c @@ -790,10 +790,6 @@ static inline cos_t *cls_select_cos(pktio_entry_t *entry, cls = &entry->s.cls; default_cos = cls->default_cos;
- /* Check for lazy parse needed */ - if (packet_parse_not_complete(pkt_hdr)) - packet_parse_layer(pkt_hdr, LAYER_ALL); - /* Return error cos for error packet */ if (pkt_hdr->p.error_flags.all) return cls->error_cos; @@ -838,7 +834,8 @@ int cls_classify_packet(pktio_entry_t *entry, const uint8_t *base, packet_parse_reset(pkt_hdr); packet_set_len(pkt_hdr, pkt_len);
- packet_parse_common(&pkt_hdr->p, base, pkt_len, seg_len, LAYER_ALL); + packet_parse_common(&pkt_hdr->p, base, pkt_len, seg_len, + ODP_PKTIO_PARSER_LAYER_ALL); cos = cls_select_cos(entry, base, pkt_hdr);
if (cos == NULL) diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index 69098624..eb66af2d 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -220,16 +220,9 @@ static inline void *packet_map(odp_packet_hdr_t *pkt_hdr, return addr; }
-static inline void packet_parse_disable(odp_packet_hdr_t *pkt_hdr) -{ - pkt_hdr->p.input_flags.parsed_l2 = 1; - pkt_hdr->p.parsed_layers = LAYER_ALL; -} - void packet_parse_reset(odp_packet_hdr_t *pkt_hdr) { /* Reset parser metadata before new parse */ - pkt_hdr->p.parsed_layers = LAYER_NONE; pkt_hdr->p.error_flags.all = 0; pkt_hdr->p.input_flags.all = 0; pkt_hdr->p.output_flags.all = 0; @@ -241,8 +234,7 @@ void packet_parse_reset(odp_packet_hdr_t *pkt_hdr) /** * Initialize packet */ -static inline void packet_init(odp_packet_hdr_t *pkt_hdr, uint32_t len, - int parse) +static inline void packet_init(odp_packet_hdr_t *pkt_hdr, uint32_t len) { uint32_t seg_len; int num = pkt_hdr->buf_hdr.segcount; @@ -257,7 +249,6 @@ static inline void packet_init(odp_packet_hdr_t *pkt_hdr, uint32_t len, pkt_hdr->buf_hdr.seg[num - 1].len = seg_len; }
- pkt_hdr->p.parsed_layers = LAYER_NONE; pkt_hdr->p.input_flags.all = 0; pkt_hdr->p.output_flags.all = 0; pkt_hdr->p.error_flags.all = 0; @@ -266,10 +257,6 @@ static inline void packet_init(odp_packet_hdr_t *pkt_hdr, uint32_t len, pkt_hdr->p.l3_offset = ODP_PACKET_OFFSET_INVALID; pkt_hdr->p.l4_offset = ODP_PACKET_OFFSET_INVALID;
- /* Disable lazy parsing on user allocated packets */ - if (!parse) - packet_parse_disable(pkt_hdr); - /* * Packet headroom is set from the pool's headroom * Packet tailroom is rounded up to fill the last @@ -485,7 +472,7 @@ static inline odp_packet_hdr_t *free_segments(odp_packet_hdr_t *pkt_hdr, }
static inline int packet_alloc(pool_t *pool, uint32_t len, int max_pkt, - int num_seg, odp_packet_t *pkt, int parse) + int num_seg, odp_packet_t *pkt) { int num_buf, i; int num = max_pkt; @@ -518,7 +505,7 @@ static inline int packet_alloc(pool_t *pool, uint32_t len, int max_pkt, pkt[i] = packet_handle(hdr); init_segments(&pkt_hdr[i * num_seg], num_seg);
- packet_init(hdr, len, parse); + packet_init(hdr, len); }
return num; @@ -531,7 +518,7 @@ int packet_alloc_multi(odp_pool_t pool_hdl, uint32_t len, int num, num_seg;
num_seg = num_segments(len); - num = packet_alloc(pool, len, max_num, num_seg, pkt, 1); + num = packet_alloc(pool, len, max_num, num_seg, pkt);
return num; } @@ -551,7 +538,7 @@ odp_packet_t odp_packet_alloc(odp_pool_t pool_hdl, uint32_t len) return ODP_PACKET_INVALID;
num_seg = num_segments(len); - num = packet_alloc(pool, len, 1, num_seg, &pkt, 0); + num = packet_alloc(pool, len, 1, num_seg, &pkt);
if (odp_unlikely(num == 0)) return ODP_PACKET_INVALID; @@ -574,7 +561,7 @@ int odp_packet_alloc_multi(odp_pool_t pool_hdl, uint32_t len, return -1;
num_seg = num_segments(len); - num = packet_alloc(pool, len, max_num, num_seg, pkt, 0); + num = packet_alloc(pool, len, max_num, num_seg, pkt);
return num; } @@ -635,7 +622,7 @@ int odp_packet_reset(odp_packet_t pkt, uint32_t len) if (len > pool->headroom + pool->data_size + pool->tailroom) return -1;
- packet_init(pkt_hdr, len, 0); + packet_init(pkt_hdr, len);
return 0; } @@ -1247,8 +1234,6 @@ void *odp_packet_l3_ptr(odp_packet_t pkt, uint32_t *len) { odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt);
- if (pkt_hdr->p.parsed_layers < LAYER_L3) - packet_parse_layer(pkt_hdr, LAYER_L3); return packet_map(pkt_hdr, pkt_hdr->p.l3_offset, len, NULL); }
@@ -1256,8 +1241,6 @@ uint32_t odp_packet_l3_offset(odp_packet_t pkt) { odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt);
- if (pkt_hdr->p.parsed_layers < LAYER_L3) - packet_parse_layer(pkt_hdr, LAYER_L3); return pkt_hdr->p.l3_offset; }
@@ -1268,8 +1251,6 @@ int odp_packet_l3_offset_set(odp_packet_t pkt, uint32_t offset) if (offset >= pkt_hdr->frame_len) return -1;
- if (pkt_hdr->p.parsed_layers < LAYER_L3) - packet_parse_layer(pkt_hdr, LAYER_L3); pkt_hdr->p.l3_offset = offset; return 0; } @@ -1278,8 +1259,6 @@ void *odp_packet_l4_ptr(odp_packet_t pkt, uint32_t *len) { odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt);
- if (pkt_hdr->p.parsed_layers < LAYER_L4) - packet_parse_layer(pkt_hdr, LAYER_L4); return packet_map(pkt_hdr, pkt_hdr->p.l4_offset, len, NULL); }
@@ -1287,8 +1266,6 @@ uint32_t odp_packet_l4_offset(odp_packet_t pkt) { odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt);
- if (pkt_hdr->p.parsed_layers < LAYER_L4) - packet_parse_layer(pkt_hdr, LAYER_L4); return pkt_hdr->p.l4_offset; }
@@ -1299,8 +1276,6 @@ int odp_packet_l4_offset_set(odp_packet_t pkt, uint32_t offset) if (offset >= pkt_hdr->frame_len) return -1;
- if (pkt_hdr->p.parsed_layers < LAYER_L4) - packet_parse_layer(pkt_hdr, LAYER_L4); pkt_hdr->p.l4_offset = offset; return 0; } @@ -1829,12 +1804,11 @@ static inline uint8_t parse_ipv4(packet_parser_t *prs, const uint8_t **parseptr, uint8_t ihl = _ODP_IPV4HDR_IHL(ipv4->ver_ihl); uint16_t frag_offset; uint32_t dstaddr = odp_be_to_cpu_32(ipv4->dst_addr); - - prs->l3_len = odp_be_to_cpu_16(ipv4->tot_len); + uint32_t l3_len = odp_be_to_cpu_16(ipv4->tot_len);
if (odp_unlikely(ihl < _ODP_IPV4HDR_IHL_MIN) || odp_unlikely(ver != 4) || - (prs->l3_len > frame_len - *offset)) { + (l3_len > frame_len - *offset)) { prs->error_flags.ip_err = 1; return 0; } @@ -1871,13 +1845,12 @@ static inline uint8_t parse_ipv6(packet_parser_t *prs, const uint8_t **parseptr, const _odp_ipv6hdr_t *ipv6 = (const _odp_ipv6hdr_t *)*parseptr; const _odp_ipv6hdr_ext_t *ipv6ext; uint32_t dstaddr0 = odp_be_to_cpu_32(ipv6->dst_addr.u8[0]); - - prs->l3_len = odp_be_to_cpu_16(ipv6->payload_len) + - _ODP_IPV6HDR_LEN; + uint32_t l3_len = odp_be_to_cpu_16(ipv6->payload_len) + + _ODP_IPV6HDR_LEN;
/* Basic sanity checks on IPv6 header */ if ((odp_be_to_cpu_32(ipv6->ver_tc_flow) >> 28) != 6 || - prs->l3_len > frame_len - *offset) { + l3_len > frame_len - *offset) { prs->error_flags.ip_err = 1; return 0; } @@ -1938,9 +1911,6 @@ static inline void parse_tcp(packet_parser_t *prs, else if ((uint32_t)tcp->hl * 4 > sizeof(_odp_tcphdr_t)) prs->input_flags.tcpopt = 1;
- prs->l4_len = prs->l3_len + - prs->l3_offset - prs->l4_offset; - if (offset) *offset += (uint32_t)tcp->hl * 4; *parseptr += (uint32_t)tcp->hl * 4; @@ -1955,13 +1925,8 @@ static inline void parse_udp(packet_parser_t *prs, const _odp_udphdr_t *udp = (const _odp_udphdr_t *)*parseptr; uint32_t udplen = odp_be_to_cpu_16(udp->length);
- if (udplen < sizeof(_odp_udphdr_t) || - udplen > (prs->l3_len + - prs->l4_offset - prs->l3_offset)) { + if (odp_unlikely(udplen < sizeof(_odp_udphdr_t))) prs->error_flags.udp_err = 1; - } - - prs->l4_len = udplen;
if (offset) *offset += sizeof(_odp_udphdr_t); @@ -1969,218 +1934,170 @@ static inline void parse_udp(packet_parser_t *prs, }
/** - * Initialize L2 related parser flags and metadata - */ -void packet_parse_l2(packet_parser_t *prs, uint32_t frame_len) -{ - /* Packet alloc or reset have already init other offsets and flags */ - - /* We only support Ethernet for now */ - prs->input_flags.eth = 1; - - /* Detect jumbo frames */ - if (frame_len > _ODP_ETH_LEN_MAX) - prs->input_flags.jumbo = 1; - - /* Assume valid L2 header, no CRC/FCS check in SW */ - prs->input_flags.l2 = 1; - - prs->input_flags.parsed_l2 = 1; -} - -/** * Parse common packet headers up to given layer * * The function expects at least PACKET_PARSE_SEG_LEN bytes of data to be * available from the ptr. */ int packet_parse_common(packet_parser_t *prs, const uint8_t *ptr, - uint32_t frame_len, uint32_t seg_len, layer_t layer) + uint32_t frame_len, uint32_t seg_len, + odp_pktio_parser_layer_t layer) { uint32_t offset; + uint16_t ethtype; const uint8_t *parseptr; + uint8_t ip_proto; + const _odp_ethhdr_t *eth; + uint16_t macaddr0, macaddr2, macaddr4; + const _odp_vlanhdr_t *vlan;
- switch (prs->parsed_layers) { - case LAYER_NONE: - /* Fall through */ - - case LAYER_L2: - { - const _odp_ethhdr_t *eth; - uint16_t macaddr0, macaddr2, macaddr4; - const _odp_vlanhdr_t *vlan; - - offset = sizeof(_odp_ethhdr_t); - if (packet_parse_l2_not_done(prs)) - packet_parse_l2(prs, frame_len); - - eth = (const _odp_ethhdr_t *)ptr; - - /* Handle Ethernet broadcast/multicast addresses */ - macaddr0 = odp_be_to_cpu_16(*((const uint16_t *) - (const void *)eth)); - prs->input_flags.eth_mcast = (macaddr0 & 0x0100) == 0x0100; - - if (macaddr0 == 0xffff) { - macaddr2 = - odp_be_to_cpu_16(*((const uint16_t *) - (const void *)eth + 1)); - macaddr4 = - odp_be_to_cpu_16(*((const uint16_t *) - (const void *)eth + 2)); - prs->input_flags.eth_bcast = - (macaddr2 == 0xffff) && (macaddr4 == 0xffff); - } else { - prs->input_flags.eth_bcast = 0; - } + if (layer == ODP_PKTIO_PARSER_LAYER_NONE) + return 0;
- /* Get Ethertype */ - prs->ethtype = odp_be_to_cpu_16(eth->type); - parseptr = (const uint8_t *)(eth + 1); + /* We only support Ethernet for now */ + prs->input_flags.eth = 1; + /* Assume valid L2 header, no CRC/FCS check in SW */ + prs->input_flags.l2 = 1; + /* Detect jumbo frames */ + if (frame_len > _ODP_ETH_LEN_MAX) + prs->input_flags.jumbo = 1;
- /* Check for SNAP vs. DIX */ - if (prs->ethtype < _ODP_ETH_LEN_MAX) { - prs->input_flags.snap = 1; - if (prs->ethtype > frame_len - offset) { - prs->error_flags.snap_len = 1; - goto parse_exit; - } - prs->ethtype = odp_be_to_cpu_16(*((const uint16_t *) - (uintptr_t) - (parseptr + 6))); - offset += 8; - parseptr += 8; - } + offset = sizeof(_odp_ethhdr_t); + eth = (const _odp_ethhdr_t *)ptr; + + /* Handle Ethernet broadcast/multicast addresses */ + macaddr0 = odp_be_to_cpu_16(*((const uint16_t *)(const void *)eth)); + prs->input_flags.eth_mcast = (macaddr0 & 0x0100) == 0x0100; + + if (macaddr0 == 0xffff) { + macaddr2 = + odp_be_to_cpu_16(*((const uint16_t *) + (const void *)eth + 1)); + macaddr4 = + odp_be_to_cpu_16(*((const uint16_t *) + (const void *)eth + 2)); + prs->input_flags.eth_bcast = + (macaddr2 == 0xffff) && (macaddr4 == 0xffff); + } else { + prs->input_flags.eth_bcast = 0; + }
- /* Parse the VLAN header(s), if present */ - if (prs->ethtype == _ODP_ETHTYPE_VLAN_OUTER) { - prs->input_flags.vlan_qinq = 1; - prs->input_flags.vlan = 1; + /* Get Ethertype */ + ethtype = odp_be_to_cpu_16(eth->type); + parseptr = (const uint8_t *)(eth + 1);
- vlan = (const _odp_vlanhdr_t *)parseptr; - prs->ethtype = odp_be_to_cpu_16(vlan->type); - offset += sizeof(_odp_vlanhdr_t); - parseptr += sizeof(_odp_vlanhdr_t); + /* Check for SNAP vs. DIX */ + if (ethtype < _ODP_ETH_LEN_MAX) { + prs->input_flags.snap = 1; + if (ethtype > frame_len - offset) { + prs->error_flags.snap_len = 1; + goto parse_exit; } + ethtype = odp_be_to_cpu_16(*((const uint16_t *)(uintptr_t) + (parseptr + 6))); + offset += 8; + parseptr += 8; + }
- if (prs->ethtype == _ODP_ETHTYPE_VLAN) { - prs->input_flags.vlan = 1; - vlan = (const _odp_vlanhdr_t *)parseptr; - prs->ethtype = odp_be_to_cpu_16(vlan->type); - offset += sizeof(_odp_vlanhdr_t); - parseptr += sizeof(_odp_vlanhdr_t); - } + /* Parse the VLAN header(s), if present */ + if (ethtype == _ODP_ETHTYPE_VLAN_OUTER) { + prs->input_flags.vlan_qinq = 1; + prs->input_flags.vlan = 1;
- prs->l3_offset = offset; - prs->parsed_layers = LAYER_L2; - if (layer == LAYER_L2) - return prs->error_flags.all != 0; + vlan = (const _odp_vlanhdr_t *)parseptr; + ethtype = odp_be_to_cpu_16(vlan->type); + offset += sizeof(_odp_vlanhdr_t); + parseptr += sizeof(_odp_vlanhdr_t); } - /* Fall through */
- case LAYER_L3: - { - offset = prs->l3_offset; - parseptr = (const uint8_t *)(ptr + offset); - /* Set l3_offset+flag only for known ethtypes */ - prs->input_flags.l3 = 1; - - /* Parse Layer 3 headers */ - switch (prs->ethtype) { - case _ODP_ETHTYPE_IPV4: - prs->input_flags.ipv4 = 1; - prs->ip_proto = parse_ipv4(prs, &parseptr, &offset, - frame_len); - break; + if (ethtype == _ODP_ETHTYPE_VLAN) { + prs->input_flags.vlan = 1; + vlan = (const _odp_vlanhdr_t *)parseptr; + ethtype = odp_be_to_cpu_16(vlan->type); + offset += sizeof(_odp_vlanhdr_t); + parseptr += sizeof(_odp_vlanhdr_t); + }
- case _ODP_ETHTYPE_IPV6: - prs->input_flags.ipv6 = 1; - prs->ip_proto = parse_ipv6(prs, &parseptr, &offset, - frame_len, seg_len); - break; + if (layer == ODP_PKTIO_PARSER_LAYER_L2) + return prs->error_flags.all != 0;
- case _ODP_ETHTYPE_ARP: - prs->input_flags.arp = 1; - prs->ip_proto = 255; /* Reserved invalid by IANA */ - break; + /* Set l3_offset+flag only for known ethtypes */ + prs->l3_offset = offset; + prs->input_flags.l3 = 1;
- default: - prs->input_flags.l3 = 0; - prs->l3_offset = ODP_PACKET_OFFSET_INVALID; - prs->ip_proto = 255; /* Reserved invalid by IANA */ - } + /* Parse Layer 3 headers */ + switch (ethtype) { + case _ODP_ETHTYPE_IPV4: + prs->input_flags.ipv4 = 1; + ip_proto = parse_ipv4(prs, &parseptr, &offset, frame_len); + break;
- /* Set l4_offset+flag only for known ip_proto */ - prs->l4_offset = offset; - prs->parsed_layers = LAYER_L3; - if (layer == LAYER_L3) - return prs->error_flags.all != 0; - } - /* Fall through */ + case _ODP_ETHTYPE_IPV6: + prs->input_flags.ipv6 = 1; + ip_proto = parse_ipv6(prs, &parseptr, &offset, frame_len, + seg_len); + break;
- case LAYER_L4: - { - offset = prs->l4_offset; - parseptr = (const uint8_t *)(ptr + offset); - prs->input_flags.l4 = 1; + case _ODP_ETHTYPE_ARP: + prs->input_flags.arp = 1; + ip_proto = 255; /* Reserved invalid by IANA */ + break;
- /* Parse Layer 4 headers */ - switch (prs->ip_proto) { - case _ODP_IPPROTO_ICMPv4: - /* Fall through */ + default: + prs->input_flags.l3 = 0; + prs->l3_offset = ODP_PACKET_OFFSET_INVALID; + ip_proto = 255; /* Reserved invalid by IANA */ + }
- case _ODP_IPPROTO_ICMPv6: - prs->input_flags.icmp = 1; - break; + if (layer == ODP_PKTIO_PARSER_LAYER_L3) + return prs->error_flags.all != 0;
- case _ODP_IPPROTO_TCP: - if (odp_unlikely(offset + _ODP_TCPHDR_LEN > seg_len)) - return -1; - prs->input_flags.tcp = 1; - parse_tcp(prs, &parseptr, NULL); - break; + /* Set l4_offset+flag only for known ip_proto */ + prs->l4_offset = offset; + prs->input_flags.l4 = 1;
- case _ODP_IPPROTO_UDP: - if (odp_unlikely(offset + _ODP_UDPHDR_LEN > seg_len)) - return -1; - prs->input_flags.udp = 1; - parse_udp(prs, &parseptr, NULL); - break; + /* Parse Layer 4 headers */ + switch (ip_proto) { + case _ODP_IPPROTO_ICMPv4: + /* Fall through */
- case _ODP_IPPROTO_AH: - prs->input_flags.ipsec = 1; - prs->input_flags.ipsec_ah = 1; - break; + case _ODP_IPPROTO_ICMPv6: + prs->input_flags.icmp = 1; + break;
- case _ODP_IPPROTO_ESP: - prs->input_flags.ipsec = 1; - prs->input_flags.ipsec_esp = 1; - break; + case _ODP_IPPROTO_TCP: + if (odp_unlikely(offset + _ODP_TCPHDR_LEN > seg_len)) + return -1; + prs->input_flags.tcp = 1; + parse_tcp(prs, &parseptr, NULL); + break;
- case _ODP_IPPROTO_SCTP: - prs->input_flags.sctp = 1; - break; + case _ODP_IPPROTO_UDP: + if (odp_unlikely(offset + _ODP_UDPHDR_LEN > seg_len)) + return -1; + prs->input_flags.udp = 1; + parse_udp(prs, &parseptr, NULL); + break;
- default: - prs->input_flags.l4 = 0; - prs->l4_offset = ODP_PACKET_OFFSET_INVALID; - break; - } + case _ODP_IPPROTO_AH: + prs->input_flags.ipsec = 1; + prs->input_flags.ipsec_ah = 1; + break;
- prs->parsed_layers = LAYER_L4; + case _ODP_IPPROTO_ESP: + prs->input_flags.ipsec = 1; + prs->input_flags.ipsec_esp = 1; break; - }
- case LAYER_ALL: + case _ODP_IPPROTO_SCTP: + prs->input_flags.sctp = 1; break;
default: - ODP_ERR("Invalid parse layer: %d\n", (int)layer); - return -1; + prs->input_flags.l4 = 0; + prs->l4_offset = ODP_PACKET_OFFSET_INVALID; + break; } - - prs->parsed_layers = LAYER_ALL; - parse_exit: return prs->error_flags.all != 0; } @@ -2188,7 +2105,8 @@ parse_exit: /** * Simple packet parser */ -int packet_parse_layer(odp_packet_hdr_t *pkt_hdr, layer_t layer) +int packet_parse_layer(odp_packet_hdr_t *pkt_hdr, + odp_pktio_parser_layer_t layer) { uint32_t seg_len = packet_first_seg_len(pkt_hdr); void *base = packet_data(pkt_hdr); diff --git a/platform/linux-generic/odp_packet_flags.c b/platform/linux-generic/odp_packet_flags.c index c2e8b9cf..72df1ecf 100644 --- a/platform/linux-generic/odp_packet_flags.c +++ b/platform/linux-generic/odp_packet_flags.c @@ -8,17 +8,13 @@ #include <odp/api/packet_flags.h> #include <odp_packet_internal.h>
-#define retflag(pkt, x, layer) do { \ +#define retflag(pkt, x) do { \ odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); \ - if (pkt_hdr->p.parsed_layers < layer) \ - packet_parse_layer(pkt_hdr, layer); \ return pkt_hdr->p.x; \ } while (0)
-#define setflag(pkt, x, v, layer) do { \ +#define setflag(pkt, x, v) do { \ odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt); \ - if (pkt_hdr->p.parsed_layers < layer) \ - packet_parse_layer(pkt_hdr, layer); \ pkt_hdr->p.x = (v) & 1; \ } while (0)
@@ -26,9 +22,7 @@ int odp_packet_has_error(odp_packet_t pkt) { odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
- if (packet_parse_not_complete(pkt_hdr)) - packet_parse_layer(pkt_hdr, LAYER_ALL); - return odp_packet_hdr(pkt)->p.error_flags.all != 0; + return pkt_hdr->p.error_flags.all != 0; }
/* Get Input Flags */ @@ -45,126 +39,117 @@ int odp_packet_has_l2_error(odp_packet_t pkt)
int odp_packet_has_l3(odp_packet_t pkt) { - retflag(pkt, input_flags.l3, LAYER_L3); + retflag(pkt, input_flags.l3); }
int odp_packet_has_l3_error(odp_packet_t pkt) { odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
- if (pkt_hdr->p.parsed_layers < LAYER_L3) - packet_parse_layer(pkt_hdr, LAYER_L3); - return pkt_hdr->p.error_flags.ip_err; }
int odp_packet_has_l4(odp_packet_t pkt) { - retflag(pkt, input_flags.l4, LAYER_L4); + retflag(pkt, input_flags.l4); }
int odp_packet_has_l4_error(odp_packet_t pkt) { odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
- if (pkt_hdr->p.parsed_layers < LAYER_L4) - packet_parse_layer(pkt_hdr, LAYER_L4); - return pkt_hdr->p.error_flags.tcp_err | pkt_hdr->p.error_flags.udp_err; }
int odp_packet_has_eth_bcast(odp_packet_t pkt) { - retflag(pkt, input_flags.eth_bcast, LAYER_L2); + retflag(pkt, input_flags.eth_bcast); }
int odp_packet_has_eth_mcast(odp_packet_t pkt) { - retflag(pkt, input_flags.eth_mcast, LAYER_L2); + retflag(pkt, input_flags.eth_mcast); }
int odp_packet_has_vlan(odp_packet_t pkt) { - retflag(pkt, input_flags.vlan, LAYER_L2); + retflag(pkt, input_flags.vlan); }
int odp_packet_has_vlan_qinq(odp_packet_t pkt) { - retflag(pkt, input_flags.vlan_qinq, LAYER_L2); + retflag(pkt, input_flags.vlan_qinq); }
int odp_packet_has_arp(odp_packet_t pkt) { - retflag(pkt, input_flags.arp, LAYER_L3); + retflag(pkt, input_flags.arp); }
int odp_packet_has_ipv4(odp_packet_t pkt) { - retflag(pkt, input_flags.ipv4, LAYER_L3); + retflag(pkt, input_flags.ipv4); }
int odp_packet_has_ipv6(odp_packet_t pkt) { - retflag(pkt, input_flags.ipv6, LAYER_L3); + retflag(pkt, input_flags.ipv6); }
int odp_packet_has_ip_bcast(odp_packet_t pkt) { - retflag(pkt, input_flags.ip_bcast, LAYER_L3); + retflag(pkt, input_flags.ip_bcast); }
int odp_packet_has_ip_mcast(odp_packet_t pkt) { - retflag(pkt, input_flags.ip_mcast, LAYER_L3); + retflag(pkt, input_flags.ip_mcast); }
int odp_packet_has_ipfrag(odp_packet_t pkt) { - retflag(pkt, input_flags.ipfrag, LAYER_L3); + retflag(pkt, input_flags.ipfrag); }
int odp_packet_has_ipopt(odp_packet_t pkt) { - retflag(pkt, input_flags.ipopt, LAYER_L3); + retflag(pkt, input_flags.ipopt); }
int odp_packet_has_ipsec(odp_packet_t pkt) { - retflag(pkt, input_flags.ipsec, LAYER_L4); + retflag(pkt, input_flags.ipsec); }
int odp_packet_has_udp(odp_packet_t pkt) { - retflag(pkt, input_flags.udp, LAYER_L4); + retflag(pkt, input_flags.udp); }
int odp_packet_has_tcp(odp_packet_t pkt) { - retflag(pkt, input_flags.tcp, LAYER_L4); + retflag(pkt, input_flags.tcp); }
int odp_packet_has_sctp(odp_packet_t pkt) { - retflag(pkt, input_flags.sctp, LAYER_L4); + retflag(pkt, input_flags.sctp); }
int odp_packet_has_icmp(odp_packet_t pkt) { - retflag(pkt, input_flags.icmp, LAYER_L4); + retflag(pkt, input_flags.icmp); }
odp_packet_color_t odp_packet_color(odp_packet_t pkt) { - retflag(pkt, input_flags.color, LAYER_ALL); + retflag(pkt, input_flags.color); }
void odp_packet_color_set(odp_packet_t pkt, odp_packet_color_t color) { odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
- if (packet_parse_not_complete(pkt_hdr)) - packet_parse_layer(pkt_hdr, LAYER_ALL); - pkt_hdr->p.input_flags.color = color; }
@@ -172,29 +157,23 @@ odp_bool_t odp_packet_drop_eligible(odp_packet_t pkt) { odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
- if (packet_parse_not_complete(pkt_hdr)) - packet_parse_layer(pkt_hdr, LAYER_ALL); - return !pkt_hdr->p.input_flags.nodrop; }
void odp_packet_drop_eligible_set(odp_packet_t pkt, odp_bool_t drop) { - setflag(pkt, input_flags.nodrop, !drop, LAYER_ALL); + setflag(pkt, input_flags.nodrop, !drop); }
int8_t odp_packet_shaper_len_adjust(odp_packet_t pkt) { - retflag(pkt, output_flags.shaper_len_adj, LAYER_ALL); + retflag(pkt, output_flags.shaper_len_adj); }
void odp_packet_shaper_len_adjust_set(odp_packet_t pkt, int8_t adj) { odp_packet_hdr_t *pkt_hdr = odp_packet_hdr(pkt);
- if (packet_parse_not_complete(pkt_hdr)) - packet_parse_layer(pkt_hdr, LAYER_ALL); - pkt_hdr->p.output_flags.shaper_len_adj = adj; }
@@ -202,107 +181,107 @@ void odp_packet_shaper_len_adjust_set(odp_packet_t pkt, int8_t adj)
void odp_packet_has_l2_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.l2, val, LAYER_L2); + setflag(pkt, input_flags.l2, val); }
void odp_packet_has_l3_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.l3, val, LAYER_L3); + setflag(pkt, input_flags.l3, val); }
void odp_packet_has_l4_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.l4, val, LAYER_L4); + setflag(pkt, input_flags.l4, val); }
void odp_packet_has_eth_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.eth, val, LAYER_L2); + setflag(pkt, input_flags.eth, val); }
void odp_packet_has_eth_bcast_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.eth_bcast, val, LAYER_L2); + setflag(pkt, input_flags.eth_bcast, val); }
void odp_packet_has_eth_mcast_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.eth_mcast, val, LAYER_L2); + setflag(pkt, input_flags.eth_mcast, val); }
void odp_packet_has_jumbo_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.jumbo, val, LAYER_L2); + setflag(pkt, input_flags.jumbo, val); }
void odp_packet_has_vlan_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.vlan, val, LAYER_L2); + setflag(pkt, input_flags.vlan, val); }
void odp_packet_has_vlan_qinq_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.vlan_qinq, val, LAYER_L2); + setflag(pkt, input_flags.vlan_qinq, val); }
void odp_packet_has_arp_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.arp, val, LAYER_L3); + setflag(pkt, input_flags.arp, val); }
void odp_packet_has_ipv4_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.ipv4, val, LAYER_L3); + setflag(pkt, input_flags.ipv4, val); }
void odp_packet_has_ipv6_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.ipv6, val, LAYER_L3); + setflag(pkt, input_flags.ipv6, val); }
void odp_packet_has_ip_bcast_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.ip_bcast, val, LAYER_L3); + setflag(pkt, input_flags.ip_bcast, val); }
void odp_packet_has_ip_mcast_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.ip_mcast, val, LAYER_L3); + setflag(pkt, input_flags.ip_mcast, val); }
void odp_packet_has_ipfrag_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.ipfrag, val, LAYER_L3); + setflag(pkt, input_flags.ipfrag, val); }
void odp_packet_has_ipopt_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.ipopt, val, LAYER_L3); + setflag(pkt, input_flags.ipopt, val); }
void odp_packet_has_ipsec_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.ipsec, val, LAYER_L4); + setflag(pkt, input_flags.ipsec, val); }
void odp_packet_has_udp_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.udp, val, LAYER_L4); + setflag(pkt, input_flags.udp, val); }
void odp_packet_has_tcp_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.tcp, val, LAYER_L4); + setflag(pkt, input_flags.tcp, val); }
void odp_packet_has_sctp_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.sctp, val, LAYER_L4); + setflag(pkt, input_flags.sctp, val); }
void odp_packet_has_icmp_set(odp_packet_t pkt, int val) { - setflag(pkt, input_flags.icmp, val, LAYER_L4); + setflag(pkt, input_flags.icmp, val); }
void odp_packet_has_flow_hash_clr(odp_packet_t pkt) diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index ea9f2a75..877978ba 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -206,6 +206,8 @@ static odp_pktio_t setup_pktio_entry(const char *name, odp_pool_t pool, memcpy(&pktio_entry->s.param, param, sizeof(odp_pktio_param_t)); pktio_entry->s.handle = hdl;
+ odp_pktio_config_init(&pktio_entry->s.config); + for (pktio_if = 0; pktio_if_ops[pktio_if]; ++pktio_if) { ret = pktio_if_ops[pktio_if]->open(hdl, pktio_entry, name, pool); diff --git a/platform/linux-generic/pktio/dpdk.c b/platform/linux-generic/pktio/dpdk.c index 6ac89bd5..c52cd09d 100644 --- a/platform/linux-generic/pktio/dpdk.c +++ b/platform/linux-generic/pktio/dpdk.c @@ -653,7 +653,8 @@ static inline int mbuf_to_pkt(pktio_entry_t *pktio_entry, if (pktio_cls_enabled(pktio_entry)) copy_packet_cls_metadata(&parsed_hdr, pkt_hdr); else - packet_parse_l2(&pkt_hdr->p, pkt_len); + packet_parse_layer(pkt_hdr, + pktio_entry->s.config.parser.layer);
if (mbuf->ol_flags & PKT_RX_RSS_HASH) odp_packet_flow_hash_set(pkt, mbuf->hash.rss); diff --git a/platform/linux-generic/pktio/loop.c b/platform/linux-generic/pktio/loop.c index 61e98ad8..e9ad22ba 100644 --- a/platform/linux-generic/pktio/loop.c +++ b/platform/linux-generic/pktio/loop.c @@ -132,7 +132,8 @@ static int loopback_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, if (pktio_cls_enabled(pktio_entry)) copy_packet_cls_metadata(&parsed_hdr, pkt_hdr); else - packet_parse_l2(&pkt_hdr->p, pkt_len); + packet_parse_layer(pkt_hdr, + pktio_entry->s.config.parser.layer);
packet_set_ts(pkt_hdr, ts);
diff --git a/platform/linux-generic/pktio/netmap.c b/platform/linux-generic/pktio/netmap.c index ae3db34d..928bb00a 100644 --- a/platform/linux-generic/pktio/netmap.c +++ b/platform/linux-generic/pktio/netmap.c @@ -663,7 +663,8 @@ static inline int netmap_pkt_to_odp(pktio_entry_t *pktio_entry, if (pktio_cls_enabled(pktio_entry)) copy_packet_cls_metadata(&parsed_hdr, pkt_hdr); else - packet_parse_l2(&pkt_hdr->p, len); + packet_parse_layer(pkt_hdr, + pktio_entry->s.config.parser.layer);
packet_set_ts(pkt_hdr, ts); } diff --git a/platform/linux-generic/pktio/pcap.c b/platform/linux-generic/pktio/pcap.c index e54a56f5..a467b640 100644 --- a/platform/linux-generic/pktio/pcap.c +++ b/platform/linux-generic/pktio/pcap.c @@ -252,7 +252,8 @@ static int pcapif_recv_pkt(pktio_entry_t *pktio_entry, int index ODP_UNUSED, break; }
- packet_parse_l2(&pkt_hdr->p, pkt_len); + packet_parse_layer(pkt_hdr, + pktio_entry->s.config.parser.layer); pktio_entry->s.stats.in_octets += pkt_hdr->frame_len;
packet_set_ts(pkt_hdr, ts); diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c index a08b0104..6f8a352e 100644 --- a/platform/linux-generic/pktio/socket.c +++ b/platform/linux-generic/pktio/socket.c @@ -750,7 +750,8 @@ static int sock_mmsg_recv(pktio_entry_t *pktio_entry, int index ODP_UNUSED, }
pkt_hdr = odp_packet_hdr(pkt); - packet_parse_l2(&pkt_hdr->p, pkt_hdr->frame_len); + packet_parse_layer(pkt_hdr, + pktio_entry->s.config.parser.layer); packet_set_ts(pkt_hdr, ts); pkt_hdr->input = pktio_entry->s.handle;
diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c index fdf8cca5..2dba7b08 100644 --- a/platform/linux-generic/pktio/socket_mmap.c +++ b/platform/linux-generic/pktio/socket_mmap.c @@ -231,7 +231,8 @@ static inline unsigned pkt_mmap_v2_rx(pktio_entry_t *pktio_entry, if (pktio_cls_enabled(pktio_entry)) copy_packet_cls_metadata(&parsed_hdr, hdr); else - packet_parse_l2(&hdr->p, pkt_len); + packet_parse_layer(hdr, + pktio_entry->s.config.parser.layer);
packet_set_ts(hdr, ts);
diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c index ac204560..650c12a7 100644 --- a/platform/linux-generic/pktio/tap.c +++ b/platform/linux-generic/pktio/tap.c @@ -213,7 +213,8 @@ static odp_packet_t pack_odp_pkt(pktio_entry_t *pktio_entry, const void *data, if (pktio_cls_enabled(pktio_entry)) copy_packet_cls_metadata(&parsed_hdr, pkt_hdr); else - packet_parse_l2(&pkt_hdr->p, len); + packet_parse_layer(pkt_hdr, + pktio_entry->s.config.parser.layer);
packet_set_ts(pkt_hdr, ts); pkt_hdr->input = pktio_entry->s.handle;
commit e49f352b8cc8dd8077999e38799ba5627212ef33 Author: Maxim Uvarov maxim.uvarov@linaro.org Date: Tue May 30 16:14:57 2017 +0300
mergefix: remove duplicate declaration
Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 157a4152..a993542f 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -656,83 +656,6 @@ int odp_crypto_auth_capability(odp_auth_alg_t auth, return num; }
-int odp_crypto_cipher_capability(odp_cipher_alg_t cipher, - odp_crypto_cipher_capability_t dst[], - int num_copy) -{ - const odp_crypto_cipher_capability_t *src; - int num; - int size = sizeof(odp_crypto_cipher_capability_t); - - switch (cipher) { - case ODP_CIPHER_ALG_NULL: - src = NULL; - num = 0; - break; - case ODP_CIPHER_ALG_DES: - src = cipher_capa_des; - num = sizeof(cipher_capa_des) / size; - break; - case ODP_CIPHER_ALG_3DES_CBC: - src = cipher_capa_trides_cbc; - num = sizeof(cipher_capa_trides_cbc) / size; - break; - case ODP_CIPHER_ALG_AES_CBC: - src = cipher_capa_aes_cbc; - num = sizeof(cipher_capa_aes_cbc) / size; - break; - case ODP_CIPHER_ALG_AES_GCM: - src = cipher_capa_aes_gcm; - num = sizeof(cipher_capa_aes_gcm) / size; - break; - default: - return -1; - } - - if (num < num_copy) - num_copy = num; - - memcpy(dst, src, num_copy * size); - - return num; -} - -int odp_crypto_auth_capability(odp_auth_alg_t auth, - odp_crypto_auth_capability_t dst[], int num_copy) -{ - const odp_crypto_auth_capability_t *src; - int num; - int size = sizeof(odp_crypto_auth_capability_t); - - switch (auth) { - case ODP_AUTH_ALG_NULL: - src = NULL; - num = 0; - break; - case ODP_AUTH_ALG_MD5_HMAC: - src = auth_capa_md5_hmac; - num = sizeof(auth_capa_md5_hmac) / size; - break; - case ODP_AUTH_ALG_SHA256_HMAC: - src = auth_capa_sha256_hmac; - num = sizeof(auth_capa_sha256_hmac) / size; - break; - case ODP_AUTH_ALG_AES_GCM: - src = auth_capa_aes_gcm; - num = sizeof(auth_capa_aes_gcm) / size; - break; - default: - return -1; - } - - if (num < num_copy) - num_copy = num; - - memcpy(dst, src, num_copy * size); - - return num; -} - int odp_crypto_session_create(odp_crypto_session_param_t *param, odp_crypto_session_t *session_out,
commit 3c3dd1ac11c311d478183667a5ac6df4192ef4ec Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Mon May 15 23:24:38 2017 +0300
linux-generic: packet: add functions to optimize memset and memcmp paths
Add function implementing memset and memcmp on packet object.
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-by: <Bill Fischofer bill.fischofer@linaro.org> Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/include/odp_packet_internal.h b/platform/linux-generic/include/odp_packet_internal.h index 0a9f1779..4c8d7515 100644 --- a/platform/linux-generic/include/odp_packet_internal.h +++ b/platform/linux-generic/include/odp_packet_internal.h @@ -268,6 +268,12 @@ int packet_parse_common(packet_parser_t *pkt_hdr, const uint8_t *ptr,
int _odp_cls_parse(odp_packet_hdr_t *pkt_hdr, const uint8_t *parseptr);
+int _odp_packet_set_data(odp_packet_t pkt, uint32_t offset, + uint8_t c, uint32_t len); + +int _odp_packet_cmp_data(odp_packet_t pkt, uint32_t offset, + const void *s, uint32_t len); + #ifdef __cplusplus } #endif diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index c6962ce9..69098624 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -1665,6 +1665,54 @@ int odp_packet_move_data(odp_packet_t pkt, uint32_t dst_offset, pkt, src_offset, len); }
+int _odp_packet_set_data(odp_packet_t pkt, uint32_t offset, + uint8_t c, uint32_t len) +{ + void *mapaddr; + uint32_t seglen = 0; /* GCC */ + uint32_t setlen; + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); + + if (offset + len > pkt_hdr->frame_len) + return -1; + + while (len > 0) { + mapaddr = packet_map(pkt_hdr, offset, &seglen, NULL); + setlen = len > seglen ? seglen : len; + memset(mapaddr, c, setlen); + offset += setlen; + len -= setlen; + } + + return 0; +} + +int _odp_packet_cmp_data(odp_packet_t pkt, uint32_t offset, + const void *s, uint32_t len) +{ + const uint8_t *ptr = s; + void *mapaddr; + uint32_t seglen = 0; /* GCC */ + uint32_t cmplen; + int ret; + odp_packet_hdr_t *pkt_hdr = packet_hdr(pkt); + + ODP_ASSERT(offset + len <= pkt_hdr->frame_len); + + while (len > 0) { + mapaddr = packet_map(pkt_hdr, offset, &seglen, NULL); + cmplen = len > seglen ? seglen : len; + ret = memcmp(mapaddr, ptr, cmplen); + if (ret != 0) + return ret; + offset += cmplen; + len -= cmplen; + ptr += cmplen; + } + + return 0; +} + /* * * Debugging
commit 5dee060187c2dbda51a18e28b3691bfc50bd1882 Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Fri May 5 04:14:34 2017 +0300
linux: crypto: fix checking of GCM tags
Currently odp_crypto code will happily accept wrong tags, because the check for EVP_DecryptFinal_ex return code is incorrect. This function returns 0 if tag is incorrect, not < 0. https://bugs.linaro.org/show_bug.cgi?id=3003
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_crypto.c b/platform/linux-generic/odp_crypto.c index 6963ee62..157a4152 100644 --- a/platform/linux-generic/odp_crypto.c +++ b/platform/linux-generic/odp_crypto.c @@ -384,7 +384,7 @@ odp_crypto_alg_err_t aes_gcm_decrypt(odp_crypto_op_param_t *param, auth_len - (aad_tail - aad_head)); }
- if (EVP_DecryptFinal_ex(ctx, cipherdata + cipher_len, &plain_len) < 0) + if (EVP_DecryptFinal_ex(ctx, cipherdata + cipher_len, &plain_len) <= 0) return ODP_CRYPTO_ALG_ERR_ICV_CHECK;
return ODP_CRYPTO_ALG_ERR_NONE;
commit 7adadc917984a3e7d101a8e9d5e4f690780e8c90 Author: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Date: Fri May 5 04:13:15 2017 +0300
test: crypto: add AES-GCM tests with wrong tag value
Signed-off-by: Dmitry Eremin-Solenikov dmitry.ereminsolenikov@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c index 57e7c0e0..9defdbfa 100644 --- a/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/common_plat/validation/api/crypto/odp_crypto_test_inp.c @@ -689,10 +689,13 @@ void crypto_test_dec_alg_aes128_gcm(void) odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 }, auth_key = { .data = NULL, .length = 0 }; odp_crypto_iv_t iv = { .data = NULL, .length = AES128_GCM_IV_LEN }; + uint8_t wrong_digest[AES128_GCM_DIGEST_LEN]; unsigned int test_vec_num = (sizeof(aes128_gcm_reference_length) / sizeof(aes128_gcm_reference_length[0])); unsigned int i;
+ memset(wrong_digest, 0xa5, sizeof(wrong_digest)); + for (i = 0; i < test_vec_num; i++) { cipher_key.data = aes128_gcm_reference_key[i]; cipher_key.length = sizeof(aes128_gcm_reference_key[i]); @@ -723,6 +726,23 @@ void crypto_test_dec_alg_aes128_gcm(void) aes128_gcm_reference_ciphertext[i] + aes128_gcm_reference_length[i], AES128_GCM_CHECK_LEN); + + alg_test(ODP_CRYPTO_OP_DECODE, + 1, + ODP_CIPHER_ALG_AES_GCM, + iv, + NULL, + cipher_key, + ODP_AUTH_ALG_AES_GCM, + auth_key, + &aes128_gcm_cipher_range[i], + &aes128_gcm_auth_range[i], + aes128_gcm_reference_ciphertext[i], + aes128_gcm_reference_length[i] + AES128_GCM_CHECK_LEN, + aes128_gcm_reference_plaintext[i], + aes128_gcm_reference_length[i], + wrong_digest, + AES128_GCM_CHECK_LEN); } }
@@ -736,10 +756,13 @@ void crypto_test_dec_alg_aes128_gcm_ovr_iv(void) odp_crypto_key_t cipher_key = { .data = NULL, .length = 0 }, auth_key = { .data = NULL, .length = 0 }; odp_crypto_iv_t iv = { .data = NULL, .length = AES128_GCM_IV_LEN }; + uint8_t wrong_digest[AES128_GCM_DIGEST_LEN]; unsigned int test_vec_num = (sizeof(aes128_gcm_reference_length) / sizeof(aes128_gcm_reference_length[0])); unsigned int i;
+ memset(wrong_digest, 0xa5, sizeof(wrong_digest)); + for (i = 0; i < test_vec_num; i++) { cipher_key.data = aes128_gcm_reference_key[i]; cipher_key.length = sizeof(aes128_gcm_reference_key[i]); @@ -768,6 +791,23 @@ void crypto_test_dec_alg_aes128_gcm_ovr_iv(void) aes128_gcm_reference_ciphertext[i] + aes128_gcm_reference_length[i], AES128_GCM_CHECK_LEN); + + alg_test(ODP_CRYPTO_OP_DECODE, + 1, + ODP_CIPHER_ALG_AES_GCM, + iv, + aes128_gcm_reference_iv[i], + cipher_key, + ODP_AUTH_ALG_AES_GCM, + auth_key, + &aes128_gcm_cipher_range[i], + &aes128_gcm_auth_range[i], + aes128_gcm_reference_ciphertext[i], + aes128_gcm_reference_length[i] + AES128_GCM_CHECK_LEN, + aes128_gcm_reference_plaintext[i], + aes128_gcm_reference_length[i], + wrong_digest, + AES128_GCM_CHECK_LEN); } }
commit 85bcdeacd7631d1fa532a67ffdd47d60394a2726 Author: Petri Savolainen petri.savolainen@linaro.org Date: Fri Apr 28 15:09:58 2017 +0300
linux-gen: time: store timespec as nsec
Use single 64 bit nanosecond value to store time when using posix time. Posix time stamp is converted directly from timespec (sec + nsec) to nsec time. Storage space for odp_time_t is halved as both posix and HW time use single u64. Some functions (sum, diff, cmp) are generic for both time sources.
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/include/odp/api/plat/time_types.h b/platform/linux-generic/include/odp/api/plat/time_types.h index 1cafb1f7..71e354e6 100644 --- a/platform/linux-generic/include/odp/api/plat/time_types.h +++ b/platform/linux-generic/include/odp/api/plat/time_types.h @@ -22,32 +22,24 @@ extern "C" { **/
/** - * @internal Time structure used to isolate odp-linux implementation from - * the linux timespec structure, which is dependent on POSIX extension level. + * @internal Time structure used for both POSIX timespec and HW counter + * implementations. */ typedef struct odp_time_t { union { - /** @internal Posix timespec */ - struct { - /** @internal Seconds */ - int64_t tv_sec; - - /** @internal Nanoseconds */ - int64_t tv_nsec; - } spec; - - /** @internal HW time counter */ - struct { - /** @internal Counter value */ - uint64_t count; - - /** @internal Reserved */ - uint64_t reserved; - } hw; + /** @internal Used with generic 64 bit operations */ + uint64_t u64; + + /** @internal Nanoseconds */ + uint64_t nsec; + + /** @internal HW timer counter value */ + uint64_t count; + }; } odp_time_t;
-#define ODP_TIME_NULL ((odp_time_t){.spec = {0, 0} }) +#define ODP_TIME_NULL ((odp_time_t){.u64 = 0})
/** * @} diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c index ac82175d..2bbe5666 100644 --- a/platform/linux-generic/odp_time.c +++ b/platform/linux-generic/odp_time.c @@ -15,10 +15,10 @@ #include <inttypes.h>
typedef struct time_global_t { - odp_time_t start_time; - int use_hw; - uint64_t hw_start; - uint64_t hw_freq_hz; + struct timespec spec_start; + int use_hw; + uint64_t hw_start; + uint64_t hw_freq_hz; } time_global_t;
static time_global_t global; @@ -27,19 +27,23 @@ static time_global_t global; * Posix timespec based functions */
-static inline odp_time_t time_spec_diff(odp_time_t t2, odp_time_t t1) +static inline uint64_t time_spec_diff_nsec(struct timespec *t2, + struct timespec *t1) { - odp_time_t time; + struct timespec diff; + uint64_t nsec;
- time.spec.tv_sec = t2.spec.tv_sec - t1.spec.tv_sec; - time.spec.tv_nsec = t2.spec.tv_nsec - t1.spec.tv_nsec; + diff.tv_sec = t2->tv_sec - t1->tv_sec; + diff.tv_nsec = t2->tv_nsec - t1->tv_nsec;
- if (time.spec.tv_nsec < 0) { - time.spec.tv_nsec += ODP_TIME_SEC_IN_NS; - --time.spec.tv_sec; + if (diff.tv_nsec < 0) { + diff.tv_nsec += ODP_TIME_SEC_IN_NS; + diff.tv_sec -= 1; }
- return time; + nsec = (diff.tv_sec * ODP_TIME_SEC_IN_NS) + diff.tv_nsec; + + return nsec; }
static inline odp_time_t time_spec_cur(void) @@ -52,10 +56,9 @@ static inline odp_time_t time_spec_cur(void) if (odp_unlikely(ret != 0)) ODP_ABORT("clock_gettime failed\n");
- time.spec.tv_sec = sys_time.tv_sec; - time.spec.tv_nsec = sys_time.tv_nsec; + time.nsec = time_spec_diff_nsec(&sys_time, &global.spec_start);
- return time_spec_diff(time, global.start_time); + return time; }
static inline uint64_t time_spec_res(void) @@ -70,48 +73,16 @@ static inline uint64_t time_spec_res(void) return ODP_TIME_SEC_IN_NS / (uint64_t)tres.tv_nsec; }
-static inline int time_spec_cmp(odp_time_t t2, odp_time_t t1) -{ - if (t2.spec.tv_sec < t1.spec.tv_sec) - return -1; - - if (t2.spec.tv_sec > t1.spec.tv_sec) - return 1; - - return t2.spec.tv_nsec - t1.spec.tv_nsec; -} - -static inline odp_time_t time_spec_sum(odp_time_t t1, odp_time_t t2) -{ - odp_time_t time; - - time.spec.tv_sec = t2.spec.tv_sec + t1.spec.tv_sec; - time.spec.tv_nsec = t2.spec.tv_nsec + t1.spec.tv_nsec; - - if (time.spec.tv_nsec >= (long)ODP_TIME_SEC_IN_NS) { - time.spec.tv_nsec -= ODP_TIME_SEC_IN_NS; - ++time.spec.tv_sec; - } - - return time; -} - static inline uint64_t time_spec_to_ns(odp_time_t time) { - uint64_t ns; - - ns = time.spec.tv_sec * ODP_TIME_SEC_IN_NS; - ns += time.spec.tv_nsec; - - return ns; + return time.nsec; }
static inline odp_time_t time_spec_from_ns(uint64_t ns) { odp_time_t time;
- time.spec.tv_sec = ns / ODP_TIME_SEC_IN_NS; - time.spec.tv_nsec = ns - time.spec.tv_sec * ODP_TIME_SEC_IN_NS; + time.nsec = ns;
return time; } @@ -124,7 +95,7 @@ static inline odp_time_t time_hw_cur(void) { odp_time_t time;
- time.hw.count = cpu_global_time() - global.hw_start; + time.count = cpu_global_time() - global.hw_start;
return time; } @@ -136,40 +107,11 @@ static inline uint64_t time_hw_res(void) return global.hw_freq_hz / 10; }
-static inline int time_hw_cmp(odp_time_t t2, odp_time_t t1) -{ - if (odp_likely(t2.hw.count > t1.hw.count)) - return 1; - - if (t2.hw.count < t1.hw.count) - return -1; - - return 0; -} - -static inline odp_time_t time_hw_diff(odp_time_t t2, odp_time_t t1) -{ - odp_time_t time; - - time.hw.count = t2.hw.count - t1.hw.count; - - return time; -} - -static inline odp_time_t time_hw_sum(odp_time_t t1, odp_time_t t2) -{ - odp_time_t time; - - time.hw.count = t1.hw.count + t2.hw.count; - - return time; -} - static inline uint64_t time_hw_to_ns(odp_time_t time) { uint64_t nsec; uint64_t freq_hz = global.hw_freq_hz; - uint64_t count = time.hw.count; + uint64_t count = time.count; uint64_t sec = 0;
if (count >= freq_hz) { @@ -197,8 +139,7 @@ static inline odp_time_t time_hw_from_ns(uint64_t ns) count = sec * freq_hz; count += (ns * freq_hz) / ODP_TIME_SEC_IN_NS;
- time.hw.reserved = 0; - time.hw.count = count; + time.count = count;
return time; } @@ -225,26 +166,22 @@ static inline uint64_t time_res(void)
static inline int time_cmp(odp_time_t t2, odp_time_t t1) { - if (global.use_hw) - return time_hw_cmp(t2, t1); - - return time_spec_cmp(t2, t1); -} + if (odp_likely(t2.u64 > t1.u64)) + return 1;
-static inline odp_time_t time_diff(odp_time_t t2, odp_time_t t1) -{ - if (global.use_hw) - return time_hw_diff(t2, t1); + if (t2.u64 < t1.u64) + return -1;
- return time_spec_diff(t2, t1); + return 0; }
static inline odp_time_t time_sum(odp_time_t t1, odp_time_t t2) { - if (global.use_hw) - return time_hw_sum(t1, t2); + odp_time_t time; + + time.u64 = t1.u64 + t2.u64;
- return time_spec_sum(t1, t2); + return time; }
static inline uint64_t time_to_ns(odp_time_t time) @@ -284,7 +221,11 @@ odp_time_t odp_time_global(void)
odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1) { - return time_diff(t2, t1); + odp_time_t time; + + time.u64 = t2.u64 - t1.u64; + + return time; }
uint64_t odp_time_to_ns(odp_time_t time) @@ -338,7 +279,6 @@ void odp_time_wait_until(odp_time_t time)
int odp_time_init_global(void) { - struct timespec sys_time; int ret = 0;
memset(&global, 0, sizeof(time_global_t)); @@ -357,13 +297,10 @@ int odp_time_init_global(void) return 0; }
- global.start_time = ODP_TIME_NULL; + global.spec_start.tv_sec = 0; + global.spec_start.tv_nsec = 0;
- ret = clock_gettime(CLOCK_MONOTONIC_RAW, &sys_time); - if (ret == 0) { - global.start_time.spec.tv_sec = sys_time.tv_sec; - global.start_time.spec.tv_nsec = sys_time.tv_nsec; - } + ret = clock_gettime(CLOCK_MONOTONIC_RAW, &global.spec_start);
return ret; }
commit 31db23d6ed4116c1fd37bfef5c6e95c952e7d7d0 Author: Petri Savolainen petri.savolainen@linaro.org Date: Fri Apr 28 15:09:57 2017 +0300
linux-gen: time: improve x86 TSC freq measurement accuracy
Add short warm up round and measure over a longer period of time (250ms vs 100ms).
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/arch/x86/odp_cpu_arch.c b/platform/linux-generic/arch/x86/odp_cpu_arch.c index 9ba601a3..b1da428b 100644 --- a/platform/linux-generic/arch/x86/odp_cpu_arch.c +++ b/platform/linux-generic/arch/x86/odp_cpu_arch.c @@ -54,11 +54,16 @@ uint64_t cpu_global_time_freq(void) uint64_t t1, t2, ts_nsec, cycles, hz; int i; uint64_t avg = 0; - int rounds = 4; + int rounds = 3; + int warm_up = 1;
for (i = 0; i < rounds; i++) { - sleep.tv_sec = 0; - sleep.tv_nsec = SEC_IN_NS / 10; + sleep.tv_sec = 0; + + if (warm_up) + sleep.tv_nsec = SEC_IN_NS / 1000; + else + sleep.tv_nsec = SEC_IN_NS / 4;
if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts1)) { ODP_DBG("clock_gettime failed\n"); @@ -85,8 +90,12 @@ uint64_t cpu_global_time_freq(void) cycles = t2 - t1;
hz = (cycles * SEC_IN_NS) / ts_nsec; - avg += hz; + + if (warm_up) + warm_up = 0; + else + avg += hz; }
- return avg / rounds; + return avg / (rounds - 1); }
commit 125fb2967f412934e7162d86630437cfa08c2397 Author: Petri Savolainen petri.savolainen@linaro.org Date: Fri Apr 28 15:09:56 2017 +0300
linux-gen: time: use hw time counter when available
Use 64 bit HW time counter when available. It is used on x86 when invariant TSC CPU flag indicates that TSC frequency is constant. Otherwise, the system time is used as before. Direct HW time counter usage avoids system call, and related latency and performance issues.
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 4262b25d..5cfa0028 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -147,6 +147,7 @@ noinst_HEADERS = \ ${srcdir}/include/odp_schedule_if.h \ ${srcdir}/include/odp_sorted_list_internal.h \ ${srcdir}/include/odp_shm_internal.h \ + ${srcdir}/include/odp_time_internal.h \ ${srcdir}/include/odp_timer_internal.h \ ${srcdir}/include/odp_timer_wheel_internal.h \ ${srcdir}/include/odp_traffic_mngr_internal.h \ diff --git a/platform/linux-generic/arch/arm/odp_cpu_arch.c b/platform/linux-generic/arch/arm/odp_cpu_arch.c index 2ac223e0..c31f9084 100644 --- a/platform/linux-generic/arch/arm/odp_cpu_arch.c +++ b/platform/linux-generic/arch/arm/odp_cpu_arch.c @@ -13,6 +13,7 @@ #include <odp/api/hints.h> #include <odp/api/system_info.h> #include <odp_debug_internal.h> +#include <odp_time_internal.h>
#define GIGA 1000000000
@@ -46,3 +47,18 @@ uint64_t odp_cpu_cycles_resolution(void) { return 1; } + +int cpu_has_global_time(void) +{ + return 0; +} + +uint64_t cpu_global_time(void) +{ + return 0; +} + +uint64_t cpu_global_time_freq(void) +{ + return 0; +} diff --git a/platform/linux-generic/arch/default/odp_cpu_arch.c b/platform/linux-generic/arch/default/odp_cpu_arch.c index 2ac223e0..c31f9084 100644 --- a/platform/linux-generic/arch/default/odp_cpu_arch.c +++ b/platform/linux-generic/arch/default/odp_cpu_arch.c @@ -13,6 +13,7 @@ #include <odp/api/hints.h> #include <odp/api/system_info.h> #include <odp_debug_internal.h> +#include <odp_time_internal.h>
#define GIGA 1000000000
@@ -46,3 +47,18 @@ uint64_t odp_cpu_cycles_resolution(void) { return 1; } + +int cpu_has_global_time(void) +{ + return 0; +} + +uint64_t cpu_global_time(void) +{ + return 0; +} + +uint64_t cpu_global_time_freq(void) +{ + return 0; +} diff --git a/platform/linux-generic/arch/mips64/odp_cpu_arch.c b/platform/linux-generic/arch/mips64/odp_cpu_arch.c index 646acf9c..f7eafa0f 100644 --- a/platform/linux-generic/arch/mips64/odp_cpu_arch.c +++ b/platform/linux-generic/arch/mips64/odp_cpu_arch.c @@ -7,6 +7,7 @@ #include <odp/api/cpu.h> #include <odp/api/hints.h> #include <odp/api/system_info.h> +#include <odp_time_internal.h>
uint64_t odp_cpu_cycles(void) { @@ -29,3 +30,18 @@ uint64_t odp_cpu_cycles_resolution(void) { return 1; } + +int cpu_has_global_time(void) +{ + return 0; +} + +uint64_t cpu_global_time(void) +{ + return 0; +} + +uint64_t cpu_global_time_freq(void) +{ + return 0; +} diff --git a/platform/linux-generic/arch/powerpc/odp_cpu_arch.c b/platform/linux-generic/arch/powerpc/odp_cpu_arch.c index 2ac223e0..c31f9084 100644 --- a/platform/linux-generic/arch/powerpc/odp_cpu_arch.c +++ b/platform/linux-generic/arch/powerpc/odp_cpu_arch.c @@ -13,6 +13,7 @@ #include <odp/api/hints.h> #include <odp/api/system_info.h> #include <odp_debug_internal.h> +#include <odp_time_internal.h>
#define GIGA 1000000000
@@ -46,3 +47,18 @@ uint64_t odp_cpu_cycles_resolution(void) { return 1; } + +int cpu_has_global_time(void) +{ + return 0; +} + +uint64_t cpu_global_time(void) +{ + return 0; +} + +uint64_t cpu_global_time_freq(void) +{ + return 0; +} diff --git a/platform/linux-generic/arch/x86/cpu_flags.c b/platform/linux-generic/arch/x86/cpu_flags.c index 954dac27..a492a35b 100644 --- a/platform/linux-generic/arch/x86/cpu_flags.c +++ b/platform/linux-generic/arch/x86/cpu_flags.c @@ -39,6 +39,7 @@
#include <arch/x86/cpu_flags.h> #include <odp_debug_internal.h> +#include <odp_time_internal.h> #include <stdio.h> #include <stdint.h>
@@ -357,3 +358,11 @@ void cpu_flags_print_all(void) str[len] = '\0'; ODP_PRINT("%s", str); } + +int cpu_has_global_time(void) +{ + if (cpu_get_flag_enabled(RTE_CPUFLAG_INVTSC) > 0) + return 1; + + return 0; +} diff --git a/platform/linux-generic/arch/x86/odp_cpu_arch.c b/platform/linux-generic/arch/x86/odp_cpu_arch.c index c8cf27b6..9ba601a3 100644 --- a/platform/linux-generic/arch/x86/odp_cpu_arch.c +++ b/platform/linux-generic/arch/x86/odp_cpu_arch.c @@ -3,7 +3,14 @@ * * SPDX-License-Identifier: BSD-3-Clause */ + +#include <odp_posix_extensions.h> + #include <odp/api/cpu.h> +#include <odp_time_internal.h> +#include <odp_debug_internal.h> + +#include <time.h>
uint64_t odp_cpu_cycles(void) { @@ -31,3 +38,55 @@ uint64_t odp_cpu_cycles_resolution(void) { return 1; } + +uint64_t cpu_global_time(void) +{ + return odp_cpu_cycles(); +} + +#define SEC_IN_NS 1000000000ULL + +/* Measure TSC frequency. Frequency information registers are defined for x86, + * but those are often not enumerated. */ +uint64_t cpu_global_time_freq(void) +{ + struct timespec sleep, ts1, ts2; + uint64_t t1, t2, ts_nsec, cycles, hz; + int i; + uint64_t avg = 0; + int rounds = 4; + + for (i = 0; i < rounds; i++) { + sleep.tv_sec = 0; + sleep.tv_nsec = SEC_IN_NS / 10; + + if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts1)) { + ODP_DBG("clock_gettime failed\n"); + return 0; + } + + t1 = cpu_global_time(); + + if (nanosleep(&sleep, NULL) < 0) { + ODP_DBG("nanosleep failed\n"); + return 0; + } + + if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts2)) { + ODP_DBG("clock_gettime failed\n"); + return 0; + } + + t2 = cpu_global_time(); + + ts_nsec = (ts2.tv_sec - ts1.tv_sec) * SEC_IN_NS; + ts_nsec += ts2.tv_nsec - ts1.tv_nsec; + + cycles = t2 - t1; + + hz = (cycles * SEC_IN_NS) / ts_nsec; + avg += hz; + } + + return avg / rounds; +} diff --git a/platform/linux-generic/include/odp/api/plat/time_types.h b/platform/linux-generic/include/odp/api/plat/time_types.h index 4847f3b1..1cafb1f7 100644 --- a/platform/linux-generic/include/odp/api/plat/time_types.h +++ b/platform/linux-generic/include/odp/api/plat/time_types.h @@ -26,11 +26,28 @@ extern "C" { * the linux timespec structure, which is dependent on POSIX extension level. */ typedef struct odp_time_t { - int64_t tv_sec; /**< @internal Seconds */ - int64_t tv_nsec; /**< @internal Nanoseconds */ + union { + /** @internal Posix timespec */ + struct { + /** @internal Seconds */ + int64_t tv_sec; + + /** @internal Nanoseconds */ + int64_t tv_nsec; + } spec; + + /** @internal HW time counter */ + struct { + /** @internal Counter value */ + uint64_t count; + + /** @internal Reserved */ + uint64_t reserved; + } hw; + }; } odp_time_t;
-#define ODP_TIME_NULL ((odp_time_t){0, 0}) +#define ODP_TIME_NULL ((odp_time_t){.spec = {0, 0} })
/** * @} diff --git a/platform/linux-generic/include/odp_time_internal.h b/platform/linux-generic/include/odp_time_internal.h new file mode 100644 index 00000000..99ac7977 --- /dev/null +++ b/platform/linux-generic/include/odp_time_internal.h @@ -0,0 +1,24 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_TIME_INTERNAL_H_ +#define ODP_TIME_INTERNAL_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +int cpu_has_global_time(void); +uint64_t cpu_global_time(void); +uint64_t cpu_global_time_freq(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c index 0e5966c0..ac82175d 100644 --- a/platform/linux-generic/odp_time.c +++ b/platform/linux-generic/odp_time.c @@ -10,36 +10,39 @@ #include <odp/api/time.h> #include <odp/api/hints.h> #include <odp_debug_internal.h> +#include <odp_time_internal.h> +#include <string.h> +#include <inttypes.h>
-static odp_time_t start_time; +typedef struct time_global_t { + odp_time_t start_time; + int use_hw; + uint64_t hw_start; + uint64_t hw_freq_hz; +} time_global_t;
-static inline -uint64_t time_to_ns(odp_time_t time) -{ - uint64_t ns; - - ns = time.tv_sec * ODP_TIME_SEC_IN_NS; - ns += time.tv_nsec; +static time_global_t global;
- return ns; -} +/* + * Posix timespec based functions + */
-static inline odp_time_t time_diff(odp_time_t t2, odp_time_t t1) +static inline odp_time_t time_spec_diff(odp_time_t t2, odp_time_t t1) { odp_time_t time;
- time.tv_sec = t2.tv_sec - t1.tv_sec; - time.tv_nsec = t2.tv_nsec - t1.tv_nsec; + time.spec.tv_sec = t2.spec.tv_sec - t1.spec.tv_sec; + time.spec.tv_nsec = t2.spec.tv_nsec - t1.spec.tv_nsec;
- if (time.tv_nsec < 0) { - time.tv_nsec += ODP_TIME_SEC_IN_NS; - --time.tv_sec; + if (time.spec.tv_nsec < 0) { + time.spec.tv_nsec += ODP_TIME_SEC_IN_NS; + --time.spec.tv_sec; }
return time; }
-static inline odp_time_t time_local(void) +static inline odp_time_t time_spec_cur(void) { int ret; odp_time_t time; @@ -49,77 +52,234 @@ static inline odp_time_t time_local(void) if (odp_unlikely(ret != 0)) ODP_ABORT("clock_gettime failed\n");
- time.tv_sec = sys_time.tv_sec; - time.tv_nsec = sys_time.tv_nsec; + time.spec.tv_sec = sys_time.tv_sec; + time.spec.tv_nsec = sys_time.tv_nsec;
- return time_diff(time, start_time); + return time_spec_diff(time, global.start_time); }
-static inline int time_cmp(odp_time_t t2, odp_time_t t1) +static inline uint64_t time_spec_res(void) { - if (t2.tv_sec < t1.tv_sec) + int ret; + struct timespec tres; + + ret = clock_getres(CLOCK_MONOTONIC_RAW, &tres); + if (odp_unlikely(ret != 0)) + ODP_ABORT("clock_getres failed\n"); + + return ODP_TIME_SEC_IN_NS / (uint64_t)tres.tv_nsec; +} + +static inline int time_spec_cmp(odp_time_t t2, odp_time_t t1) +{ + if (t2.spec.tv_sec < t1.spec.tv_sec) return -1;
- if (t2.tv_sec > t1.tv_sec) + if (t2.spec.tv_sec > t1.spec.tv_sec) return 1;
- return t2.tv_nsec - t1.tv_nsec; + return t2.spec.tv_nsec - t1.spec.tv_nsec; }
-static inline odp_time_t time_sum(odp_time_t t1, odp_time_t t2) +static inline odp_time_t time_spec_sum(odp_time_t t1, odp_time_t t2) { odp_time_t time;
- time.tv_sec = t2.tv_sec + t1.tv_sec; - time.tv_nsec = t2.tv_nsec + t1.tv_nsec; + time.spec.tv_sec = t2.spec.tv_sec + t1.spec.tv_sec; + time.spec.tv_nsec = t2.spec.tv_nsec + t1.spec.tv_nsec;
- if (time.tv_nsec >= (long)ODP_TIME_SEC_IN_NS) { - time.tv_nsec -= ODP_TIME_SEC_IN_NS; - ++time.tv_sec; + if (time.spec.tv_nsec >= (long)ODP_TIME_SEC_IN_NS) { + time.spec.tv_nsec -= ODP_TIME_SEC_IN_NS; + ++time.spec.tv_sec; }
return time; }
-static inline odp_time_t time_local_from_ns(uint64_t ns) +static inline uint64_t time_spec_to_ns(odp_time_t time) +{ + uint64_t ns; + + ns = time.spec.tv_sec * ODP_TIME_SEC_IN_NS; + ns += time.spec.tv_nsec; + + return ns; +} + +static inline odp_time_t time_spec_from_ns(uint64_t ns) { odp_time_t time;
- time.tv_sec = ns / ODP_TIME_SEC_IN_NS; - time.tv_nsec = ns - time.tv_sec * ODP_TIME_SEC_IN_NS; + time.spec.tv_sec = ns / ODP_TIME_SEC_IN_NS; + time.spec.tv_nsec = ns - time.spec.tv_sec * ODP_TIME_SEC_IN_NS;
return time; }
-static inline void time_wait_until(odp_time_t time) +/* + * HW time counter based functions + */ + +static inline odp_time_t time_hw_cur(void) { - odp_time_t cur; + odp_time_t time;
- do { - cur = time_local(); - } while (time_cmp(time, cur) > 0); + time.hw.count = cpu_global_time() - global.hw_start; + + return time; }
-static inline uint64_t time_local_res(void) +static inline uint64_t time_hw_res(void) { - int ret; - struct timespec tres; + /* Promise a bit lower resolution than average cycle counter + * frequency */ + return global.hw_freq_hz / 10; +}
- ret = clock_getres(CLOCK_MONOTONIC_RAW, &tres); - if (odp_unlikely(ret != 0)) - ODP_ABORT("clock_getres failed\n"); +static inline int time_hw_cmp(odp_time_t t2, odp_time_t t1) +{ + if (odp_likely(t2.hw.count > t1.hw.count)) + return 1;
- return ODP_TIME_SEC_IN_NS / (uint64_t)tres.tv_nsec; + if (t2.hw.count < t1.hw.count) + return -1; + + return 0; +} + +static inline odp_time_t time_hw_diff(odp_time_t t2, odp_time_t t1) +{ + odp_time_t time; + + time.hw.count = t2.hw.count - t1.hw.count; + + return time; +} + +static inline odp_time_t time_hw_sum(odp_time_t t1, odp_time_t t2) +{ + odp_time_t time; + + time.hw.count = t1.hw.count + t2.hw.count; + + return time; +} + +static inline uint64_t time_hw_to_ns(odp_time_t time) +{ + uint64_t nsec; + uint64_t freq_hz = global.hw_freq_hz; + uint64_t count = time.hw.count; + uint64_t sec = 0; + + if (count >= freq_hz) { + sec = count / freq_hz; + count = count - sec * freq_hz; + } + + nsec = (ODP_TIME_SEC_IN_NS * count) / freq_hz; + + return (sec * ODP_TIME_SEC_IN_NS) + nsec; +} + +static inline odp_time_t time_hw_from_ns(uint64_t ns) +{ + odp_time_t time; + uint64_t count; + uint64_t freq_hz = global.hw_freq_hz; + uint64_t sec = 0; + + if (ns >= ODP_TIME_SEC_IN_NS) { + sec = ns / ODP_TIME_SEC_IN_NS; + ns = ns - sec * ODP_TIME_SEC_IN_NS; + } + + count = sec * freq_hz; + count += (ns * freq_hz) / ODP_TIME_SEC_IN_NS; + + time.hw.reserved = 0; + time.hw.count = count; + + return time; +} + +/* + * Common functions + */ + +static inline odp_time_t time_cur(void) +{ + if (global.use_hw) + return time_hw_cur(); + + return time_spec_cur(); +} + +static inline uint64_t time_res(void) +{ + if (global.use_hw) + return time_hw_res(); + + return time_spec_res(); +} + +static inline int time_cmp(odp_time_t t2, odp_time_t t1) +{ + if (global.use_hw) + return time_hw_cmp(t2, t1); + + return time_spec_cmp(t2, t1); +} + +static inline odp_time_t time_diff(odp_time_t t2, odp_time_t t1) +{ + if (global.use_hw) + return time_hw_diff(t2, t1); + + return time_spec_diff(t2, t1); +} + +static inline odp_time_t time_sum(odp_time_t t1, odp_time_t t2) +{ + if (global.use_hw) + return time_hw_sum(t1, t2); + + return time_spec_sum(t1, t2); +} + +static inline uint64_t time_to_ns(odp_time_t time) +{ + if (global.use_hw) + return time_hw_to_ns(time); + + return time_spec_to_ns(time); +} + +static inline odp_time_t time_from_ns(uint64_t ns) +{ + if (global.use_hw) + return time_hw_from_ns(ns); + + return time_spec_from_ns(ns); +} + +static inline void time_wait_until(odp_time_t time) +{ + odp_time_t cur; + + do { + cur = time_cur(); + } while (time_cmp(time, cur) > 0); }
odp_time_t odp_time_local(void) { - return time_local(); + return time_cur(); }
odp_time_t odp_time_global(void) { - return time_local(); + return time_cur(); }
odp_time_t odp_time_diff(odp_time_t t2, odp_time_t t1) @@ -134,12 +294,12 @@ uint64_t odp_time_to_ns(odp_time_t time)
odp_time_t odp_time_local_from_ns(uint64_t ns) { - return time_local_from_ns(ns); + return time_from_ns(ns); }
odp_time_t odp_time_global_from_ns(uint64_t ns) { - return time_local_from_ns(ns); + return time_from_ns(ns); }
int odp_time_cmp(odp_time_t t2, odp_time_t t1) @@ -154,18 +314,18 @@ odp_time_t odp_time_sum(odp_time_t t1, odp_time_t t2)
uint64_t odp_time_local_res(void) { - return time_local_res(); + return time_res(); }
uint64_t odp_time_global_res(void) { - return time_local_res(); + return time_res(); }
void odp_time_wait_ns(uint64_t ns) { - odp_time_t cur = time_local(); - odp_time_t wait = time_local_from_ns(ns); + odp_time_t cur = time_cur(); + odp_time_t wait = time_from_ns(ns); odp_time_t end_time = time_sum(cur, wait);
time_wait_until(end_time); @@ -178,15 +338,31 @@ void odp_time_wait_until(odp_time_t time)
int odp_time_init_global(void) { - int ret; - struct timespec time; - - ret = clock_gettime(CLOCK_MONOTONIC_RAW, &time); - if (ret) { - start_time = ODP_TIME_NULL; - } else { - start_time.tv_sec = time.tv_sec; - start_time.tv_nsec = time.tv_nsec; + struct timespec sys_time; + int ret = 0; + + memset(&global, 0, sizeof(time_global_t)); + + if (cpu_has_global_time()) { + global.use_hw = 1; + global.hw_freq_hz = cpu_global_time_freq(); + + if (global.hw_freq_hz == 0) + return -1; + + printf("HW time counter freq: %" PRIu64 " hz\n\n", + global.hw_freq_hz); + + global.hw_start = cpu_global_time(); + return 0; + } + + global.start_time = ODP_TIME_NULL; + + ret = clock_gettime(CLOCK_MONOTONIC_RAW, &sys_time); + if (ret == 0) { + global.start_time.spec.tv_sec = sys_time.tv_sec; + global.start_time.spec.tv_nsec = sys_time.tv_nsec; }
return ret;
commit 86f1e0fb0cbb938875b273dab3d396ecd8634a17 Author: Petri Savolainen petri.savolainen@linaro.org Date: Fri Apr 28 15:09:55 2017 +0300
test: validation: add time accuracy test
Test ODP time keeping accuracy against system time.
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/validation/api/time/time.c b/test/common_plat/validation/api/time/time.c index 36c419cb..e2ca2e17 100644 --- a/test/common_plat/validation/api/time/time.c +++ b/test/common_plat/validation/api/time/time.c @@ -7,6 +7,7 @@ #include <odp_api.h> #include "odp_cunit_common.h" #include "time_test.h" +#include <time.h>
#define BUSY_LOOP_CNT 30000000 /* used for t > min resolution */ #define BUSY_LOOP_CNT_LONG 6000000000 /* used for t > 4 sec */ @@ -140,25 +141,25 @@ void time_test_monotony(void) CU_ASSERT(ns3 > ns2); }
-static void time_test_cmp(time_cb time, time_from_ns_cb time_from_ns) +static void time_test_cmp(time_cb time_cur, time_from_ns_cb time_from_ns) { /* volatile to stop optimization of busy loop */ volatile int count = 0; odp_time_t t1, t2, t3;
- t1 = time(); + t1 = time_cur();
while (count < BUSY_LOOP_CNT) { count++; };
- t2 = time(); + t2 = time_cur();
while (count < BUSY_LOOP_CNT * 2) { count++; };
- t3 = time(); + t3 = time_cur();
CU_ASSERT(odp_time_cmp(t2, t1) > 0); CU_ASSERT(odp_time_cmp(t3, t2) > 0); @@ -191,7 +192,7 @@ void time_test_global_cmp(void) }
/* check that a time difference gives a reasonable result */ -static void time_test_diff(time_cb time, +static void time_test_diff(time_cb time_cur, time_from_ns_cb time_from_ns, uint64_t res) { @@ -202,13 +203,13 @@ static void time_test_diff(time_cb time, uint64_t upper_limit, lower_limit;
/* test timestamp diff */ - t1 = time(); + t1 = time_cur();
while (count < BUSY_LOOP_CNT) { count++; };
- t2 = time(); + t2 = time_cur(); CU_ASSERT(odp_time_cmp(t2, t1) > 0);
diff = odp_time_diff(t2, t1); @@ -268,7 +269,7 @@ void time_test_global_diff(void) }
/* check that a time sum gives a reasonable result */ -static void time_test_sum(time_cb time, +static void time_test_sum(time_cb time_cur, time_from_ns_cb time_from_ns, uint64_t res) { @@ -277,7 +278,7 @@ static void time_test_sum(time_cb time, uint64_t upper_limit, lower_limit;
/* sum timestamp and interval */ - t1 = time(); + t1 = time_cur(); ns2 = 103; t2 = time_from_ns(ns2); ns1 = odp_time_to_ns(t1); @@ -319,20 +320,20 @@ void time_test_global_sum(void) time_test_sum(odp_time_global, odp_time_global_from_ns, global_res); }
-static void time_test_wait_until(time_cb time, time_from_ns_cb time_from_ns) +static void time_test_wait_until(time_cb time_cur, time_from_ns_cb time_from_ns) { int i; odp_time_t lower_limit, upper_limit; odp_time_t start_time, end_time, wait; odp_time_t second = time_from_ns(ODP_TIME_SEC_IN_NS);
- start_time = time(); + start_time = time_cur(); wait = start_time; for (i = 0; i < WAIT_SECONDS; i++) { wait = odp_time_sum(wait, second); odp_time_wait_until(wait); } - end_time = time(); + end_time = time_cur();
wait = odp_time_diff(end_time, start_time); lower_limit = time_from_ns(WAIT_SECONDS * ODP_TIME_SEC_IN_NS - @@ -398,6 +399,45 @@ void time_test_wait_ns(void) } }
+static void time_test_accuracy(time_cb time_cur, time_from_ns_cb time_from_ns) +{ + int i; + odp_time_t t1, t2, wait, diff; + clock_t c1, c2; + double sec_t, sec_c; + odp_time_t sec = time_from_ns(ODP_TIME_SEC_IN_NS); + + c1 = clock(); + t1 = time_cur(); + + wait = odp_time_sum(t1, sec); + for (i = 0; i < 5; i++) { + odp_time_wait_until(wait); + wait = odp_time_sum(wait, sec); + } + + t2 = time_cur(); + c2 = clock(); + + diff = odp_time_diff(t2, t1); + sec_t = ((double)odp_time_to_ns(diff)) / ODP_TIME_SEC_IN_NS; + sec_c = ((double)(c2 - c1)) / CLOCKS_PER_SEC; + + /* Check that ODP time is within +-5% of system time */ + CU_ASSERT(sec_t < sec_c * 1.05); + CU_ASSERT(sec_t > sec_c * 0.95); +} + +static void time_test_local_accuracy(void) +{ + time_test_accuracy(odp_time_local, odp_time_local_from_ns); +} + +static void time_test_global_accuracy(void) +{ + time_test_accuracy(odp_time_global, odp_time_global_from_ns); +} + odp_testinfo_t time_suite_time[] = { ODP_TEST_INFO(time_test_constants), ODP_TEST_INFO(time_test_local_res), @@ -408,12 +448,14 @@ odp_testinfo_t time_suite_time[] = { ODP_TEST_INFO(time_test_local_sum), ODP_TEST_INFO(time_test_local_wait_until), ODP_TEST_INFO(time_test_wait_ns), + ODP_TEST_INFO(time_test_local_accuracy), ODP_TEST_INFO(time_test_global_res), ODP_TEST_INFO(time_test_global_conversion), ODP_TEST_INFO(time_test_global_cmp), ODP_TEST_INFO(time_test_global_diff), ODP_TEST_INFO(time_test_global_sum), ODP_TEST_INFO(time_test_global_wait_until), + ODP_TEST_INFO(time_test_global_accuracy), ODP_TEST_INFO_NULL };
commit b9946c8372014ddce127cf2c74ef825ab80ff0aa Author: Petri Savolainen petri.savolainen@linaro.org Date: Fri Apr 28 15:09:54 2017 +0300
test: validation: rename time test header file
Header file name time.h is ambiguos since C has a library header file with the same name.
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/validation/api/time/Makefile.am b/test/common_plat/validation/api/time/Makefile.am index bf2d0268..999fcf15 100644 --- a/test/common_plat/validation/api/time/Makefile.am +++ b/test/common_plat/validation/api/time/Makefile.am @@ -7,4 +7,4 @@ test_PROGRAMS = time_main$(EXEEXT) dist_time_main_SOURCES = time_main.c time_main_LDADD = libtesttime.la $(LIBCUNIT_COMMON) $(LIBODP)
-EXTRA_DIST = time.h +EXTRA_DIST = time_test.h diff --git a/test/common_plat/validation/api/time/time.c b/test/common_plat/validation/api/time/time.c index df65c719..36c419cb 100644 --- a/test/common_plat/validation/api/time/time.c +++ b/test/common_plat/validation/api/time/time.c @@ -6,7 +6,7 @@
#include <odp_api.h> #include "odp_cunit_common.h" -#include "time.h" +#include "time_test.h"
#define BUSY_LOOP_CNT 30000000 /* used for t > min resolution */ #define BUSY_LOOP_CNT_LONG 6000000000 /* used for t > 4 sec */ diff --git a/test/common_plat/validation/api/time/time_main.c b/test/common_plat/validation/api/time/time_main.c index f86d638a..bf1cfe7b 100644 --- a/test/common_plat/validation/api/time/time_main.c +++ b/test/common_plat/validation/api/time/time_main.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-3-Clause */
-#include "time.h" +#include "time_test.h"
int main(int argc, char *argv[]) { diff --git a/test/common_plat/validation/api/time/time.h b/test/common_plat/validation/api/time/time_test.h similarity index 100% rename from test/common_plat/validation/api/time/time.h rename to test/common_plat/validation/api/time/time_test.h
commit 6e651715d36571b884cb4d272f4a91bbc1ba9beb Author: Petri Savolainen petri.savolainen@linaro.org Date: Fri Apr 28 15:09:53 2017 +0300
test: sched_latency: use sys_info_print
Use the new system info print function.
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/performance/odp_sched_latency.c b/test/common_plat/performance/odp_sched_latency.c index b4018687..026f2f6c 100644 --- a/test/common_plat/performance/odp_sched_latency.c +++ b/test/common_plat/performance/odp_sched_latency.c @@ -667,16 +667,7 @@ int main(int argc, char *argv[]) return -1; }
- printf("\n"); - printf("ODP system info\n"); - printf("---------------\n"); - printf("ODP API version: %s\n", odp_version_api_str()); - printf("ODP impl name: %s\n", odp_version_impl_name()); - printf("ODP impl details: %s\n", odp_version_impl_str()); - printf("CPU model: %s\n", odp_cpu_model_str()); - printf("CPU freq (hz): %" PRIu64 "\n", odp_cpu_hz_max()); - printf("Cache line size: %i\n", odp_sys_cache_line_size()); - printf("Max CPU count: %i\n", odp_cpu_count()); + odp_sys_info_print();
/* Get default worker cpumask */ if (args.cpu_count) @@ -687,9 +678,10 @@ int main(int argc, char *argv[])
(void)odp_cpumask_to_str(&cpumask, cpumaskstr, sizeof(cpumaskstr));
- printf("Worker threads: %i\n", num_workers); - printf("First CPU: %i\n", odp_cpumask_first(&cpumask)); - printf("CPU mask: %s\n\n", cpumaskstr); + printf("CPU mask info:\n"); + printf(" Worker threads: %i\n", num_workers); + printf(" First CPU: %i\n", odp_cpumask_first(&cpumask)); + printf(" CPU mask: %s\n", cpumaskstr);
thread_tbl = calloc(sizeof(odph_odpthread_t), num_workers); if (!thread_tbl) {
commit 2133fde4a61f46666d365dbecc61da8311299b3b Author: Petri Savolainen petri.savolainen@linaro.org Date: Fri Apr 28 15:09:52 2017 +0300
test: validation: add odp_sys_info_print test
Added validation test for the new system info print call.
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/validation/api/system/system.c b/test/common_plat/validation/api/system/system.c index 57ff34eb..5b7ca01a 100644 --- a/test/common_plat/validation/api/system/system.c +++ b/test/common_plat/validation/api/system/system.c @@ -301,6 +301,13 @@ void system_test_odp_cpu_hz_max_id(void) } }
+void system_test_info_print(void) +{ + printf("\n\nCalling system info print...\n"); + odp_sys_info_print(); + printf("...done. "); +} + odp_testinfo_t system_suite[] = { ODP_TEST_INFO(system_test_odp_version_numbers), ODP_TEST_INFO(system_test_odp_cpu_count), @@ -319,6 +326,7 @@ odp_testinfo_t system_suite[] = { ODP_TEST_INFO(system_test_odp_cpu_cycles_max), ODP_TEST_INFO(system_test_odp_cpu_cycles_resolution), ODP_TEST_INFO(system_test_odp_cpu_cycles_diff), + ODP_TEST_INFO(system_test_info_print), ODP_TEST_INFO_NULL, };
diff --git a/test/common_plat/validation/api/system/system.h b/test/common_plat/validation/api/system/system.h index cbb994eb..c33729b9 100644 --- a/test/common_plat/validation/api/system/system.h +++ b/test/common_plat/validation/api/system/system.h @@ -30,6 +30,7 @@ void system_test_odp_cpu_cycles_max(void); void system_test_odp_cpu_cycles(void); void system_test_odp_cpu_cycles_diff(void); void system_test_odp_cpu_cycles_resolution(void); +void system_test_info_print(void);
/* test arrays: */ extern odp_testinfo_t system_suite[];
commit 73ae15cdb4bc6b46bc4a81f711a0f5a069ed889b Author: Petri Savolainen petri.savolainen@linaro.org Date: Fri Apr 28 15:09:51 2017 +0300
linux-gen: system: implement system info print
Print API, impl name, CPU model/freq, cache line size and CPU count by default. Print CPU flags in case of x86.
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/arch/arm/odp_sysinfo_parse.c b/platform/linux-generic/arch/arm/odp_sysinfo_parse.c index 53e2aaea..8ae2022a 100644 --- a/platform/linux-generic/arch/arm/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/arm/odp_sysinfo_parse.c @@ -25,3 +25,7 @@ uint64_t odp_cpu_hz_current(int id ODP_UNUSED) { return 0; } + +void sys_info_print_arch(void) +{ +} diff --git a/platform/linux-generic/arch/default/odp_sysinfo_parse.c b/platform/linux-generic/arch/default/odp_sysinfo_parse.c index 53e2aaea..8ae2022a 100644 --- a/platform/linux-generic/arch/default/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/default/odp_sysinfo_parse.c @@ -25,3 +25,7 @@ uint64_t odp_cpu_hz_current(int id ODP_UNUSED) { return 0; } + +void sys_info_print_arch(void) +{ +} diff --git a/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c b/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c index 407264b7..d6f75f28 100644 --- a/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/mips64/odp_sysinfo_parse.c @@ -62,3 +62,7 @@ uint64_t odp_cpu_hz_current(int id ODP_UNUSED) { return 0; } + +void sys_info_print_arch(void) +{ +} diff --git a/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c b/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c index 3b88d55b..bd4b9b42 100644 --- a/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/powerpc/odp_sysinfo_parse.c @@ -61,3 +61,7 @@ uint64_t odp_cpu_hz_current(int id ODP_UNUSED) { return 0; } + +void sys_info_print_arch(void) +{ +} diff --git a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c index 96127ec6..d77165a4 100644 --- a/platform/linux-generic/arch/x86/odp_sysinfo_parse.c +++ b/platform/linux-generic/arch/x86/odp_sysinfo_parse.c @@ -5,6 +5,7 @@ */
#include <odp_internal.h> +#include <arch/x86/cpu_flags.h> #include <string.h>
int cpuinfo_parser(FILE *file, system_info_t *sysinfo) @@ -73,3 +74,8 @@ uint64_t odp_cpu_hz_current(int id)
return 0; } + +void sys_info_print_arch(void) +{ + cpu_flags_print_all(); +} diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h index e1267cff..8bae028d 100644 --- a/platform/linux-generic/include/odp_internal.h +++ b/platform/linux-generic/include/odp_internal.h @@ -128,6 +128,7 @@ int _odp_ishm_term_local(void);
int cpuinfo_parser(FILE *file, system_info_t *sysinfo); uint64_t odp_cpu_hz_current(int id); +void sys_info_print_arch(void);
#ifdef __cplusplus } diff --git a/platform/linux-generic/odp_system_info.c b/platform/linux-generic/odp_system_info.c index 18c61dbe..40ffca07 100644 --- a/platform/linux-generic/odp_system_info.c +++ b/platform/linux-generic/odp_system_info.c @@ -14,6 +14,7 @@ #include <odp_posix_extensions.h>
#include <odp/api/system_info.h> +#include <odp/api/version.h> #include <odp_internal.h> #include <odp_debug_internal.h> #include <odp/api/align.h> @@ -405,3 +406,32 @@ int odp_cpu_count(void) { return odp_global_data.system_info.cpu_count; } + +void odp_sys_info_print(void) +{ + int len; + int max_len = 512; + char str[max_len]; + + len = snprintf(str, max_len, "\n" + "ODP system info\n" + "---------------\n" + "ODP API version: %s\n" + "ODP impl name: %s\n" + "CPU model: %s\n" + "CPU freq (hz): %" PRIu64 "\n" + "Cache line size: %i\n" + "CPU count: %i\n" + "\n", + odp_version_api_str(), + odp_version_impl_name(), + odp_cpu_model_str(), + odp_cpu_hz_max(), + odp_sys_cache_line_size(), + odp_cpu_count()); + + str[len] = '\0'; + ODP_PRINT("%s", str); + + sys_info_print_arch(); +}
commit e20e7877c6a5062754a1deddbabab7f3d55dff80 Author: Petri Savolainen petri.savolainen@linaro.org Date: Fri Apr 28 15:09:50 2017 +0300
linux-gen: cpu_flags: added x86 cpu flag read functions
When building on x86 CPU flags can be used to determine which CPU features are supported. CPU flag definitions and the code to read the flags is from DPDK.
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/configure.ac b/configure.ac index 0743f761..58682564 100644 --- a/configure.ac +++ b/configure.ac @@ -225,6 +225,7 @@ AM_CONDITIONAL([HAVE_DOXYGEN], [test "x${DOXYGEN}" = "xdoxygen"]) AM_CONDITIONAL([user_guide], [test "x${user_guides}" = "xyes" ]) AM_CONDITIONAL([HAVE_MSCGEN], [test "x${MSCGEN}" = "xmscgen"]) AM_CONDITIONAL([helper_linux], [test x$helper_linux = xyes ]) +AM_CONDITIONAL([ARCH_IS_X86], [test "x${ARCH_DIR}" = "xx86"])
########################################################################## # Setup doxygen documentation diff --git a/platform/Makefile.inc b/platform/Makefile.inc index 59a57724..9844a58a 100644 --- a/platform/Makefile.inc +++ b/platform/Makefile.inc @@ -98,4 +98,6 @@ EXTRA_DIST = \ arch/powerpc/odp_sysinfo_parse.c \ arch/x86/odp/api/cpu_arch.h \ arch/x86/odp_cpu_arch.c \ - arch/x86/odp_sysinfo_parse.c + arch/x86/odp_sysinfo_parse.c \ + arch/x86/cpu_flags.c \ + arch/x86/cpu_flags.h diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 22c3247e..4262b25d 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -220,6 +220,10 @@ __LIB__libodp_linux_la_SOURCES = \ arch/@ARCH_DIR@/odp_cpu_arch.c \ arch/@ARCH_DIR@/odp_sysinfo_parse.c
+if ARCH_IS_X86 +__LIB__libodp_linux_la_SOURCES += arch/@ARCH_DIR@/cpu_flags.c +endif + if HAVE_PCAP __LIB__libodp_linux_la_SOURCES += pktio/pcap.c endif diff --git a/platform/linux-generic/arch/x86/cpu_flags.c b/platform/linux-generic/arch/x86/cpu_flags.c new file mode 100644 index 00000000..954dac27 --- /dev/null +++ b/platform/linux-generic/arch/x86/cpu_flags.c @@ -0,0 +1,359 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/*- + * BSD LICENSE + * + * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <arch/x86/cpu_flags.h> +#include <odp_debug_internal.h> +#include <stdio.h> +#include <stdint.h> + +enum rte_cpu_flag_t { + /* (EAX 01h) ECX features*/ + RTE_CPUFLAG_SSE3 = 0, /**< SSE3 */ + RTE_CPUFLAG_PCLMULQDQ, /**< PCLMULQDQ */ + RTE_CPUFLAG_DTES64, /**< DTES64 */ + RTE_CPUFLAG_MONITOR, /**< MONITOR */ + RTE_CPUFLAG_DS_CPL, /**< DS_CPL */ + RTE_CPUFLAG_VMX, /**< VMX */ + RTE_CPUFLAG_SMX, /**< SMX */ + RTE_CPUFLAG_EIST, /**< EIST */ + RTE_CPUFLAG_TM2, /**< TM2 */ + RTE_CPUFLAG_SSSE3, /**< SSSE3 */ + RTE_CPUFLAG_CNXT_ID, /**< CNXT_ID */ + RTE_CPUFLAG_FMA, /**< FMA */ + RTE_CPUFLAG_CMPXCHG16B, /**< CMPXCHG16B */ + RTE_CPUFLAG_XTPR, /**< XTPR */ + RTE_CPUFLAG_PDCM, /**< PDCM */ + RTE_CPUFLAG_PCID, /**< PCID */ + RTE_CPUFLAG_DCA, /**< DCA */ + RTE_CPUFLAG_SSE4_1, /**< SSE4_1 */ + RTE_CPUFLAG_SSE4_2, /**< SSE4_2 */ + RTE_CPUFLAG_X2APIC, /**< X2APIC */ + RTE_CPUFLAG_MOVBE, /**< MOVBE */ + RTE_CPUFLAG_POPCNT, /**< POPCNT */ + RTE_CPUFLAG_TSC_DEADLINE, /**< TSC_DEADLINE */ + RTE_CPUFLAG_AES, /**< AES */ + RTE_CPUFLAG_XSAVE, /**< XSAVE */ + RTE_CPUFLAG_OSXSAVE, /**< OSXSAVE */ + RTE_CPUFLAG_AVX, /**< AVX */ + RTE_CPUFLAG_F16C, /**< F16C */ + RTE_CPUFLAG_RDRAND, /**< RDRAND */ + + /* (EAX 01h) EDX features */ + RTE_CPUFLAG_FPU, /**< FPU */ + RTE_CPUFLAG_VME, /**< VME */ + RTE_CPUFLAG_DE, /**< DE */ + RTE_CPUFLAG_PSE, /**< PSE */ + RTE_CPUFLAG_TSC, /**< TSC */ + RTE_CPUFLAG_MSR, /**< MSR */ + RTE_CPUFLAG_PAE, /**< PAE */ + RTE_CPUFLAG_MCE, /**< MCE */ + RTE_CPUFLAG_CX8, /**< CX8 */ + RTE_CPUFLAG_APIC, /**< APIC */ + RTE_CPUFLAG_SEP, /**< SEP */ + RTE_CPUFLAG_MTRR, /**< MTRR */ + RTE_CPUFLAG_PGE, /**< PGE */ + RTE_CPUFLAG_MCA, /**< MCA */ + RTE_CPUFLAG_CMOV, /**< CMOV */ + RTE_CPUFLAG_PAT, /**< PAT */ + RTE_CPUFLAG_PSE36, /**< PSE36 */ + RTE_CPUFLAG_PSN, /**< PSN */ + RTE_CPUFLAG_CLFSH, /**< CLFSH */ + RTE_CPUFLAG_DS, /**< DS */ + RTE_CPUFLAG_ACPI, /**< ACPI */ + RTE_CPUFLAG_MMX, /**< MMX */ + RTE_CPUFLAG_FXSR, /**< FXSR */ + RTE_CPUFLAG_SSE, /**< SSE */ + RTE_CPUFLAG_SSE2, /**< SSE2 */ + RTE_CPUFLAG_SS, /**< SS */ + RTE_CPUFLAG_HTT, /**< HTT */ + RTE_CPUFLAG_TM, /**< TM */ + RTE_CPUFLAG_PBE, /**< PBE */ + + /* (EAX 06h) EAX features */ + RTE_CPUFLAG_DIGTEMP, /**< DIGTEMP */ + RTE_CPUFLAG_TRBOBST, /**< TRBOBST */ + RTE_CPUFLAG_ARAT, /**< ARAT */ + RTE_CPUFLAG_PLN, /**< PLN */ + RTE_CPUFLAG_ECMD, /**< ECMD */ + RTE_CPUFLAG_PTM, /**< PTM */ + + /* (EAX 06h) ECX features */ + RTE_CPUFLAG_MPERF_APERF_MSR, /**< MPERF_APERF_MSR */ + RTE_CPUFLAG_ACNT2, /**< ACNT2 */ + RTE_CPUFLAG_ENERGY_EFF, /**< ENERGY_EFF */ + + /* (EAX 07h, ECX 0h) EBX features */ + RTE_CPUFLAG_FSGSBASE, /**< FSGSBASE */ + RTE_CPUFLAG_BMI1, /**< BMI1 */ + RTE_CPUFLAG_HLE, /**< Hardware Lock elision */ + RTE_CPUFLAG_AVX2, /**< AVX2 */ + RTE_CPUFLAG_SMEP, /**< SMEP */ + RTE_CPUFLAG_BMI2, /**< BMI2 */ + RTE_CPUFLAG_ERMS, /**< ERMS */ + RTE_CPUFLAG_INVPCID, /**< INVPCID */ + RTE_CPUFLAG_RTM, /**< Transactional memory */ + RTE_CPUFLAG_AVX512F, /**< AVX512F */ + + /* (EAX 80000001h) ECX features */ + RTE_CPUFLAG_LAHF_SAHF, /**< LAHF_SAHF */ + RTE_CPUFLAG_LZCNT, /**< LZCNT */ + + /* (EAX 80000001h) EDX features */ + RTE_CPUFLAG_SYSCALL, /**< SYSCALL */ + RTE_CPUFLAG_XD, /**< XD */ + RTE_CPUFLAG_1GB_PG, /**< 1GB_PG */ + RTE_CPUFLAG_RDTSCP, /**< RDTSCP */ + RTE_CPUFLAG_EM64T, /**< EM64T */ + + /* (EAX 80000007h) EDX features */ + RTE_CPUFLAG_INVTSC, /**< INVTSC */ + + /* The last item */ + RTE_CPUFLAG_NUMFLAGS, /**< This should always be the last! */ +}; + +enum cpu_register_t { + RTE_REG_EAX = 0, + RTE_REG_EBX, + RTE_REG_ECX, + RTE_REG_EDX, +}; + +typedef uint32_t cpuid_registers_t[4]; + +/** + * Struct to hold a processor feature entry + */ +struct feature_entry { + uint32_t leaf; /**< cpuid leaf */ + uint32_t subleaf; /**< cpuid subleaf */ + uint32_t reg; /**< cpuid register */ + uint32_t bit; /**< cpuid register bit */ +#define CPU_FLAG_NAME_MAX_LEN 64 + char name[CPU_FLAG_NAME_MAX_LEN]; /**< String for printing */ +}; + +#define FEAT_DEF(name, leaf, subleaf, reg, bit) \ + [RTE_CPUFLAG_##name] = {leaf, subleaf, reg, bit, #name }, + +static const struct feature_entry cpu_feature_table[] = { + FEAT_DEF(SSE3, 0x00000001, 0, RTE_REG_ECX, 0) + FEAT_DEF(PCLMULQDQ, 0x00000001, 0, RTE_REG_ECX, 1) + FEAT_DEF(DTES64, 0x00000001, 0, RTE_REG_ECX, 2) + FEAT_DEF(MONITOR, 0x00000001, 0, RTE_REG_ECX, 3) + FEAT_DEF(DS_CPL, 0x00000001, 0, RTE_REG_ECX, 4) + FEAT_DEF(VMX, 0x00000001, 0, RTE_REG_ECX, 5) + FEAT_DEF(SMX, 0x00000001, 0, RTE_REG_ECX, 6) + FEAT_DEF(EIST, 0x00000001, 0, RTE_REG_ECX, 7) + FEAT_DEF(TM2, 0x00000001, 0, RTE_REG_ECX, 8) + FEAT_DEF(SSSE3, 0x00000001, 0, RTE_REG_ECX, 9) + FEAT_DEF(CNXT_ID, 0x00000001, 0, RTE_REG_ECX, 10) + FEAT_DEF(FMA, 0x00000001, 0, RTE_REG_ECX, 12) + FEAT_DEF(CMPXCHG16B, 0x00000001, 0, RTE_REG_ECX, 13) + FEAT_DEF(XTPR, 0x00000001, 0, RTE_REG_ECX, 14) + FEAT_DEF(PDCM, 0x00000001, 0, RTE_REG_ECX, 15) + FEAT_DEF(PCID, 0x00000001, 0, RTE_REG_ECX, 17) + FEAT_DEF(DCA, 0x00000001, 0, RTE_REG_ECX, 18) + FEAT_DEF(SSE4_1, 0x00000001, 0, RTE_REG_ECX, 19) + FEAT_DEF(SSE4_2, 0x00000001, 0, RTE_REG_ECX, 20) + FEAT_DEF(X2APIC, 0x00000001, 0, RTE_REG_ECX, 21) + FEAT_DEF(MOVBE, 0x00000001, 0, RTE_REG_ECX, 22) + FEAT_DEF(POPCNT, 0x00000001, 0, RTE_REG_ECX, 23) + FEAT_DEF(TSC_DEADLINE, 0x00000001, 0, RTE_REG_ECX, 24) + FEAT_DEF(AES, 0x00000001, 0, RTE_REG_ECX, 25) + FEAT_DEF(XSAVE, 0x00000001, 0, RTE_REG_ECX, 26) + FEAT_DEF(OSXSAVE, 0x00000001, 0, RTE_REG_ECX, 27) + FEAT_DEF(AVX, 0x00000001, 0, RTE_REG_ECX, 28) + FEAT_DEF(F16C, 0x00000001, 0, RTE_REG_ECX, 29) + FEAT_DEF(RDRAND, 0x00000001, 0, RTE_REG_ECX, 30) + + FEAT_DEF(FPU, 0x00000001, 0, RTE_REG_EDX, 0) + FEAT_DEF(VME, 0x00000001, 0, RTE_REG_EDX, 1) + FEAT_DEF(DE, 0x00000001, 0, RTE_REG_EDX, 2) + FEAT_DEF(PSE, 0x00000001, 0, RTE_REG_EDX, 3) + FEAT_DEF(TSC, 0x00000001, 0, RTE_REG_EDX, 4) + FEAT_DEF(MSR, 0x00000001, 0, RTE_REG_EDX, 5) + FEAT_DEF(PAE, 0x00000001, 0, RTE_REG_EDX, 6) + FEAT_DEF(MCE, 0x00000001, 0, RTE_REG_EDX, 7) + FEAT_DEF(CX8, 0x00000001, 0, RTE_REG_EDX, 8) + FEAT_DEF(APIC, 0x00000001, 0, RTE_REG_EDX, 9) + FEAT_DEF(SEP, 0x00000001, 0, RTE_REG_EDX, 11) + FEAT_DEF(MTRR, 0x00000001, 0, RTE_REG_EDX, 12) + FEAT_DEF(PGE, 0x00000001, 0, RTE_REG_EDX, 13) + FEAT_DEF(MCA, 0x00000001, 0, RTE_REG_EDX, 14) + FEAT_DEF(CMOV, 0x00000001, 0, RTE_REG_EDX, 15) + FEAT_DEF(PAT, 0x00000001, 0, RTE_REG_EDX, 16) + FEAT_DEF(PSE36, 0x00000001, 0, RTE_REG_EDX, 17) + FEAT_DEF(PSN, 0x00000001, 0, RTE_REG_EDX, 18) + FEAT_DEF(CLFSH, 0x00000001, 0, RTE_REG_EDX, 19) + FEAT_DEF(DS, 0x00000001, 0, RTE_REG_EDX, 21) + FEAT_DEF(ACPI, 0x00000001, 0, RTE_REG_EDX, 22) + FEAT_DEF(MMX, 0x00000001, 0, RTE_REG_EDX, 23) + FEAT_DEF(FXSR, 0x00000001, 0, RTE_REG_EDX, 24) + FEAT_DEF(SSE, 0x00000001, 0, RTE_REG_EDX, 25) + FEAT_DEF(SSE2, 0x00000001, 0, RTE_REG_EDX, 26) + FEAT_DEF(SS, 0x00000001, 0, RTE_REG_EDX, 27) + FEAT_DEF(HTT, 0x00000001, 0, RTE_REG_EDX, 28) + FEAT_DEF(TM, 0x00000001, 0, RTE_REG_EDX, 29) + FEAT_DEF(PBE, 0x00000001, 0, RTE_REG_EDX, 31) + + FEAT_DEF(DIGTEMP, 0x00000006, 0, RTE_REG_EAX, 0) + FEAT_DEF(TRBOBST, 0x00000006, 0, RTE_REG_EAX, 1) + FEAT_DEF(ARAT, 0x00000006, 0, RTE_REG_EAX, 2) + FEAT_DEF(PLN, 0x00000006, 0, RTE_REG_EAX, 4) + FEAT_DEF(ECMD, 0x00000006, 0, RTE_REG_EAX, 5) + FEAT_DEF(PTM, 0x00000006, 0, RTE_REG_EAX, 6) + + FEAT_DEF(MPERF_APERF_MSR, 0x00000006, 0, RTE_REG_ECX, 0) + FEAT_DEF(ACNT2, 0x00000006, 0, RTE_REG_ECX, 1) + FEAT_DEF(ENERGY_EFF, 0x00000006, 0, RTE_REG_ECX, 3) + + FEAT_DEF(FSGSBASE, 0x00000007, 0, RTE_REG_EBX, 0) + FEAT_DEF(BMI1, 0x00000007, 0, RTE_REG_EBX, 2) + FEAT_DEF(HLE, 0x00000007, 0, RTE_REG_EBX, 4) + FEAT_DEF(AVX2, 0x00000007, 0, RTE_REG_EBX, 5) + FEAT_DEF(SMEP, 0x00000007, 0, RTE_REG_EBX, 6) + FEAT_DEF(BMI2, 0x00000007, 0, RTE_REG_EBX, 7) + FEAT_DEF(ERMS, 0x00000007, 0, RTE_REG_EBX, 8) + FEAT_DEF(INVPCID, 0x00000007, 0, RTE_REG_EBX, 10) + FEAT_DEF(RTM, 0x00000007, 0, RTE_REG_EBX, 11) + FEAT_DEF(AVX512F, 0x00000007, 0, RTE_REG_EBX, 16) + + FEAT_DEF(LAHF_SAHF, 0x80000001, 0, RTE_REG_ECX, 0) + FEAT_DEF(LZCNT, 0x80000001, 0, RTE_REG_ECX, 4) + + FEAT_DEF(SYSCALL, 0x80000001, 0, RTE_REG_EDX, 11) + FEAT_DEF(XD, 0x80000001, 0, RTE_REG_EDX, 20) + FEAT_DEF(1GB_PG, 0x80000001, 0, RTE_REG_EDX, 26) + FEAT_DEF(RDTSCP, 0x80000001, 0, RTE_REG_EDX, 27) + FEAT_DEF(EM64T, 0x80000001, 0, RTE_REG_EDX, 29) + + FEAT_DEF(INVTSC, 0x80000007, 0, RTE_REG_EDX, 8) +}; + +/* + * Execute CPUID instruction and get contents of a specific register + * + * This function, when compiled with GCC, will generate architecture-neutral + * code, as per GCC manual. + */ +static void cpu_get_features(uint32_t leaf, uint32_t subleaf, + cpuid_registers_t out) +{ +#if defined(__i386__) && defined(__PIC__) + /* %ebx is a forbidden register if we compile with -fPIC or -fPIE */ + __asm__ __volatile__("movl %%ebx,%0 ; cpuid ; xchgl %%ebx,%0" + : "=r" (out[RTE_REG_EBX]), + "=a" (out[RTE_REG_EAX]), + "=c" (out[RTE_REG_ECX]), + "=d" (out[RTE_REG_EDX]) + : "a" (leaf), "c" (subleaf)); +#else + __asm__ __volatile__("cpuid" + : "=a" (out[RTE_REG_EAX]), + "=b" (out[RTE_REG_EBX]), + "=c" (out[RTE_REG_ECX]), + "=d" (out[RTE_REG_EDX]) + : "a" (leaf), "c" (subleaf)); +#endif +} + +static int cpu_get_flag_enabled(enum rte_cpu_flag_t feature) +{ + const struct feature_entry *feat; + cpuid_registers_t regs; + + if (feature >= RTE_CPUFLAG_NUMFLAGS) + /* Flag does not match anything in the feature tables */ + return -1; + + feat = &cpu_feature_table[feature]; + + if (!feat->leaf) + /* This entry in the table wasn't filled out! */ + return -1; + + cpu_get_features(feat->leaf & 0xffff0000, 0, regs); + if (((regs[RTE_REG_EAX] ^ feat->leaf) & 0xffff0000) || + regs[RTE_REG_EAX] < feat->leaf) + return 0; + + /* get the cpuid leaf containing the desired feature */ + cpu_get_features(feat->leaf, feat->subleaf, regs); + + /* check if the feature is enabled */ + return (regs[feat->reg] >> feat->bit) & 1; +} + +static const char *cpu_get_flag_name(enum rte_cpu_flag_t feature) +{ + if (feature >= RTE_CPUFLAG_NUMFLAGS) + return NULL; + return cpu_feature_table[feature].name; +} + +void cpu_flags_print_all(void) +{ + int len, i; + int max_str = 1024; + int max_len = max_str - 1; + char str[max_str]; + + len = snprintf(str, max_len, "\nCPU features supported:\n"); + + for (i = 0; i < RTE_CPUFLAG_NUMFLAGS; i++) { + if (cpu_get_flag_enabled(i) > 0) + len += snprintf(&str[len], max_len - len, "%s ", + cpu_get_flag_name(i)); + } + + len += snprintf(&str[len], max_len - len, + "\n\nCPU features NOT supported:\n"); + + for (i = 0; i < RTE_CPUFLAG_NUMFLAGS; i++) { + if (cpu_get_flag_enabled(i) <= 0) + len += snprintf(&str[len], max_len - len, "%s ", + cpu_get_flag_name(i)); + } + + len += snprintf(&str[len], max_len - len, "\n\n"); + + str[len] = '\0'; + ODP_PRINT("%s", str); +} diff --git a/platform/linux-generic/arch/x86/cpu_flags.h b/platform/linux-generic/arch/x86/cpu_flags.h new file mode 100644 index 00000000..f709ca08 --- /dev/null +++ b/platform/linux-generic/arch/x86/cpu_flags.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_PLAT_CPU_FLAGS_H_ +#define ODP_PLAT_CPU_FLAGS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +void cpu_flags_print_all(void); + +#ifdef __cplusplus +} +#endif + +#endif
commit aafbf4394c9d4d63baa3f750baf6ac19137d6ab2 Author: Petri Savolainen petri.savolainen@linaro.org Date: Fri Apr 28 15:09:49 2017 +0300
api: system: added system info print
This information specifies the system where ODP application is running for debugging purposes.
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/include/odp/api/spec/system_info.h b/include/odp/api/spec/system_info.h index 0bb4f1f1..ca4dcdc7 100644 --- a/include/odp/api/spec/system_info.h +++ b/include/odp/api/spec/system_info.h @@ -45,6 +45,15 @@ uint64_t odp_sys_page_size(void); int odp_sys_cache_line_size(void);
/** + * Print system info + * + * Print out implementation defined information about the system. This + * information is intended for debugging purposes and may contain e.g. + * information about CPUs, memory and other HW configuration. + */ +void odp_sys_info_print(void); + +/** * @} */
commit 9d5b473fcb86d61391d519b7cf2fa398017ce468 Author: Petri Savolainen petri.savolainen@linaro.org Date: Fri Apr 28 15:09:48 2017 +0300
api: time: remove odp_time_to_u64 from API
Debug function that converts odp_time_t to u64 is unnecessary since odp_time_to_ns() returns time as a u64 (nsec) value. Application can always use that as the 64 bit representation of an odp_time_t value. Also validation tests for odp_time_to_u64() were erroneous since those compared returned u64 values and expected greater/lesser than relation.
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/include/odp/api/spec/time.h b/include/odp/api/spec/time.h index fcc94c98..29175eb5 100644 --- a/include/odp/api/spec/time.h +++ b/include/odp/api/spec/time.h @@ -158,19 +158,6 @@ void odp_time_wait_until(odp_time_t time); void odp_time_wait_ns(uint64_t ns);
/** - * Get printable value for an odp_time_t - * - * @param time time to be printed - * - * @return uint64_t value that can be used to print/display this time - * - * @note This routine is intended to be used for diagnostic purposes - * to enable applications to generate a printable value that represents - * an odp_time_t time. - */ -uint64_t odp_time_to_u64(odp_time_t time); - -/** * @} */
diff --git a/platform/linux-generic/odp_time.c b/platform/linux-generic/odp_time.c index 81e05224..0e5966c0 100644 --- a/platform/linux-generic/odp_time.c +++ b/platform/linux-generic/odp_time.c @@ -176,21 +176,6 @@ void odp_time_wait_until(odp_time_t time) return time_wait_until(time); }
-uint64_t odp_time_to_u64(odp_time_t time) -{ - int ret; - struct timespec tres; - uint64_t resolution; - - ret = clock_getres(CLOCK_MONOTONIC_RAW, &tres); - if (odp_unlikely(ret != 0)) - ODP_ABORT("clock_getres failed\n"); - - resolution = (uint64_t)tres.tv_nsec; - - return time_to_ns(time) / resolution; -} - int odp_time_init_global(void) { int ret; diff --git a/test/common_plat/validation/api/time/time.c b/test/common_plat/validation/api/time/time.c index 530d5c07..df65c719 100644 --- a/test/common_plat/validation/api/time/time.c +++ b/test/common_plat/validation/api/time/time.c @@ -398,41 +398,6 @@ void time_test_wait_ns(void) } }
-static void time_test_to_u64(time_cb time) -{ - volatile int count = 0; - uint64_t val1, val2; - odp_time_t t1, t2; - - t1 = time(); - - val1 = odp_time_to_u64(t1); - CU_ASSERT(val1 > 0); - - while (count < BUSY_LOOP_CNT) { - count++; - }; - - t2 = time(); - val2 = odp_time_to_u64(t2); - CU_ASSERT(val2 > 0); - - CU_ASSERT(val2 > val1); - - val1 = odp_time_to_u64(ODP_TIME_NULL); - CU_ASSERT(val1 == 0); -} - -void time_test_local_to_u64(void) -{ - time_test_to_u64(odp_time_local); -} - -void time_test_global_to_u64(void) -{ - time_test_to_u64(odp_time_global); -} - odp_testinfo_t time_suite_time[] = { ODP_TEST_INFO(time_test_constants), ODP_TEST_INFO(time_test_local_res), @@ -443,14 +408,12 @@ odp_testinfo_t time_suite_time[] = { ODP_TEST_INFO(time_test_local_sum), ODP_TEST_INFO(time_test_local_wait_until), ODP_TEST_INFO(time_test_wait_ns), - ODP_TEST_INFO(time_test_local_to_u64), ODP_TEST_INFO(time_test_global_res), ODP_TEST_INFO(time_test_global_conversion), ODP_TEST_INFO(time_test_global_cmp), ODP_TEST_INFO(time_test_global_diff), ODP_TEST_INFO(time_test_global_sum), ODP_TEST_INFO(time_test_global_wait_until), - ODP_TEST_INFO(time_test_global_to_u64), ODP_TEST_INFO_NULL };
diff --git a/test/common_plat/validation/api/time/time.h b/test/common_plat/validation/api/time/time.h index e5132a49..10956294 100644 --- a/test/common_plat/validation/api/time/time.h +++ b/test/common_plat/validation/api/time/time.h @@ -24,8 +24,6 @@ void time_test_global_sum(void); void time_test_local_wait_until(void); void time_test_global_wait_until(void); void time_test_wait_ns(void); -void time_test_local_to_u64(void); -void time_test_global_to_u64(void); void time_test_monotony(void);
/* test arrays: */
commit 476b52c41e17940c39368a7bd81149e2780303ac Author: Bill Fischofer bill.fischofer@linaro.org Date: Fri Apr 21 09:25:25 2017 -0500
helper: add additional doxygen documentation
Resolve Bug https://bugs.linaro.org/show_bug.cgi?id=2952 by adding additional field documentation to avoid problems with doxygen 1.8.13 and higher.
Signed-off-by: Bill Fischofer bill.fischofer@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/helper/include/odp/helper/icmp.h b/helper/include/odp/helper/icmp.h index e25646ad..bef96784 100644 --- a/helper/include/odp/helper/icmp.h +++ b/helper/include/odp/helper/icmp.h @@ -32,15 +32,18 @@ typedef struct ODP_PACKED { uint8_t type; /**< message type */ uint8_t code; /**< type sub-code */ odp_u16sum_t chksum; /**< checksum of icmp header */ + /** Variant mappings of ICMP fields */ union { + /** Fields used for ICMP echo msgs */ struct { - odp_u16be_t id; - odp_u16be_t sequence; + odp_u16be_t id; /**< id */ + odp_u16be_t sequence; /**< sequence */ } echo; /**< echo datagram */ odp_u32be_t gateway; /**< gateway address */ + /** Fields used for ICMP frag msgs */ struct { - odp_u16be_t __unused; - odp_u16be_t mtu; + odp_u16be_t __unused; /**< @internal */ + odp_u16be_t mtu; /**< mtu */ } frag; /**< path mtu discovery */ } un; /**< icmp sub header */ } odph_icmphdr_t; diff --git a/helper/include/odp/helper/strong_types.h b/helper/include/odp/helper/strong_types.h index 13e35a43..501d0f28 100644 --- a/helper/include/odp/helper/strong_types.h +++ b/helper/include/odp/helper/strong_types.h @@ -20,10 +20,11 @@
/** Use strong typing for ODP types */ #ifdef __cplusplus +/** @internal C++ helper macro for strong typing @param type @return */ #define ODPH_HANDLE_T(type) struct _##type { uint8_t unused_dummy_var; } *type #else #define odph_handle_t struct { uint8_t unused_dummy_var; } * -/** C/C++ helper macro for strong typing */ +/** @internal C helper macro for strong typing @param type @return */ #define ODPH_HANDLE_T(type) odph_handle_t type #endif
diff --git a/helper/include/odp/helper/table.h b/helper/include/odp/helper/table.h index b3440ef5..96c9c5fe 100644 --- a/helper/include/odp/helper/table.h +++ b/helper/include/odp/helper/table.h @@ -94,7 +94,7 @@ extern "C" { #define ODPH_TABLE_NAME_LEN 32
#include <odp/helper/strong_types.h> -/** ODP table handle */ +/** @internal ODPH table handle @return */ typedef ODPH_HANDLE_T(odph_table_t);
/** diff --git a/helper/include/odp/helper/tcp.h b/helper/include/odp/helper/tcp.h index fd234e58..e91b52e2 100644 --- a/helper/include/odp/helper/tcp.h +++ b/helper/include/odp/helper/tcp.h @@ -32,8 +32,9 @@ typedef struct ODP_PACKED { odp_u16be_t dst_port; /**< Destination port */ odp_u32be_t seq_no; /**< Sequence number */ odp_u32be_t ack_no; /**< Acknowledgment number */ + /** Variant maps for TCP header fields */ union { - odp_u16be_t doffset_flags; + odp_u16be_t doffset_flags; /**< TCP Flags aggregate */ #if ODP_BIG_ENDIAN_BITFIELD struct { odp_u16be_t rsvd1:8; @@ -42,14 +43,14 @@ typedef struct ODP_PACKED { struct { odp_u16be_t hl:4; /**< Hdr len, in words */ odp_u16be_t rsvd3:4; /**< Reserved */ - odp_u16be_t cwr:1; - odp_u16be_t ece:1; - odp_u16be_t urg:1; - odp_u16be_t ack:1; - odp_u16be_t psh:1; - odp_u16be_t rst:1; - odp_u16be_t syn:1; - odp_u16be_t fin:1; + odp_u16be_t cwr:1; /**< cwr bit */ + odp_u16be_t ece:1; /**< ece bit */ + odp_u16be_t urg:1; /**< urg bit */ + odp_u16be_t ack:1; /**< ack bit */ + odp_u16be_t psh:1; /**< psh bit */ + odp_u16be_t rst:1; /**< rst bit */ + odp_u16be_t syn:1; /**< syn bit */ + odp_u16be_t fin:1; /**< fin bit */ }; #elif ODP_LITTLE_ENDIAN_BITFIELD struct { @@ -59,14 +60,14 @@ typedef struct ODP_PACKED { struct { odp_u16be_t rsvd3:4; /**< Reserved */ odp_u16be_t hl:4; /**< Hdr len, in words */ - odp_u16be_t fin:1; - odp_u16be_t syn:1; - odp_u16be_t rst:1; - odp_u16be_t psh:1; - odp_u16be_t ack:1; - odp_u16be_t urg:1; - odp_u16be_t ece:1; - odp_u16be_t cwr:1; + odp_u16be_t fin:1; /**< fin bit */ + odp_u16be_t syn:1; /**< syn bit */ + odp_u16be_t rst:1; /**< rst bit */ + odp_u16be_t psh:1; /**< psh bit */ + odp_u16be_t ack:1; /**< ack bit */ + odp_u16be_t urg:1; /**< urg bit */ + odp_u16be_t ece:1; /**< ece bit */ + odp_u16be_t cwr:1; /**< cwr bit */ };
#else diff --git a/helper/include/odp/helper/threads.h b/helper/include/odp/helper/threads.h index 5682bab9..526f0d48 100644 --- a/helper/include/odp/helper/threads.h +++ b/helper/include/odp/helper/threads.h @@ -80,12 +80,15 @@ typedef struct { odph_odpthread_start_args_t start_args; /**< start arguments */ int cpu; /**< CPU ID */ int last; /**< true if last table entry */ + /** Variant field mappings for thread/process modes */ union { - struct { /* for thread implementation */ + /** For thread implementation */ + struct { pthread_t thread_id; /**< Pthread ID */ pthread_attr_t attr; /**< Pthread attributes */ } thread; - struct { /* for process implementation */ + /** For process implementation */ + struct { pid_t pid; /**< Process ID */ int status; /**< Process state chge status*/ } proc;
commit e167796e4bcb8c3f19737acb5358b5edabcdfa56 Author: Bill Fischofer bill.fischofer@linaro.org Date: Fri Apr 21 09:25:24 2017 -0500
linux-generic: types: add additional doxygen documentation
Resolve Bug https://bugs.linaro.org/show_bug.cgi?id=2952 by adding additional field documentation to avoid problems with doxygen 1.8.13 and higher.
Signed-off-by: Bill Fischofer bill.fischofer@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/include/odp/api/debug.h b/platform/linux-generic/include/odp/api/debug.h index b0f91b1c..bef2fd0e 100644 --- a/platform/linux-generic/include/odp/api/debug.h +++ b/platform/linux-generic/include/odp/api/debug.h @@ -25,17 +25,23 @@ extern "C" { * versions. */ #define _odp_merge(a, b) a##b +/** @internal */ #define _odp_label(a) _odp_merge(_ODP_SASSERT_, a) +/** @internal */ #define _ODP_SASSERT _odp_label(__COUNTER__) +/** @internal */ #define _ODP_SASSERT_ENUM(e) { _ODP_SASSERT = 1 / !!(e) } +/** @internal */ #define _odp_static_assert(e, s) enum _ODP_SASSERT_ENUM(e)
#if defined(__clang__) #if defined(__cplusplus) #if !__has_feature(cxx_static_assert) && !defined(static_assert) +/** @internal */ #define static_assert(e, s) _odp_static_assert(e, s) #endif #elif !__has_feature(c_static_assert) && !defined(_Static_assert) +/** @internal */ #define _Static_assert(e, s) _odp_static_assert(e, s) #endif
@@ -44,9 +50,11 @@ extern "C" { (__GNUC__ < 6 && defined(__cplusplus)) #if defined(__cplusplus) #if !defined(static_assert) +/** @intenral */ #define static_assert(e, s) _odp_static_assert(e, s) #endif #elif !defined(_Static_assert) +/** @internal */ #define _Static_assert(e, s) _odp_static_assert(e, s) #endif #endif diff --git a/platform/linux-generic/include/odp/api/plat/packet_types.h b/platform/linux-generic/include/odp/api/plat/packet_types.h index 7e3c51e6..95cba5eb 100644 --- a/platform/linux-generic/include/odp/api/plat/packet_types.h +++ b/platform/linux-generic/include/odp/api/plat/packet_types.h @@ -105,6 +105,7 @@ typedef union { /** All input flags */ uint64_t all;
+ /** Individual input flags */ struct { uint64_t parsed_l2:1; /**< L2 parsed */ uint64_t dst_queue:1; /**< Dst queue present */ diff --git a/platform/linux-generic/include/odp/api/plat/traffic_mngr_types.h b/platform/linux-generic/include/odp/api/plat/traffic_mngr_types.h index b766afec..f47a13f6 100644 --- a/platform/linux-generic/include/odp/api/plat/traffic_mngr_types.h +++ b/platform/linux-generic/include/odp/api/plat/traffic_mngr_types.h @@ -168,7 +168,7 @@ typedef odp_tm_handle_t odp_tm_wred_t; */ #define ODP_TM_ROOT ((odp_tm_handle_t)-1)
-/** Get printable format of odp_queue_t */ +/** @internal Get printable format of odp_tm_handle_t @param hdl @return */ static inline uint64_t odp_tm_handle_to_u64(odp_tm_handle_t hdl) { return hdl;
commit 88e3d6b326a4c84f1b5a1e4c099a3a2519efb1f2 Author: Bill Fischofer bill.fischofer@linaro.org Date: Fri Apr 21 09:25:23 2017 -0500
api: tm: add additional doxygen documentation
Resolve Bug https://bugs.linaro.org/show_bug.cgi?id=2952 by adding additional field documentation to avoid problems with doxygen 1.8.13 and higher.
Signed-off-by: Bill Fischofer bill.fischofer@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/include/odp/api/spec/traffic_mngr.h b/include/odp/api/spec/traffic_mngr.h index 71198bbd..3a748cef 100644 --- a/include/odp/api/spec/traffic_mngr.h +++ b/include/odp/api/spec/traffic_mngr.h @@ -471,9 +471,10 @@ typedef enum { typedef struct { odp_tm_egress_kind_t egress_kind; /**< Union discriminator */
+ /** Variant parameters for different TM outputs */ union { - odp_pktio_t pktio; - odp_tm_egress_fcn_t egress_fcn; + odp_pktio_t pktio; /**< Output to PktIO */ + odp_tm_egress_fcn_t egress_fcn; /**< Output to user func */ }; } odp_tm_egress_t;
commit 83031014c51be27b9b64cf5fda10efc7fa1d3ed1 Author: Bill Fischofer bill.fischofer@linaro.org Date: Fri Apr 21 09:25:22 2017 -0500
api: pool: add additional doxygen documentation
Resolve Bug https://bugs.linaro.org/show_bug.cgi?id=2952 by adding additional field documentation to avoid problems with doxygen 1.8.13 and higher.
Signed-off-by: Bill Fischofer bill.fischofer@linaro.org Reviewed-by: Petri Savolainen petri.savolainen@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/include/odp/api/spec/pool.h b/include/odp/api/spec/pool.h index c0de195a..6fc5b6b4 100644 --- a/include/odp/api/spec/pool.h +++ b/include/odp/api/spec/pool.h @@ -166,7 +166,9 @@ typedef struct odp_pool_param_t { /** Pool type */ int type;
+ /** Variant parameters for different pool types */ union { + /** Parameters for buffer pools */ struct { /** Number of buffers in the pool */ uint32_t num; @@ -180,6 +182,8 @@ typedef struct odp_pool_param_t { Default will always be a multiple of 8. */ uint32_t align; } buf; + + /** Parameters for packet pools */ struct { /** The number of packets that the pool must provide that are packet length 'len' bytes or smaller. @@ -211,6 +215,8 @@ typedef struct odp_pool_param_t { Specify as 0 if no user area is needed. */ uint32_t uarea_size; } pkt; + + /** Parameters for timeout pools */ struct { /** Number of timeouts in the pool */ uint32_t num;
commit bae7f03986f3c62f86f4d794cd0fa17924b3f424 Author: Honnappa Nagarahalli honnappa.nagarahalli@linaro.org Date: Thu Apr 6 23:07:04 2017 -0500
helper: cuckoo: add queue size config to cuckoo table
Some queue implementations in ODP take queue size input. Cuckoo table is modified to provide the queue size input while creating the queue.
Signed-off-by: Honnappa Nagarahalli honnappa.nagarahalli@linaro.org Reviewed-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/helper/cuckootable.c b/helper/cuckootable.c index 80ff4989..0d46300e 100644 --- a/helper/cuckootable.c +++ b/helper/cuckootable.c @@ -256,6 +256,7 @@ odph_cuckoo_table_create( /* initialize free_slots queue */ odp_queue_param_init(&qparam); qparam.type = ODP_QUEUE_TYPE_PLAIN; + qparam.size = capacity;
snprintf(queue_name, sizeof(queue_name), "fs_%s", name); queue = odp_queue_create(queue_name, &qparam);
commit 5d4492900724ac7df931f57416c0d93c05d9d25d Author: Kevin Wang kevin.wang@arm.com Date: Fri Apr 14 10:57:21 2017 +0800
validation: scheduler: release context according to scheduler sync type
For different scheduler sync type, need to call different release function.
Signed-off-by: Kevin Wang kevin.wang@arm.com Reviewed-by: Honnappa Nagarahalli honnappa.nagarahalli@arm.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/validation/api/scheduler/scheduler.c b/test/common_plat/validation/api/scheduler/scheduler.c index f46d3910..4f99435c 100644 --- a/test/common_plat/validation/api/scheduler/scheduler.c +++ b/test/common_plat/validation/api/scheduler/scheduler.c @@ -129,6 +129,14 @@ static int exit_schedule_loop(void) return ret; }
+static void release_context(odp_schedule_sync_t sync) +{ + if (sync == ODP_SCHED_SYNC_ATOMIC) + odp_schedule_release_atomic(); + else if (sync == ODP_SCHED_SYNC_ORDERED) + odp_schedule_release_ordered(); +} + void scheduler_test_wait_time(void) { int i; @@ -251,8 +259,7 @@ void scheduler_test_queue_destroy(void) CU_ASSERT_FATAL(u32[0] == MAGIC);
odp_buffer_free(buf); - odp_schedule_release_ordered(); - + release_context(qp.sched.sync); CU_ASSERT_FATAL(odp_queue_destroy(queue) == 0); }
@@ -820,12 +827,7 @@ static int schedule_common_(void *arg) } }
- if (sync == ODP_SCHED_SYNC_ATOMIC) - odp_schedule_release_atomic(); - - if (sync == ODP_SCHED_SYNC_ORDERED) - odp_schedule_release_ordered(); - + release_context(sync); odp_ticketlock_lock(&globals->lock);
globals->buf_count -= num;
commit 75709852a7bc8a9f4856d9b182f6265d6cc098cc Author: Kevin Wang kevin.wang@arm.com Date: Tue Apr 11 10:38:06 2017 +0800
validation: scheduler: modify the queue size for atomic queue
Signed-off-by: Kevin Wang kevin.wang@arm.com Reviewed-by: Honnappa Nagarahalli honnappa.nagarahalli@arm.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/validation/api/scheduler/scheduler.c b/test/common_plat/validation/api/scheduler/scheduler.c index 952561cd..f46d3910 100644 --- a/test/common_plat/validation/api/scheduler/scheduler.c +++ b/test/common_plat/validation/api/scheduler/scheduler.c @@ -1388,6 +1388,7 @@ static int create_queues(void)
snprintf(name, sizeof(name), "sched_%d_%d_a", i, j); p.sched.sync = ODP_SCHED_SYNC_ATOMIC; + p.size = BUFS_PER_QUEUE_EXCL; q = odp_queue_create(name, &p);
if (q == ODP_QUEUE_INVALID) { @@ -1423,6 +1424,7 @@ static int create_queues(void) snprintf(name, sizeof(name), "sched_%d_%d_o", i, j); p.sched.sync = ODP_SCHED_SYNC_ORDERED; p.sched.lock_count = capa.max_ordered_locks; + p.size = 0; q = odp_queue_create(name, &p);
if (q == ODP_QUEUE_INVALID) {
commit b5c9093ac785f9b68b123d0e15629609a297bbcb Author: Petri Savolainen petri.savolainen@linaro.org Date: Thu Apr 13 17:40:51 2017 +0300
validation: queue: test queue max_num per type
Updated implementation and test with type specific number of queues.
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-by: Bill Fischofer bill.fischofer@linaro.org Reviewed-by: Honnappa Nagarahalli honnappa.nagarahalli@linaro.org Reviewed-by: Balasubramanian Manoharan bala.manoharan@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_queue.c b/platform/linux-generic/odp_queue.c index a96f9225..dd430cd1 100644 --- a/platform/linux-generic/odp_queue.c +++ b/platform/linux-generic/odp_queue.c @@ -176,6 +176,8 @@ int odp_queue_capability(odp_queue_capability_t *capa) capa->max_ordered_locks = sched_fn->max_ordered_locks(); capa->max_sched_groups = sched_fn->num_grps(); capa->sched_prios = odp_schedule_num_prio(); + capa->plain.max_num = capa->max_queues; + capa->sched.max_num = capa->max_queues;
return 0; } diff --git a/test/common_plat/validation/api/queue/queue.c b/test/common_plat/validation/api/queue/queue.c index 1f7913a1..6a13c006 100644 --- a/test/common_plat/validation/api/queue/queue.c +++ b/test/common_plat/validation/api/queue/queue.c @@ -56,7 +56,7 @@ void queue_test_capa(void) odp_queue_param_t qparams; char name[ODP_QUEUE_NAME_LEN]; odp_queue_t queue[MAX_QUEUES]; - uint32_t num_queues, i; + uint32_t num_queues, min, i, j;
memset(&capa, 0, sizeof(odp_queue_capability_t)); CU_ASSERT(odp_queue_capability(&capa) == 0); @@ -65,34 +65,49 @@ void queue_test_capa(void) CU_ASSERT(capa.max_ordered_locks != 0); CU_ASSERT(capa.max_sched_groups != 0); CU_ASSERT(capa.sched_prios != 0); + CU_ASSERT(capa.plain.max_num != 0); + CU_ASSERT(capa.sched.max_num != 0); + + min = capa.plain.max_num; + if (min > capa.sched.max_num) + min = capa.sched.max_num; + + CU_ASSERT(capa.max_queues >= min);
for (i = 0; i < ODP_QUEUE_NAME_LEN; i++) name[i] = 'A' + (i % 26);
name[ODP_QUEUE_NAME_LEN - 1] = 0;
- if (capa.max_queues > MAX_QUEUES) - num_queues = MAX_QUEUES; - else - num_queues = capa.max_queues; - odp_queue_param_init(&qparams);
- for (i = 0; i < num_queues; i++) { - generate_name(name, i); - queue[i] = odp_queue_create(name, &qparams); + for (j = 0; j < 2; j++) { + if (j == 0) { + num_queues = capa.plain.max_num; + } else { + num_queues = capa.sched.max_num; + qparams.type = ODP_QUEUE_TYPE_SCHED; + } + + if (num_queues > MAX_QUEUES) + num_queues = MAX_QUEUES;
- if (queue[i] == ODP_QUEUE_INVALID) { - CU_FAIL("Queue create failed"); - num_queues = i; - break; + for (i = 0; i < num_queues; i++) { + generate_name(name, i); + queue[i] = odp_queue_create(name, &qparams); + + if (queue[i] == ODP_QUEUE_INVALID) { + CU_FAIL("Queue create failed"); + num_queues = i; + break; + } + + CU_ASSERT(odp_queue_lookup(name) != ODP_QUEUE_INVALID); }
- CU_ASSERT(odp_queue_lookup(name) != ODP_QUEUE_INVALID); + for (i = 0; i < num_queues; i++) + CU_ASSERT(odp_queue_destroy(queue[i]) == 0); } - - for (i = 0; i < num_queues; i++) - CU_ASSERT(odp_queue_destroy(queue[i]) == 0); }
void queue_test_mode(void)
commit b563a8d681c1fa8c208c51bf83f545cfe28f4a7e Author: Petri Savolainen petri.savolainen@linaro.org Date: Thu Apr 13 17:40:50 2017 +0300
api: queue: added queue size param
Added capability information about maximum number of queues and queue sizes. Both are defined per queue type, since plain and scheduled queues may have different implementations (e.g. one uses HW while the other is SW).
Added queue size parameter, which specifies how large storage size application requires in minimum.
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-by: Bill Fischofer bill.fischofer@linaro.org Reviewed-by: Honnappa Nagarahalli honnappa.nagarahalli@linaro.org Reviewed-by: Balasubramanian Manoharan bala.manoharan@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/include/odp/api/spec/queue.h b/include/odp/api/spec/queue.h index 7972feac..9dd0a561 100644 --- a/include/odp/api/spec/queue.h +++ b/include/odp/api/spec/queue.h @@ -100,7 +100,9 @@ typedef enum odp_queue_op_mode_t { * Queue capabilities */ typedef struct odp_queue_capability_t { - /** Maximum number of event queues */ + /** Maximum number of event queues of any type (default size). Use + * this in addition to queue type specific 'max_num', if both queue + * types are used simultaneously. */ uint32_t max_queues;
/** Maximum number of ordered locks per queue */ @@ -112,6 +114,32 @@ typedef struct odp_queue_capability_t { /** Number of scheduling priorities */ unsigned sched_prios;
+ /** Plain queue capabilities */ + struct { + /** Maximum number of plain queues of the default size. */ + uint32_t max_num; + + /** Maximum number of events a plain queue can store + * simultaneously. The value of zero means that plain + * queues do not have a size limit, but a single queue can + * store all available events. */ + uint32_t max_size; + + } plain; + + /** Scheduled queue capabilities */ + struct { + /** Maximum number of scheduled queues of the default size. */ + uint32_t max_num; + + /** Maximum number of events a scheduled queue can store + * simultaneously. The value of zero means that scheduled + * queues do not have a size limit, but a single queue can + * store all available events. */ + uint32_t max_size; + + } sched; + } odp_queue_capability_t;
/** @@ -165,6 +193,15 @@ typedef struct odp_queue_param_t { * The implementation may use this value as a hint for the number of * context data bytes to prefetch. Default value is zero (no hint). */ uint32_t context_len; + + /** Queue size + * + * The queue must be able to store at minimum this many events + * simultaneously. The value must not exceed 'max_size' queue + * capability. The value of zero means implementation specific + * default size. */ + uint32_t size; + } odp_queue_param_t;
/**
commit cbba67aab7235a2c78a1a29cd0870498bd5ba897 Author: Matias Elo matias.elo@nokia.com Date: Thu Apr 6 17:41:17 2017 +0300
validation: pktio: remove CRCs from parser test packets
Remove precalculated CRCs from test packets. Some pktio devices may drop CRCs causing the tests to fail.
Signed-off-by: Matias Elo matias.elo@nokia.com Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/validation/api/pktio/parser.h b/test/common_plat/validation/api/pktio/parser.h index 57c62388..5cc2b988 100644 --- a/test/common_plat/validation/api/pktio/parser.h +++ b/test/common_plat/validation/api/pktio/parser.h @@ -28,6 +28,8 @@ int parser_suite_init(void); /* test arrays: */ extern odp_testinfo_t parser_suite[];
+/* Test packets without CRC */ + /** * ARP request */ @@ -39,7 +41,7 @@ static const uint8_t test_packet_arp[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xA8, 0x01, 0x02, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, - 0x0E, 0x0F, 0x10, 0x11, 0xA1, 0xA8, 0x27, 0x43, + 0x0E, 0x0F, 0x10, 0x11 };
/** @@ -53,7 +55,7 @@ static const uint8_t test_packet_ipv4_icmp[] = { 0x01, 0x02, 0x00, 0x00, 0xB7, 0xAB, 0x00, 0x01, 0x00, 0x02, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, - 0x0E, 0x0F, 0x10, 0x11, 0xD9, 0x7F, 0xE8, 0x02, + 0x0E, 0x0F, 0x10, 0x11 };
/** @@ -67,7 +69,7 @@ static const uint8_t test_packet_ipv4_tcp[] = { 0x01, 0x01, 0x04, 0xD2, 0x10, 0xE1, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x50, 0x00, 0x00, 0x00, 0x0C, 0xCC, 0x00, 0x00, 0x00, 0x01, - 0x02, 0x03, 0x04, 0x05, 0x2E, 0xDE, 0x5E, 0x48, + 0x02, 0x03, 0x04, 0x05 };
/** @@ -81,7 +83,7 @@ static const uint8_t test_packet_ipv4_udp[] = { 0x01, 0x01, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x1A, 0x2F, 0x97, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, - 0x0E, 0x0F, 0x10, 0x11, 0x64, 0xF4, 0xE4, 0xB6, + 0x0E, 0x0F, 0x10, 0x11 };
/** @@ -96,7 +98,7 @@ static const uint8_t test_packet_vlan_ipv4_udp[] = { 0x01, 0x02, 0xC4, 0xA8, 0x01, 0x01, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x16, 0x4D, 0xBF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, - 0x0A, 0x0B, 0x0C, 0x0D, 0xCB, 0xBF, 0xD0, 0x29, + 0x0A, 0x0B, 0x0C, 0x0D };
/** @@ -112,7 +114,7 @@ static const uint8_t test_packet_vlan_qinq_ipv4_udp[] = { 0xF3, 0x73, 0xC0, 0xA8, 0x01, 0x02, 0xC4, 0xA8, 0x01, 0x01, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x12, 0x63, 0xDF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, - 0x06, 0x07, 0x08, 0x09, 0x80, 0x98, 0xB8, 0x18, + 0x06, 0x07, 0x08, 0x09 };
/** @@ -126,8 +128,7 @@ static const uint8_t test_packet_ipv6_icmp[] = { 0x09, 0xFF, 0xFE, 0x00, 0x04, 0x00, 0x35, 0x55, 0x55, 0x55, 0x66, 0x66, 0x66, 0x66, 0x77, 0x77, 0x77, 0x77, 0x88, 0x88, 0x88, 0x88, 0x80, 0x00, - 0x1B, 0xC2, 0x00, 0x01, 0x00, 0x02, 0xE0, 0x68, - 0x0E, 0xBA, + 0x1B, 0xC2, 0x00, 0x01, 0x00, 0x02 };
/** @@ -143,7 +144,7 @@ static const uint8_t test_packet_ipv6_tcp[] = { 0x77, 0x77, 0x88, 0x88, 0x88, 0x88, 0x04, 0xD2, 0x10, 0xE1, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x50, 0x00, 0x00, 0x00, 0x36, 0x37, - 0x00, 0x00, 0x28, 0x67, 0xD2, 0xAF, + 0x00, 0x00 };
/** @@ -157,8 +158,7 @@ static const uint8_t test_packet_ipv6_udp[] = { 0x09, 0xFF, 0xFE, 0x00, 0x04, 0x00, 0x35, 0x55, 0x55, 0x55, 0x66, 0x66, 0x66, 0x66, 0x77, 0x77, 0x77, 0x77, 0x88, 0x88, 0x88, 0x88, 0x00, 0x3F, - 0x00, 0x3F, 0x00, 0x08, 0x9B, 0x68, 0x35, 0xD3, - 0x64, 0x49, + 0x00, 0x3F, 0x00, 0x08, 0x9B, 0x68 };
/** @@ -174,7 +174,7 @@ static const uint8_t test_packet_vlan_ipv6_udp[] = { 0x04, 0x00, 0x35, 0x55, 0x55, 0x55, 0x66, 0x66, 0x66, 0x66, 0x77, 0x77, 0x77, 0x77, 0x88, 0x88, 0x88, 0x88, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x08, - 0x9B, 0x68, 0xC5, 0xD8, 0x2F, 0x5C, + 0x9B, 0x68 };
#endif
commit f982a0d5793970f379ddcba78278363208f37e86 Author: Matias Elo matias.elo@nokia.com Date: Tue Apr 4 09:28:21 2017 +0300
validation: pktio: add tests for packet parsing
Test packet parsing using predefined test packets (byte arrays). Test packets are looped through tested pktio interfaces to force packet parsing.
Signed-off-by: Matias Elo matias.elo@nokia.com Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/validation/api/pktio/Makefile.am b/test/common_plat/validation/api/pktio/Makefile.am index 466d690d..c6368fba 100644 --- a/test/common_plat/validation/api/pktio/Makefile.am +++ b/test/common_plat/validation/api/pktio/Makefile.am @@ -4,7 +4,7 @@ noinst_LTLIBRARIES = libtestpktio.la libtestpktio_la_SOURCES = pktio.c
test_PROGRAMS = pktio_main$(EXEEXT) -dist_pktio_main_SOURCES = pktio_main.c +dist_pktio_main_SOURCES = pktio_main.c parser.c pktio_main_LDADD = libtestpktio.la $(LIBCUNIT_COMMON) $(LIBODP)
-EXTRA_DIST = pktio.h +EXTRA_DIST = pktio.h parser.h diff --git a/test/common_plat/validation/api/pktio/parser.c b/test/common_plat/validation/api/pktio/parser.c new file mode 100644 index 00000000..ad7101d0 --- /dev/null +++ b/test/common_plat/validation/api/pktio/parser.c @@ -0,0 +1,545 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#include <odp_api.h> +#include <odp_cunit_common.h> + +#include <odp/helper/odph_api.h> + +#include <stdlib.h> +#include "parser.h" +#include "pktio.h" + +#define MAX_NUM_IFACES 2 +#define PKT_POOL_NUM 256 +#define PKT_POOL_BUF_LEN (2 * 1024) + +/** + * local container for pktio attributes + */ +typedef struct { + const char *name; + odp_pktio_t hdl; + odp_pktout_queue_t pktout; + odp_pktin_queue_t pktin; +} pktio_info_t; + +/** Interface names used for testing */ +static const char *iface_name[MAX_NUM_IFACES]; + +/** Test interfaces */ +pktio_info_t pktios[MAX_NUM_IFACES]; +pktio_info_t *pktio_a; +pktio_info_t *pktio_b; + +/** Number of interfaces being used (1=loopback, 2=pair) */ +static int num_ifaces; + +/** While testing real-world interfaces additional time may be needed for + * external network to enable link to pktio interface that just become up. + */ +static bool wait_for_network; + +/** Parser packet pool */ +odp_pool_t parser_pool = ODP_POOL_INVALID; + +static inline void wait_linkup(odp_pktio_t pktio) +{ + /* wait 1 second for link up */ + uint64_t wait_ns = (10 * ODP_TIME_MSEC_IN_NS); + int wait_num = 100; + int i; + int ret = -1; + + for (i = 0; i < wait_num; i++) { + ret = odp_pktio_link_status(pktio); + if (ret < 0 || ret == 1) + break; + /* link is down, call status again after delay */ + odp_time_wait_ns(wait_ns); + } +} + +static int pkt_pool_create(void) +{ + odp_pool_capability_t capa; + odp_pool_param_t params; + + if (odp_pool_capability(&capa) != 0) { + printf("Error: unable to query pool capability.\n"); + return -1; + } + + if (capa.pkt.max_num && capa.pkt.max_num < PKT_POOL_NUM) { + printf("Error: packet pool size not supported.\n"); + printf("MAX: %" PRIu32 "\n", capa.pkt.max_num); + return -1; + } else if (capa.pkt.max_len && capa.pkt.max_len < PKT_POOL_BUF_LEN) { + printf("Error: packet length not supported.\n"); + return -1; + } else if (capa.pkt.max_seg_len && + capa.pkt.max_seg_len < PKT_POOL_BUF_LEN) { + printf("Error: segment length not supported.\n"); + return -1; + } + + odp_pool_param_init(¶ms); + params.pkt.seg_len = PKT_POOL_BUF_LEN; + params.pkt.len = PKT_POOL_BUF_LEN; + params.pkt.num = PKT_POOL_NUM; + params.type = ODP_POOL_PACKET; + + parser_pool = odp_pool_create("pkt_pool_default", ¶ms); + if (parser_pool == ODP_POOL_INVALID) { + printf("Error: packet pool create failed.\n"); + return -1; + } + + return 0; +} + +static odp_pktio_t create_pktio(int iface_idx, odp_pool_t pool) +{ + odp_pktio_t pktio; + odp_pktio_config_t config; + odp_pktio_param_t pktio_param; + const char *iface = iface_name[iface_idx]; + + odp_pktio_param_init(&pktio_param); + pktio_param.in_mode = ODP_PKTIN_MODE_DIRECT; + pktio_param.out_mode = ODP_PKTOUT_MODE_DIRECT; + + pktio = odp_pktio_open(iface, pool, &pktio_param); + if (pktio == ODP_PKTIO_INVALID) { + printf("Error: failed to open %s\n", iface); + return ODP_PKTIO_INVALID; + } + + odp_pktio_config_init(&config); + config.parser.layer = ODP_PKTIO_PARSER_LAYER_ALL; + if (odp_pktio_config(pktio, &config)) { + printf("Error: failed to configure %s\n", iface); + return ODP_PKTIO_INVALID; + } + + /* By default, single input and output queue is used */ + if (odp_pktin_queue_config(pktio, NULL)) { + printf("Error: failed to config input queue for %s\n", iface); + return ODP_PKTIO_INVALID; + } + if (odp_pktout_queue_config(pktio, NULL)) { + printf("Error: failed to config output queue for %s\n", iface); + return ODP_PKTIO_INVALID; + } + + if (wait_for_network) + odp_time_wait_ns(ODP_TIME_SEC_IN_NS / 4); + + return pktio; +} + +static odp_packet_t create_packet(const uint8_t *data, uint32_t len) +{ + odp_packet_t pkt; + + pkt = odp_packet_alloc(parser_pool, len); + if (pkt == ODP_PACKET_INVALID) + return ODP_PACKET_INVALID; + + if (odp_packet_copy_from_mem(pkt, 0, len, data)) { + printf("Error: failed to copy test packet data\n"); + odp_packet_free(pkt); + return ODP_PACKET_INVALID; + } + + odp_packet_l2_offset_set(pkt, 0); + + return pkt; +} + +/** + * Receive incoming packets and compare them to the original. Function returns + * a valid packet handle only when the received packet matches to the original + * packet. + */ +static odp_packet_t recv_and_cmp_packet(odp_pktin_queue_t pktin, + odp_packet_t orig_pkt, uint64_t ns) +{ + odp_packet_t pkt = ODP_PACKET_INVALID; + odp_time_t wait_time, end; + uint32_t orig_len; + uint8_t *orig_data; + + orig_len = odp_packet_len(orig_pkt); + orig_data = odp_packet_data(orig_pkt); + wait_time = odp_time_local_from_ns(ns); + end = odp_time_sum(odp_time_local(), wait_time); + + do { + int ret; + odp_packet_t tmp_pkt; + + ret = odp_pktin_recv(pktin, &tmp_pkt, 1); + if (ret < 0) + break; + + if (ret == 1) { + uint32_t len; + uint8_t *data; + + len = odp_packet_len(tmp_pkt); + data = odp_packet_data(tmp_pkt); + + if (len == orig_len && + memcmp(data, orig_data, len) == 0) { + pkt = tmp_pkt; + break; + } + odp_packet_free(tmp_pkt); + } + } while (odp_time_cmp(end, odp_time_local()) > 0); + + return pkt; +} + +/** + * Creates a test packet from data array and loops it through the test pktio + * interfaces forcing packet parsing. + */ +static odp_packet_t loopback_packet(pktio_info_t *pktio_a, + pktio_info_t *pktio_b, const uint8_t *data, + uint32_t len) +{ + odp_packet_t pkt; + odp_packet_t sent_pkt; + + pkt = create_packet(data, len); + if (pkt == ODP_PACKET_INVALID) { + CU_FAIL("failed to generate test packet"); + return ODP_PACKET_INVALID; + } + + pktio_pkt_set_macs(pkt, pktio_a->hdl, pktio_b->hdl); + + sent_pkt = odp_packet_copy(pkt, parser_pool); + if (sent_pkt == ODP_PACKET_INVALID) { + CU_FAIL_FATAL("failed to copy test packet"); + odp_packet_free(pkt); + return ODP_PACKET_INVALID; + } + + while (1) { + int ret = odp_pktout_send(pktio_a->pktout, &pkt, 1); + + if (ret < 0) { + CU_FAIL_FATAL("failed to send test packet"); + odp_packet_free(pkt); + odp_packet_free(sent_pkt); + return ODP_PACKET_INVALID; + } + if (ret == 1) + break; + } + + /* and wait for them to arrive back */ + pkt = recv_and_cmp_packet(pktio_b->pktin, sent_pkt, ODP_TIME_SEC_IN_NS); + odp_packet_free(sent_pkt); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_input(pkt) == pktio_b->hdl); + CU_ASSERT(odp_packet_has_error(pkt) == 0); + + return pkt; +} + +void parser_test_arp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_arp, + sizeof(test_packet_arp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_arp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv4(pkt)); + CU_ASSERT(!odp_packet_has_ipv6(pkt)); + + odp_packet_free(pkt); +} + +void parser_test_ipv4_icmp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_ipv4_icmp, + sizeof(test_packet_ipv4_icmp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_ipv4(pkt)); + CU_ASSERT(odp_packet_has_icmp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv6(pkt)); + CU_ASSERT(!odp_packet_has_tcp(pkt)); + CU_ASSERT(!odp_packet_has_udp(pkt)); + + odp_packet_free(pkt); +} + +void parser_test_ipv4_tcp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_ipv4_tcp, + sizeof(test_packet_ipv4_tcp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_ipv4(pkt)); + CU_ASSERT(odp_packet_has_tcp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv6(pkt)); + CU_ASSERT(!odp_packet_has_udp(pkt)); + + odp_packet_free(pkt); +} + +void parser_test_ipv4_udp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_ipv4_udp, + sizeof(test_packet_ipv4_udp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_ipv4(pkt)); + CU_ASSERT(odp_packet_has_udp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv6(pkt)); + CU_ASSERT(!odp_packet_has_tcp(pkt)); + + odp_packet_free(pkt); +} + +void parser_test_vlan_ipv4_udp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_vlan_ipv4_udp, + sizeof(test_packet_vlan_ipv4_udp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_vlan(pkt)); + CU_ASSERT(odp_packet_has_ipv4(pkt)); + CU_ASSERT(odp_packet_has_udp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv6(pkt)); + CU_ASSERT(!odp_packet_has_tcp(pkt)); + + odp_packet_free(pkt); +} + +void parser_test_vlan_qinq_ipv4_udp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_vlan_qinq_ipv4_udp, + sizeof(test_packet_vlan_qinq_ipv4_udp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_vlan(pkt)); + CU_ASSERT(odp_packet_has_vlan_qinq(pkt)); + CU_ASSERT(odp_packet_has_ipv4(pkt)); + CU_ASSERT(odp_packet_has_udp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv6(pkt)); + CU_ASSERT(!odp_packet_has_tcp(pkt)); + + odp_packet_free(pkt); +} + +void parser_test_ipv6_icmp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_ipv6_icmp, + sizeof(test_packet_ipv6_icmp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_ipv6(pkt)); + CU_ASSERT(odp_packet_has_icmp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv4(pkt)); + CU_ASSERT(!odp_packet_has_tcp(pkt)); + CU_ASSERT(!odp_packet_has_udp(pkt)); + + odp_packet_free(pkt); +} + +void parser_test_ipv6_tcp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_ipv6_tcp, + sizeof(test_packet_ipv6_tcp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_ipv6(pkt)); + CU_ASSERT(odp_packet_has_tcp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv4(pkt)); + CU_ASSERT(!odp_packet_has_udp(pkt)); + + odp_packet_free(pkt); +} + +void parser_test_ipv6_udp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_ipv6_udp, + sizeof(test_packet_ipv6_udp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_ipv6(pkt)); + CU_ASSERT(odp_packet_has_udp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv4(pkt)); + CU_ASSERT(!odp_packet_has_tcp(pkt)); + + odp_packet_free(pkt); +} + +void parser_test_vlan_ipv6_udp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_vlan_ipv6_udp, + sizeof(test_packet_vlan_ipv6_udp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_vlan(pkt)); + CU_ASSERT(odp_packet_has_ipv6(pkt)); + CU_ASSERT(odp_packet_has_udp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv4(pkt)); + CU_ASSERT(!odp_packet_has_tcp(pkt)); + + odp_packet_free(pkt); +} + +int parser_suite_init(void) +{ + int i; + + if (getenv("ODP_WAIT_FOR_NETWORK")) + wait_for_network = true; + + iface_name[0] = getenv("ODP_PKTIO_IF0"); + iface_name[1] = getenv("ODP_PKTIO_IF1"); + num_ifaces = 1; + + if (!iface_name[0]) { + printf("No interfaces specified, using default "loop".\n"); + iface_name[0] = "loop"; + } else if (!iface_name[1]) { + printf("Using loopback interface: %s\n", iface_name[0]); + } else { + num_ifaces = 2; + printf("Using paired interfaces: %s %s\n", + iface_name[0], iface_name[1]); + } + + if (pkt_pool_create() != 0) { + printf("Error: failed to create parser pool\n"); + return -1; + } + + /* Create pktios and associate input/output queues */ + for (i = 0; i < num_ifaces; ++i) { + pktio_info_t *io; + + io = &pktios[i]; + io->name = iface_name[i]; + io->hdl = create_pktio(i, parser_pool); + if (io->hdl == ODP_PKTIO_INVALID) { + printf("Error: failed to open iface"); + return -1; + } + + if (odp_pktout_queue(io->hdl, &io->pktout, 1) != 1) { + printf("Error: failed to start iface: %s\n", io->name); + return -1; + } + + if (odp_pktin_queue(io->hdl, &io->pktin, 1) != 1) { + printf("Error: failed to start iface: %s\n", io->name); + return -1; + } + + if (odp_pktio_start(io->hdl)) { + printf("Error: failed to start iface: %s\n", io->name); + return -1; + } + + wait_linkup(io->hdl); + } + + pktio_a = &pktios[0]; + pktio_b = &pktios[1]; + if (num_ifaces == 1) + pktio_b = pktio_a; + + return 0; +} + +int parser_suite_term(void) +{ + int i; + int ret = 0; + + for (i = 0; i < num_ifaces; ++i) { + if (odp_pktio_stop(pktios[i].hdl)) { + printf("Error: failed to stop pktio: %s\n", + pktios[i].name); + ret = -1; + } + if (odp_pktio_close(pktios[i].hdl)) { + printf("Error: failed to close pktio: %s\n", + pktios[i].name); + ret = -1; + } + } + + if (odp_pool_destroy(parser_pool) != 0) { + printf("Error: failed to destroy packet pool\n"); + ret = -1; + } + + return ret; +} + +/** + * Certain tests can only be run with 'loop' pktio. + */ +static int loop_pktio(void) +{ + if (strcmp(iface_name[0], "loop") == 0) + return ODP_TEST_ACTIVE; + else + return ODP_TEST_INACTIVE; +} + +odp_testinfo_t parser_suite[] = { + ODP_TEST_INFO(parser_test_arp), + ODP_TEST_INFO(parser_test_ipv4_icmp), + ODP_TEST_INFO(parser_test_ipv4_tcp), + ODP_TEST_INFO(parser_test_ipv4_udp), + ODP_TEST_INFO_CONDITIONAL(parser_test_vlan_ipv4_udp, loop_pktio), + ODP_TEST_INFO_CONDITIONAL(parser_test_vlan_qinq_ipv4_udp, loop_pktio), + ODP_TEST_INFO(parser_test_ipv6_icmp), + ODP_TEST_INFO(parser_test_ipv6_tcp), + ODP_TEST_INFO(parser_test_ipv6_udp), + ODP_TEST_INFO_CONDITIONAL(parser_test_vlan_ipv6_udp, loop_pktio), + ODP_TEST_INFO_NULL +}; diff --git a/test/common_plat/validation/api/pktio/parser.h b/test/common_plat/validation/api/pktio/parser.h new file mode 100644 index 00000000..57c62388 --- /dev/null +++ b/test/common_plat/validation/api/pktio/parser.h @@ -0,0 +1,180 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_PARSER_H_ +#define _ODP_TEST_PARSER_H_ + +#include <odp_cunit_common.h> + +/* test functions: */ +void parser_test_arp(void); +void parser_test_ipv4_icmp(void); +void parser_test_ipv4_tcp(void); +void parser_test_ipv4_udp(void); +void parser_test_vlan_ipv4_udp(void); +void parser_test_vlan_qinq_ipv4_udp(void); +void parser_test_ipv6_icmp(void); +void parser_test_ipv6_tcp(void); +void parser_test_ipv6_udp(void); +void parser_test_vlan_ipv6_udp(void); + +/* test array init/term functions: */ +int parser_suite_term(void); +int parser_suite_init(void); + +/* test arrays: */ +extern odp_testinfo_t parser_suite[]; + +/** + * ARP request + */ +static const uint8_t test_packet_arp[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x08, 0x06, 0x00, 0x01, + 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0xC0, 0xA8, 0x01, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xA8, + 0x01, 0x02, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, + 0x0E, 0x0F, 0x10, 0x11, 0xA1, 0xA8, 0x27, 0x43, +}; + +/** + * ICMPv4 echo reply + */ +static const uint8_t test_packet_ipv4_icmp[] = { + 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x08, 0x00, 0x45, 0x00, + 0x00, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x40, 0x01, + 0xF3, 0x7B, 0xC0, 0xA8, 0x01, 0x01, 0xC4, 0xA8, + 0x01, 0x02, 0x00, 0x00, 0xB7, 0xAB, 0x00, 0x01, + 0x00, 0x02, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, + 0x0E, 0x0F, 0x10, 0x11, 0xD9, 0x7F, 0xE8, 0x02, +}; + +/** + * IPv4 TCP + */ +static const uint8_t test_packet_ipv4_tcp[] = { + 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x08, 0x00, 0x45, 0x00, + 0x00, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x40, 0x06, + 0xF3, 0x76, 0xC0, 0xA8, 0x01, 0x02, 0xC4, 0xA8, + 0x01, 0x01, 0x04, 0xD2, 0x10, 0xE1, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x50, 0x00, + 0x00, 0x00, 0x0C, 0xCC, 0x00, 0x00, 0x00, 0x01, + 0x02, 0x03, 0x04, 0x05, 0x2E, 0xDE, 0x5E, 0x48, +}; + +/** + * IPv4 UDP + */ +static const uint8_t test_packet_ipv4_udp[] = { + 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x08, 0x00, 0x45, 0x00, + 0x00, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x40, 0x11, + 0xF3, 0x6B, 0xC0, 0xA8, 0x01, 0x02, 0xC4, 0xA8, + 0x01, 0x01, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x1A, + 0x2F, 0x97, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, + 0x0E, 0x0F, 0x10, 0x11, 0x64, 0xF4, 0xE4, 0xB6, +}; + +/** + * VLAN IPv4 UDP + * - ID: 23 + */ +static const uint8_t test_packet_vlan_ipv4_udp[] = { + 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x81, 0x00, 0x00, 0x17, + 0x08, 0x00, 0x45, 0x00, 0x00, 0x2A, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x11, 0xF3, 0x6F, 0xC0, 0xA8, + 0x01, 0x02, 0xC4, 0xA8, 0x01, 0x01, 0x00, 0x3F, + 0x00, 0x3F, 0x00, 0x16, 0x4D, 0xBF, 0x00, 0x01, + 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + 0x0A, 0x0B, 0x0C, 0x0D, 0xCB, 0xBF, 0xD0, 0x29, +}; + +/** + * VLAN Q-in-Q IPv4 UDP + * - Outer: Tag Protocol ID 0x88a8, VLAN ID 1 + * - Inner: Tag Protocol ID 0x8100, VLAN ID 2 + */ +static const uint8_t test_packet_vlan_qinq_ipv4_udp[] = { + 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x88, 0xA8, 0x00, 0x01, + 0x81, 0x00, 0x00, 0x02, 0x08, 0x00, 0x45, 0x00, + 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x40, 0x11, + 0xF3, 0x73, 0xC0, 0xA8, 0x01, 0x02, 0xC4, 0xA8, + 0x01, 0x01, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x12, + 0x63, 0xDF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x08, 0x09, 0x80, 0x98, 0xB8, 0x18, +}; + +/** + * ICMPv6 echo request + */ +static const uint8_t test_packet_ipv6_icmp[] = { + 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x86, 0xDD, 0x60, 0x30, + 0x00, 0x00, 0x00, 0x08, 0x3A, 0xFF, 0xFE, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x09, 0xFF, 0xFE, 0x00, 0x04, 0x00, 0x35, 0x55, + 0x55, 0x55, 0x66, 0x66, 0x66, 0x66, 0x77, 0x77, + 0x77, 0x77, 0x88, 0x88, 0x88, 0x88, 0x80, 0x00, + 0x1B, 0xC2, 0x00, 0x01, 0x00, 0x02, 0xE0, 0x68, + 0x0E, 0xBA, +}; + +/** + * IPv6 TCP + */ +static const uint8_t test_packet_ipv6_tcp[] = { + 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x86, 0xDD, 0x60, 0x30, + 0x00, 0x00, 0x00, 0x14, 0x06, 0xFF, 0xFE, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x09, 0xFF, 0xFE, 0x00, 0x04, 0x00, 0x35, 0x55, + 0x55, 0x55, 0x66, 0x66, 0x66, 0x66, 0x77, 0x77, + 0x77, 0x77, 0x88, 0x88, 0x88, 0x88, 0x04, 0xD2, + 0x10, 0xE1, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x02, 0x50, 0x00, 0x00, 0x00, 0x36, 0x37, + 0x00, 0x00, 0x28, 0x67, 0xD2, 0xAF, +}; + +/** + * IPv6 UDP + */ +static const uint8_t test_packet_ipv6_udp[] = { + 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x86, 0xDD, 0x60, 0x30, + 0x00, 0x00, 0x00, 0x08, 0x11, 0xFF, 0xFE, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x09, 0xFF, 0xFE, 0x00, 0x04, 0x00, 0x35, 0x55, + 0x55, 0x55, 0x66, 0x66, 0x66, 0x66, 0x77, 0x77, + 0x77, 0x77, 0x88, 0x88, 0x88, 0x88, 0x00, 0x3F, + 0x00, 0x3F, 0x00, 0x08, 0x9B, 0x68, 0x35, 0xD3, + 0x64, 0x49, +}; + +/** + * VLAN IPv6 + * - ID: 23 + */ +static const uint8_t test_packet_vlan_ipv6_udp[] = { + 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x81, 0x00, 0x00, 0x17, + 0x86, 0xDD, 0x60, 0x30, 0x00, 0x00, 0x00, 0x08, + 0x11, 0xFF, 0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x09, 0xFF, 0xFE, 0x00, + 0x04, 0x00, 0x35, 0x55, 0x55, 0x55, 0x66, 0x66, + 0x66, 0x66, 0x77, 0x77, 0x77, 0x77, 0x88, 0x88, + 0x88, 0x88, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x08, + 0x9B, 0x68, 0xC5, 0xD8, 0x2F, 0x5C, +}; + +#endif diff --git a/test/common_plat/validation/api/pktio/pktio.c b/test/common_plat/validation/api/pktio/pktio.c index a21959ef..43fe515a 100644 --- a/test/common_plat/validation/api/pktio/pktio.c +++ b/test/common_plat/validation/api/pktio/pktio.c @@ -10,6 +10,7 @@
#include <stdlib.h> #include "pktio.h" +#include "parser.h"
#define PKT_BUF_NUM 32 #define PKT_BUF_SIZE (9 * 1024) @@ -143,8 +144,7 @@ static void set_pool_len(odp_pool_param_t *params, odp_pool_capability_t *capa) } }
-static void pktio_pkt_set_macs(odp_packet_t pkt, - odp_pktio_t src, odp_pktio_t dst) +void pktio_pkt_set_macs(odp_packet_t pkt, odp_pktio_t src, odp_pktio_t dst) { uint32_t len; odph_ethhdr_t *eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, &len); @@ -2190,6 +2190,7 @@ odp_suiteinfo_t pktio_suites[] = { pktio_suite_term, pktio_suite_unsegmented}, {"Packet I/O Segmented", pktio_suite_init_segmented, pktio_suite_term, pktio_suite_segmented}, + {"Packet parser", parser_suite_init, parser_suite_term, parser_suite}, ODP_SUITE_INFO_NULL };
diff --git a/test/common_plat/validation/api/pktio/pktio.h b/test/common_plat/validation/api/pktio/pktio.h index 8131d05f..b8799d9e 100644 --- a/test/common_plat/validation/api/pktio/pktio.h +++ b/test/common_plat/validation/api/pktio/pktio.h @@ -61,4 +61,7 @@ extern odp_suiteinfo_t pktio_suites[]; /* main test program: */ int pktio_main(int argc, char *argv[]);
+/* functions shared by parser test suite */ +void pktio_pkt_set_macs(odp_packet_t pkt, odp_pktio_t src, odp_pktio_t dst); + #endif
commit 91b26ee0ef846979b8a2bfdfb44076a497611d5a Author: Maxim Uvarov maxim.uvarov@linaro.org Date: Tue Apr 11 16:31:14 2017 +0300
Revert "validation: pktio: add tests for packet parsing"
This reverts commit 5a770508ecf (validation: pktio: add tests for packet parsing) This commit breaks tap pktio test on Travis CI and some over envs. That needs to be fixed before restoring it back. Suite: Packet parser Test: parser_test_arp ...passed Test: parser_test_ipv4_icmp ...received pkt 0x7fec7ea00000, len == 60, orig_len = 64 FAILED 1. parser.c:251 - pkt != ODP_PACKET_INVALID Test: parser_test_ipv4_tcp ...received pkt 0x7fec7ea425c0, len == 60, orig_len = 64 FAILED 1. parser.c:251 - pkt != ODP_PACKET_INVALID Test: parser_test_ipv4_udp ...received pkt 0x7fec7ea00000, len == 60, orig_len = 64 FAILED 1. parser.c:251 - pkt != ODP_PACKET_INVALID Test: parser_test_ipv6_icmp ...received pkt 0x7fec7ea425c0, len == 62, orig_len = 66 FAILED 1. parser.c:251 - pkt != ODP_PACKET_INVALID Test: parser_test_ipv6_tcp ...received pkt 0x7fec7ea00000, len == 74, orig_len = 78 FAILED 1. parser.c:251 - pkt != ODP_PACKET_INVALID Test: parser_test_ipv6_udp ...received pkt 0x7fec7ea425c0, len == 62, orig_len = 66 FAILED 1. parser.c:251 - pkt != ODP_PACKET_INVALID
Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/validation/api/pktio/Makefile.am b/test/common_plat/validation/api/pktio/Makefile.am index c6368fba..466d690d 100644 --- a/test/common_plat/validation/api/pktio/Makefile.am +++ b/test/common_plat/validation/api/pktio/Makefile.am @@ -4,7 +4,7 @@ noinst_LTLIBRARIES = libtestpktio.la libtestpktio_la_SOURCES = pktio.c
test_PROGRAMS = pktio_main$(EXEEXT) -dist_pktio_main_SOURCES = pktio_main.c parser.c +dist_pktio_main_SOURCES = pktio_main.c pktio_main_LDADD = libtestpktio.la $(LIBCUNIT_COMMON) $(LIBODP)
-EXTRA_DIST = pktio.h parser.h +EXTRA_DIST = pktio.h diff --git a/test/common_plat/validation/api/pktio/parser.c b/test/common_plat/validation/api/pktio/parser.c deleted file mode 100644 index ad7101d0..00000000 --- a/test/common_plat/validation/api/pktio/parser.c +++ /dev/null @@ -1,545 +0,0 @@ -/* Copyright (c) 2017, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ -#include <odp_api.h> -#include <odp_cunit_common.h> - -#include <odp/helper/odph_api.h> - -#include <stdlib.h> -#include "parser.h" -#include "pktio.h" - -#define MAX_NUM_IFACES 2 -#define PKT_POOL_NUM 256 -#define PKT_POOL_BUF_LEN (2 * 1024) - -/** - * local container for pktio attributes - */ -typedef struct { - const char *name; - odp_pktio_t hdl; - odp_pktout_queue_t pktout; - odp_pktin_queue_t pktin; -} pktio_info_t; - -/** Interface names used for testing */ -static const char *iface_name[MAX_NUM_IFACES]; - -/** Test interfaces */ -pktio_info_t pktios[MAX_NUM_IFACES]; -pktio_info_t *pktio_a; -pktio_info_t *pktio_b; - -/** Number of interfaces being used (1=loopback, 2=pair) */ -static int num_ifaces; - -/** While testing real-world interfaces additional time may be needed for - * external network to enable link to pktio interface that just become up. - */ -static bool wait_for_network; - -/** Parser packet pool */ -odp_pool_t parser_pool = ODP_POOL_INVALID; - -static inline void wait_linkup(odp_pktio_t pktio) -{ - /* wait 1 second for link up */ - uint64_t wait_ns = (10 * ODP_TIME_MSEC_IN_NS); - int wait_num = 100; - int i; - int ret = -1; - - for (i = 0; i < wait_num; i++) { - ret = odp_pktio_link_status(pktio); - if (ret < 0 || ret == 1) - break; - /* link is down, call status again after delay */ - odp_time_wait_ns(wait_ns); - } -} - -static int pkt_pool_create(void) -{ - odp_pool_capability_t capa; - odp_pool_param_t params; - - if (odp_pool_capability(&capa) != 0) { - printf("Error: unable to query pool capability.\n"); - return -1; - } - - if (capa.pkt.max_num && capa.pkt.max_num < PKT_POOL_NUM) { - printf("Error: packet pool size not supported.\n"); - printf("MAX: %" PRIu32 "\n", capa.pkt.max_num); - return -1; - } else if (capa.pkt.max_len && capa.pkt.max_len < PKT_POOL_BUF_LEN) { - printf("Error: packet length not supported.\n"); - return -1; - } else if (capa.pkt.max_seg_len && - capa.pkt.max_seg_len < PKT_POOL_BUF_LEN) { - printf("Error: segment length not supported.\n"); - return -1; - } - - odp_pool_param_init(¶ms); - params.pkt.seg_len = PKT_POOL_BUF_LEN; - params.pkt.len = PKT_POOL_BUF_LEN; - params.pkt.num = PKT_POOL_NUM; - params.type = ODP_POOL_PACKET; - - parser_pool = odp_pool_create("pkt_pool_default", ¶ms); - if (parser_pool == ODP_POOL_INVALID) { - printf("Error: packet pool create failed.\n"); - return -1; - } - - return 0; -} - -static odp_pktio_t create_pktio(int iface_idx, odp_pool_t pool) -{ - odp_pktio_t pktio; - odp_pktio_config_t config; - odp_pktio_param_t pktio_param; - const char *iface = iface_name[iface_idx]; - - odp_pktio_param_init(&pktio_param); - pktio_param.in_mode = ODP_PKTIN_MODE_DIRECT; - pktio_param.out_mode = ODP_PKTOUT_MODE_DIRECT; - - pktio = odp_pktio_open(iface, pool, &pktio_param); - if (pktio == ODP_PKTIO_INVALID) { - printf("Error: failed to open %s\n", iface); - return ODP_PKTIO_INVALID; - } - - odp_pktio_config_init(&config); - config.parser.layer = ODP_PKTIO_PARSER_LAYER_ALL; - if (odp_pktio_config(pktio, &config)) { - printf("Error: failed to configure %s\n", iface); - return ODP_PKTIO_INVALID; - } - - /* By default, single input and output queue is used */ - if (odp_pktin_queue_config(pktio, NULL)) { - printf("Error: failed to config input queue for %s\n", iface); - return ODP_PKTIO_INVALID; - } - if (odp_pktout_queue_config(pktio, NULL)) { - printf("Error: failed to config output queue for %s\n", iface); - return ODP_PKTIO_INVALID; - } - - if (wait_for_network) - odp_time_wait_ns(ODP_TIME_SEC_IN_NS / 4); - - return pktio; -} - -static odp_packet_t create_packet(const uint8_t *data, uint32_t len) -{ - odp_packet_t pkt; - - pkt = odp_packet_alloc(parser_pool, len); - if (pkt == ODP_PACKET_INVALID) - return ODP_PACKET_INVALID; - - if (odp_packet_copy_from_mem(pkt, 0, len, data)) { - printf("Error: failed to copy test packet data\n"); - odp_packet_free(pkt); - return ODP_PACKET_INVALID; - } - - odp_packet_l2_offset_set(pkt, 0); - - return pkt; -} - -/** - * Receive incoming packets and compare them to the original. Function returns - * a valid packet handle only when the received packet matches to the original - * packet. - */ -static odp_packet_t recv_and_cmp_packet(odp_pktin_queue_t pktin, - odp_packet_t orig_pkt, uint64_t ns) -{ - odp_packet_t pkt = ODP_PACKET_INVALID; - odp_time_t wait_time, end; - uint32_t orig_len; - uint8_t *orig_data; - - orig_len = odp_packet_len(orig_pkt); - orig_data = odp_packet_data(orig_pkt); - wait_time = odp_time_local_from_ns(ns); - end = odp_time_sum(odp_time_local(), wait_time); - - do { - int ret; - odp_packet_t tmp_pkt; - - ret = odp_pktin_recv(pktin, &tmp_pkt, 1); - if (ret < 0) - break; - - if (ret == 1) { - uint32_t len; - uint8_t *data; - - len = odp_packet_len(tmp_pkt); - data = odp_packet_data(tmp_pkt); - - if (len == orig_len && - memcmp(data, orig_data, len) == 0) { - pkt = tmp_pkt; - break; - } - odp_packet_free(tmp_pkt); - } - } while (odp_time_cmp(end, odp_time_local()) > 0); - - return pkt; -} - -/** - * Creates a test packet from data array and loops it through the test pktio - * interfaces forcing packet parsing. - */ -static odp_packet_t loopback_packet(pktio_info_t *pktio_a, - pktio_info_t *pktio_b, const uint8_t *data, - uint32_t len) -{ - odp_packet_t pkt; - odp_packet_t sent_pkt; - - pkt = create_packet(data, len); - if (pkt == ODP_PACKET_INVALID) { - CU_FAIL("failed to generate test packet"); - return ODP_PACKET_INVALID; - } - - pktio_pkt_set_macs(pkt, pktio_a->hdl, pktio_b->hdl); - - sent_pkt = odp_packet_copy(pkt, parser_pool); - if (sent_pkt == ODP_PACKET_INVALID) { - CU_FAIL_FATAL("failed to copy test packet"); - odp_packet_free(pkt); - return ODP_PACKET_INVALID; - } - - while (1) { - int ret = odp_pktout_send(pktio_a->pktout, &pkt, 1); - - if (ret < 0) { - CU_FAIL_FATAL("failed to send test packet"); - odp_packet_free(pkt); - odp_packet_free(sent_pkt); - return ODP_PACKET_INVALID; - } - if (ret == 1) - break; - } - - /* and wait for them to arrive back */ - pkt = recv_and_cmp_packet(pktio_b->pktin, sent_pkt, ODP_TIME_SEC_IN_NS); - odp_packet_free(sent_pkt); - CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); - CU_ASSERT(odp_packet_input(pkt) == pktio_b->hdl); - CU_ASSERT(odp_packet_has_error(pkt) == 0); - - return pkt; -} - -void parser_test_arp(void) -{ - odp_packet_t pkt; - - pkt = loopback_packet(pktio_a, pktio_b, test_packet_arp, - sizeof(test_packet_arp)); - CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); - CU_ASSERT(odp_packet_has_eth(pkt)); - CU_ASSERT(odp_packet_has_arp(pkt)); - - CU_ASSERT(!odp_packet_has_ipv4(pkt)); - CU_ASSERT(!odp_packet_has_ipv6(pkt)); - - odp_packet_free(pkt); -} - -void parser_test_ipv4_icmp(void) -{ - odp_packet_t pkt; - - pkt = loopback_packet(pktio_a, pktio_b, test_packet_ipv4_icmp, - sizeof(test_packet_ipv4_icmp)); - CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); - CU_ASSERT(odp_packet_has_eth(pkt)); - CU_ASSERT(odp_packet_has_ipv4(pkt)); - CU_ASSERT(odp_packet_has_icmp(pkt)); - - CU_ASSERT(!odp_packet_has_ipv6(pkt)); - CU_ASSERT(!odp_packet_has_tcp(pkt)); - CU_ASSERT(!odp_packet_has_udp(pkt)); - - odp_packet_free(pkt); -} - -void parser_test_ipv4_tcp(void) -{ - odp_packet_t pkt; - - pkt = loopback_packet(pktio_a, pktio_b, test_packet_ipv4_tcp, - sizeof(test_packet_ipv4_tcp)); - CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); - CU_ASSERT(odp_packet_has_eth(pkt)); - CU_ASSERT(odp_packet_has_ipv4(pkt)); - CU_ASSERT(odp_packet_has_tcp(pkt)); - - CU_ASSERT(!odp_packet_has_ipv6(pkt)); - CU_ASSERT(!odp_packet_has_udp(pkt)); - - odp_packet_free(pkt); -} - -void parser_test_ipv4_udp(void) -{ - odp_packet_t pkt; - - pkt = loopback_packet(pktio_a, pktio_b, test_packet_ipv4_udp, - sizeof(test_packet_ipv4_udp)); - CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); - CU_ASSERT(odp_packet_has_eth(pkt)); - CU_ASSERT(odp_packet_has_ipv4(pkt)); - CU_ASSERT(odp_packet_has_udp(pkt)); - - CU_ASSERT(!odp_packet_has_ipv6(pkt)); - CU_ASSERT(!odp_packet_has_tcp(pkt)); - - odp_packet_free(pkt); -} - -void parser_test_vlan_ipv4_udp(void) -{ - odp_packet_t pkt; - - pkt = loopback_packet(pktio_a, pktio_b, test_packet_vlan_ipv4_udp, - sizeof(test_packet_vlan_ipv4_udp)); - CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); - CU_ASSERT(odp_packet_has_eth(pkt)); - CU_ASSERT(odp_packet_has_vlan(pkt)); - CU_ASSERT(odp_packet_has_ipv4(pkt)); - CU_ASSERT(odp_packet_has_udp(pkt)); - - CU_ASSERT(!odp_packet_has_ipv6(pkt)); - CU_ASSERT(!odp_packet_has_tcp(pkt)); - - odp_packet_free(pkt); -} - -void parser_test_vlan_qinq_ipv4_udp(void) -{ - odp_packet_t pkt; - - pkt = loopback_packet(pktio_a, pktio_b, test_packet_vlan_qinq_ipv4_udp, - sizeof(test_packet_vlan_qinq_ipv4_udp)); - CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); - CU_ASSERT(odp_packet_has_eth(pkt)); - CU_ASSERT(odp_packet_has_vlan(pkt)); - CU_ASSERT(odp_packet_has_vlan_qinq(pkt)); - CU_ASSERT(odp_packet_has_ipv4(pkt)); - CU_ASSERT(odp_packet_has_udp(pkt)); - - CU_ASSERT(!odp_packet_has_ipv6(pkt)); - CU_ASSERT(!odp_packet_has_tcp(pkt)); - - odp_packet_free(pkt); -} - -void parser_test_ipv6_icmp(void) -{ - odp_packet_t pkt; - - pkt = loopback_packet(pktio_a, pktio_b, test_packet_ipv6_icmp, - sizeof(test_packet_ipv6_icmp)); - CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); - CU_ASSERT(odp_packet_has_eth(pkt)); - CU_ASSERT(odp_packet_has_ipv6(pkt)); - CU_ASSERT(odp_packet_has_icmp(pkt)); - - CU_ASSERT(!odp_packet_has_ipv4(pkt)); - CU_ASSERT(!odp_packet_has_tcp(pkt)); - CU_ASSERT(!odp_packet_has_udp(pkt)); - - odp_packet_free(pkt); -} - -void parser_test_ipv6_tcp(void) -{ - odp_packet_t pkt; - - pkt = loopback_packet(pktio_a, pktio_b, test_packet_ipv6_tcp, - sizeof(test_packet_ipv6_tcp)); - CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); - CU_ASSERT(odp_packet_has_eth(pkt)); - CU_ASSERT(odp_packet_has_ipv6(pkt)); - CU_ASSERT(odp_packet_has_tcp(pkt)); - - CU_ASSERT(!odp_packet_has_ipv4(pkt)); - CU_ASSERT(!odp_packet_has_udp(pkt)); - - odp_packet_free(pkt); -} - -void parser_test_ipv6_udp(void) -{ - odp_packet_t pkt; - - pkt = loopback_packet(pktio_a, pktio_b, test_packet_ipv6_udp, - sizeof(test_packet_ipv6_udp)); - CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); - CU_ASSERT(odp_packet_has_eth(pkt)); - CU_ASSERT(odp_packet_has_ipv6(pkt)); - CU_ASSERT(odp_packet_has_udp(pkt)); - - CU_ASSERT(!odp_packet_has_ipv4(pkt)); - CU_ASSERT(!odp_packet_has_tcp(pkt)); - - odp_packet_free(pkt); -} - -void parser_test_vlan_ipv6_udp(void) -{ - odp_packet_t pkt; - - pkt = loopback_packet(pktio_a, pktio_b, test_packet_vlan_ipv6_udp, - sizeof(test_packet_vlan_ipv6_udp)); - CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); - CU_ASSERT(odp_packet_has_eth(pkt)); - CU_ASSERT(odp_packet_has_vlan(pkt)); - CU_ASSERT(odp_packet_has_ipv6(pkt)); - CU_ASSERT(odp_packet_has_udp(pkt)); - - CU_ASSERT(!odp_packet_has_ipv4(pkt)); - CU_ASSERT(!odp_packet_has_tcp(pkt)); - - odp_packet_free(pkt); -} - -int parser_suite_init(void) -{ - int i; - - if (getenv("ODP_WAIT_FOR_NETWORK")) - wait_for_network = true; - - iface_name[0] = getenv("ODP_PKTIO_IF0"); - iface_name[1] = getenv("ODP_PKTIO_IF1"); - num_ifaces = 1; - - if (!iface_name[0]) { - printf("No interfaces specified, using default "loop".\n"); - iface_name[0] = "loop"; - } else if (!iface_name[1]) { - printf("Using loopback interface: %s\n", iface_name[0]); - } else { - num_ifaces = 2; - printf("Using paired interfaces: %s %s\n", - iface_name[0], iface_name[1]); - } - - if (pkt_pool_create() != 0) { - printf("Error: failed to create parser pool\n"); - return -1; - } - - /* Create pktios and associate input/output queues */ - for (i = 0; i < num_ifaces; ++i) { - pktio_info_t *io; - - io = &pktios[i]; - io->name = iface_name[i]; - io->hdl = create_pktio(i, parser_pool); - if (io->hdl == ODP_PKTIO_INVALID) { - printf("Error: failed to open iface"); - return -1; - } - - if (odp_pktout_queue(io->hdl, &io->pktout, 1) != 1) { - printf("Error: failed to start iface: %s\n", io->name); - return -1; - } - - if (odp_pktin_queue(io->hdl, &io->pktin, 1) != 1) { - printf("Error: failed to start iface: %s\n", io->name); - return -1; - } - - if (odp_pktio_start(io->hdl)) { - printf("Error: failed to start iface: %s\n", io->name); - return -1; - } - - wait_linkup(io->hdl); - } - - pktio_a = &pktios[0]; - pktio_b = &pktios[1]; - if (num_ifaces == 1) - pktio_b = pktio_a; - - return 0; -} - -int parser_suite_term(void) -{ - int i; - int ret = 0; - - for (i = 0; i < num_ifaces; ++i) { - if (odp_pktio_stop(pktios[i].hdl)) { - printf("Error: failed to stop pktio: %s\n", - pktios[i].name); - ret = -1; - } - if (odp_pktio_close(pktios[i].hdl)) { - printf("Error: failed to close pktio: %s\n", - pktios[i].name); - ret = -1; - } - } - - if (odp_pool_destroy(parser_pool) != 0) { - printf("Error: failed to destroy packet pool\n"); - ret = -1; - } - - return ret; -} - -/** - * Certain tests can only be run with 'loop' pktio. - */ -static int loop_pktio(void) -{ - if (strcmp(iface_name[0], "loop") == 0) - return ODP_TEST_ACTIVE; - else - return ODP_TEST_INACTIVE; -} - -odp_testinfo_t parser_suite[] = { - ODP_TEST_INFO(parser_test_arp), - ODP_TEST_INFO(parser_test_ipv4_icmp), - ODP_TEST_INFO(parser_test_ipv4_tcp), - ODP_TEST_INFO(parser_test_ipv4_udp), - ODP_TEST_INFO_CONDITIONAL(parser_test_vlan_ipv4_udp, loop_pktio), - ODP_TEST_INFO_CONDITIONAL(parser_test_vlan_qinq_ipv4_udp, loop_pktio), - ODP_TEST_INFO(parser_test_ipv6_icmp), - ODP_TEST_INFO(parser_test_ipv6_tcp), - ODP_TEST_INFO(parser_test_ipv6_udp), - ODP_TEST_INFO_CONDITIONAL(parser_test_vlan_ipv6_udp, loop_pktio), - ODP_TEST_INFO_NULL -}; diff --git a/test/common_plat/validation/api/pktio/parser.h b/test/common_plat/validation/api/pktio/parser.h deleted file mode 100644 index 57c62388..00000000 --- a/test/common_plat/validation/api/pktio/parser.h +++ /dev/null @@ -1,180 +0,0 @@ -/* Copyright (c) 2017, Linaro Limited - * All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#ifndef _ODP_TEST_PARSER_H_ -#define _ODP_TEST_PARSER_H_ - -#include <odp_cunit_common.h> - -/* test functions: */ -void parser_test_arp(void); -void parser_test_ipv4_icmp(void); -void parser_test_ipv4_tcp(void); -void parser_test_ipv4_udp(void); -void parser_test_vlan_ipv4_udp(void); -void parser_test_vlan_qinq_ipv4_udp(void); -void parser_test_ipv6_icmp(void); -void parser_test_ipv6_tcp(void); -void parser_test_ipv6_udp(void); -void parser_test_vlan_ipv6_udp(void); - -/* test array init/term functions: */ -int parser_suite_term(void); -int parser_suite_init(void); - -/* test arrays: */ -extern odp_testinfo_t parser_suite[]; - -/** - * ARP request - */ -static const uint8_t test_packet_arp[] = { - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, - 0x09, 0x00, 0x04, 0x00, 0x08, 0x06, 0x00, 0x01, - 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0x00, 0x00, - 0x09, 0x00, 0x04, 0x00, 0xC0, 0xA8, 0x01, 0x01, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xA8, - 0x01, 0x02, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, - 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, - 0x0E, 0x0F, 0x10, 0x11, 0xA1, 0xA8, 0x27, 0x43, -}; - -/** - * ICMPv4 echo reply - */ -static const uint8_t test_packet_ipv4_icmp[] = { - 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x04, 0x00, 0x08, 0x00, 0x45, 0x00, - 0x00, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x40, 0x01, - 0xF3, 0x7B, 0xC0, 0xA8, 0x01, 0x01, 0xC4, 0xA8, - 0x01, 0x02, 0x00, 0x00, 0xB7, 0xAB, 0x00, 0x01, - 0x00, 0x02, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, - 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, - 0x0E, 0x0F, 0x10, 0x11, 0xD9, 0x7F, 0xE8, 0x02, -}; - -/** - * IPv4 TCP - */ -static const uint8_t test_packet_ipv4_tcp[] = { - 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x04, 0x00, 0x08, 0x00, 0x45, 0x00, - 0x00, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x40, 0x06, - 0xF3, 0x76, 0xC0, 0xA8, 0x01, 0x02, 0xC4, 0xA8, - 0x01, 0x01, 0x04, 0xD2, 0x10, 0xE1, 0x00, 0x00, - 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x50, 0x00, - 0x00, 0x00, 0x0C, 0xCC, 0x00, 0x00, 0x00, 0x01, - 0x02, 0x03, 0x04, 0x05, 0x2E, 0xDE, 0x5E, 0x48, -}; - -/** - * IPv4 UDP - */ -static const uint8_t test_packet_ipv4_udp[] = { - 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x04, 0x00, 0x08, 0x00, 0x45, 0x00, - 0x00, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x40, 0x11, - 0xF3, 0x6B, 0xC0, 0xA8, 0x01, 0x02, 0xC4, 0xA8, - 0x01, 0x01, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x1A, - 0x2F, 0x97, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, - 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, - 0x0E, 0x0F, 0x10, 0x11, 0x64, 0xF4, 0xE4, 0xB6, -}; - -/** - * VLAN IPv4 UDP - * - ID: 23 - */ -static const uint8_t test_packet_vlan_ipv4_udp[] = { - 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x04, 0x00, 0x81, 0x00, 0x00, 0x17, - 0x08, 0x00, 0x45, 0x00, 0x00, 0x2A, 0x00, 0x00, - 0x00, 0x00, 0x40, 0x11, 0xF3, 0x6F, 0xC0, 0xA8, - 0x01, 0x02, 0xC4, 0xA8, 0x01, 0x01, 0x00, 0x3F, - 0x00, 0x3F, 0x00, 0x16, 0x4D, 0xBF, 0x00, 0x01, - 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, - 0x0A, 0x0B, 0x0C, 0x0D, 0xCB, 0xBF, 0xD0, 0x29, -}; - -/** - * VLAN Q-in-Q IPv4 UDP - * - Outer: Tag Protocol ID 0x88a8, VLAN ID 1 - * - Inner: Tag Protocol ID 0x8100, VLAN ID 2 - */ -static const uint8_t test_packet_vlan_qinq_ipv4_udp[] = { - 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x04, 0x00, 0x88, 0xA8, 0x00, 0x01, - 0x81, 0x00, 0x00, 0x02, 0x08, 0x00, 0x45, 0x00, - 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x40, 0x11, - 0xF3, 0x73, 0xC0, 0xA8, 0x01, 0x02, 0xC4, 0xA8, - 0x01, 0x01, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x12, - 0x63, 0xDF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, - 0x06, 0x07, 0x08, 0x09, 0x80, 0x98, 0xB8, 0x18, -}; - -/** - * ICMPv6 echo request - */ -static const uint8_t test_packet_ipv6_icmp[] = { - 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x04, 0x00, 0x86, 0xDD, 0x60, 0x30, - 0x00, 0x00, 0x00, 0x08, 0x3A, 0xFF, 0xFE, 0x80, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, - 0x09, 0xFF, 0xFE, 0x00, 0x04, 0x00, 0x35, 0x55, - 0x55, 0x55, 0x66, 0x66, 0x66, 0x66, 0x77, 0x77, - 0x77, 0x77, 0x88, 0x88, 0x88, 0x88, 0x80, 0x00, - 0x1B, 0xC2, 0x00, 0x01, 0x00, 0x02, 0xE0, 0x68, - 0x0E, 0xBA, -}; - -/** - * IPv6 TCP - */ -static const uint8_t test_packet_ipv6_tcp[] = { - 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x04, 0x00, 0x86, 0xDD, 0x60, 0x30, - 0x00, 0x00, 0x00, 0x14, 0x06, 0xFF, 0xFE, 0x80, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, - 0x09, 0xFF, 0xFE, 0x00, 0x04, 0x00, 0x35, 0x55, - 0x55, 0x55, 0x66, 0x66, 0x66, 0x66, 0x77, 0x77, - 0x77, 0x77, 0x88, 0x88, 0x88, 0x88, 0x04, 0xD2, - 0x10, 0xE1, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, - 0x00, 0x02, 0x50, 0x00, 0x00, 0x00, 0x36, 0x37, - 0x00, 0x00, 0x28, 0x67, 0xD2, 0xAF, -}; - -/** - * IPv6 UDP - */ -static const uint8_t test_packet_ipv6_udp[] = { - 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x04, 0x00, 0x86, 0xDD, 0x60, 0x30, - 0x00, 0x00, 0x00, 0x08, 0x11, 0xFF, 0xFE, 0x80, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, - 0x09, 0xFF, 0xFE, 0x00, 0x04, 0x00, 0x35, 0x55, - 0x55, 0x55, 0x66, 0x66, 0x66, 0x66, 0x77, 0x77, - 0x77, 0x77, 0x88, 0x88, 0x88, 0x88, 0x00, 0x3F, - 0x00, 0x3F, 0x00, 0x08, 0x9B, 0x68, 0x35, 0xD3, - 0x64, 0x49, -}; - -/** - * VLAN IPv6 - * - ID: 23 - */ -static const uint8_t test_packet_vlan_ipv6_udp[] = { - 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, - 0x09, 0x00, 0x04, 0x00, 0x81, 0x00, 0x00, 0x17, - 0x86, 0xDD, 0x60, 0x30, 0x00, 0x00, 0x00, 0x08, - 0x11, 0xFF, 0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x02, 0x00, 0x09, 0xFF, 0xFE, 0x00, - 0x04, 0x00, 0x35, 0x55, 0x55, 0x55, 0x66, 0x66, - 0x66, 0x66, 0x77, 0x77, 0x77, 0x77, 0x88, 0x88, - 0x88, 0x88, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x08, - 0x9B, 0x68, 0xC5, 0xD8, 0x2F, 0x5C, -}; - -#endif diff --git a/test/common_plat/validation/api/pktio/pktio.c b/test/common_plat/validation/api/pktio/pktio.c index 43fe515a..a21959ef 100644 --- a/test/common_plat/validation/api/pktio/pktio.c +++ b/test/common_plat/validation/api/pktio/pktio.c @@ -10,7 +10,6 @@
#include <stdlib.h> #include "pktio.h" -#include "parser.h"
#define PKT_BUF_NUM 32 #define PKT_BUF_SIZE (9 * 1024) @@ -144,7 +143,8 @@ static void set_pool_len(odp_pool_param_t *params, odp_pool_capability_t *capa) } }
-void pktio_pkt_set_macs(odp_packet_t pkt, odp_pktio_t src, odp_pktio_t dst) +static void pktio_pkt_set_macs(odp_packet_t pkt, + odp_pktio_t src, odp_pktio_t dst) { uint32_t len; odph_ethhdr_t *eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, &len); @@ -2190,7 +2190,6 @@ odp_suiteinfo_t pktio_suites[] = { pktio_suite_term, pktio_suite_unsegmented}, {"Packet I/O Segmented", pktio_suite_init_segmented, pktio_suite_term, pktio_suite_segmented}, - {"Packet parser", parser_suite_init, parser_suite_term, parser_suite}, ODP_SUITE_INFO_NULL };
diff --git a/test/common_plat/validation/api/pktio/pktio.h b/test/common_plat/validation/api/pktio/pktio.h index b8799d9e..8131d05f 100644 --- a/test/common_plat/validation/api/pktio/pktio.h +++ b/test/common_plat/validation/api/pktio/pktio.h @@ -61,7 +61,4 @@ extern odp_suiteinfo_t pktio_suites[]; /* main test program: */ int pktio_main(int argc, char *argv[]);
-/* functions shared by parser test suite */ -void pktio_pkt_set_macs(odp_packet_t pkt, odp_pktio_t src, odp_pktio_t dst); - #endif
commit d4983d155f3172344dd55196b3918fc14b1c5d8b Author: Janne Peltonen janne.peltonen@nokia.com Date: Fri Apr 7 12:54:00 2017 +0300
abi: event: add ODP_EVENT_IPSEC_STATUS
Update ABI spec with the new IPsec event type.
Signed-off-by: Janne Peltonen janne.peltonen@nokia.com Reviewed-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/include/odp/arch/default/api/abi/event.h b/include/odp/arch/default/api/abi/event.h index ab141572..87220d63 100644 --- a/include/odp/arch/default/api/abi/event.h +++ b/include/odp/arch/default/api/abi/event.h @@ -29,7 +29,8 @@ typedef enum odp_event_type_t { ODP_EVENT_PACKET = 2, ODP_EVENT_TIMEOUT = 3, ODP_EVENT_CRYPTO_COMPL = 4, - ODP_EVENT_IPSEC_RESULT = 5 + ODP_EVENT_IPSEC_RESULT = 5, + ODP_EVENT_IPSEC_STATUS = 6 } odp_event_type_t;
/**
commit b40c6127cb52c6d33719f9ff923b6b8ee7f38f21 Author: Matias Elo matias.elo@nokia.com Date: Tue Apr 4 09:28:21 2017 +0300
validation: pktio: add tests for packet parsing
Test packet parsing using predefined test packets (byte arrays). Test packets are looped through tested pktio interfaces to force packet parsing.
Signed-off-by: Matias Elo matias.elo@nokia.com Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/test/common_plat/validation/api/pktio/Makefile.am b/test/common_plat/validation/api/pktio/Makefile.am index 466d690d..c6368fba 100644 --- a/test/common_plat/validation/api/pktio/Makefile.am +++ b/test/common_plat/validation/api/pktio/Makefile.am @@ -4,7 +4,7 @@ noinst_LTLIBRARIES = libtestpktio.la libtestpktio_la_SOURCES = pktio.c
test_PROGRAMS = pktio_main$(EXEEXT) -dist_pktio_main_SOURCES = pktio_main.c +dist_pktio_main_SOURCES = pktio_main.c parser.c pktio_main_LDADD = libtestpktio.la $(LIBCUNIT_COMMON) $(LIBODP)
-EXTRA_DIST = pktio.h +EXTRA_DIST = pktio.h parser.h diff --git a/test/common_plat/validation/api/pktio/parser.c b/test/common_plat/validation/api/pktio/parser.c new file mode 100644 index 00000000..ad7101d0 --- /dev/null +++ b/test/common_plat/validation/api/pktio/parser.c @@ -0,0 +1,545 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +#include <odp_api.h> +#include <odp_cunit_common.h> + +#include <odp/helper/odph_api.h> + +#include <stdlib.h> +#include "parser.h" +#include "pktio.h" + +#define MAX_NUM_IFACES 2 +#define PKT_POOL_NUM 256 +#define PKT_POOL_BUF_LEN (2 * 1024) + +/** + * local container for pktio attributes + */ +typedef struct { + const char *name; + odp_pktio_t hdl; + odp_pktout_queue_t pktout; + odp_pktin_queue_t pktin; +} pktio_info_t; + +/** Interface names used for testing */ +static const char *iface_name[MAX_NUM_IFACES]; + +/** Test interfaces */ +pktio_info_t pktios[MAX_NUM_IFACES]; +pktio_info_t *pktio_a; +pktio_info_t *pktio_b; + +/** Number of interfaces being used (1=loopback, 2=pair) */ +static int num_ifaces; + +/** While testing real-world interfaces additional time may be needed for + * external network to enable link to pktio interface that just become up. + */ +static bool wait_for_network; + +/** Parser packet pool */ +odp_pool_t parser_pool = ODP_POOL_INVALID; + +static inline void wait_linkup(odp_pktio_t pktio) +{ + /* wait 1 second for link up */ + uint64_t wait_ns = (10 * ODP_TIME_MSEC_IN_NS); + int wait_num = 100; + int i; + int ret = -1; + + for (i = 0; i < wait_num; i++) { + ret = odp_pktio_link_status(pktio); + if (ret < 0 || ret == 1) + break; + /* link is down, call status again after delay */ + odp_time_wait_ns(wait_ns); + } +} + +static int pkt_pool_create(void) +{ + odp_pool_capability_t capa; + odp_pool_param_t params; + + if (odp_pool_capability(&capa) != 0) { + printf("Error: unable to query pool capability.\n"); + return -1; + } + + if (capa.pkt.max_num && capa.pkt.max_num < PKT_POOL_NUM) { + printf("Error: packet pool size not supported.\n"); + printf("MAX: %" PRIu32 "\n", capa.pkt.max_num); + return -1; + } else if (capa.pkt.max_len && capa.pkt.max_len < PKT_POOL_BUF_LEN) { + printf("Error: packet length not supported.\n"); + return -1; + } else if (capa.pkt.max_seg_len && + capa.pkt.max_seg_len < PKT_POOL_BUF_LEN) { + printf("Error: segment length not supported.\n"); + return -1; + } + + odp_pool_param_init(¶ms); + params.pkt.seg_len = PKT_POOL_BUF_LEN; + params.pkt.len = PKT_POOL_BUF_LEN; + params.pkt.num = PKT_POOL_NUM; + params.type = ODP_POOL_PACKET; + + parser_pool = odp_pool_create("pkt_pool_default", ¶ms); + if (parser_pool == ODP_POOL_INVALID) { + printf("Error: packet pool create failed.\n"); + return -1; + } + + return 0; +} + +static odp_pktio_t create_pktio(int iface_idx, odp_pool_t pool) +{ + odp_pktio_t pktio; + odp_pktio_config_t config; + odp_pktio_param_t pktio_param; + const char *iface = iface_name[iface_idx]; + + odp_pktio_param_init(&pktio_param); + pktio_param.in_mode = ODP_PKTIN_MODE_DIRECT; + pktio_param.out_mode = ODP_PKTOUT_MODE_DIRECT; + + pktio = odp_pktio_open(iface, pool, &pktio_param); + if (pktio == ODP_PKTIO_INVALID) { + printf("Error: failed to open %s\n", iface); + return ODP_PKTIO_INVALID; + } + + odp_pktio_config_init(&config); + config.parser.layer = ODP_PKTIO_PARSER_LAYER_ALL; + if (odp_pktio_config(pktio, &config)) { + printf("Error: failed to configure %s\n", iface); + return ODP_PKTIO_INVALID; + } + + /* By default, single input and output queue is used */ + if (odp_pktin_queue_config(pktio, NULL)) { + printf("Error: failed to config input queue for %s\n", iface); + return ODP_PKTIO_INVALID; + } + if (odp_pktout_queue_config(pktio, NULL)) { + printf("Error: failed to config output queue for %s\n", iface); + return ODP_PKTIO_INVALID; + } + + if (wait_for_network) + odp_time_wait_ns(ODP_TIME_SEC_IN_NS / 4); + + return pktio; +} + +static odp_packet_t create_packet(const uint8_t *data, uint32_t len) +{ + odp_packet_t pkt; + + pkt = odp_packet_alloc(parser_pool, len); + if (pkt == ODP_PACKET_INVALID) + return ODP_PACKET_INVALID; + + if (odp_packet_copy_from_mem(pkt, 0, len, data)) { + printf("Error: failed to copy test packet data\n"); + odp_packet_free(pkt); + return ODP_PACKET_INVALID; + } + + odp_packet_l2_offset_set(pkt, 0); + + return pkt; +} + +/** + * Receive incoming packets and compare them to the original. Function returns + * a valid packet handle only when the received packet matches to the original + * packet. + */ +static odp_packet_t recv_and_cmp_packet(odp_pktin_queue_t pktin, + odp_packet_t orig_pkt, uint64_t ns) +{ + odp_packet_t pkt = ODP_PACKET_INVALID; + odp_time_t wait_time, end; + uint32_t orig_len; + uint8_t *orig_data; + + orig_len = odp_packet_len(orig_pkt); + orig_data = odp_packet_data(orig_pkt); + wait_time = odp_time_local_from_ns(ns); + end = odp_time_sum(odp_time_local(), wait_time); + + do { + int ret; + odp_packet_t tmp_pkt; + + ret = odp_pktin_recv(pktin, &tmp_pkt, 1); + if (ret < 0) + break; + + if (ret == 1) { + uint32_t len; + uint8_t *data; + + len = odp_packet_len(tmp_pkt); + data = odp_packet_data(tmp_pkt); + + if (len == orig_len && + memcmp(data, orig_data, len) == 0) { + pkt = tmp_pkt; + break; + } + odp_packet_free(tmp_pkt); + } + } while (odp_time_cmp(end, odp_time_local()) > 0); + + return pkt; +} + +/** + * Creates a test packet from data array and loops it through the test pktio + * interfaces forcing packet parsing. + */ +static odp_packet_t loopback_packet(pktio_info_t *pktio_a, + pktio_info_t *pktio_b, const uint8_t *data, + uint32_t len) +{ + odp_packet_t pkt; + odp_packet_t sent_pkt; + + pkt = create_packet(data, len); + if (pkt == ODP_PACKET_INVALID) { + CU_FAIL("failed to generate test packet"); + return ODP_PACKET_INVALID; + } + + pktio_pkt_set_macs(pkt, pktio_a->hdl, pktio_b->hdl); + + sent_pkt = odp_packet_copy(pkt, parser_pool); + if (sent_pkt == ODP_PACKET_INVALID) { + CU_FAIL_FATAL("failed to copy test packet"); + odp_packet_free(pkt); + return ODP_PACKET_INVALID; + } + + while (1) { + int ret = odp_pktout_send(pktio_a->pktout, &pkt, 1); + + if (ret < 0) { + CU_FAIL_FATAL("failed to send test packet"); + odp_packet_free(pkt); + odp_packet_free(sent_pkt); + return ODP_PACKET_INVALID; + } + if (ret == 1) + break; + } + + /* and wait for them to arrive back */ + pkt = recv_and_cmp_packet(pktio_b->pktin, sent_pkt, ODP_TIME_SEC_IN_NS); + odp_packet_free(sent_pkt); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_input(pkt) == pktio_b->hdl); + CU_ASSERT(odp_packet_has_error(pkt) == 0); + + return pkt; +} + +void parser_test_arp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_arp, + sizeof(test_packet_arp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_arp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv4(pkt)); + CU_ASSERT(!odp_packet_has_ipv6(pkt)); + + odp_packet_free(pkt); +} + +void parser_test_ipv4_icmp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_ipv4_icmp, + sizeof(test_packet_ipv4_icmp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_ipv4(pkt)); + CU_ASSERT(odp_packet_has_icmp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv6(pkt)); + CU_ASSERT(!odp_packet_has_tcp(pkt)); + CU_ASSERT(!odp_packet_has_udp(pkt)); + + odp_packet_free(pkt); +} + +void parser_test_ipv4_tcp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_ipv4_tcp, + sizeof(test_packet_ipv4_tcp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_ipv4(pkt)); + CU_ASSERT(odp_packet_has_tcp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv6(pkt)); + CU_ASSERT(!odp_packet_has_udp(pkt)); + + odp_packet_free(pkt); +} + +void parser_test_ipv4_udp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_ipv4_udp, + sizeof(test_packet_ipv4_udp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_ipv4(pkt)); + CU_ASSERT(odp_packet_has_udp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv6(pkt)); + CU_ASSERT(!odp_packet_has_tcp(pkt)); + + odp_packet_free(pkt); +} + +void parser_test_vlan_ipv4_udp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_vlan_ipv4_udp, + sizeof(test_packet_vlan_ipv4_udp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_vlan(pkt)); + CU_ASSERT(odp_packet_has_ipv4(pkt)); + CU_ASSERT(odp_packet_has_udp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv6(pkt)); + CU_ASSERT(!odp_packet_has_tcp(pkt)); + + odp_packet_free(pkt); +} + +void parser_test_vlan_qinq_ipv4_udp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_vlan_qinq_ipv4_udp, + sizeof(test_packet_vlan_qinq_ipv4_udp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_vlan(pkt)); + CU_ASSERT(odp_packet_has_vlan_qinq(pkt)); + CU_ASSERT(odp_packet_has_ipv4(pkt)); + CU_ASSERT(odp_packet_has_udp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv6(pkt)); + CU_ASSERT(!odp_packet_has_tcp(pkt)); + + odp_packet_free(pkt); +} + +void parser_test_ipv6_icmp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_ipv6_icmp, + sizeof(test_packet_ipv6_icmp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_ipv6(pkt)); + CU_ASSERT(odp_packet_has_icmp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv4(pkt)); + CU_ASSERT(!odp_packet_has_tcp(pkt)); + CU_ASSERT(!odp_packet_has_udp(pkt)); + + odp_packet_free(pkt); +} + +void parser_test_ipv6_tcp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_ipv6_tcp, + sizeof(test_packet_ipv6_tcp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_ipv6(pkt)); + CU_ASSERT(odp_packet_has_tcp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv4(pkt)); + CU_ASSERT(!odp_packet_has_udp(pkt)); + + odp_packet_free(pkt); +} + +void parser_test_ipv6_udp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_ipv6_udp, + sizeof(test_packet_ipv6_udp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_ipv6(pkt)); + CU_ASSERT(odp_packet_has_udp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv4(pkt)); + CU_ASSERT(!odp_packet_has_tcp(pkt)); + + odp_packet_free(pkt); +} + +void parser_test_vlan_ipv6_udp(void) +{ + odp_packet_t pkt; + + pkt = loopback_packet(pktio_a, pktio_b, test_packet_vlan_ipv6_udp, + sizeof(test_packet_vlan_ipv6_udp)); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_has_eth(pkt)); + CU_ASSERT(odp_packet_has_vlan(pkt)); + CU_ASSERT(odp_packet_has_ipv6(pkt)); + CU_ASSERT(odp_packet_has_udp(pkt)); + + CU_ASSERT(!odp_packet_has_ipv4(pkt)); + CU_ASSERT(!odp_packet_has_tcp(pkt)); + + odp_packet_free(pkt); +} + +int parser_suite_init(void) +{ + int i; + + if (getenv("ODP_WAIT_FOR_NETWORK")) + wait_for_network = true; + + iface_name[0] = getenv("ODP_PKTIO_IF0"); + iface_name[1] = getenv("ODP_PKTIO_IF1"); + num_ifaces = 1; + + if (!iface_name[0]) { + printf("No interfaces specified, using default "loop".\n"); + iface_name[0] = "loop"; + } else if (!iface_name[1]) { + printf("Using loopback interface: %s\n", iface_name[0]); + } else { + num_ifaces = 2; + printf("Using paired interfaces: %s %s\n", + iface_name[0], iface_name[1]); + } + + if (pkt_pool_create() != 0) { + printf("Error: failed to create parser pool\n"); + return -1; + } + + /* Create pktios and associate input/output queues */ + for (i = 0; i < num_ifaces; ++i) { + pktio_info_t *io; + + io = &pktios[i]; + io->name = iface_name[i]; + io->hdl = create_pktio(i, parser_pool); + if (io->hdl == ODP_PKTIO_INVALID) { + printf("Error: failed to open iface"); + return -1; + } + + if (odp_pktout_queue(io->hdl, &io->pktout, 1) != 1) { + printf("Error: failed to start iface: %s\n", io->name); + return -1; + } + + if (odp_pktin_queue(io->hdl, &io->pktin, 1) != 1) { + printf("Error: failed to start iface: %s\n", io->name); + return -1; + } + + if (odp_pktio_start(io->hdl)) { + printf("Error: failed to start iface: %s\n", io->name); + return -1; + } + + wait_linkup(io->hdl); + } + + pktio_a = &pktios[0]; + pktio_b = &pktios[1]; + if (num_ifaces == 1) + pktio_b = pktio_a; + + return 0; +} + +int parser_suite_term(void) +{ + int i; + int ret = 0; + + for (i = 0; i < num_ifaces; ++i) { + if (odp_pktio_stop(pktios[i].hdl)) { + printf("Error: failed to stop pktio: %s\n", + pktios[i].name); + ret = -1; + } + if (odp_pktio_close(pktios[i].hdl)) { + printf("Error: failed to close pktio: %s\n", + pktios[i].name); + ret = -1; + } + } + + if (odp_pool_destroy(parser_pool) != 0) { + printf("Error: failed to destroy packet pool\n"); + ret = -1; + } + + return ret; +} + +/** + * Certain tests can only be run with 'loop' pktio. + */ +static int loop_pktio(void) +{ + if (strcmp(iface_name[0], "loop") == 0) + return ODP_TEST_ACTIVE; + else + return ODP_TEST_INACTIVE; +} + +odp_testinfo_t parser_suite[] = { + ODP_TEST_INFO(parser_test_arp), + ODP_TEST_INFO(parser_test_ipv4_icmp), + ODP_TEST_INFO(parser_test_ipv4_tcp), + ODP_TEST_INFO(parser_test_ipv4_udp), + ODP_TEST_INFO_CONDITIONAL(parser_test_vlan_ipv4_udp, loop_pktio), + ODP_TEST_INFO_CONDITIONAL(parser_test_vlan_qinq_ipv4_udp, loop_pktio), + ODP_TEST_INFO(parser_test_ipv6_icmp), + ODP_TEST_INFO(parser_test_ipv6_tcp), + ODP_TEST_INFO(parser_test_ipv6_udp), + ODP_TEST_INFO_CONDITIONAL(parser_test_vlan_ipv6_udp, loop_pktio), + ODP_TEST_INFO_NULL +}; diff --git a/test/common_plat/validation/api/pktio/parser.h b/test/common_plat/validation/api/pktio/parser.h new file mode 100644 index 00000000..57c62388 --- /dev/null +++ b/test/common_plat/validation/api/pktio/parser.h @@ -0,0 +1,180 @@ +/* Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_TEST_PARSER_H_ +#define _ODP_TEST_PARSER_H_ + +#include <odp_cunit_common.h> + +/* test functions: */ +void parser_test_arp(void); +void parser_test_ipv4_icmp(void); +void parser_test_ipv4_tcp(void); +void parser_test_ipv4_udp(void); +void parser_test_vlan_ipv4_udp(void); +void parser_test_vlan_qinq_ipv4_udp(void); +void parser_test_ipv6_icmp(void); +void parser_test_ipv6_tcp(void); +void parser_test_ipv6_udp(void); +void parser_test_vlan_ipv6_udp(void); + +/* test array init/term functions: */ +int parser_suite_term(void); +int parser_suite_init(void); + +/* test arrays: */ +extern odp_testinfo_t parser_suite[]; + +/** + * ARP request + */ +static const uint8_t test_packet_arp[] = { + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x08, 0x06, 0x00, 0x01, + 0x08, 0x00, 0x06, 0x04, 0x00, 0x01, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0xC0, 0xA8, 0x01, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xA8, + 0x01, 0x02, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, + 0x0E, 0x0F, 0x10, 0x11, 0xA1, 0xA8, 0x27, 0x43, +}; + +/** + * ICMPv4 echo reply + */ +static const uint8_t test_packet_ipv4_icmp[] = { + 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x08, 0x00, 0x45, 0x00, + 0x00, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x40, 0x01, + 0xF3, 0x7B, 0xC0, 0xA8, 0x01, 0x01, 0xC4, 0xA8, + 0x01, 0x02, 0x00, 0x00, 0xB7, 0xAB, 0x00, 0x01, + 0x00, 0x02, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, + 0x0E, 0x0F, 0x10, 0x11, 0xD9, 0x7F, 0xE8, 0x02, +}; + +/** + * IPv4 TCP + */ +static const uint8_t test_packet_ipv4_tcp[] = { + 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x08, 0x00, 0x45, 0x00, + 0x00, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x40, 0x06, + 0xF3, 0x76, 0xC0, 0xA8, 0x01, 0x02, 0xC4, 0xA8, + 0x01, 0x01, 0x04, 0xD2, 0x10, 0xE1, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x50, 0x00, + 0x00, 0x00, 0x0C, 0xCC, 0x00, 0x00, 0x00, 0x01, + 0x02, 0x03, 0x04, 0x05, 0x2E, 0xDE, 0x5E, 0x48, +}; + +/** + * IPv4 UDP + */ +static const uint8_t test_packet_ipv4_udp[] = { + 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x08, 0x00, 0x45, 0x00, + 0x00, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x40, 0x11, + 0xF3, 0x6B, 0xC0, 0xA8, 0x01, 0x02, 0xC4, 0xA8, + 0x01, 0x01, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x1A, + 0x2F, 0x97, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, + 0x0E, 0x0F, 0x10, 0x11, 0x64, 0xF4, 0xE4, 0xB6, +}; + +/** + * VLAN IPv4 UDP + * - ID: 23 + */ +static const uint8_t test_packet_vlan_ipv4_udp[] = { + 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x81, 0x00, 0x00, 0x17, + 0x08, 0x00, 0x45, 0x00, 0x00, 0x2A, 0x00, 0x00, + 0x00, 0x00, 0x40, 0x11, 0xF3, 0x6F, 0xC0, 0xA8, + 0x01, 0x02, 0xC4, 0xA8, 0x01, 0x01, 0x00, 0x3F, + 0x00, 0x3F, 0x00, 0x16, 0x4D, 0xBF, 0x00, 0x01, + 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + 0x0A, 0x0B, 0x0C, 0x0D, 0xCB, 0xBF, 0xD0, 0x29, +}; + +/** + * VLAN Q-in-Q IPv4 UDP + * - Outer: Tag Protocol ID 0x88a8, VLAN ID 1 + * - Inner: Tag Protocol ID 0x8100, VLAN ID 2 + */ +static const uint8_t test_packet_vlan_qinq_ipv4_udp[] = { + 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x88, 0xA8, 0x00, 0x01, + 0x81, 0x00, 0x00, 0x02, 0x08, 0x00, 0x45, 0x00, + 0x00, 0x26, 0x00, 0x00, 0x00, 0x00, 0x40, 0x11, + 0xF3, 0x73, 0xC0, 0xA8, 0x01, 0x02, 0xC4, 0xA8, + 0x01, 0x01, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x12, + 0x63, 0xDF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, + 0x06, 0x07, 0x08, 0x09, 0x80, 0x98, 0xB8, 0x18, +}; + +/** + * ICMPv6 echo request + */ +static const uint8_t test_packet_ipv6_icmp[] = { + 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x86, 0xDD, 0x60, 0x30, + 0x00, 0x00, 0x00, 0x08, 0x3A, 0xFF, 0xFE, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x09, 0xFF, 0xFE, 0x00, 0x04, 0x00, 0x35, 0x55, + 0x55, 0x55, 0x66, 0x66, 0x66, 0x66, 0x77, 0x77, + 0x77, 0x77, 0x88, 0x88, 0x88, 0x88, 0x80, 0x00, + 0x1B, 0xC2, 0x00, 0x01, 0x00, 0x02, 0xE0, 0x68, + 0x0E, 0xBA, +}; + +/** + * IPv6 TCP + */ +static const uint8_t test_packet_ipv6_tcp[] = { + 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x86, 0xDD, 0x60, 0x30, + 0x00, 0x00, 0x00, 0x14, 0x06, 0xFF, 0xFE, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x09, 0xFF, 0xFE, 0x00, 0x04, 0x00, 0x35, 0x55, + 0x55, 0x55, 0x66, 0x66, 0x66, 0x66, 0x77, 0x77, + 0x77, 0x77, 0x88, 0x88, 0x88, 0x88, 0x04, 0xD2, + 0x10, 0xE1, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, + 0x00, 0x02, 0x50, 0x00, 0x00, 0x00, 0x36, 0x37, + 0x00, 0x00, 0x28, 0x67, 0xD2, 0xAF, +}; + +/** + * IPv6 UDP + */ +static const uint8_t test_packet_ipv6_udp[] = { + 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x86, 0xDD, 0x60, 0x30, + 0x00, 0x00, 0x00, 0x08, 0x11, 0xFF, 0xFE, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, + 0x09, 0xFF, 0xFE, 0x00, 0x04, 0x00, 0x35, 0x55, + 0x55, 0x55, 0x66, 0x66, 0x66, 0x66, 0x77, 0x77, + 0x77, 0x77, 0x88, 0x88, 0x88, 0x88, 0x00, 0x3F, + 0x00, 0x3F, 0x00, 0x08, 0x9B, 0x68, 0x35, 0xD3, + 0x64, 0x49, +}; + +/** + * VLAN IPv6 + * - ID: 23 + */ +static const uint8_t test_packet_vlan_ipv6_udp[] = { + 0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00, + 0x09, 0x00, 0x04, 0x00, 0x81, 0x00, 0x00, 0x17, + 0x86, 0xDD, 0x60, 0x30, 0x00, 0x00, 0x00, 0x08, + 0x11, 0xFF, 0xFE, 0x80, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x02, 0x00, 0x09, 0xFF, 0xFE, 0x00, + 0x04, 0x00, 0x35, 0x55, 0x55, 0x55, 0x66, 0x66, + 0x66, 0x66, 0x77, 0x77, 0x77, 0x77, 0x88, 0x88, + 0x88, 0x88, 0x00, 0x3F, 0x00, 0x3F, 0x00, 0x08, + 0x9B, 0x68, 0xC5, 0xD8, 0x2F, 0x5C, +}; + +#endif diff --git a/test/common_plat/validation/api/pktio/pktio.c b/test/common_plat/validation/api/pktio/pktio.c index a21959ef..43fe515a 100644 --- a/test/common_plat/validation/api/pktio/pktio.c +++ b/test/common_plat/validation/api/pktio/pktio.c @@ -10,6 +10,7 @@
#include <stdlib.h> #include "pktio.h" +#include "parser.h"
#define PKT_BUF_NUM 32 #define PKT_BUF_SIZE (9 * 1024) @@ -143,8 +144,7 @@ static void set_pool_len(odp_pool_param_t *params, odp_pool_capability_t *capa) } }
-static void pktio_pkt_set_macs(odp_packet_t pkt, - odp_pktio_t src, odp_pktio_t dst) +void pktio_pkt_set_macs(odp_packet_t pkt, odp_pktio_t src, odp_pktio_t dst) { uint32_t len; odph_ethhdr_t *eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, &len); @@ -2190,6 +2190,7 @@ odp_suiteinfo_t pktio_suites[] = { pktio_suite_term, pktio_suite_unsegmented}, {"Packet I/O Segmented", pktio_suite_init_segmented, pktio_suite_term, pktio_suite_segmented}, + {"Packet parser", parser_suite_init, parser_suite_term, parser_suite}, ODP_SUITE_INFO_NULL };
diff --git a/test/common_plat/validation/api/pktio/pktio.h b/test/common_plat/validation/api/pktio/pktio.h index 8131d05f..b8799d9e 100644 --- a/test/common_plat/validation/api/pktio/pktio.h +++ b/test/common_plat/validation/api/pktio/pktio.h @@ -61,4 +61,7 @@ extern odp_suiteinfo_t pktio_suites[]; /* main test program: */ int pktio_main(int argc, char *argv[]);
+/* functions shared by parser test suite */ +void pktio_pkt_set_macs(odp_packet_t pkt, odp_pktio_t src, odp_pktio_t dst); + #endif
commit 41fd88bcac110322424f1418c751707f9b40409c Author: Matias Elo matias.elo@nokia.com Date: Tue Apr 4 09:28:20 2017 +0300
examples: use odp_pktio_config() to select required packet parsing level
Select required packet parsing level when full packet parsing is not required.
Signed-off-by: Matias Elo matias.elo@nokia.com Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/example/l2fwd_simple/odp_l2fwd_simple.c b/example/l2fwd_simple/odp_l2fwd_simple.c index b97808f4..e6381455 100644 --- a/example/l2fwd_simple/odp_l2fwd_simple.c +++ b/example/l2fwd_simple/odp_l2fwd_simple.c @@ -41,6 +41,7 @@ static odp_pktio_t create_pktio(const char *name, odp_pool_t pool, odp_pktin_queue_param_t in_queue_param; odp_pktout_queue_param_t out_queue_param; odp_pktio_t pktio; + odp_pktio_config_t config;
odp_pktio_param_init(&pktio_param);
@@ -50,6 +51,10 @@ static odp_pktio_t create_pktio(const char *name, odp_pool_t pool, exit(1); }
+ odp_pktio_config_init(&config); + config.parser.layer = ODP_PKTIO_PARSER_LAYER_L2; + odp_pktio_config(pktio, &config); + odp_pktin_queue_param_init(&in_queue_param); odp_pktout_queue_param_init(&out_queue_param);
diff --git a/example/l3fwd/odp_l3fwd.c b/example/l3fwd/odp_l3fwd.c index ba069720..f579d36d 100644 --- a/example/l3fwd/odp_l3fwd.c +++ b/example/l3fwd/odp_l3fwd.c @@ -101,6 +101,7 @@ static int create_pktio(const char *name, odp_pool_t pool, odp_pktio_param_t pktio_param; odp_pktio_t pktio; odp_pktio_capability_t capa; + odp_pktio_config_t config; int rc;
odp_pktio_param_init(&pktio_param); @@ -120,6 +121,12 @@ static int create_pktio(const char *name, odp_pool_t pool, return -1; }
+ odp_pktio_config_init(&config); + config.parser.layer = global.cmd_args.error_check ? + ODP_PKTIO_PARSER_LAYER_ALL : + ODP_PKTIO_PARSER_LAYER_L4; + odp_pktio_config(pktio, &config); + fwd_pktio->nb_rxq = (int)capa.max_input_queues; fwd_pktio->nb_txq = (int)capa.max_output_queues;
diff --git a/example/switch/odp_switch.c b/example/switch/odp_switch.c index 561c2934..5bec6a04 100644 --- a/example/switch/odp_switch.c +++ b/example/switch/odp_switch.c @@ -217,6 +217,7 @@ static int create_pktio(const char *dev, int idx, int num_rx, int num_tx, odp_pktio_t pktio; odp_pktio_param_t pktio_param; odp_pktio_capability_t capa; + odp_pktio_config_t config; odp_pktin_queue_param_t pktin_param; odp_pktout_queue_param_t pktout_param; odp_pktio_op_mode_t mode_rx; @@ -238,6 +239,10 @@ static int create_pktio(const char *dev, int idx, int num_rx, int num_tx, return -1; }
+ odp_pktio_config_init(&config); + config.parser.layer = ODP_PKTIO_PARSER_LAYER_L2; + odp_pktio_config(pktio, &config); + odp_pktin_queue_param_init(&pktin_param); odp_pktout_queue_param_init(&pktout_param);
diff --git a/test/common_plat/performance/odp_l2fwd.c b/test/common_plat/performance/odp_l2fwd.c index 33efc022..78b3633b 100644 --- a/test/common_plat/performance/odp_l2fwd.c +++ b/test/common_plat/performance/odp_l2fwd.c @@ -619,6 +619,7 @@ static int create_pktio(const char *dev, int idx, int num_rx, int num_tx, odp_pktio_param_t pktio_param; odp_schedule_sync_t sync_mode; odp_pktio_capability_t capa; + odp_pktio_config_t config; odp_pktin_queue_param_t pktin_param; odp_pktout_queue_param_t pktout_param; odp_pktio_op_mode_t mode_rx; @@ -655,6 +656,12 @@ static int create_pktio(const char *dev, int idx, int num_rx, int num_tx, return -1; }
+ odp_pktio_config_init(&config); + config.parser.layer = gbl_args->appl.error_check ? + ODP_PKTIO_PARSER_LAYER_ALL : + ODP_PKTIO_PARSER_LAYER_NONE; + odp_pktio_config(pktio, &config); + odp_pktin_queue_param_init(&pktin_param); odp_pktout_queue_param_init(&pktout_param);
diff --git a/test/common_plat/performance/odp_pktio_ordered.c b/test/common_plat/performance/odp_pktio_ordered.c index bff4586e..4bb0bef9 100644 --- a/test/common_plat/performance/odp_pktio_ordered.c +++ b/test/common_plat/performance/odp_pktio_ordered.c @@ -586,6 +586,7 @@ static int create_pktio(const char *dev, int idx, int num_rx, int num_tx, odp_pktio_t pktio; odp_pktio_param_t pktio_param; odp_pktio_capability_t capa; + odp_pktio_config_t config; odp_pktin_queue_param_t pktin_param; odp_pktout_queue_param_t pktout_param; odp_pktio_op_mode_t mode_rx; @@ -611,6 +612,10 @@ static int create_pktio(const char *dev, int idx, int num_rx, int num_tx, return -1; }
+ odp_pktio_config_init(&config); + config.parser.layer = ODP_PKTIO_PARSER_LAYER_L2; + odp_pktio_config(pktio, &config); + odp_pktin_queue_param_init(&pktin_param); odp_pktout_queue_param_init(&pktout_param);
commit fe831783bda53ec4f883cb7f42e585cf37d282db Author: Matias Elo matias.elo@nokia.com Date: Tue Apr 4 09:28:18 2017 +0300
linux-gen: packet: recognize ICMPv6 packets
Signed-off-by: Matias Elo matias.elo@nokia.com Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/example/generator/odp_generator.c b/example/generator/odp_generator.c index 3ec7d8d1..9336cec1 100644 --- a/example/generator/odp_generator.c +++ b/example/generator/odp_generator.c @@ -319,7 +319,7 @@ static odp_packet_t setup_icmp_pkt_ref(odp_pool_t pool) ip->ttl = 64; ip->tot_len = odp_cpu_to_be_16(args->appl.payload + ODPH_ICMPHDR_LEN + ODPH_IPV4HDR_LEN); - ip->proto = ODPH_IPPROTO_ICMP; + ip->proto = ODPH_IPPROTO_ICMPv4; ip->id = 0; ip->chksum = 0;
@@ -664,7 +664,7 @@ static void print_pkts(int thr, odp_packet_t pkt_tbl[], unsigned len) }
/* icmp */ - if (ip->proto == ODPH_IPPROTO_ICMP) { + if (ip->proto == ODPH_IPPROTO_ICMPv4) { icmp = (odph_icmphdr_t *)(buf + offset);
process_icmp_pkt(icmp, msg); diff --git a/example/ipsec/odp_ipsec_stream.c b/example/ipsec/odp_ipsec_stream.c index 15087cbe..e37fbee2 100644 --- a/example/ipsec/odp_ipsec_stream.c +++ b/example/ipsec/odp_ipsec_stream.c @@ -219,7 +219,7 @@ odp_packet_t create_ipv4_packet(stream_db_entry_t *stream, ip->src_addr = odp_cpu_to_be_32(entry->tun_src_ip); ip->dst_addr = odp_cpu_to_be_32(entry->tun_dst_ip); } else { - ip->proto = ODPH_IPPROTO_ICMP; + ip->proto = ODPH_IPPROTO_ICMPv4; ip->src_addr = odp_cpu_to_be_32(stream->src_ip); ip->dst_addr = odp_cpu_to_be_32(stream->dst_ip); } @@ -262,7 +262,7 @@ odp_packet_t create_ipv4_packet(stream_db_entry_t *stream, inner_ip = (odph_ipv4hdr_t *)data; memset((char *)inner_ip, 0, sizeof(*inner_ip)); inner_ip->ver_ihl = 0x45; - inner_ip->proto = ODPH_IPPROTO_ICMP; + inner_ip->proto = ODPH_IPPROTO_ICMPv4; inner_ip->id = odp_cpu_to_be_16(stream->id); inner_ip->ttl = 64; inner_ip->tos = 0; @@ -519,7 +519,7 @@ clear_packet: icmp = (odph_icmphdr_t *)(inner_ip + 1); data = (uint8_t *)icmp; } else { - if (ODPH_IPPROTO_ICMP != ip->proto) + if (ODPH_IPPROTO_ICMPv4 != ip->proto) return FALSE; icmp = (odph_icmphdr_t *)data; } diff --git a/helper/include/odp/helper/ip.h b/helper/include/odp/helper/ip.h index ba6e675f..91776fad 100644 --- a/helper/include/odp/helper/ip.h +++ b/helper/include/odp/helper/ip.h @@ -205,13 +205,14 @@ typedef struct ODP_PACKED { * IP protocol values (IPv4:'proto' or IPv6:'next_hdr') * @{*/ #define ODPH_IPPROTO_HOPOPTS 0x00 /**< IPv6 hop-by-hop options */ -#define ODPH_IPPROTO_ICMP 0x01 /**< Internet Control Message Protocol (1) */ +#define ODPH_IPPROTO_ICMPv4 0x01 /**< Internet Control Message Protocol (1) */ #define ODPH_IPPROTO_TCP 0x06 /**< Transmission Control Protocol (6) */ #define ODPH_IPPROTO_UDP 0x11 /**< User Datagram Protocol (17) */ #define ODPH_IPPROTO_ROUTE 0x2B /**< IPv6 Routing header (43) */ #define ODPH_IPPROTO_FRAG 0x2C /**< IPv6 Fragment (44) */ #define ODPH_IPPROTO_AH 0x33 /**< Authentication Header (51) */ #define ODPH_IPPROTO_ESP 0x32 /**< Encapsulating Security Payload (50) */ +#define ODPH_IPPROTO_ICMPv6 0x3A /**< Internet Control Message Protocol (58) */ #define ODPH_IPPROTO_INVALID 0xFF /**< Reserved invalid by IANA */
/**@}*/ diff --git a/platform/linux-generic/include/protocols/ip.h b/platform/linux-generic/include/protocols/ip.h index 20041f1c..2b34a753 100644 --- a/platform/linux-generic/include/protocols/ip.h +++ b/platform/linux-generic/include/protocols/ip.h @@ -157,13 +157,14 @@ typedef struct ODP_PACKED { * IP protocol values (IPv4:'proto' or IPv6:'next_hdr') * @{*/ #define _ODP_IPPROTO_HOPOPTS 0x00 /**< IPv6 hop-by-hop options */ -#define _ODP_IPPROTO_ICMP 0x01 /**< Internet Control Message Protocol (1) */ +#define _ODP_IPPROTO_ICMPv4 0x01 /**< Internet Control Message Protocol (1) */ #define _ODP_IPPROTO_TCP 0x06 /**< Transmission Control Protocol (6) */ #define _ODP_IPPROTO_UDP 0x11 /**< User Datagram Protocol (17) */ #define _ODP_IPPROTO_ROUTE 0x2B /**< IPv6 Routing header (43) */ #define _ODP_IPPROTO_FRAG 0x2C /**< IPv6 Fragment (44) */ #define _ODP_IPPROTO_AH 0x33 /**< Authentication Header (51) */ #define _ODP_IPPROTO_ESP 0x32 /**< Encapsulating Security Payload (50) */ +#define _ODP_IPPROTO_ICMPv6 0x3A /**< Internet Control Message Protocol (58) */ #define _ODP_IPPROTO_SCTP 0x84 /**< Stream Control Transmission protocol (132) */ #define _ODP_IPPROTO_INVALID 0xFF /**< Reserved invalid by IANA */ diff --git a/platform/linux-generic/odp_packet.c b/platform/linux-generic/odp_packet.c index e2bb8426..c6962ce9 100644 --- a/platform/linux-generic/odp_packet.c +++ b/platform/linux-generic/odp_packet.c @@ -2078,7 +2078,10 @@ int packet_parse_common(packet_parser_t *prs, const uint8_t *ptr,
/* Parse Layer 4 headers */ switch (prs->ip_proto) { - case _ODP_IPPROTO_ICMP: + case _ODP_IPPROTO_ICMPv4: + /* Fall through */ + + case _ODP_IPPROTO_ICMPv6: prs->input_flags.icmp = 1; break;
commit d305e9182802c0522c759ec80b55404ada8ac627 Author: Petri Savolainen petri.savolainen@linaro.org Date: Fri Feb 17 16:20:07 2017 +0200
linux-gen: pktio: parser default config
Fill default parser configuration and capability. All pktios use same parser code, so the capability is the same (all layers).
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 50a000e5..ea9f2a75 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -931,6 +931,8 @@ void odp_pktout_queue_param_init(odp_pktout_queue_param_t *param) void odp_pktio_config_init(odp_pktio_config_t *config) { memset(config, 0, sizeof(odp_pktio_config_t)); + + config->parser.layer = ODP_PKTIO_PARSER_LAYER_ALL; }
int odp_pktio_info(odp_pktio_t hdl, odp_pktio_info_t *info) @@ -1106,6 +1108,7 @@ int odp_pktio_term_global(void) int odp_pktio_capability(odp_pktio_t pktio, odp_pktio_capability_t *capa) { pktio_entry_t *entry; + int ret;
entry = get_pktio_entry(pktio); if (entry == NULL) { @@ -1114,9 +1117,15 @@ int odp_pktio_capability(odp_pktio_t pktio, odp_pktio_capability_t *capa) }
if (entry->s.ops->capability) - return entry->s.ops->capability(entry, capa); + ret = entry->s.ops->capability(entry, capa); + else + ret = single_capability(capa);
- return single_capability(capa); + /* The same parser is used for all pktios */ + if (ret == 0) + capa->config.parser.layer = ODP_PKTIO_PARSER_LAYER_ALL; + + return ret; }
unsigned odp_pktio_max_index(void) diff --git a/test/common_plat/validation/api/pktio/pktio.c b/test/common_plat/validation/api/pktio/pktio.c index 11fe974f..a21959ef 100644 --- a/test/common_plat/validation/api/pktio/pktio.c +++ b/test/common_plat/validation/api/pktio/pktio.c @@ -1182,6 +1182,8 @@ void pktio_test_pktio_config(void)
odp_pktio_config_init(&config);
+ CU_ASSERT(config.parser.layer == ODP_PKTIO_PARSER_LAYER_ALL); + CU_ASSERT(odp_pktio_config(pktio, NULL) == 0);
CU_ASSERT(odp_pktio_config(pktio, &config) == 0);
commit 705ed6cbd52911ccc439dd43230ac4cf6aee4d5f Author: Petri Savolainen petri.savolainen@linaro.org Date: Fri Feb 17 16:20:06 2017 +0200
api: pktio: add parser configuration
Packet input parsing level configuration is added. An application may express the maximum layer it is interested about. Implementations may optimize packet input performance as parsing can be stopped on the application required level. Implementations are free to parse more layers than application requests.
Lazy parsing (e.g. in current odp-linux) does not work in practice. The implementation cannot continue parsing after the application has got access to packet data, since application may overwrite some packet headers. Parse results must reflect the format of the received packet.
Signed-off-by: Petri Savolainen petri.savolainen@linaro.org Reviewed-and-tested-by: Bill Fischofer bill.fischofer@linaro.org Signed-off-by: Maxim Uvarov maxim.uvarov@linaro.org
diff --git a/include/odp/api/spec/packet_io.h b/include/odp/api/spec/packet_io.h index 85cd6d18..cec1f22a 100644 --- a/include/odp/api/spec/packet_io.h +++ b/include/odp/api/spec/packet_io.h @@ -346,6 +346,39 @@ typedef union odp_pktout_config_opt_t { } odp_pktout_config_opt_t;
/** + * Parser layers + */ +typedef enum odp_pktio_parser_layer_t { + /** No layers */ + ODP_PKTIO_PARSER_LAYER_NONE = 0, + + /** Layer L2 protocols (Ethernet, VLAN, ARP, etc) */ + ODP_PKTIO_PARSER_LAYER_L2, + + /** Layer L3 protocols (IPv4, IPv6, ICMP, IPsec, etc) */ + ODP_PKTIO_PARSER_LAYER_L3, + + /** Layer L4 protocols (UDP, TCP, SCTP) */ + ODP_PKTIO_PARSER_LAYER_L4, + + /** All layers */ + ODP_PKTIO_PARSER_LAYER_ALL + +} odp_pktio_parser_layer_t; + +/** + * Parser configuration + */ +typedef struct odp_pktio_parser_config_t { + /** Protocol parsing level in packet input + * + * Parse protocol layers in minimum up to this level during packet + * input. The default value is ODP_PKTIO_PARSER_LAYER_ALL. */ + odp_pktio_parser_layer_t layer; + +} odp_pktio_parser_config_t; + +/** * Packet IO configuration options * * Packet IO interface level configuration options. Use odp_pktio_capability() @@ -363,6 +396,9 @@ typedef struct odp_pktio_config_t { * Default value for all bits is zero. */ odp_pktout_config_opt_t pktout;
+ /** Packet input parser configuration */ + odp_pktio_parser_config_t parser; + /** Interface loopback mode * * In this mode the packets sent out through the interface is
-----------------------------------------------------------------------
Summary of changes: include/odp/api/spec/event.h | 2 +- include/odp/api/spec/ipsec.h | 1359 -------------------- include/odp/api/spec/packet.h | 26 - include/odp/api/spec/packet_io.h | 32 - include/odp/api/spec/support.h | 57 - include/odp_api.h | 2 - platform/Makefile.inc | 2 - platform/linux-generic/Makefile.am | 4 - platform/linux-generic/include/odp/api/ipsec.h | 36 - .../include/odp/api/plat/event_types.h | 1 - .../include/odp/api/plat/ipsec_types.h | 39 - platform/linux-generic/include/odp/api/support.h | 34 - platform/linux-generic/odp_ipsec.c | 151 --- test/common_plat/m4/configure.m4 | 1 - test/common_plat/validation/api/Makefile.am | 1 - test/common_plat/validation/api/ipsec/.gitignore | 1 - test/common_plat/validation/api/ipsec/Makefile.am | 10 - test/common_plat/validation/api/ipsec/ipsec.c | 44 - test/common_plat/validation/api/ipsec/ipsec.h | 24 - test/common_plat/validation/api/ipsec/ipsec_main.c | 12 - test/linux-generic/Makefile.am | 1 - 21 files changed, 1 insertion(+), 1838 deletions(-) delete mode 100644 include/odp/api/spec/ipsec.h delete mode 100644 include/odp/api/spec/support.h delete mode 100644 platform/linux-generic/include/odp/api/ipsec.h delete mode 100644 platform/linux-generic/include/odp/api/plat/ipsec_types.h delete mode 100644 platform/linux-generic/include/odp/api/support.h delete mode 100644 platform/linux-generic/odp_ipsec.c delete mode 100644 test/common_plat/validation/api/ipsec/.gitignore delete mode 100644 test/common_plat/validation/api/ipsec/Makefile.am delete mode 100644 test/common_plat/validation/api/ipsec/ipsec.c delete mode 100644 test/common_plat/validation/api/ipsec/ipsec.h delete mode 100644 test/common_plat/validation/api/ipsec/ipsec_main.c
hooks/post-receive