| 2462 | } |
| 2463 | |
| 2464 | static int |
| 2465 | vxlan_encap4(struct vxlan_softc *sc, const union vxlan_sockaddr *fvxlsa, |
| 2466 | struct mbuf *m) |
| 2467 | { |
| 2468 | #ifdef INET |
| 2469 | struct ifnet *ifp; |
| 2470 | struct ip *ip; |
| 2471 | struct in_addr srcaddr, dstaddr; |
| 2472 | uint16_t srcport, dstport; |
| 2473 | int len, mcast, error; |
| 2474 | struct route route, *ro; |
| 2475 | struct sockaddr_in *sin; |
| 2476 | uint32_t csum_flags; |
| 2477 | |
| 2478 | NET_EPOCH_ASSERT(); |
| 2479 | |
| 2480 | ifp = sc->vxl_ifp; |
| 2481 | srcaddr = sc->vxl_src_addr.in4.sin_addr; |
| 2482 | srcport = vxlan_pick_source_port(sc, m); |
| 2483 | dstaddr = fvxlsa->in4.sin_addr; |
| 2484 | dstport = fvxlsa->in4.sin_port; |
| 2485 | |
| 2486 | M_PREPEND(m, sizeof(struct ip) + sizeof(struct vxlanudphdr), |
| 2487 | M_NOWAIT); |
| 2488 | if (m == NULL) { |
| 2489 | if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); |
| 2490 | return (ENOBUFS); |
| 2491 | } |
| 2492 | |
| 2493 | len = m->m_pkthdr.len; |
| 2494 | |
| 2495 | ip = mtod(m, struct ip *); |
| 2496 | ip->ip_tos = 0; |
| 2497 | ip->ip_len = htons(len); |
| 2498 | ip->ip_off = 0; |
| 2499 | ip->ip_ttl = sc->vxl_ttl; |
| 2500 | ip->ip_p = IPPROTO_UDP; |
| 2501 | ip->ip_sum = 0; |
| 2502 | ip->ip_src = srcaddr; |
| 2503 | ip->ip_dst = dstaddr; |
| 2504 | |
| 2505 | vxlan_encap_header(sc, m, sizeof(struct ip), srcport, dstport); |
| 2506 | |
| 2507 | mcast = (m->m_flags & (M_MCAST | M_BCAST)) ? 1 : 0; |
| 2508 | m->m_flags &= ~(M_MCAST | M_BCAST); |
| 2509 | |
| 2510 | m->m_pkthdr.csum_flags &= CSUM_FLAGS_TX; |
| 2511 | if (m->m_pkthdr.csum_flags != 0) { |
| 2512 | /* |
| 2513 | * HW checksum (L3 and/or L4) or TSO has been requested. Look |
| 2514 | * up the ifnet for the outbound route and verify that the |
| 2515 | * outbound ifnet can perform the requested operation on the |
| 2516 | * inner frame. |
| 2517 | */ |
| 2518 | bzero(&route, sizeof(route)); |
| 2519 | ro = &route; |
| 2520 | sin = (struct sockaddr_in *)&ro->ro_dst; |
| 2521 | sin->sin_family = AF_INET; |
no test coverage detected