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 union pkt_buf ripv12_buf;
74 /* Another for only RIPv2 listeners */
76 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;
111 if (osin.sin_port == 0)
112 osin.sin_port = htons(RIP_PORT);
114 if (osin.sin_len == 0)
115 osin.sin_len = sizeof(osin);
123 msg = "Answer Query";
125 soc = ifp->int_rip_sock;
130 soc = ifp->int_rip_sock;
131 flags = MSG_DONTROUTE;
134 if (ifp->int_if_flags & IFF_POINTOPOINT) {
139 flags = MSG_DONTROUTE;
142 if (ifp->int_if_flags & IFF_POINTOPOINT) {
143 msg = "Send pt-to-pt";
144 } else if (ifp->int_state & IS_DUP) {
145 trace_act("abort multicast output via %s"
146 " with duplicate address",
151 if (rip_sock_mcast != ifp) {
152 struct ip_mreqn mreqn;
154 memset(&mreqn, 0, sizeof(struct ip_mreqn));
155 mreqn.imr_ifindex = ifp->int_index;
156 if (0 > setsockopt(rip_sock,
162 LOGERR("setsockopt(rip_sock, "
168 rip_sock_mcast = ifp;
170 osin.sin_addr.s_addr = htonl(INADDR_RIP_GROUP);
174 case NO_OUT_MULTICAST:
183 trace_rip(msg, "to", &osin, ifp, buf, size);
185 res = sendto(soc, buf, size, flags,
186 (struct sockaddr *)&osin, sizeof(osin));
188 && (ifp == 0 || !(ifp->int_state & IS_BROKE))) {
190 msglog("%s sendto(%s%s%s.%d): %s", msg,
191 ifp != 0 ? ifp->int_name : "",
192 ifp != 0 ? ", " : "",
193 inet_ntoa(osin.sin_addr),
194 ntohs(osin.sin_port),
203 /* Find the first key for a packet to send.
204 * Try for a key that is eligible and has not expired, but settle for
205 * the last key if they have all expired.
206 * If no key is ready yet, give up.
209 find_auth(struct interface *ifp)
211 struct auth *ap, *res;
220 for (i = 0; i < MAX_AUTH_KEYS; i++, ap++) {
221 /* stop looking after the last key */
222 if (ap->type == RIP_AUTH_NONE)
225 /* ignore keys that are not ready yet */
226 if ((u_long)ap->start > (u_long)clk.tv_sec)
229 if ((u_long)ap->end < (u_long)clk.tv_sec) {
230 /* note best expired password as a fall-back */
231 if (res == 0 || (u_long)ap->end > (u_long)res->end)
236 /* note key with the best future */
237 if (res == 0 || (u_long)res->end < (u_long)ap->end)
245 clr_ws_buf(struct ws_buf *wb,
250 wb->lim = wb->base + NETS_LEN;
252 memset(wb->n, 0, NETS_LEN*sizeof(*wb->n));
254 /* (start to) install authentication if appropriate
259 na = (struct netauth*)wb->n;
260 if (ap->type == RIP_AUTH_PW) {
261 na->a_family = RIP_AF_AUTH;
262 na->a_type = RIP_AUTH_PW;
263 memcpy(na->au.au_pw, ap->key, sizeof(na->au.au_pw));
266 } else if (ap->type == RIP_AUTH_MD5) {
267 na->a_family = RIP_AF_AUTH;
268 na->a_type = RIP_AUTH_MD5;
269 na->au.a_md5.md5_keyid = ap->keyid;
270 na->au.a_md5.md5_auth_len = RIP_AUTH_MD5_KEY_LEN;
271 na->au.a_md5.md5_seqno = htonl(clk.tv_sec);
273 wb->lim--; /* make room for trailer */
279 end_md5_auth(struct ws_buf *wb,
282 struct netauth *na, *na2;
287 na = (struct netauth*)wb->base;
288 na2 = (struct netauth*)wb->n;
289 len = (char *)na2-(char *)wb->buf;
290 na2->a_family = RIP_AF_AUTH;
291 na2->a_type = htons(1);
292 na->au.a_md5.md5_pkt_len = htons(len);
294 MD5Update(&md5_ctx, (u_char *)wb->buf, len + RIP_AUTH_MD5_HASH_XTRA);
295 MD5Update(&md5_ctx, ap->key, RIP_AUTH_MD5_KEY_LEN);
296 MD5Final(na2->au.au_pw, &md5_ctx);
304 supply_write(struct ws_buf *wb)
306 /* Output multicast only if legal.
307 * If we would multicast and it would be illegal, then discard the
311 case NO_OUT_MULTICAST:
312 trace_pkt("skip multicast to %s because impossible",
313 naddr_ntoa(ws.to.sin_addr.s_addr));
318 if (ws.a != 0 && ws.a->type == RIP_AUTH_MD5)
319 end_md5_auth(wb,ws.a);
320 if (output(wb->type, &ws.to, ws.ifp, wb->buf,
321 ((char *)wb->n - (char*)wb->buf)) < 0
332 /* put an entry into the packet
335 supply_out(struct ag_info *ag)
338 naddr mask, v1_mask, dst_h, ddst_h = 0;
342 /* Skip this route if doing a flash update and it and the routes
343 * it aggregates have not changed recently.
345 if (ag->ag_seqno < update_seqno
346 && (ws.state & WS_ST_FLASH))
349 dst_h = ag->ag_dst_h;
351 v1_mask = ripv1_mask_host(htonl(dst_h),
352 (ws.state & WS_ST_TO_ON_NET) ? ws.ifp : 0);
355 /* If we are sending RIPv2 packets that cannot (or must not) be
356 * heard by RIPv1 listeners, do not worry about sub- or supernets.
357 * Subnets (from other networks) can only be sent via multicast.
358 * A pair of subnet routes might have been promoted so that they
359 * are legal to send by RIPv1.
360 * If RIPv1 is off, use the multicast buffer.
362 if ((ws.state & WS_ST_RIP2_ALL)
363 || ((ag->ag_state & AGS_RIPV2) && v1_mask != mask)) {
364 /* use the RIPv2-only buffer */
368 /* use the RIPv1-or-RIPv2 buffer */
371 /* Convert supernet route into corresponding set of network
372 * routes for RIPv1, but leave non-contiguous netmasks
376 && mask + (mask & -mask) == 0) {
377 ddst_h = v1_mask & -v1_mask;
378 i = (v1_mask & ~mask)/ddst_h;
380 if (i > ws.gen_limit) {
381 /* Punt if we would have to generate an
382 * unreasonable number of routes.
385 trace_misc("sending %s-->%s as 1"
386 " instead of %d routes",
387 addrname(htonl(dst_h), mask,
389 naddr_ntoa(ws.to.sin_addr
402 wb->n->n_family = RIP_AF_INET;
403 wb->n->n_dst = htonl(dst_h);
404 /* If the route is from router-discovery or we are
405 * shutting down, admit only a bad metric.
407 wb->n->n_metric = ((stopint || ag->ag_metric < 1)
410 wb->n->n_metric = htonl(wb->n->n_metric);
411 /* Any non-zero bits in the supposedly unused RIPv1 fields
412 * cause the old `routed` to ignore the route.
413 * That means the mask and so forth cannot be sent
414 * in the hybrid RIPv1/RIPv2 mode.
416 if (ws.state & WS_ST_RIP2_ALL) {
418 && ((ws.state & WS_ST_QUERY)
419 || (ag->ag_nhop != ws.ifp->int_addr
420 && on_net(ag->ag_nhop,
423 wb->n->n_nhop = ag->ag_nhop;
424 wb->n->n_mask = htonl(mask);
425 wb->n->n_tag = ag->ag_tag;
429 if (++wb->n >= wb->lim)
435 /* supply one route from the table
439 walk_supply(struct radix_node *rn,
440 struct walkarg *argp UNUSED)
442 #define RT ((struct rt_entry *)rn)
446 struct rt_spare *rts;
450 /* Do not advertise external remote interfaces or passive interfaces.
452 if ((RT->rt_state & RS_IF)
454 && (RT->rt_ifp->int_state & IS_PASSIVE)
455 && !(RT->rt_state & RS_MHOME))
458 /* If being quiet about our ability to forward, then
459 * do not say anything unless responding to a query,
460 * except about our main interface.
462 if (!supplier && !(ws.state & WS_ST_QUERY)
463 && !(RT->rt_state & RS_MHOME))
468 /* do not collide with the fake default route */
469 if (dst == RIP_DEFAULT
470 && (ws.state & WS_ST_DEFAULT))
473 if (RT->rt_state & RS_NET_SYN) {
474 if (RT->rt_state & RS_NET_INT) {
475 /* Do not send manual synthetic network routes
478 if (on_net(ws.to.sin_addr.s_addr,
479 ntohl(dst), RT->rt_mask))
483 /* Do not send automatic synthetic network routes
484 * if they are not needed because no RIPv1 listeners
487 if (ws.state & WS_ST_RIP2_ALL)
490 /* Do not send automatic synthetic network routes to
493 if (on_net(ws.to.sin_addr.s_addr,
494 ntohl(dst), RT->rt_mask))
500 /* Advertise the next hop if this is not a route for one
501 * of our interfaces and the next hop is on the same
502 * network as the target.
503 * The final determination is made by supply_out().
505 if (!(RT->rt_state & RS_IF)
506 && RT->rt_gate != myaddr
507 && RT->rt_gate != loopaddr)
513 metric = RT->rt_metric;
516 if (RT->rt_state & RS_MHOME) {
517 /* retain host route of multi-homed servers */
520 } else if (RT_ISHOST(RT)) {
521 /* We should always suppress (into existing network routes)
522 * the host routes for the local end of our point-to-point
524 * If we are suppressing host routes in general, then do so.
525 * Avoid advertising host routes onto their own network,
526 * where they should be handled by proxy-ARP.
528 if ((RT->rt_state & RS_LOCAL)
530 || on_net(dst, ws.to_net, ws.to_mask))
533 /* Aggregate stray host routes into network routes if allowed.
534 * We cannot aggregate host routes into small network routes
535 * without confusing RIPv1 listeners into thinking the
536 * network routes are host routes.
538 if ((ws.state & WS_ST_AG) && (ws.state & WS_ST_RIP2_ALL))
539 ags |= AGS_AGGREGATE;
542 /* Always suppress network routes into other, existing
547 /* Generate supernets if allowed.
548 * If we can be heard by RIPv1 systems, we will
549 * later convert back to ordinary nets.
550 * This unifies dealing with received supernets.
552 if ((ws.state & WS_ST_AG)
553 && ((RT->rt_state & RS_SUBNET)
554 || (ws.state & WS_ST_SUPER_AG)))
555 ags |= AGS_AGGREGATE;
558 /* Do not send RIPv1 advertisements of subnets to other
559 * networks. If possible, multicast them by RIPv2.
561 if ((RT->rt_state & RS_SUBNET)
562 && !(ws.state & WS_ST_RIP2_ALL)
563 && !on_net(dst, ws.to_std_net, ws.to_std_mask))
564 ags |= AGS_RIPV2 | AGS_AGGREGATE;
567 /* Do not send a route back to where it came from, except in
568 * response to a query. This is "split-horizon". That means not
569 * advertising back to the same network and so via the same interface.
571 * We want to suppress routes that might have been fragmented
572 * from this route by a RIPv1 router and sent back to us, and so we
573 * cannot forget this route here. Let the split-horizon route
574 * suppress the fragmented routes and then itself be forgotten.
576 * Include the routes for both ends of point-to-point interfaces
577 * among those suppressed by split-horizon, since the other side
578 * should knows them as well as we do.
580 * Notice spare routes with the same metric that we are about to
581 * advertise, to split the horizon on redundant, inactive paths.
583 * Do not suppress advertisements of interface-related addresses on
584 * non-point-to-point interfaces. This ensures that we have something
585 * to say every 30 seconds to help detect broken Ethernets or
586 * other interfaces where one packet every 30 seconds costs nothing.
589 && !(ws.state & WS_ST_QUERY)
590 && (ws.state & WS_ST_TO_ON_NET)
591 && (!(RT->rt_state & RS_IF)
592 || ws.ifp->int_if_flags & IFF_POINTOPOINT)) {
593 for (rts = RT->rt_spares, i = NUM_SPARES; i != 0; i--, rts++) {
594 if (rts->rts_metric > metric
595 || rts->rts_ifp != ws.ifp)
598 /* If we do not mark the route with AGS_SPLIT_HZ here,
599 * it will be poisoned-reverse, or advertised back
600 * toward its source with an infinite metric.
601 * If we have recently advertised the route with a
602 * better metric than we now have, then we should
603 * poison-reverse the route before suppressing it for
606 * In almost all cases, if there is no spare for the
607 * route then it is either old and dead or a brand
608 * new route. If it is brand new, there is no need
609 * for poison-reverse. If it is old and dead, it
610 * is already poisoned.
612 if (RT->rt_poison_time < now_expire
613 || RT->rt_poison_metric >= metric
614 || RT->rt_spares[1].rts_gate == 0) {
616 ags &= ~AGS_SUPPRESS;
618 metric = HOPCNT_INFINITY;
623 /* Keep track of the best metric with which the
624 * route has been advertised recently.
626 if (RT->rt_poison_metric >= metric
627 || RT->rt_poison_time < now_expire) {
628 RT->rt_poison_time = now.tv_sec;
629 RT->rt_poison_metric = metric;
632 /* Adjust the outgoing metric by the cost of the link.
633 * Avoid aggregation when a route is counting to infinity.
635 pref = RT->rt_poison_metric + ws.metric;
638 /* Do not advertise stable routes that will be ignored,
639 * unless we are answering a query.
640 * If the route recently was advertised with a metric that
641 * would have been less than infinity through this interface,
642 * we need to continue to advertise it in order to poison it.
644 if (metric >= HOPCNT_INFINITY) {
645 if (!(ws.state & WS_ST_QUERY)
646 && (pref >= HOPCNT_INFINITY
647 || RT->rt_poison_time < now_garbage))
650 metric = HOPCNT_INFINITY;
653 ag_check(dst, RT->rt_mask, 0, nhop, metric, pref,
654 RT->rt_seqno, RT->rt_tag, ags, supply_out);
660 /* Supply dst with the contents of the routing tables.
661 * If this won't fit in one packet, chop it up into several.
664 supply(struct sockaddr_in *dst,
665 struct interface *ifp, /* output interface */
666 enum output_type type,
667 int flash, /* 1=flash update */
668 int vers, /* RIP version */
669 int passwd_ok) /* OK to include cleartext password */
679 ws.to_std_mask = std_mask(ws.to.sin_addr.s_addr);
680 ws.to_std_net = ntohl(ws.to.sin_addr.s_addr) & ws.to_std_mask;
683 ws.to_mask = ifp->int_mask;
684 ws.to_net = ifp->int_net;
685 if (on_net(ws.to.sin_addr.s_addr, ws.to_net, ws.to_mask))
686 ws.state |= WS_ST_TO_ON_NET;
689 ws.to_mask = ripv1_mask_net(ws.to.sin_addr.s_addr, 0);
690 ws.to_net = ntohl(ws.to.sin_addr.s_addr) & ws.to_mask;
691 rt = rtfind(dst->sin_addr.s_addr);
698 ws.state |= WS_ST_FLASH;
700 if ((ws.ifp = ifp) == 0) {
703 /* Adjust the advertised metric by the outgoing interface
706 ws.metric = ifp->int_metric + 1 + ifp->int_adj_outmetric;
709 ripv12_buf.rip.rip_vers = vers;
713 if (ifp->int_if_flags & IFF_MULTICAST)
714 v2buf.type = OUT_MULTICAST;
716 v2buf.type = NO_OUT_MULTICAST;
717 v12buf.type = OUT_BROADCAST;
721 ws.state |= WS_ST_QUERY;
725 v2buf.type = (vers == RIPv2) ? type : NO_OUT_RIPV2;
729 case NO_OUT_MULTICAST:
731 break; /* no output */
735 /* full RIPv2 only if cannot be heard by RIPv1 listeners */
736 if (type != OUT_BROADCAST)
737 ws.state |= WS_ST_RIP2_ALL;
738 if ((ws.state & WS_ST_QUERY)
739 || !(ws.state & WS_ST_TO_ON_NET)) {
740 ws.state |= (WS_ST_AG | WS_ST_SUPER_AG);
741 } else if (ifp == 0 || !(ifp->int_state & IS_NO_AG)) {
742 ws.state |= WS_ST_AG;
743 if (type != OUT_BROADCAST
745 || !(ifp->int_state & IS_NO_SUPER_AG)))
746 ws.state |= WS_ST_SUPER_AG;
750 ws.a = (vers == RIPv2) ? find_auth(ifp) : 0;
751 if (!passwd_ok && ws.a != 0 && ws.a->type == RIP_AUTH_PW)
753 clr_ws_buf(&v12buf,ws.a);
754 clr_ws_buf(&v2buf,ws.a);
756 /* Fake a default route if asked and if there is not already
757 * a better, real default route.
759 if (supplier && (def_metric = ifp->int_d_metric) != 0) {
760 if (0 == (rt = rtget(RIP_DEFAULT, 0))
761 || rt->rt_metric+ws.metric >= def_metric) {
762 ws.state |= WS_ST_DEFAULT;
763 ag_check(0, 0, 0, 0, def_metric, def_metric,
764 0, 0, 0, supply_out);
766 def_metric = rt->rt_metric+ws.metric;
769 /* If both RIPv2 and the poor-man's router discovery
770 * kludge are on, arrange to advertise an extra
771 * default route via RIPv1.
773 if ((ws.state & WS_ST_RIP2_ALL)
774 && (ifp->int_state & IS_PM_RDISC)) {
775 ripv12_buf.rip.rip_vers = RIPv1;
776 v12buf.n->n_family = RIP_AF_INET;
777 v12buf.n->n_dst = htonl(RIP_DEFAULT);
778 v12buf.n->n_metric = htonl(def_metric);
783 (void)rn_walktree(rhead, walk_supply, 0);
784 ag_flush(0,0,supply_out);
786 /* Flush the packet buffers, provided they are not empty and
787 * do not contain only the password.
789 if (v12buf.n != v12buf.base
790 && (v12buf.n > v12buf.base+1
791 || v12buf.base->n_family != RIP_AF_AUTH))
792 supply_write(&v12buf);
793 if (v2buf.n != v2buf.base
794 && (v2buf.n > v2buf.base+1
795 || v2buf.base->n_family != RIP_AF_AUTH))
796 supply_write(&v2buf);
798 /* If we sent nothing and this is an answer to a query, send
802 && (ws.state & WS_ST_QUERY))
803 supply_write(&v12buf);
807 /* send all of the routing table or just do a flash update
813 static struct sockaddr_in dst = {sizeof(dst), AF_INET, 0, {0}, {0}};
815 static struct sockaddr_in dst = {AF_INET};
817 struct interface *ifp;
818 enum output_type type;
820 struct timeval rtime;
824 intvl_random(&rtime, MIN_WAITTIME, MAX_WAITTIME);
826 timevaladd(&no_flash, &now);
831 trace_act("send %s and inhibit dynamic updates for %.3f sec",
832 flash ? "dynamic update" : "all routes",
833 rtime.tv_sec + ((float)rtime.tv_usec)/1000000.0);
835 for (ifp = ifnet; ifp != 0; ifp = ifp->int_next) {
836 /* Skip interfaces not doing RIP.
837 * Do try broken interfaces to see if they have healed.
839 if (IS_RIP_OUT_OFF(ifp->int_state))
842 /* skip turned off interfaces */
843 if (!iff_up(ifp->int_if_flags))
846 vers = (ifp->int_state & IS_NO_RIPV1_OUT) ? RIPv2 : RIPv1;
848 if (ifp->int_if_flags & IFF_BROADCAST) {
849 /* ordinary, hardware interface */
850 dst.sin_addr.s_addr = ifp->int_brdaddr;
853 && !(ifp->int_state & IS_NO_RIP_MCAST)) {
854 type = OUT_MULTICAST;
856 type = OUT_BROADCAST;
859 } else if (ifp->int_if_flags & IFF_POINTOPOINT) {
860 /* point-to-point hardware interface */
861 dst.sin_addr.s_addr = ifp->int_dstaddr;
864 } else if (ifp->int_state & IS_REMOTE) {
865 /* remote interface */
866 dst.sin_addr.s_addr = ifp->int_addr;
870 /* ATM, HIPPI, etc. */
874 supply(&dst, ifp, type, flash, vers, 1);
877 update_seqno++; /* all routes are up to date */
882 * Do it only once to an interface, and not even after the interface
883 * was broken and recovered.
889 static struct sockaddr_in dst = {sizeof(dst), AF_INET, 0, {0}, {0}};
891 static struct sockaddr_in dst = {AF_INET};
893 struct interface *ifp;
895 enum output_type type;
901 memset(&buf, 0, sizeof(buf));
903 for (ifp = ifnet; ifp; ifp = ifp->int_next) {
904 /* Skip interfaces those already queried.
905 * Do not ask via interfaces through which we don't
906 * accept input. Do not ask via interfaces that cannot
908 * Do try broken interfaces to see if they have healed.
910 if (IS_RIP_IN_OFF(ifp->int_state)
911 || ifp->int_query_time != NEVER)
914 /* skip turned off interfaces */
915 if (!iff_up(ifp->int_if_flags))
918 buf.rip_vers = (ifp->int_state&IS_NO_RIPV1_OUT) ? RIPv2:RIPv1;
919 buf.rip_cmd = RIPCMD_REQUEST;
920 buf.rip_nets[0].n_family = RIP_AF_UNSPEC;
921 buf.rip_nets[0].n_metric = htonl(HOPCNT_INFINITY);
923 /* Send a RIPv1 query only if allowed and if we will
924 * listen to RIPv1 routers.
926 if ((ifp->int_state & IS_NO_RIPV1_OUT)
927 || (ifp->int_state & IS_NO_RIPV1_IN)) {
928 buf.rip_vers = RIPv2;
930 buf.rip_vers = RIPv1;
933 if (ifp->int_if_flags & IFF_BROADCAST) {
934 /* ordinary, hardware interface */
935 dst.sin_addr.s_addr = ifp->int_brdaddr;
937 /* Broadcast RIPv1 queries and RIPv2 queries
938 * when the hardware cannot multicast.
940 if (buf.rip_vers == RIPv2
941 && (ifp->int_if_flags & IFF_MULTICAST)
942 && !(ifp->int_state & IS_NO_RIP_MCAST)) {
943 type = OUT_MULTICAST;
945 type = OUT_BROADCAST;
948 } else if (ifp->int_if_flags & IFF_POINTOPOINT) {
949 /* point-to-point hardware interface */
950 dst.sin_addr.s_addr = ifp->int_dstaddr;
953 } else if (ifp->int_state & IS_REMOTE) {
954 /* remote interface */
955 dst.sin_addr.s_addr = ifp->int_addr;
959 /* ATM, HIPPI, etc. */
963 ifp->int_query_time = now.tv_sec+SUPPLY_INTERVAL;
964 if (output(type, &dst, ifp, &buf, sizeof(buf)) < 0)