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 $
34 * $DragonFly: src/sbin/routed/output.c,v 1.5 2005/03/16 21:21:34 cpressey Exp $
39 #if !defined(sgi) && !defined(__NetBSD__)
40 static char sccsid
[] __attribute__((unused
)) = "@(#)output.c 8.1 (Berkeley) 6/5/93";
41 #elif defined(__NetBSD__)
49 /* walk the tree of routes with this for output
52 struct sockaddr_in to
;
57 struct interface
*ifp
; /* usually output interface */
59 char metric
; /* adjust metrics by interface */
63 #define WS_ST_FLASH 0x001 /* send only changed routes */
64 #define WS_ST_RIP2_ALL 0x002 /* send full featured RIPv2 */
65 #define WS_ST_AG 0x004 /* ok to aggregate subnets */
66 #define WS_ST_SUPER_AG 0x008 /* ok to aggregate networks */
67 #define WS_ST_QUERY 0x010 /* responding to a query */
68 #define WS_ST_TO_ON_NET 0x020 /* sending onto one of our nets */
69 #define WS_ST_DEFAULT 0x040 /* faking a default */
72 /* A buffer for what can be heard by both RIPv1 and RIPv2 listeners */
74 union pkt_buf ripv12_buf
;
76 /* Another for only RIPv2 listeners */
78 union pkt_buf rip_v2_buf
;
85 ripv12_buf
.rip
.rip_cmd
= RIPCMD_RESPONSE
;
86 v12buf
.buf
= &ripv12_buf
.rip
;
87 v12buf
.base
= &v12buf
.buf
->rip_nets
[0];
89 rip_v2_buf
.rip
.rip_cmd
= RIPCMD_RESPONSE
;
90 rip_v2_buf
.rip
.rip_vers
= RIPv2
;
91 v2buf
.buf
= &rip_v2_buf
.rip
;
92 v2buf
.base
= &v2buf
.buf
->rip_nets
[0];
96 /* Send the contents of the global buffer via the non-multicast socket
98 int /* <0 on failure */
99 output(enum output_type type
,
100 struct sockaddr_in
*dst
, /* send to here */
101 struct interface
*ifp
,
103 int size
) /* this many bytes */
105 struct sockaddr_in in
;
114 if (in
.sin_port
== 0)
115 in
.sin_port
= htons(RIP_PORT
);
118 in
.sin_len
= sizeof(in
);
126 msg
= "Answer Query";
128 soc
= ifp
->int_rip_sock
;
133 soc
= ifp
->int_rip_sock
;
134 flags
= MSG_DONTROUTE
;
137 if (ifp
->int_if_flags
& IFF_POINTOPOINT
) {
142 flags
= MSG_DONTROUTE
;
145 if (ifp
->int_if_flags
& IFF_POINTOPOINT
) {
146 msg
= "Send pt-to-pt";
147 } else if (ifp
->int_state
& IS_DUP
) {
148 trace_act("abort multicast output via %s"
149 " with duplicate address",
154 if (rip_sock_mcast
!= ifp
) {
156 /* Do not specify the primary interface
157 * explicitly if we have the multicast
158 * point-to-point kernel bug, since the
159 * kernel will do the wrong thing if the
160 * local address of a point-to-point link
161 * is the same as the address of an ordinary
164 if (ifp
->int_addr
== myaddr
) {
168 tgt_mcast
= ifp
->int_addr
;
169 if (0 > setsockopt(rip_sock
,
170 IPPROTO_IP
, IP_MULTICAST_IF
,
172 sizeof(tgt_mcast
))) {
174 LOGERR("setsockopt(rip_sock,"
180 rip_sock_mcast
= ifp
;
182 in
.sin_addr
.s_addr
= htonl(INADDR_RIP_GROUP
);
186 case NO_OUT_MULTICAST
:
195 trace_rip(msg
, "to", &in
, ifp
, buf
, size
);
197 res
= sendto(soc
, buf
, size
, flags
,
198 (struct sockaddr
*)&in
, sizeof(in
));
200 && (ifp
== 0 || !(ifp
->int_state
& IS_BROKE
))) {
202 msglog("%s sendto(%s%s%s.%d): %s", msg
,
203 ifp
!= 0 ? ifp
->int_name
: "",
204 ifp
!= 0 ? ", " : "",
205 inet_ntoa(in
.sin_addr
),
215 /* Find the first key for a packet to send.
216 * Try for a key that is eligible and has not expired, but settle for
217 * the last key if they have all expired.
218 * If no key is ready yet, give up.
221 find_auth(struct interface
*ifp
)
223 struct auth
*ap
, *res
;
232 for (i
= 0; i
< MAX_AUTH_KEYS
; i
++, ap
++) {
233 /* stop looking after the last key */
234 if (ap
->type
== RIP_AUTH_NONE
)
237 /* ignore keys that are not ready yet */
238 if ((u_long
)ap
->start
> (u_long
)clk
.tv_sec
)
241 if ((u_long
)ap
->end
< (u_long
)clk
.tv_sec
) {
242 /* note best expired password as a fall-back */
243 if (res
== 0 || (u_long
)ap
->end
> (u_long
)res
->end
)
248 /* note key with the best future */
249 if (res
== 0 || (u_long
)res
->end
< (u_long
)ap
->end
)
257 clr_ws_buf(struct ws_buf
*wb
,
262 wb
->lim
= wb
->base
+ NETS_LEN
;
264 memset(wb
->n
, 0, NETS_LEN
*sizeof(*wb
->n
));
266 /* (start to) install authentication if appropriate
271 na
= (struct netauth
*)wb
->n
;
272 if (ap
->type
== RIP_AUTH_PW
) {
273 na
->a_family
= RIP_AF_AUTH
;
274 na
->a_type
= RIP_AUTH_PW
;
275 memcpy(na
->au
.au_pw
, ap
->key
, sizeof(na
->au
.au_pw
));
278 } else if (ap
->type
== RIP_AUTH_MD5
) {
279 na
->a_family
= RIP_AF_AUTH
;
280 na
->a_type
= RIP_AUTH_MD5
;
281 na
->au
.a_md5
.md5_keyid
= ap
->keyid
;
282 na
->au
.a_md5
.md5_auth_len
= RIP_AUTH_MD5_LEN
;
283 na
->au
.a_md5
.md5_seqno
= htonl(clk
.tv_sec
);
285 wb
->lim
--; /* make room for trailer */
291 end_md5_auth(struct ws_buf
*wb
,
294 struct netauth
*na
, *na2
;
299 na
= (struct netauth
*)wb
->base
;
300 na2
= (struct netauth
*)wb
->n
;
301 len
= (char *)na2
-(char *)wb
->buf
;
302 na2
->a_family
= RIP_AF_AUTH
;
303 na2
->a_type
= htons(1);
304 na
->au
.a_md5
.md5_pkt_len
= htons(len
);
306 MD5Update(&md5_ctx
, (u_char
*)wb
->buf
, len
);
307 MD5Update(&md5_ctx
, ap
->key
, RIP_AUTH_MD5_LEN
);
308 MD5Final(na2
->au
.au_pw
, &md5_ctx
);
316 supply_write(struct ws_buf
*wb
)
318 /* Output multicast only if legal.
319 * If we would multicast and it would be illegal, then discard the
323 case NO_OUT_MULTICAST
:
324 trace_pkt("skip multicast to %s because impossible",
325 naddr_ntoa(ws
.to
.sin_addr
.s_addr
));
330 if (ws
.a
!= 0 && ws
.a
->type
== RIP_AUTH_MD5
)
331 end_md5_auth(wb
,ws
.a
);
332 if (output(wb
->type
, &ws
.to
, ws
.ifp
, wb
->buf
,
333 ((char *)wb
->n
- (char*)wb
->buf
)) < 0
344 /* put an entry into the packet
347 supply_out(struct ag_info
*ag
)
350 naddr mask
, v1_mask
, dst_h
, ddst_h
= 0;
354 /* Skip this route if doing a flash update and it and the routes
355 * it aggregates have not changed recently.
357 if (ag
->ag_seqno
< update_seqno
358 && (ws
.state
& WS_ST_FLASH
))
361 dst_h
= ag
->ag_dst_h
;
363 v1_mask
= ripv1_mask_host(htonl(dst_h
),
364 (ws
.state
& WS_ST_TO_ON_NET
) ? ws
.ifp
: 0);
367 /* If we are sending RIPv2 packets that cannot (or must not) be
368 * heard by RIPv1 listeners, do not worry about sub- or supernets.
369 * Subnets (from other networks) can only be sent via multicast.
370 * A pair of subnet routes might have been promoted so that they
371 * are legal to send by RIPv1.
372 * If RIPv1 is off, use the multicast buffer.
374 if ((ws
.state
& WS_ST_RIP2_ALL
)
375 || ((ag
->ag_state
& AGS_RIPV2
) && v1_mask
!= mask
)) {
376 /* use the RIPv2-only buffer */
380 /* use the RIPv1-or-RIPv2 buffer */
383 /* Convert supernet route into corresponding set of network
384 * routes for RIPv1, but leave non-contiguous netmasks
388 && mask
+ (mask
& -mask
) == 0) {
389 ddst_h
= v1_mask
& -v1_mask
;
390 i
= (v1_mask
& ~mask
)/ddst_h
;
392 if (i
> ws
.gen_limit
) {
393 /* Punt if we would have to generate an
394 * unreasonable number of routes.
397 trace_misc("sending %s-->%s as 1"
398 " instead of %d routes",
399 addrname(htonl(dst_h
), mask
,
401 naddr_ntoa(ws
.to
.sin_addr
414 wb
->n
->n_family
= RIP_AF_INET
;
415 wb
->n
->n_dst
= htonl(dst_h
);
416 /* If the route is from router-discovery or we are
417 * shutting down, admit only a bad metric.
419 wb
->n
->n_metric
= ((stopint
|| ag
->ag_metric
< 1)
422 wb
->n
->n_metric
= htonl(wb
->n
->n_metric
);
423 /* Any non-zero bits in the supposedly unused RIPv1 fields
424 * cause the old `routed` to ignore the route.
425 * That means the mask and so forth cannot be sent
426 * in the hybrid RIPv1/RIPv2 mode.
428 if (ws
.state
& WS_ST_RIP2_ALL
) {
430 && ((ws
.state
& WS_ST_QUERY
)
431 || (ag
->ag_nhop
!= ws
.ifp
->int_addr
432 && on_net(ag
->ag_nhop
,
435 wb
->n
->n_nhop
= ag
->ag_nhop
;
436 wb
->n
->n_mask
= htonl(mask
);
437 wb
->n
->n_tag
= ag
->ag_tag
;
441 if (++wb
->n
>= wb
->lim
)
447 /* supply one route from the table
451 walk_supply(struct radix_node
*rn
,
452 struct walkarg
*argp UNUSED
)
454 #define RT ((struct rt_entry *)rn)
458 struct rt_spare
*rts
;
462 /* Do not advertise external remote interfaces or passive interfaces.
464 if ((RT
->rt_state
& RS_IF
)
466 && (RT
->rt_ifp
->int_state
& IS_PASSIVE
)
467 && !(RT
->rt_state
& RS_MHOME
))
470 /* If being quiet about our ability to forward, then
471 * do not say anything unless responding to a query,
472 * except about our main interface.
474 if (!supplier
&& !(ws
.state
& WS_ST_QUERY
)
475 && !(RT
->rt_state
& RS_MHOME
))
480 /* do not collide with the fake default route */
481 if (dst
== RIP_DEFAULT
482 && (ws
.state
& WS_ST_DEFAULT
))
485 if (RT
->rt_state
& RS_NET_SYN
) {
486 if (RT
->rt_state
& RS_NET_INT
) {
487 /* Do not send manual synthetic network routes
490 if (on_net(ws
.to
.sin_addr
.s_addr
,
491 ntohl(dst
), RT
->rt_mask
))
495 /* Do not send automatic synthetic network routes
496 * if they are not needed because no RIPv1 listeners
499 if (ws
.state
& WS_ST_RIP2_ALL
)
502 /* Do not send automatic synthetic network routes to
505 if (on_net(ws
.to
.sin_addr
.s_addr
,
506 ntohl(dst
), RT
->rt_mask
))
512 /* Advertise the next hop if this is not a route for one
513 * of our interfaces and the next hop is on the same
514 * network as the target.
515 * The final determination is made by supply_out().
517 if (!(RT
->rt_state
& RS_IF
)
518 && RT
->rt_gate
!= myaddr
519 && RT
->rt_gate
!= loopaddr
)
525 metric
= RT
->rt_metric
;
528 if (RT
->rt_state
& RS_MHOME
) {
529 /* retain host route of multi-homed servers */
532 } else if (RT_ISHOST(RT
)) {
533 /* We should always suppress (into existing network routes)
534 * the host routes for the local end of our point-to-point
536 * If we are suppressing host routes in general, then do so.
537 * Avoid advertising host routes onto their own network,
538 * where they should be handled by proxy-ARP.
540 if ((RT
->rt_state
& RS_LOCAL
)
542 || on_net(dst
, ws
.to_net
, ws
.to_mask
))
545 /* Aggregate stray host routes into network routes if allowed.
546 * We cannot aggregate host routes into small network routes
547 * without confusing RIPv1 listeners into thinking the
548 * network routes are host routes.
550 if ((ws
.state
& WS_ST_AG
)
551 && !(ws
.state
& WS_ST_RIP2_ALL
))
552 ags
|= AGS_AGGREGATE
;
555 /* Always suppress network routes into other, existing
560 /* Generate supernets if allowed.
561 * If we can be heard by RIPv1 systems, we will
562 * later convert back to ordinary nets.
563 * This unifies dealing with received supernets.
565 if ((ws
.state
& WS_ST_AG
)
566 && ((RT
->rt_state
& RS_SUBNET
)
567 || (ws
.state
& WS_ST_SUPER_AG
)))
568 ags
|= AGS_AGGREGATE
;
571 /* Do not send RIPv1 advertisements of subnets to other
572 * networks. If possible, multicast them by RIPv2.
574 if ((RT
->rt_state
& RS_SUBNET
)
575 && !(ws
.state
& WS_ST_RIP2_ALL
)
576 && !on_net(dst
, ws
.to_std_net
, ws
.to_std_mask
))
577 ags
|= AGS_RIPV2
| AGS_AGGREGATE
;
580 /* Do not send a route back to where it came from, except in
581 * response to a query. This is "split-horizon". That means not
582 * advertising back to the same network and so via the same interface.
584 * We want to suppress routes that might have been fragmented
585 * from this route by a RIPv1 router and sent back to us, and so we
586 * cannot forget this route here. Let the split-horizon route
587 * suppress the fragmented routes and then itself be forgotten.
589 * Include the routes for both ends of point-to-point interfaces
590 * among those suppressed by split-horizon, since the other side
591 * should knows them as well as we do.
593 * Notice spare routes with the same metric that we are about to
594 * advertise, to split the horizon on redundant, inactive paths.
597 && !(ws
.state
& WS_ST_QUERY
)
598 && (ws
.state
& WS_ST_TO_ON_NET
)
599 && (!(RT
->rt_state
& RS_IF
)
600 || ws
.ifp
->int_if_flags
& IFF_POINTOPOINT
)) {
601 for (rts
= RT
->rt_spares
, i
= NUM_SPARES
; i
!= 0; i
--, rts
++) {
602 if (rts
->rts_metric
> metric
603 || rts
->rts_ifp
!= ws
.ifp
)
606 /* If we do not mark the route with AGS_SPLIT_HZ here,
607 * it will be poisoned-reverse, or advertised back
608 * toward its source with an infinite metric.
609 * If we have recently advertised the route with a
610 * better metric than we now have, then we should
611 * poison-reverse the route before suppressing it for
614 * In almost all cases, if there is no spare for the
615 * route then it is either old and dead or a brand
616 * new route. If it is brand new, there is no need
617 * for poison-reverse. If it is old and dead, it
618 * is already poisoned.
620 if (RT
->rt_poison_time
< now_expire
621 || RT
->rt_poison_metric
>= metric
622 || RT
->rt_spares
[1].rts_gate
== 0) {
624 ags
&= ~AGS_SUPPRESS
;
626 metric
= HOPCNT_INFINITY
;
631 /* Keep track of the best metric with which the
632 * route has been advertised recently.
634 if (RT
->rt_poison_metric
>= metric
635 || RT
->rt_poison_time
< now_expire
) {
636 RT
->rt_poison_time
= now
.tv_sec
;
637 RT
->rt_poison_metric
= metric
;
640 /* Adjust the outgoing metric by the cost of the link.
641 * Avoid aggregation when a route is counting to infinity.
643 pref
= RT
->rt_poison_metric
+ ws
.metric
;
646 /* Do not advertise stable routes that will be ignored,
647 * unless we are answering a query.
648 * If the route recently was advertised with a metric that
649 * would have been less than infinity through this interface,
650 * we need to continue to advertise it in order to poison it.
652 if (metric
>= HOPCNT_INFINITY
) {
653 if (!(ws
.state
& WS_ST_QUERY
)
654 && (pref
>= HOPCNT_INFINITY
655 || RT
->rt_poison_time
< now_garbage
))
658 metric
= HOPCNT_INFINITY
;
661 ag_check(dst
, RT
->rt_mask
, 0, nhop
, metric
, pref
,
662 RT
->rt_seqno
, RT
->rt_tag
, ags
, supply_out
);
668 /* Supply dst with the contents of the routing tables.
669 * If this won't fit in one packet, chop it up into several.
672 supply(struct sockaddr_in
*dst
,
673 struct interface
*ifp
, /* output interface */
674 enum output_type type
,
675 int flash
, /* 1=flash update */
676 int vers
, /* RIP version */
677 int passwd_ok
) /* OK to include cleartext password */
687 ws
.to_std_mask
= std_mask(ws
.to
.sin_addr
.s_addr
);
688 ws
.to_std_net
= ntohl(ws
.to
.sin_addr
.s_addr
) & ws
.to_std_mask
;
691 ws
.to_mask
= ifp
->int_mask
;
692 ws
.to_net
= ifp
->int_net
;
693 if (on_net(ws
.to
.sin_addr
.s_addr
, ws
.to_net
, ws
.to_mask
))
694 ws
.state
|= WS_ST_TO_ON_NET
;
697 ws
.to_mask
= ripv1_mask_net(ws
.to
.sin_addr
.s_addr
, 0);
698 ws
.to_net
= ntohl(ws
.to
.sin_addr
.s_addr
) & ws
.to_mask
;
699 rt
= rtfind(dst
->sin_addr
.s_addr
);
706 ws
.state
|= WS_ST_FLASH
;
708 if ((ws
.ifp
= ifp
) == 0) {
711 /* Adjust the advertised metric by the outgoing interface
714 ws
.metric
= ifp
->int_metric
+1;
717 ripv12_buf
.rip
.rip_vers
= vers
;
721 if (ifp
->int_if_flags
& IFF_MULTICAST
)
722 v2buf
.type
= OUT_MULTICAST
;
724 v2buf
.type
= NO_OUT_MULTICAST
;
725 v12buf
.type
= OUT_BROADCAST
;
729 ws
.state
|= WS_ST_QUERY
;
733 v2buf
.type
= (vers
== RIPv2
) ? type
: NO_OUT_RIPV2
;
737 case NO_OUT_MULTICAST
:
739 break; /* no output */
743 /* full RIPv2 only if cannot be heard by RIPv1 listeners */
744 if (type
!= OUT_BROADCAST
)
745 ws
.state
|= WS_ST_RIP2_ALL
;
746 if ((ws
.state
& WS_ST_QUERY
)
747 || !(ws
.state
& WS_ST_TO_ON_NET
)) {
748 ws
.state
|= (WS_ST_AG
| WS_ST_SUPER_AG
);
749 } else if (ifp
== 0 || !(ifp
->int_state
& IS_NO_AG
)) {
750 ws
.state
|= WS_ST_AG
;
751 if (type
!= OUT_BROADCAST
753 || !(ifp
->int_state
& IS_NO_SUPER_AG
)))
754 ws
.state
|= WS_ST_SUPER_AG
;
758 ws
.a
= (vers
== RIPv2
) ? find_auth(ifp
) : 0;
759 if (!passwd_ok
&& ws
.a
!= 0 && ws
.a
->type
== RIP_AUTH_PW
)
761 clr_ws_buf(&v12buf
,ws
.a
);
762 clr_ws_buf(&v2buf
,ws
.a
);
764 /* Fake a default route if asked and if there is not already
765 * a better, real default route.
767 if (supplier
&& (def_metric
= ifp
->int_d_metric
) != 0) {
768 if (0 == (rt
= rtget(RIP_DEFAULT
, 0))
769 || rt
->rt_metric
+ws
.metric
>= def_metric
) {
770 ws
.state
|= WS_ST_DEFAULT
;
771 ag_check(0, 0, 0, 0, def_metric
, def_metric
,
772 0, 0, 0, supply_out
);
774 def_metric
= rt
->rt_metric
+ws
.metric
;
777 /* If both RIPv2 and the poor-man's router discovery
778 * kludge are on, arrange to advertise an extra
779 * default route via RIPv1.
781 if ((ws
.state
& WS_ST_RIP2_ALL
)
782 && (ifp
->int_state
& IS_PM_RDISC
)) {
783 ripv12_buf
.rip
.rip_vers
= RIPv1
;
784 v12buf
.n
->n_family
= RIP_AF_INET
;
785 v12buf
.n
->n_dst
= htonl(RIP_DEFAULT
);
786 v12buf
.n
->n_metric
= htonl(def_metric
);
791 rn_walktree(rhead
, walk_supply
, 0);
792 ag_flush(0,0,supply_out
);
794 /* Flush the packet buffers, provided they are not empty and
795 * do not contain only the password.
797 if (v12buf
.n
!= v12buf
.base
798 && (v12buf
.n
> v12buf
.base
+1
799 || v12buf
.base
->n_family
!= RIP_AF_AUTH
))
800 supply_write(&v12buf
);
801 if (v2buf
.n
!= v2buf
.base
802 && (v2buf
.n
> v2buf
.base
+1
803 || v2buf
.base
->n_family
!= RIP_AF_AUTH
))
804 supply_write(&v2buf
);
806 /* If we sent nothing and this is an answer to a query, send
810 && (ws
.state
& WS_ST_QUERY
))
811 supply_write(&v12buf
);
815 /* send all of the routing table or just do a flash update
821 static struct sockaddr_in dst
= {sizeof(dst
), AF_INET
, 0, {0}, {0}};
823 static struct sockaddr_in dst
= {AF_INET
};
825 struct interface
*ifp
;
826 enum output_type type
;
828 struct timeval rtime
;
832 intvl_random(&rtime
, MIN_WAITTIME
, MAX_WAITTIME
);
834 timevaladd(&no_flash
, &now
);
839 trace_act("send %s and inhibit dynamic updates for %.3f sec",
840 flash
? "dynamic update" : "all routes",
841 rtime
.tv_sec
+ ((float)rtime
.tv_usec
)/1000000.0);
843 for (ifp
= ifnet
; ifp
!= 0; ifp
= ifp
->int_next
) {
844 /* Skip interfaces not doing RIP.
845 * Do try broken interfaces to see if they have healed.
847 if (IS_RIP_OUT_OFF(ifp
->int_state
))
850 /* skip turned off interfaces */
851 if (!iff_up(ifp
->int_if_flags
))
854 vers
= (ifp
->int_state
& IS_NO_RIPV1_OUT
) ? RIPv2
: RIPv1
;
856 if (ifp
->int_if_flags
& IFF_BROADCAST
) {
857 /* ordinary, hardware interface */
858 dst
.sin_addr
.s_addr
= ifp
->int_brdaddr
;
861 && !(ifp
->int_state
& IS_NO_RIP_MCAST
)) {
862 type
= OUT_MULTICAST
;
864 type
= OUT_BROADCAST
;
867 } else if (ifp
->int_if_flags
& IFF_POINTOPOINT
) {
868 /* point-to-point hardware interface */
869 dst
.sin_addr
.s_addr
= ifp
->int_dstaddr
;
872 } else if (ifp
->int_state
& IS_REMOTE
) {
873 /* remote interface */
874 dst
.sin_addr
.s_addr
= ifp
->int_addr
;
878 /* ATM, HIPPI, etc. */
882 supply(&dst
, ifp
, type
, flash
, vers
, 1);
885 update_seqno
++; /* all routes are up to date */
890 * Do it only once to an interface, and not even after the interface
891 * was broken and recovered.
897 static struct sockaddr_in dst
= {sizeof(dst
), AF_INET
, 0, {0}, {0}};
899 static struct sockaddr_in dst
= {AF_INET
};
901 struct interface
*ifp
;
903 enum output_type type
;
909 memset(&buf
, 0, sizeof(buf
));
911 for (ifp
= ifnet
; ifp
; ifp
= ifp
->int_next
) {
912 /* Skip interfaces those already queried.
913 * Do not ask via interfaces through which we don't
914 * accept input. Do not ask via interfaces that cannot
916 * Do try broken interfaces to see if they have healed.
918 if (IS_RIP_IN_OFF(ifp
->int_state
)
919 || ifp
->int_query_time
!= NEVER
)
922 /* skip turned off interfaces */
923 if (!iff_up(ifp
->int_if_flags
))
926 buf
.rip_vers
= (ifp
->int_state
&IS_NO_RIPV1_OUT
) ? RIPv2
:RIPv1
;
927 buf
.rip_cmd
= RIPCMD_REQUEST
;
928 buf
.rip_nets
[0].n_family
= RIP_AF_UNSPEC
;
929 buf
.rip_nets
[0].n_metric
= htonl(HOPCNT_INFINITY
);
931 /* Send a RIPv1 query only if allowed and if we will
932 * listen to RIPv1 routers.
934 if ((ifp
->int_state
& IS_NO_RIPV1_OUT
)
935 || (ifp
->int_state
& IS_NO_RIPV1_IN
)) {
936 buf
.rip_vers
= RIPv2
;
938 buf
.rip_vers
= RIPv1
;
941 if (ifp
->int_if_flags
& IFF_BROADCAST
) {
942 /* ordinary, hardware interface */
943 dst
.sin_addr
.s_addr
= ifp
->int_brdaddr
;
945 /* Broadcast RIPv1 queries and RIPv2 queries
946 * when the hardware cannot multicast.
948 if (buf
.rip_vers
== RIPv2
949 && (ifp
->int_if_flags
& IFF_MULTICAST
)
950 && !(ifp
->int_state
& IS_NO_RIP_MCAST
)) {
951 type
= OUT_MULTICAST
;
953 type
= OUT_BROADCAST
;
956 } else if (ifp
->int_if_flags
& IFF_POINTOPOINT
) {
957 /* point-to-point hardware interface */
958 dst
.sin_addr
.s_addr
= ifp
->int_dstaddr
;
961 } else if (ifp
->int_state
& IS_REMOTE
) {
962 /* remote interface */
963 dst
.sin_addr
.s_addr
= ifp
->int_addr
;
967 /* ATM, HIPPI, etc. */
971 ifp
->int_query_time
= now
.tv_sec
+SUPPLY_INTERVAL
;
972 if (output(type
, &dst
, ifp
, &buf
, sizeof(buf
)) < 0)