Annotation of embedaddon/strongswan/src/libstrongswan/plugins/af_alg/af_alg_plugin.c, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2010 Martin Willi
                      3:  * Copyright (C) 2010 revosec AG
                      4:  *
                      5:  * This program is free software; you can redistribute it and/or modify it
                      6:  * under the terms of the GNU General Public License as published by the
                      7:  * Free Software Foundation; either version 2 of the License, or (at your
                      8:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
                      9:  *
                     10:  * This program is distributed in the hope that it will be useful, but
                     11:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     12:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
                     13:  * for more details.
                     14:  */
                     15: 
                     16: #include "af_alg_plugin.h"
                     17: 
                     18: #include <library.h>
                     19: 
                     20: #include "af_alg_hasher.h"
                     21: #include "af_alg_signer.h"
                     22: #include "af_alg_prf.h"
                     23: #include "af_alg_crypter.h"
                     24: 
                     25: #include <unistd.h>
                     26: 
                     27: typedef struct private_af_alg_plugin_t private_af_alg_plugin_t;
                     28: 
                     29: /**
                     30:  * private data of af_alg_plugin
                     31:  */
                     32: struct private_af_alg_plugin_t {
                     33: 
                     34:        /**
                     35:         * public functions
                     36:         */
                     37:        af_alg_plugin_t public;
                     38: };
                     39: 
                     40: METHOD(plugin_t, get_name, char*,
                     41:        private_af_alg_plugin_t *this)
                     42: {
                     43:        return "af-alg";
                     44: }
                     45: 
                     46: static bool af_alg_supported()
                     47: {
                     48:        int fd;
                     49: 
                     50:        fd = socket(AF_ALG, SOCK_SEQPACKET, 0);
                     51:        if (fd != -1)
                     52:        {
                     53:                close(fd);
                     54:                return true;
                     55:        }
                     56:        return false;
                     57: }
                     58: 
                     59: METHOD(plugin_t, get_features, int,
                     60:        private_af_alg_plugin_t *this, plugin_feature_t *features[])
                     61: {
                     62:        static plugin_feature_t f[AF_ALG_HASHER + AF_ALG_SIGNER +
                     63:                                                          AF_ALG_PRF + AF_ALG_CRYPTER + 4] = {};
                     64:        static int count = 0;
                     65: 
                     66:        if (!count)
                     67:        {       /* initialize only once */
                     68:                if (!af_alg_supported())
                     69:                {
                     70:                        return 0;
                     71:                }
                     72:                f[count++] = PLUGIN_REGISTER(HASHER, af_alg_hasher_create);
                     73:                af_alg_hasher_probe(f, &count);
                     74:                f[count++] = PLUGIN_REGISTER(SIGNER, af_alg_signer_create);
                     75:                af_alg_signer_probe(f, &count);
                     76:                f[count++] = PLUGIN_REGISTER(PRF, af_alg_prf_create);
                     77:                af_alg_prf_probe(f, &count);
                     78:                f[count++] = PLUGIN_REGISTER(CRYPTER, af_alg_crypter_create);
                     79:                af_alg_crypter_probe(f, &count);
                     80:        }
                     81:        *features = f;
                     82:        return count;
                     83: }
                     84: 
                     85: METHOD(plugin_t, destroy, void,
                     86:        private_af_alg_plugin_t *this)
                     87: {
                     88:        free(this);
                     89: }
                     90: 
                     91: /*
                     92:  * see header file
                     93:  */
                     94: plugin_t *af_alg_plugin_create()
                     95: {
                     96:        private_af_alg_plugin_t *this;
                     97: 
                     98:        INIT(this,
                     99:                .public = {
                    100:                        .plugin = {
                    101:                                .get_name = _get_name,
                    102:                                .get_features = _get_features,
                    103:                                .destroy = _destroy,
                    104:                        },
                    105:                },
                    106:        );
                    107: 
                    108:        return &this->public.plugin;
                    109: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>