Files
m241Neelima/components/ip_net2-6.9/iprip/include/iprip.h
T
2026-07-30 11:19:44 +05:30

599 lines
24 KiB
C

/*
******************************************************************************
* HEADER FILE
*
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: iprip.h,v $ $Revision: 1.20.48.1 $
* $Source: /home/interpeak/CVSRoot/iprip/include/iprip.h,v $
* $Author: csun $ $Date: 2014-07-08 07:15:26 $
* $State: Exp $ $Locker: $
*
* INTERPEAK_COPYRIGHT_STRING
* Design and implementation by Lennart Bang <lob@interpeak.se>
******************************************************************************
*/
#ifndef IPRIP_H
#define IPRIP_H
/*
****************************************************************************
* 1 DESCRIPTION
****************************************************************************
* Interpeak Routing Information Protocol - IPRIP
* -----------------------------------------------
* RTOS and TCP/IP stack portable implementation of Routing Information
* Protocol RIPv1/v2 including MIB support and authentication.
*
* Compliant with the following RFCs:
* RFC 1058 RIP version 1
* RFC 2453(STD56) RIP Version 2 (obsoletes RFC 1723 and RFC 1388).
* RFC 1724 RIP version 2 MIB Extension (obsoletes RFC 1389).
*
* In addition, RIPv2 MD5 authentication compliant with GateDaemon MD5 style.
*
*/
/*
****************************************************************************
* 2 CONFIGURATION
****************************************************************************
*/
/*
****************************************************************************
* 3 INCLUDE FILES
****************************************************************************
*/
#include <ipcom_type.h>
#include <ipcom_list.h>
#include <ipcom_sock.h>
#include <ipcom_inet.h>
#include <ipcom_tags.h>
#include <ipcom_route.h>
#ifdef __cplusplus
extern "C" {
#endif
/*
****************************************************************************
* 4 DEFINES
****************************************************************************
*/
/*
*===========================================================================
* IPRIP_RELEASE
*===========================================================================
* IPRIP release version.
*/
#define IPRIP_RELEASE 60600
/*
****************************************************************************
* 5 TYPES
****************************************************************************
*/
/*
*===========================================================================
* Iprip_rt
*===========================================================================
*/
typedef struct Iprip_rt_struct
{
Ipcom_route_entry hdr; /* The header required by the route package */
Ipcom_list rt_list;
/* User Route info. */
Ip_u32 ipaddr_n; /* Route destination IP address (host or net). */
Ip_u32 mask_n; /* 'ipaddr' mask. If not specified netmask is used. */
Ip_u32 keymask[2];
Ip_u32 router_n; /* Router, i.e. gateway. '0' for localhost. */
Ip_s32 metric; /* Metric. */
Ip_u32 ifindex; /* Interface index. */
Ip_u16 flags; /* Route flags. See IPRIP_ROUTE_FLAG_XXX below. */
Ip_u16 routetag_n; /* RIPv2 route tag in network endian */
Ip_u16 age; /* Route age in seconds. */
Ip_u16 update_inst; /* Update instance number. */
}
Iprip_rt;
#define IPRIP_ROUTE_FLAG_INTERFACE (Ip_u16)0x0001
#define IPRIP_ROUTE_FLAG_PERMANENT (Ip_u16)0x0002
#define IPRIP_ROUTE_FLAG_STATIC (Ip_u16)0x0004
#define IPRIP_ROUTE_FLAG_GARBAGE (Ip_u16)0x0100 /* Don't set! */
#define IPRIP_ROUTE_FLAG_STACKROUTE (Ip_u16)0x0200
#define IPRIP_ROUTE_FLAG_LEAKED (Ip_u16)0x0400
/* Route types that do not age. */
#define IPRIP_ROUTE_FLAGS_NONAGE (IPRIP_ROUTE_FLAG_INTERFACE + IPRIP_ROUTE_FLAG_PERMANENT + IPRIP_ROUTE_FLAG_STATIC + IPRIP_ROUTE_FLAG_LEAKED)
/*
*===========================================================================
* Iprip_open
*===========================================================================
* The Iprip_open structure is used to pass global, i.e. non-interface
* specific configuration and callback functions to IPRIP.
* The 'udp_fd' is used in combination with the rip_write() callback function
* to output UDP RIP packets.
* The add_route() and delete_route() callback functions are called by IPRIP
* each time a RIP route is added or deleted. Code to set or delete a route
* with the TCP/IP stack should be placed in these callbacks.
* The 'cookie' is passed in the three callback functions and is user
* specific and not looked at by IPRIP.
* No optional global configuration is available yet, hence conf[0] must
* currently always be set to IPTAG_END.
*/
typedef struct Iprip_open_struct
{
Ip_fd udp_fd; /* RIP UDP socket. */
/* Callback functions. */
void *cookie; /* 32bit user-data returned in each callback. */
Ip_err (*rip_write) (Ip_fd udp_fd, void *cookie, Ip_u32 ipaddr_n, Ipcom_sock_addr *dest, void *buf, Ip_size_t len);
Ip_err (*add_route) (void *cookie, Iprip_rt *rt);
Ip_err (*delete_route) (void *cookie, Iprip_rt *rt);
Ip_tag conf[1]; /* None available, included for future compability. */
}
Iprip_open;
/*
*===========================================================================
* Iprip_interface
*===========================================================================
* The Iprip_interface structure is used by the application to initialize and
* configure a new RIP interface. The structure, which is dynamic in size, is
* filled in by the application and passed to IPRIP in the iprip_ifopen()
* function call.
*
* 'ipaddr_n', 'mask_n' stores the IP address and its subnet mask in network
* endian. 'brdaddr_n' is the IP destination address that should be used for
* sending the continuous RIP update signals. If 'brdaddr_n' is set to 0, no
* RIP updates whether triggered or timed-out are sent, i.e. silent RIP host.
*
* Optional interface configuration is passed in the tag array 'conf' which
* must always be terminated with the IPTAG_END constant.
*/
typedef struct Iprip_interface_struct
{
Ip_u32 ipaddr_n; /* IP address (router IP) in network endian. */
Ip_u32 mask_n; /* Subnet mask in network endian. */
Ip_u32 brdaddr_n; /* RIP broadcast address (0 for silent). */
Ip_tag conf[1]; /* Optional interface configuration (see tags below) */
}
Iprip_interface;
/* possible 'brdaddr_n' value: RIP multicast group, "224.0.0.9" */
#define IPRIP_MADDR ip_htonl(0xe0000009L)
/****** Optional interface configuration - iprip_ifopen() 'conf' tags *****/
/* RIP receive compability switch. */
#define IPTAG_IPRIP_RX_COMPAT 0xff030001
/* Valid RX_COMPAT values: */
#define IPRIP_RX_RIPX_NONE 0 /* Disable RIP input on this interface. */
#define IPRIP_RX_RIP1_ONLY 1 /* Only accept RIPv1. */
#define IPRIP_RX_RIP2_ONLY 2 /* Only accept RIPv2. */
#define IPRIP_RX_RIPX_ANY 3 /* Default. Accept both RIPv1 and RIPv2. */
/* Use this tag to raise the metric. Default = 1. */
#define IPTAG_IPRIP_METRIC 0xff030002
/* Use this tag to change the RIP version. Default = 2. */
#define IPTAG_IPRIP_VERSION 0xff030003
/* Use this tag to use "simple split horizon" instead of "poisonous" */
#define IPTAG_IPRIP_DISABLE_POISON 0xff030004
/* Use this tag to set the route tag for this interface route. */
#define IPTAG_IPRIP_ROUTE_TAG 0xff030005
/* Foreign IP address in network endian.
* Signifies that the newly opened RIP interface is on a PPP link.
*/
#define IPTAG_IPRIP_FOREIGN_IPADDR 0xff030006
/* Set authentication password, a null-terminated password string of
* maximum 16 bytes. Default password is an empty string.
*/
#define IPTAG_IPRIP_AUTH_PASSWORD 0xff030007
/* Set RIP authentication type on this interface.
* Supported tag values: 1 = none, 2 = simple and 3 = md5.
* All incoming response packets must be authenticated or they are ignored.
*/
#define IPTAG_IPRIP_AUTH_TYPE 0xff030008
/* Valid Authentication types: */
#define IPRIP_AUTHTYPE_NONE 1
#define IPRIP_AUTHTYPE_SIMPLE 2
#define IPRIP_AUTHTYPE_MD5 3
/* Set initial MD5 authentication sequence number.
* RIPv2 MD5 authentication requires increasing sequence numebers to be
* authenticated. hence, when an interface goes down and quickly comes up
* again the sequence numbers must be larger than before the reboot or the
* RIP packets will be ignored by the other gateways. One good idea is to
* use this tag and set the initial sequence number from the clock. This
* will ensure increasing RIP sequence numbers even after reboot.
*/
#define IPTAG_IPRIP_AUTH_SEQ_NUMBER 0xff030009
/*
*===========================================================================
* Iprip_route
*===========================================================================
* The Iprip_route structure is used by the iprip_rtadd() and iprip_rtdelete()
* function calls to add and delete static or leaked RIP routes. A static RIP
* route is normally used to specify routing paths before the dynamic routing
* takes over.
* A leaked route may have been learned from other routing daemons (e.g. OSPF)
* and added to IPRIP.
* If the route flag 'IPRIP_ROUTE_FLAG_STATIC' is set it signifies that the
* route is static which means it will never age though it may still be
* replaced by a better route learned from a neighbouring RIP router. If the
* route should never be replaced, even by better routes, 'flags' should be
* set to 'IPRIP_ROUTE_FLAG_PERMANENT'. A permanent route can still be deleted by
* the use of iprip_rtdelete().
* If the route should not try to add a route to the stack (by calling add_route())
* it should be flagged IPRIP_ROUTE_FLAG_LEAKED.
*/
typedef struct Iprip_route_struct
{
Ip_u32 ipaddr_n; /* Route destination IP address (host or net). */
Ip_u32 mask_n; /* 'ipaddr_n' mask. If not specified netmask is used. */
Ip_u32 router_n; /* Router in network endian. Normally '0' for local host. */
Ip_s32 metric; /* Route RIP metric. */
Ip_u16 routetag; /* RIPv2 route tag. */
Ip_u16 flags; /* Routing flags (IPRIP_ROUTE_FLAG_XXX). */
}
Iprip_route;
/*
****************************************************************************
* 6 PUBLIC FUNCTIONS
****************************************************************************
*/
/*
*===========================================================================
* iprip_init
*===========================================================================
* Description: Initialize IPRIP global data 'iprip' and allocate
* temporary RIP output buffer memory.
* Parameters: .
* Returns: IPCOM_SUCCESS or error code.
*
*/
IP_PUBLIC Ip_err iprip_init(void);
/*
*===========================================================================
* iprip_exit
*===========================================================================
* Description: Release, i.e. free, temporary IPRIP dynamic memory.
* Parameters: .
* Returns: .
*
*/
IP_PUBLIC Ip_err iprip_exit(void);
/*
*===========================================================================
* iprip_open
*===========================================================================
* Description: Open and configure IPRIP with global, i.e. non-interface
* specific, information.
* Parameters: config - A pointer to an initialized Iprip_open structure:
* cookie - Optional user specific data returned in the
* callback functions below.
* add_route - Function hook called each time a route is added.
* delete_route - Function hook called each time a route is deleted.
* conf - Optional configuration (none in use yet).
* Returns: IPCOM_ERR_ALREADY_OPEN - iprip_open() should only be called
* once.
* IPCOM_ERR_UNSUPPORTED_TAG - No optional configuration is
* in use and conf[0] must be set to IPTAG_END.
* IPCOM_SUCCESS - Success.
*
*/
IP_PUBLIC Ip_err iprip_open(Iprip_open *config);
/*
*===========================================================================
* iprip_close
*===========================================================================
* Description: Close an opened IPRIP. all the RIP
* interfaces are closed and deleted.
* Parameters: .
* Returns: IPCOM_ERR_ALREADY_CLOSED - Failed to close since not open.
* IPCOM_SUCCESS - Success.
*
*/
IP_PUBLIC Ip_err iprip_close(void);
/*
*===========================================================================
* iprip_ctrl
*===========================================================================
* Description: Get global IPRIP statistics or interface information.
* Parameters: ctrltags A IPTAG_END terminated tag array containing the
* desired information tags and space for the return value.
* Returns: IPCOM_ERR_UNSUPPORTED_TAG - The configuration tag array
* contained an unknown tag.
* IPCOM_SUCCESS - Success.
*
*/
IP_PUBLIC Ip_err iprip_ctrl(Ip_tag *ctrltags);
/****** IPRIP control tags. ******/
/* Get interface index of interface with IP address tag value, i.e. use
* this tag if you have the IP address and require the RIP interface index
* having that IP address. Note that this implies that all RIP interfaces
* must have unique IP addresses. The IP address is given in network endian.
*/
#define IPRIP_CTRLT_GET_IFINDEX_INTERFACE 0xff040001
/* Get first/next lexicographic RIP interface index (IP address > tag value).
* The tag value should be set to 0 for the first interface. Setting the tag
* value to an IP address results in the retrieval of the next lexicographic
* interface or NSINVAL_IFINDEX if none available. The IP address is given in
* network endian.
*/
#define IPRIP_CTRLT_GET_NEXT_INTERFACE 0xff040002
/* Get number of route changes made to the IP route database by RIP. */
#define IPRIP_CTRLT_GET_rip2GlobalRouteChanges 0xff040003
/* Get number of responses sent to RIP queries from other systems. */
#define IPRIP_CTRLT_GET_rip2GlobalQueries 0xff040004
/*
*===========================================================================
* iprip_ifopen
*===========================================================================
* Description: Open and configure a new RIP interface. The newly opened
* interface is hereon identified by 'ifindex' which must be
* unique. The interface will start by sending a RIP request
* in order to immediately gain route information.
* Parameters: ifindex Interface index, a unique identifier specified
* by the application used to identify the interface
* in all further RIP interface function calls as
* well as callbacks.
* interface A pointer to a Iprip_interface structure that
* is initialized by the application containing
* mandatory and optional interface configuration.
* Returns: IPCOM_ERR_ALREADY_OPENED - An interface with the same
* 'ifindex' is already in use, i.e. opened.
* IPCOM_ERR_INVALID_TAG_VALUE - One of the optional tags
* contained an illegal configuration value.
* IPCOM_ERR_UNSUPPORTED_TAG - The optional configuration
* tag array contained an unknown tag.
* IPCOM_SUCCESS - Success.
*
*/
IP_PUBLIC Ip_err iprip_ifopen(Ip_u32 ifindex, Iprip_interface *interface);
/*
*===========================================================================
* iprip_ifisopen
*===========================================================================
* Description: Check if interface specified by 'ifindex' is open.
* Parameters: ifindex Interface index, a unique identifier specified
* by the application used to identify the interface
* Returns: IP_TRUE if interface is open, else IP_FALSE
*
*/
IP_PUBLIC Ip_bool iprip_ifisopen(Ip_u32 ifindex);
/*
*===========================================================================
* iprip_ifclose
*===========================================================================
* Description: Close the RIP interface specified by 'ifindex'.
* Parameters: ifindex Which interface to close.
* Returns: IPCOM_ERR_ILLEGAL_INTERFACE - Unknown interface.
* IPCOM_SUCCESS - Success.
*/
IP_PUBLIC Ip_err iprip_ifclose(Ip_u32 ifindex);
/*
*===========================================================================
* iprip_ifread
*===========================================================================
* Description: Pass an incoming RIP packet specified by 'pkt' to IPRIP
* for input parsing.
* Parameters: ifindex The interface index of the incoming RIP packet or
* the index of any open interface if unavailable.
* pkt Nssock_packet pointer (defined in nssock.h) that
* contains the RIP packet. The 'to' information is
* not used hence need not be set.
* Returns: IPCOM_ERR_ILLEGAL_INTERFACE - Unknown interface.
* IPCOM_ERR_BAD_PACKET - A corrupt or illegal RIP packet. The
* packet is ignored.
* IPCOM_ERR_AUTH_FAILED - Authentication is mandatory and was
* missing or incorrect, packet ignored.
* IPCOM_SUCCESS - Success.
*
*/
IP_PUBLIC Ip_err iprip_ifread(Ip_u32 ifindex, Ipcom_sock_packet *pkt);
/*
*===========================================================================
* iprip_ifctrl
*===========================================================================
* Description: Get or set interface specific information and configuration.
* Parameters: ifindex Which interface to get info/configure.
* ctrltags A IPTAG_END terminated tag array containing the
* get/set tags and their values.
* Returns: IPCOM_ERR_ILLEGAL_INTERFACE - Unknown interface.
* IPCOM_ERR_INVALID_TAG_VALUE - One of the set tags
* contained an illegal configuration value.
* IPCOM_ERR_UNSUPPORTED_TAG - The tag array contained
* an unknown tag.
* IPCOM_SUCCESS - Success.
*
*/
IP_PUBLIC Ip_err iprip_ifctrl(Ip_u32 ifindex, Ip_tag *ctrltags);
/****** IPRIP interface control tags. ******/
/* Get interface IP address in network endian. */
#define IPRIP_IFCTRLT_GET_IP_ADDRESS 0xff050001
#define IPRIP_IFCTRLT_GET_rip2IfStatAddress IPRIP_IFCTRLT_GET_IP_ADDRESS
#define IPRIP_IFCTRLT_GET_rip2IfConfAddress IPRIP_IFCTRLT_GET_IP_ADDRESS
/* Get MIB rip2IfStatRcvBadPackets. */
#define IPRIP_IFCTRLT_GET_rip2IfStatRcvBadPackets 0xff050002
/* Get MIB rip2IfStatRcvBadRoutes. */
#define IPRIP_IFCTRLT_GET_rip2IfStatRcvBadRoutes 0xff050003
/* Get MIB rip2IfStatSentUpdates. */
#define IPRIP_IFCTRLT_GET_rip2IfStatSentUpdates 0xff050004
/* Get MIB rip2IfConfAuthType.
* Tag values: 1 = none, 2 = simple and 3 = md5.
*/
#define IPRIP_IFCTRLT_GET_rip2IfConfAuthType 0xff050005
/* Get MIB rip2IfConfSend.
* Tag values: 1 = doNotSend, 2 = ripVersion1, 3 = rip1Compatible
* and 4 = ripVersion2.
*/
#define IPRIP_IFCTRLT_GET_rip2IfConfSend 0xff050006
/* Get MIB rip2IfConfReceive.
* Tag values: 1 = rip1, 2 = rip2, 3 = rip1OrRip2 and 4 = doNotReceive.
*/
#define IPRIP_IFCTRLT_GET_rip2IfConfReceive 0xff050007
/* Set MIB rip2IfConfAuthType.
* Supported tag values: 1 = none, 2 = simple and 3 = md5.
*/
#define IPRIP_IFCTRLT_SET_rip2IfConfAuthType 0xff050008
/* Set MIB rip2IfConfAuthKey (password of maximum 16 bytes). */
#define IPRIP_IFCTRLT_SET_rip2IfConfAuthKey 0xff050009
/* Set MIB rip2IfConfSend.
* Tag values: 1 = doNotSend, 2 = ripVersion1, 3 = rip1Compatible
* and 4 = ripVersion2.
*/
#define IPRIP_IFCTRLT_SET_rip2IfConfSend 0xff05000a
/* Set MIB rip2IfConfReceive.
* Tag values: 1 = rip1, 2 = rip2, 3 = rip1OrRip2 and 4 = doNotReceive.
*/
#define IPRIP_IFCTRLT_SET_rip2IfConfReceive 0xff05000b
/*
*===========================================================================
* iprip_rtadd
*===========================================================================
* Description: Add a static or permanent RIP route.
* Parameters: route A Iprip_route pointer that contains the static
* route to add.
* Returns: IPCOM_ERR_INVALID_ROUTE - The route is invalid or not on a
* directly attached network.
* IPCOM_ERR_DUPLICATE_ROUTE - An identical static route
* already exists.
* IPCOM_SUCCESS - Success.
*
*/
IP_PUBLIC Ip_err iprip_rtadd(Iprip_route *route);
/*
*===========================================================================
* iprip_rtdelete
*===========================================================================
* Description: Delete a RIP route (static or dynamic). Even permanent
* routes may be deleted using iprip_rtdelete().
* Parameters: route A Iprip_route pointer that contains information
* about the route to delete. Only the ipaddr_n
* and mask_n are looked at to find the route.
* Returns: IPCOM_ERR_INVALID_ROUTE - The route is invalid because it
* contains a non-zero network part.
* IPCOM_ERR_NO_ROUTE - No such route was found hence could
* not be deleted.
* IPCOM_ERR_DEAD_ROUTE - Route is already dead, i.e. timing
* out and unusable.
* IPCOM_SUCCESS - Success.
*
*/
IP_PUBLIC Ip_err iprip_rtdelete(Iprip_route *route);
/*
*===========================================================================
* iprip_rtwalk
*===========================================================================
* Description: Walk through all routes calling rtwalk_func on each one.
* Parameters: User cookie and the walk function.
* Returns: IPCOM_SUCCESS.
*
*/
typedef int (* Iprip_rtwalk_func) (void *cookie, Iprip_rt *rt);
IP_PUBLIC Ip_err iprip_rtwalk(void *cookie, Iprip_rtwalk_func rtwalk_func);
/*
****************************************************************************
* 7 GLOBAL FUNCTIONS
****************************************************************************
* Internal functions for the ipnet port.
*/
IP_GLOBAL char *iprip_routeinfo(Iprip_rt *rt);
IP_GLOBAL void iprip_config_read(void);
IP_GLOBAL Ip_fd iprip_socket(void);
#ifdef __cplusplus
}
#endif
#endif
/*#ifndef IPRIP_H*/
/*
****************************************************************************
* END OF FILE
****************************************************************************
*/