245 lines
7.6 KiB
C
245 lines
7.6 KiB
C
/* ipdiameter_routing.h - Diameter routing defining head file */
|
|
|
|
/*
|
|
* Copyright (c) 2007 Wind River Systems, Inc.
|
|
*
|
|
* The right to copy, distribute or otherwise make use of this software
|
|
* may be licensed only pursuant to the terms of an applicable Wind River
|
|
* license agreement. No license to Wind River intellectual property rights
|
|
* is granted herein. All rights not licensed by Wind River are reserved
|
|
* by Wind River.
|
|
*/
|
|
|
|
/*
|
|
modification history
|
|
--------------------
|
|
01h,25mar08,ggz Additional buffer IPDIAMETER_ADDITIONAL_BUFFER for result AVP
|
|
01g,03mar08,ggz Added next hop server to pending packet structure for rerouting
|
|
01f,17apr08,tlu Add compile condition to call ipcom mutex utilities directly
|
|
for VxWorks, and call recursive semaphore for Linux
|
|
01e,31jan08,ggz Added recursive locks for routing and policy enforcment
|
|
01d,26jan08,ggz Moved public header function declarations from c file into header file
|
|
01c,24jan08,tlu Added policy structure
|
|
01b,18jan08,ggz Added prototype ipdiameter_proxy_process_protocol_errors
|
|
01a,16july07,cwu Created.
|
|
*/
|
|
|
|
#ifndef IPDIAMETER_ROUTING_H
|
|
#define IPDIAMETER_ROUTING_H
|
|
|
|
|
|
/*
|
|
****************************************************************************
|
|
* INCLUDE FILES
|
|
****************************************************************************
|
|
*/
|
|
#include "ipdiameter_constant.h"
|
|
#include "ipdiameter_peer.h"
|
|
#include "ipdiameter.h"
|
|
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
|
|
/*
|
|
**************************************************************************
|
|
* DEFINES
|
|
*************************************************************************
|
|
*/
|
|
#define IPDIAMETER_ENABLE_REENTRANT
|
|
#ifdef IPDIAMETER_ENABLE_REENTRANT
|
|
|
|
#ifdef IP_PORT_VXWORKS
|
|
#define IPDIAMETER_ROUTE_LOCK(route) ipcom_mutex_lock(route->code_mutex)
|
|
#define IPDIAMETER_ROUTE_UNLOCK(route) ipcom_mutex_unlock(route->code_mutex)
|
|
#define IPDIAMETER_POLICY_LOCK(policy) ipcom_mutex_lock(policy->code_mutex)
|
|
#define IPDIAMETER_POLICY_UNLOCK(policy) ipcom_mutex_unlock(policy->code_mutex)
|
|
#else /* !IP_PORT_VXWORKS, Linux recursive semaphore */
|
|
#define IPDIAMETER_ROUTE_LOCK(route) ipdiameter_route_lck(route)
|
|
#define IPDIAMETER_ROUTE_UNLOCK(route) ipdiameter_route_unlck(route)
|
|
#define IPDIAMETER_POLICY_LOCK(policy) ipdiameter_policy_lck(policy)
|
|
#define IPDIAMETER_POLICY_UNLOCK(policy) ipdiameter_policy_unlck(policy)
|
|
#endif /* IP_PORT_VXWORKS */
|
|
|
|
#else
|
|
#define IPDIAMETER_ROUTE_LOCK(route) IP_NOOP
|
|
#define IPDIAMETER_ROUTE_UNLOCK(route) IP_NOOP
|
|
#define IPDIAMETER_POLICY_LOCK(policy) IP_NOOP
|
|
#define IPDIAMETER_POLICY_UNLOCK(policy) IP_NOOP
|
|
#endif
|
|
|
|
/* Used to allocated additional memory for adding a Result Code. */
|
|
#define IPDIAMETER_ADDITIONAL_BUFFER 15
|
|
|
|
/* Ipdiameter_route_action types: 'action_type' */
|
|
typedef enum
|
|
{
|
|
DIAMETER_LOCAL = 1,
|
|
DIAMETER_RELAY,
|
|
DIAMETER_PROXY,
|
|
DIAMETER_REDIRECT
|
|
}Ipdiameter_route_action_type;
|
|
|
|
typedef struct Ipdiameter_route_server_struct
|
|
{
|
|
/* server-id */
|
|
Ipcom_list server_list;
|
|
|
|
/* Peer IP address */
|
|
union Ip_sockaddr_union peer_addr;
|
|
|
|
/* server-id */
|
|
char server_id[IPDIAMETER_MAX_FQDN_SIZE];
|
|
|
|
/* metric */
|
|
Ip_u32 metric;
|
|
} Ipdiameter_route_server;
|
|
|
|
typedef struct Ipdiameter_agent_pending_packet_struct
|
|
{
|
|
|
|
/* original hop_to_hop id */
|
|
Ip_u32 original_hbh_id;
|
|
Ip_u32 new_hbh_id;
|
|
|
|
/*original peer information */
|
|
Ipdiameter_peer_entry *original_peer;
|
|
Ipdiameter_peer_entry *new_peer;
|
|
|
|
/* added proxy-informaiton AVP */
|
|
Ip_u8 proxy_state;
|
|
|
|
/* original request packet length */
|
|
Ip_u32 pkt_length;
|
|
char next_hope_server[IPDIAMETER_MAX_FQDN_SIZE];
|
|
} Ipdiameter_agent_pending_packet_entry;
|
|
|
|
/******************************************************************************
|
|
* Diameter route entry definition
|
|
* refer to RFC 3588, section 2.7
|
|
*****************************************************************************
|
|
*/
|
|
typedef struct Ipdiameter_route_struct
|
|
{
|
|
Ipcom_list route_list;
|
|
|
|
/* realm id */
|
|
char realm_id[IPDIAMETER_MAX_FQDN_SIZE];
|
|
|
|
/* application id */
|
|
Ip_u32 application_id;
|
|
|
|
/* vendor_id. If application id is standard , this is always set to 0 */
|
|
Ip_u32 vendor_id;
|
|
|
|
/* local action type for this route entry, RFC 2.7 */
|
|
Ipdiameter_route_action_type action_type;
|
|
|
|
/* server list */
|
|
Ipcom_list server_head;
|
|
/* server_num, the current size of server list */
|
|
Ip_u32 server_num;
|
|
|
|
/* route type, static route or dynamic route */
|
|
Ip_bool dynamic;
|
|
|
|
/* if this is a dynamic route, it will expire after expiration_time seconds */
|
|
Ip_time_t expiration_time;
|
|
|
|
#ifdef IPDIAMETER_ENABLE_REENTRANT
|
|
Ipcom_mutex code_mutex; /* Mutex to protect IPDIAMETER route data. */
|
|
#endif
|
|
|
|
/* the process that currently holds the semaphore and taken counter */
|
|
Ip_pid_t pid;
|
|
Ip_u8 s_counter;
|
|
|
|
} Ipdiameter_route_entry;
|
|
|
|
|
|
typedef struct Ipdiameter_policy_entry_struct
|
|
{
|
|
Ipcom_list policy_list;
|
|
|
|
Ip_bool have_uname;
|
|
union {
|
|
/* user name */
|
|
char username[IPDIAMETER_MAX_FQDN_SIZE];
|
|
|
|
/* host id */
|
|
char hostid[IPDIAMETER_MAX_FQDN_SIZE];
|
|
} name;
|
|
#ifdef IPDIAMETER_ENABLE_REENTRANT
|
|
Ipcom_mutex code_mutex; /* Mutex to protect IPDIAMETER policy data. */
|
|
#endif
|
|
|
|
/* the process that currently holds the semaphore and taken counter */
|
|
Ip_pid_t pid;
|
|
Ip_u8 s_counter;
|
|
|
|
} Ipdiameter_policy_entry;
|
|
|
|
|
|
IP_PUBLIC Ipdiameter_route_entry
|
|
*ipdiameter_find_route(Ipdiameter_route_entry *route);
|
|
|
|
IP_PUBLIC Ipdiameter_route_entry
|
|
*ipdiameter_create_route(Ipdiameter_route_entry *route, char *server);
|
|
|
|
IP_PUBLIC Ip_bool
|
|
ipdiameter_delete_route(Ipdiameter_route_entry *route, char *server);
|
|
|
|
IP_PUBLIC Ip_bool
|
|
ipdiameter_del_route(Ipdiameter_route_entry *route);
|
|
|
|
IP_PUBLIC Ipdiameter_policy_entry
|
|
*ipdiameter_find_policy(Ip_bool username, char *name);
|
|
|
|
IP_PUBLIC Ip_err
|
|
ipdiameter_create_policy(Ipdiameter_policy_entry *policy);
|
|
|
|
IP_PUBLIC Ip_err
|
|
ipdiameter_delete_policy(Ipdiameter_policy_entry *policy);
|
|
|
|
|
|
IP_PUBLIC Ip_bool ipdiameter_proxy_process_protocol_errors(struct Ipdiameter_header *packet,
|
|
Ipdiameter_peer_entry *peer, Ip_u32 error_type);
|
|
|
|
IP_PUBLIC Ip_bool ipdiameter_proxy_process_received_protocol_errors (struct Ipdiameter_header *packet,
|
|
struct Ipdiameter_request_entry *reqent,
|
|
Ipdiameter_peer_entry *peer);
|
|
|
|
IP_PUBLIC Ip_bool ipdiameter_proxy_process_permanent_errors(struct Ipdiameter_header *packet,
|
|
Ipdiameter_peer_entry *peer, Ip_u32 error_type);
|
|
|
|
IP_PUBLIC Ipdiameter_route_entry *ipdiameter_find_default_route(void);
|
|
|
|
IP_PUBLIC void ipdiameter_route_lck(Ipdiameter_route_entry *route);
|
|
|
|
IP_PUBLIC void ipdiameter_route_unlck(Ipdiameter_route_entry *route);
|
|
|
|
IP_PUBLIC void ipdiameter_policy_lck(Ipdiameter_policy_entry *policy);
|
|
|
|
IP_PUBLIC void ipdiameter_policy_unlck(Ipdiameter_policy_entry *policy);
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* #ifndef IPDIAMETER_ROUTING_H */
|
|
|
|
/*
|
|
****************************************************************************
|
|
* END OF FILE
|
|
****************************************************************************
|
|
*/
|
|
|