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

Function tunoutput

freebsd/net/if_tuntap.c:1367–1451  ·  view source on GitHub ↗

* tunoutput - queue packets from higher level ready to put out. */

Source from the content-addressed store, hash-verified

1365 * tunoutput - queue packets from higher level ready to put out.
1366 */
1367static int
1368tunoutput(struct ifnet *ifp, struct mbuf *m0, const struct sockaddr *dst,
1369 struct route *ro)
1370{
1371 struct tuntap_softc *tp = ifp->if_softc;
1372 u_short cached_tun_flags;
1373 int error;
1374 u_int32_t af;
1375
1376 TUNDEBUG (ifp, "tunoutput\n");
1377
1378#ifdef MAC
1379 error = mac_ifnet_check_transmit(ifp, m0);
1380 if (error) {
1381 m_freem(m0);
1382 return (error);
1383 }
1384#endif
1385
1386 /* Could be unlocked read? */
1387 TUN_LOCK(tp);
1388 cached_tun_flags = tp->tun_flags;
1389 TUN_UNLOCK(tp);
1390 if ((cached_tun_flags & TUN_READY) != TUN_READY) {
1391 TUNDEBUG (ifp, "not ready 0%o\n", tp->tun_flags);
1392 m_freem (m0);
1393 return (EHOSTDOWN);
1394 }
1395
1396 if ((ifp->if_flags & IFF_UP) != IFF_UP) {
1397 m_freem (m0);
1398 return (EHOSTDOWN);
1399 }
1400
1401 /* BPF writes need to be handled specially. */
1402 if (dst->sa_family == AF_UNSPEC)
1403 bcopy(dst->sa_data, &af, sizeof(af));
1404 else
1405 af = dst->sa_family;
1406
1407 if (bpf_peers_present(ifp->if_bpf))
1408 bpf_mtap2(ifp->if_bpf, &af, sizeof(af), m0);
1409
1410 /* prepend sockaddr? this may abort if the mbuf allocation fails */
1411 if (cached_tun_flags & TUN_LMODE) {
1412 /* allocate space for sockaddr */
1413 M_PREPEND(m0, dst->sa_len, M_NOWAIT);
1414
1415 /* if allocation failed drop packet */
1416 if (m0 == NULL) {
1417 if_inc_counter(ifp, IFCOUNTER_IQDROPS, 1);
1418 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1);
1419 return (ENOBUFS);
1420 } else {
1421 bcopy(dst, m0->m_data, dst->sa_len);
1422 }
1423 }
1424

Callers

nothing calls this directly

Calls 5

mac_ifnet_check_transmitFunction · 0.85
bpf_mtap2Function · 0.85
if_inc_counterFunction · 0.85
bpf_peers_presentFunction · 0.70
m_freemFunction · 0.50

Tested by

no test coverage detected