⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 riplib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* ripLib.c - Routing Information Protocol (RIP) v1 and v2 library *//* Copyright 1984 - 2002 Wind River Systems, Inc. */#include "copyright_wrs.h"/* * Copyright (c) 1983, 1988, 1993 *	The Regents of the University of California.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by the University of *	California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors *    may be used to endorse or promote products derived from this software *    without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. *//*modification history--------------------02c,22mar02,niq  Merged from Synth view, tor3_x.synth branch, ver 02x02b,24jan02,niq  SPR 72415 - Added support for Route tags                 SPR 62733 - Initialize parameters correctly in ripSplitPacket02a,15oct01,rae  merge from truestack ver 02n, base 01x (SPRs 70188, 69983 etc.) 01z,10nov00,spm  merged from version 02b of tor3_x branch (multiple SPR fixes)01y,06nov00,rae  Fixed SPR #2646201x,16mar99,spm  recovered orphaned code from tor1_0_1.sens1_1 (SPR #25770)01w,05oct98,spm  made task parameters adjustable and optimized stack                  size (SPR #22422)01v,11sep98,spm  general overhaul - moved expanded ripShutdown routine                 from ripTimer.c (SPR #22352); altered ripBuildPacket to                  allow class-based masks for internal supernets (SPR #22350)01u,01sep98,spm  changed ripBuildPacket to include correct netmask for                 classless routing (SPR #22220 and #22065); added support                 for default next hop routers (SPR #21940)01t,26jun98,spm  corrected ripBuildPacket to test version against MIB values                  (allowing RIPv1 updates) and added subnet test to use valid                 router in RIPv2 updates; moved semaphore creation before                  first use; changed RIP_MCAST_ADDR constant from string to                 value; added ripClearInterfaces routine needed to comply                 with ANVL RIP tests; removed compiler warnings01s,14dec97,jdi  doc: cleanup.01r,21oct97,kbw  made minor man page font fix01q,06oct97,gnn  added sendHook routines and cleaned up warnings01p,04aug97,kbw  fixed man page problems found in beta review01o,02jun97,gnn  fixed SPR 8685 so that the timer task does not respawn.01n,16may97,gnn  added code to implement leaking routes.                 modified ripSplitPacket to handle stupid packets (ANVL).                 renamed myHook to ripAuthHook.01m,08may97,gnn  fixed an authentication bug.01l,05may97,rjc  changed error return value to m2Lib stuff.01k,28apr97,gnn  added some descriptive text.01j,20apr97,kbw  fixed man page format, did spell check.01h,18apr97,gnn  removed device specific code.01g,17apr97,gnn  fixed errors pointed out by ANVL.01f,14apr97,gnn  added authentication hook routines.01e,07apr97,gnn  removed device specific code.01d,07apr97,gnn  cleared up some of the more egregious warnings.                 added MIB-II interfaces and options.01c,12mar97,gnn  added multicast support.                 added time variables.01b,24feb97,gnn  added routines for version 2 support.01a,26nov96,gnn  created from BSD4.4 routed main.c*//*DESCRIPTIONThis library implements versions 1 and 2 of the Routing Information Protocol (RIP). The protocol is intended to operate as an interior gateway protocolwithin a relatively small network with a longest path of 15 hops.HIGH-LEVEL INTERFACEThe ripLibInit() routine links this library into the VxWorks image and beginsa RIP session. This happens automatically if INCLUDE_RIP is defined at thetime the image is built. Once started, RIP will maintain the network routing table until deactivated by a call to the ripShutdown() routine, which will remove all route entries and disable the RIP library routines. All RIPrequests and responses are handled as defined in the RFC specifications.RFC 1058 defines the basic protocol operation and RFC 1723 details theextensions that constitute version 2.When acting as a supplier, outgoing route updates are filtered using simplesplit horizon. Split horizon with poisoned reverse is not currently available.Additional route entries may be excluded from the periodic update with theripSendHookAdd() routine. If a RIP session is terminated, the networking subsystem may not function correctly until RIP is restarted with a new call to ripLibInit() unlessrouting information is provided by some other method.CONFIGURATION INTERFACEBy default, a RIP session only uses the network interfaces created before itstarted. The ripIfSearch() routine allows RIP to recognize any interfaces added to the system after that point. If the address or netmask of anexisting interface is changed during a RIP session, the ripIfReset() routine must be used to update the RIP configuration appropriately.The current RIP implementation also automatically performs the bordergateway filtering required by the RFC specification. Those restrictionsprovide correct operation in a mixed environment of RIP-1 and RIP-2 routers.The ripFilterDisable() routine will remove those limitations, and can producemore efficient routing for some topologies. However, you must not use that routine if any version 1 routers are present. The ripFilterEnable() routine will restore the default behavior. AUTHENTICATION INTERFACEBy default, authentication is disabled, but may be activated by an SNMPagent on an interface-specific basis. While authentication is disabled,any RIP-2 messages containing authentication entries are discarded. Whenenabled, all RIP-2 messages without authentication entries are automaticallyrejected. To fully support authentication, an authentication routine shouldbe specified with the ripAuthHookAdd() routine. The specified functionwill be called to screen every RIP-1 message and all unverified RIP-2 messages containing authentication entries. It may be removed with the ripAuthHookDelete() routine. All RIP-1 and unverified RIP-2 messages will be discarded while authentication is enabled unless a hook is present.OPTIONAL INTERFACEThe ripLeakHookAdd() routine allows the use of an alternative routingprotocol that uses RIP as a transport mechanism. The specified functioncan prevent the RIP session from creating any table entries from thereceived messages. The ripLeakHookDelete() routine will restore thedefault operation. DEBUGGING INTERFACEAs required by the RFC specification, the obsolete traceon and traceoff messages are not supported by this implementation. The ripRouteShow()routine will display the contents of the internal RIP routing table.Routines such as mRouteShow() to display the corresponding kernel routing table will also be available if INCLUDE_NET_SHOW is defined when the image is built. If additional information is required, the ripDebugLevelSet() routine will enable predefined debugging messages that will be sent to the standard output.INCLUDE FILES: ripLib.hSEE ALSO: RFC 1058, RFC 1723*//* * Routing Table Management Daemon */#include "vxWorks.h"#include "rip/defs.h"#include "m2Lib.h"#include "sys/ioctl.h"#include "sys/socket.h"#include "inetLib.h"#include "taskLib.h"#include "tickLib.h"#include "sockLib.h"#include "sysLib.h"#include "lstLib.h"#include "routeEnhLib.h"#include "net/if.h"#include "errnoLib.h"#include "errno.h"#include "logLib.h"#include "wdLib.h"#include "semLib.h"#include "ioLib.h"#ifdef VIRTUAL_STACK#include "netinet/vsLib.h"#include "netinet/vsRip.h"#endif /* VIRTUAL_STACK */#ifdef RIP_MD5#include "rip/md5.h"#endif /* RIP_MD5 *//* forward declarations. */IMPORT void addrouteforif(register struct interface *ifp);IMPORT void ripRouteMetricSet (struct rt_entry * pRtEntry);void ripIfShow (void);#define SOCKADDR_IN(s) (((struct sockaddr_in*)(s))->sin_addr.s_addr)#define RIP_TASK_PRIORITY		101#define RIP_TIMER_TASK_PRIORITY		100#define RIP_TASK_STACK_SIZE		3750#define RIP_TIMER_TASK_STACK_SIZE	3000#define RIP_TASK_OPTIONS			0#define RIP_TIMER_TASK_OPTIONS		0#ifndef VIRTUAL_STACK/* globals */RIP 	ripState;int	routedDebug = 0;SEM_ID 	ripLockSem;BOOL 	ripFilterFlag = TRUE;LIST 	ripIfExcludeList;/* * Settings for primary and timer tasks. For correct operation, the timer * task must run at a higher priority than the primary task. The stack * sizes are chosen based on the high-water mark measured on a Sparc target, * since the high use of registers in that architecture provides a likely * maximum. The actual values measured were 2524 bytes for the primary task  * and 1824 bytes for the timer task. * * Use a task priority between 100 and 255 as that is the default priority  * range for a user protection domain. */int _ripTaskPriority = RIP_TASK_PRIORITY;int _ripTaskOptions = RIP_TASK_OPTIONS;int _ripTaskStackSize = RIP_TASK_STACK_SIZE;int _ripTimerTaskPriority = RIP_TIMER_TASK_PRIORITY;int _ripTimerTaskOptions = RIP_TIMER_TASK_OPTIONS;int _ripTimerTaskStackSize = RIP_TIMER_TASK_STACK_SIZE;/* locals */LOCAL BOOL ripInitFlag = FALSE;IMPORT struct interface *ripIfNet;IMPORT struct interface **ifnext;#endif /* VIRTUAL_STACK */#ifdef ROUTER_STACKLOCAL char rtmMessages [][16] = {    "ILLEGAL",    "RTM_ADD",    "RTM_DELETE",    "RTM_CHANGE",    "RTM_GET",    "RTM_LOSING",    "RTM_REDIRECT",    "RTM_MISS",    "RTM_LOCK",    "RTM_OLDADD",    "RTM_OLDDEL",    "RTM_RESOLVE",    "RTM_NEWADDR",    "RTM_DELADDR",    "RTM_IFINFO",    "RTM_ADDEXTRA",    "RTM_DELEXTRA",    "RTM_NEWCHANGE",    "RTM_NEWGET",    "RTM_GETALL",    "RTM_NEWIPROUTE",    "RTM_OLDIPROUTE"    };#endif /* ROUTER_STACK *//* defines */#define BUFSPACE 127*1024#define ROUNDUP(a) \        ((a) > 0 ? (1 + (((a) - 1) | (sizeof (long) - 1))) : sizeof (long))#define ADVANCE(x, n) (x += ROUNDUP ((n)->sa_len)) /* forward declarations */   void rtdeleteall ();IMPORT void ripTimer ();int ripTask ();void timevaladd (struct timeval *t1, struct timeval *t2);void timevalsub (struct timeval *t1, struct timeval *t2);void ripTimeSet (struct timeval *pTimer);void process (int fd);#ifdef ROUTER_STACKLOCAL void ripRouteMsgProcess (void);LOCAL BOOL ripRouteSame (struct rt_entry *pRtEntry, struct sockaddr *pDstAddr,                          struct sockaddr *pNetmask, struct sockaddr *pGateway);LOCAL STATUS ripInterfaceUpFlagSet (u_short ifIndex, BOOL up);LOCAL STATUS ripInterfaceDelete (struct interface *pIf);#endif /* ROUTER_STACK */void ripTimerArm (long timeout);int getsocket (int domain, int type, struct sockaddr_in *sin);void routedTableInit ();void rtdefault ();STATUS routedIfInit (BOOL resetFlag, long ifIndex);void routedInput (struct sockaddr *from, register RIP_PKT *rip, int size);void toall (int (*f)(), int rtstate, struct interface *skipif);LOCAL STATUS ripRoutesDelete (struct interface *pIf, BOOL deleteAllRoutes);LOCAL STATUS ripInterfaceIntDelete (struct interface *pIf,                                     struct interface *pPrevIf);void _ripAddrsXtract (caddr_t cp, caddr_t cpLim, struct rt_addrinfo *pRtInfo);/******************************************************************************** ripLibInit - initialize the RIP routing library** This routine creates and initializes the global data structures used by * the RIP routing library and starts a RIP session to maintain routing * tables for a host. You must call ripLibInit() before you can use any other * ripLib routines. A VxWorks image automatically invokes ripLibInit() * if INCLUDE_RIP was defined when the image was built.** The resulting RIP session will monitor all network interfaces that are * currently available for messages from other RIP routers. If the <supplier>* parameter is true, it will also respond to specific requests from other* routers and transmit route updates over every known interface at the * interval specified by <supplyInterval>.** Specifying a <gateway> setting of true establishes this router as a* gateway to the wider Internet, capable of routing packets anywhere within * the local networks. The final <multicast> flag indicates whether the* RIP messages are sent to the pre-defined multicast address of 224.0.0.9* (which requires a <version> setting of 2) or to the broadcast address of * the interfaces.** The <version> parameter determines the format used for outgoing RIP * messages, and also sets the initial settings of the MIB-II compatibility * switches in combination with the <multicast> flag. A <version> of 1 will * restrict all incoming traffic to that older message type. A <version> of * 2 will set the receive switch to accept either type unless <multicast> is * true, which limits reception to version 2 messages only. SNMP agents may * alter those settings on a per-interface basis once startup is complete.** The remaining parameters set various system timers used to maintain the* routing table. All of the values are expressed in seconds, and must be* greater than or equal to 1. The <timerRate> determines how often* the routing table is examined for changes and expired routes. The* <supplyInterval> must be an exact multiple of that value. The* <expire> parameter specifies the maximum time between updates before* a route is invalidated and removed from the kernel table. Expired routes * are then deleted from the internal RIP routing table if no update has* been received within the time set by the <garbage> parameter.** The following configuration parameters determine the initial values for* all these settings. The default timer values match the settings indicated* in the RFC specification.** \ts* Parameter Name    | Default Value   | Configuration Parameter* ------------------+-----------------+------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -