Commit | Line | Data |
---|---|---|
7e7de0c9 | 1 | #ifndef lint |
55d340a4 | 2 | static char sccsid[] = "@(#)output.c 4.3 (Berkeley) %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 | */ | |
16 | toall(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; | |
55d340a4 | 30 | flags = ifp->int_flags & IFF_INTERFACE ? MSG_DONTROUTE : 0; |
7fe7fe74 | 31 | (*f)(dst, flags, ifp); |
7e7de0c9 SL |
32 | } |
33 | } | |
34 | ||
35 | /* | |
36 | * Output a preformed packet. | |
37 | */ | |
38 | /*ARGSUSED*/ | |
7fe7fe74 | 39 | sendmsg(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 | 54 | supply(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; | |
55d340a4 | 67 | msg->rip_vers = RIPVERSION; |
7e7de0c9 SL |
68 | again: |
69 | for (rh = base; rh < &base[ROUTEHASHSIZ]; rh++) | |
70 | for (rt = rh->rt_forw; rt != (struct rt_entry *)rh; rt = rt->rt_forw) { | |
71 | size = (char *)n - packet; | |
72 | if (size > MAXPACKETSIZE - sizeof (struct netinfo)) { | |
7fe7fe74 | 73 | (*output)(s, flags, dst, size); |
7e7de0c9 SL |
74 | TRACE_OUTPUT(ifp, dst, size); |
75 | n = msg->rip_nets; | |
76 | } | |
77 | n->rip_dst = rt->rt_dst; | |
78 | n->rip_metric = min(rt->rt_metric + 1, HOPCNT_INFINITY); | |
55d340a4 SL |
79 | #ifdef notyet |
80 | n->rip_dst.sa_family = htons(n->rip_dst.sa_family); | |
81 | n->rip_metric = htonl(n->rip_metric); | |
82 | #endif | |
7e7de0c9 SL |
83 | n++; |
84 | } | |
85 | if (doinghost) { | |
86 | doinghost = 0; | |
87 | base = nethash; | |
88 | goto again; | |
89 | } | |
90 | if (n != msg->rip_nets) { | |
91 | size = (char *)n - packet; | |
7fe7fe74 | 92 | (*output)(s, flags, dst, size); |
7e7de0c9 SL |
93 | TRACE_OUTPUT(ifp, dst, size); |
94 | } | |
95 | } |