?? input.c
字號:
/* input.c - routines for processing incoming RIP messages *//* 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. * @(#)input.c 8.3 (Berkeley) 4/28/95 *//*modification history--------------------01s,22mar02,niq Merged from Synth view, tor3_x.synth branch, ver 01z01r,24jan02,niq SPR 72415 - Added support for Route tags01q,15oct01,rae merge from truestack ver 01t, base 01n (SPRs 70188, 69983 etc.)01p,21nov00,spm fixed transmission of responses to wrong port (SPR #62532)01o,10nov00,spm merged from version 01p of tor3_x branch (SPR #33692 fix)01n,16mar99,spm recovered orphaned code from tor1_0_1.sens1_1 (SPR #25770)01m,29sep98,spm updated route modification time for IP group MIB (SPR #9374)01l,11sep98,spm general overhaul of input processing (SPR #22297); removed all references to bloated trace commands (SPR #22350)01k,01sep98,spm changed test of next hop address to detect supernet matches (SPR #22220) and comply with RIP specification; modified whitespace (for coding standards) and added comments01j,26jun98,spm corrected timer setting for poisoned routes; removed duplicate tests from response processing; updated debug messages and added typecast to remove compiler warning01i,03oct97,gnn added includes and declarations to remove warnings01h,15may97,gnn fixed errors relating to ripSplitPacket.01g,08may97,gnn fixed more ANVL related errors.01f,17apr97,gnn fixed errors pointed out by ANVL. 01e,14apr97,gnn added input packet authentication.01d,07apr97,gnn cleared up some of the more egregious warnings. added MIB-II interface and option support.01c,12mar97,gnn added multicast support. added time variables.01b,24feb97,gnn added rip version 2 functionality01a,26nov96,gnn created from BSD4.4 routed*//*DESCRIPTION*//* * Routing Table Management Daemon */#include "vxWorks.h"#include "logLib.h"#include "tickLib.h"#include "rip/defs.h"#include "m2Lib.h"#include "routeEnhLib.h"#ifdef VIRTUAL_STACK#include "netinet/vsLib.h"#include "netinet/vsRip.h"#elseIMPORT int routedDebug;#endif/* The random number generation limits the frequency of triggered updates. */LOCAL u_long ripRandTimeSeed = 1;LOCAL u_long ripRandTime (void);LOCAL void ripRouteAgeUpdate(struct rt_entry *pRtEntry);#define RANDOMDELAY() (MIN_WAITTIME * 1000000 + \ ripRandTime() % ((MAX_WAITTIME - MIN_WAITTIME) * 1000000))#define osa(x) ((struct osockaddr *)(&(x)))/* forward declarations */void addrouteforif(register struct interface *ifp);void ripSplitPacket (struct interface* pIfp, struct sockaddr_in *src, struct sockaddr* orig, struct sockaddr* gateway, struct sockaddr* netmask, int* pTag );void timevaladd (struct timeval *t1, struct timeval *t2);IMPORT STATUS ripAuthCheck (char *, RIP_PKT *);IMPORT void ripSockaddrPrint (struct sockaddr *);/* * Process a newly received packet. */void routedInput ( struct sockaddr *from, register RIP_PKT *rip, int size ) { register struct rt_entry *rt; register struct netinfo *n; register struct netinfo *pFirst; register struct interface *ifp; register struct interface *pErrorIfp; struct interface *ripIfWithDstAddr(); int count, changes = 0; register struct afswitch *afp; static struct sockaddr badfrom, badfrom2; struct sockaddr gateway; struct sockaddr netmask; int tag; int origMetric;#ifndef VIRTUAL_STACK IMPORT RIP ripState;#endif ifp = 0; if (routedDebug > 2) logMsg ("Received RIP message.\n", 0, 0, 0, 0, 0, 0); if (from->sa_family >= AF_MAX || (afp = &afswitch[from->sa_family])->af_hash == (int (*)())0) { if (routedDebug) logMsg ("Command %d received from unsupported address family %d.\n", rip->rip_cmd, from->sa_family, 0, 0, 0, 0); return; } /* * Determine the interface connected to the source of the * RIP message. If no match is found, the message will be ignored. */ pErrorIfp = ripIfLookup (from); if (pErrorIfp == NULL) { if (routedDebug) logMsg ("RIP message received from unreachable router %s.\n", (int)(*afswitch[from->sa_family].af_format)(from), 0, 0, 0, 0, 0); return; } /* If the interface has been disabled, silently drop received packets. */ if (pErrorIfp->ifConf.rip2IfConfStatus != M2_rip2IfConfStatus_valid) return; /* * Test for valid version numbers and filter RIP messages based on the * current setting of the interface's receive control switch. */ if (rip->rip_vers == 0) { if (routedDebug) logMsg ("RIP version 0 packet received from %s! (cmd %d)\n", (int)(*afswitch[from->sa_family].af_format)(from), rip->rip_cmd, 0, 0, 0, 0); pErrorIfp->ifStat.rip2IfStatRcvBadPackets++; return; } if (rip->rip_vers == 1 && pErrorIfp->ifConf.rip2IfConfReceive == M2_rip2IfConfReceive_rip2) { if (routedDebug) logMsg ("RIP-1 message rejected by receive control switch.\n", 0, 0, 0, 0, 0, 0); pErrorIfp->ifStat.rip2IfStatRcvBadPackets++; return; } if (rip->rip_vers == 2 && pErrorIfp->ifConf.rip2IfConfReceive == M2_rip2IfConfReceive_rip1) { if (routedDebug) logMsg ("RIP-2 message rejected by receive control switch.\n", 0, 0, 0, 0, 0, 0); pErrorIfp->ifStat.rip2IfStatRcvBadPackets++; return; } /* * Handle message authentication. If authentication is active, only * messages validated by the authentication hook are accepted. That * routine may allow RIP-1 messages if desired and must validate all * RIP-2 messages. */ if (pErrorIfp->ifConf.rip2IfConfAuthType == M2_rip2IfConfAuthType_noAuthentication) { /* * Authentication is not enabled. Discard any RIP-2 messages * containing authentication entries. */ if (rip->rip_vers == 2) { pFirst = rip->rip_nets; if (ntohs(osa(pFirst->rip_dst)->sa_family) == RIP2_AUTH) { if (routedDebug) logMsg ("Discarding message with unused authentication.\n", 0, 0, 0, 0, 0, 0); pErrorIfp->ifStat.rip2IfStatRcvBadPackets++; return; } } /* Get the first rip entry for processing */ pFirst = n = rip->rip_nets; } else { /* * Authenticate message. All RIP-2 messages without authentication * entries are rejected. RIP-2 messages with the current MD5 key * or simple password are accepted. Under MD5 authentication, all * other RIP-2 messages and all RIP-1 messages are rejected. Under * simple password authentication, those messages are still accepted * if the hook routine returns OK but are rejected if no hook routine * is installed. */ if (rip->rip_vers == 2) { pFirst = rip->rip_nets; if (ntohs (osa (pFirst->rip_dst)->sa_family) != RIP2_AUTH) { if (routedDebug) logMsg ("Discarding unauthenticated RIP-2 message.\n", 0, 0, 0, 0, 0, 0); pErrorIfp->ifStat.rip2IfStatRcvBadPackets++; return; } }#ifdef RIP_MD5 /* * When MD5 authentication is active, the validation routine discards * all RIP-1 messages and any RIP-2 messages without a matching key. */ if (pErrorIfp->ifConf.rip2IfConfAuthType == M2_rip2IfConfAuthType_md5) { if (ripAuthKeyInMD5(pErrorIfp, rip, size) == ERROR) { if (routedDebug) logMsg ("Unable to authenticate RIP message.\n", 0, 0, 0, 0, 0, 0); return; } /* * Reduce the reported size to ignore the entry which contains * the MD5 authentication trailer (20 bytes). */ size -= sizeof(struct netinfo); } else if (pErrorIfp->ifConf.rip2IfConfAuthType == M2_rip2IfConfAuthType_simplePassword)#else if (pErrorIfp->ifConf.rip2IfConfAuthType == M2_rip2IfConfAuthType_simplePassword)#endif /* RIP_MD5 */ { /* * The ripAuthCheck() routine automatically accepts any RIP-2 * messages containing the correct simple password authentication * key. All other messages are handled by the authentication hook, * or discarded if none is available. */ if (ripAuthCheck (pErrorIfp->ifConf.rip2IfConfAuthKey, rip) == ERROR) { if (pErrorIfp->authHook) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -