Annotation of embedaddon/strongswan/src/libcharon/attributes/mem_pool.h, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (C) 2010 Tobias Brunner
        !             3:  * HSR Hochschule fuer Technik Rapperswil
        !             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: /**
        !            17:  * @defgroup mem_pool mem_pool
        !            18:  * @{ @ingroup attributes
        !            19:  */
        !            20: 
        !            21: #ifndef MEM_POOL_H
        !            22: #define MEM_POOL_H
        !            23: 
        !            24: typedef struct mem_pool_t mem_pool_t;
        !            25: typedef enum mem_pool_op_t mem_pool_op_t;
        !            26: 
        !            27: #include <networking/host.h>
        !            28: #include <utils/identification.h>
        !            29: 
        !            30: /**
        !            31:  * In-memory IP pool acquire operation.
        !            32:  */
        !            33: enum mem_pool_op_t {
        !            34:        /** Check for an existing lease */
        !            35:        MEM_POOL_EXISTING,
        !            36:        /** Get a new lease */
        !            37:        MEM_POOL_NEW,
        !            38:        /** Replace an existing offline lease of another ID */
        !            39:        MEM_POOL_REASSIGN,
        !            40: };
        !            41: 
        !            42: /**
        !            43:  * An in-memory IP address pool.
        !            44:  */
        !            45: struct mem_pool_t {
        !            46: 
        !            47:        /**
        !            48:         * Get the name of this pool.
        !            49:         *
        !            50:         * @return                      the name of this pool
        !            51:         */
        !            52:        const char* (*get_name)(mem_pool_t *this);
        !            53: 
        !            54:        /**
        !            55:         * Get the base (first) address of this pool.
        !            56:         *
        !            57:         * @return                      base address, internal host
        !            58:         */
        !            59:        host_t* (*get_base)(mem_pool_t *this);
        !            60: 
        !            61:        /**
        !            62:         * Get the size (i.e. number of addresses) of this pool.
        !            63:         *
        !            64:         * @return                      the size of this pool
        !            65:         */
        !            66:        u_int (*get_size)(mem_pool_t *this);
        !            67: 
        !            68:        /**
        !            69:         * Get the number of online leases.
        !            70:         *
        !            71:         * @return                      the number of offline leases
        !            72:         */
        !            73:        u_int (*get_online)(mem_pool_t *this);
        !            74: 
        !            75:        /**
        !            76:         * Get the number of offline leases.
        !            77:         *
        !            78:         * @return                      the number of online leases
        !            79:         */
        !            80:        u_int (*get_offline)(mem_pool_t *this);
        !            81: 
        !            82:        /**
        !            83:         * Acquire an address for the given id from this pool.
        !            84:         *
        !            85:         * This call is usually invoked several times: The first time to find an
        !            86:         * existing lease (MEM_POOL_EXISTING), if none found a second time to
        !            87:         * acquire a new lease (MEM_POOL_NEW), and if the pool is full once again
        !            88:         * to assign an existing offline lease (MEM_POOL_REASSIGN).
        !            89:         *
        !            90:         * If the same identity requests a virtual IP that is already assigned to
        !            91:         * it, the peer address and port is used to check if it is the same client
        !            92:         * instance that is connecting. If this is true, the request is considered
        !            93:         * a request for a reauthentication attempt, and the same virtual IP gets
        !            94:         * assigned to the peer.
        !            95:         *
        !            96:         * @param id            the id to acquire an address for
        !            97:         * @param requested     acquire this address, if possible
        !            98:         * @param operation     acquire operation to perform, see above
        !            99:         * @param peer          optional remote IKE address and port
        !           100:         * @return                      the acquired address
        !           101:         */
        !           102:        host_t* (*acquire_address)(mem_pool_t *this, identification_t *id,
        !           103:                                                           host_t *requested, mem_pool_op_t operation,
        !           104:                                                           host_t *peer);
        !           105: 
        !           106:        /**
        !           107:         * Release a previously acquired address.
        !           108:         *
        !           109:         * @param address       the address to release
        !           110:         * @param id            the id the address was assigned to
        !           111:         * @return                      TRUE, if the lease was found
        !           112:         */
        !           113:        bool (*release_address)(mem_pool_t *this, host_t *address,
        !           114:                                                        identification_t *id);
        !           115: 
        !           116:        /**
        !           117:         * Create an enumerator over the leases of this pool.
        !           118:         *
        !           119:         * Enumerator enumerates over
        !           120:         * identification_t *id, host_t *address, bool online
        !           121:         *
        !           122:         * @return                      enumerator
        !           123:         */
        !           124:        enumerator_t* (*create_lease_enumerator)(mem_pool_t *this);
        !           125: 
        !           126:        /**
        !           127:         * Destroy a mem_pool_t instance.
        !           128:         */
        !           129:        void (*destroy)(mem_pool_t *this);
        !           130: };
        !           131: 
        !           132: /**
        !           133:  * Create an in-memory IP address pool.
        !           134:  *
        !           135:  * An empty pool just returns the requested address.
        !           136:  *
        !           137:  * @param name         name of this pool
        !           138:  * @param base         base address of this pool, NULL to create an empty pool
        !           139:  * @param bits         number of non-network bits in base, as in CIDR notation
        !           140:  * @return                     memory pool instance
        !           141:  */
        !           142: mem_pool_t *mem_pool_create(char *name, host_t *base, int bits);
        !           143: 
        !           144: /**
        !           145:  * Create an in-memory IP address from a range.
        !           146:  *
        !           147:  * @param name         name of this pool
        !           148:  * @param from         start of ranged pool
        !           149:  * @param to           end of ranged pool
        !           150:  * @return                     memory pool instance, NULL if range invalid
        !           151:  */
        !           152: mem_pool_t *mem_pool_create_range(char *name, host_t *from, host_t *to);
        !           153: 
        !           154: #endif /** MEM_POOL_H_ @} */

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