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