📄 input.c
字号:
} 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. */ if ( ((*afp->af_checkhost)(&n->rip_dst, ifp)) == 0) { if (routedDebug) logMsg ("bad host in route from %s (af %d)\n", (int)(*afswitch[from->sa_family].af_format)(from), from->sa_family, 0, 0, 0, 0); pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++; continue; } if ((n->rip_metric == 0) || ((unsigned) n->rip_metric > HOPCNT_INFINITY)) { if (memcmp(from, &badfrom2, sizeof(badfrom2)) != 0) { if (routedDebug) logMsg ("bad metric (%d) from %s\n", n->rip_metric, (int)(*afswitch[from->sa_family].af_format)(from), 0, 0, 0, 0); badfrom2 = *from; } pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++; continue; } rt = rtlookup (&n->rip_dst); /* * Do not allow a route learnt from other protocols to be * replaced */ if (rt && ((rt->rt_state & RTS_OTHER) != 0)) continue; if (rt == 0 || (rt->rt_state & (RTS_INTERNAL|RTS_INTERFACE)) == (RTS_INTERNAL|RTS_INTERFACE)) { /* * If we're hearing a logical network route * back from a peer to which we sent it, * ignore it. */ if (rt && rt->rt_state & RTS_SUBNET && (*afp->af_sendroute)(rt, from, ifp)) { pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++; continue; } /* * Adjust metric according to incoming interface. */ if ((unsigned)n->rip_metric < HOPCNT_INFINITY) { /* * Look for an equivalent route that * includes this one before adding * this route. */ rt = rtfind(&n->rip_dst); if ((rt && equal(from, &rt->rt_router)) && (rt->rt_metric <= n->rip_metric)) continue; n->rip_metric += ifp->int_metric; if (rip->rip_vers < 2) { rtadd (&n->rip_dst, from, n->rip_metric, 0, NULL, M2_ipRouteProto_rip, 0, ((struct sockaddr_in *)from)-> sin_addr.s_addr, pErrorIfp); } else { ripSplitPacket (ifp, (struct sockaddr_in *)from, &n->rip_dst, &gateway, &netmask, &tag); if (((struct sockaddr_in *)&netmask)-> sin_addr.s_addr == -1) { pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++; continue; } /* * RFC 1723, Section 3.4: check to see that the * gateway is directly reachable. If not, treat * that value as 0.0.0.0 by using the originator * as the gateway. */ if ((((struct sockaddr_in *)&gateway)-> sin_addr.s_addr & htonl (ifp->int_subnetmask)) != (((struct sockaddr_in *)&ifp->int_addr)-> sin_addr.s_addr & htonl (ifp->int_subnetmask))) { ((struct sockaddr_in *)&gateway)-> sin_addr.s_addr = ((struct sockaddr_in *)from)-> sin_addr.s_addr; } rtadd(&n->rip_dst, &gateway, n->rip_metric, 0, &netmask, M2_ipRouteProto_rip, tag, ((struct sockaddr_in *)from)-> sin_addr.s_addr, pErrorIfp); } changes++; } continue; } /* * Update if from gateway and different, * shorter, or equivalent but old route * is getting stale. */ /* * If this was a pre-existinng route then we can * update it to be "infinite" and should. * ANVL 7.13. */ origMetric = n->rip_metric; if ((unsigned) n->rip_metric < HOPCNT_INFINITY) n->rip_metric += ifp->int_metric; if (n->rip_metric > HOPCNT_INFINITY) { pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++; continue; } if (rip->rip_vers > 1) { ripSplitPacket(ifp, (struct sockaddr_in *)from, &n->rip_dst, &gateway, &netmask, &tag); if (((struct sockaddr_in *)&netmask)-> sin_addr.s_addr == -1) { pErrorIfp->ifStat.rip2IfStatRcvBadRoutes++; continue; } /* * RFC 1723, Section 3.4: check to see that the * gateway is directly reachable. If not, treat * that value as 0.0.0.0 by using the originator * as the gateway. */ if ((((struct sockaddr_in *)&gateway)->sin_addr.s_addr & htonl (ifp->int_subnetmask)) != (((struct sockaddr_in *)&ifp->int_addr)-> sin_addr.s_addr & htonl (ifp->int_subnetmask))) { ((struct sockaddr_in *)&gateway)->sin_addr.s_addr = ((struct sockaddr_in *)from)->sin_addr.s_addr; } } /* * We are making an assumption here that the address * is an internet address (4 bytes long). Since we currently * support only the AF_INET family its OK, but if that * changes, the following check will need to be changed * accordingly */ if (((struct sockaddr_in *)from)->sin_addr.s_addr == rt->rt_orgrouter)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -