Files
2026-07-30 11:19:44 +05:30

834 lines
24 KiB
C

/* ipmip4_pkt.h - ipmip4_pkt.h */
/*
******************************************************************************
* HEADER FILE
*
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipmip4_pkt.h,v $ $Revision: 1.5 $
* $Source: /home/interpeak/CVSRoot/ipmip4/include/private/ipmip4_pkt.h,v $
* $Author: jhorteli $ $Date: 2011-01-21 15:31:36 $
* $State: Exp $ $Locker: $
*
* INTERPEAK_COPYRIGHT_STRING
* Design and implementation by Joel Hortelius <joel.hortelius@interpeak.se>
******************************************************************************
*/
#ifndef IPMIP4_PACKET_H
#define IPMIP4_PACKET_H
/*
****************************************************************************
* 1 DESCRIPTION
****************************************************************************
* Base packet management class, containing vital information for creating
* packets, receiving packets and sending packets.
*/
/*
DESCRIPTION
Base packet management class, containing vital information for creating
packets, receiving packets and sending packets.
EXAMPLE
These examples extends the example functions originally defined
ipmip4_context.h, and shows how should create and manage the packet
context.
.CS
IP_GLOBAL void
ipmip4_reg_recv(struct Ipmip4_my_context *ctx,
struct Ipmip_proc *proc,
Ipmip4_pktbuf_t *pbuf,
void *arg)
{
/@ Process the registration request @/
/@ Release the packet buffer @/
ipmip_pktbuf_release(&ctx->ipmip4.ipmip, proc, &pbuf->ipmip);
}
IP_GLOBAL void
ipmip4_udp_recv(struct Ipmip4_my_context *ctx,
struct Ipmip_proc *proc,
Ipmip4_pktbuf_t *pbuf,
void *arg)
{
/@ Process the UDP packet @/
/@ Release the packet buffer @/
ipmip_pktbuf_release(&ctx->ipmip4.ipmip, proc, &pbuf->ipmip);
}
IP_GLOBAL void
ipmip4_adv_recv(struct Ipmip4_my_context *ctx,
struct Ipmip_proc *proc,
Ipmip4_pktbuf_t *pbuf)
{
Ipcom_icmp_header *icmph = IPMIP_BUFFER_PTR(&pbuf->ipmip.packet);
/@ Process the ICMP packet @/
/@ Release the packet buffer @/
ipmip_pktbuf_release(&data->ipmip4.ipmip, proc, &pbuf->ipmip4.ipmip);
}
struct Ipmip4_my_context *my_init_func4(Ipmip_proc_t *proc)
{
/@ Allocate my context; indicate the size of my overloaded structure @/
struct Ipmip4_my_context *ctx = (struct Ipmip_my_context *)ipmip_context_alloc(proc, sizeof(*ctx), "mymip4", IPCOM_LOG_DEBUG2, 10);
struct Ip_sockaddr_in udp;
/@ Initialize the MIP4 portion of the context @/
ipmip4_context_init(&ctx->ipmip4, proc);
/@ Create a packet context @/
ipmip4_pkt_context_create(&ctx->ipmip4,
proc,
IPMIP4_PKT_UDP_IN_434|IPMIP4_PKT_UDP_IN_OUT|IPMIP4_PKT_PKT_OUT|IPMIP4_PKT_ICMP_IN,
(Ipmip4_pkt_udp_cb_t)ipmip4_reg_recv,
(Ipmip4_pkt_icmp_cb_t)ipmip4_adv_recv,
IP_NULL);
/@ Register an extra UDP socket to the packet context @/
ipcom_memset(&udp, 0, sizeof(udp));
udp.sin_family = IP_AF_INET;
udp.sin_len = sizeof(udp);
udp.sin_addr.s_addr = 0;
udp.sin_port = ip_htons(1000);
ctx->udpr.udp_callback = (Ipmip4_pkt_udp_cb_t)ipmip4_udp_recv;
ctx->udpr.opaque = IP_NULL;
ctx->udpr.fd = ipmip_inet_udp_socket(&udp);
ipmip4_pkt_udp_register(&ctx->ipmip4, proc, &cfg->udpr);
/@ Start the context @/
ipmip4_context_start(&ctx->ipmip4, proc);
}
.CE
*/
/*
****************************************************************************
* 2 CONFIGURATION
****************************************************************************
*/
/*
****************************************************************************
* 3 INCLUDE FILES
****************************************************************************
*/
#include <private/ipmip_buffer.h>
#include <private/ipmip4_context.h>
#include <private/ipmip4_if.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
****************************************************************************
* 4 DEFINES
****************************************************************************
*/
#define IPMIP4_PKT_UDP_IN_434 (1 << 0)
#define IPMIP4_PKT_UDP_IN_OUT (1 << 1) /* Use two different sockets for in/out */
#define IPMIP4_PKT_PKT_IN (1 << 2) /* ARP/PACKET IN required */
#define IPMIP4_PKT_PKT_OUT (1 << 3) /* ARP/PACKET OUT required */
#define IPMIP4_PKT_ICMP_IN (1 << 4) /* Inbound ICMP packets */
/*
****************************************************************************
* 5 TYPES
****************************************************************************
*/
#include "ipcom_align16.h"
/*
*===========================================================================
* Ipnet_pkt_arp
*===========================================================================
*/
typedef IP_PACKED1 struct Ipmip4_pkt_arp
{
/* ARP header. */
Ip_u16 hrd; /* Format of hardware address. */
Ip_u16 pro; /* Format of protocol address. */
Ip_u16 hln_pln; /* Length of hardware and protocol address. */
Ip_u16 op; /* Code */
Ip_u8 eth_src[IPMIP_ETH_ADDR_SIZE];
Ip_u16 ip_src[2];
Ip_u8 eth_dst[IPMIP_ETH_ADDR_SIZE];
Ip_u16 ip_dst[2];
}
IP_PACKED2 Ipmip4_pkt_arp_t;
#include "ipcom_align16.h"
struct Ipmip4_pktbuf;
struct Ipmip4_context;
struct Ipmip_proc;
typedef Ip_bool (*Ipmip4_pkt_udp_cb_t)
(
Ipmip4_context_t *context,
Ipmip_proc_t *proc,
struct Ipmip4_pktbuf *pbuf,
void *arg
);
typedef Ip_bool (*Ipmip4_pkt_icmp_cb_t)
(
Ipmip4_context_t *context,
Ipmip_proc_t *proc,
struct Ipmip4_pktbuf *pbuf
);
typedef Ip_bool (*Ipmip4_pkt_packet_cb_t)
(
Ipmip4_context_t *context,
Ipmip_proc_t *proc,
struct Ipmip4_pktbuf *pbuf
);
typedef struct Ipmip4_pkt_udp_register
{
Ipcom_list next;
Ipmip4_pkt_udp_cb_t udp_callback;
Ip_fd fd;
void *opaque;
} Ipmip4_pkt_udp_register_t;
typedef struct Ipmip4_pkt_context
{
Ipcom_list udp_sockets;
struct Ipmip_proc *proc;
Ip_fd fd_raw;
Ip_fd fd_pkt;
Ip_fd fd_icmp_in;
struct Ip_sockaddr_in s_udp_in;
struct Ip_sockaddr_in s_udp_out;
Ip_u32 flags;
Ipmip4_pkt_udp_register_t udp_in;
Ipmip4_pkt_udp_register_t udp_out;
/* Callbacks */
Ipmip4_pkt_udp_cb_t udp;
Ipmip4_pkt_icmp_cb_t icmp;
Ipmip4_pkt_packet_cb_t packet;
} Ipmip4_pkt_context_t;
/*
****************************************************************************
* 6 FUNCTIONS
****************************************************************************
*/
/*******************************************************************************
*
* ipmip4_pkt_context_destroy - ipmip4_pkt_context_destroy
*
* Destroy the packet context
*
* Parameters:
* \is
* \i ctx
* The generic mobility singleton context for IPMIP4. 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 ipmip4_context_create(). See ipmip4_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 ipmip4_pkt_context_destroy
(
struct Ipmip4_context *ctx,
struct Ipmip_proc *proc
);
/*******************************************************************************
*
* ipmip4_pkt_context_create - ipmip4_pkt_context_create
*
* Create the packet context
*
* Parameters:
* \is
* \i ctx
* The generic mobility singleton context for IPMIP4. 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 ipmip4_context_create(). See ipmip4_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 flags
* Flags what packet context features we need.
* \i udp
* UDP callback
* \i icmp
* ICMP callback
* \i packet
* Packet callback
* \ie
*
* RETURNS: IP_TRUE on success.
*
* ERRNO:
*
* NOMANUAL
*/
IP_GLOBAL Ip_bool ipmip4_pkt_context_create
(
struct Ipmip4_context *ctx,
struct Ipmip_proc *proc,
Ip_u32 flags,
Ipmip4_pkt_udp_cb_t udp,
Ipmip4_pkt_icmp_cb_t icmp,
Ipmip4_pkt_packet_cb_t packet
);
/*******************************************************************************
*
* ipmip4_pkt_context_start - ipmip4_pkt_context_start
*
* Start the packet context
*
* Parameters:
* \is
* \i ctx
* The generic mobility singleton context for IPMIP4. 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 ipmip4_context_create(). See ipmip4_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: IP_TRUE on success.
*
* ERRNO:
*
* NOMANUAL
*/
IP_GLOBAL Ip_bool ipmip4_pkt_context_start
(
struct Ipmip4_context *ctx,
struct Ipmip_proc *proc
);
/*******************************************************************************
*
* ipmip4_pkt_context_stop - ipmip4_pkt_context_stop
*
* Stops the packet thread.
*
* Parameters:
* \is
* \i ctx
* The generic mobility singleton context for IPMIP4. 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 ipmip4_context_create(). See ipmip4_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 ipmip4_pkt_context_stop
(
struct Ipmip4_context *ctx,
struct Ipmip_proc *proc
);
/*******************************************************************************
*
* ipmip4_pkt_icmp_write - ipmip4_pkt_icmp_write
*
* Write an ICMP message to a link local host.
*
* Parameters:
* \is
* \i ctx
* The generic mobility singleton context for IPMIP4. 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 ipmip4_context_create(). See ipmip4_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 payload
* The payload packet
* \i from
* The source
* \i to
* The destination
* \i iff
* Outgoing interface
* \i lladdr
* Link level address
* \ie
*
* RETURNS: IP_TRUE if successful.
*
* ERRNO:
*
* NOMANUAL
*/
IP_GLOBAL Ip_bool ipmip4_pkt_icmp_write
(
struct Ipmip4_context *ctx,
struct Ipmip_proc *proc,
Ipmip_buffer_t *payload,
Ip_u32 from,
Ip_u32 to,
Ipmip4_if_t *iff,
Ipmip_lladdr_t *lladdr
);
/*******************************************************************************
*
* ipmip4_pkt_icmp_sendmsg - ipmip4_pkt_icmp_sendmsg
*
* Send an ICMP message
*
* Parameters:
* \is
* \i ctx
* The generic mobility singleton context for IPMIP4. 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 ipmip4_context_create(). See ipmip4_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 payload
* The payload packet
* \i from
* The source
* \i to
* The destination
* \i iff
* Outgoing interface
* \i ttl
* TTL
* \ie
*
* RETURNS: IP_TRUE if successful.
*
* ERRNO:
*
* NOMANUAL
*/
IP_GLOBAL Ip_bool ipmip4_pkt_icmp_sendmsg
(
struct Ipmip4_context *ctx,
struct Ipmip_proc *proc,
Ipmip_buffer_t *payload,
Ip_u32 from,
Ip_u32 to,
Ipmip4_if_t *iff,
Ip_u8 ttl
);
/*******************************************************************************
*
* ipmip4_pkt_udp_sendmsg - ipmip4_pkt_udp_sendmsg
*
* Send a UDP message to a remote host
*
* Parameters:
* \is
* \i ctx
* The generic mobility singleton context for IPMIP4. 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 ipmip4_context_create(). See ipmip4_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 payload
* The payload buffer
* \i from
* The source address
* \i from_port
* The source port in network byte order
* \i to
* The destination address
* \i to_port
* The destination port in network byte order
* \i iff
* If set; the interface to force the output on.
* \ie
*
* RETURNS: The resulting return code.
*
* ERRNO:
*
* NOMANUAL
*/
IP_GLOBAL int ipmip4_pkt_udp_sendmsg
(
struct Ipmip4_context *ctx,
struct Ipmip_proc *proc,
Ipmip_buffer_t *payload,
Ip_u32 from,
Ip_u16 from_port,
Ip_u32 to,
Ip_u16 to_port,
Ipmip4_if_t *iff
);
/*******************************************************************************
*
* ipmip4_pkt_udp_write - ipmip4_pkt_udp_write
*
* Send a UDP message to a link local host with the
* indicated MAC address.
*
* Parameters:
* \is
* \i ctx
* The generic mobility singleton context for IPMIP4. 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 ipmip4_context_create(). See ipmip4_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 payload
* The payload buffer
* \i from
* The source address
* \i from_port
* The source port in netwrok byte order
* \i to
* The destination address
* \i to_port
* The destination port in network byte order
* \i iff
* Outgoing interface
* \i lladdr
* MAC address
* \ie
*
* RETURNS: The resulting return code.
*
* ERRNO:
*
* NOMANUAL
*/
IP_GLOBAL int ipmip4_pkt_udp_write
(
struct Ipmip4_context *ctx,
struct Ipmip_proc *proc,
Ipmip_buffer_t *payload,
Ip_u32 from,
Ip_u16 from_port,
Ip_u32 to,
Ip_u16 to_port,
Ipmip4_if_t *iff,
Ipmip_lladdr_t *lladdr
);
/*******************************************************************************
*
* ipmip4_pkt_arp_write - ipmip4_pkt_arp_write
*
* Send an ARP message to specific destination
*
* Parameters:
* \is
* \i ctx
* The generic mobility singleton context for IPMIP4. 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 ipmip4_context_create(). See ipmip4_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 from
* From IP address
* \i to
* To IP address
* \i iff
* Outgoing interface
* \i lladdr
* LLA destination
* \ie
*
* RETURNS: No return value
*
* ERRNO:
*
* NOMANUAL
*/
IP_GLOBAL void ipmip4_pkt_arp_write
(
struct Ipmip4_context *ctx,
struct Ipmip_proc *proc,
Ip_u32 from,
Ip_u32 to,
Ipmip4_if_t *iff,
Ipmip_lladdr_t *lladdr
);
/*******************************************************************************
*
* ipmip4_pkt_icmp_echo_request - ipmip4_pkt_icmp_echo_request
*
* Send an echo request message
*
* Parameters:
* \is
* \i ctx
* The generic mobility singleton context for IPMIP4. 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 ipmip4_context_create(). See ipmip4_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 from
* Source IP
* \i to
* Destination IP
* \i iff
* Outgoing interface
* \ie
*
* RETURNS: IP_TRUE if successful.
*
* ERRNO:
*
* NOMANUAL
*/
IP_GLOBAL Ip_bool ipmip4_pkt_icmp_echo_request
(
struct Ipmip4_context *ctx,
struct Ipmip_proc *proc,
Ip_u32 from,
Ip_u32 to,
Ipmip4_if_t *iff
);
/*******************************************************************************
*
* ipmip4_pkt_icmp_join - ipmip4_pkt_icmp_join
*
* Join a specific multicast group
*
* Parameters:
* \is
* \i ctx
* The generic mobility singleton context for IPMIP4. 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 ipmip4_context_create(). See ipmip4_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 group
* The group
* \i ifindex
* The ifindex
* \ie
*
* RETURNS: IP_TRUE on success
*
* ERRNO:
*
* NOMANUAL
*/
IP_GLOBAL Ip_bool ipmip4_pkt_icmp_join
(
struct Ipmip4_context *ctx,
struct Ipmip_proc *proc,
Ip_u32 group,
Ip_u32 ifindex
);
/*******************************************************************************
*
* ipmip4_pkt_udp_register - ipmip4_pkt_udp_register
*
* Register a UDP socket to the packet loop. Packets received on these
* sockets will be fed through the provided callback.
*
* Parameters:
* \is
* \i ctx
* The generic mobility singleton context for IPMIP4. 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 ipmip4_context_create(). See ipmip4_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 udpr
* UDP registration structure.
* \ie
*
* RETURNS:
*
* ERRNO:
*
*/
IP_GLOBAL void ipmip4_pkt_udp_register
(
struct Ipmip4_context *ctx,
struct Ipmip_proc *proc,
Ipmip4_pkt_udp_register_t *udpr
);
/*******************************************************************************
*
* ipmip4_pkt_udp_unregister - ipmip4_pkt_udp_unregister
*
* Unregister a UDP socket from the packet loop.
*
* Parameters:
* \is
* \i ctx
* The generic mobility singleton context for IPMIP4. 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 ipmip4_context_create(). See ipmip4_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 udpr
* UDP registration structure.
* \ie
*
* RETURNS:
*
* ERRNO:
*
*/
IP_GLOBAL void ipmip4_pkt_udp_unregister
(
struct Ipmip4_context *ctx,
struct Ipmip_proc *proc,
Ipmip4_pkt_udp_register_t *udpr
);
#ifdef __cplusplus
}
#endif
#endif
/*
****************************************************************************
* END OF FILE
****************************************************************************
*/