📄 input.c
字号:
/* input.c - routines for processing incoming RIP messages *//* Copyright 1984 - 1999 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--------------------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"IMPORT int routedDebug;/* The random number generation limits the frequency of triggered updates. */LOCAL u_long ripRandTimeSeed = 1;LOCAL u_long ripRandTime (void);#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 );void timevaladd (struct timeval *t1, struct timeval *t2);IMPORT STATUS ripAuthCheck (char *, RIP_PKT *);/* * 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; IMPORT RIP ripState; 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; } } } else { /* * Authenticate message. All RIP-2 messages without authentication * entries are rejected. Other messages are accepted if the hook * routine returns OK. If no hook routine is installed, the * unvalidated RIP-2 messages are rejected and all RIP-1 messages * are also discarded for maximum security. */ 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; } } /* * 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) { if (pErrorIfp->authHook (pErrorIfp->ifConf.rip2IfConfAuthKey, rip) != OK) { pErrorIfp->ifStat.rip2IfStatRcvBadPackets++; return; } } else { if (routedDebug) logMsg ("Discarding unvalidated RIP version %d message.\n", rip->rip_vers, 0, 0, 0, 0, 0); pErrorIfp->ifStat.rip2IfStatRcvBadPackets++; return; } } } if (size > RIP_MAX_PACKET) { if (routedDebug) logMsg ("Packet too large 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 (((size - 4) % 20) != 0) { if (routedDebug) logMsg("Badly formed packet from %s. (cmd %d)\n", (int)(*afswitch[from->sa_family].af_format)(from), rip->rip_cmd, 0, 0, 0, 0); pErrorIfp->ifStat.rip2IfStatRcvBadPackets++; return; } /* Check that the unused RIP header field contains 0 if required. */ if (rip->rip_vers == 1) { if (rip->rip_domain[0] != 0 || rip->rip_domain[1] != 0) { pErrorIfp->ifStat.rip2IfStatRcvBadPackets++; return ; } } /* * Process the received message. RIP responses will exit the switch * statement so that triggered updates will be scheduled if necessary. * All other commands must execute return statements within the switch * to prevent that activity. */ switch (rip->rip_cmd) { case RIPCMD_REQUEST:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -