if_ether.c (128398) | if_ether.c (128636) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)if_ether.c 8.1 (Berkeley) 6/10/93 | 1/* 2 * Copyright (c) 1982, 1986, 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)if_ether.c 8.1 (Berkeley) 6/10/93 |
30 * $FreeBSD: head/sys/netinet/if_ether.c 128398 2004-04-18 11:45:49Z luigi $ | 30 * $FreeBSD: head/sys/netinet/if_ether.c 128636 2004-04-25 09:24:52Z luigi $ |
31 */ 32 33/* 34 * Ethernet address resolution protocol. 35 * TODO: 36 * add "inuse/lock" bit (or ref. count) along with valid bit 37 */ 38 --- 297 unchanged lines hidden (view full) --- 336 * Resolve an IP address into an ethernet address. If success, 337 * desten is filled in. If there is no entry in arptab, 338 * set one up and broadcast a request for the IP address. 339 * Hold onto this mbuf and resend it once the address 340 * is finally resolved. A return value of 1 indicates 341 * that desten has been filled in and the packet should be sent 342 * normally; a 0 return indicates that the packet has been 343 * taken over here, either now or for later transmission. | 31 */ 32 33/* 34 * Ethernet address resolution protocol. 35 * TODO: 36 * add "inuse/lock" bit (or ref. count) along with valid bit 37 */ 38 --- 297 unchanged lines hidden (view full) --- 336 * Resolve an IP address into an ethernet address. If success, 337 * desten is filled in. If there is no entry in arptab, 338 * set one up and broadcast a request for the IP address. 339 * Hold onto this mbuf and resend it once the address 340 * is finally resolved. A return value of 1 indicates 341 * that desten has been filled in and the packet should be sent 342 * normally; a 0 return indicates that the packet has been 343 * taken over here, either now or for later transmission. |
344 * 345 * NEW COMMENT 346 * Resolve an IP address into an ethernet address. 347 * On input: 348 * ifp is the interface we use 349 * dst is the next hop, 350 * rt0 is the route to the final destination (possibly useless) 351 * m is the mbuf 352 * desten is where we want the address. 353 * 354 * On success, desten is filled in and the function returns 0; 355 * If the packet must be held pending resolution, we return EWOULDBLOCK 356 * On other errors, we return the corresponding error code. |
|
344 */ 345int | 357 */ 358int |
346arpresolve(struct ifnet *ifp, struct rtentry *rt, struct mbuf *m, | 359arpresolve(struct ifnet *ifp, struct rtentry *rt0, struct mbuf *m, |
347 struct sockaddr *dst, u_char *desten) 348{ 349 struct llinfo_arp *la = 0; 350 struct sockaddr_dl *sdl; | 360 struct sockaddr *dst, u_char *desten) 361{ 362 struct llinfo_arp *la = 0; 363 struct sockaddr_dl *sdl; |
364 int error; 365 struct rtentry *rt; |
|
351 | 366 |
367 error = rt_check(&rt, &rt0, dst); 368 if (error) { 369 m_freem(m); 370 return error; 371 } 372 |
|
352 if (m->m_flags & M_BCAST) { /* broadcast */ 353 (void)memcpy(desten, ifp->if_broadcastaddr, ifp->if_addrlen); | 373 if (m->m_flags & M_BCAST) { /* broadcast */ 374 (void)memcpy(desten, ifp->if_broadcastaddr, ifp->if_addrlen); |
354 return (1); | 375 return (0); |
355 } 356 if (m->m_flags & M_MCAST && ifp->if_type != IFT_ARCNET) {/* multicast */ 357 ETHER_MAP_IP_MULTICAST(&SIN(dst)->sin_addr, desten); | 376 } 377 if (m->m_flags & M_MCAST && ifp->if_type != IFT_ARCNET) {/* multicast */ 378 ETHER_MAP_IP_MULTICAST(&SIN(dst)->sin_addr, desten); |
358 return(1); | 379 return (0); |
359 } 360 if (rt) 361 la = (struct llinfo_arp *)rt->rt_llinfo; 362 if (la == 0) { 363 la = arplookup(SIN(dst)->sin_addr.s_addr, 1, 0); 364 if (la) 365 rt = la->la_rt; 366 } 367 if (la == 0 || rt == 0) { 368 log(LOG_DEBUG, "arpresolve: can't allocate llinfo for %s%s%s\n", 369 inet_ntoa(SIN(dst)->sin_addr), la ? "la" : "", 370 rt ? "rt" : ""); 371 m_freem(m); | 380 } 381 if (rt) 382 la = (struct llinfo_arp *)rt->rt_llinfo; 383 if (la == 0) { 384 la = arplookup(SIN(dst)->sin_addr.s_addr, 1, 0); 385 if (la) 386 rt = la->la_rt; 387 } 388 if (la == 0 || rt == 0) { 389 log(LOG_DEBUG, "arpresolve: can't allocate llinfo for %s%s%s\n", 390 inet_ntoa(SIN(dst)->sin_addr), la ? "la" : "", 391 rt ? "rt" : ""); 392 m_freem(m); |
372 return (0); | 393 return (EINVAL); /* XXX */ |
373 } 374 sdl = SDL(rt->rt_gateway); 375 /* 376 * Check the address family and length is valid, the address 377 * is resolved; otherwise, try to resolve. 378 */ 379 if ((rt->rt_expire == 0 || rt->rt_expire > time_second) && 380 sdl->sdl_family == AF_LINK && sdl->sdl_alen != 0) { --- 7 unchanged lines hidden (view full) --- 388 arprequest(ifp, 389 &SIN(rt->rt_ifa->ifa_addr)->sin_addr, 390 &SIN(dst)->sin_addr, 391 IF_LLADDR(ifp)); 392 la->la_preempt--; 393 } 394 395 bcopy(LLADDR(sdl), desten, sdl->sdl_alen); | 394 } 395 sdl = SDL(rt->rt_gateway); 396 /* 397 * Check the address family and length is valid, the address 398 * is resolved; otherwise, try to resolve. 399 */ 400 if ((rt->rt_expire == 0 || rt->rt_expire > time_second) && 401 sdl->sdl_family == AF_LINK && sdl->sdl_alen != 0) { --- 7 unchanged lines hidden (view full) --- 409 arprequest(ifp, 410 &SIN(rt->rt_ifa->ifa_addr)->sin_addr, 411 &SIN(dst)->sin_addr, 412 IF_LLADDR(ifp)); 413 la->la_preempt--; 414 } 415 416 bcopy(LLADDR(sdl), desten, sdl->sdl_alen); |
396 return 1; | 417 return (0); |
397 } 398 /* 399 * If ARP is disabled or static on this interface, stop. 400 * XXX 401 * Probably should not allocate empty llinfo struct if we are 402 * not going to be sending out an arp request. 403 */ 404 if (ifp->if_flags & (IFF_NOARP | IFF_STATICARP)) { 405 m_freem(m); | 418 } 419 /* 420 * If ARP is disabled or static on this interface, stop. 421 * XXX 422 * Probably should not allocate empty llinfo struct if we are 423 * not going to be sending out an arp request. 424 */ 425 if (ifp->if_flags & (IFF_NOARP | IFF_STATICARP)) { 426 m_freem(m); |
406 return (0); | 427 return (EINVAL); |
407 } 408 /* 409 * There is an arptab entry, but no ethernet address 410 * response yet. Replace the held mbuf with this 411 * latest one. 412 */ 413 if (la->la_hold) 414 m_freem(la->la_hold); --- 13 unchanged lines hidden (view full) --- 428 rt->rt_expire += arpt_down; 429 la->la_asked = 0; 430 la->la_preempt = arp_maxtries; 431 } 432 433 } 434 RT_UNLOCK(rt); 435 } | 428 } 429 /* 430 * There is an arptab entry, but no ethernet address 431 * response yet. Replace the held mbuf with this 432 * latest one. 433 */ 434 if (la->la_hold) 435 m_freem(la->la_hold); --- 13 unchanged lines hidden (view full) --- 449 rt->rt_expire += arpt_down; 450 la->la_asked = 0; 451 la->la_preempt = arp_maxtries; 452 } 453 454 } 455 RT_UNLOCK(rt); 456 } |
436 return (0); | 457 return (EWOULDBLOCK); |
437} 438 439/* 440 * Common length and type checks are done here, 441 * then the protocol-specific routine is called. 442 */ 443static void 444arpintr(struct mbuf *m) --- 441 unchanged lines hidden --- | 458} 459 460/* 461 * Common length and type checks are done here, 462 * then the protocol-specific routine is called. 463 */ 464static void 465arpintr(struct mbuf *m) --- 441 unchanged lines hidden --- |