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. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgment:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * $FreeBSD: src/sbin/routed/output.c,v 1.5.2.1 2000/08/14 17:00:03 sheldonh Exp $
38 #if !defined(sgi) && !defined(__NetBSD__)
39 static char sccsid
[] __attribute__((unused
)) = "@(#)output.c 8.1 (Berkeley) 6/5/93";
40 #elif defined(__NetBSD__)
48 /* walk the tree of routes with this for output
51 struct sockaddr_in to
;
56 struct interface
*ifp
; /* usually output interface */
58 char metric
; /* adjust metrics by interface */
62 #define WS_ST_FLASH 0x001 /* send only changed routes */
63 #define WS_ST_RIP2_ALL 0x002 /* send full featured RIPv2 */
64 #define WS_ST_AG 0x004 /* ok to aggregate subnets */
65 #define WS_ST_SUPER_AG 0x008 /* ok to aggregate networks */
66 #define WS_ST_QUERY 0x010 /* responding to a query */
67 #define WS_ST_TO_ON_NET 0x020 /* sending onto one of our nets */
68 #define WS_ST_DEFAULT 0x040 /* faking a default */
71 /* A buffer for what can be heard by both RIPv1 and RIPv2 listeners */
73 union pkt_buf ripv12_buf
;
75 /* Another for only RIPv2 listeners */
77 union pkt_buf rip_v2_buf
;
84 ripv12_buf
.rip
.rip_cmd
= RIPCMD_RESPONSE
;
85 v12buf
.buf
= &ripv12_buf
.rip
;
86 v12buf
.base
= &v12buf
.buf
->rip_nets
[0];
88 rip_v2_buf
.rip
.rip_cmd
= RIPCMD_RESPONSE
;
89 rip_v2_buf
.rip
.rip_vers
= RIPv2
;
90 v2buf
.buf
= &rip_v2_buf
.rip
;
91 v2buf
.base
= &v2buf
.buf
->rip_nets
[0];
95 /* Send the contents of the global buffer via the non-multicast socket
97 int /* <0 on failure */
98 output(enum output_type type
,
99 struct sockaddr_in
*dst
, /* send to here */
100 struct interface
*ifp
,
102 int size
) /* this many bytes */
104 struct sockaddr_in in
;
113 if (in
.sin_port
== 0)
114 in
.sin_port
= htons(RIP_PORT
);
117 in
.sin_len
= sizeof(in
);
125 msg
= "Answer Query";
127 soc
= ifp
->int_rip_sock
;
132 soc
= ifp
->int_rip_sock
;
133 flags
= MSG_DONTROUTE
;
136 if (ifp
->int_if_flags
& IFF_POINTOPOINT
) {
141 flags
= MSG_DONTROUTE
;
144 if (ifp
->int_if_flags
& IFF_POINTOPOINT
) {
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
) {
155 /* Do not specify the primary interface
156 * explicitly if we have the multicast
157 * point-to-point kernel bug, since the
158 * kernel will do the wrong thing if the
159 * local address of a point-to-point link
160 * is the same as the address of an ordinary
163 if (ifp
->int_addr
== myaddr
) {
167 tgt_mcast
= ifp
->int_addr
;
168 if (0 > setsockopt(rip_sock
,
169 IPPROTO_IP
, IP_MULTICAST_IF
,
171 sizeof(tgt_mcast
))) {
173 LOGERR("setsockopt(rip_sock,"
179 rip_sock_mcast
= ifp
;
181 in
.sin_addr
.s_addr
= htonl(INADDR_RIP_GROUP
);
185 case NO_OUT_MULTICAST
:
194 trace_rip(msg
, "to", &in
, ifp
, buf
, size
);
196 res
= sendto(soc
, buf
, size
, flags
,
197 (struct sockaddr
*)&in
, sizeof(in
));
199 && (ifp
== NULL
|| !(ifp
->int_state
& IS_BROKE
))) {
201 msglog("%s sendto(%s%s%s.%d): %s", msg
,
202 ifp
!= NULL
? ifp
->int_name
: "",
203 ifp
!= NULL
? ", " : "",
204 inet_ntoa(in
.sin_addr
),
214 /* Find the first key for a packet to send.
215 * Try for a key that is eligible and has not expired, but settle for
216 * the last key if they have all expired.
217 * If no key is ready yet, give up.
220 find_auth(struct interface
*ifp
)
222 struct auth
*ap
, *res
;
231 for (i
= 0; i
< MAX_AUTH_KEYS
; i
++, ap
++) {
232 /* stop looking after the last key */
233 if (ap
->type
== RIP_AUTH_NONE
)
236 /* ignore keys that are not ready yet */
237 if ((u_long
)ap
->start
> (u_long
)clk
.tv_sec
)
240 if ((u_long
)ap
->end
< (u_long
)clk
.tv_sec
) {
241 /* note best expired password as a fall-back */
242 if (res
== NULL
|| (u_long
)ap
->end
> (u_long
)res
->end
)
247 /* note key with the best future */
248 if (res
== NULL
|| (u_long
)res
->end
< (u_long
)ap
->end
)
256 clr_ws_buf(struct ws_buf
*wb
,
261 wb
->lim
= wb
->base
+ NETS_LEN
;
263 memset(wb
->n
, 0, NETS_LEN
*sizeof(*wb
->n
));
265 /* (start to) install authentication if appropriate
270 na
= (struct netauth
*)wb
->n
;
271 if (ap
->type
== RIP_AUTH_PW
) {
272 na
->a_family
= RIP_AF_AUTH
;
273 na
->a_type
= RIP_AUTH_PW
;
274 memcpy(na
->au
.au_pw
, ap
->key
, sizeof(na
->au
.au_pw
));
277 } else if (ap
->type
== RIP_AUTH_MD5
) {
278 na
->a_family
= RIP_AF_AUTH
;
279 na
->a_type
= RIP_AUTH_MD5
;
280 na
->au
.a_md5
.md5_keyid
= ap
->keyid
;
281 na
->au
.a_md5
.md5_auth_len
= RIP_AUTH_MD5_LEN
;
282 na
->au
.a_md5
.md5_seqno
= htonl(clk
.tv_sec
);
284 wb
->lim
--; /* make room for trailer */
290 end_md5_auth(struct ws_buf
*wb
,
293 struct netauth
*na
, *na2
;
298 na
= (struct netauth
*)wb
->base
;
299 na2
= (struct netauth
*)wb
->n
;
300 len
= (char *)na2
-(char *)wb
->buf
;
301 na2
->a_family
= RIP_AF_AUTH
;
302 na2
->a_type
= htons(1);
303 na
->au
.a_md5
.md5_pkt_len
= htons(len
);
305 MD5Update(&md5_ctx
, (u_char
*)wb
->buf
, len
);
306 MD5Update(&md5_ctx
, ap
->key
, RIP_AUTH_MD5_LEN
);
307 MD5Final(na2
->au
.au_pw
, &md5_ctx
);
315 supply_write(struct ws_buf
*wb
)
317 /* Output multicast only if legal.
318 * If we would multicast and it would be illegal, then discard the
322 case NO_OUT_MULTICAST
:
323 trace_pkt("skip multicast to %s because impossible",
324 naddr_ntoa(ws
.to
.sin_addr
.s_addr
));
329 if (ws
.a
!= NULL
&& ws
.a
->type
== RIP_AUTH_MD5
)
330 end_md5_auth(wb
,ws
.a
);
331 if (output(wb
->type
, &ws
.to
, ws
.ifp
, wb
->buf
,
332 ((char *)wb
->n
- (char*)wb
->buf
)) < 0
343 /* put an entry into the packet
346 supply_out(struct ag_info
*ag
)
349 naddr mask
, v1_mask
, dst_h
, ddst_h
= 0;
353 /* Skip this route if doing a flash update and it and the routes
354 * it aggregates have not changed recently.
356 if (ag
->ag_seqno
< update_seqno
357 && (ws
.state
& WS_ST_FLASH
))
360 dst_h
= ag
->ag_dst_h
;
362 v1_mask
= ripv1_mask_host(htonl(dst_h
),
363 (ws
.state
& WS_ST_TO_ON_NET
) ? ws
.ifp
: 0);
366 /* If we are sending RIPv2 packets that cannot (or must not) be
367 * heard by RIPv1 listeners, do not worry about sub- or supernets.
368 * Subnets (from other networks) can only be sent via multicast.
369 * A pair of subnet routes might have been promoted so that they
370 * are legal to send by RIPv1.
371 * If RIPv1 is off, use the multicast buffer.
373 if ((ws
.state
& WS_ST_RIP2_ALL
)
374 || ((ag
->ag_state
& AGS_RIPV2
) && v1_mask
!= mask
)) {
375 /* use the RIPv2-only buffer */
379 /* use the RIPv1-or-RIPv2 buffer */
382 /* Convert supernet route into corresponding set of network
383 * routes for RIPv1, but leave non-contiguous netmasks
387 && mask
+ (mask
& -mask
) == 0) {
388 ddst_h
= v1_mask
& -v1_mask
;
389 i
= (v1_mask
& ~mask
)/ddst_h
;
391 if (i
> ws
.gen_limit
) {
392 /* Punt if we would have to generate an
393 * unreasonable number of routes.
396 trace_misc("sending %s-->%s as 1"
397 " instead of %d routes",
398 addrname(htonl(dst_h
), mask
,
400 naddr_ntoa(ws
.to
.sin_addr
413 wb
->n
->n_family
= RIP_AF_INET
;
414 wb
->n
->n_dst
= htonl(dst_h
);
415 /* If the route is from router-discovery or we are
416 * shutting down, admit only a bad metric.
418 wb
->n
->n_metric
= ((stopint
|| ag
->ag_metric
< 1)
421 wb
->n
->n_metric
= htonl(wb
->n
->n_metric
);
422 /* Any non-zero bits in the supposedly unused RIPv1 fields
423 * cause the old `routed` to ignore the route.
424 * That means the mask and so forth cannot be sent
425 * in the hybrid RIPv1/RIPv2 mode.
427 if (ws
.state
& WS_ST_RIP2_ALL
) {
429 && ((ws
.state
& WS_ST_QUERY
)
430 || (ag
->ag_nhop
!= ws
.ifp
->int_addr
431 && on_net(ag
->ag_nhop
,
434 wb
->n
->n_nhop
= ag
->ag_nhop
;
435 wb
->n
->n_mask
= htonl(mask
);
436 wb
->n
->n_tag
= ag
->ag_tag
;
440 if (++wb
->n
>= wb
->lim
)
446 /* supply one route from the table
450 walk_supply(struct radix_node
*rn
,
451 struct walkarg
*argp UNUSED
)
453 #define RT ((struct rt_entry *)rn)
457 struct rt_spare
*rts
;
461 /* Do not advertise external remote interfaces or passive interfaces.
463 if ((RT
->rt_state
& RS_IF
)
465 && (RT
->rt_ifp
->int_state
& IS_PASSIVE
)
466 && !(RT
->rt_state
& RS_MHOME
))
469 /* If being quiet about our ability to forward, then
470 * do not say anything unless responding to a query,
471 * except about our main interface.
473 if (!supplier
&& !(ws
.state
& WS_ST_QUERY
)
474 && !(RT
->rt_state
& RS_MHOME
))
479 /* do not collide with the fake default route */
480 if (dst
== RIP_DEFAULT
481 && (ws
.state
& WS_ST_DEFAULT
))
484 if (RT
->rt_state
& RS_NET_SYN
) {
485 if (RT
->rt_state
& RS_NET_INT
) {
486 /* Do not send manual synthetic network routes
489 if (on_net(ws
.to
.sin_addr
.s_addr
,
490 ntohl(dst
), RT
->rt_mask
))
494 /* Do not send automatic synthetic network routes
495 * if they are not needed because no RIPv1 listeners
498 if (ws
.state
& WS_ST_RIP2_ALL
)
501 /* Do not send automatic synthetic network routes to
504 if (on_net(ws
.to
.sin_addr
.s_addr
,
505 ntohl(dst
), RT
->rt_mask
))
511 /* Advertise the next hop if this is not a route for one
512 * of our interfaces and the next hop is on the same
513 * network as the target.
514 * The final determination is made by supply_out().
516 if (!(RT
->rt_state
& RS_IF
)
517 && RT
->rt_gate
!= myaddr
518 && RT
->rt_gate
!= loopaddr
)
524 metric
= RT
->rt_metric
;
527 if (RT
->rt_state
& RS_MHOME
) {
528 /* retain host route of multi-homed servers */
531 } else if (RT_ISHOST(RT
)) {
532 /* We should always suppress (into existing network routes)
533 * the host routes for the local end of our point-to-point
535 * If we are suppressing host routes in general, then do so.
536 * Avoid advertising host routes onto their own network,
537 * where they should be handled by proxy-ARP.
539 if ((RT
->rt_state
& RS_LOCAL
)
541 || on_net(dst
, ws
.to_net
, ws
.to_mask
))
544 /* Aggregate stray host routes into network routes if allowed.
545 * We cannot aggregate host routes into small network routes
546 * without confusing RIPv1 listeners into thinking the
547 * network routes are host routes.
549 if ((ws
.state
& WS_ST_AG
)
550 && !(ws
.state
& WS_ST_RIP2_ALL
))
551 ags
|= AGS_AGGREGATE
;
554 /* Always suppress network routes into other, existing
559 /* Generate supernets if allowed.
560 * If we can be heard by RIPv1 systems, we will
561 * later convert back to ordinary nets.
562 * This unifies dealing with received supernets.
564 if ((ws
.state
& WS_ST_AG
)
565 && ((RT
->rt_state
& RS_SUBNET
)
566 || (ws
.state
& WS_ST_SUPER_AG
)))
567 ags
|= AGS_AGGREGATE
;
570 /* Do not send RIPv1 advertisements of subnets to other
571 * networks. If possible, multicast them by RIPv2.
573 if ((RT
->rt_state
& RS_SUBNET
)
574 && !(ws
.state
& WS_ST_RIP2_ALL
)
575 && !on_net(dst
, ws
.to_std_net
, ws
.to_std_mask
))
576 ags
|= AGS_RIPV2
| AGS_AGGREGATE
;
579 /* Do not send a route back to where it came from, except in
580 * response to a query. This is "split-horizon". That means not
581 * advertising back to the same network and so via the same interface.
583 * We want to suppress routes that might have been fragmented
584 * from this route by a RIPv1 router and sent back to us, and so we
585 * cannot forget this route here. Let the split-horizon route
586 * suppress the fragmented routes and then itself be forgotten.
588 * Include the routes for both ends of point-to-point interfaces
589 * among those suppressed by split-horizon, since the other side
590 * should knows them as well as we do.
592 * Notice spare routes with the same metric that we are about to
593 * advertise, to split the horizon on redundant, inactive paths.
596 && !(ws
.state
& WS_ST_QUERY
)
597 && (ws
.state
& WS_ST_TO_ON_NET
)
598 && (!(RT
->rt_state
& RS_IF
)
599 || ws
.ifp
->int_if_flags
& IFF_POINTOPOINT
)) {
600 for (rts
= RT
->rt_spares
, i
= NUM_SPARES
; i
!= 0; i
--, rts
++) {
601 if (rts
->rts_metric
> metric
602 || rts
->rts_ifp
!= ws
.ifp
)
605 /* If we do not mark the route with AGS_SPLIT_HZ here,
606 * it will be poisoned-reverse, or advertised back
607 * toward its source with an infinite metric.
608 * If we have recently advertised the route with a
609 * better metric than we now have, then we should
610 * poison-reverse the route before suppressing it for
613 * In almost all cases, if there is no spare for the
614 * route then it is either old and dead or a brand
615 * new route. If it is brand new, there is no need
616 * for poison-reverse. If it is old and dead, it
617 * is already poisoned.
619 if (RT
->rt_poison_time
< now_expire
620 || RT
->rt_poison_metric
>= metric
621 || RT
->rt_spares
[1].rts_gate
== 0) {
623 ags
&= ~AGS_SUPPRESS
;
625 metric
= HOPCNT_INFINITY
;
630 /* Keep track of the best metric with which the
631 * route has been advertised recently.
633 if (RT
->rt_poison_metric
>= metric
634 || RT
->rt_poison_time
< now_expire
) {
635 RT
->rt_poison_time
= now
.tv_sec
;
636 RT
->rt_poison_metric
= metric
;
639 /* Adjust the outgoing metric by the cost of the link.
640 * Avoid aggregation when a route is counting to infinity.
642 pref
= RT
->rt_poison_metric
+ ws
.metric
;
645 /* Do not advertise stable routes that will be ignored,
646 * unless we are answering a query.
647 * If the route recently was advertised with a metric that
648 * would have been less than infinity through this interface,
649 * we need to continue to advertise it in order to poison it.
651 if (metric
>= HOPCNT_INFINITY
) {
652 if (!(ws
.state
& WS_ST_QUERY
)
653 && (pref
>= HOPCNT_INFINITY
654 || RT
->rt_poison_time
< now_garbage
))
657 metric
= HOPCNT_INFINITY
;
660 ag_check(dst
, RT
->rt_mask
, 0, nhop
, metric
, pref
,
661 RT
->rt_seqno
, RT
->rt_tag
, ags
, supply_out
);
667 /* Supply dst with the contents of the routing tables.
668 * If this won't fit in one packet, chop it up into several.
671 supply(struct sockaddr_in
*dst
,
672 struct interface
*ifp
, /* output interface */
673 enum output_type type
,
674 int flash
, /* 1=flash update */
675 int vers
, /* RIP version */
676 int passwd_ok
) /* OK to include cleartext password */
686 ws
.to_std_mask
= std_mask(ws
.to
.sin_addr
.s_addr
);
687 ws
.to_std_net
= ntohl(ws
.to
.sin_addr
.s_addr
) & ws
.to_std_mask
;
690 ws
.to_mask
= ifp
->int_mask
;
691 ws
.to_net
= ifp
->int_net
;
692 if (on_net(ws
.to
.sin_addr
.s_addr
, ws
.to_net
, ws
.to_mask
))
693 ws
.state
|= WS_ST_TO_ON_NET
;
696 ws
.to_mask
= ripv1_mask_net(ws
.to
.sin_addr
.s_addr
, 0);
697 ws
.to_net
= ntohl(ws
.to
.sin_addr
.s_addr
) & ws
.to_mask
;
698 rt
= rtfind(dst
->sin_addr
.s_addr
);
705 ws
.state
|= WS_ST_FLASH
;
707 if ((ws
.ifp
= ifp
) == NULL
) {
710 /* Adjust the advertised metric by the outgoing interface
713 ws
.metric
= ifp
->int_metric
+1;
716 ripv12_buf
.rip
.rip_vers
= vers
;
720 if (ifp
->int_if_flags
& IFF_MULTICAST
)
721 v2buf
.type
= OUT_MULTICAST
;
723 v2buf
.type
= NO_OUT_MULTICAST
;
724 v12buf
.type
= OUT_BROADCAST
;
728 ws
.state
|= WS_ST_QUERY
;
732 v2buf
.type
= (vers
== RIPv2
) ? type
: NO_OUT_RIPV2
;
736 case NO_OUT_MULTICAST
:
738 break; /* no output */
742 /* full RIPv2 only if cannot be heard by RIPv1 listeners */
743 if (type
!= OUT_BROADCAST
)
744 ws
.state
|= WS_ST_RIP2_ALL
;
745 if ((ws
.state
& WS_ST_QUERY
)
746 || !(ws
.state
& WS_ST_TO_ON_NET
)) {
747 ws
.state
|= (WS_ST_AG
| WS_ST_SUPER_AG
);
748 } else if (ifp
== NULL
|| !(ifp
->int_state
& IS_NO_AG
)) {
749 ws
.state
|= WS_ST_AG
;
750 if (type
!= OUT_BROADCAST
752 || !(ifp
->int_state
& IS_NO_SUPER_AG
)))
753 ws
.state
|= WS_ST_SUPER_AG
;
757 ws
.a
= (vers
== RIPv2
) ? find_auth(ifp
) : 0;
758 if (!passwd_ok
&& ws
.a
!= NULL
&& ws
.a
->type
== RIP_AUTH_PW
)
760 clr_ws_buf(&v12buf
,ws
.a
);
761 clr_ws_buf(&v2buf
,ws
.a
);
763 /* Fake a default route if asked and if there is not already
764 * a better, real default route.
766 if (supplier
&& (def_metric
= ifp
->int_d_metric
) != 0) {
767 if (NULL
== (rt
= rtget(RIP_DEFAULT
, 0))
768 || rt
->rt_metric
+ws
.metric
>= def_metric
) {
769 ws
.state
|= WS_ST_DEFAULT
;
770 ag_check(0, 0, 0, 0, def_metric
, def_metric
,
771 0, 0, 0, supply_out
);
773 def_metric
= rt
->rt_metric
+ws
.metric
;
776 /* If both RIPv2 and the poor-man's router discovery
777 * kludge are on, arrange to advertise an extra
778 * default route via RIPv1.
780 if ((ws
.state
& WS_ST_RIP2_ALL
)
781 && (ifp
->int_state
& IS_PM_RDISC
)) {
782 ripv12_buf
.rip
.rip_vers
= RIPv1
;
783 v12buf
.n
->n_family
= RIP_AF_INET
;
784 v12buf
.n
->n_dst
= htonl(RIP_DEFAULT
);
785 v12buf
.n
->n_metric
= htonl(def_metric
);
790 rn_walktree(rhead
, walk_supply
, 0);
791 ag_flush(0,0,supply_out
);
793 /* Flush the packet buffers, provided they are not empty and
794 * do not contain only the password.
796 if (v12buf
.n
!= v12buf
.base
797 && (v12buf
.n
> v12buf
.base
+1
798 || v12buf
.base
->n_family
!= RIP_AF_AUTH
))
799 supply_write(&v12buf
);
800 if (v2buf
.n
!= v2buf
.base
801 && (v2buf
.n
> v2buf
.base
+1
802 || v2buf
.base
->n_family
!= RIP_AF_AUTH
))
803 supply_write(&v2buf
);
805 /* If we sent nothing and this is an answer to a query, send
809 && (ws
.state
& WS_ST_QUERY
))
810 supply_write(&v12buf
);
814 /* send all of the routing table or just do a flash update
820 static struct sockaddr_in dst
= {sizeof(dst
), AF_INET
, 0, {0}, {0}};
822 static struct sockaddr_in dst
= {AF_INET
};
824 struct interface
*ifp
;
825 enum output_type type
;
827 struct timeval rtime
;
831 intvl_random(&rtime
, MIN_WAITTIME
, MAX_WAITTIME
);
833 timevaladd(&no_flash
, &now
);
838 trace_act("send %s and inhibit dynamic updates for %.3f sec",
839 flash
? "dynamic update" : "all routes",
840 rtime
.tv_sec
+ ((float)rtime
.tv_usec
)/1000000.0);
842 for (ifp
= ifnet
; ifp
!= NULL
; ifp
= ifp
->int_next
) {
843 /* Skip interfaces not doing RIP.
844 * Do try broken interfaces to see if they have healed.
846 if (IS_RIP_OUT_OFF(ifp
->int_state
))
849 /* skip turned off interfaces */
850 if (!iff_up(ifp
->int_if_flags
))
853 vers
= (ifp
->int_state
& IS_NO_RIPV1_OUT
) ? RIPv2
: RIPv1
;
855 if (ifp
->int_if_flags
& IFF_BROADCAST
) {
856 /* ordinary, hardware interface */
857 dst
.sin_addr
.s_addr
= ifp
->int_brdaddr
;
860 && !(ifp
->int_state
& IS_NO_RIP_MCAST
)) {
861 type
= OUT_MULTICAST
;
863 type
= OUT_BROADCAST
;
866 } else if (ifp
->int_if_flags
& IFF_POINTOPOINT
) {
867 /* point-to-point hardware interface */
868 dst
.sin_addr
.s_addr
= ifp
->int_dstaddr
;
871 } else if (ifp
->int_state
& IS_REMOTE
) {
872 /* remote interface */
873 dst
.sin_addr
.s_addr
= ifp
->int_addr
;
877 /* ATM, HIPPI, etc. */
881 supply(&dst
, ifp
, type
, flash
, vers
, 1);
884 update_seqno
++; /* all routes are up to date */
889 * Do it only once to an interface, and not even after the interface
890 * was broken and recovered.
896 static struct sockaddr_in dst
= {sizeof(dst
), AF_INET
, 0, {0}, {0}};
898 static struct sockaddr_in dst
= {AF_INET
};
900 struct interface
*ifp
;
902 enum output_type type
;
908 memset(&buf
, 0, sizeof(buf
));
910 for (ifp
= ifnet
; ifp
; ifp
= ifp
->int_next
) {
911 /* Skip interfaces those already queried.
912 * Do not ask via interfaces through which we don't
913 * accept input. Do not ask via interfaces that cannot
915 * Do try broken interfaces to see if they have healed.
917 if (IS_RIP_IN_OFF(ifp
->int_state
)
918 || ifp
->int_query_time
!= NEVER
)
921 /* skip turned off interfaces */
922 if (!iff_up(ifp
->int_if_flags
))
925 buf
.rip_vers
= (ifp
->int_state
&IS_NO_RIPV1_OUT
) ? RIPv2
:RIPv1
;
926 buf
.rip_cmd
= RIPCMD_REQUEST
;
927 buf
.rip_nets
[0].n_family
= RIP_AF_UNSPEC
;
928 buf
.rip_nets
[0].n_metric
= htonl(HOPCNT_INFINITY
);
930 /* Send a RIPv1 query only if allowed and if we will
931 * listen to RIPv1 routers.
933 if ((ifp
->int_state
& IS_NO_RIPV1_OUT
)
934 || (ifp
->int_state
& IS_NO_RIPV1_IN
)) {
935 buf
.rip_vers
= RIPv2
;
937 buf
.rip_vers
= RIPv1
;
940 if (ifp
->int_if_flags
& IFF_BROADCAST
) {
941 /* ordinary, hardware interface */
942 dst
.sin_addr
.s_addr
= ifp
->int_brdaddr
;
944 /* Broadcast RIPv1 queries and RIPv2 queries
945 * when the hardware cannot multicast.
947 if (buf
.rip_vers
== RIPv2
948 && (ifp
->int_if_flags
& IFF_MULTICAST
)
949 && !(ifp
->int_state
& IS_NO_RIP_MCAST
)) {
950 type
= OUT_MULTICAST
;
952 type
= OUT_BROADCAST
;
955 } else if (ifp
->int_if_flags
& IFF_POINTOPOINT
) {
956 /* point-to-point hardware interface */
957 dst
.sin_addr
.s_addr
= ifp
->int_dstaddr
;
960 } else if (ifp
->int_state
& IS_REMOTE
) {
961 /* remote interface */
962 dst
.sin_addr
.s_addr
= ifp
->int_addr
;
966 /* ATM, HIPPI, etc. */
970 ifp
->int_query_time
= now
.tv_sec
+SUPPLY_INTERVAL
;
971 if (output(type
, &dst
, ifp
, &buf
, sizeof(buf
)) < 0)