Commit | Line | Data |
---|---|---|
3efa4c38 | 1 | /* |
3565c602 KB |
2 | * Copyright (c) 1985 The Regents of the University of California. |
3 | * All rights reserved. | |
3efa4c38 | 4 | * |
3565c602 KB |
5 | * This file includes significant work done at Cornell University by |
6 | * Bill Nesheim. That work included by permission. | |
7 | * | |
6ecf3d85 | 8 | * %sccs.include.redist.c% |
3efa4c38 KS |
9 | */ |
10 | ||
df6b4396 | 11 | #ifndef lint |
b6a2f0a4 | 12 | static char sccsid[] = "@(#)output.c 5.8 (Berkeley) %G%"; |
3565c602 | 13 | #endif /* not lint */ |
df6b4396 KS |
14 | |
15 | /* | |
16 | * Routing Table Management Daemon | |
17 | */ | |
18 | #include "defs.h" | |
19 | ||
20 | /* | |
21 | * Apply the function "f" to all non-passive | |
22 | * interfaces. If the interface supports the | |
23 | * use of broadcasting use it, otherwise address | |
24 | * the output to the known router. | |
25 | */ | |
26 | toall(f) | |
27 | int (*f)(); | |
28 | { | |
29 | register struct interface *ifp; | |
30 | register struct sockaddr *dst; | |
31 | register int flags; | |
32 | extern struct interface *ifnet; | |
33 | ||
34 | for (ifp = ifnet; ifp; ifp = ifp->int_next) { | |
35 | if (ifp->int_flags & IFF_PASSIVE) | |
36 | continue; | |
37 | dst = ifp->int_flags & IFF_BROADCAST ? &ifp->int_broadaddr : | |
38 | ifp->int_flags & IFF_POINTOPOINT ? &ifp->int_dstaddr : | |
39 | &ifp->int_addr; | |
40 | flags = ifp->int_flags & IFF_INTERFACE ? MSG_DONTROUTE : 0; | |
41 | (*f)(dst, flags, ifp); | |
42 | } | |
43 | } | |
44 | ||
45 | /* | |
46 | * Output a preformed packet. | |
47 | */ | |
48 | /*ARGSUSED*/ | |
b6a2f0a4 | 49 | sndmsg(dst, flags, ifp) |
df6b4396 KS |
50 | struct sockaddr *dst; |
51 | int flags; | |
52 | struct interface *ifp; | |
53 | { | |
54 | ||
48681466 KS |
55 | (*afswitch[dst->sa_family].af_output) |
56 | (flags, dst, sizeof (struct rip)); | |
df6b4396 KS |
57 | TRACE_OUTPUT(ifp, dst, sizeof (struct rip)); |
58 | } | |
59 | ||
60 | /* | |
61 | * Supply dst with the contents of the routing tables. | |
62 | * If this won't fit in one packet, chop it up into several. | |
63 | */ | |
64 | supply(dst, flags, ifp) | |
65 | struct sockaddr *dst; | |
66 | int flags; | |
67 | struct interface *ifp; | |
68 | { | |
69 | register struct rt_entry *rt; | |
df6b4396 | 70 | register struct rthash *rh; |
4a10c08d KS |
71 | register struct netinfo *nn; |
72 | register struct netinfo *n = msg->rip_nets; | |
df6b4396 | 73 | struct rthash *base = hosthash; |
48681466 | 74 | struct sockaddr_ns *sns = (struct sockaddr_ns *) dst; |
df6b4396 | 75 | int (*output)() = afswitch[dst->sa_family].af_output; |
4a10c08d | 76 | int doinghost = 1, size, metric; |
84f93e8f | 77 | union ns_net net; |
df6b4396 KS |
78 | |
79 | msg->rip_cmd = ntohs(RIPCMD_RESPONSE); | |
80 | again: | |
81 | for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) | |
82 | for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) { | |
83 | size = (char *)n - (char *)msg; | |
84 | if (size > MAXPACKETSIZE - sizeof (struct netinfo)) { | |
48681466 | 85 | (*output)(flags, dst, size); |
df6b4396 KS |
86 | TRACE_OUTPUT(ifp, dst, size); |
87 | n = msg->rip_nets; | |
88 | } | |
48681466 | 89 | sns = (struct sockaddr_ns *)&rt->rt_dst; |
3efa4c38 KS |
90 | if ((rt->rt_flags & (RTF_HOST|RTF_GATEWAY)) == RTF_HOST) |
91 | sns = (struct sockaddr_ns *)&rt->rt_router; | |
4a10c08d | 92 | metric = min(rt->rt_metric + 1, HOPCNT_INFINITY); |
84f93e8f | 93 | net = sns->sns_addr.x_net; |
4a10c08d KS |
94 | /* |
95 | * Make sure that we don't put out a two net entries | |
96 | * for a pt to pt link (one for the G route, one for the if) | |
97 | * This is a kludge, and won't work if there are lots of nets. | |
98 | */ | |
99 | for (nn = msg->rip_nets; nn < n; nn++) { | |
84f93e8f KS |
100 | if (ns_neteqnn(net, nn->rip_dst)) { |
101 | if (metric < ntohs(nn->rip_metric)) | |
4a10c08d KS |
102 | nn->rip_metric = htons(metric); |
103 | goto next; | |
104 | } | |
105 | } | |
84f93e8f | 106 | n->rip_dst = net; |
4a10c08d | 107 | n->rip_metric = htons(metric); |
df6b4396 | 108 | n++; |
4a10c08d | 109 | next:; |
df6b4396 KS |
110 | } |
111 | if (doinghost) { | |
112 | doinghost = 0; | |
113 | base = nethash; | |
114 | goto again; | |
115 | } | |
116 | if (n != msg->rip_nets) { | |
117 | size = (char *)n - (char *)msg; | |
48681466 | 118 | (*output)(flags, dst, size); |
df6b4396 KS |
119 | TRACE_OUTPUT(ifp, dst, size); |
120 | } | |
121 | } |