/* This file is provided under a dual BSD/GPLv2 license. When using or redistributing this file, you may do so under either license. GPL LICENSE SUMMARY Copyright(c) 2014-2015 Intel Corporation. This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. The full GNU General Public License is included in this distribution in the file called LICENSE.GPL. Contact Information: Intel Corporation 2200 Mission College Blvd. Santa Clara, CA 97052 BSD LICENSE Copyright(c) 2014-2015 Intel Corporation. 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. */ /***************************************************************************/ /*! \file ti_pp_path.h \brief Exports of PP Path counters ****************************************************************************/ #ifndef _TI_PP_PATH_H_ #define _TI_PP_PATH_H_ #ifndef _TI_PP_PATH_C #define EXTERN #else #define EXTERN extern #endif /* To include debug code, enable this */ //#define PPP_DEBUG /**************************************************************************/ /* INCLUDES */ /**************************************************************************/ #include /**************************************************************************/ /* INTERFACE Defines and Structs */ /**************************************************************************/ /*! \var typedef enum PPP_pathDir_e \brief Defines the direction of a path */ typedef enum { /* PPP_PATHDIR_NONE is for internal use only, not to be used by APIs */ PPP_PATHDIR_NONE = 0, /* Keep it ==0, so memest 0 will set to the default value of NONE */ /* *** */ PPP_PATHDIR_IN, PPP_PATHDIR_OUT } PPP_pathDir_e; /*! \var typedef struct PPP_1Counetr_t \brief Single counter with all counted element types */ typedef struct { Uint64 octets; Uint64 packets; } PPP_1Counetr_t; /*! \var typedef struct PPP_unidirCounetrs_t \brief Uni-directional counters */ typedef struct { PPP_1Counetr_t unicastCtr; PPP_1Counetr_t multicastCtr; } PPP_unidirCounetrs_t; /*! \var typedef struct PPP_counters_t \brief Path counters */ typedef struct { PPP_unidirCounetrs_t inCtrs; PPP_unidirCounetrs_t outCtrs; } PPP_counters_t; /*! \var typedef struct TI_PPP_PACKET_INFO \brief Per packet info required for PP Path management Theoretiaclly, we need a linked list of all devices the packet travelled thru, but to save RT, we use a static array. Length 2 should suffice, but to be on the safe side we use 5 */ typedef struct { Uint32 num_devs; /* Number of devices */ int devices[5]; /* device index */ #ifdef PPP_DEBUG Uint32 num_clones; /* Number of clonings this skb suffered */ Uint32 num_copies; /* Number of clonings this skb suffered */ int clones[5]; /* device index */ int copies[5]; /* device index */ #ifdef CONFIG_FTRACE unsigned long long markTime[5]; unsigned long long allocTime; #endif #endif } TI_PPP_PACKET_INFO; /**************************************************************************/ /*! \var PPP_1CTR(__ctr, __path, __session) ************************************************************************** * \brief Refernce a single counter * \param[in] __ctr: Name of counter - PPP_counters_t * * \param[in] __dir: Direction to count * \param[in] __mcast: Multi/Unicast * \return Counter variable PPP_uniCounetrs_t **************************************************************************/ #define PPP_1CTR(__ctr, __dir, __mcast) \ ((__dir) == PPP_PATHDIR_IN) ? \ ((__mcast) ? &((__ctr)->inCtrs.multicastCtr) : &((__ctr)->inCtrs.unicastCtr)) : \ ((__mcast) ? &((__ctr)->outCtrs.multicastCtr) : &((__ctr)->outCtrs.unicastCtr)) #define PPP_ZERO_CTR(__ctr) \ do { \ memset((__ctr), 0, sizeof(*(__ctr))); \ } while (0) #define PPP_ADD_1CTR_oct_pckt(__dest, __oct, __pckt) \ do { \ (__dest)->octets += (__oct); \ (__dest)->packets += (__pckt); \ } while (0) #define PPP_ADD_1CTR(__dest, __add) \ PPP_ADD_1CTR_oct_pckt((__dest), (__add)->octets, (__add)->packets) #define PPP_ADD_UNIDIRCTR(__dest, __add) \ do { \ PPP_ADD_1CTR(&((__dest)->unicastCtr), &((__add)->unicastCtr)); \ PPP_ADD_1CTR(&((__dest)->multicastCtr), &((__add)->multicastCtr)); \ } while (0) #define PPP_ADD_CTRS(__dest, __add) \ do { \ PPP_ADD_UNIDIRCTR(&((__dest)->inCtrs), &((__add)->inCtrs)); \ PPP_ADD_UNIDIRCTR(&((__dest)->outCtrs),&((__add)->outCtrs)); \ } while (0) #define PPP_DISPLAY_FORMAT_1CTR \ "Bytes %llu, Packets %llu" #define PPP_DISPLAY_ELEMENTS_1CTR(__ctr) \ (__ctr)->octets, (__ctr)->packets #define PPP_DISPLAY_FORMAT_UNIDIRCTR(__indent) \ "\n" __indent "Unicast [" PPP_DISPLAY_FORMAT_1CTR "]" \ "\n" __indent "Multicast [" PPP_DISPLAY_FORMAT_1CTR "]" #define PPP_DISPLAY_ELEMENTS_UNIDIRCTR(__ctr) \ PPP_DISPLAY_ELEMENTS_1CTR(&((__ctr)->unicastCtr)), \ PPP_DISPLAY_ELEMENTS_1CTR(&((__ctr)->multicastCtr)) #define PPP_DISPLAY_FORMAT_CTRS(__indent) \ "\n" __indent "In" PPP_DISPLAY_FORMAT_UNIDIRCTR(__indent "\t") \ "\n" __indent "Out" PPP_DISPLAY_FORMAT_UNIDIRCTR(__indent "\t") #define PPP_DISPLAY_ELEMENTS_CTRS(__ctr) \ PPP_DISPLAY_ELEMENTS_UNIDIRCTR(&((__ctr)->inCtrs)), \ PPP_DISPLAY_ELEMENTS_UNIDIRCTR(&((__ctr)->outCtrs)) /**************************************************************************/ /* EXTERN definition block */ /**************************************************************************/ /**************************************************************************/ /* INTERFACE VARIABLES (prefix with EXTERN) */ /**************************************************************************/ /**************************************************************************/ /* INTERFACE FUNCTIONS Prototypes: */ /**************************************************************************/ #if defined(__KERNEL__) /**************************************************************************/ /*! \fn int PPP_Init(void) ************************************************************************** * \brief Init the PPP module * \return 0 (OK) / 1 (NOK) **************************************************************************/ int PPP_Init(void); /**************************************************************************/ /*! \fn int PPP_AddPath(char *rxFrom, char *txTo, char *viaVirtualDev, PPP_pathDir_e pathDir) ************************************************************************** * \brief Add a path * \param[in] rxFrom - input device * \param[in] txTo - output device * \param[in] viaVirtualDev - virtual device through which the traffic flows * \param[in] pathDir - does the count belong to the IN (to the box) or OUT (of the box) * \return 0 (OK) / err (NOK) **************************************************************************/ int PPP_AddPath(char *rxFrom, char *txTo, char *viaVirtualDev, PPP_pathDir_e pathDir); /**************************************************************************/ /*! \fn int PPP_DelPath(char *rxFrom, char *txTo, char *viaVirtualDev) ************************************************************************** * \brief Delete a path * \param[in] rxFrom - device used as IN * \param[in] txTo - device used as OUT * \param[in] viaVirtualDev - virtual device through which the traffic flows * \return 0 (OK) / 1 (NOK) **************************************************************************/ int PPP_DelPath(char *rxFrom, char *txTo, char *viaVirtualDev); /**************************************************************************/ /*! \fn int PPP_ReadCounters(char *viaVirtualDev, PPP_counters_t *pppCtrs) ************************************************************************** * \brief Read a path's counters * \param[in] viaVirtualDev - virtual device through which the traffic flows * \param[out] pppCtrs - Counters of PP traffic going through the virtual device * in/out are provided according to the paths requested when * adding the paths. * \return 0 (OK) / 1 (NOK) **************************************************************************/ int PPP_ReadCounters(char *viaVirtualDev, PPP_counters_t *pppCtrs); /**************************************************************************/ /*! \fn static int PPP_MarkPacket(struct sk_buff *skb, int dev) ************************************************************************** * \brief Mark (in the skb) that the packet flowed via the device * \param[in] skb - skb that started the session * \param[in] dev - the device index through which the packet is flowing * \return 0 (OK) / !=1 (NOK) **************************************************************************/ int PPP_MarkPacket(struct sk_buff *skb, int dev); #endif /*KERNEL*/ #endif