void ci_sock_cmn_timestamp_q_enqueue(ci_netif* ni, ci_sock_cmn* s, ci_ip_pkt_fmt* pkt) { ci_ip_pkt_queue* qu = &s->timestamp_q; oo_pkt_p prev_head = qu->head; /* This part is effectively ci_ip_queue_enqueue(ni, &s->timestamp_q, p); * but inlined to allow using tsq_next field */ pkt->tsq_next = OO_PP_NULL; if( ci_ip_queue_is_empty(qu) ) { ci_assert(OO_PP_IS_NULL(qu->head)); qu->head = OO_PKT_P(pkt); } else { ci_assert(OO_PP_NOT_NULL(qu->head)); /* This assumes the netif lock is held, so use ci_ip_queue_enqueue_nnl() if it's not */ PKT(ni, qu->tail)->tsq_next = OO_PKT_P(pkt); } qu->tail = OO_PKT_P(pkt); qu->num++; if( OO_PP_IS_NULL(prev_head) ) { ci_assert(OO_PP_IS_NULL(s->timestamp_q_extract)); s->timestamp_q_extract = qu->head; } else { ci_sock_cmn_timestamp_q_reap(ni, s); } /* Tells post-poll loop to put socket on the [reap_list]. */ s->b.sb_flags |= CI_SB_FLAG_RX_DELIVERED; }
static void ci_udp_pkt_to_zc_msg(ci_netif* ni, ci_ip_pkt_fmt* pkt, struct onload_zc_msg* zc_msg) { int i, bytes_left = pkt->pf.udp.pay_len; ci_ip_pkt_fmt* frag; ci_ip_pkt_fmt* handle_frag; handle_frag = frag = pkt; i = 0; ci_assert_nequal(zc_msg->iov, NULL); /* Ignore first frag if zero length and there is another frag, but * still pass the zero-length buffer as the onload_zc_handle so it * will get freed correctly */ if( oo_offbuf_left(&frag->buf) == 0 && OO_PP_NOT_NULL(frag->frag_next) ) frag = PKT_CHK_NNL(ni, frag->frag_next); do { zc_msg->iov[i].iov_len = CI_MIN(oo_offbuf_left(&frag->buf), bytes_left); zc_msg->iov[i].iov_base = oo_offbuf_ptr(&frag->buf); zc_msg->iov[i].buf = (onload_zc_handle)handle_frag; zc_msg->iov[i].iov_flags = 0; bytes_left -= zc_msg->iov[i].iov_len; ++i; if( OO_PP_IS_NULL(frag->frag_next) || (i == CI_UDP_ZC_IOVEC_MAX) || (bytes_left == 0) ) break; frag = PKT_CHK_NNL(ni, frag->frag_next); handle_frag = frag; } while( 1 ); zc_msg->msghdr.msg_iovlen = i; }
void ci_sock_cmn_timestamp_q_drop(ci_netif* netif, ci_sock_cmn* s) { ci_ip_pkt_queue* qu = &s->timestamp_q; ci_ip_pkt_fmt* p; CI_DEBUG(int i = qu->num); ci_assert(netif); ci_assert(qu); while( OO_PP_NOT_NULL(qu->head) CI_DEBUG( && i-- > 0) ) { p = PKT_CHK(netif, qu->head); qu->head = p->tsq_next; ci_netif_pkt_release(netif, p); } ci_assert_equal(i, 0); ci_assert(OO_PP_IS_NULL(qu->head)); qu->num = 0; }
static int ci_udp_recvmsg_socklocked_slowpath(ci_udp_iomsg_args* a, ci_msghdr* msg, ci_iovec_ptr *piov, int flags) { int rc = 0; ci_netif* ni = a->ni; ci_udp_state* us = a->us; if(CI_UNLIKELY( ni->state->rxq_low )) ci_netif_rxq_low_on_recv(ni, &us->s, 1 /* assume at least one pkt freed */); /* In the kernel recv() with flags is not called. * only read(). So flags may only contain MSG_DONTWAIT */ #ifdef __KERNEL__ ci_assert_equal(flags, 0); #endif #ifndef __KERNEL__ if( flags & MSG_ERRQUEUE_CHK ) { if( OO_PP_NOT_NULL(us->timestamp_q.extract) ) { ci_ip_pkt_fmt* pkt; struct timespec ts[3]; struct cmsg_state cmsg_state; ci_udp_hdr* udp; int paylen; /* TODO is this necessary? - mirroring ci_udp_recvmsg_get() */ ci_rmb(); pkt = PKT_CHK_NNL(ni, us->timestamp_q.extract); if( pkt->tx_hw_stamp.tv_sec == CI_PKT_TX_HW_STAMP_CONSUMED ) { if( OO_PP_IS_NULL(pkt->tsq_next) ) goto errqueue_empty; us->timestamp_q.extract = pkt->tsq_next; pkt = PKT_CHK_NNL(ni, us->timestamp_q.extract); ci_assert(pkt->tx_hw_stamp.tv_sec != CI_PKT_TX_HW_STAMP_CONSUMED); } udp = oo_ip_data(pkt); paylen = CI_BSWAP_BE16(oo_ip_hdr(pkt)->ip_tot_len_be16) - sizeof(ci_ip4_hdr) - sizeof(udp); msg->msg_flags = 0; cmsg_state.msg = msg; cmsg_state.cm = msg->msg_control; cmsg_state.cmsg_bytes_used = 0; ci_iovec_ptr_init_nz(piov, msg->msg_iov, msg->msg_iovlen); memset(ts, 0, sizeof(ts)); if( us->s.timestamping_flags & ONLOAD_SOF_TIMESTAMPING_RAW_HARDWARE ) { ts[2].tv_sec = pkt->tx_hw_stamp.tv_sec; ts[2].tv_nsec = pkt->tx_hw_stamp.tv_nsec; } if( (us->s.timestamping_flags & ONLOAD_SOF_TIMESTAMPING_SYS_HARDWARE) && (pkt->tx_hw_stamp.tv_nsec & CI_IP_PKT_HW_STAMP_FLAG_IN_SYNC) ) { ts[1].tv_sec = pkt->tx_hw_stamp.tv_sec; ts[1].tv_nsec = pkt->tx_hw_stamp.tv_nsec; } ci_put_cmsg(&cmsg_state, SOL_SOCKET, ONLOAD_SCM_TIMESTAMPING, sizeof(ts), &ts); oo_offbuf_set_start(&pkt->buf, udp + 1); oo_offbuf_set_len(&pkt->buf, paylen); rc = oo_copy_pkt_to_iovec_no_adv(ni, pkt, piov, paylen); /* Mark this packet/timestamp as consumed */ pkt->tx_hw_stamp.tv_sec = CI_PKT_TX_HW_STAMP_CONSUMED; ci_ip_cmsg_finish(&cmsg_state); msg->msg_flags |= MSG_ERRQUEUE_CHK; return rc; } errqueue_empty: /* ICMP is handled via OS, so get OS error */ rc = oo_os_sock_recvmsg(ni, SC_SP(&us->s), msg, flags); if( rc < 0 ) { ci_assert(-rc == errno); return -1; } else return rc; } #endif if( (rc = ci_get_so_error(&us->s)) != 0 ) { CI_SET_ERROR(rc, rc); return rc; } if( msg->msg_iovlen > 0 && msg->msg_iov == NULL ) { CI_SET_ERROR(rc, EFAULT); return rc; } #if MSG_OOB_CHK if( flags & MSG_OOB_CHK ) { CI_SET_ERROR(rc, EOPNOTSUPP); return rc; } #endif #if CI_CFG_POSIX_RECV if( ! udp_lport_be16(us)) { LOG_UV(log("%s: -1 (ENOTCONN)", __FUNCTION__)); CI_SET_ERROR(rc, ENOTCONN); return rc; } #endif if( msg->msg_iovlen == 0 ) { /* We have a difference in behaviour from the Linux stack here. When ** msg_iovlen is 0 Linux 2.4.21-15.EL does not set MSG_TRUNC when a ** datagram has non-zero length. We do. */ CI_IOVEC_LEN(&piov->io) = piov->iovlen = 0; return IOVLEN_WORKAROUND_RC_VALUE; } return 0; }