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 * 3. 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
29 * $FreeBSD: src/sbin/routed/output.c,v 1.5.2.1 2000/08/14 17:00:03 sheldonh Exp $
34 #if !defined(__NetBSD__)
35 static char sccsid
[] __attribute__((unused
)) = "@(#)output.c 8.1 (Berkeley) 6/5/93";
36 #elif defined(__NetBSD__)
44 /* walk the tree of routes with this for output
47 struct sockaddr_in to
;
52 struct interface
*ifp
; /* usually output interface */
54 char metric
; /* adjust metrics by interface */
58 #define WS_ST_FLASH 0x001 /* send only changed routes */
59 #define WS_ST_RIP2_ALL 0x002 /* send full featured RIPv2 */
60 #define WS_ST_AG 0x004 /* ok to aggregate subnets */
61 #define WS_ST_SUPER_AG 0x008 /* ok to aggregate networks */
62 #define WS_ST_QUERY 0x010 /* responding to a query */
63 #define WS_ST_TO_ON_NET 0x020 /* sending onto one of our nets */
64 #define WS_ST_DEFAULT 0x040 /* faking a default */
67 /* A buffer for what can be heard by both RIPv1 and RIPv2 listeners */
69 union pkt_buf ripv12_buf
;
71 /* Another for only RIPv2 listeners */
73 union pkt_buf rip_v2_buf
;
80 ripv12_buf
.rip
.rip_cmd
= RIPCMD_RESPONSE
;
81 v12buf
.buf
= &ripv12_buf
.rip
;
82 v12buf
.base
= &v12buf
.buf
->rip_nets
[0];
84 rip_v2_buf
.rip
.rip_cmd
= RIPCMD_RESPONSE
;
85 rip_v2_buf
.rip
.rip_vers
= RIPv2
;
86 v2buf
.buf
= &rip_v2_buf
.rip
;
87 v2buf
.base
= &v2buf
.buf
->rip_nets
[0];
91 /* Send the contents of the global buffer via the non-multicast socket
93 int /* <0 on failure */
94 output(enum output_type type
,
95 struct sockaddr_in
*dst
, /* send to here */
96 struct interface
*ifp
,
98 int size
) /* this many bytes */
100 struct sockaddr_in in
;
109 if (in
.sin_port
== 0)
110 in
.sin_port
= htons(RIP_PORT
);
113 in
.sin_len
= sizeof(in
);
121 msg
= "Answer Query";
123 soc
= ifp
->int_rip_sock
;
128 soc
= ifp
->int_rip_sock
;
129 flags
= MSG_DONTROUTE
;
132 if (ifp
->int_if_flags
& IFF_POINTOPOINT
) {
137 flags
= MSG_DONTROUTE
;
140 if (ifp
->int_if_flags
& IFF_POINTOPOINT
) {
141 msg
= "Send pt-to-pt";
142 } else if (ifp
->int_state
& IS_DUP
) {
143 trace_act("abort multicast output via %s"
144 " with duplicate address",
149 if (rip_sock_mcast
!= ifp
) {
151 /* Do not specify the primary interface
152 * explicitly if we have the multicast
153 * point-to-point kernel bug, since the
154 * kernel will do the wrong thing if the
155 * local address of a point-to-point link
156 * is the same as the address of an ordinary
159 if (ifp
->int_addr
== myaddr
) {
163 tgt_mcast
= ifp
->int_addr
;
164 if (0 > setsockopt(rip_sock
,
165 IPPROTO_IP
, IP_MULTICAST_IF
,
167 sizeof(tgt_mcast
))) {
169 LOGERR("setsockopt(rip_sock,"
175 rip_sock_mcast
= ifp
;
177 in
.sin_addr
.s_addr
= htonl(INADDR_RIP_GROUP
);
181 case NO_OUT_MULTICAST
:
190 trace_rip(msg
, "to", &in
, ifp
, buf
, size
);
192 res
= sendto(soc
, buf
, size
, flags
,
193 (struct sockaddr
*)&in
, sizeof(in
));
195 && (ifp
== NULL
|| !(ifp
->int_state
& IS_BROKE
))) {
197 msglog("%s sendto(%s%s%s.%d): %s", msg
,
198 ifp
!= NULL
? ifp
->int_name
: "",
199 ifp
!= NULL
? ", " : "",
200 inet_ntoa(in
.sin_addr
),
210 /* Find the first key for a packet to send.
211 * Try for a key that is eligible and has not expired, but settle for
212 * the last key if they have all expired.
213 * If no key is ready yet, give up.
216 find_auth(struct interface
*ifp
)
218 struct auth
*ap
, *res
;
227 for (i
= 0; i
< MAX_AUTH_KEYS
; i
++, ap
++) {
228 /* stop looking after the last key */
229 if (ap
->type
== RIP_AUTH_NONE
)
232 /* ignore keys that are not ready yet */
233 if ((u_long
)ap
->start
> (u_long
)clk
.tv_sec
)
236 if ((u_long
)ap
->end
< (u_long
)clk
.tv_sec
) {
237 /* note best expired password as a fall-back */
238 if (res
== NULL
|| (u_long
)ap
->end
> (u_long
)res
->end
)
243 /* note key with the best future */
244 if (res
== NULL
|| (u_long
)res
->end
< (u_long
)ap
->end
)
252 clr_ws_buf(struct ws_buf
*wb
,
257 wb
->lim
= wb
->base
+ NETS_LEN
;
259 memset(wb
->n
, 0, NETS_LEN
*sizeof(*wb
->n
));
261 /* (start to) install authentication if appropriate
266 na
= (struct netauth
*)wb
->n
;
267 if (ap
->type
== RIP_AUTH_PW
) {
268 na
->a_family
= RIP_AF_AUTH
;
269 na
->a_type
= RIP_AUTH_PW
;
270 memcpy(na
->au
.au_pw
, ap
->key
, sizeof(na
->au
.au_pw
));
273 } else if (ap
->type
== RIP_AUTH_MD5
) {
274 na
->a_family
= RIP_AF_AUTH
;
275 na
->a_type
= RIP_AUTH_MD5
;
276 na
->au
.a_md5
.md5_keyid
= ap
->keyid
;
277 na
->au
.a_md5
.md5_auth_len
= RIP_AUTH_MD5_LEN
;
278 na
->au
.a_md5
.md5_seqno
= htonl(clk
.tv_sec
);
280 wb
->lim
--; /* make room for trailer */
286 end_md5_auth(struct ws_buf
*wb
,
289 struct netauth
*na
, *na2
;
294 na
= (struct netauth
*)wb
->base
;
295 na2
= (struct netauth
*)wb
->n
;
296 len
= (char *)na2
-(char *)wb
->buf
;
297 na2
->a_family
= RIP_AF_AUTH
;
298 na2
->a_type
= htons(1);
299 na
->au
.a_md5
.md5_pkt_len
= htons(len
);
301 MD5Update(&md5_ctx
, (u_char
*)wb
->buf
, len
);
302 MD5Update(&md5_ctx
, ap
->key
, RIP_AUTH_MD5_LEN
);
303 MD5Final(na2
->au
.au_pw
, &md5_ctx
);
311 supply_write(struct ws_buf
*wb
)
313 /* Output multicast only if legal.
314 * If we would multicast and it would be illegal, then discard the
318 case NO_OUT_MULTICAST
:
319 trace_pkt("skip multicast to %s because impossible",
320 naddr_ntoa(ws
.to
.sin_addr
.s_addr
));
325 if (ws
.a
!= NULL
&& ws
.a
->type
== RIP_AUTH_MD5
)
326 end_md5_auth(wb
,ws
.a
);
327 if (output(wb
->type
, &ws
.to
, ws
.ifp
, wb
->buf
,
328 ((char *)wb
->n
- (char*)wb
->buf
)) < 0
339 /* put an entry into the packet
342 supply_out(struct ag_info
*ag
)
345 naddr mask
, v1_mask
, dst_h
, ddst_h
= 0;
349 /* Skip this route if doing a flash update and it and the routes
350 * it aggregates have not changed recently.
352 if (ag
->ag_seqno
< update_seqno
353 && (ws
.state
& WS_ST_FLASH
))
356 dst_h
= ag
->ag_dst_h
;
358 v1_mask
= ripv1_mask_host(htonl(dst_h
),
359 (ws
.state
& WS_ST_TO_ON_NET
) ? ws
.ifp
: 0);
362 /* If we are sending RIPv2 packets that cannot (or must not) be
363 * heard by RIPv1 listeners, do not worry about sub- or supernets.
364 * Subnets (from other networks) can only be sent via multicast.
365 * A pair of subnet routes might have been promoted so that they
366 * are legal to send by RIPv1.
367 * If RIPv1 is off, use the multicast buffer.
369 if ((ws
.state
& WS_ST_RIP2_ALL
)
370 || ((ag
->ag_state
& AGS_RIPV2
) && v1_mask
!= mask
)) {
371 /* use the RIPv2-only buffer */
375 /* use the RIPv1-or-RIPv2 buffer */
378 /* Convert supernet route into corresponding set of network
379 * routes for RIPv1, but leave non-contiguous netmasks
383 && mask
+ (mask
& -mask
) == 0) {
384 ddst_h
= v1_mask
& -v1_mask
;
385 i
= (v1_mask
& ~mask
)/ddst_h
;
387 if (i
> ws
.gen_limit
) {
388 /* Punt if we would have to generate an
389 * unreasonable number of routes.
392 trace_misc("sending %s-->%s as 1"
393 " instead of %d routes",
394 addrname(htonl(dst_h
), mask
,
396 naddr_ntoa(ws
.to
.sin_addr
409 wb
->n
->n_family
= RIP_AF_INET
;
410 wb
->n
->n_dst
= htonl(dst_h
);
411 /* If the route is from router-discovery or we are
412 * shutting down, admit only a bad metric.
414 wb
->n
->n_metric
= ((stopint
|| ag
->ag_metric
< 1)
417 wb
->n
->n_metric
= htonl(wb
->n
->n_metric
);
418 /* Any non-zero bits in the supposedly unused RIPv1 fields
419 * cause the old `routed` to ignore the route.
420 * That means the mask and so forth cannot be sent
421 * in the hybrid RIPv1/RIPv2 mode.
423 if (ws
.state
& WS_ST_RIP2_ALL
) {
425 && ((ws
.state
& WS_ST_QUERY
)
426 || (ag
->ag_nhop
!= ws
.ifp
->int_addr
427 && on_net(ag
->ag_nhop
,
430 wb
->n
->n_nhop
= ag
->ag_nhop
;
431 wb
->n
->n_mask
= htonl(mask
);
432 wb
->n
->n_tag
= ag
->ag_tag
;
436 if (++wb
->n
>= wb
->lim
)
442 /* supply one route from the table
446 walk_supply(struct radix_node
*rn
,
447 struct walkarg
*argp UNUSED
)
449 #define RT ((struct rt_entry *)rn)
453 struct rt_spare
*rts
;
457 /* Do not advertise external remote interfaces or passive interfaces.
459 if ((RT
->rt_state
& RS_IF
)
461 && (RT
->rt_ifp
->int_state
& IS_PASSIVE
)
462 && !(RT
->rt_state
& RS_MHOME
))
465 /* If being quiet about our ability to forward, then
466 * do not say anything unless responding to a query,
467 * except about our main interface.
469 if (!supplier
&& !(ws
.state
& WS_ST_QUERY
)
470 && !(RT
->rt_state
& RS_MHOME
))
475 /* do not collide with the fake default route */
476 if (dst
== RIP_DEFAULT
477 && (ws
.state
& WS_ST_DEFAULT
))
480 if (RT
->rt_state
& RS_NET_SYN
) {
481 if (RT
->rt_state
& RS_NET_INT
) {
482 /* Do not send manual synthetic network routes
485 if (on_net(ws
.to
.sin_addr
.s_addr
,
486 ntohl(dst
), RT
->rt_mask
))
490 /* Do not send automatic synthetic network routes
491 * if they are not needed because no RIPv1 listeners
494 if (ws
.state
& WS_ST_RIP2_ALL
)
497 /* Do not send automatic synthetic network routes to
500 if (on_net(ws
.to
.sin_addr
.s_addr
,
501 ntohl(dst
), RT
->rt_mask
))
507 /* Advertise the next hop if this is not a route for one
508 * of our interfaces and the next hop is on the same
509 * network as the target.
510 * The final determination is made by supply_out().
512 if (!(RT
->rt_state
& RS_IF
)
513 && RT
->rt_gate
!= myaddr
514 && RT
->rt_gate
!= loopaddr
)
520 metric
= RT
->rt_metric
;
523 if (RT
->rt_state
& RS_MHOME
) {
524 /* retain host route of multi-homed servers */
527 } else if (RT_ISHOST(RT
)) {
528 /* We should always suppress (into existing network routes)
529 * the host routes for the local end of our point-to-point
531 * If we are suppressing host routes in general, then do so.
532 * Avoid advertising host routes onto their own network,
533 * where they should be handled by proxy-ARP.
535 if ((RT
->rt_state
& RS_LOCAL
)
537 || on_net(dst
, ws
.to_net
, ws
.to_mask
))
540 /* Aggregate stray host routes into network routes if allowed.
541 * We cannot aggregate host routes into small network routes
542 * without confusing RIPv1 listeners into thinking the
543 * network routes are host routes.
545 if ((ws
.state
& WS_ST_AG
)
546 && !(ws
.state
& WS_ST_RIP2_ALL
))
547 ags
|= AGS_AGGREGATE
;
550 /* Always suppress network routes into other, existing
555 /* Generate supernets if allowed.
556 * If we can be heard by RIPv1 systems, we will
557 * later convert back to ordinary nets.
558 * This unifies dealing with received supernets.
560 if ((ws
.state
& WS_ST_AG
)
561 && ((RT
->rt_state
& RS_SUBNET
)
562 || (ws
.state
& WS_ST_SUPER_AG
)))
563 ags
|= AGS_AGGREGATE
;
566 /* Do not send RIPv1 advertisements of subnets to other
567 * networks. If possible, multicast them by RIPv2.
569 if ((RT
->rt_state
& RS_SUBNET
)
570 && !(ws
.state
& WS_ST_RIP2_ALL
)
571 && !on_net(dst
, ws
.to_std_net
, ws
.to_std_mask
))
572 ags
|= AGS_RIPV2
| AGS_AGGREGATE
;
575 /* Do not send a route back to where it came from, except in
576 * response to a query. This is "split-horizon". That means not
577 * advertising back to the same network and so via the same interface.
579 * We want to suppress routes that might have been fragmented
580 * from this route by a RIPv1 router and sent back to us, and so we
581 * cannot forget this route here. Let the split-horizon route
582 * suppress the fragmented routes and then itself be forgotten.
584 * Include the routes for both ends of point-to-point interfaces
585 * among those suppressed by split-horizon, since the other side
586 * should knows them as well as we do.
588 * Notice spare routes with the same metric that we are about to
589 * advertise, to split the horizon on redundant, inactive paths.
592 && !(ws
.state
& WS_ST_QUERY
)
593 && (ws
.state
& WS_ST_TO_ON_NET
)
594 && (!(RT
->rt_state
& RS_IF
)
595 || ws
.ifp
->int_if_flags
& IFF_POINTOPOINT
)) {
596 for (rts
= RT
->rt_spares
, i
= NUM_SPARES
; i
!= 0; i
--, rts
++) {
597 if (rts
->rts_metric
> metric
598 || rts
->rts_ifp
!= ws
.ifp
)
601 /* If we do not mark the route with AGS_SPLIT_HZ here,
602 * it will be poisoned-reverse, or advertised back
603 * toward its source with an infinite metric.
604 * If we have recently advertised the route with a
605 * better metric than we now have, then we should
606 * poison-reverse the route before suppressing it for
609 * In almost all cases, if there is no spare for the
610 * route then it is either old and dead or a brand
611 * new route. If it is brand new, there is no need
612 * for poison-reverse. If it is old and dead, it
613 * is already poisoned.
615 if (RT
->rt_poison_time
< now_expire
616 || RT
->rt_poison_metric
>= metric
617 || RT
->rt_spares
[1].rts_gate
== 0) {
619 ags
&= ~AGS_SUPPRESS
;
621 metric
= HOPCNT_INFINITY
;
626 /* Keep track of the best metric with which the
627 * route has been advertised recently.
629 if (RT
->rt_poison_metric
>= metric
630 || RT
->rt_poison_time
< now_expire
) {
631 RT
->rt_poison_time
= now
.tv_sec
;
632 RT
->rt_poison_metric
= metric
;
635 /* Adjust the outgoing metric by the cost of the link.
636 * Avoid aggregation when a route is counting to infinity.
638 pref
= RT
->rt_poison_metric
+ ws
.metric
;
641 /* Do not advertise stable routes that will be ignored,
642 * unless we are answering a query.
643 * If the route recently was advertised with a metric that
644 * would have been less than infinity through this interface,
645 * we need to continue to advertise it in order to poison it.
647 if (metric
>= HOPCNT_INFINITY
) {
648 if (!(ws
.state
& WS_ST_QUERY
)
649 && (pref
>= HOPCNT_INFINITY
650 || RT
->rt_poison_time
< now_garbage
))
653 metric
= HOPCNT_INFINITY
;
656 ag_check(dst
, RT
->rt_mask
, 0, nhop
, metric
, pref
,
657 RT
->rt_seqno
, RT
->rt_tag
, ags
, supply_out
);
663 /* Supply dst with the contents of the routing tables.
664 * If this won't fit in one packet, chop it up into several.
667 supply(struct sockaddr_in
*dst
,
668 struct interface
*ifp
, /* output interface */
669 enum output_type type
,
670 int flash
, /* 1=flash update */
671 int vers
, /* RIP version */
672 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
) == NULL
) {
706 /* Adjust the advertised metric by the outgoing interface
709 ws
.metric
= ifp
->int_metric
+1;
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
== NULL
|| !(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
!= NULL
&& 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 (NULL
== (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 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 for (ifp
= ifnet
; ifp
!= NULL
; ifp
= ifp
->int_next
) {
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
;
867 } else if (ifp
->int_state
& IS_REMOTE
) {
868 /* remote interface */
869 dst
.sin_addr
.s_addr
= ifp
->int_addr
;
873 /* ATM, HIPPI, etc. */
877 supply(&dst
, ifp
, type
, flash
, vers
, 1);
880 update_seqno
++; /* all routes are up to date */
885 * Do it only once to an interface, and not even after the interface
886 * was broken and recovered.
892 static struct sockaddr_in dst
= {sizeof(dst
), AF_INET
, 0, {0}, {0}};
894 static struct sockaddr_in dst
= {AF_INET
};
896 struct interface
*ifp
;
898 enum output_type type
;
904 memset(&buf
, 0, sizeof(buf
));
906 for (ifp
= ifnet
; ifp
; ifp
= ifp
->int_next
) {
907 /* Skip interfaces those already queried.
908 * Do not ask via interfaces through which we don't
909 * accept input. Do not ask via interfaces that cannot
911 * Do try broken interfaces to see if they have healed.
913 if (IS_RIP_IN_OFF(ifp
->int_state
)
914 || ifp
->int_query_time
!= NEVER
)
917 /* skip turned off interfaces */
918 if (!iff_up(ifp
->int_if_flags
))
921 buf
.rip_vers
= (ifp
->int_state
&IS_NO_RIPV1_OUT
) ? RIPv2
:RIPv1
;
922 buf
.rip_cmd
= RIPCMD_REQUEST
;
923 buf
.rip_nets
[0].n_family
= RIP_AF_UNSPEC
;
924 buf
.rip_nets
[0].n_metric
= htonl(HOPCNT_INFINITY
);
926 /* Send a RIPv1 query only if allowed and if we will
927 * listen to RIPv1 routers.
929 if ((ifp
->int_state
& IS_NO_RIPV1_OUT
)
930 || (ifp
->int_state
& IS_NO_RIPV1_IN
)) {
931 buf
.rip_vers
= RIPv2
;
933 buf
.rip_vers
= RIPv1
;
936 if (ifp
->int_if_flags
& IFF_BROADCAST
) {
937 /* ordinary, hardware interface */
938 dst
.sin_addr
.s_addr
= ifp
->int_brdaddr
;
940 /* Broadcast RIPv1 queries and RIPv2 queries
941 * when the hardware cannot multicast.
943 if (buf
.rip_vers
== RIPv2
944 && (ifp
->int_if_flags
& IFF_MULTICAST
)
945 && !(ifp
->int_state
& IS_NO_RIP_MCAST
)) {
946 type
= OUT_MULTICAST
;
948 type
= OUT_BROADCAST
;
951 } else if (ifp
->int_if_flags
& IFF_POINTOPOINT
) {
952 /* point-to-point hardware interface */
953 dst
.sin_addr
.s_addr
= ifp
->int_dstaddr
;
956 } else if (ifp
->int_state
& IS_REMOTE
) {
957 /* remote interface */
958 dst
.sin_addr
.s_addr
= ifp
->int_addr
;
962 /* ATM, HIPPI, etc. */
966 ifp
->int_query_time
= now
.tv_sec
+SUPPLY_INTERVAL
;
967 if (output(type
, &dst
, ifp
, &buf
, sizeof(buf
)) < 0)