Commit | Line | Data |
---|---|---|
8ae0e4b4 | 1 | /* |
9d91b170 | 2 | * Copyright (c) 1982, 1986, 1988 Regents of the University of California. |
2b6b6284 | 3 | * All rights reserved. |
8ae0e4b4 | 4 | * |
dbf0c423 | 5 | * %sccs.include.redist.c% |
2b6b6284 | 6 | * |
2cf7dc27 | 7 | * @(#)if_ether.c 7.18 (Berkeley) %G% |
8ae0e4b4 | 8 | */ |
2b0e2bab SL |
9 | |
10 | /* | |
11 | * Ethernet address resolution protocol. | |
878ad3fa | 12 | * TODO: |
878ad3fa | 13 | * add "inuse/lock" bit (or ref. count) along with valid bit |
2b0e2bab SL |
14 | */ |
15 | ||
20666ad3 JB |
16 | #include "param.h" |
17 | #include "systm.h" | |
9d91b170 | 18 | #include "malloc.h" |
20666ad3 JB |
19 | #include "mbuf.h" |
20 | #include "socket.h" | |
21 | #include "time.h" | |
22 | #include "kernel.h" | |
23 | #include "errno.h" | |
24 | #include "ioctl.h" | |
8a0ea807 | 25 | #include "syslog.h" |
2b0e2bab SL |
26 | |
27 | #include "../net/if.h" | |
1302f739 KS |
28 | #include "../net/if_dl.h" |
29 | #include "../net/route.h" | |
30 | ||
20666ad3 JB |
31 | #include "in.h" |
32 | #include "in_systm.h" | |
b4dc7708 | 33 | #include "in_var.h" |
20666ad3 JB |
34 | #include "ip.h" |
35 | #include "if_ether.h" | |
2b0e2bab | 36 | |
1302f739 KS |
37 | #define SIN(s) ((struct sockaddr_in *)s) |
38 | #define SDL(s) ((struct sockaddr_dl *)s) | |
39 | #define SRP(s) ((struct sockaddr_inarp *)s) | |
2b0e2bab | 40 | |
8a0ea807 MK |
41 | /* |
42 | * ARP trailer negotiation. Trailer protocol is not IP specific, | |
43 | * but ARP request/response use IP addresses. | |
44 | */ | |
45 | #define ETHERTYPE_IPTRAILERS ETHERTYPE_TRAIL | |
46 | ||
2b0e2bab SL |
47 | |
48 | /* timer values */ | |
1302f739 KS |
49 | int arpt_prune = (5*60*1); /* walk list every 5 minutes */ |
50 | int arpt_keep = (20*60); /* once resolved, good for 20 more minutes */ | |
51 | int arpt_down = 20; /* once declared down, don't send for 20 secs */ | |
52 | #define RTF_USETRAILERS RTF_PROTO1 | |
53 | #define rt_expire rt_rmx.rmx_expire | |
2b0e2bab | 54 | |
2b0e2bab | 55 | extern struct ifnet loif; |
1302f739 KS |
56 | extern struct timeval time; |
57 | struct llinfo_arp *arplookup(), llinfo_arp = {&llinfo_arp, &llinfo_arp}; | |
58 | struct ifqueue arpintrq = {0, 0, 0, 50}; | |
59 | int arp_inuse, arp_allocated, arp_intimer; | |
60 | int arp_maxtries = 5; | |
61 | int useloopback = 1; /* use loopback interface for local traffic */ | |
62 | int arpinit_done = 0; | |
2b0e2bab | 63 | |
2b0e2bab | 64 | /* |
1302f739 | 65 | * Timeout routine. Age arp_tab entries periodically. |
2b0e2bab SL |
66 | */ |
67 | arptimer() | |
68 | { | |
1302f739 KS |
69 | int s = splnet(); |
70 | register struct llinfo_arp *la = llinfo_arp.la_next; | |
71 | ||
72 | timeout(arptimer, (caddr_t)0, arpt_prune * hz); | |
73 | while (la != &llinfo_arp) { | |
74 | register struct rtentry *rt = la->la_rt; | |
75 | la = la->la_next; | |
76 | if (rt->rt_expire && rt->rt_expire <= time.tv_sec) | |
77 | arptfree(la->la_prev); /* timer has expired, clear */ | |
78 | } | |
79 | splx(s); | |
80 | } | |
81 | ||
82 | /* | |
83 | * Parallel to llc_rtrequest. | |
84 | */ | |
85 | arp_rtrequest(req, rt, sa) | |
86 | int req; | |
87 | register struct rtentry *rt; | |
88 | struct sockaddr *sa; | |
89 | { | |
90 | register struct sockaddr *gate = rt->rt_gateway; | |
91 | register struct llinfo_arp *la = (struct llinfo_arp *)rt->rt_llinfo; | |
92 | static struct sockaddr_dl null_sdl = {sizeof(null_sdl), AF_LINK}; | |
93 | ||
94 | if (!arpinit_done) { | |
95 | arpinit_done = 1; | |
96 | timeout(arptimer, (caddr_t)0, hz); | |
97 | } | |
98 | if (rt->rt_flags & RTF_GATEWAY) | |
99 | return; | |
100 | switch (req) { | |
101 | case RTM_ADD: | |
102 | case RTM_RESOLVE: | |
aa959139 KS |
103 | if ((rt->rt_flags & RTF_HOST) == 0) /* Route to IF? XXX*/ |
104 | rt->rt_flags |= RTF_CLONING; | |
1302f739 KS |
105 | if (rt->rt_flags & RTF_CLONING) { |
106 | /* | |
107 | * Case 1: This route should come from a route to iface. | |
108 | */ | |
109 | rt_setgate(rt, rt_key(rt), &null_sdl); | |
110 | gate = rt->rt_gateway; | |
111 | SDL(gate)->sdl_type = rt->rt_ifp->if_type; | |
112 | SDL(gate)->sdl_index = rt->rt_ifp->if_index; | |
113 | rt->rt_expire = time.tv_sec; | |
114 | break; | |
115 | } | |
116 | if (gate->sa_family != AF_LINK || | |
117 | gate->sa_len < sizeof(null_sdl)) { | |
118 | log(LOG_DEBUG, "arp_rtrequest: bad gateway value"); | |
119 | break; | |
120 | } | |
121 | SDL(gate)->sdl_type = rt->rt_ifp->if_type; | |
122 | SDL(gate)->sdl_index = rt->rt_ifp->if_index; | |
123 | if (la != 0) | |
124 | break; /* This happens on a route change */ | |
125 | /* | |
126 | * Case 2: This route may come from cloning, or a manual route | |
127 | * add with a LL address. | |
128 | */ | |
129 | R_Malloc(la, struct llinfo_arp *, sizeof(*la)); | |
130 | rt->rt_llinfo = (caddr_t)la; | |
131 | if (la == 0) { | |
132 | log(LOG_DEBUG, "arp_rtrequest: malloc failed\n"); | |
133 | break; | |
134 | } | |
135 | arp_inuse++, arp_allocated++; | |
136 | Bzero(la, sizeof(*la)); | |
137 | la->la_rt = rt; | |
138 | rt->rt_flags |= RTF_LLINFO; | |
139 | insque(la, &llinfo_arp); | |
140 | if (SIN(rt_key(rt))->sin_addr.s_addr == | |
141 | (IA_SIN(rt->rt_ifa))->sin_addr.s_addr) { | |
142 | /* | |
143 | * This test used to be | |
144 | * if (loif.if_flags & IFF_UP) | |
145 | * It allowed local traffic to be forced | |
146 | * through the hardware by configuring the loopback down. | |
147 | * However, it causes problems during network configuration | |
148 | * for boards that can't receive packets they send. | |
149 | * It is now necessary to clear "useloopback" and remove | |
150 | * the route to force traffic out to the hardware. | |
151 | */ | |
152 | rt->rt_expire = 0; | |
153 | Bcopy(((struct arpcom *)rt->rt_ifp)->ac_enaddr, | |
154 | LLADDR(SDL(gate)), SDL(gate)->sdl_alen = 6); | |
155 | if (useloopback) | |
156 | rt->rt_ifp = &loif; | |
157 | ||
158 | } | |
159 | break; | |
160 | ||
161 | case RTM_DELETE: | |
162 | if (la == 0) | |
163 | break; | |
164 | arp_inuse--; | |
165 | remque(la); | |
166 | rt->rt_llinfo = 0; | |
167 | rt->rt_flags &= ~RTF_LLINFO; | |
168 | if (la->la_hold) | |
169 | m_freem(la->la_hold); | |
170 | Free((caddr_t)la); | |
2b0e2bab SL |
171 | } |
172 | } | |
173 | ||
174 | /* | |
175 | * Broadcast an ARP packet, asking who has addr on interface ac. | |
176 | */ | |
2cf7dc27 | 177 | void |
2b0e2bab SL |
178 | arpwhohas(ac, addr) |
179 | register struct arpcom *ac; | |
1302f739 | 180 | struct inaddr *addr; |
2b0e2bab SL |
181 | { |
182 | register struct mbuf *m; | |
183 | register struct ether_header *eh; | |
184 | register struct ether_arp *ea; | |
185 | struct sockaddr sa; | |
186 | ||
9d91b170 | 187 | if ((m = m_gethdr(M_DONTWAIT, MT_DATA)) == NULL) |
8011f5df | 188 | return; |
9d91b170 MK |
189 | m->m_len = sizeof(*ea); |
190 | m->m_pkthdr.len = sizeof(*ea); | |
191 | MH_ALIGN(m, sizeof(*ea)); | |
2b0e2bab SL |
192 | ea = mtod(m, struct ether_arp *); |
193 | eh = (struct ether_header *)sa.sa_data; | |
755d8841 | 194 | bzero((caddr_t)ea, sizeof (*ea)); |
9350cacc MK |
195 | bcopy((caddr_t)etherbroadcastaddr, (caddr_t)eh->ether_dhost, |
196 | sizeof(eh->ether_dhost)); | |
935a6d59 | 197 | eh->ether_type = ETHERTYPE_ARP; /* if_output will swap */ |
2b0e2bab | 198 | ea->arp_hrd = htons(ARPHRD_ETHER); |
935a6d59 | 199 | ea->arp_pro = htons(ETHERTYPE_IP); |
9350cacc MK |
200 | ea->arp_hln = sizeof(ea->arp_sha); /* hardware address length */ |
201 | ea->arp_pln = sizeof(ea->arp_spa); /* protocol address length */ | |
2b0e2bab | 202 | ea->arp_op = htons(ARPOP_REQUEST); |
9350cacc MK |
203 | bcopy((caddr_t)ac->ac_enaddr, (caddr_t)ea->arp_sha, |
204 | sizeof(ea->arp_sha)); | |
205 | bcopy((caddr_t)&ac->ac_ipaddr, (caddr_t)ea->arp_spa, | |
206 | sizeof(ea->arp_spa)); | |
207 | bcopy((caddr_t)addr, (caddr_t)ea->arp_tpa, sizeof(ea->arp_tpa)); | |
2b0e2bab | 208 | sa.sa_family = AF_UNSPEC; |
0d246a40 | 209 | sa.sa_len = sizeof(sa); |
24b9cbfc | 210 | (*ac->ac_if.if_output)(&ac->ac_if, m, &sa, (struct rtentry *)0); |
2b0e2bab SL |
211 | } |
212 | ||
878ad3fa MK |
213 | int useloopback = 1; /* use loopback interface for local traffic */ |
214 | ||
2b0e2bab SL |
215 | /* |
216 | * Resolve an IP address into an ethernet address. If success, | |
8a0ea807 MK |
217 | * desten is filled in. If there is no entry in arptab, |
218 | * set one up and broadcast a request for the IP address. | |
219 | * Hold onto this mbuf and resend it once the address | |
220 | * is finally resolved. A return value of 1 indicates | |
221 | * that desten has been filled in and the packet should be sent | |
222 | * normally; a 0 return indicates that the packet has been | |
223 | * taken over here, either now or for later transmission. | |
2b0e2bab | 224 | */ |
1302f739 | 225 | arpresolve(ac, rt, m, dst, desten, usetrailers) |
2b0e2bab | 226 | register struct arpcom *ac; |
1302f739 | 227 | register struct rtentry *rt; |
2b0e2bab | 228 | struct mbuf *m; |
1302f739 | 229 | register struct sockaddr *dst; |
9350cacc | 230 | register u_char *desten; |
8a0ea807 | 231 | int *usetrailers; |
2b0e2bab | 232 | { |
1302f739 | 233 | register struct llinfo_arp *la; |
b4dc7708 | 234 | register struct in_ifaddr *ia; |
1302f739 | 235 | struct sockaddr_dl *sdl; |
2b0e2bab | 236 | |
8a0ea807 | 237 | *usetrailers = 0; |
9d91b170 | 238 | if (m->m_flags & M_BCAST) { /* broadcast */ |
9350cacc MK |
239 | bcopy((caddr_t)etherbroadcastaddr, (caddr_t)desten, |
240 | sizeof(etherbroadcastaddr)); | |
2b0e2bab SL |
241 | return (1); |
242 | } | |
1302f739 KS |
243 | if (rt) |
244 | la = (struct llinfo_arp *)rt->rt_llinfo; | |
245 | else { | |
246 | if (la = arplookup(SIN(dst)->sin_addr.s_addr, 1, 0)) | |
247 | rt = la->la_rt; | |
2b0e2bab | 248 | } |
1302f739 KS |
249 | if (la == 0 || rt == 0) { |
250 | log(LOG_DEBUG, "arpresolve: can't allocate llinfo"); | |
251 | m_freem(m); | |
252 | return (0); | |
2b0e2bab | 253 | } |
1302f739 KS |
254 | sdl = SDL(rt->rt_gateway); |
255 | /* | |
256 | * Check the address family and length is valid, the address | |
257 | * is resolved; otherwise, try to resolve. | |
258 | */ | |
259 | if ((rt->rt_expire == 0 || rt->rt_expire > time.tv_sec) && | |
260 | sdl->sdl_family == AF_LINK && sdl->sdl_alen != 0) { | |
261 | bcopy(LLADDR(sdl), desten, sdl->sdl_alen); | |
262 | *usetrailers = rt->rt_flags & RTF_USETRAILERS; | |
263 | return 1; | |
2b0e2bab SL |
264 | } |
265 | /* | |
266 | * There is an arptab entry, but no ethernet address | |
267 | * response yet. Replace the held mbuf with this | |
268 | * latest one. | |
269 | */ | |
1302f739 KS |
270 | if (la->la_hold) |
271 | m_freem(la->la_hold); | |
272 | la->la_hold = m; | |
273 | if (rt->rt_expire) { | |
274 | rt->rt_flags &= ~RTF_REJECT; | |
275 | if (la->la_asked == 0 || rt->rt_expire != time.tv_sec) { | |
276 | rt->rt_expire = time.tv_sec; | |
277 | if (la->la_asked++ < arp_maxtries) | |
278 | arpwhohas(ac, &(SIN(dst)->sin_addr)); | |
279 | else { | |
280 | rt->rt_flags |= RTF_REJECT; | |
281 | rt->rt_expire += arpt_down; | |
282 | la->la_asked = 0; | |
283 | } | |
284 | ||
285 | } | |
286 | } | |
2b0e2bab SL |
287 | return (0); |
288 | } | |
289 | ||
2b0e2bab | 290 | /* |
1302f739 | 291 | * Common length and type checks are done here, |
8a0ea807 MK |
292 | * then the protocol-specific routine is called. |
293 | */ | |
1302f739 | 294 | arpintr() |
8a0ea807 | 295 | { |
1302f739 | 296 | register struct mbuf *m; |
8a0ea807 | 297 | register struct arphdr *ar; |
1302f739 | 298 | int s; |
8a0ea807 | 299 | |
1302f739 KS |
300 | while (arpintrq.ifq_head) { |
301 | s = splimp(); | |
302 | IF_DEQUEUE(&arpintrq, m); | |
303 | splx(s); | |
304 | if (m == 0 || (m->m_flags & M_PKTHDR) == 0) | |
305 | panic("arpintr"); | |
306 | if (m->m_len >= sizeof(struct arphdr) && | |
307 | (ar = mtod(m, struct arphdr *)) && | |
308 | ntohs(ar->ar_hrd) == ARPHRD_ETHER && | |
309 | m->m_len >= | |
310 | sizeof(struct arphdr) + 2 * ar->ar_hln + 2 * ar->ar_pln) | |
311 | ||
312 | switch (ntohs(ar->ar_pro)) { | |
313 | ||
314 | case ETHERTYPE_IP: | |
315 | case ETHERTYPE_IPTRAILERS: | |
316 | in_arpinput(m); | |
317 | continue; | |
318 | } | |
319 | m_freem(m); | |
8a0ea807 | 320 | } |
8a0ea807 MK |
321 | } |
322 | ||
323 | /* | |
324 | * ARP for Internet protocols on 10 Mb/s Ethernet. | |
325 | * Algorithm is that given in RFC 826. | |
2b0e2bab SL |
326 | * In addition, a sanity check is performed on the sender |
327 | * protocol address, to catch impersonators. | |
8a0ea807 MK |
328 | * We also handle negotiations for use of trailer protocol: |
329 | * ARP replies for protocol type ETHERTYPE_TRAIL are sent | |
330 | * along with IP replies if we want trailers sent to us, | |
331 | * and also send them in response to IP replies. | |
332 | * This allows either end to announce the desire to receive | |
333 | * trailer packets. | |
334 | * We reply to requests for ETHERTYPE_TRAIL protocol as well, | |
335 | * but don't normally send requests. | |
2b0e2bab | 336 | */ |
0cf7ef94 | 337 | void |
1302f739 | 338 | in_arpinput(m) |
2b0e2bab SL |
339 | struct mbuf *m; |
340 | { | |
341 | register struct ether_arp *ea; | |
1302f739 | 342 | register struct arpcom *ac = (struct arpcom *)m->m_pkthdr.rcvif; |
2b0e2bab | 343 | struct ether_header *eh; |
91e0f45a | 344 | register struct llinfo_arp *la = 0; |
1302f739 KS |
345 | register struct rtentry *rt; |
346 | struct in_ifaddr *ia, *maybe_ia = 0; | |
8a0ea807 | 347 | struct mbuf *mcopy = 0; |
1302f739 | 348 | struct sockaddr_dl *sdl; |
2b0e2bab | 349 | struct sockaddr sa; |
8a0ea807 | 350 | struct in_addr isaddr, itaddr, myaddr; |
1302f739 | 351 | int proto, op, completed = 0, sendtrailers; |
2b0e2bab | 352 | |
1302f739 KS |
353 | if (ac->ac_if.if_flags & IFF_NOARP) |
354 | goto out; | |
2b0e2bab | 355 | ea = mtod(m, struct ether_arp *); |
8a0ea807 MK |
356 | proto = ntohs(ea->arp_pro); |
357 | op = ntohs(ea->arp_op); | |
878ad3fa MK |
358 | bcopy((caddr_t)ea->arp_spa, (caddr_t)&isaddr, sizeof (isaddr)); |
359 | bcopy((caddr_t)ea->arp_tpa, (caddr_t)&itaddr, sizeof (itaddr)); | |
b4dc7708 KS |
360 | for (ia = in_ifaddr; ia; ia = ia->ia_next) |
361 | if (ia->ia_ifp == &ac->ac_if) { | |
362 | maybe_ia = ia; | |
363 | if ((itaddr.s_addr == ia->ia_addr.sin_addr.s_addr) || | |
364 | (isaddr.s_addr == ia->ia_addr.sin_addr.s_addr)) | |
365 | break; | |
366 | } | |
367 | if (maybe_ia == 0) | |
368 | goto out; | |
369 | myaddr = ia ? ia->ia_addr.sin_addr : maybe_ia->ia_addr.sin_addr; | |
9350cacc | 370 | if (!bcmp((caddr_t)ea->arp_sha, (caddr_t)ac->ac_enaddr, |
9d91b170 | 371 | sizeof (ea->arp_sha))) |
2b0e2bab | 372 | goto out; /* it's from me, ignore it. */ |
8a0ea807 MK |
373 | if (!bcmp((caddr_t)ea->arp_sha, (caddr_t)etherbroadcastaddr, |
374 | sizeof (ea->arp_sha))) { | |
375 | log(LOG_ERR, | |
376 | "arp: ether address is broadcast for IP address %x!\n", | |
377 | ntohl(isaddr.s_addr)); | |
378 | goto out; | |
379 | } | |
2b0e2bab | 380 | if (isaddr.s_addr == myaddr.s_addr) { |
0d246a40 MK |
381 | log(LOG_ERR, |
382 | "duplicate IP address %x!! sent from ethernet address: %s\n", | |
383 | ntohl(isaddr.s_addr), ether_sprintf(ea->arp_sha)); | |
07847ffa | 384 | itaddr = myaddr; |
8a0ea807 | 385 | if (op == ARPOP_REQUEST) |
2b0e2bab SL |
386 | goto reply; |
387 | goto out; | |
388 | } | |
878ad3fa | 389 | s = splimp(); |
1302f739 KS |
390 | la = arplookup(isaddr.s_addr, itaddr.s_addr == myaddr.s_addr, 0); |
391 | if (la && (rt = la->la_rt) && (sdl = SDL(rt->rt_gateway))) { | |
392 | if (sdl->sdl_alen && | |
393 | bcmp((caddr_t)ea->arp_sha, LLADDR(sdl), sdl->sdl_alen)) | |
394 | log(LOG_INFO, "arp info overwritten for %x by %s\n", | |
395 | isaddr.s_addr, ether_sprintf(ea->arp_sha)); | |
396 | completed = 1; | |
397 | bcopy((caddr_t)ea->arp_sha, LLADDR(sdl), | |
398 | sdl->sdl_alen = sizeof(ea->arp_sha)); | |
399 | if (rt->rt_expire) | |
400 | rt->rt_expire = time.tv_sec + arpt_keep; | |
401 | rt->rt_flags &= ~RTF_REJECT; | |
402 | la->la_asked = 0; | |
403 | if (la->la_hold) { | |
404 | (*ac->ac_if.if_output)(&ac->ac_if, la->la_hold, | |
405 | rt_key(rt), rt); | |
406 | la->la_hold = 0; | |
9c76eb65 | 407 | } |
2b0e2bab | 408 | } |
2b0e2bab | 409 | reply: |
8a0ea807 MK |
410 | switch (proto) { |
411 | ||
412 | case ETHERTYPE_IPTRAILERS: | |
413 | /* partner says trailers are OK */ | |
1302f739 KS |
414 | if (la) |
415 | la->la_rt->rt_flags |= RTF_USETRAILERS; | |
8a0ea807 MK |
416 | /* |
417 | * Reply to request iff we want trailers. | |
418 | */ | |
419 | if (op != ARPOP_REQUEST || ac->ac_if.if_flags & IFF_NOTRAILERS) | |
420 | goto out; | |
421 | break; | |
422 | ||
423 | case ETHERTYPE_IP: | |
424 | /* | |
9dc83963 MK |
425 | * Reply if this is an IP request, |
426 | * or if we want to send a trailer response. | |
427 | * Send the latter only to the IP response | |
428 | * that completes the current ARP entry. | |
8a0ea807 | 429 | */ |
9dc83963 MK |
430 | if (op != ARPOP_REQUEST && |
431 | (completed == 0 || ac->ac_if.if_flags & IFF_NOTRAILERS)) | |
8a0ea807 MK |
432 | goto out; |
433 | } | |
434 | if (itaddr.s_addr == myaddr.s_addr) { | |
435 | /* I am the target */ | |
436 | bcopy((caddr_t)ea->arp_sha, (caddr_t)ea->arp_tha, | |
437 | sizeof(ea->arp_sha)); | |
438 | bcopy((caddr_t)ac->ac_enaddr, (caddr_t)ea->arp_sha, | |
439 | sizeof(ea->arp_sha)); | |
1302f739 | 440 | sendtrailers = !(ac->ac_if.if_flags & IFF_NOTRAILERS); |
8a0ea807 | 441 | } else { |
1302f739 KS |
442 | la = arplookup(itaddr.s_addr, 0, SIN_PROXY); |
443 | if (la == NULL) | |
8a0ea807 MK |
444 | goto out; |
445 | bcopy((caddr_t)ea->arp_sha, (caddr_t)ea->arp_tha, | |
446 | sizeof(ea->arp_sha)); | |
1302f739 KS |
447 | sdl = SDL(la->la_rt->rt_gateway); |
448 | bcopy(LLADDR(sdl), (caddr_t)ea->arp_sha, sizeof(ea->arp_sha)); | |
449 | sendtrailers = rt->rt_flags & RTF_USETRAILERS; | |
8a0ea807 MK |
450 | } |
451 | ||
452 | bcopy((caddr_t)ea->arp_spa, (caddr_t)ea->arp_tpa, | |
453 | sizeof(ea->arp_spa)); | |
9350cacc MK |
454 | bcopy((caddr_t)&itaddr, (caddr_t)ea->arp_spa, |
455 | sizeof(ea->arp_spa)); | |
8a0ea807 MK |
456 | ea->arp_op = htons(ARPOP_REPLY); |
457 | /* | |
458 | * If incoming packet was an IP reply, | |
459 | * we are sending a reply for type IPTRAILERS. | |
460 | * If we are sending a reply for type IP | |
461 | * and we want to receive trailers, | |
462 | * send a trailer reply as well. | |
463 | */ | |
464 | if (op == ARPOP_REPLY) | |
465 | ea->arp_pro = htons(ETHERTYPE_IPTRAILERS); | |
1302f739 | 466 | else if (proto == ETHERTYPE_IP && sendtrailers) |
03510dd5 | 467 | mcopy = m_copy(m, 0, (int)M_COPYALL); |
2b0e2bab | 468 | eh = (struct ether_header *)sa.sa_data; |
9350cacc MK |
469 | bcopy((caddr_t)ea->arp_tha, (caddr_t)eh->ether_dhost, |
470 | sizeof(eh->ether_dhost)); | |
935a6d59 | 471 | eh->ether_type = ETHERTYPE_ARP; |
2b0e2bab | 472 | sa.sa_family = AF_UNSPEC; |
0d246a40 | 473 | sa.sa_len = sizeof(sa); |
24b9cbfc | 474 | (*ac->ac_if.if_output)(&ac->ac_if, m, &sa, (struct rtentry *)0); |
8a0ea807 MK |
475 | if (mcopy) { |
476 | ea = mtod(mcopy, struct ether_arp *); | |
477 | ea->arp_pro = htons(ETHERTYPE_IPTRAILERS); | |
24b9cbfc KS |
478 | (*ac->ac_if.if_output)(&ac->ac_if, |
479 | mcopy, &sa, (struct rtentry *)0); | |
8a0ea807 | 480 | } |
2b0e2bab SL |
481 | return; |
482 | out: | |
483 | m_freem(m); | |
484 | return; | |
485 | } | |
486 | ||
487 | /* | |
1302f739 | 488 | * Free an arp entry. |
2b0e2bab | 489 | */ |
1302f739 KS |
490 | arptfree(la) |
491 | register struct llinfo_arp *la; | |
2b0e2bab | 492 | { |
1302f739 KS |
493 | register struct rtentry *rt = la->la_rt; |
494 | register struct sockaddr_dl *sdl; | |
495 | if (rt == 0) | |
496 | panic("arptfree"); | |
497 | if (rt->rt_refcnt > 0 && (sdl = SDL(rt->rt_gateway)) && | |
498 | sdl->sdl_family == AF_LINK) { | |
499 | sdl->sdl_alen = 0; | |
500 | la->la_asked = 0; | |
501 | rt->rt_flags &= ~RTF_REJECT; | |
502 | return; | |
503 | } | |
504 | rtrequest(RTM_DELETE, rt_key(rt), (struct sockaddr *)0, rt_mask(rt), | |
505 | 0, (struct rtentry **)0); | |
2b0e2bab | 506 | } |
1302f739 | 507 | int arpdebug = 0; |
2b0e2bab | 508 | /* |
1302f739 | 509 | * Lookup or enter a new address in arptab. |
2b0e2bab | 510 | */ |
1302f739 KS |
511 | struct llinfo_arp * |
512 | arplookup(addr, create, proxy) | |
513 | u_long addr; | |
2b0e2bab | 514 | { |
1302f739 KS |
515 | register struct rtentry *rt; |
516 | static struct sockaddr_inarp sin = {sizeof(sin), AF_INET }; | |
517 | ||
518 | sin.sin_addr.s_addr = addr; | |
519 | sin.sin_other = proxy ? SIN_PROXY : 0; | |
520 | rt = rtalloc1((struct sockaddr *)&sin, create); | |
521 | if (rt == 0) | |
522 | return (0); | |
523 | rt->rt_refcnt--; | |
524 | if ((rt->rt_flags & RTF_GATEWAY) || !(rt->rt_flags & RTF_LLINFO) || | |
525 | rt->rt_gateway->sa_family != AF_LINK) { | |
526 | arpcatchme(); | |
527 | if (arpdebug) | |
528 | log(LOG_DEBUG, "arptnew failed on %x\n", ntohl(addr)); | |
529 | return (0); | |
07847ffa | 530 | } |
1302f739 | 531 | return ((struct llinfo_arp *)rt->rt_llinfo); |
2b0e2bab | 532 | } |
07847ffa | 533 | |
1302f739 KS |
534 | arpcatchme(){} |
535 | ||
07847ffa MK |
536 | arpioctl(cmd, data) |
537 | int cmd; | |
538 | caddr_t data; | |
539 | { | |
1302f739 | 540 | return (EOPNOTSUPP); |
07847ffa | 541 | } |