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

815 lines
24 KiB
C

/* ipmip_dhcp6.h - ipmip_dhcp6.h */
/*
******************************************************************************
* HEADER FILE
*
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipmip_dhcp6.h,v $ $Revision: 1.7 $
* $Source: /home/interpeak/CVSRoot/ipmip/include/private/ipmip_dhcp6.h,v $
* $Author: jhorteli $ $Date: 2010-12-07 09:55:01 $
* $State: Exp $ $Locker: $
*
* INTERPEAK_COPYRIGHT_STRING
* Design and implementation by Joel Hortelius <joel.hortelius@interpeak.se>
******************************************************************************
*/
#ifndef IPMIP_DHCP6_H
#define IPMIP_DHCP6_H
/*
****************************************************************************
* 1 DESCRIPTION
****************************************************************************
*/
/*
DESCRIPTION
DHCP6 proxy and server implementation used to integrate DHCP6 with various
MIP DHCP6 requirements. DHCP6 in primarily used with Proxy Mobility. This
module allows for a MIP entity to send, receive and process DHCP6 messages
from proxies, clients and servers.
EXAMPLE
This example provides a basic DHCP relay functionality example.
.CS
static int my_mip_dhcpv6_relay(int event,
struct Ipmip_my_context *ctx,
Ipmip_proc_t *proc,
Ipmip_dhcp6_node_t *relay,
Ipmip_pktbuf_t *pbuf)
{
/@ Properly invoked? @/
if (event == IPMIP_TIMER_EVENT_RUN)
{
Ipmip_dhcp6_hdr_t *pkt = (Ipmip_dhcp6_hdr_t *)IPMIP_BUFFER_PTR(&pbuf->packet);
Ipmip_dhcp6_relay_hdr_t *rpkt = (Ipmip_dhcp6_relay_hdr_t *)IPMIP_BUFFER_PTR(&pbuf->packet);
Ip_u8 hc = 0;
switch (pkt->msg_type)
{
case IPMIP_DHCP6_MSG_RELAY_REPLY:
{
Ipmip_dhcp6_option_hdr_t *rmsg = ipmip_dhcp6_option_buffer_find(&pbuf->.packet, IPMIP_DHCP6_OPTION_RELAY_MSG);
if (rmsg == IP_NULL)
goto done_out;
/@ Do forward @/
ipmip_dhcp6_send_msg(&ctx->ipmip, proc, rmsg + 1, IP_GET_NTOHS(&rmsg->length), &rpkt->peer_addr, relay->ifindex);
}
break;
case IPMIP_DHCP6_MSG_RELAY_FORWARD:
hc = rpkt->hop_count;
/@ Fall Through @/
default:
{
Ipmip_pktbuf_t *rpbuf = (Ipmip_pktbuf_t *)ipmip_dhcp6_relay_msg(&ctx->ipmip, proc, IP_NULL, hc, pbuf);
if (rpbuf)
{
ipmip_dhcp6_send_msg(&ctx->ipmip6.ipmip, proc, IPMIP_BUFFER_DATA(&rpbuf->packet), IPMIP_BUFFER_SIZE(&rpbuf->packet), &ctx->my_dhcp6_server_address, relay->ifindex);
ipmip_pktbuf_release(&ctx->ipmip6.ipmip, proc, rpbuf);
}
}
break;
}
}
done_out:
ipmip_pktbuf_release(&ctx->ipmip6.ipmip, proc, &pbuf->ipmip6.ipmip);
return IPMIP_TIMER_RET_DONE;
}
void my_init_func(struct Ipmip_my_context *ctx, Ipmip_proc_t *proc, int ifindex, struct Ip_in6_addr *server_addr)
{
/@ Create the DHCP context - Can be done during context initialization,
or later for example depending on configuration @/
/@ This context will create the required UDP sockets for retrieving and
sending DHCP6 datagrams @/
ipmip_dhcp6_context_create(&ctx->ipmip, proc);
/@ Setup the DHCP callback structure, specify the interface we
are interested in receiving replies from and what callback to be invoked @/
cfg->my_dhcp6.ifindex = ifindex;
cfg->my_dhcp6.lock = ctx->my_lock;
cfg->my_dhcp6.process_func = (Ipmip_timer_func_t)my_mip_dhcpv6_relay;
cfg->my_dhcp6_server_address = *server_addr;
/@ Register the DHCP callback function @/
ipmip_dhcp6_register(&ctx->ipmip, proc, &ctx->my_dhcp6);
}
.CE
*/
/*
****************************************************************************
* 2 CONFIGURATION
****************************************************************************
*/
/*
****************************************************************************
* 3 INCLUDE FILES
****************************************************************************
*/
#include <private/ipmip_context.h>
#include <private/ipmip_timer.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef IPMIP_USE_INET6
/*
****************************************************************************
* 4 DEFINES
****************************************************************************
*/
#define IPMIP_DHCP6_MSG_SOLICIT 1
#define IPMIP_DHCP6_MSG_ADVERTISE 2
#define IPMIP_DHCP6_MSG_REQUEST 3
#define IPMIP_DHCP6_MSG_CONFIRM 4
#define IPMIP_DHCP6_MSG_RENEW 5
#define IPMIP_DHCP6_MSG_REBIND 6
#define IPMIP_DHCP6_MSG_REPLY 7
#define IPMIP_DHCP6_MSG_RELEASE 8
#define IPMIP_DHCP6_MSG_DECLINE 9
#define IPMIP_DHCP6_MSG_RECONFIGURE 10
#define IPMIP_DHCP6_MSG_INFORMATION_REQUEST 11
#define IPMIP_DHCP6_MSG_RELAY_FORWARD 12
#define IPMIP_DHCP6_MSG_RELAY_REPLY 13
#define IPMIP_DHCP6_OPTION_CLIENTID 1
#define IPMIP_DHCP6_OPTION_SERVERID 2
#define IPMIP_DHCP6_OPTION_IA_NA 3
#define IPMIP_DHCP6_OPTION_IA_TA 4
#define IPMIP_DHCP6_OPTION_IAADDR 5
#define IPMIP_DHCP6_OPTION_ORO 6
#define IPMIP_DHCP6_OPTION_PREFERENCE 7
#define IPMIP_DHCP6_OPTION_ELAPSED_TIME 8
#define IPMIP_DHCP6_OPTION_RELAY_MSG 9
#define IPMIP_DHCP6_OPTION_AUTH 11
#define IPMIP_DHCP6_OPTION_UNICAST 12
#define IPMIP_DHCP6_OPTION_STATUS_CODE 13
#define IPMIP_DHCP6_OPTION_RAPID_COMMIT 14
#define IPMIP_DHCP6_OPTION_USER_CLASS 15
#define IPMIP_DHCP6_OPTION_VENDOR_CLASS 16
#define IPMIP_DHCP6_OPTION_VENDOR_OPTS 17
#define IPMIP_DHCP6_OPTION_INTERFACE_ID 18
#define IPMIP_DHCP6_OPTION_RECONF_MSG 19
#define IPMIP_DHCP6_OPTION_RECONF_ACCEPT 20
#define IPMIP_DHCP6_OPTION_DNS_SERVERS 23
#define IPMIP_DHCP6_OPTION_DOMAIN_LIST 24
#define IPMIP_DHCP6_OPTION_IA_PD 25
#define IPMIP_DHCP6_OPTION_IAPREFIX 26
#define IPMIP_DHCP6_OPTION_SNTP_SERVERS 31
#define IPMIP_DHCP6_OPTION_INFORMATION_REFRESH_TIME 32
/*
****************************************************************************
* 5 TYPES
****************************************************************************
*/
struct Ipmip_pktbuf;
struct Ipmip_context;
struct Ipmip_proc;
struct Ipmip_buffer;
#include <ipcom_align16.h>
typedef struct IP_PACKED1 Ipmip_dhcp6_hdr
{
Ip_u8 msg_type;
Ip_u8 tid[3];
} IP_PACKED2
Ipmip_dhcp6_hdr_t;
typedef struct IP_PACKED1 Ipmip_dhcp6_option_hdr
{
Ip_u16 code;
Ip_u16 length;
} IP_PACKED2
Ipmip_dhcp6_option_hdr_t;
typedef IP_PACKED1 struct Ipmip_dhcp6_relay_hdr
{
Ip_u8 msg_type;
Ip_u8 hop_count;
struct Ip_in6_addr link_addr;
struct Ip_in6_addr peer_addr;
}
IP_PACKED2 Ipmip_dhcp6_relay_hdr_t;
#include <ipcom_align16.h>
typedef struct Ipmip_dhcp6_node
{
/* HASH parameters */
Ip_u32 ifindex;
Ipmip_timer_lock_t *lock;
Ipmip_timer_func_t process_func;
void *opaque;
} Ipmip_dhcp6_node_t;
typedef struct Ipmip_dhcp6_context
{
/**/
Ipcom_mutex mutex;
Ip_fd fd_udp;
Ipcom_hash *ifindex_table;
} Ipmip_dhcp6_context_t;
typedef struct Ipmip_dhcp6_embedded_server
{
/**/
Ip_u32 refcount;
struct Ipmip_proc *proc;
} Ipmip_dhcp6_embedded_server_t;
extern struct Ip_in6_addr ipmip_dhcp6_all_dhcp_relay_agents_and_servers;
extern struct Ip_in6_addr ipmip_dhcp6_all_dhcp_servers;
/*
****************************************************************************
* 6 FUNCTIONS
****************************************************************************
*/
/*******************************************************************************
*
* ipmip_dhcp6_context_create - ipmip_dhcp6_context_create
*
* Allocate the DHCP6 context
*
* 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_dhcp6_context_create
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc
);
/*******************************************************************************
*
* ipmip_dhcp6_context_destroy - ipmip_dhcp6_context_destroy
*
* Free an DHCP6 context
*
* 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_dhcp6_context_destroy
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc
);
/*******************************************************************************
*
* ipmip_dhcp6_process - ipmip_dhcp6_process
*
* Process DHCP6 messages. This method is invoked internally from the
* the packet loops. Unless you are certain of what you are doing, you should
* not invoke this method yourself.
*
* 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_dhcp6_process
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc
);
/*******************************************************************************
*
* ipmip_dhcp6_relay_msg - ipmip_dhcp6_relay_msg
*
* Create a DHCP6 relay message based on a 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 link_addr
* Link address
* \i hop count
* Current hop count
* \i req
* Request to relay
* \ie
*
* RETURNS: The relay message
*
* ERRNO:
*
*/
IP_GLOBAL struct Ipmip_pktbuf *ipmip_dhcp6_relay_msg
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc,
struct Ip_in6_addr *link_addr,
Ip_u8 hop_count,
struct Ipmip_pktbuf *req
);
/*******************************************************************************
*
* ipmip_dhcp6_send_msg - ipmip_dhcp6_send_msg
*
* Forward a DHCP6 message
*
* 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 msg
* Message
* \i size
* Size of message
* \i dst
* Destination
* \i ifscope
* Interface
* \ie
*
* RETURNS: IPCOM_SUCCESS on success, < 0 on error.
*
* ERRNO:
*
*/
IP_GLOBAL int ipmip_dhcp6_send_msg
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc,
void *msg,
Ip_size_t size,
struct Ip_in6_addr *dst,
Ip_u32 ifscope
);
/*******************************************************************************
*
* ipmip_dhcp6_add_option - ipmip_dhcp6_add_option
*
* Add a DHCP6 option to a buffer
*
* Parameters:
* \is
* \i dhcp
* DHCP buffer
* \i code
* DHCP code
* \i length
* Length of option (data)
* \i data
* Data
* \ie
*
* RETURNS: No return value
*
* ERRNO:
*
*/
IP_GLOBAL void ipmip_dhcp6_add_option
(
struct Ipmip_buffer *dhcp,
Ip_u16 code,
Ip_u16 length,
void *data
);
/*******************************************************************************
*
* ipmip_dhcp6_option_next - ipmip_dhcp6_option_next
*
* Get next DHCP6 option
*
* Parameters:
* \is
* \i hdr
* Last header
* \i optstart
* DHCP options start
* \i optsize
* The size of DHCP options
* \ie
*
* RETURNS: DHCP6 option if found, IP_NULL otherwise
*
* ERRNO:
*
*/
IP_GLOBAL Ipmip_dhcp6_option_hdr_t *ipmip_dhcp6_option_next
(
Ipmip_dhcp6_option_hdr_t *hdr,
Ip_u8 *optstart,
int optsize
);
/*******************************************************************************
*
* ipmip_dhcp6_option_first - ipmip_dhcp6_option_first
*
* Get first DHCP6 option
*
* Parameters:
* \is
* \i options
* DHCP options
* \i optsize
* The size of DHCP options
* \ie
*
* RETURNS: DHCP6 option if found, IP_NULL otherwise
*
* ERRNO:
*
*/
IP_GLOBAL Ipmip_dhcp6_option_hdr_t *ipmip_dhcp6_option_first
(
Ip_u8 *options,
int optsize
);
/*******************************************************************************
*
* ipmip_dhcp6_option_find - ipmip_dhcp6_option_find
*
* Find a specific DHCP6 option
*
* Parameters:
* \is
* \i options
* DHCP options
* \i optsize
* The size of DHCP options
* \i code
* The code of the DHCP option
* \ie
*
* RETURNS: DHCP6 option if found, IP_NULL otherwise
*
* ERRNO:
*
*/
IP_GLOBAL Ipmip_dhcp6_option_hdr_t *ipmip_dhcp6_option_find
(
Ip_u8 *options,
int optsize,
Ip_u16 code
);
/*******************************************************************************
*
* ipmip_dhcp6_option_buffer_find - ipmip_dhcp6_option_buffer_find
*
* Find a specific DHCP6 option
*
* Parameters:
* \is
* \i dhcp
* DHCP packet
* \i code
* The code of the DHCP option
* \ie
*
* RETURNS: DHCP6 option if found, IP_NULL otherwise
*
* ERRNO:
*
*/
IP_GLOBAL Ipmip_dhcp6_option_hdr_t *ipmip_dhcp6_option_buffer_find
(
struct Ipmip_buffer *dhcp,
Ip_u16 code
);
/*******************************************************************************
*
* ipmip_dhcp6_option_buffer_first - ipmip_dhcp6_option_buffer_first
*
* Return the first DHCP6 option
*
* Parameters:
* \is
* \i dhcp
* DHCP packet
* \ie
*
* RETURNS: DHCP6 option if found, IP_NULL otherwise
*
* ERRNO:
*
*/
IP_GLOBAL Ipmip_dhcp6_option_hdr_t *ipmip_dhcp6_option_buffer_first
(
struct Ipmip_buffer *dhcp
);
/*******************************************************************************
*
* ipmip_dhcp6_option_buffer_next - ipmip_dhcp6_option_buffer_next
*
* Return the next DHCP6 option
*
* Parameters:
* \is
* \i hdr
* Last DHCP option
* \i dhcp
* DHCP packet
* \ie
*
* RETURNS: DHCP6 option if found, IP_NULL otherwise
*
* ERRNO:
*
*/
IP_GLOBAL Ipmip_dhcp6_option_hdr_t *ipmip_dhcp6_option_buffer_next
(
Ipmip_dhcp6_option_hdr_t *hdr,
struct Ipmip_buffer *dhcp
);
/*******************************************************************************
*
* ipmip_dhcp6_register - ipmip_dhcp6_register
*
* Register a forwarding 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_dhcp6_register
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc,
Ipmip_dhcp6_node_t *node
);
/*******************************************************************************
*
* ipmip_dhcp6_unregister - ipmip_dhcp6_unregister
*
* Unregister a forwarding 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_dhcp6_unregister
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc,
Ipmip_dhcp6_node_t *node
);
/*******************************************************************************
*
* ipmip_dhcp6_embedded_server_init - ipmip_dhcp6_embedded_server_init
*
* Initialize the embedded server
*
* 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_dhcp6_embedded_server_init
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc
);
/*******************************************************************************
*
* ipmip_dhcp6_embedded_server_start - ipmip_dhcp6_embedded_server_start
*
* Start the embedded server
*
* 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 ifname
* Interface to use for duid init
* \ie
*
* RETURNS: No return value
*
* ERRNO:
*
*/
IP_GLOBAL void ipmip_dhcp6_embedded_server_start
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc,
const char *ifname
);
/*******************************************************************************
*
* ipmip_dhcp6_embedded_server_stop - ipmip_dhcp6_embedded_server_stop
*
* Stop the embedded server
*
* 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_dhcp6_embedded_server_stop
(
struct Ipmip_context *ctx,
struct Ipmip_proc *proc
);
#endif
#ifdef __cplusplus
}
#endif
#endif
/*
****************************************************************************
* END OF FILE
****************************************************************************
*/