/* * Copyright 2006 Wind River Systems, Inc. * * The right to copy, distribute, modify or otherwise make use * of this software may be licensed only pursuant to the terms * of an applicable Wind River license agreement. */ /* modification history -------------------- 01i,05nov08,rme Added 'ipripng_sflag' (WIND00141137) 01c,09feb07,tlu Fixed gnu compiler error on Windows 01b,24jan07,kch Fixed gnu warnings 01a,12jun06,tlu Initial creation */ #ifndef IPRIPNG_H #define IPRIPNG_H /* **************************************************************************** * 1 DESCRIPTION **************************************************************************** * Routing Information Protocol - IPRIPng * -------------------------------------- * RTOS and TCP/IP stack portable implementation of Routing Information * Protocol RIPng. * * Compliant with the following RFC: * RFC 2080 RIPng * * */ /* **************************************************************************** * 2 CONFIGURATION **************************************************************************** */ /* **************************************************************************** * 3 INCLUDE FILES **************************************************************************** */ #include #include #include #include #include #include #include #include #ifdef __cplusplus extern "C" { #endif /* **************************************************************************** * 4 DEFINES **************************************************************************** */ #define SET_IN6_LINKLOCAL_IFINDEX(addr, index) \ do { \ (addr).s6_addr[2] = (Ip_u8)(((index) >> 8) & 0xff); \ (addr).s6_addr[3] = (Ip_u8)((index) & 0xff); \ } while (0) #define ROUNDUP(a) \ ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) /* **************************************************************************** * 5 TYPES **************************************************************************** */ struct ifc; #define in6_addr Ip_in6_addr /* *=========================================================================== * Ipripng_rt *=========================================================================== */ struct netinfo6 { struct in6_addr rip6_dest; Ip_u16 rip6_tag; Ip_u8 rip6_plen; Ip_u8 rip6_metric; }; typedef struct Ipripng_rt_struct { Ipcom_route_entry hdr; /* The header required by the route package */ Ipcom_list rt_list; /* User Route info. */ struct Ipripng_rt *rrt_next; /* next destination */ struct netinfo6 rrt_info; /* network info */ struct in6_addr rrt_gw; /* gateway */ Ip_u32 rrt_flags; /* kernel routing table flags */ Ip_u32 rrt_rflags; /* ripng routing table flags */ Ip_time_t rrt_t; /* when the route validated */ int rrt_index; /* ifindex from which this route got */ Ip_u32 keymask[2]; #if 0 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. */ #endif Ip_u16 update_inst; /* Update instance number. */ } Ipripng_rt; #define RRTF_INTERFACE 0x00800000 #define RRTF_STACKROUTE 0x01000000 #define RRTF_DELETED 0x02000000 #define RRTF_RIPNGLEARNED 0x04000000 #define RRTF_AGGREGATE 0x08000000 #define RRTF_NOADVERTISE 0x10000000 #define RRTF_NH_NOT_LLADDR 0x20000000 #define RRTF_SENDANYWAY 0x40000000 #define RRTF_CHANGED 0x80000000 /* *=========================================================================== * Ipripng_open *=========================================================================== * The Ipripng_open structure is used to pass global, i.e. non-interface * specific configuration and callback functions to IPRIPng. * The 'udp_fd' is used to output UDP RIPng packets. * The add_route() and delete_route() callback functions are called by IPRIPng * each time a RIPng 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 IPRIPng. * No optional global configuration is available yet, hence conf[0] must * currently always be set to IPTAG_END. */ typedef struct Ipripng_open_struct { Ip_fd udp_fd; /* RIP UDP socket. */ /* Callback functions. */ Ip_err (*add_route) (Ipripng_rt *rrt, const struct in6_addr *gw, struct ifc *ifcp); Ip_err (*delete_route) (struct netinfo6 *np, const struct in6_addr *gw, Ip_bool proto_set); Ip_tag conf[1]; /* None available, included for future compability. */ } Ipripng_open; /* *=========================================================================== * RIPng Interface *=========================================================================== */ struct iff { int iff_type; struct in6_addr iff_addr; int iff_plen; struct iff *iff_next; }; struct ifc { /* Configuration of an RIPng interface */ char *ifc_name; /* if name */ struct ifc *ifc_next; int ifc_index; /* if index */ int ifc_mtu; /* if mtu */ int ifc_metric; /* if metric */ unsigned int ifc_flags; /* flags */ int ifc_cflags; /* IFC_XXX */ struct in6_addr ifc_mylladdr; /* my link-local address */ struct Ip_sockaddr_in6 ifc_ripsin; /* ripng multicast address */ struct iff *ifc_filter; /* filter structure */ struct ifac *ifc_addr; /* list of AF_INET6 addresses */ int ifc_joined; /* joined to ff02::9 */ int ifc_horizcfg; /* Split Horizon Configuration */ }; struct ifac { /* Adddress associated to an interface */ struct ifc *ifa_conf; /* back pointer */ struct ifac *ifa_next; struct in6_addr ifa_addr; /* address */ struct in6_addr ifa_raddr; /* remote address, valid in p2p */ int ifa_plen; /* prefix length */ }; /* *=========================================================================== * Allowed neighbor list *=========================================================================== */ struct nb_list { struct nb_list *nb_next; struct in6_addr nb_addr; }; /* **************************************************************************** * 6 PUBLIC FUNCTIONS **************************************************************************** */ /* *=========================================================================== * ipripng_init *=========================================================================== * Description: Initialize IPRIPng global data 'ipripng' and allocate * temporary RIPng output buffer memory. * Parameters: . * Returns: IPCOM_SUCCESS or error code. * */ IP_PUBLIC Ip_err ipripng_init(void); /* *=========================================================================== * ipripng_exit *=========================================================================== * Description: Release, i.e. free, temporary IPRIPng dynamic memory. * Parameters: . * Returns: . * */ IP_PUBLIC Ip_err ipripng_exit(void); /* *=========================================================================== * ipripng_open *=========================================================================== * Description: Open and configure IPRIPng with global, i.e. non-interface * specific, information. * Parameters: config - A pointer to an initialized Ipripng_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 ipripng_open(Ipripng_open *config); /* *=========================================================================== * ipripng_close *=========================================================================== * Description: Close an opened IPRIPng. all the RIPng * interfaces are closed and deleted. * Parameters: . * Returns: IPCOM_ERR_ALREADY_CLOSED - Failed to close since not open. * IPCOM_SUCCESS - Success. * */ IP_PUBLIC Ip_err ipripng_close(void); /* *=========================================================================== * ipripng_ctrl *=========================================================================== * Description: Get global IPRIPng 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 ipripng_ctrl(Ip_tag *ctrltags); /****** IPRIPng 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 RIPng interface index * having that IP address. Note that this implies that all RIPng interfaces * must have unique IP addresses. The IP address is given in network endian. */ #define IPRIPNG_CTRLT_GET_IFINDEX_INTERFACE 0xff050001 /* Get first/next lexicographic RIPng 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 IPRIPNG_CTRLT_GET_NEXT_INTERFACE 0xff050002 /* Get number of route changes made to the IP route database by RIPng. */ #define IPRIPNG_CTRLT_GET_rip2GlobalRouteChanges 0xff050003 /* Get number of responses sent to RIPng queries from other systems. */ #define IPRIPNG_CTRLT_GET_rip2GlobalQueries 0xff050004 /* **************************************************************************** * 7 GLOBAL FUNCTIONS **************************************************************************** * Internal functions for the ipnet port. */ IP_GLOBAL char *ipripng_allocopy(char *p); IP_GLOBAL struct ifc *ifc_find(char *name); IP_GLOBAL struct iff *iff_find(struct ifc *ifcp, int type); IP_GLOBAL void ifflags(int flags, char *ripng_if_buf); IP_GLOBAL int mask2len(const struct in6_addr *addr, int lenlim); IP_GLOBAL struct ifac *ifa_match(const struct ifc *ifcp, const struct in6_addr *ia, int plen); IP_GLOBAL int getifmtu(int ifindex); IP_GLOBAL void applyplen(struct in6_addr *ipa, int plen); IP_GLOBAL Ip_time_t time_offset(Ip_time_t *tod); IP_GLOBAL Ip_time_t ipripng_nexttrigger_time(void); IP_GLOBAL int sin6mask2len(const struct Ip_sockaddr_in6 *sin6); IP_GLOBAL void rtflags(struct Ipnet_rt_msghdr *rtm, char *ripng_rt_buf); IP_PUBLIC int out_filter(Ipripng_rt *rrt, struct ifc *ifcp); IP_GLOBAL int tobeadv(Ipripng_rt *rrt, struct ifc *ifcp); IP_GLOBAL Ip_bool ipripng_neighbor_verify(struct in6_addr * nb_addr); IP_GLOBAL struct in6_addr *plen2mask(int n); #if 0 IP_GLOBAL char *ipripng_routeinfo(Ipripng_rt *rt); #endif IP_GLOBAL void ipripng_config_read(void); IP_GLOBAL Ip_fd ipripng_ripsocket(void); IP_GLOBAL Ip_fd ipripng_rtsocket(void); IP_GLOBAL struct ifc *ipripng_ifhead(void); IP_GLOBAL int ipripng_nflag(void); IP_GLOBAL int ipripng_sflag(void); IP_GLOBAL int ipripng_Sflag(void); IP_GLOBAL struct nb_list *ipripng_nb_list_root(void); IP_GLOBAL Ip_err ipripng_krtread(int again); IP_GLOBAL void ipripng_sendrequest(struct ifc *ifcp); IP_GLOBAL Ip_err ipripng_rtrecv(void); IP_GLOBAL Ip_err ipripng_initsocks(void); IP_GLOBAL int ipripng_ifrt(struct ifc *ifcp, int again); IP_GLOBAL Ip_err ipripng_filterconfig(void); IP_GLOBAL Ip_err ipripng_riprecv(void); IP_GLOBAL Ip_err ipripng_ifconfig(void); IP_PUBLIC Ip_err ipripng_init(void); IP_PUBLIC Ip_err ipripng_exit(void); IP_PUBLIC Ip_err ipripng_open(Ipripng_open *config); IP_PUBLIC Ip_err ipripng_close(void); IP_PUBLIC Ip_err ipripng_ctrl(Ip_tag *ctrltags); IP_PUBLIC Ip_err ipripng_ifclose(Ip_u32 ifindex); IP_GLOBAL void ipripng_ifdump(void); IP_GLOBAL void ipripng_rtdump(void); IP_PUBLIC const char * ipripng_version(void); IP_PUBLIC Ip_err ripngStart(char *,int); IP_GLOBAL void ripngStop(void); IP_PUBLIC Ip_err ipripng_start(void); #ifdef __cplusplus } #endif #endif /*#ifndef IPRIPNG_H*/ /* **************************************************************************** * END OF FILE **************************************************************************** */