2 * Copyright (c) 1983, 1988, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #elif defined(__FreeBSD__)
39 __RCSID("$Revision: 2.27 $");
40 #ident "$Revision: 2.27 $"
47 /* walk the tree of routes with this for output
50 struct sockaddr_in to;
55 struct interface *ifp; /* usually output interface */
57 char metric; /* adjust metrics by interface */
61 #define WS_ST_FLASH 0x001 /* send only changed routes */
62 #define WS_ST_RIP2_ALL 0x002 /* send full featured RIPv2 */
63 #define WS_ST_AG 0x004 /* ok to aggregate subnets */
64 #define WS_ST_SUPER_AG 0x008 /* ok to aggregate networks */
65 #define WS_ST_QUERY 0x010 /* responding to a query */
66 #define WS_ST_TO_ON_NET 0x020 /* sending onto one of our nets */
67 #define WS_ST_DEFAULT 0x040 /* faking a default */
70 /* A buffer for what can be heard by both RIPv1 and RIPv2 listeners */
72 static union pkt_buf ripv12_buf;
74 /* Another for only RIPv2 listeners */
75 static struct ws_buf v2buf;
76 static union pkt_buf rip_v2_buf;
83 ripv12_buf.rip.rip_cmd = RIPCMD_RESPONSE;
84 v12buf.buf = &ripv12_buf.rip;
85 v12buf.base = &v12buf.buf->rip_nets[0];
87 rip_v2_buf.rip.rip_cmd = RIPCMD_RESPONSE;
88 rip_v2_buf.rip.rip_vers = RIPv2;
89 v2buf.buf = &rip_v2_buf.rip;
90 v2buf.base = &v2buf.buf->rip_nets[0];
94 /* Send the contents of the global buffer via the non-multicast socket
96 int /* <0 on failure */
97 output(enum output_type type,
98 struct sockaddr_in *dst, /* send to here */
99 struct interface *ifp,
101 int size) /* this many bytes */
103 struct sockaddr_in osin;
112 if (osin.sin_port == 0)
113 osin.sin_port = htons(RIP_PORT);
115 if (osin.sin_len == 0)
116 osin.sin_len = sizeof(osin);
124 msg = "Answer Query";
126 soc = ifp->int_rip_sock;
131 soc = ifp->int_rip_sock;
132 flags = MSG_DONTROUTE;
135 if (ifp->int_if_flags & IFF_POINTOPOINT) {
140 flags = MSG_DONTROUTE;
143 if ((ifp->int_if_flags & (IFF_POINTOPOINT|IFF_MULTICAST)) ==
145 msg = "Send pt-to-pt";
146 } else if (ifp->int_state & IS_DUP) {
147 trace_act("abort multicast output via %s"
148 " with duplicate address",
153 if (rip_sock_mcast != ifp) {
154 struct ip_mreqn mreqn;
156 memset(&mreqn, 0, sizeof(struct ip_mreqn));
157 mreqn.imr_ifindex = ifp->int_index;
158 if (0 > setsockopt(rip_sock,
164 LOGERR("setsockopt(rip_sock, "
170 rip_sock_mcast = ifp;
172 osin.sin_addr.s_addr = htonl(INADDR_RIP_GROUP);
176 case NO_OUT_MULTICAST:
185 trace_rip(msg, "to", &osin, ifp, buf, size);
187 res = sendto(soc, buf, size, flags,
188 (struct sockaddr *)&osin, sizeof(osin));
190 && (ifp == 0 || !(ifp->int_state & IS_BROKE))) {
192 msglog("%s sendto(%s%s%s.%d): %s", msg,
193 ifp != 0 ? ifp->int_name : "",
194 ifp != 0 ? ", " : "",
195 inet_ntoa(osin.sin_addr),
196 ntohs(osin.sin_port),
205 /* Find the first key for a packet to send.
206 * Try for a key that is eligible and has not expired, but settle for
207 * the last key if they have all expired.
208 * If no key is ready yet, give up.
211 find_auth(struct interface *ifp)
213 struct auth *ap, *res;
222 for (i = 0; i < MAX_AUTH_KEYS; i++, ap++) {
223 /* stop looking after the last key */
224 if (ap->type == RIP_AUTH_NONE)
227 /* ignore keys that are not ready yet */
228 if ((u_long)ap->start > (u_long)clk.tv_sec)
231 if ((u_long)ap->end < (u_long)clk.tv_sec) {
232 /* note best expired password as a fall-back */
233 if (res == 0 || (u_long)ap->end > (u_long)res->end)
238 /* note key with the best future */
239 if (res == 0 || (u_long)res->end < (u_long)ap->end)
247 clr_ws_buf(struct ws_buf *wb,
252 wb->lim = wb->base + NETS_LEN;
254 memset(wb->n, 0, NETS_LEN*sizeof(*wb->n));
256 /* (start to) install authentication if appropriate
261 na = (struct netauth*)wb->n;
262 if (ap->type == RIP_AUTH_PW) {
263 na->a_family = RIP_AF_AUTH;
264 na->a_type = RIP_AUTH_PW;
265 memcpy(na->au.au_pw, ap->key, sizeof(na->au.au_pw));
268 } else if (ap->type == RIP_AUTH_MD5) {
269 na->a_family = RIP_AF_AUTH;
270 na->a_type = RIP_AUTH_MD5;
271 na->au.a_md5.md5_keyid = ap->keyid;
272 na->au.a_md5.md5_auth_len = RIP_AUTH_MD5_KEY_LEN;
273 na->au.a_md5.md5_seqno = htonl(clk.tv_sec);
275 wb->lim--; /* make room for trailer */
281 end_md5_auth(struct ws_buf *wb,
284 struct netauth *na, *na2;
289 na = (struct netauth*)wb->base;
290 na2 = (struct netauth*)wb->n;
291 len = (char *)na2-(char *)wb->buf;
292 na2->a_family = RIP_AF_AUTH;
293 na2->a_type = htons(1);
294 na->au.a_md5.md5_pkt_len = htons(len);
296 MD5Update(&md5_ctx, (u_char *)wb->buf, len + RIP_AUTH_MD5_HASH_XTRA);
297 MD5Update(&md5_ctx, ap->key, RIP_AUTH_MD5_KEY_LEN);
298 MD5Final(na2->au.au_pw, &md5_ctx);
306 supply_write(struct ws_buf *wb)
308 /* Output multicast only if legal.
309 * If we would multicast and it would be illegal, then discard the
313 case NO_OUT_MULTICAST:
314 trace_pkt("skip multicast to %s because impossible",
315 naddr_ntoa(ws.to.sin_addr.s_addr));
320 if (ws.a != 0 && ws.a->type == RIP_AUTH_MD5)
321 end_md5_auth(wb,ws.a);
322 if (output(wb->type, &ws.to, ws.ifp, wb->buf,
323 ((char *)wb->n - (char*)wb->buf)) < 0
334 /* put an entry into the packet
337 supply_out(struct ag_info *ag)
340 naddr mask, v1_mask, dst_h, ddst_h = 0;
344 /* Skip this route if doing a flash update and it and the routes
345 * it aggregates have not changed recently.
347 if (ag->ag_seqno < update_seqno
348 && (ws.state & WS_ST_FLASH))
351 dst_h = ag->ag_dst_h;
353 v1_mask = ripv1_mask_host(htonl(dst_h),
354 (ws.state & WS_ST_TO_ON_NET) ? ws.ifp : 0);
357 /* If we are sending RIPv2 packets that cannot (or must not) be
358 * heard by RIPv1 listeners, do not worry about sub- or supernets.
359 * Subnets (from other networks) can only be sent via multicast.
360 * A pair of subnet routes might have been promoted so that they
361 * are legal to send by RIPv1.
362 * If RIPv1 is off, use the multicast buffer.
364 if ((ws.state & WS_ST_RIP2_ALL)
365 || ((ag->ag_state & AGS_RIPV2) && v1_mask != mask)) {
366 /* use the RIPv2-only buffer */
370 /* use the RIPv1-or-RIPv2 buffer */
373 /* Convert supernet route into corresponding set of network
374 * routes for RIPv1, but leave non-contiguous netmasks
378 && mask + (mask & -mask) == 0) {
379 ddst_h = v1_mask & -v1_mask;
380 i = (v1_mask & ~mask)/ddst_h;
382 if (i > ws.gen_limit) {
383 /* Punt if we would have to generate an
384 * unreasonable number of routes.
387 trace_misc("sending %s-->%s as 1"
388 " instead of %d routes",
389 addrname(htonl(dst_h), mask,
391 naddr_ntoa(ws.to.sin_addr
404 wb->n->n_family = RIP_AF_INET;
405 wb->n->n_dst = htonl(dst_h);
406 /* If the route is from router-discovery or we are
407 * shutting down, admit only a bad metric.
409 wb->n->n_metric = ((stopint || ag->ag_metric < 1)
412 wb->n->n_metric = htonl(wb->n->n_metric);
413 /* Any non-zero bits in the supposedly unused RIPv1 fields
414 * cause the old `routed` to ignore the route.
415 * That means the mask and so forth cannot be sent
416 * in the hybrid RIPv1/RIPv2 mode.
418 if (ws.state & WS_ST_RIP2_ALL) {
420 && ((ws.state & WS_ST_QUERY)
421 || (ag->ag_nhop != ws.ifp->int_addr
422 && on_net(ag->ag_nhop,
425 wb->n->n_nhop = ag->ag_nhop;
426 wb->n->n_mask = htonl(mask);
427 wb->n->n_tag = ag->ag_tag;
431 if (++wb->n >= wb->lim)
437 /* supply one route from the table
441 walk_supply(struct radix_node *rn,
442 struct walkarg *argp UNUSED)
444 #define RT ((struct rt_entry *)rn)
448 struct rt_spare *rts;
452 /* Do not advertise external remote interfaces or passive interfaces.
454 if ((RT->rt_state & RS_IF)
456 && (RT->rt_ifp->int_state & IS_PASSIVE)
457 && !(RT->rt_state & RS_MHOME))
460 /* If being quiet about our ability to forward, then
461 * do not say anything unless responding to a query,
462 * except about our main interface.
464 if (!supplier && !(ws.state & WS_ST_QUERY)
465 && !(RT->rt_state & RS_MHOME))
470 /* do not collide with the fake default route */
471 if (dst == RIP_DEFAULT
472 && (ws.state & WS_ST_DEFAULT))
475 if (RT->rt_state & RS_NET_SYN) {
476 if (RT->rt_state & RS_NET_INT) {
477 /* Do not send manual synthetic network routes
480 if (on_net(ws.to.sin_addr.s_addr,
481 ntohl(dst), RT->rt_mask))
485 /* Do not send automatic synthetic network routes
486 * if they are not needed because no RIPv1 listeners
489 if (ws.state & WS_ST_RIP2_ALL)
492 /* Do not send automatic synthetic network routes to
495 if (on_net(ws.to.sin_addr.s_addr,
496 ntohl(dst), RT->rt_mask))
502 /* Advertise the next hop if this is not a route for one
503 * of our interfaces and the next hop is on the same
504 * network as the target.
505 * The final determination is made by supply_out().
507 if (!(RT->rt_state & RS_IF)
508 && RT->rt_gate != myaddr
509 && RT->rt_gate != loopaddr)
515 metric = RT->rt_metric;
518 if (RT->rt_state & RS_MHOME) {
519 /* retain host route of multi-homed servers */
522 } else if (RT_ISHOST(RT)) {
523 /* We should always suppress (into existing network routes)
524 * the host routes for the local end of our point-to-point
526 * If we are suppressing host routes in general, then do so.
527 * Avoid advertising host routes onto their own network,
528 * where they should be handled by proxy-ARP.
530 if ((RT->rt_state & RS_LOCAL)
532 || on_net(dst, ws.to_net, ws.to_mask))
535 /* Aggregate stray host routes into network routes if allowed.
536 * We cannot aggregate host routes into small network routes
537 * without confusing RIPv1 listeners into thinking the
538 * network routes are host routes.
540 if ((ws.state & WS_ST_AG) && (ws.state & WS_ST_RIP2_ALL))
541 ags |= AGS_AGGREGATE;
544 /* Always suppress network routes into other, existing
549 /* Generate supernets if allowed.
550 * If we can be heard by RIPv1 systems, we will
551 * later convert back to ordinary nets.
552 * This unifies dealing with received supernets.
554 if ((ws.state & WS_ST_AG)
555 && ((RT->rt_state & RS_SUBNET)
556 || (ws.state & WS_ST_SUPER_AG)))
557 ags |= AGS_AGGREGATE;
560 /* Do not send RIPv1 advertisements of subnets to other
561 * networks. If possible, multicast them by RIPv2.
563 if ((RT->rt_state & RS_SUBNET)
564 && !(ws.state & WS_ST_RIP2_ALL)
565 && !on_net(dst, ws.to_std_net, ws.to_std_mask))
566 ags |= AGS_RIPV2 | AGS_AGGREGATE;
569 /* Do not send a route back to where it came from, except in
570 * response to a query. This is "split-horizon". That means not
571 * advertising back to the same network and so via the same interface.
573 * We want to suppress routes that might have been fragmented
574 * from this route by a RIPv1 router and sent back to us, and so we
575 * cannot forget this route here. Let the split-horizon route
576 * suppress the fragmented routes and then itself be forgotten.
578 * Include the routes for both ends of point-to-point interfaces
579 * among those suppressed by split-horizon, since the other side
580 * should knows them as well as we do.
582 * Notice spare routes with the same metric that we are about to
583 * advertise, to split the horizon on redundant, inactive paths.
585 * Do not suppress advertisements of interface-related addresses on
586 * non-point-to-point interfaces. This ensures that we have something
587 * to say every 30 seconds to help detect broken Ethernets or
588 * other interfaces where one packet every 30 seconds costs nothing.
591 && !(ws.state & WS_ST_QUERY)
592 && (ws.state & WS_ST_TO_ON_NET)
593 && (!(RT->rt_state & RS_IF)
594 || ws.ifp->int_if_flags & IFF_POINTOPOINT)) {
595 for (rts = RT->rt_spares, i = NUM_SPARES; i != 0; i--, rts++) {
596 if (rts->rts_metric > metric
597 || rts->rts_ifp != ws.ifp)
600 /* If we do not mark the route with AGS_SPLIT_HZ here,
601 * it will be poisoned-reverse, or advertised back
602 * toward its source with an infinite metric.
603 * If we have recently advertised the route with a
604 * better metric than we now have, then we should
605 * poison-reverse the route before suppressing it for
608 * In almost all cases, if there is no spare for the
609 * route then it is either old and dead or a brand
610 * new route. If it is brand new, there is no need
611 * for poison-reverse. If it is old and dead, it
612 * is already poisoned.
614 if (RT->rt_poison_time < now_expire
615 || RT->rt_poison_metric >= metric
616 || RT->rt_spares[1].rts_gate == 0) {
618 ags &= ~AGS_SUPPRESS;
620 metric = HOPCNT_INFINITY;
625 /* Keep track of the best metric with which the
626 * route has been advertised recently.
628 if (RT->rt_poison_metric >= metric
629 || RT->rt_poison_time < now_expire) {
630 RT->rt_poison_time = now.tv_sec;
631 RT->rt_poison_metric = metric;
634 /* Adjust the outgoing metric by the cost of the link.
635 * Avoid aggregation when a route is counting to infinity.
637 pref = RT->rt_poison_metric + ws.metric;
640 /* Do not advertise stable routes that will be ignored,
641 * unless we are answering a query.
642 * If the route recently was advertised with a metric that
643 * would have been less than infinity through this interface,
644 * we need to continue to advertise it in order to poison it.
646 if (metric >= HOPCNT_INFINITY) {
647 if (!(ws.state & WS_ST_QUERY)
648 && (pref >= HOPCNT_INFINITY
649 || RT->rt_poison_time < now_garbage))
652 metric = HOPCNT_INFINITY;
655 ag_check(dst, RT->rt_mask, 0, nhop, metric, pref,
656 RT->rt_seqno, RT->rt_tag, ags, supply_out);
662 /* Supply dst with the contents of the routing tables.
663 * If this won't fit in one packet, chop it up into several.
666 supply(struct sockaddr_in *dst,
667 struct interface *ifp, /* output interface */
668 enum output_type type,
669 int flash, /* 1=flash update */
670 int vers, /* RIP version */
671 int passwd_ok) /* OK to include cleartext password */
682 ws.to_std_mask = std_mask(ws.to.sin_addr.s_addr);
683 ws.to_std_net = ntohl(ws.to.sin_addr.s_addr) & ws.to_std_mask;
686 ws.to_mask = ifp->int_mask;
687 ws.to_net = ifp->int_net;
688 if (on_net(ws.to.sin_addr.s_addr, ws.to_net, ws.to_mask))
689 ws.state |= WS_ST_TO_ON_NET;
692 ws.to_mask = ripv1_mask_net(ws.to.sin_addr.s_addr, 0);
693 ws.to_net = ntohl(ws.to.sin_addr.s_addr) & ws.to_mask;
694 rt = rtfind(dst->sin_addr.s_addr);
701 ws.state |= WS_ST_FLASH;
703 if ((ws.ifp = ifp) == 0) {
706 /* Adjust the advertised metric by the outgoing interface
709 ws.metric = ifp->int_metric + 1 + ifp->int_adj_outmetric;
712 ripv12_buf.rip.rip_vers = vers;
716 if (ifp->int_if_flags & IFF_MULTICAST)
717 v2buf.type = OUT_MULTICAST;
719 v2buf.type = NO_OUT_MULTICAST;
720 v12buf.type = OUT_BROADCAST;
724 ws.state |= WS_ST_QUERY;
728 v2buf.type = (vers == RIPv2) ? type : NO_OUT_RIPV2;
732 case NO_OUT_MULTICAST:
734 break; /* no output */
738 /* full RIPv2 only if cannot be heard by RIPv1 listeners */
739 if (type != OUT_BROADCAST)
740 ws.state |= WS_ST_RIP2_ALL;
741 if ((ws.state & WS_ST_QUERY)
742 || !(ws.state & WS_ST_TO_ON_NET)) {
743 ws.state |= (WS_ST_AG | WS_ST_SUPER_AG);
744 } else if (ifp == 0 || !(ifp->int_state & IS_NO_AG)) {
745 ws.state |= WS_ST_AG;
746 if (type != OUT_BROADCAST
748 || !(ifp->int_state & IS_NO_SUPER_AG)))
749 ws.state |= WS_ST_SUPER_AG;
753 ws.a = (vers == RIPv2) ? find_auth(ifp) : 0;
754 if (!passwd_ok && ws.a != 0 && ws.a->type == RIP_AUTH_PW)
756 clr_ws_buf(&v12buf,ws.a);
757 clr_ws_buf(&v2buf,ws.a);
759 /* Fake a default route if asked and if there is not already
760 * a better, real default route.
762 if (supplier && (def_metric = ifp->int_d_metric) != 0) {
763 if (0 == (rt = rtget(RIP_DEFAULT, 0))
764 || rt->rt_metric+ws.metric >= def_metric) {
765 ws.state |= WS_ST_DEFAULT;
766 ag_check(0, 0, 0, 0, def_metric, def_metric,
767 0, 0, 0, supply_out);
769 def_metric = rt->rt_metric+ws.metric;
772 /* If both RIPv2 and the poor-man's router discovery
773 * kludge are on, arrange to advertise an extra
774 * default route via RIPv1.
776 if ((ws.state & WS_ST_RIP2_ALL)
777 && (ifp->int_state & IS_PM_RDISC)) {
778 ripv12_buf.rip.rip_vers = RIPv1;
779 v12buf.n->n_family = RIP_AF_INET;
780 v12buf.n->n_dst = htonl(RIP_DEFAULT);
781 v12buf.n->n_metric = htonl(def_metric);
786 (void)rn_walktree(rhead, walk_supply, 0);
787 ag_flush(0,0,supply_out);
789 /* Flush the packet buffers, provided they are not empty and
790 * do not contain only the password.
792 if (v12buf.n != v12buf.base
793 && (v12buf.n > v12buf.base+1
794 || v12buf.base->n_family != RIP_AF_AUTH))
795 supply_write(&v12buf);
796 if (v2buf.n != v2buf.base
797 && (v2buf.n > v2buf.base+1
798 || v2buf.base->n_family != RIP_AF_AUTH))
799 supply_write(&v2buf);
801 /* If we sent nothing and this is an answer to a query, send
805 && (ws.state & WS_ST_QUERY))
806 supply_write(&v12buf);
810 /* send all of the routing table or just do a flash update
816 static struct sockaddr_in dst = {sizeof(dst), AF_INET, 0, {0}, {0}};
818 static struct sockaddr_in dst = {AF_INET};
820 struct interface *ifp;
821 enum output_type type;
823 struct timeval rtime;
827 intvl_random(&rtime, MIN_WAITTIME, MAX_WAITTIME);
829 timevaladd(&no_flash, &now);
834 trace_act("send %s and inhibit dynamic updates for %.3f sec",
835 flash ? "dynamic update" : "all routes",
836 rtime.tv_sec + ((float)rtime.tv_usec)/1000000.0);
838 LIST_FOREACH(ifp, &ifnet, int_list) {
839 /* Skip interfaces not doing RIP.
840 * Do try broken interfaces to see if they have healed.
842 if (IS_RIP_OUT_OFF(ifp->int_state))
845 /* skip turned off interfaces */
846 if (!iff_up(ifp->int_if_flags))
849 vers = (ifp->int_state & IS_NO_RIPV1_OUT) ? RIPv2 : RIPv1;
851 if (ifp->int_if_flags & IFF_BROADCAST) {
852 /* ordinary, hardware interface */
853 dst.sin_addr.s_addr = ifp->int_brdaddr;
856 && !(ifp->int_state & IS_NO_RIP_MCAST)) {
857 type = OUT_MULTICAST;
859 type = OUT_BROADCAST;
862 } else if (ifp->int_if_flags & IFF_POINTOPOINT) {
863 /* point-to-point hardware interface */
864 dst.sin_addr.s_addr = ifp->int_dstaddr;
866 ifp->int_if_flags & IFF_MULTICAST &&
867 !(ifp->int_state & IS_NO_RIP_MCAST)) {
868 type = OUT_MULTICAST;
873 } else if (ifp->int_state & IS_REMOTE) {
874 /* remote interface */
875 dst.sin_addr.s_addr = ifp->int_addr;
879 /* ATM, HIPPI, etc. */
883 supply(&dst, ifp, type, flash, vers, 1);
886 update_seqno++; /* all routes are up to date */
891 * Do it only once to an interface, and not even after the interface
892 * was broken and recovered.
898 static struct sockaddr_in dst = {sizeof(dst), AF_INET, 0, {0}, {0}};
900 static struct sockaddr_in dst = {AF_INET};
902 struct interface *ifp;
904 enum output_type type;
910 memset(&buf, 0, sizeof(buf));
912 LIST_FOREACH(ifp, &ifnet, int_list) {
913 /* Skip interfaces those already queried.
914 * Do not ask via interfaces through which we don't
915 * accept input. Do not ask via interfaces that cannot
917 * Do try broken interfaces to see if they have healed.
919 if (IS_RIP_IN_OFF(ifp->int_state)
920 || ifp->int_query_time != NEVER)
923 /* skip turned off interfaces */
924 if (!iff_up(ifp->int_if_flags))
927 buf.rip_vers = (ifp->int_state&IS_NO_RIPV1_OUT) ? RIPv2:RIPv1;
928 buf.rip_cmd = RIPCMD_REQUEST;
929 buf.rip_nets[0].n_family = RIP_AF_UNSPEC;
930 buf.rip_nets[0].n_metric = htonl(HOPCNT_INFINITY);
932 /* Send a RIPv1 query only if allowed and if we will
933 * listen to RIPv1 routers.
935 if ((ifp->int_state & IS_NO_RIPV1_OUT)
936 || (ifp->int_state & IS_NO_RIPV1_IN)) {
937 buf.rip_vers = RIPv2;
939 buf.rip_vers = RIPv1;
942 if (ifp->int_if_flags & IFF_BROADCAST) {
943 /* ordinary, hardware interface */
944 dst.sin_addr.s_addr = ifp->int_brdaddr;
946 /* Broadcast RIPv1 queries and RIPv2 queries
947 * when the hardware cannot multicast.
949 if (buf.rip_vers == RIPv2
950 && (ifp->int_if_flags & IFF_MULTICAST)
951 && !(ifp->int_state & IS_NO_RIP_MCAST)) {
952 type = OUT_MULTICAST;
954 type = OUT_BROADCAST;
957 } else if (ifp->int_if_flags & IFF_POINTOPOINT) {
958 /* point-to-point hardware interface */
959 dst.sin_addr.s_addr = ifp->int_dstaddr;
962 } else if (ifp->int_state & IS_REMOTE) {
963 /* remote interface */
964 dst.sin_addr.s_addr = ifp->int_addr;
968 /* ATM, HIPPI, etc. */
972 ifp->int_query_time = now.tv_sec+SUPPLY_INTERVAL;
973 if (output(type, &dst, ifp, &buf, sizeof(buf)) < 0)