/* ipmip_pktbuf.h - ipmip_pktbuf.h */ /* ****************************************************************************** * HEADER FILE * * Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipmip_pktbuf.h,v $ $Revision: 1.11 $ * $Source: /home/interpeak/CVSRoot/ipmip/include/private/ipmip_pktbuf.h,v $ * $Author: jhorteli $ $Date: 2011-01-21 15:31:28 $ * $State: Exp $ $Locker: $ * * INTERPEAK_COPYRIGHT_STRING * Design and implementation by Joel Hortelius ****************************************************************************** */ #ifndef IPMIP_PKTBUF_H #define IPMIP_PKTBUF_H /* **************************************************************************** * 1 DESCRIPTION **************************************************************************** * Packet buffer base class, which is usually overloaded by the various * mobile agents and nodes in order to contain instantiation specific * information. */ /* DESCRIPTION Packet buffer base class, which is usually overloaded by the various mobile agents and nodes in order to contain instantiation specific information. EXAMPLE This example provides information regarding how the packet context create is done. The base example is lifted from the ipmip_context.h, and the appropriate code for packet context initialization added. .CS struct Ipmip_my_pktbuf { Ipmip_pktbuf_t ipmip; int extra_data; }; IP_GLOBAL Ipmip_pktbuf_t *ipmip_my_pktbuf_alloc(struct Ipmip_my_context *ctx, Ipmip_proc_t *proc, Ip_size_t extra) { struct Ipmip_my_pktbuf *pbuf = ipcom_calloc(1, sizeof(struct Ipmip_my_pktbuf) + extra); if (pbuf) { /@ Initialize the packet buffer. Tell the IPMIP packet context where our header ends. @/ pbuf->ipmip.pktend = (void *) (pbuf + 1); return &pbuf->ipmip; } return IP_NULL; } IP_GLOBAL void ipmipha_pktbuf_free(struct Ipmip_my_context *ctx, Ipmip_proc_t *proc, struct Ipmip_my_pktbuf *pbuf) { /@ Free the packet buffer. If you had extra data allocated in the alloc, this would be the place to free it @/ ipcom_free(pbuf); } struct Ipmip_my_context *my_init_func(Ipmip_proc_t *proc) { /@ Allocate my context; indicate the size of my overloaded structure @/ struct Ipmip_my_context *ctx = (struct Ipmip_my_context *)ipmip_context_alloc(proc, sizeof(*ctx), "mymip", IPCOM_LOG_DEBUG2, 10); /@ Create the packet context @/ ipmip_pktbuf_context_create(&ctx->ipmip, proc, (Ipmip_pkt_buf_alloc_t)ipmip_my_pktbuf_alloc, (Ipmip_pkt_buf_free_t)ipmip_my_pktbuf_free); /@ Start the context @/ ipmip_context_start(&ctx->ipmip, proc); } .CE This particular example allocates and frees a buffer .CS void my_packet_routine(struct Ipmip_my_context *ctx, Ipmip_proc_t *proc) { /@ Allocate a packet buffer with a minimum of 1024 bytes already allocated @/ struct Ipmip_my_pktbuf *pbuf = (struct Ipmip_my_pktbuf * *)ipmip_pktbuf_alloc(&ctx->ipmip, proc, 1024); /@ Release the packet buffer @/ ipmip_pktbuf_release(&ctx->ipmip, proc, &pbuf->ipmip); } .CE */ /* **************************************************************************** * 2 CONFIGURATION **************************************************************************** */ /* **************************************************************************** * 3 INCLUDE FILES **************************************************************************** */ #include #include #include #ifdef __cplusplus extern "C" { #endif /* **************************************************************************** * 4 DEFINES **************************************************************************** */ #define ipmip_pktbuf_indexdata(pbuf, index) ((pbuf)->pktarr[i])) #define ipmip_pktbuf_pktdata(pbuf, reg) ipmip_pktbuf_indexdata(pbuf, (reg)->pktbuf_data_index) /* **************************************************************************** * 5 TYPES **************************************************************************** */ struct Ipmip_pktbuf; struct Ipmip_if; struct Ipmip_pkt_context; struct Ipmip_context; struct Ipmip_proc; struct Ipmip_lladdr; typedef struct Ipmip_pktbuf * (*Ipmip_pkt_buf_alloc_t) ( struct Ipmip_context *ctx, struct Ipmip_proc *proc, Ip_size_t extra ); typedef void (*Ipmip_pkt_buf_free_t) ( struct Ipmip_context *ctx, struct Ipmip_proc *proc, struct Ipmip_pktbuf *pbuf ); typedef void (*Ipmip_pkt_buf_released_t) ( struct Ipmip_context *ctx, struct Ipmip_proc *proc, struct Ipmip_pktbuf *pbuf ); typedef struct Ipmip_pktbuf_pktinfo { union Ip_sockaddr_union dst; Ip_u32 ifindex; } Ipmip_pktbuf_pktinfo_t; struct Ipmip_pktbuf_srcinfo { union Ip_sockaddr_union *src; Ipmip_pktbuf_pktinfo_t *dst; struct Ip_sockaddr_dl *dl; struct Ip_sockaddr_ll *ll; struct Ipmip_lladdr *lladdr; int ttl; }; typedef struct Ipmip_pktbuf { Ipcom_list next; Ipmip_buffer_t packet; Ipmip_timer_t timeout; Ipmip_timer_t pending; Ipmip_pkt_buf_released_t released; struct Ipmip_pktbuf_srcinfo srcinfo; Ipcom_atomic_t refcnt; /* Transaction identifier */ char *message; Ip_u8 error_code; /* App data */ Ip_u8 *pktend; void **pktarr; Ip_size_t pktoff; } Ipmip_pktbuf_t; typedef void (*Ipmip_pktbuf_free_data_t) (struct Ipmip_context *, struct Ipmip_proc *, struct Ipmip_pktbuf *, void *data); typedef struct Ipmip_pktbuf_payload { Ipmip_pktbuf_free_data_t pktbuf_data_free; Ip_size_t pktbuf_data_size; Ip_u32 pktbuf_data_index; } Ipmip_pktbuf_payload_t; typedef struct Ipmip_pktbuf_context { Ipmip_pkt_buf_alloc_t bufalloc; Ipmip_pkt_buf_free_t buffree; } Ipmip_pktbuf_context_t; typedef struct Ipmip_pktbuf_pktaux { Ipmip_pktbuf_payload_t *pktdata[IPMIP_PKTBUF_PKTAUX_SIZE]; Ip_size_t pktdata_num; Ip_size_t pktdata_header; Ip_size_t pktdata_payload; } Ipmip_pktbuf_pktaux_t; /* **************************************************************************** * 6 FUNCTIONS **************************************************************************** */ /******************************************************************************* * * ipmip_pktbuf_alloc - ipmip_pktbuf_alloc * * Allocate a pktbuf. The packet will have a minimum of pkt_size * bytes already available in the packet buffer. The real allocation * of this frame is done by the bufalloc hook registered in the packet * context create. * * Parameters: * \is * \i context * The context * \i proc * The process context associated with the currently executing thread. Each * thread and/or process in MIP must have its own unique process context. * If a process is started using ipmip_proc_start, the process context will * be allocated automatically by the IPMIP framework. Otherwise it must * be allocated using ipmip_proc_alloc(). * \i pkt_size * The initial size of the packet buffer * \ie * * RETURNS: A newly allocated and initialized pktbuf on success * * ERRNO: * */ IP_GLOBAL Ipmip_pktbuf_t * ipmip_pktbuf_alloc ( struct Ipmip_context *context, struct Ipmip_proc *proc, Ip_size_t pkt_size ); /******************************************************************************* * * ipmip_pktbuf_free - ipmip_pktbuf_free * * Free a previously allocated pktbuf. You should not invoke this function * unless you are certain the packet is unreferenced. Otherwise you should * invoke ipmip_pktbuf_release. The real releasing of resources is done by * the buffree function registered in the packet context create. * * Parameters: * \is * \i ctx * The generic mobility singleton context for IPMIP. For each started mobility * entity, there exists a mobility context which tracks configuration, system * events, available features and started processes. The mobility context is * created using ipmip_context_create(). See ipmip_context.h for more information * regarding the mobility entity context singleton. * \i proc * The process context associated with the currently executing thread. Each * thread and/or process in MIP must have its own unique process context. * If a process is started using ipmip_proc_start, the process context will * be allocated automatically by the IPMIP framework. Otherwise it must * be allocated using ipmip_proc_alloc(). * \i pbuf * The pktbuf * \ie * * RETURNS: No return value * * ERRNO: * */ IP_GLOBAL void ipmip_pktbuf_free ( struct Ipmip_context *ctx, struct Ipmip_proc *proc, Ipmip_pktbuf_t *pbuf ); /******************************************************************************* * * ipmip_pktbuf_release - ipmip_pktbuf_release * * Release the pktbuf, and if possible, free it. * * Parameters: * \is * \i ctx * The generic mobility singleton context for IPMIP. For each started mobility * entity, there exists a mobility context which tracks configuration, system * events, available features and started processes. The mobility context is * created using ipmip_context_create(). See ipmip_context.h for more information * regarding the mobility entity context singleton. * \i proc * The process context associated with the currently executing thread. Each * thread and/or process in MIP must have its own unique process context. * If a process is started using ipmip_proc_start, the process context will * be allocated automatically by the IPMIP framework. Otherwise it must * be allocated using ipmip_proc_alloc(). * \i pbuf * The pktbuf * \ie * * RETURNS: No return value * * ERRNO: * */ IP_GLOBAL void ipmip_pktbuf_release ( struct Ipmip_context *ctx, struct Ipmip_proc *proc, Ipmip_pktbuf_t *pbuf ); /******************************************************************************* * * ipmip_pktbuf_reference - ipmip_pktbuf_reference * * Reference the pktbuf * * Parameters: * \is * \i ctx * The generic mobility singleton context for IPMIP. For each started mobility * entity, there exists a mobility context which tracks configuration, system * events, available features and started processes. The mobility context is * created using ipmip_context_create(). See ipmip_context.h for more information * regarding the mobility entity context singleton. * \i proc * The process context associated with the currently executing thread. Each * thread and/or process in MIP must have its own unique process context. * If a process is started using ipmip_proc_start, the process context will * be allocated automatically by the IPMIP framework. Otherwise it must * be allocated using ipmip_proc_alloc(). * \i pbuf * The pktbuf * \ie * * RETURNS: No return value * * ERRNO: * */ IP_GLOBAL void ipmip_pktbuf_reference ( struct Ipmip_context *ctx, struct Ipmip_proc *proc, Ipmip_pktbuf_t *pbuf ); /******************************************************************************* * * ipmip_pktbuf_context_create - ipmip_pktbuf_context_create * * This function creates the packet buffer context. It requires two arguments, * which are the bufalloc and buffree function callbacks. * The bufalloc callback will be invoked when a packet frame is to be allocated, * and parameters to this function call will be the extra size that IPMIP * requires beyond the basic sizeof(Ipmip_pktbuf_t). The bufalloc function * must initialize the pktend pointer in the Ipmip_pktbuf_t to the end * of the packet header, where the end is either sizeof(Ipmip_pktbuf_t) bytes * in to the frame, or more if Ipmip_pktbuf_t has been overloaded in order * to define more required packet buffer parameters for that system. * The buffree function hook will be invoked when a frame is to be freed. It * is supposed to free the packet buffer and any extra data allocated by the * bufalloc routine, * * Parameters: * \is * \i ctx * The generic mobility singleton context for IPMIP. For each started mobility * entity, there exists a mobility context which tracks configuration, system * events, available features and started processes. The mobility context is * created using ipmip_context_create(). See ipmip_context.h for more information * regarding the mobility entity context singleton. * \i proc * The process context associated with the currently executing thread. Each * thread and/or process in MIP must have its own unique process context. * If a process is started using ipmip_proc_start, the process context will * be allocated automatically by the IPMIP framework. Otherwise it must * be allocated using ipmip_proc_alloc(). * \i bufalloc * Pkt buffer allocation function; If NULL a * * straight Ipmip_pktbuf_t will be allocated. * \i buffree * Overriding free function for packet buffers; * * if none, ordinary free will be used. * \ie * * RETURNS: IP_TRUE if successful * * ERRNO: * * NOMANUAL */ IP_GLOBAL Ip_bool ipmip_pktbuf_context_create ( struct Ipmip_context *ctx, struct Ipmip_proc *proc, Ipmip_pkt_buf_alloc_t bufalloc, Ipmip_pkt_buf_free_t buffree ); /******************************************************************************* * * ipmip_pktbuf_context_destroy - ipmip_pktbuf_context_destroy * * Destroy the buffer context. This method is used internally by the IPMIP * context, and you should not ever need to invoke it. It's called from * the ipmip_context_destroy function. * * Parameters: * \is * \i ctx * The generic mobility singleton context for IPMIP. For each started mobility * entity, there exists a mobility context which tracks configuration, system * events, available features and started processes. The mobility context is * created using ipmip_context_create(). See ipmip_context.h for more information * regarding the mobility entity context singleton. * \i proc * The process context associated with the currently executing thread. Each * thread and/or process in MIP must have its own unique process context. * If a process is started using ipmip_proc_start, the process context will * be allocated automatically by the IPMIP framework. Otherwise it must * be allocated using ipmip_proc_alloc(). * \ie * * RETURNS: No return value * * ERRNO: * * NOMANUAL */ IP_GLOBAL void ipmip_pktbuf_context_destroy ( struct Ipmip_context *ctx, struct Ipmip_proc *proc ); /******************************************************************************* * * ipmip_pktbuf_error - ipmip_pktbuf_error * * Set an error message and a code in a packet buffer. * * Parameters: * \is * \i pbuf * The pktbuf * \i error_code * Error code * \i format * The format string * \i ... * The format parameters * \ie * * RETURNS: No return value * * ERRNO: * */ IP_GLOBAL void ipmip_pktbuf_error ( Ipmip_pktbuf_t *pbuf, Ip_u8 error_code, const char *format, ... ); #ifdef IPMIP_USE_INET /******************************************************************************* * * ipmip_pktbuf_srcinfo_dst_inet - ipmip_pktbuf_srcinfo_dst_inet * * Set the destination sourceinfo based on an inet pktinfo. * * Parameters: * \is * \i pbuf * The pktbuf * \i pktinfo * Packet info container * \ie * * RETURNS: No return value * * ERRNO: * * NOMANUAL */ IP_GLOBAL void ipmip_pktbuf_srcinfo_dst_inet ( Ipmip_pktbuf_t *pbuf, struct Ip_in_pktinfo *pktinfo ); #endif #ifdef IPMIP_USE_INET6 /******************************************************************************* * * ipmip_pktbuf_srcinfo_dst_inet6 - ipmip_pktbuf_srcinfo_dst_inet6 * * Set the destination sourceinfo based on an inet6 pktinfo. * * Parameters: * \is * \i pbuf * The pktbuf * \i pktinfo * Packet info container * \ie * * RETURNS: No return value * * ERRNO: * * NOMANUAL */ IP_GLOBAL void ipmip_pktbuf_srcinfo_dst_inet6 ( Ipmip_pktbuf_t *pbuf, struct Ip_in6_pktinfo *pktinfo ); #endif /******************************************************************************* * * ipmip_pktbuf_pktaux_add - ipmip_pktbuf_pktaux_add * * Register a packet buffer data extension. This function is invoked during * setup of a MIP entity. It will reserve the space indicated by pktaux in * all allocated packet buffers. * * Parameters: * * \is * \i aux * Packet context auxillary information * \i pktaux * Packet buffer auxillary definition * \ie * * RETURNS: The packet payload index on success, 0 on failure. * * ERRNO: * * NOMANUAL */ IP_GLOBAL Ip_u32 ipmip_pktbuf_pktaux_add ( Ipmip_pktbuf_pktaux_t *aux, Ipmip_pktbuf_payload_t *pktaux ); /******************************************************************************* * * ipmip_pktbuf_pktaux_data_get - ipmip_pktbuf_pktaux_data_get * * Retrieve the data allocated for a specific payload index. The payload * index is the number returned by the ipmip_pktbuf_pktaux_add function. * * Parameters: * * \is * \i ctx * The generic mobility singleton context for IPMIP. For each started mobility * entity, there exists a mobility context which tracks configuration, system * events, available features and started processes. The mobility context is * created using ipmip_context_create(). See ipmip_context.h for more information * regarding the mobility entity context singleton. * \i pbuf * Packet buffer * \i payload_index * The packet buffer payload index * \i payload_create * Create the payload buffer if TRUE, otherwise just return what is. * \ie * * RETURNS: The data if available, or IP_NULL. * * ERRNO: * * NOMANUAL */ IP_GLOBAL void *ipmip_pktbuf_pktaux_data_get ( struct Ipmip_context *ctx, Ipmip_pktbuf_t *pbuf, Ip_u32 payload_index, Ip_bool payload_create ); #ifdef __cplusplus } #endif #endif /* **************************************************************************** * END OF FILE **************************************************************************** */