2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1983, 1988, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 /* walk the tree of routes with this for output
45 struct sockaddr_in to;
50 struct interface *ifp; /* usually output interface */
52 char metric; /* adjust metrics by interface */
56 #define WS_ST_FLASH 0x001 /* send only changed routes */
57 #define WS_ST_RIP2_ALL 0x002 /* send full featured RIPv2 */
58 #define WS_ST_AG 0x004 /* ok to aggregate subnets */
59 #define WS_ST_SUPER_AG 0x008 /* ok to aggregate networks */
60 #define WS_ST_QUERY 0x010 /* responding to a query */
61 #define WS_ST_TO_ON_NET 0x020 /* sending onto one of our nets */
62 #define WS_ST_DEFAULT 0x040 /* faking a default */
65 /* A buffer for what can be heard by both RIPv1 and RIPv2 listeners */
67 static union pkt_buf ripv12_buf;
69 /* Another for only RIPv2 listeners */
70 static struct ws_buf v2buf;
71 static union pkt_buf rip_v2_buf;
78 ripv12_buf.rip.rip_cmd = RIPCMD_RESPONSE;
79 v12buf.buf = &ripv12_buf.rip;
80 v12buf.base = &v12buf.buf->rip_nets[0];
82 rip_v2_buf.rip.rip_cmd = RIPCMD_RESPONSE;
83 rip_v2_buf.rip.rip_vers = RIPv2;
84 v2buf.buf = &rip_v2_buf.rip;
85 v2buf.base = &v2buf.buf->rip_nets[0];
89 /* Send the contents of the global buffer via the non-multicast socket
91 int /* <0 on failure */
92 output(enum output_type type,
93 struct sockaddr_in *dst, /* send to here */
94 struct interface *ifp,
96 int size) /* this many bytes */
98 struct sockaddr_in osin;
107 if (osin.sin_port == 0)
108 osin.sin_port = htons(RIP_PORT);
110 if (osin.sin_len == 0)
111 osin.sin_len = sizeof(osin);
119 msg = "Answer Query";
121 soc = ifp->int_rip_sock;
126 soc = ifp->int_rip_sock;
127 flags = MSG_DONTROUTE;
130 if (ifp->int_if_flags & IFF_POINTOPOINT) {
135 flags = MSG_DONTROUTE;
138 if ((ifp->int_if_flags & (IFF_POINTOPOINT|IFF_MULTICAST)) ==
140 msg = "Send pt-to-pt";
141 } else if (ifp->int_state & IS_DUP) {
142 trace_act("abort multicast output via %s"
143 " with duplicate address",
148 if (rip_sock_mcast != ifp) {
149 struct ip_mreqn mreqn;
151 memset(&mreqn, 0, sizeof(struct ip_mreqn));
152 mreqn.imr_ifindex = ifp->int_index;
153 if (0 > setsockopt(rip_sock,
159 LOGERR("setsockopt(rip_sock, "
165 rip_sock_mcast = ifp;
167 osin.sin_addr.s_addr = htonl(INADDR_RIP_GROUP);
171 case NO_OUT_MULTICAST:
180 trace_rip(msg, "to", &osin, ifp, buf, size);
182 res = sendto(soc, buf, size, flags,
183 (struct sockaddr *)&osin, sizeof(osin));
185 && (ifp == NULL || !(ifp->int_state & IS_BROKE))) {
187 msglog("%s sendto(%s%s%s.%d): %s", msg,
188 ifp != NULL ? ifp->int_name : "",
189 ifp != NULL ? ", " : "",
190 inet_ntoa(osin.sin_addr),
191 ntohs(osin.sin_port),
200 /* Find the first key for a packet to send.
201 * Try for a key that is eligible and has not expired, but settle for
202 * the last key if they have all expired.
203 * If no key is ready yet, give up.
206 find_auth(struct interface *ifp)
208 struct auth *ap, *res;
217 for (i = 0; i < MAX_AUTH_KEYS; i++, ap++) {
218 /* stop looking after the last key */
219 if (ap->type == RIP_AUTH_NONE)
222 /* ignore keys that are not ready yet */
223 if ((u_long)ap->start > (u_long)clk.tv_sec)
226 if ((u_long)ap->end < (u_long)clk.tv_sec) {
227 /* note best expired password as a fall-back */
228 if (res == NULL || (u_long)ap->end > (u_long)res->end)
233 /* note key with the best future */
234 if (res == NULL || (u_long)res->end < (u_long)ap->end)
242 clr_ws_buf(struct ws_buf *wb,
247 wb->lim = wb->base + NETS_LEN;
249 memset(wb->n, 0, NETS_LEN*sizeof(*wb->n));
251 /* (start to) install authentication if appropriate
256 na = (struct netauth*)wb->n;
257 if (ap->type == RIP_AUTH_PW) {
258 na->a_family = RIP_AF_AUTH;
259 na->a_type = RIP_AUTH_PW;
260 memcpy(na->au.au_pw, ap->key, sizeof(na->au.au_pw));
263 } else if (ap->type == RIP_AUTH_MD5) {
264 na->a_family = RIP_AF_AUTH;
265 na->a_type = RIP_AUTH_MD5;
266 na->au.a_md5.md5_keyid = ap->keyid;
267 na->au.a_md5.md5_auth_len = RIP_AUTH_MD5_KEY_LEN;
268 na->au.a_md5.md5_seqno = htonl(clk.tv_sec);
270 wb->lim--; /* make room for trailer */
276 end_md5_auth(struct ws_buf *wb,
279 struct netauth *na, *na2;
284 na = (struct netauth*)wb->base;
285 na2 = (struct netauth*)wb->n;
286 len = (char *)na2-(char *)wb->buf;
287 na2->a_family = RIP_AF_AUTH;
288 na2->a_type = htons(1);
289 na->au.a_md5.md5_pkt_len = htons(len);
291 MD5Update(&md5_ctx, (u_char *)wb->buf, len + RIP_AUTH_MD5_HASH_XTRA);
292 MD5Update(&md5_ctx, ap->key, RIP_AUTH_MD5_KEY_LEN);
293 MD5Final(na2->au.au_pw, &md5_ctx);
301 supply_write(struct ws_buf *wb)
303 /* Output multicast only if legal.
304 * If we would multicast and it would be illegal, then discard the
308 case NO_OUT_MULTICAST:
309 trace_pkt("skip multicast to %s because impossible",
310 naddr_ntoa(ws.to.sin_addr.s_addr));
315 if (ws.a != NULL && ws.a->type == RIP_AUTH_MD5)
316 end_md5_auth(wb,ws.a);
317 if (output(wb->type, &ws.to, ws.ifp, wb->buf,
318 ((char *)wb->n - (char*)wb->buf)) < 0
329 /* put an entry into the packet
332 supply_out(struct ag_info *ag)
335 naddr mask, v1_mask, dst_h, ddst_h = 0;
339 /* Skip this route if doing a flash update and it and the routes
340 * it aggregates have not changed recently.
342 if (ag->ag_seqno < update_seqno
343 && (ws.state & WS_ST_FLASH))
346 dst_h = ag->ag_dst_h;
348 v1_mask = ripv1_mask_host(htonl(dst_h),
349 (ws.state & WS_ST_TO_ON_NET) ? ws.ifp : 0);
352 /* If we are sending RIPv2 packets that cannot (or must not) be
353 * heard by RIPv1 listeners, do not worry about sub- or supernets.
354 * Subnets (from other networks) can only be sent via multicast.
355 * A pair of subnet routes might have been promoted so that they
356 * are legal to send by RIPv1.
357 * If RIPv1 is off, use the multicast buffer.
359 if ((ws.state & WS_ST_RIP2_ALL)
360 || ((ag->ag_state & AGS_RIPV2) && v1_mask != mask)) {
361 /* use the RIPv2-only buffer */
365 /* use the RIPv1-or-RIPv2 buffer */
368 /* Convert supernet route into corresponding set of network
369 * routes for RIPv1, but leave non-contiguous netmasks
373 && mask + (mask & -mask) == 0) {
374 ddst_h = v1_mask & -v1_mask;
375 i = (v1_mask & ~mask)/ddst_h;
377 if (i > ws.gen_limit) {
378 /* Punt if we would have to generate an
379 * unreasonable number of routes.
382 trace_misc("sending %s-->%s as 1"
383 " instead of %d routes",
384 addrname(htonl(dst_h), mask,
386 naddr_ntoa(ws.to.sin_addr
399 wb->n->n_family = RIP_AF_INET;
400 wb->n->n_dst = htonl(dst_h);
401 /* If the route is from router-discovery or we are
402 * shutting down, admit only a bad metric.
404 wb->n->n_metric = ((stopint || ag->ag_metric < 1)
407 wb->n->n_metric = htonl(wb->n->n_metric);
408 /* Any non-zero bits in the supposedly unused RIPv1 fields
409 * cause the old `routed` to ignore the route.
410 * That means the mask and so forth cannot be sent
411 * in the hybrid RIPv1/RIPv2 mode.
413 if (ws.state & WS_ST_RIP2_ALL) {
415 && ((ws.state & WS_ST_QUERY)
416 || (ag->ag_nhop != ws.ifp->int_addr
417 && on_net(ag->ag_nhop,
420 wb->n->n_nhop = ag->ag_nhop;
421 wb->n->n_mask = htonl(mask);
422 wb->n->n_tag = ag->ag_tag;
426 if (++wb->n >= wb->lim)
432 /* supply one route from the table
436 walk_supply(struct radix_node *rn,
437 struct walkarg *argp UNUSED)
439 #define RT ((struct rt_entry *)rn)
443 struct rt_spare *rts;
447 /* Do not advertise external remote interfaces or passive interfaces.
449 if ((RT->rt_state & RS_IF)
451 && (RT->rt_ifp->int_state & IS_PASSIVE)
452 && !(RT->rt_state & RS_MHOME))
455 /* If being quiet about our ability to forward, then
456 * do not say anything unless responding to a query,
457 * except about our main interface.
459 if (!supplier && !(ws.state & WS_ST_QUERY)
460 && !(RT->rt_state & RS_MHOME))
465 /* do not collide with the fake default route */
466 if (dst == RIP_DEFAULT
467 && (ws.state & WS_ST_DEFAULT))
470 if (RT->rt_state & RS_NET_SYN) {
471 if (RT->rt_state & RS_NET_INT) {
472 /* Do not send manual synthetic network routes
475 if (on_net(ws.to.sin_addr.s_addr,
476 ntohl(dst), RT->rt_mask))
480 /* Do not send automatic synthetic network routes
481 * if they are not needed because no RIPv1 listeners
484 if (ws.state & WS_ST_RIP2_ALL)
487 /* Do not send automatic synthetic network routes to
490 if (on_net(ws.to.sin_addr.s_addr,
491 ntohl(dst), RT->rt_mask))
497 /* Advertise the next hop if this is not a route for one
498 * of our interfaces and the next hop is on the same
499 * network as the target.
500 * The final determination is made by supply_out().
502 if (!(RT->rt_state & RS_IF)
503 && RT->rt_gate != myaddr
504 && RT->rt_gate != loopaddr)
510 metric = RT->rt_metric;
513 if (RT->rt_state & RS_MHOME) {
514 /* retain host route of multi-homed servers */
517 } else if (RT_ISHOST(RT)) {
518 /* We should always suppress (into existing network routes)
519 * the host routes for the local end of our point-to-point
521 * If we are suppressing host routes in general, then do so.
522 * Avoid advertising host routes onto their own network,
523 * where they should be handled by proxy-ARP.
525 if ((RT->rt_state & RS_LOCAL)
527 || on_net(dst, ws.to_net, ws.to_mask))
530 /* Aggregate stray host routes into network routes if allowed.
531 * We cannot aggregate host routes into small network routes
532 * without confusing RIPv1 listeners into thinking the
533 * network routes are host routes.
535 if ((ws.state & WS_ST_AG) && (ws.state & WS_ST_RIP2_ALL))
536 ags |= AGS_AGGREGATE;
539 /* Always suppress network routes into other, existing
544 /* Generate supernets if allowed.
545 * If we can be heard by RIPv1 systems, we will
546 * later convert back to ordinary nets.
547 * This unifies dealing with received supernets.
549 if ((ws.state & WS_ST_AG)
550 && ((RT->rt_state & RS_SUBNET)
551 || (ws.state & WS_ST_SUPER_AG)))
552 ags |= AGS_AGGREGATE;
555 /* Do not send RIPv1 advertisements of subnets to other
556 * networks. If possible, multicast them by RIPv2.
558 if ((RT->rt_state & RS_SUBNET)
559 && !(ws.state & WS_ST_RIP2_ALL)
560 && !on_net(dst, ws.to_std_net, ws.to_std_mask))
561 ags |= AGS_RIPV2 | AGS_AGGREGATE;
564 /* Do not send a route back to where it came from, except in
565 * response to a query. This is "split-horizon". That means not
566 * advertising back to the same network and so via the same interface.
568 * We want to suppress routes that might have been fragmented
569 * from this route by a RIPv1 router and sent back to us, and so we
570 * cannot forget this route here. Let the split-horizon route
571 * suppress the fragmented routes and then itself be forgotten.
573 * Include the routes for both ends of point-to-point interfaces
574 * among those suppressed by split-horizon, since the other side
575 * should knows them as well as we do.
577 * Notice spare routes with the same metric that we are about to
578 * advertise, to split the horizon on redundant, inactive paths.
580 * Do not suppress advertisements of interface-related addresses on
581 * non-point-to-point interfaces. This ensures that we have something
582 * to say every 30 seconds to help detect broken Ethernets or
583 * other interfaces where one packet every 30 seconds costs nothing.
586 && !(ws.state & WS_ST_QUERY)
587 && (ws.state & WS_ST_TO_ON_NET)
588 && (!(RT->rt_state & RS_IF)
589 || ws.ifp->int_if_flags & IFF_POINTOPOINT)) {
590 for (rts = RT->rt_spares, i = NUM_SPARES; i != 0; i--, rts++) {
591 if (rts->rts_metric > metric
592 || rts->rts_ifp != ws.ifp)
595 /* If we do not mark the route with AGS_SPLIT_HZ here,
596 * it will be poisoned-reverse, or advertised back
597 * toward its source with an infinite metric.
598 * If we have recently advertised the route with a
599 * better metric than we now have, then we should
600 * poison-reverse the route before suppressing it for
603 * In almost all cases, if there is no spare for the
604 * route then it is either old and dead or a brand
605 * new route. If it is brand new, there is no need
606 * for poison-reverse. If it is old and dead, it
607 * is already poisoned.
609 if (RT->rt_poison_time < now_expire
610 || RT->rt_poison_metric >= metric
611 || RT->rt_spares[1].rts_gate == 0) {
613 ags &= ~AGS_SUPPRESS;
615 metric = HOPCNT_INFINITY;
620 /* Keep track of the best metric with which the
621 * route has been advertised recently.
623 if (RT->rt_poison_metric >= metric
624 || RT->rt_poison_time < now_expire) {
625 RT->rt_poison_time = now.tv_sec;
626 RT->rt_poison_metric = metric;
629 /* Adjust the outgoing metric by the cost of the link.
630 * Avoid aggregation when a route is counting to infinity.
632 pref = RT->rt_poison_metric + ws.metric;
635 /* Do not advertise stable routes that will be ignored,
636 * unless we are answering a query.
637 * If the route recently was advertised with a metric that
638 * would have been less than infinity through this interface,
639 * we need to continue to advertise it in order to poison it.
641 if (metric >= HOPCNT_INFINITY) {
642 if (!(ws.state & WS_ST_QUERY)
643 && (pref >= HOPCNT_INFINITY
644 || RT->rt_poison_time < now_garbage))
647 metric = HOPCNT_INFINITY;
650 ag_check(dst, RT->rt_mask, 0, nhop, metric, pref,
651 RT->rt_seqno, RT->rt_tag, ags, supply_out);
657 /* Supply dst with the contents of the routing tables.
658 * If this won't fit in one packet, chop it up into several.
661 supply(struct sockaddr_in *dst,
662 struct interface *ifp, /* output interface */
663 enum output_type type,
664 int flash, /* 1=flash update */
665 int vers, /* RIP version */
666 int passwd_ok) /* OK to include cleartext password */
675 ws.to_std_mask = std_mask(ws.to.sin_addr.s_addr);
676 ws.to_std_net = ntohl(ws.to.sin_addr.s_addr) & ws.to_std_mask;
679 ws.to_mask = ifp->int_mask;
680 ws.to_net = ifp->int_net;
681 if (on_net(ws.to.sin_addr.s_addr, ws.to_net, ws.to_mask))
682 ws.state |= WS_ST_TO_ON_NET;
685 ws.to_mask = ripv1_mask_net(ws.to.sin_addr.s_addr, 0);
686 ws.to_net = ntohl(ws.to.sin_addr.s_addr) & ws.to_mask;
687 rt = rtfind(dst->sin_addr.s_addr);
694 ws.state |= WS_ST_FLASH;
696 if ((ws.ifp = ifp) == NULL) {
699 /* Adjust the advertised metric by the outgoing interface
702 ws.metric = ifp->int_metric + 1 + ifp->int_adj_outmetric;
705 ripv12_buf.rip.rip_vers = vers;
709 if (ifp != NULL && ifp->int_if_flags & IFF_MULTICAST)
710 v2buf.type = OUT_MULTICAST;
712 v2buf.type = NO_OUT_MULTICAST;
713 v12buf.type = OUT_BROADCAST;
717 ws.state |= WS_ST_QUERY;
721 v2buf.type = (vers == RIPv2) ? type : NO_OUT_RIPV2;
725 case NO_OUT_MULTICAST:
727 break; /* no output */
731 /* full RIPv2 only if cannot be heard by RIPv1 listeners */
732 if (type != OUT_BROADCAST)
733 ws.state |= WS_ST_RIP2_ALL;
734 if ((ws.state & WS_ST_QUERY)
735 || !(ws.state & WS_ST_TO_ON_NET)) {
736 ws.state |= (WS_ST_AG | WS_ST_SUPER_AG);
737 } else if (ifp == NULL || !(ifp->int_state & IS_NO_AG)) {
738 ws.state |= WS_ST_AG;
739 if (type != OUT_BROADCAST
741 || !(ifp->int_state & IS_NO_SUPER_AG)))
742 ws.state |= WS_ST_SUPER_AG;
746 ws.a = (vers == RIPv2) ? find_auth(ifp) : 0;
747 if (!passwd_ok && ws.a != NULL && ws.a->type == RIP_AUTH_PW)
749 clr_ws_buf(&v12buf,ws.a);
750 clr_ws_buf(&v2buf,ws.a);
752 /* Fake a default route if asked and if there is not already
753 * a better, real default route.
755 if (supplier && ifp && (def_metric = ifp->int_d_metric) != 0) {
756 if ((rt = rtget(RIP_DEFAULT, 0)) == NULL
757 || rt->rt_metric+ws.metric >= def_metric) {
758 ws.state |= WS_ST_DEFAULT;
759 ag_check(0, 0, 0, 0, def_metric, def_metric,
760 0, 0, 0, supply_out);
762 def_metric = rt->rt_metric+ws.metric;
765 /* If both RIPv2 and the poor-man's router discovery
766 * kludge are on, arrange to advertise an extra
767 * default route via RIPv1.
769 if ((ws.state & WS_ST_RIP2_ALL)
770 && (ifp->int_state & IS_PM_RDISC)) {
771 ripv12_buf.rip.rip_vers = RIPv1;
772 v12buf.n->n_family = RIP_AF_INET;
773 v12buf.n->n_dst = htonl(RIP_DEFAULT);
774 v12buf.n->n_metric = htonl(def_metric);
779 (void)rn_walktree(rhead, walk_supply, 0);
780 ag_flush(0,0,supply_out);
782 /* Flush the packet buffers, provided they are not empty and
783 * do not contain only the password.
785 if (v12buf.n != v12buf.base
786 && (v12buf.n > v12buf.base+1
787 || v12buf.base->n_family != RIP_AF_AUTH))
788 supply_write(&v12buf);
789 if (v2buf.n != v2buf.base
790 && (v2buf.n > v2buf.base+1
791 || v2buf.base->n_family != RIP_AF_AUTH))
792 supply_write(&v2buf);
794 /* If we sent nothing and this is an answer to a query, send
798 && (ws.state & WS_ST_QUERY))
799 supply_write(&v12buf);
803 /* send all of the routing table or just do a flash update
809 static struct sockaddr_in dst = {sizeof(dst), AF_INET, 0, {0}, {0}};
811 static struct sockaddr_in dst = {AF_INET};
813 struct interface *ifp;
814 enum output_type type;
816 struct timeval rtime;
820 intvl_random(&rtime, MIN_WAITTIME, MAX_WAITTIME);
822 timevaladd(&no_flash, &now);
827 trace_act("send %s and inhibit dynamic updates for %.3f sec",
828 flash ? "dynamic update" : "all routes",
829 rtime.tv_sec + ((float)rtime.tv_usec)/1000000.0);
831 LIST_FOREACH(ifp, &ifnet, int_list) {
832 /* Skip interfaces not doing RIP.
833 * Do try broken interfaces to see if they have healed.
835 if (IS_RIP_OUT_OFF(ifp->int_state))
838 /* skip turned off interfaces */
839 if (!iff_up(ifp->int_if_flags))
842 vers = (ifp->int_state & IS_NO_RIPV1_OUT) ? RIPv2 : RIPv1;
844 if (ifp->int_if_flags & IFF_BROADCAST) {
845 /* ordinary, hardware interface */
846 dst.sin_addr.s_addr = ifp->int_brdaddr;
849 && !(ifp->int_state & IS_NO_RIP_MCAST)) {
850 type = OUT_MULTICAST;
852 type = OUT_BROADCAST;
855 } else if (ifp->int_if_flags & IFF_POINTOPOINT) {
856 /* point-to-point hardware interface */
857 dst.sin_addr.s_addr = ifp->int_dstaddr;
859 ifp->int_if_flags & IFF_MULTICAST &&
860 !(ifp->int_state & IS_NO_RIP_MCAST)) {
861 type = OUT_MULTICAST;
866 } else if (ifp->int_state & IS_REMOTE) {
867 /* remote interface */
868 dst.sin_addr.s_addr = ifp->int_addr;
872 /* ATM, HIPPI, etc. */
876 supply(&dst, ifp, type, flash, vers, 1);
879 update_seqno++; /* all routes are up to date */
884 * Do it only once to an interface, and not even after the interface
885 * was broken and recovered.
891 static struct sockaddr_in dst = {sizeof(dst), AF_INET, 0, {0}, {0}};
893 static struct sockaddr_in dst = {AF_INET};
895 struct interface *ifp;
897 enum output_type type;
903 memset(&buf, 0, sizeof(buf));
905 LIST_FOREACH(ifp, &ifnet, int_list) {
906 /* Skip interfaces those already queried.
907 * Do not ask via interfaces through which we don't
908 * accept input. Do not ask via interfaces that cannot
910 * Do try broken interfaces to see if they have healed.
912 if (IS_RIP_IN_OFF(ifp->int_state)
913 || ifp->int_query_time != NEVER)
916 /* skip turned off interfaces */
917 if (!iff_up(ifp->int_if_flags))
920 buf.rip_vers = (ifp->int_state&IS_NO_RIPV1_OUT) ? RIPv2:RIPv1;
921 buf.rip_cmd = RIPCMD_REQUEST;
922 buf.rip_nets[0].n_family = RIP_AF_UNSPEC;
923 buf.rip_nets[0].n_metric = htonl(HOPCNT_INFINITY);
925 /* Send a RIPv1 query only if allowed and if we will
926 * listen to RIPv1 routers.
928 if ((ifp->int_state & IS_NO_RIPV1_OUT)
929 || (ifp->int_state & IS_NO_RIPV1_IN)) {
930 buf.rip_vers = RIPv2;
932 buf.rip_vers = RIPv1;
935 if (ifp->int_if_flags & IFF_BROADCAST) {
936 /* ordinary, hardware interface */
937 dst.sin_addr.s_addr = ifp->int_brdaddr;
939 /* Broadcast RIPv1 queries and RIPv2 queries
940 * when the hardware cannot multicast.
942 if (buf.rip_vers == RIPv2
943 && (ifp->int_if_flags & IFF_MULTICAST)
944 && !(ifp->int_state & IS_NO_RIP_MCAST)) {
945 type = OUT_MULTICAST;
947 type = OUT_BROADCAST;
950 } else if (ifp->int_if_flags & IFF_POINTOPOINT) {
951 /* point-to-point hardware interface */
952 dst.sin_addr.s_addr = ifp->int_dstaddr;
955 } else if (ifp->int_state & IS_REMOTE) {
956 /* remote interface */
957 dst.sin_addr.s_addr = ifp->int_addr;
961 /* ATM, HIPPI, etc. */
965 ifp->int_query_time = now.tv_sec+SUPPLY_INTERVAL;
966 if (output(type, &dst, ifp, &buf, sizeof(buf)) < 0)