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 * @(#)output.c 8.1 (Berkeley) 6/5/93
30 * $FreeBSD: src/sbin/routed/output.c,v 1.5.2.1 2000/08/14 17:00:03 sheldonh Exp $
38 /* walk the tree of routes with this for output
41 struct sockaddr_in to
;
46 struct interface
*ifp
; /* usually output interface */
48 char metric
; /* adjust metrics by interface */
52 #define WS_ST_FLASH 0x001 /* send only changed routes */
53 #define WS_ST_RIP2_ALL 0x002 /* send full featured RIPv2 */
54 #define WS_ST_AG 0x004 /* ok to aggregate subnets */
55 #define WS_ST_SUPER_AG 0x008 /* ok to aggregate networks */
56 #define WS_ST_QUERY 0x010 /* responding to a query */
57 #define WS_ST_TO_ON_NET 0x020 /* sending onto one of our nets */
58 #define WS_ST_DEFAULT 0x040 /* faking a default */
61 /* A buffer for what can be heard by both RIPv1 and RIPv2 listeners */
63 union pkt_buf ripv12_buf
;
65 /* Another for only RIPv2 listeners */
67 union pkt_buf rip_v2_buf
;
74 ripv12_buf
.rip
.rip_cmd
= RIPCMD_RESPONSE
;
75 v12buf
.buf
= &ripv12_buf
.rip
;
76 v12buf
.base
= &v12buf
.buf
->rip_nets
[0];
78 rip_v2_buf
.rip
.rip_cmd
= RIPCMD_RESPONSE
;
79 rip_v2_buf
.rip
.rip_vers
= RIPv2
;
80 v2buf
.buf
= &rip_v2_buf
.rip
;
81 v2buf
.base
= &v2buf
.buf
->rip_nets
[0];
85 /* Send the contents of the global buffer via the non-multicast socket
87 int /* <0 on failure */
88 output(enum output_type type
,
89 struct sockaddr_in
*dst
, /* send to here */
90 struct interface
*ifp
,
92 int size
) /* this many bytes */
94 struct sockaddr_in in
;
103 if (in
.sin_port
== 0)
104 in
.sin_port
= htons(RIP_PORT
);
107 in
.sin_len
= sizeof(in
);
115 msg
= "Answer Query";
117 soc
= ifp
->int_rip_sock
;
122 soc
= ifp
->int_rip_sock
;
123 flags
= MSG_DONTROUTE
;
126 if (ifp
->int_if_flags
& IFF_POINTOPOINT
) {
131 flags
= MSG_DONTROUTE
;
134 if (ifp
->int_if_flags
& IFF_POINTOPOINT
) {
135 msg
= "Send pt-to-pt";
136 } else if (ifp
->int_state
& IS_DUP
) {
137 trace_act("abort multicast output via %s"
138 " with duplicate address",
143 if (rip_sock_mcast
!= ifp
) {
145 /* Do not specify the primary interface
146 * explicitly if we have the multicast
147 * point-to-point kernel bug, since the
148 * kernel will do the wrong thing if the
149 * local address of a point-to-point link
150 * is the same as the address of an ordinary
153 if (ifp
->int_addr
== myaddr
) {
157 tgt_mcast
= ifp
->int_addr
;
158 if (0 > setsockopt(rip_sock
,
159 IPPROTO_IP
, IP_MULTICAST_IF
,
161 sizeof(tgt_mcast
))) {
163 LOGERR("setsockopt(rip_sock,"
169 rip_sock_mcast
= ifp
;
171 in
.sin_addr
.s_addr
= htonl(INADDR_RIP_GROUP
);
175 case NO_OUT_MULTICAST
:
184 trace_rip(msg
, "to", &in
, ifp
, buf
, size
);
186 res
= sendto(soc
, buf
, size
, flags
,
187 (struct sockaddr
*)&in
, sizeof(in
));
189 && (ifp
== NULL
|| !(ifp
->int_state
& IS_BROKE
))) {
191 msglog("%s sendto(%s%s%s.%d): %s", msg
,
192 ifp
!= NULL
? ifp
->int_name
: "",
193 ifp
!= NULL
? ", " : "",
194 inet_ntoa(in
.sin_addr
),
204 /* Find the first key for a packet to send.
205 * Try for a key that is eligible and has not expired, but settle for
206 * the last key if they have all expired.
207 * If no key is ready yet, give up.
210 find_auth(struct interface
*ifp
)
212 struct auth
*ap
, *res
;
221 for (i
= 0; i
< MAX_AUTH_KEYS
; i
++, ap
++) {
222 /* stop looking after the last key */
223 if (ap
->type
== RIP_AUTH_NONE
)
226 /* ignore keys that are not ready yet */
227 if ((u_long
)ap
->start
> (u_long
)clk
.tv_sec
)
230 if ((u_long
)ap
->end
< (u_long
)clk
.tv_sec
) {
231 /* note best expired password as a fall-back */
232 if (res
== NULL
|| (u_long
)ap
->end
> (u_long
)res
->end
)
237 /* note key with the best future */
238 if (res
== NULL
|| (u_long
)res
->end
< (u_long
)ap
->end
)
246 clr_ws_buf(struct ws_buf
*wb
,
251 wb
->lim
= wb
->base
+ NETS_LEN
;
253 memset(wb
->n
, 0, NETS_LEN
*sizeof(*wb
->n
));
255 /* (start to) install authentication if appropriate
260 na
= (struct netauth
*)wb
->n
;
261 if (ap
->type
== RIP_AUTH_PW
) {
262 na
->a_family
= RIP_AF_AUTH
;
263 na
->a_type
= RIP_AUTH_PW
;
264 memcpy(na
->au
.au_pw
, ap
->key
, sizeof(na
->au
.au_pw
));
267 } else if (ap
->type
== RIP_AUTH_MD5
) {
268 na
->a_family
= RIP_AF_AUTH
;
269 na
->a_type
= RIP_AUTH_MD5
;
270 na
->au
.a_md5
.md5_keyid
= ap
->keyid
;
271 na
->au
.a_md5
.md5_auth_len
= RIP_AUTH_MD5_LEN
;
272 na
->au
.a_md5
.md5_seqno
= htonl(clk
.tv_sec
);
274 wb
->lim
--; /* make room for trailer */
280 end_md5_auth(struct ws_buf
*wb
,
283 struct netauth
*na
, *na2
;
288 na
= (struct netauth
*)wb
->base
;
289 na2
= (struct netauth
*)wb
->n
;
290 len
= (char *)na2
-(char *)wb
->buf
;
291 na2
->a_family
= RIP_AF_AUTH
;
292 na2
->a_type
= htons(1);
293 na
->au
.a_md5
.md5_pkt_len
= htons(len
);
295 MD5Update(&md5_ctx
, (u_char
*)wb
->buf
, len
);
296 MD5Update(&md5_ctx
, ap
->key
, RIP_AUTH_MD5_LEN
);
297 MD5Final(na2
->au
.au_pw
, &md5_ctx
);
305 supply_write(struct ws_buf
*wb
)
307 /* Output multicast only if legal.
308 * If we would multicast and it would be illegal, then discard the
312 case NO_OUT_MULTICAST
:
313 trace_pkt("skip multicast to %s because impossible",
314 naddr_ntoa(ws
.to
.sin_addr
.s_addr
));
319 if (ws
.a
!= NULL
&& ws
.a
->type
== RIP_AUTH_MD5
)
320 end_md5_auth(wb
,ws
.a
);
321 if (output(wb
->type
, &ws
.to
, ws
.ifp
, wb
->buf
,
322 ((char *)wb
->n
- (char*)wb
->buf
)) < 0
333 /* put an entry into the packet
336 supply_out(struct ag_info
*ag
)
339 naddr mask
, v1_mask
, dst_h
, ddst_h
= 0;
343 /* Skip this route if doing a flash update and it and the routes
344 * it aggregates have not changed recently.
346 if (ag
->ag_seqno
< update_seqno
347 && (ws
.state
& WS_ST_FLASH
))
350 dst_h
= ag
->ag_dst_h
;
352 v1_mask
= ripv1_mask_host(htonl(dst_h
),
353 (ws
.state
& WS_ST_TO_ON_NET
) ? ws
.ifp
: 0);
356 /* If we are sending RIPv2 packets that cannot (or must not) be
357 * heard by RIPv1 listeners, do not worry about sub- or supernets.
358 * Subnets (from other networks) can only be sent via multicast.
359 * A pair of subnet routes might have been promoted so that they
360 * are legal to send by RIPv1.
361 * If RIPv1 is off, use the multicast buffer.
363 if ((ws
.state
& WS_ST_RIP2_ALL
)
364 || ((ag
->ag_state
& AGS_RIPV2
) && v1_mask
!= mask
)) {
365 /* use the RIPv2-only buffer */
369 /* use the RIPv1-or-RIPv2 buffer */
372 /* Convert supernet route into corresponding set of network
373 * routes for RIPv1, but leave non-contiguous netmasks
377 && mask
+ (mask
& -mask
) == 0) {
378 ddst_h
= v1_mask
& -v1_mask
;
379 i
= (v1_mask
& ~mask
)/ddst_h
;
381 if (i
> ws
.gen_limit
) {
382 /* Punt if we would have to generate an
383 * unreasonable number of routes.
386 trace_misc("sending %s-->%s as 1"
387 " instead of %d routes",
388 addrname(htonl(dst_h
), mask
,
390 naddr_ntoa(ws
.to
.sin_addr
403 wb
->n
->n_family
= RIP_AF_INET
;
404 wb
->n
->n_dst
= htonl(dst_h
);
405 /* If the route is from router-discovery or we are
406 * shutting down, admit only a bad metric.
408 wb
->n
->n_metric
= ((stopint
|| ag
->ag_metric
< 1)
411 wb
->n
->n_metric
= htonl(wb
->n
->n_metric
);
412 /* Any non-zero bits in the supposedly unused RIPv1 fields
413 * cause the old `routed` to ignore the route.
414 * That means the mask and so forth cannot be sent
415 * in the hybrid RIPv1/RIPv2 mode.
417 if (ws
.state
& WS_ST_RIP2_ALL
) {
419 && ((ws
.state
& WS_ST_QUERY
)
420 || (ag
->ag_nhop
!= ws
.ifp
->int_addr
421 && on_net(ag
->ag_nhop
,
424 wb
->n
->n_nhop
= ag
->ag_nhop
;
425 wb
->n
->n_mask
= htonl(mask
);
426 wb
->n
->n_tag
= ag
->ag_tag
;
430 if (++wb
->n
>= wb
->lim
)
436 /* supply one route from the table
440 walk_supply(struct radix_node
*rn
, __unused
struct walkarg
*argp
)
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
)
539 && !(ws
.state
& WS_ST_RIP2_ALL
))
540 ags
|= AGS_AGGREGATE
;
543 /* Always suppress network routes into other, existing
548 /* Generate supernets if allowed.
549 * If we can be heard by RIPv1 systems, we will
550 * later convert back to ordinary nets.
551 * This unifies dealing with received supernets.
553 if ((ws
.state
& WS_ST_AG
)
554 && ((RT
->rt_state
& RS_SUBNET
)
555 || (ws
.state
& WS_ST_SUPER_AG
)))
556 ags
|= AGS_AGGREGATE
;
559 /* Do not send RIPv1 advertisements of subnets to other
560 * networks. If possible, multicast them by RIPv2.
562 if ((RT
->rt_state
& RS_SUBNET
)
563 && !(ws
.state
& WS_ST_RIP2_ALL
)
564 && !on_net(dst
, ws
.to_std_net
, ws
.to_std_mask
))
565 ags
|= AGS_RIPV2
| AGS_AGGREGATE
;
568 /* Do not send a route back to where it came from, except in
569 * response to a query. This is "split-horizon". That means not
570 * advertising back to the same network and so via the same interface.
572 * We want to suppress routes that might have been fragmented
573 * from this route by a RIPv1 router and sent back to us, and so we
574 * cannot forget this route here. Let the split-horizon route
575 * suppress the fragmented routes and then itself be forgotten.
577 * Include the routes for both ends of point-to-point interfaces
578 * among those suppressed by split-horizon, since the other side
579 * should knows them as well as we do.
581 * Notice spare routes with the same metric that we are about to
582 * advertise, to split the horizon on redundant, inactive paths.
585 && !(ws
.state
& WS_ST_QUERY
)
586 && (ws
.state
& WS_ST_TO_ON_NET
)
587 && (!(RT
->rt_state
& RS_IF
)
588 || ws
.ifp
->int_if_flags
& IFF_POINTOPOINT
)) {
589 for (rts
= RT
->rt_spares
, i
= NUM_SPARES
; i
!= 0; i
--, rts
++) {
590 if (rts
->rts_metric
> metric
591 || rts
->rts_ifp
!= ws
.ifp
)
594 /* If we do not mark the route with AGS_SPLIT_HZ here,
595 * it will be poisoned-reverse, or advertised back
596 * toward its source with an infinite metric.
597 * If we have recently advertised the route with a
598 * better metric than we now have, then we should
599 * poison-reverse the route before suppressing it for
602 * In almost all cases, if there is no spare for the
603 * route then it is either old and dead or a brand
604 * new route. If it is brand new, there is no need
605 * for poison-reverse. If it is old and dead, it
606 * is already poisoned.
608 if (RT
->rt_poison_time
< now_expire
609 || RT
->rt_poison_metric
>= metric
610 || RT
->rt_spares
[1].rts_gate
== 0) {
612 ags
&= ~AGS_SUPPRESS
;
614 metric
= HOPCNT_INFINITY
;
619 /* Keep track of the best metric with which the
620 * route has been advertised recently.
622 if (RT
->rt_poison_metric
>= metric
623 || RT
->rt_poison_time
< now_expire
) {
624 RT
->rt_poison_time
= now
.tv_sec
;
625 RT
->rt_poison_metric
= metric
;
628 /* Adjust the outgoing metric by the cost of the link.
629 * Avoid aggregation when a route is counting to infinity.
631 pref
= RT
->rt_poison_metric
+ ws
.metric
;
634 /* Do not advertise stable routes that will be ignored,
635 * unless we are answering a query.
636 * If the route recently was advertised with a metric that
637 * would have been less than infinity through this interface,
638 * we need to continue to advertise it in order to poison it.
640 if (metric
>= HOPCNT_INFINITY
) {
641 if (!(ws
.state
& WS_ST_QUERY
)
642 && (pref
>= HOPCNT_INFINITY
643 || RT
->rt_poison_time
< now_garbage
))
646 metric
= HOPCNT_INFINITY
;
649 ag_check(dst
, RT
->rt_mask
, 0, nhop
, metric
, pref
,
650 RT
->rt_seqno
, RT
->rt_tag
, ags
, supply_out
);
656 /* Supply dst with the contents of the routing tables.
657 * If this won't fit in one packet, chop it up into several.
660 supply(struct sockaddr_in
*dst
,
661 struct interface
*ifp
, /* output interface */
662 enum output_type type
,
663 int flash
, /* 1=flash update */
664 int vers
, /* RIP version */
665 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;
705 ripv12_buf
.rip
.rip_vers
= vers
;
709 if (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
&& (def_metric
= ifp
->int_d_metric
) != 0) {
756 if (NULL
== (rt
= rtget(RIP_DEFAULT
, 0))
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 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 for (ifp
= ifnet
; ifp
!= NULL
; ifp
= ifp
->int_next
) {
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
;
860 } else if (ifp
->int_state
& IS_REMOTE
) {
861 /* remote interface */
862 dst
.sin_addr
.s_addr
= ifp
->int_addr
;
866 /* ATM, HIPPI, etc. */
870 supply(&dst
, ifp
, type
, flash
, vers
, 1);
873 update_seqno
++; /* all routes are up to date */
878 * Do it only once to an interface, and not even after the interface
879 * was broken and recovered.
885 static struct sockaddr_in dst
= {sizeof(dst
), AF_INET
, 0, {0}, {0}};
887 static struct sockaddr_in dst
= {AF_INET
};
889 struct interface
*ifp
;
891 enum output_type type
;
897 memset(&buf
, 0, sizeof(buf
));
899 for (ifp
= ifnet
; ifp
; ifp
= ifp
->int_next
) {
900 /* Skip interfaces those already queried.
901 * Do not ask via interfaces through which we don't
902 * accept input. Do not ask via interfaces that cannot
904 * Do try broken interfaces to see if they have healed.
906 if (IS_RIP_IN_OFF(ifp
->int_state
)
907 || ifp
->int_query_time
!= NEVER
)
910 /* skip turned off interfaces */
911 if (!iff_up(ifp
->int_if_flags
))
914 buf
.rip_vers
= (ifp
->int_state
&IS_NO_RIPV1_OUT
) ? RIPv2
:RIPv1
;
915 buf
.rip_cmd
= RIPCMD_REQUEST
;
916 buf
.rip_nets
[0].n_family
= RIP_AF_UNSPEC
;
917 buf
.rip_nets
[0].n_metric
= htonl(HOPCNT_INFINITY
);
919 /* Send a RIPv1 query only if allowed and if we will
920 * listen to RIPv1 routers.
922 if ((ifp
->int_state
& IS_NO_RIPV1_OUT
)
923 || (ifp
->int_state
& IS_NO_RIPV1_IN
)) {
924 buf
.rip_vers
= RIPv2
;
926 buf
.rip_vers
= RIPv1
;
929 if (ifp
->int_if_flags
& IFF_BROADCAST
) {
930 /* ordinary, hardware interface */
931 dst
.sin_addr
.s_addr
= ifp
->int_brdaddr
;
933 /* Broadcast RIPv1 queries and RIPv2 queries
934 * when the hardware cannot multicast.
936 if (buf
.rip_vers
== RIPv2
937 && (ifp
->int_if_flags
& IFF_MULTICAST
)
938 && !(ifp
->int_state
& IS_NO_RIP_MCAST
)) {
939 type
= OUT_MULTICAST
;
941 type
= OUT_BROADCAST
;
944 } else if (ifp
->int_if_flags
& IFF_POINTOPOINT
) {
945 /* point-to-point hardware interface */
946 dst
.sin_addr
.s_addr
= ifp
->int_dstaddr
;
949 } else if (ifp
->int_state
& IS_REMOTE
) {
950 /* remote interface */
951 dst
.sin_addr
.s_addr
= ifp
->int_addr
;
955 /* ATM, HIPPI, etc. */
959 ifp
->int_query_time
= now
.tv_sec
+SUPPLY_INTERVAL
;
960 if (output(type
, &dst
, ifp
, &buf
, sizeof(buf
)) < 0)