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

📄 input.c

📁 VxWorks BSP框架源代码包含头文件和驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
        }    /*     * 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:            /*             * Preserve port number before converting source address to             * canonical form for testing against local interface addresses.             */            ((struct sockaddr_in *)&gateway)->sin_port =                 ((struct sockaddr_in *)from)->sin_port;                        /* Ignore requests reflected from a local interface. */            (*afp->af_canon) (from);            ifp = ripIfWithAddr (from);            if (ifp)                return;            /* Restore the port number for requests from valid interfaces. */            ((struct sockaddr_in *)from)->sin_port =                 ((struct sockaddr_in *)&gateway)->sin_port;            /*             * Determine number of entries in message. If there are no             * entries, no response is given.             */            count = size - ((char *)n - (char *)rip);            if (count < sizeof (struct netinfo))                return;            for (; count > 0; n++)                {                if (count < sizeof (struct netinfo))                    break;                count -= sizeof (struct netinfo);                if (rip->rip_vers == 1)                    {                    if ( ((RIP2PKT *)n)->tag != 0)                        {                        pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++;                        continue;                        }                    if ( ((RIP2PKT *)n)->subnet != 0)                        {                        pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++;                        continue;                        }                    if ( ((RIP2PKT *)n)->gateway != 0)                        {                        pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++;                        continue;                        }                    }                                n->rip_dst.sa_family = ntohs (osa (n->rip_dst)->sa_family);                n->rip_dst.sa_len = sizeof (n->rip_dst);                n->rip_metric = ntohl (n->rip_metric);                /*                  * Check for special case: the entire routing table is                 * sent if the message contains a single entry with a                  * family identifier of 0 (meaning unspecified: AF_UNSPEC)                  * and an infinite metric.                 */                if (n->rip_dst.sa_family == AF_UNSPEC &&                    (count != 0 || n != pFirst))                    {                    /*                     * Ignore entry with family of 0 if the message                      * contains multiple route entries.                     */                    pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++;                    continue;                    }                if (n->rip_dst.sa_family == AF_UNSPEC &&                    n->rip_metric != HOPCNT_INFINITY)                    {                    /*                      * Ignore message with single entry and family of 0                      * if metric is finite.                      */                    pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++;                    return;                    }                if (n->rip_dst.sa_family == AF_UNSPEC)                    {                    /*                      * Send the entire routing table, except for entries                     * learned from the interface which received the request.                     * Silent RIP processes will only respond to a query which                     * used a non-standard port. (RFC 1058, section 3.4.1).                     */                    if (ripState.supplier ||                        (*afp->af_portmatch)(from) == 0)                        {                        supply (from, 0, pErrorIfp, 0, rip->rip_vers);                        ripState.ripGlobal.rip2GlobalQueries++;                        }                    return;                    }                /*                  * Ignore entries with unsupported address families.                 * Currently, only entries with a family of AF_INET                  * are accepted.                 */                if (n->rip_dst.sa_family != AF_INET)                    {                    pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++;                    continue;                    }                if (n->rip_dst.sa_family < AF_MAX &&                    afswitch[n->rip_dst.sa_family].af_hash)                    {                    rt = rtlookup(&n->rip_dst);                    /*                     * If the interface for the route is down, the                     * route is not reachable.                     */                    if (rt && rt->rt_ifp && 			(rt->rt_ifp->int_flags & IFF_UP) == 0)                        rt = 0;                    }                else                    rt = 0;                n->rip_metric = rt == 0 ? HOPCNT_INFINITY :                    min(rt->rt_metric + 1, HOPCNT_INFINITY);                osa(n->rip_dst)->sa_family =                    htons(n->rip_dst.sa_family);                n->rip_metric = htonl(n->rip_metric);                changes++;                }            /*              * The RFC specification does not clearly define the desired             * behavior for the case where all entries in a request use              * an unknown family. Although the individual entries must             * be ignored, it seems as if a response containing unchanged              * metrics should be returned, but that behavior causes ANVL              * test 6.5 to fail. The following test avoids that problem.             */            if (changes)                {                /* Send a reply if at least one entry was recognized. */                rip->rip_cmd = RIPCMD_RESPONSE;                memmove(ripState.packet, rip, size);                (*afp->af_output)(ripState.s, 0, from, size);                ripState.ripGlobal.rip2GlobalQueries++;                }            return;                    case RIPCMD_TRACEON:        case RIPCMD_TRACEOFF:            /* Obsolete commands ignored by RIP. (RFC 1058, section 3.1) */            if (routedDebug)                logMsg ("Ignoring obsolete trace command from router %s.\n",                        (int)(*afswitch[from->sa_family].af_format)(from),                        0, 0, 0, 0, 0);            pErrorIfp->ifStat.rip2IfStatRcvBadPackets++;            return;                    case RIPCMD_RESPONSE:            /* Verify that the message used the required port. */            if ((*afp->af_portmatch)(from) == 0)                {                pErrorIfp->ifStat.rip2IfStatRcvBadPackets++;                return;                }            /*              * Check for reflected updates from the router's own interface.             * The test also eliminates updates from a directed broadcast             * address which is one of the illegal source addresses forbidden             * by the router requirements RFC.             */            (*afp->af_canon) (from);            ifp = ripIfWithAddr (from);            if (ifp)                {                /*                 * When a router receives an invalid update, it uses it to                  * track the status of a directly connected interface, but                  * the message is otherwise ignored.                 */                if (ifp->int_flags & IFF_PASSIVE)                    {                    if (routedDebug)                        logMsg ("bogus input (from passive interface, %s)\n",                             (int)(*afswitch[from->sa_family].af_format)(from),                                0, 0, 0, 0, 0);                    ifp->ifStat.rip2IfStatRcvBadPackets++;                    return;                    }                /*                  * Search for a route entry to the directly connected network                 * and reset the expiration timer if found. If no such route                 * is present or a non-interface route is detected, the                  * receiving interface was either recently added or restarted.                  * The addrouteforif routine will create a permanent interface                  * route and remove any overlapping (learned) route.                 */                rt = rtfind(from);                if (rt == 0 || (((rt->rt_state & RTS_INTERFACE) == 0) &&                    rt->rt_metric >= ifp->int_metric))                    addrouteforif(ifp);                else                    {                    rt->rt_timer = 0;                    /* Update age for IP group MIB. */                    if (rt->inKernel)                         ripRouteAgeUpdate (rt);                     }                return;                }            /*             * Update timer for interface route on which the message arrived.             * If none is found and the sender is the other end of a              * point-to-point link that isn't registered in the routing              * tables, add or restore that route.             */            if ((rt = rtfind(from)) &&                (rt->rt_state & (RTS_INTERFACE | RTS_REMOTE)))                {                rt->rt_timer = 0;                if (rt->inKernel)                     ripRouteAgeUpdate (rt); /* Update age for IP group MIB. */                }            else if ((ifp = ripIfWithDstAddr(from, NULL)) &&                     (rt == 0 || rt->rt_metric >= ifp->int_metric))                addrouteforif(ifp);            /*              * NOTE: The preceding rtfind() routine will not detect a              * match for updates from a router on the same supernet with              * a different class-based network number than the local             * interfaces. (For instance, it will not reset the route              * timer for 192.168.254.0/23 when an update is received              * from 192.168.255.x/23 if the local interface has the              * address 192.168.254.x/23. This omission has no effect              * because the timer for an interface route is never              * incremented. The return value of 0 will not cause an             * incorrect call to addrouteforif() because the search in             *  ripIfWithDstAddr will always fail in this situation.             */            /*             * Reset the pointer to validate the interface from which the             * message arrived. Updates are accepted from routers directly              * connected via broadcast or point-to-point networks.             */            ifp = pErrorIfp;    /* Results of ripIfLookup on source address. */            if ( (ifp->int_flags &                     (IFF_BROADCAST | IFF_POINTOPOINT | IFF_REMOTE)) == 0 ||                ifp->int_flags & IFF_PASSIVE)                {                /* Error: source does not use a directly-connected network. */                if (memcmp(from, &badfrom, sizeof(badfrom)) != 0)                    {                    if (routedDebug)                        logMsg ("packet from unknown router, %s\n",                             (int)(*afswitch[from->sa_family].af_format)(from),                                0, 0, 0, 0, 0);                    badfrom = *from;                    }                pErrorIfp->ifStat.rip2IfStatRcvBadPackets++;                return;                }            /*             * At this point, the source address and port number of the              * response have been checked. It is from another host on a              * directly connected network and was sent to the correct port.              * Begin processing the datagram by ignoring the initial data              * (command, version, and two unused bytes) and leading              * authentication header, if any.             */            size = size - ((char *)n - (char *)rip);            /* Now start processing actual route entries. */            for (; size > 0; size -= sizeof (struct netinfo), n++)                {                if (size < sizeof (struct netinfo))                    break;                n->rip_dst.sa_family =                    ntohs(osa(n->rip_dst)->sa_family);                n->rip_dst.sa_len = sizeof(n->rip_dst);                n->rip_metric = ntohl(n->rip_metric);                /* Ignore any entry with an unknown address family. */                if (n->rip_dst.sa_family >= AF_MAX ||                    (afp = &afswitch[n->rip_dst.sa_family])->af_hash ==                    (int (*)())0)                    {                    if (routedDebug)                        logMsg("route in unsupported address family %d from %s"                               "(af %d)\n", n->rip_dst.sa_family,                                (int)(*afswitch[from->sa_family].af_format)                               (from), from->sa_family, 0, 0, 0);                    pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++;                    continue;                    }                 /*                   * Ignore an entry if the unused fields are not zero.                  * (These fields are only unused in version 1 updates).                  */                if (rip->rip_vers == 1)                    {                    if ( ((RIP2PKT *)n)->tag != 0)                        {                        pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++;                        continue;                        }                    if ( ((RIP2PKT *)n)->subnet != 0)                        {                        pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++;                        continue;                        }                    if ( ((RIP2PKT *)n)->gateway != 0)                        {                        pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++;                        continue;                        }                    }                /*                  * Ignore any entry with an inappropriate address.                 * The receiving interface is used to detect broadcast                 * addresses if no netmask is present in the route update.                 */

⌨️ 快捷键说明

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