* Broadcast an ARP request. Caller specifies: * - arp header source ip address * - arp header target ip address * - arp header source ethernet address */
| 357 | * - arp header source ethernet address |
| 358 | */ |
| 359 | static int |
| 360 | arprequest_internal(struct ifnet *ifp, const struct in_addr *sip, |
| 361 | const struct in_addr *tip, u_char *enaddr) |
| 362 | { |
| 363 | struct mbuf *m; |
| 364 | struct arphdr *ah; |
| 365 | struct sockaddr sa; |
| 366 | u_char *carpaddr = NULL; |
| 367 | uint8_t linkhdr[LLE_MAX_LINKHDR]; |
| 368 | size_t linkhdrsize; |
| 369 | struct route ro; |
| 370 | int error; |
| 371 | |
| 372 | NET_EPOCH_ASSERT(); |
| 373 | |
| 374 | if (sip == NULL) { |
| 375 | /* |
| 376 | * The caller did not supply a source address, try to find |
| 377 | * a compatible one among those assigned to this interface. |
| 378 | */ |
| 379 | struct ifaddr *ifa; |
| 380 | |
| 381 | CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { |
| 382 | if (ifa->ifa_addr->sa_family != AF_INET) |
| 383 | continue; |
| 384 | |
| 385 | if (ifa->ifa_carp) { |
| 386 | if ((*carp_iamatch_p)(ifa, &carpaddr) == 0) |
| 387 | continue; |
| 388 | sip = &IA_SIN(ifa)->sin_addr; |
| 389 | } else { |
| 390 | carpaddr = NULL; |
| 391 | sip = &IA_SIN(ifa)->sin_addr; |
| 392 | } |
| 393 | |
| 394 | if (0 == ((sip->s_addr ^ tip->s_addr) & |
| 395 | IA_MASKSIN(ifa)->sin_addr.s_addr)) |
| 396 | break; /* found it. */ |
| 397 | } |
| 398 | if (sip == NULL) { |
| 399 | printf("%s: cannot find matching address\n", __func__); |
| 400 | return (EADDRNOTAVAIL); |
| 401 | } |
| 402 | } |
| 403 | if (enaddr == NULL) |
| 404 | enaddr = carpaddr ? carpaddr : (u_char *)IF_LLADDR(ifp); |
| 405 | |
| 406 | if ((m = m_gethdr(M_NOWAIT, MT_DATA)) == NULL) |
| 407 | return (ENOMEM); |
| 408 | m->m_len = sizeof(*ah) + 2 * sizeof(struct in_addr) + |
| 409 | 2 * ifp->if_addrlen; |
| 410 | m->m_pkthdr.len = m->m_len; |
| 411 | M_ALIGN(m, m->m_len); |
| 412 | ah = mtod(m, struct arphdr *); |
| 413 | bzero((caddr_t)ah, m->m_len); |
| 414 | #ifdef MAC |
| 415 | mac_netinet_arp_send(ifp, m); |
| 416 | #endif |
no test coverage detected