Files
m241Neelima/components/ip_net2-6.9/ipmip6pm/config/ipmip6pm_service_selection.c
2026-07-30 11:19:44 +05:30

333 lines
12 KiB
C

/*
******************************************************************************
* INTERPEAK SOURCE FILE
*
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipmip6pm_service_selection.c,v $ $Revision: 1.8 $
* $Source: /home/interpeak/CVSRoot/ipmip6pm/config/ipmip6pm_service_selection.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 <private/ipmip6_sysext.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_SERVICE_SELECTION_NAME "SERVICE-SELECTION"
/*
****************************************************************************
* 5 TYPES
****************************************************************************
*/
typedef struct Ipmip6pm_service_selection_config_global
{
Ipmip6_mh_mo_service_selection_mobility_option_t *selection;
} Ipmip6pm_service_selection_config_global_t;
typedef struct Ipmip6pm_service_selection_config
{
Ipmip6_mh_mo_service_selection_mobility_option_t *selection;
} Ipmip6pm_service_selection_config_t;
typedef struct Ipmip6pm_service_selection_node_config
{
Ipmip6_mh_mo_service_selection_mobility_option_t *selection;
} Ipmip6pm_service_selection_node_config_t;
/*
****************************************************************************
* 6 EXTERN PROTOTYPES
****************************************************************************
*/
/*
****************************************************************************
* 7 LOCAL PROTOTYPES
****************************************************************************
*/
/*
****************************************************************************
* 8 DATA
****************************************************************************
*/
/*
****************************************************************************
* 9 STATIC FUNCTIONS
****************************************************************************
*/
IP_STATIC void
ipmip6pm_service_selection_request_rep_apply(struct Ipmip6pm_context *ctx,
struct Ipmip_proc *proc,
Ipmip6pm_service_selection_config_global_t *gcfg,
Ipmip6pm_service_selection_config_t *ifcfg,
Ipmip6pm_service_selection_node_config_t *nodecfg,
struct Ipmip6pm_node *node,
struct Ipmip6pm_pktbuf *pbuf)
{
IPMIP_UNUSED_PARAMETER(node);
IPMIP_UNUSED_PARAMETER(gcfg);
IPMIP_UNUSED_PARAMETER(ifcfg);
/**/
if (node->mip6MnBLTable.mip6MnBLAccepted == IP_FALSE)
{
if (nodecfg->selection != IP_NULL)
{
IPMIP6_EVENT_IF(INFO, proc,
ipmip_log_event_add(&ctx->ipmip6.ipmip,
proc,
"%s requesting service selection '%s'",
ipmip6pm_node_describe(proc, node),
(char *)&nodecfg->selection->identifier[0]));
ipmip6_mh_pkt_opt_add_mo(&ctx->ipmip6,
proc,
&pbuf->ipmip6,
&nodecfg->selection->hdr);
}
}
}
IP_STATIC void
ipmip6pm_service_selection_config_global(struct Ipmip6pm_context *ctx,
struct Ipmip_proc *proc,
int action,
Ipmip6pm_service_selection_config_global_t *gcfg,
Ipmip_cli_message_t *request)
{
IPMIP_UNUSED_PARAMETER(ctx);
IPMIP_UNUSED_PARAMETER(proc);
if (action == IPMIP_CALLBACK_CONFIG_READ)
{
gcfg->selection = ipmip6_sysext_service_selection("ipmip6pm.service_selection");
}
else if (action == IPMIP_CALLBACK_CONFIG_FREE)
{
/* Do nothing */
}
else if (action == IPMIP_CALLBACK_CONFIG_DUMP)
{
if (gcfg->selection)
{
ipmip_cli_config_printf(&request->message,
"ipmip6pm.service_selection=%s",
&gcfg->selection->identifier[0]);
}
}
}
IP_STATIC void
ipmip6pm_service_selection_config(struct Ipmip6pm_context *ctx,
struct Ipmip_proc *proc,
int action,
struct Ipmip6pm_if *ifp,
Ipmip6pm_service_selection_config_global_t *gcfg,
Ipmip6pm_service_selection_config_t *cfg,
Ipmip_cli_message_t *request)
{
IPMIP_UNUSED_PARAMETER(ctx);
IPMIP_UNUSED_PARAMETER(proc);
IPMIP_UNUSED_PARAMETER(gcfg);
if (action == IPMIP_CALLBACK_CONFIG_READ)
{
/* Read the prefix list allowed for this interface */
cfg->selection = ipmip6_sysext_service_selection("ipmip6pm.interface.%s.service_selection", ifp->ipmip6.iff.ifname);
}
else if (action == IPMIP_CALLBACK_CONFIG_FREE)
{
/* Do nothing */
}
else if (action == IPMIP_CALLBACK_CONFIG_DUMP)
{
if (cfg->selection != IP_NULL)
{
ipmip_cli_config_printf(&request->message,
"ipmip6pm.interface.%s.service_selection=%s",
ifp->ipmip6.iff.ifname, &cfg->selection->identifier[0]);
}
}
}
IP_STATIC void
ipmip6pm_service_selection_free(Ipmip6pm_service_selection_config_global_t *gcfg,
Ipmip6pm_service_selection_config_t *ifcfg,
Ipmip6pm_service_selection_node_config_t *nodecfg)
{
/* Do Nothing */
if (nodecfg->selection != IP_NULL)
{
if (nodecfg->selection != ifcfg->selection && nodecfg->selection != gcfg->selection)
ipcom_free(nodecfg->selection);
nodecfg->selection = IP_NULL;
}
}
IP_STATIC Ip_bool
ipmip6pm_service_selection_setup(struct Ipmip6pm_context *ctx,
struct Ipmip_proc *proc,
int action,
Ipmip6pm_service_selection_config_global_t *gcfg,
Ipmip6pm_service_selection_config_t *ifcfg,
Ipmip6pm_service_selection_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)
{
/* Dont allow more than one */
ipmip6pm_service_selection_free(gcfg, ifcfg, nodecfg);
if (value == IP_NULL)
{
/* No explicit identifier */
if (ifcfg->selection != IP_NULL)
nodecfg->selection = ifcfg->selection;
else if (gcfg->selection != IP_NULL)
nodecfg->selection = gcfg->selection;
}
else
{
nodecfg->selection = ipmip6_util_mo_service_selection(value);
}
return nodecfg->selection != IP_NULL;
}
else if (action == IPMIP_CALLBACK_CONFIG_FREE)
{
/* Do Nothing */
ipmip6pm_service_selection_free(gcfg, ifcfg, nodecfg);
}
else if (action == IPMIP_CALLBACK_CONFIG_DUMP)
{
if (nodecfg->selection != IP_NULL)
{
Ip_size_t rta = ipmip_attr_begin(&request->message, IPMIP6PM_CLI_ATTR_BC_P_SERVICE);
ipmip_attr_put_str(&request->message,
IPMIP6PM_CLI_ATTR_BC_P_SRV_MODULE,
IPMIP6PM_SERVICE_SELECTION_NAME);
ipmip_attr_put_str(&request->message,
IPMIP6PM_CLI_ATTR_BC_P_SRV_VALUE,
(char *)&nodecfg->selection->identifier[0]);
ipmip_attr_end(&request->message, rta);
}
}
return IP_FALSE;
}
/*
****************************************************************************
* 10 GLOBAL FUNCTIONS
****************************************************************************
*/
IP_GLOBAL void ipmip6pm_service_selection_install(struct Ipmip6pm_context *ctx);
IP_GLOBAL void
ipmip6pm_service_selection_install(struct Ipmip6pm_context *ctx)
{
static Ipmip6pm_extension_t srv;
srv.name = IPMIP6PM_SERVICE_SELECTION_NAME;
srv.syntax = "<service selection string>";
srv.node_data_size = sizeof(Ipmip6pm_service_selection_node_config_t);
srv.ifp_data_size = sizeof(Ipmip6pm_service_selection_config_t);
srv.global_data_size= sizeof(Ipmip6pm_service_selection_config_global_t);
srv.config_global = (Ipmip6pm_extension_config_global_t)ipmip6pm_service_selection_config_global;
srv.config_ifp = (Ipmip6pm_extension_config_ifp_t)ipmip6pm_service_selection_config;
srv.setup = (Ipmip6pm_extension_setup_t)ipmip6pm_service_selection_setup;
srv.pkt_req_apply = (Ipmip6pm_extension_pkt_req_apply_t)ipmip6pm_service_selection_request_rep_apply;
ipmip6pm_context_register_extension(ctx, &srv, IPMIP6PM_FUNCTION_SERVICE);
}
/*
****************************************************************************
* 11 PUBLIC FUNCTIONS
****************************************************************************
*/
/*
****************************************************************************
* END OF FILE
****************************************************************************
*/