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

718 lines
21 KiB
C

/* ipmip_inet.h - ipmip_inet.h */
/*
******************************************************************************
* HEADER FILE
*
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipmip_inet.h,v $ $Revision: 1.9.10.1 $
* $Source: /home/interpeak/CVSRoot/ipmip/include/private/ipmip_inet.h,v $
* $Author: svc-cmnet $ $Date: 2013-03-13 07:45:30 $
* $State: Exp $ $Locker: $
*
* INTERPEAK_COPYRIGHT_STRING
* Design and implementation by Joel Hortelius <joel.hortelius@interpeak.se>
******************************************************************************
*/
#ifndef IPMIP_INET_H
#define IPMIP_INET_H
/*
****************************************************************************
* 1 DESCRIPTION
****************************************************************************
*/
/*
DESCRIPTION
INET address domain specific utility functions and routines. This module
provides routines for sending/writing link layer packet frames, IP frames,
UDP frames and ARP messages.It also provides an ARP proxy for MIP entities
that are required to proxy ARP for various INET addresses such as Proxy MIP
entities, Home Agents in the INET domain, and NEMO solutions.
EXAMPLE
This is a disruptive example that simply proxy ARP answers any incoming
ARP requests.
.CS
static int my_arp_reply(int event,
struct Ipmip_my_context *ctx,
Ipmip_proc_t *proc,
Ipmip_arp_node_t *arp,
Ipmip_pktbuf_t *pbuf)
{
/@ Were we correctly invoked @/
if (event == IPMIP_TIMER_EVENT_RUN)
{
Ipmip_arp_hdr_t *pkt = (Ipmip_arp_hdr_t *)IPMIP_BUFFER_PTR(&pbuf->packet);
struct Ipmip_my_iff *iff = arp->opaque;
if (pkt->op == IPMIP_ARP_OP_REQUEST)
ipmip_inet_arp_reply(&ctx->ipmip, proc, pkt, &iff->ipmip);
}
ipmip_pktbuf_release(&ctx->ipmip6.ipmip, proc, &pbuf->ipmip6.ipmip);
return IPMIP_TIMER_RET_DONE;
}
void my_init_function(struct Ipmip_my_context *ctx, Ipmip_proc_t *proc, struct Ipmip_my_iff *iff)
{
static Ipmip_arp_node_t node;
ipmip_inet_arp_context_in_create(&ctx->ipmip, proc);
ipmip_inet_arp_context_out_create(&ctx->ipmip, proc);
ipcom_memset(&node, 0, sizeof(node));
arp.ifindex = iff->ipmip.ifindex;
arp.lock = ctx->my_lock;
arp.opaque = iff;
arp.process_func = (Ipmip_timer_func_t)my_arp_reply;
ipmip_inet_arp_register(&ctx->ipmip, proc, &arp);
}
.CE
*/
/*
****************************************************************************
* 2 CONFIGURATION
****************************************************************************
*/
/*
****************************************************************************
* 3 INCLUDE FILES
****************************************************************************
*/
#include <ipcom_hash.h>
#include <private/ipmip_timer.h>
#include <private/ipmip_lladdr.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef IPMIP_USE_INET
/*
****************************************************************************
* 4 DEFINES
****************************************************************************
*/
/* ARP pkt header values: */
#define IPMIP_ARP_HRD_ETHER ip_htons(0x0001)
#define IPMIP_ARP_PRO_IP ip_htons(IPMIP_ETH_P_IP)
#define IPMIP_ARP_HLN_PLN ip_htons(0x0604)
#define IPMIP_ARP_OP_REQUEST ip_htons(0x0001)
#define IPMIP_ARP_OP_REPLY ip_htons(0x0002)
/*
****************************************************************************
* 5 TYPES
****************************************************************************
*/
struct Ipmip_context;
struct Ipmip_proc;
struct Ipmip_pktbuf;
struct Ipmip_lladdr;
struct Ipmip_if;
struct Ipmip_buffer;
typedef struct Ipmip_arp_node
{
/* HASH parameters */
Ip_u32 ifindex;
Ip_u32 src;
Ipmip_timer_lock_t *lock;
Ipmip_timer_func_t process_func;
void *opaque;
} Ipmip_arp_node_t;
typedef struct Ipmip_arp_context
{
/**/
Ipcom_mutex mutex;
Ip_fd fd_arp_in;
Ip_fd fd_arp_out;
Ipcom_hash *ifindex_table;
} Ipmip_arp_context_t;
#include "ipcom_align16.h"
typedef IP_PACKED1 struct Ipmip_arp_hdr
{
/* 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 Ipmip_arp_hdr_t;
#include "ipcom_align16.h"
/*
****************************************************************************
* 6 FUNCTIONS
****************************************************************************
*/
/*******************************************************************************
*
* ipmip_inet_arp_context_in_create - ipmip_inet_arp_context_in_create
*
* Allocate the ARP receive context; this context is required in order to
* receive ARP requests.
*
* 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:
*
*/
IP_GLOBAL void ipmip_inet_arp_context_in_create
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc
);
/*******************************************************************************
*
* ipmip_inet_arp_context_out_create - ipmip_inet_arp_context_out_create
*
* Allocate the ARP send context. This context is required in order to
* send ARP requests.
*
* 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:
*
*/
IP_GLOBAL void ipmip_inet_arp_context_out_create
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc
);
/*******************************************************************************
*
* ipmip_inet_arp_context_destroy - ipmip_inet_arp_context_destroy
*
* Free an ARP context. Free the in/out ARP contexts.
*
* 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:
*
*/
IP_GLOBAL void ipmip_inet_arp_context_destroy
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc
);
/*******************************************************************************
*
* ipmip_inet_udp_recvmsg - ipmip_inet_udp_recvmsg
*
* Receive an INET UDP message from an IP_IPPROTO_UDP socket. This method
* will also resolve link layer address, packet information (receiving address,
* interface) and TTL.
*
* 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 vlen
* Buffer size
* \i fd
* File descriptor
* \ie
*
* RETURNS: The packet buffer on success
*
* ERRNO:
*
*/
IP_GLOBAL struct Ipmip_pktbuf *ipmip_inet_udp_recvmsg
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc,
Ip_size_t vlen,
Ip_fd fd
);
/*******************************************************************************
*
* ipmip_inet_udp_write - ipmip_inet_udp_write
*
* Write an INET UDP message. This method will write the UDP frame directly
* with IP and link layer header out onto the interface specificied
* in the request.
*
* 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 fd_pkt
* AF_PACKET socket to use if required
* \i fd_raw
* SOCK_RAW socket to use if required
* \i payload
* UDP Payload
* \i from
* IP source address
* \i from_port
* UDP source port
* \i to
* IP destination address
* \i to_port
* UDP destination port
* \i iff
* Interface
* \i lladdr
* Destination LLADDR
* \ie
*
* RETURNS:
*
* ERRNO:
*
*/
IP_GLOBAL int ipmip_inet_udp_write
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc,
Ip_fd fd_pkt,
Ip_fd fd_raw,
struct Ipmip_buffer *payload,
Ip_u32 from,
Ip_u16 from_port,
Ip_u32 to,
Ip_u16 to_port,
struct Ipmip_if *iff,
struct Ipmip_lladdr *lladdr
);
/*******************************************************************************
*
* ipmip_inet_udp_socket - ipmip_inet_udp_socket
*
* Allocate an INET UDP socket with the required ancillary data
* parameters set.
*
* Parameters:
* \is
* \i s_in
* Optional bind information
* \ie
*
* RETURNS: The new socket or IP_INVALID_SOCKET on failure.
*
* ERRNO:
*
*/
IP_GLOBAL Ip_fd ipmip_inet_udp_socket
(
struct Ip_sockaddr_in *s_in
);
/*******************************************************************************
*
* ipmip_inet_udp_sendmsg - ipmip_inet_udp_sendmsg
*
* Send an INET UDP message. The message will be provided with an IP header
* and sent using the provided raw socket. If an interface is provided,
* the frame will be forcibly sent through 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 fd_raw
* SOCK_RAW socket to use
* \i payload
* UDP Payload
* \i from
* IP source address
* \i from_port
* UDP source port
* \i to
* IP destination address
* \i to_port
* UDP destination port
* \i iff
* Interface to send frame on.
* \ie
*
* RETURNS:
*
* ERRNO:
*
*/
IP_GLOBAL int ipmip_inet_udp_sendmsg
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc,
Ip_fd fd_raw,
struct Ipmip_buffer *payload,
Ip_u32 from,
Ip_u16 from_port,
Ip_u32 to,
Ip_u16 to_port,
struct Ipmip_if *iff
);
/*******************************************************************************
*
* ipmip_inet_arp_process - ipmip_inet_arp_process
*
* Used internally by IPMIP4 and IPMIP6 packet contexts.
* Process ARP messages
*
* 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:
*
*/
IP_GLOBAL void ipmip_inet_arp_process
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc
);
/*******************************************************************************
*
* ipmip_inet_arp_write - ipmip_inet_arp_write
*
* Write an ARP REPLY message to a specified link address on the specified
* interface.
*
* 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 from
* Source IP
* \i to
* Dest IP
* \i iff
* Interface
* \i lladdr
* Link local address
* \ie
*
* RETURNS: No return value
*
* ERRNO:
*
*/
IP_GLOBAL void ipmip_inet_arp_write
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc,
Ip_u32 from,
Ip_u32 to,
struct Ipmip_if *iff,
Ipmip_lladdr_t *lladdr
);
/*******************************************************************************
*
* ipmip_inet_arp_reply - ipmip_inet_arp_reply
*
* Reply to an ARP REQUEST. Will extract the required information from the
* request frame and invoke ipmip_inet_arp_write.
*
* 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 arp_req
* Arp request
* \i iff
* Interface
* \ie
*
* RETURNS: No return value
*
* ERRNO:
*
*/
IP_GLOBAL void ipmip_inet_arp_reply
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc,
Ipmip_arp_hdr_t *arp_req,
struct Ipmip_if *iff
);
/*******************************************************************************
*
* ipmip_inet_arp_register - ipmip_inet_arp_register
*
* Register an ARP structure. ARP frames destined for the address specified
* in the ARP node will be fed to the callback specified in the node.
*
* 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 node
* Node to register
* \ie
*
* RETURNS: No return value
*
* ERRNO:
*
*/
IP_GLOBAL void ipmip_inet_arp_register
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc,
Ipmip_arp_node_t *node
);
/*******************************************************************************
*
* ipmip_inet_arp_unregister - ipmip_inet_arp_unregister
*
* Unregister an ARP structure
*
* 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 node
* Node to register
* \ie
*
* RETURNS: No return value
*
* ERRNO:
*
*/
IP_GLOBAL void ipmip_inet_arp_unregister
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc,
Ipmip_arp_node_t *node
);
/*******************************************************************************
*
* ipmip_inet_arp_proxy - ipmip_inet_arp_proxy
*
* Install or Delete a static proxy arp entry
*
* 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 ifindex
* Interface index
* \i address
* The address to proxy for
* \i set
* IP_TRUE if set, IP_FALSE if delete
* \ie
*
* RETURNS: IP_TRUE on success
*
* ERRNO:
*
*/
IP_GLOBAL Ip_bool ipmip_inet_arp_proxy
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc,
Ip_u32 ifindex,
Ip_u32 address,
Ip_bool set
);
#endif
#ifdef __cplusplus
}
#endif
#endif
/*
****************************************************************************
* END OF FILE
****************************************************************************
*/