Commit | Line | Data |
---|---|---|
de602274 | 1 | /* if.c 4.18 82/06/23 */ |
1bfd8df7 BJ |
2 | |
3 | #include "../h/param.h" | |
4 | #include "../h/systm.h" | |
ee787340 | 5 | #include "../h/socket.h" |
72e4f44e | 6 | #include "../h/protosw.h" |
8a13b737 BJ |
7 | #include "../net/in.h" |
8 | #include "../net/in_systm.h" | |
1bfd8df7 | 9 | #include "../net/if.h" |
ee787340 | 10 | #include "../net/af.h" |
1bfd8df7 | 11 | |
1e977657 BJ |
12 | int ifqmaxlen = IFQ_MAXLEN; |
13 | ||
ee787340 SL |
14 | /* |
15 | * Network interface utility routines. | |
16 | * | |
17 | * Routines with if_ifwith* names take sockaddr *'s as | |
18 | * parameters. Other routines take value parameters, | |
19 | * e.g. if_ifwithnet takes the network number. | |
20 | */ | |
21 | ||
85ce71f2 BJ |
22 | ifinit() |
23 | { | |
24 | register struct ifnet *ifp; | |
25 | ||
26 | for (ifp = ifnet; ifp; ifp = ifp->if_next) | |
1e977657 | 27 | if (ifp->if_init) { |
ee787340 | 28 | (*ifp->if_init)(ifp->if_unit); |
1e977657 BJ |
29 | if (ifp->if_snd.ifq_maxlen == 0) |
30 | ifp->if_snd.ifq_maxlen = ifqmaxlen; | |
31 | } | |
85ce71f2 BJ |
32 | } |
33 | ||
ee787340 SL |
34 | /* |
35 | * Call each interface on a Unibus reset. | |
36 | */ | |
85ce71f2 BJ |
37 | ifubareset(uban) |
38 | int uban; | |
39 | { | |
40 | register struct ifnet *ifp; | |
41 | ||
42 | for (ifp = ifnet; ifp; ifp = ifp->if_next) | |
43 | if (ifp->if_ubareset) | |
44 | (*ifp->if_ubareset)(uban); | |
45 | } | |
46 | ||
ee787340 SL |
47 | /* |
48 | * Attach an interface to the | |
49 | * list of "active" interfaces. | |
50 | */ | |
405c9168 BJ |
51 | if_attach(ifp) |
52 | struct ifnet *ifp; | |
53 | { | |
c4af8b24 | 54 | register struct ifnet **p = &ifnet; |
405c9168 | 55 | |
c4af8b24 BJ |
56 | while (*p) |
57 | p = &((*p)->if_next); | |
58 | *p = ifp; | |
405c9168 BJ |
59 | } |
60 | ||
ee787340 SL |
61 | /* |
62 | * Locate an interface based on a complete address. | |
63 | */ | |
4ad99bae BJ |
64 | /*ARGSUSED*/ |
65 | struct ifnet * | |
ee787340 SL |
66 | if_ifwithaddr(addr) |
67 | struct sockaddr *addr; | |
1bfd8df7 BJ |
68 | { |
69 | register struct ifnet *ifp; | |
70 | ||
ee787340 SL |
71 | #define equal(a1, a2) \ |
72 | (bcmp((caddr_t)((a1)->sa_data), (caddr_t)((a2)->sa_data), 14) == 0) | |
73 | for (ifp = ifnet; ifp; ifp = ifp->if_next) { | |
74 | if (ifp->if_addr.sa_family != addr->sa_family) | |
75 | continue; | |
76 | if (equal(&ifp->if_addr, addr)) | |
77 | break; | |
78 | if ((ifp->if_flags & IFF_BROADCAST) && | |
79 | equal(&ifp->if_broadaddr, addr)) | |
1bfd8df7 | 80 | break; |
ee787340 | 81 | } |
1bfd8df7 BJ |
82 | return (ifp); |
83 | } | |
84 | ||
ee787340 SL |
85 | /* |
86 | * Find an interface on a specific network. If many, choice | |
87 | * is first found. | |
88 | */ | |
4ad99bae | 89 | struct ifnet * |
ee787340 SL |
90 | if_ifwithnet(addr) |
91 | register struct sockaddr *addr; | |
92 | { | |
93 | register struct ifnet *ifp; | |
94 | register int af = addr->sa_family; | |
e65dcd4c | 95 | register int (*netmatch)(); |
ee787340 | 96 | |
e65dcd4c SL |
97 | if (af >= AF_MAX) |
98 | return (0); | |
99 | netmatch = afswitch[af].af_netmatch; | |
ee787340 SL |
100 | for (ifp = ifnet; ifp; ifp = ifp->if_next) { |
101 | if (af != ifp->if_addr.sa_family) | |
102 | continue; | |
103 | if ((*netmatch)(addr, &ifp->if_addr)) | |
104 | break; | |
105 | } | |
106 | return (ifp); | |
107 | } | |
108 | ||
109 | /* | |
110 | * As above, but parameter is network number. | |
111 | */ | |
112 | struct ifnet * | |
113 | if_ifonnetof(net) | |
114 | register int net; | |
1bfd8df7 BJ |
115 | { |
116 | register struct ifnet *ifp; | |
1bfd8df7 | 117 | |
1bfd8df7 BJ |
118 | for (ifp = ifnet; ifp; ifp = ifp->if_next) |
119 | if (ifp->if_net == net) | |
120 | break; | |
1bfd8df7 BJ |
121 | return (ifp); |
122 | } | |
123 | ||
ee787340 SL |
124 | /* |
125 | * Find an interface using a specific address family | |
126 | */ | |
8a13b737 | 127 | struct ifnet * |
ee787340 SL |
128 | if_ifwithaf(af) |
129 | register int af; | |
8a13b737 | 130 | { |
ee787340 | 131 | register struct ifnet *ifp; |
8a13b737 | 132 | |
ee787340 SL |
133 | for (ifp = ifnet; ifp; ifp = ifp->if_next) |
134 | if (ifp->if_addr.sa_family == af) | |
135 | break; | |
136 | return (ifp); | |
8a13b737 | 137 | } |
f1b2fa5b | 138 | |
72e4f44e SL |
139 | /* |
140 | * Mark an interface down and notify protocols of | |
141 | * the transition. | |
142 | */ | |
143 | if_down(ifp) | |
144 | register struct ifnet *ifp; | |
145 | { | |
146 | ifp->if_flags &= ~IFF_UP; | |
147 | pfctlinput(PRC_IFDOWN, (caddr_t)&ifp->if_addr); | |
148 | } | |
de602274 SL |
149 | |
150 | /* | |
151 | * Handle interface watchdog timer routines. Called | |
152 | * from softclock, we decrement timers (if set) and | |
153 | * call the appropriate interface routine on expiration. | |
154 | */ | |
155 | if_slowtimo() | |
156 | { | |
157 | register struct ifnet *ifp; | |
158 | ||
159 | for (ifp = ifnet; ifp; ifp = ifp->if_next) | |
160 | if (ifp->if_timer && --ifp->if_timer == 0) { | |
161 | if (ifp->if_watchdog == 0) { | |
162 | printf("%s%d: no watchdog routine\n", | |
163 | ifp->if_name, ifp->if_unit); | |
164 | continue; | |
165 | } | |
166 | (*ifp->if_watchdog)(ifp->if_unit); | |
167 | } | |
168 | } |