371 lines
14 KiB
C
371 lines
14 KiB
C
|
|
/*
|
|
******************************************************************************
|
|
* INTERPEAK SOURCE FILE
|
|
*
|
|
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipmip6pm_link_address.c,v $ $Revision: 1.9 $
|
|
* $Source: /home/interpeak/CVSRoot/ipmip6pm/config/ipmip6pm_link_address.c,v $
|
|
* $Author: jhorteli $
|
|
* $State: Exp $ $Locker: $
|
|
*
|
|
* INTERPEAK_COPYRIGHT_STRING
|
|
* Design and implementation by Joel Hortelius <joel.hortelis@interpeak.se>
|
|
******************************************************************************
|
|
*/
|
|
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 1 DESCRIPTION
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 2 CONFIGURATION
|
|
****************************************************************************
|
|
*/
|
|
|
|
#include "ipmip6pm_config.h"
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 3 INCLUDE FILES
|
|
****************************************************************************
|
|
*/
|
|
#define IPCOM_USE_CLIB_PROTO
|
|
#include <ipcom_clib.h>
|
|
#include <ipcom_os.h>
|
|
#include <ipcom_sock.h>
|
|
#include <ipcom_sock6.h>
|
|
#include <ipcom_inet.h>
|
|
#include <ipcom_list.h>
|
|
#include <ipcom_hash.h>
|
|
#include <ipcom_err.h>
|
|
#include <ipcom_sysvar.h>
|
|
#include <ipcom_syslog.h>
|
|
#include <ipcom_shell.h>
|
|
#include <ipcom_route.h>
|
|
|
|
#include <ipnet.h>
|
|
#include <ipnet_policy_routing.h>
|
|
|
|
#include <ipmip.h>
|
|
#include <private/ipmip_util.h>
|
|
#include <private/ipmip_sysvar.h>
|
|
|
|
#include <ipmip6.h>
|
|
#include <private/ipmip6_context.h>
|
|
#include <private/ipmip6_netlink.h>
|
|
#include <private/ipmip6_if.h>
|
|
#include <private/ipmip6_icmp.h>
|
|
#include <private/ipmip6_util.h>
|
|
|
|
#include "ipmip6pm_h.h"
|
|
#include "ipmip6pm_attr_h.h"
|
|
#include "ipmip6pm_if.h"
|
|
#include "ipmip6pm_node.h"
|
|
#include "ipmip6pm_pktbuf.h"
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 4 DEFINES
|
|
****************************************************************************
|
|
*/
|
|
#define IPMIP6PM_LINK_ADDRESS_NAME "LINK-ADDRESS"
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 5 TYPES
|
|
****************************************************************************
|
|
*/
|
|
typedef struct Ipmip6pm_link_address_config_global
|
|
{
|
|
Ipmip_lladdr_t *FixedMAGLinkLayerAddressOnAllAccessLinks;
|
|
} Ipmip6pm_link_address_config_global_t;
|
|
|
|
typedef struct Ipmip6pm_link_address_config
|
|
{
|
|
Ipmip_lladdr_t *FixedMAGLinkLayerAddressOnAllAccessLinks;
|
|
} Ipmip6pm_link_address_config_t;
|
|
|
|
typedef struct Ipmip6pm_link_address_node_config
|
|
{
|
|
Ipmip_lladdr_t *LinkLayerAddress;
|
|
} Ipmip6pm_link_address_node_config_t;
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 6 EXTERN PROTOTYPES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 7 LOCAL PROTOTYPES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 8 DATA
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 9 STATIC FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
|
|
IP_STATIC void
|
|
ipmip6pm_link_address_config_global(struct Ipmip6pm_context *ctx,
|
|
struct Ipmip_proc *proc,
|
|
int action,
|
|
Ipmip6pm_link_address_config_global_t *gcfg,
|
|
Ipmip_cli_message_t *request)
|
|
{
|
|
IPMIP_UNUSED_PARAMETER(ctx);
|
|
IPMIP_UNUSED_PARAMETER(proc);
|
|
|
|
if (action == IPMIP_CALLBACK_CONFIG_READ)
|
|
{
|
|
char *dptr;
|
|
|
|
dptr = ipmip_sysvar("ipmip6pm.FixedMAGLinkLayerAddressOnAllAccessLinks");
|
|
|
|
/**/
|
|
if (dptr != IP_NULL)
|
|
{
|
|
gcfg->FixedMAGLinkLayerAddressOnAllAccessLinks = ipmip_lladdr_parse(proc, 0, 0, dptr);
|
|
/**/
|
|
ipcom_free(dptr);
|
|
}
|
|
}
|
|
else if (action == IPMIP_CALLBACK_CONFIG_FREE)
|
|
{
|
|
/* Do nothing */
|
|
if (gcfg->FixedMAGLinkLayerAddressOnAllAccessLinks)
|
|
{
|
|
ipcom_free(gcfg->FixedMAGLinkLayerAddressOnAllAccessLinks);
|
|
gcfg->FixedMAGLinkLayerAddressOnAllAccessLinks = IP_NULL;
|
|
}
|
|
}
|
|
else if (action == IPMIP_CALLBACK_CONFIG_DUMP)
|
|
{
|
|
if (gcfg->FixedMAGLinkLayerAddressOnAllAccessLinks)
|
|
{
|
|
ipmip_cli_config_printf(&request->message,
|
|
"ipmip6pm.FixedMAGLinkLayerAddressOnAllAccessLinks=%s",
|
|
ipmip_ntop_lladdr(proc, gcfg->FixedMAGLinkLayerAddressOnAllAccessLinks));
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
IP_STATIC void
|
|
ipmip6pm_link_address_config(struct Ipmip6pm_context *ctx,
|
|
struct Ipmip_proc *proc,
|
|
int action,
|
|
struct Ipmip6pm_if *ifp,
|
|
Ipmip6pm_link_address_config_global_t *gcfg,
|
|
Ipmip6pm_link_address_config_t *cfg,
|
|
Ipmip_cli_message_t *request)
|
|
{
|
|
IPMIP_UNUSED_PARAMETER(ctx);
|
|
IPMIP_UNUSED_PARAMETER(proc);
|
|
|
|
if (action == IPMIP_CALLBACK_CONFIG_READ)
|
|
{
|
|
char *dptr;
|
|
|
|
dptr = ipmip_sysvar("ipmip6pm.interface.%s.FixedMAGLinkLayerAddressOnAllAccessLinks", ifp->ipmip6.iff.ifname);
|
|
|
|
/**/
|
|
if (dptr != IP_NULL)
|
|
{
|
|
cfg->FixedMAGLinkLayerAddressOnAllAccessLinks = ipmip_lladdr_parse(proc, 0, 0, dptr);
|
|
/**/
|
|
ipcom_free(dptr);
|
|
}
|
|
else if (gcfg->FixedMAGLinkLayerAddressOnAllAccessLinks)
|
|
{
|
|
cfg->FixedMAGLinkLayerAddressOnAllAccessLinks = ipmip_lladdr_dup(gcfg->FixedMAGLinkLayerAddressOnAllAccessLinks);
|
|
}
|
|
}
|
|
else if (action == IPMIP_CALLBACK_CONFIG_FREE)
|
|
{
|
|
/* Do nothing */
|
|
if (cfg->FixedMAGLinkLayerAddressOnAllAccessLinks)
|
|
{
|
|
ipcom_free(cfg->FixedMAGLinkLayerAddressOnAllAccessLinks);
|
|
cfg->FixedMAGLinkLayerAddressOnAllAccessLinks = IP_NULL;
|
|
}
|
|
}
|
|
else if (action == IPMIP_CALLBACK_CONFIG_DUMP)
|
|
{
|
|
if (cfg->FixedMAGLinkLayerAddressOnAllAccessLinks)
|
|
{
|
|
ipmip_cli_config_printf(&request->message,
|
|
"ipmip6pm.interface.%s.FixedMAGLinkLayerAddressOnAllAccessLinks=%s",
|
|
ifp->ipmip6.iff.ifname, ipmip_ntop_lladdr(proc, cfg->FixedMAGLinkLayerAddressOnAllAccessLinks));
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
IP_STATIC int
|
|
ipmip6pm_link_address_provide(struct Ipmip6pm_context *ctx,
|
|
struct Ipmip_proc *proc,
|
|
int action,
|
|
Ipmip6pm_link_address_config_global_t *gcfg,
|
|
Ipmip6pm_link_address_config_t *ifcfg,
|
|
Ipmip6pm_link_address_node_config_t *nodecfg,
|
|
struct Ipmip6pm_node *node,
|
|
struct Ipmip_timer *service)
|
|
{
|
|
IPMIP_UNUSED_PARAMETER(service);
|
|
IPMIP_UNUSED_PARAMETER(gcfg);
|
|
|
|
if (action == IPMIP_CALLBACK_ENABLE)
|
|
{
|
|
int ret;
|
|
Ipmip_lladdr_t *lla = nodecfg->LinkLayerAddress? nodecfg->LinkLayerAddress : ifcfg->FixedMAGLinkLayerAddressOnAllAccessLinks;
|
|
|
|
/* Must stop interface for assignment */
|
|
#if 0
|
|
ipmip_if_clear_flags(&ctx->ipmip6.ipmip, proc, &node->ifp_private.ipmip6.ifp->iff, IP_IFF_UP);
|
|
#endif
|
|
|
|
/* Assign LLADDR */
|
|
if ((ret = ipmip_netlink_link(&ctx->ipmip6.ipmip,
|
|
proc,
|
|
IP_RTM_SETLINK,
|
|
node->ifp_private.ipmip6.ifp->iff.ifindex,
|
|
0,
|
|
0,
|
|
IPMIP_LLADDR_DATA(lla),
|
|
IPMIP_LLADDR_LEN_LLA(lla),
|
|
0)) != 0)
|
|
{
|
|
/* Do something */
|
|
IPMIP6_EVENT_IF(INFO, proc,
|
|
ipmip_log_event_add(&ctx->ipmip6.ipmip,
|
|
proc,
|
|
"Proxy Mobile node %s interface %s unable to assign Link-Layer address (%d)",
|
|
ipmip6pm_node_describe(proc, node),
|
|
node->ifp_private.ipmip6.ifp->iff.ifname,
|
|
-ret));
|
|
|
|
}
|
|
|
|
#if 0
|
|
ipmip_if_set_flags(&ctx->ipmip6.ipmip, proc, &node->ifp_private.ipmip6.ifp->iff, IP_IFF_UP);
|
|
#endif
|
|
/* Re-resolve LLA */
|
|
ipmip_timer_lock_acquire(&ctx->ipmip6.ipmip, proc, node->ifp_private.ipmip6.ifp->iff_lock);
|
|
ipmip_if_resolve_lla(&ctx->ipmip6.ipmip, proc, &node->ifp_private.ipmip6.ifp->iff);
|
|
ipmip_timer_lock_release(&ctx->ipmip6.ipmip, proc, node->ifp_private.ipmip6.ifp->iff_lock);
|
|
}
|
|
else if (action == IPMIP_CALLBACK_DISABLE)
|
|
{
|
|
}
|
|
|
|
/* Don't delay */
|
|
return IPMIP_CALLBACK_RET_SUCCESS;
|
|
}
|
|
|
|
IP_STATIC Ip_bool
|
|
ipmip6pm_link_address_setup(struct Ipmip6pm_context *ctx,
|
|
struct Ipmip_proc *proc,
|
|
int action,
|
|
Ipmip6pm_link_address_config_global_t *gcfg,
|
|
Ipmip6pm_link_address_config_t *ifcfg,
|
|
Ipmip6pm_link_address_node_config_t *nodecfg,
|
|
struct Ipmip6pm_node *node,
|
|
const char *value,
|
|
Ipmip_cli_message_t *request)
|
|
{
|
|
IPMIP_UNUSED_PARAMETER(ctx);
|
|
IPMIP_UNUSED_PARAMETER(proc);
|
|
IPMIP_UNUSED_PARAMETER(node);
|
|
IPMIP_UNUSED_PARAMETER(gcfg);
|
|
|
|
if (action == IPMIP_CALLBACK_CONFIG_READ)
|
|
{
|
|
/* Turned off in configuration */
|
|
if (value == IP_NULL)
|
|
return ifcfg->FixedMAGLinkLayerAddressOnAllAccessLinks != IP_NULL;
|
|
|
|
if (nodecfg->LinkLayerAddress)
|
|
ipcom_free(nodecfg->LinkLayerAddress);
|
|
nodecfg->LinkLayerAddress = ipmip_lladdr_parse(proc, 0, 0, value);
|
|
return nodecfg->LinkLayerAddress != IP_NULL;
|
|
}
|
|
else if (action == IPMIP_CALLBACK_CONFIG_FREE)
|
|
{
|
|
if (nodecfg->LinkLayerAddress)
|
|
{
|
|
ipcom_free(nodecfg->LinkLayerAddress);
|
|
nodecfg->LinkLayerAddress = IP_NULL;
|
|
}
|
|
}
|
|
else if (action == IPMIP_CALLBACK_CONFIG_DUMP)
|
|
{
|
|
if (nodecfg->LinkLayerAddress)
|
|
{
|
|
Ip_size_t rta = ipmip_attr_begin(&request->message, IPMIP6PM_CLI_ATTR_BC_P_LINK);
|
|
|
|
ipmip_attr_put_str(&request->message,
|
|
IPMIP6PM_CLI_ATTR_BC_P_SRV_MODULE,
|
|
IPMIP6PM_LINK_ADDRESS_NAME);
|
|
|
|
ipmip_attr_put_str(&request->message,
|
|
IPMIP6PM_CLI_ATTR_BC_P_SRV_VALUE,
|
|
ipmip_ntop_lladdr(proc, nodecfg->LinkLayerAddress));
|
|
ipmip_attr_end(&request->message, rta);
|
|
}
|
|
}
|
|
|
|
return IP_FALSE;
|
|
}
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 10 GLOBAL FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
|
|
IP_GLOBAL void ipmip6pm_link_address_install(struct Ipmip6pm_context *ctx);
|
|
IP_GLOBAL void
|
|
ipmip6pm_link_address_install(struct Ipmip6pm_context *ctx)
|
|
{
|
|
static Ipmip6pm_extension_t srv;
|
|
|
|
srv.name = IPMIP6PM_LINK_ADDRESS_NAME;
|
|
srv.syntax = "<MAC ADDRESS>";
|
|
srv.node_data_size = sizeof(Ipmip6pm_link_address_node_config_t);
|
|
srv.ifp_data_size = sizeof(Ipmip6pm_link_address_config_t);
|
|
srv.global_data_size= sizeof(Ipmip6pm_link_address_config_global_t);
|
|
|
|
srv.config_global = (Ipmip6pm_extension_config_global_t)ipmip6pm_link_address_config_global;
|
|
srv.config_ifp = (Ipmip6pm_extension_config_ifp_t)ipmip6pm_link_address_config;
|
|
srv.provide = (Ipmip6pm_extension_provide_t)ipmip6pm_link_address_provide;
|
|
srv.setup = (Ipmip6pm_extension_setup_t)ipmip6pm_link_address_setup;
|
|
|
|
ipmip6pm_context_register_extension(ctx, &srv, IPMIP6PM_FUNCTION_LINK);
|
|
}
|
|
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 11 PUBLIC FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* END OF FILE
|
|
****************************************************************************
|
|
*/
|