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

481 lines
10 KiB
C

/* ipmip_lladdr.h - ipmip_lladdr.h */
/*
******************************************************************************
* HEADER FILE
*
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipmip_lladdr.h,v $ $Revision: 1.15 $
* $Source: /home/interpeak/CVSRoot/ipmip/include/private/ipmip_lladdr.h,v $
* $Author: jhorteli $ $Date: 2011-01-21 15:31:28 $
* $State: Exp $ $Locker: $
*
* INTERPEAK_COPYRIGHT_STRING
* Design and implementation by Joel Hortelius <joel.hortelius@interpeak.se>
******************************************************************************
*/
#ifndef IPMIP_LLADDR_H
#define IPMIP_LLADDR_H
/*
****************************************************************************
* 1 DESCRIPTION
****************************************************************************
*/
/*
DESCRIPTION
Utility library for managing link-layer addresses. These methods compare,
create and convert link layer addresses for use by the MIP system. This library
MUST be a superset of the other link-layer address definitions provided by
MIP6, MIP4 and IPNET.
EXAMPLE
This example describes how to create a LLADDR.
.CS
Ipmip_lladdr_t *create_lladdr(void)
{
char *mac = { 0x1, 0x1, 0x1, 0x1, 0x1, 0x1 };
/@ Dynamically allocate an ethernet type LLADDR with the MAC set to all 1's @/
Ipmip_lladdr_t *lla = ipmip_lladdr_build(IP_NULL,
IPMIP_LLADDR_TYPE_MAC,
IPMIP_LLADDR_SUBTYPE_MAC_802_3,
mac,
6);
return lla;
}
.CE
*/
/*
****************************************************************************
* 2 CONFIGURATION
****************************************************************************
*/
/*
****************************************************************************
* 3 INCLUDE FILES
****************************************************************************
*/
#ifdef __cplusplus
extern "C" {
#endif
/*
****************************************************************************
* 4 DEFINES
****************************************************************************
*/
enum
{
IPMIP_LLADDR_TYPE_NONE,
IPMIP_LLADDR_TYPE_MAC,
IPMIP_LLADDR_TYPE_EUID64,
IPMIP_LLADDR_TYPE_MEID,
IPMIP_LLADDR_TYPE_ESN,
IPMIP_LLADDR_TYPE_IMEI,
IPMIP_LLADDR_TYPE_INET,
IPMIP_LLADDR_TYPE_INET6,
IPMIP_LL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E_TUNNEL_GRE6,
IPMIP_LLADDR_SUBTYPE_TUNNEL_6TO4,
IPMIP_LLADDR_SUBTYPE_TUNNEL_6OVER4,
IPMIP_LLADDR_SUBTYPE_TUNNEL_MAX
};
/*
****************************************************************************
* 5 TYPES
****************************************************************************
*/
typedef struct Ipmip_lladdr
{
Ip_u8 type;
Ip_u8 subtype;
Ip_u8 len;
Ip_u8 lla[1];
}
Ipmip_lladdr_t;
#define IPMIP_LLADDR_LEN(lladdr) (((Ipmip_lladdr_t *)(lladdr))->len)
#define IPMIP_LLADDR_LEN_LLA(lladdr) (IPMIP_LLADDR_LEN(lladdr) - 3)
#define IPMIP_LLADDR_LEN_TOTAL(llalen) ((llalen) + 3)
#define IPMIP_LLADDR_DATA(lladdr) ((void*)(&((Ipmip_lladdr_t *)(lladdr))->lla[0]))
enum
{
IPMIP_LLADDR_FORMAT_NONE,
IPMIP_LLADDR_FORMAT_HEX,
IPMIP_LLADDR_FORMAT_INET,
IPMIP_LLADDR_FORMAT_U32,
IPMIP_LLADDR_FORMAT_DEC_DIGIT,
IPMIP_LLADDR_FORMAT_HEX_DIGIT,
IPMIP_LLADDR_FORMAT_INET6
};
struct Ipmip_proc;
typedef struct Ipmip_lladdr_parse
{
const char *pre;
Ip_u8 pre_len;
Ip_u8 type;
Ip_u8 subtype;
Ip_u8 format;
} Ipmip_lladdr_parse_t;
typedef struct Ipmip_lladdr_typedef
{
const char *name;
Ip_u8 size;
Ip_u8 format;
Ip_size_t max_subtypes;
const char **subtypes;
} Ipmip_lladdr_typedef_t;
/*
****************************************************************************
* 6 FUNCTIONS
****************************************************************************
*/
extern Ipmip_lladdr_parse_t ipmip_lladdr_parse_defs[];
extern Ipmip_lladdr_typedef_t ipmip_lladdr_type_defs[];
extern const char *ipmip_lladdr_mac_subtypes[];
extern const char *ipmip_lladdr_tunnel_subtypes[];
extern const char *ipmip_lladdr_inet_subtypes[];
extern const char *ipmip_lladdr_3gpp2_subtypes[];
extern const char *ipmip_lladdr_3gpp_subtypes[];
/*******************************************************************************
*
* ipmip_lladdr_build - ipmip_lladdr_build
*
* Initialize a LLA extension based on the provided parameters
*
* Parameters:
* \is
* \i lla_ext
* The extension; must be large enough
* \i type
* The type.
* \i type
* The subtype.
* \i lla
* The link layer address
* \i lla_len
* The link layer address length
* \ie
*
* RETURNS: No return value
*
* ERRNO:
*
*/
IP_GLOBAL Ipmip_lladdr_t *ipmip_lladdr_build
(
Ipmip_lladdr_t *lla_ext,
Ip_u8 type,
Ip_u8 subtype,
void *lla,
int lla_len
);
/*******************************************************************************
*
* ipmip_lladdr_cmp - ipmip_lladdr_cmp
*
* Compares two LLA's
*
* Parameters:
* \is
* \i lla1
* The first lla
* \i lla2
* The second lla
* \ie
*
* RETURNS: IP_TRUE if they're identical.
*
* ERRNO:
*
*/
IP_GLOBAL Ip_bool ipmip_lladdr_cmp
(
Ipmip_lladdr_t *lla1,
Ipmip_lladdr_t *lla2
);
/*******************************************************************************
*
* ipmip_lladdr_dup - ipmip_lladdr_dup
*
* Duplicate a LLA
*
* Parameters:
* \is
* \i lla
* The lla to duplicate
* \ie
*
* RETURNS: A pointer to the new LLA
*
* ERRNO:
*
*/
IP_GLOBAL Ipmip_lladdr_t * ipmip_lladdr_dup
(
Ipmip_lladdr_t *lla
);
/*******************************************************************************
*
* ipmip_lladdr_arphdr_to_lltype - ipmip_lladdr_arphdr_to_lltype
*
* Convert an ARPHRD_* type to LLADDR
*
* Parameters:
* \is
* \i type
* The type to convert
* \i ll_type
* The resolved LLADDR type
* \i ll_subtype
* The resolved LLADDR subtype
* \ie
*
* RETURNS: IP_TRUE on success
*
* ERRNO:
*
*/
IP_GLOBAL Ip_bool ipmip_lladdr_arphdr_to_lltype
(
Ip_u16 type,
Ip_u8 *ll_type,
Ip_u8 *ll_subtype
);
/*******************************************************************************
*
* ipmip_lladdr_ift_to_lltype - ipmip_lladdr_ift_to_lltype
*
* Convert an IFT_* type to LLADDR
*
* Parameters:
* \is
* \i type
* The type to convert
* \i ll_type
* The resolved LLADDR type
* \i ll_subtype
* The resolved LLADDR subtype
* \ie
*
* RETURNS: IP_TRUE on success
*
* ERRNO:
*
*/
IP_GLOBAL Ip_bool ipmip_lladdr_ift_to_lltype
(
Ip_u16 type,
Ip_u8 *ll_type,
Ip_u8 *ll_subtype
);
/*******************************************************************************
*
* ipmip_lladdr_dl_to_lladdr - ipmip_lladdr_dl_to_lladdr
*
* Create a LLADDR based on DL and if
*
* Parameters:
* \is
* \i dl
* The link-layer address
* \i ifindex
* The ifindex
* \ie
*
* RETURNS: A pointer to the new LLA
*
* ERRNO:
*
*/
IP_GLOBAL Ipmip_lladdr_t * ipmip_lladdr_dl_to_lladdr
(
struct Ip_sockaddr_dl *dl,
Ip_u32 ifindex
);
/*******************************************************************************
*
* ipmip_lladdr_ll_to_lladdr - ipmip_lladdr_ll_to_lladdr
*
* Create a LLADDR based on LL and if
*
* Parameters:
* \is
* \i ll
* The link-layer address
* \ie
*
* RETURNS: A pointer to the new LLA
*
* ERRNO:
*
*/
IP_GLOBAL Ipmip_lladdr_t * ipmip_lladdr_ll_to_lladdr
(
struct Ip_sockaddr_ll *ll
);
/*******************************************************************************
*
* ipmip_lladdr_sanitize - ipmip_lladdr_sanitize
*
* Sanitize a LLADDR based on the interface's LLADDR
*
* Parameters:
* \is
* \i iflla
* The interface LLADDR
* \i lla
* The LLADDR to sanitize
* \ie
*
* RETURNS: A pointer to the LLA
*
* ERRNO:
*
* NOMANUAL
*/
IP_GLOBAL Ipmip_lladdr_t *ipmip_lladdr_sanitize
(
Ipmip_lladdr_t *iflla,
Ipmip_lladdr_t *lla
);
/*******************************************************************************
*
* ipmip_lladdr_parse - ipmip_lladdr_parse
*
* Create a LLADDR based on a textual string
*
* Parameters:
* \is
* \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 type_hint
* A hint regarding the LL type
* \i subtype_hint
* A hint regarding the LL subtype
* \i llstr
* The textual string
* \ie
*
* RETURNS: A pointer to the new LLA
*
* ERRNO:
*
* NOMANUAL
*/
IP_GLOBAL Ipmip_lladdr_t * ipmip_lladdr_parse
(
struct Ipmip_proc *proc,
Ip_u8 type_hint,
Ip_u8 subtype_hint,
const char *llstr
);
#ifdef __cplusplus
}
#endif
#endif
/*
****************************************************************************
* END OF FILE
****************************************************************************
*/