get "h" and "m" flags working; clean up interface with getvol()
[unix-history] / usr / src / sbin / routed / output.c
CommitLineData
7e7de0c9 1#ifndef lint
7fe7fe74 2static char sccsid[] = "@(#)output.c 4.2 %G%";
7e7de0c9
SL
3#endif
4
5/*
6 * Routing Table Management Daemon
7 */
7fe7fe74 8#include "defs.h"
7e7de0c9
SL
9
10/*
11 * Apply the function "f" to all non-passive
12 * interfaces. If the interface supports the
13 * use of broadcasting use it, otherwise address
14 * the output to the known router.
15 */
16toall(f)
17 int (*f)();
18{
19 register struct interface *ifp;
20 register struct sockaddr *dst;
7fe7fe74 21 register int flags;
7e7de0c9
SL
22 extern struct interface *ifnet;
23
24 for (ifp = ifnet; ifp; ifp = ifp->int_next) {
25 if (ifp->int_flags & IFF_PASSIVE)
26 continue;
27 dst = ifp->int_flags & IFF_BROADCAST ? &ifp->int_broadaddr :
28 ifp->int_flags & IFF_POINTOPOINT ? &ifp->int_dstaddr :
29 &ifp->int_addr;
7fe7fe74
SL
30 flags = ifp->int_flags & IFF_INTERFACE ? SOF_DONTROUTE : 0;
31 (*f)(dst, flags, ifp);
7e7de0c9
SL
32 }
33}
34
35/*
36 * Output a preformed packet.
37 */
38/*ARGSUSED*/
7fe7fe74 39sendmsg(dst, flags, ifp)
7e7de0c9 40 struct sockaddr *dst;
7fe7fe74 41 int flags;
7e7de0c9
SL
42 struct interface *ifp;
43{
44
7fe7fe74 45 (*afswitch[dst->sa_family].af_output)(s, flags,
7e7de0c9
SL
46 dst, sizeof (struct rip));
47 TRACE_OUTPUT(ifp, dst, sizeof (struct rip));
48}
49
50/*
51 * Supply dst with the contents of the routing tables.
52 * If this won't fit in one packet, chop it up into several.
53 */
7fe7fe74 54supply(dst, flags, ifp)
7e7de0c9 55 struct sockaddr *dst;
7fe7fe74 56 int flags;
7e7de0c9
SL
57 struct interface *ifp;
58{
59 register struct rt_entry *rt;
60 struct netinfo *n = msg->rip_nets;
61 register struct rthash *rh;
62 struct rthash *base = hosthash;
63 int doinghost = 1, size;
64 int (*output)() = afswitch[dst->sa_family].af_output;
7e7de0c9
SL
65
66 msg->rip_cmd = RIPCMD_RESPONSE;
67again:
68 for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++)
69 for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) {
70 size = (char *)n - packet;
71 if (size > MAXPACKETSIZE - sizeof (struct netinfo)) {
7fe7fe74 72 (*output)(s, flags, dst, size);
7e7de0c9
SL
73 TRACE_OUTPUT(ifp, dst, size);
74 n = msg->rip_nets;
75 }
76 n->rip_dst = rt->rt_dst;
77 n->rip_metric = min(rt->rt_metric + 1, HOPCNT_INFINITY);
78 n++;
79 }
80 if (doinghost) {
81 doinghost = 0;
82 base = nethash;
83 goto again;
84 }
85 if (n != msg->rip_nets) {
86 size = (char *)n - packet;
7fe7fe74 87 (*output)(s, flags, dst, size);
7e7de0c9
SL
88 TRACE_OUTPUT(ifp, dst, size);
89 }
90}