MCPcopy Create free account
hub / github.com/F-Stack/f-stack / vxlan_encap4

Function vxlan_encap4

freebsd/net/if_vxlan.c:2464–2574  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2462}
2463
2464static int
2465vxlan_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;

Callers 1

vxlan_transmitFunction · 0.85

Calls 11

vxlan_pick_source_portFunction · 0.85
if_inc_counterFunction · 0.85
vxlan_encap_headerFunction · 0.85
bzeroFunction · 0.85
fib4_lookupFunction · 0.85
if_printfFunction · 0.85
ip_outputFunction · 0.85
m_freemFunction · 0.50
ppsratecheckFunction · 0.50
counter_u64_addFunction · 0.50

Tested by

no test coverage detected