void ci_ip_send_pkt_lookup(ci_netif* ni, const struct oo_sock_cplane* sock_cp_opt, ci_ip_pkt_fmt* pkt, ci_ip_cached_hdrs* ipcache) { ci_ip4_hdr* pkt_ip = oo_tx_ip_hdr(pkt); struct oo_sock_cplane sock_cp; ci_assert(pkt_ip->ip_saddr_be32 != 0); ci_assert(pkt_ip->ip_daddr_be32 != 0); if( sock_cp_opt != NULL ) sock_cp = *sock_cp_opt; else oo_sock_cplane_init(&sock_cp); ci_ip_cache_init(ipcache); sock_cp.ip_laddr_be32 = pkt_ip->ip_saddr_be32; ipcache->ip.ip_daddr_be32 = pkt_ip->ip_daddr_be32; switch( pkt_ip->ip_protocol ) { case IPPROTO_UDP: case IPPROTO_TCP: sock_cp.lport_be16 = TX_PKT_SPORT_BE16(pkt); ipcache->dport_be16 = TX_PKT_DPORT_BE16(pkt); break; default: sock_cp.lport_be16 = 0; ipcache->dport_be16 = 0; break; } cicp_user_retrieve(ni, ipcache, &sock_cp); }
void ci_sock_cmn_reinit(ci_netif* ni, ci_sock_cmn* s) { s->so_error = 0; s->tx_errno = EPIPE; s->rx_errno = ENOTCONN; s->pkt.ether_type = CI_ETHERTYPE_IP; ci_ip_cache_init(&s->pkt); }
void ci_sock_cmn_reinit(ci_netif* ni, ci_sock_cmn* s) { s->so_error = 0; s->tx_errno = EPIPE; s->rx_errno = ENOTCONN; s->pkt.ether_type = CI_ETHERTYPE_IP; ci_ip_cache_init(&s->pkt); s->s_flags &= ~(CI_SOCK_FLAG_FILTER | CI_SOCK_FLAG_MAC_FILTER); }
/* initialise all the fields that we can in the UDP state structure. ** There are no IP options, no destination addresses, no ports */ static void ci_udp_state_init(ci_netif* netif, ci_udp_state* us) { ci_sock_cmn_init(netif, &us->s, 1); /* IP_MULTICAST_LOOP is 1 by default, so we should not send multicast * unless specially permitted */ if( ! NI_OPTS(netif).force_send_multicast ) us->s.cp.sock_cp_flags |= OO_SCP_NO_MULTICAST; /* Poison. */ CI_DEBUG(memset(&us->s + 1, 0xf0, (char*) (us + 1) - (char*) (&us->s + 1))); /*! \todo This should be part of sock_cmn reinit, but the comment to that * function suggests that it's possibly not a good plan to move it there */ #if CI_CFG_TIMESTAMPING ci_udp_recv_q_init(&us->timestamp_q); #endif /*! \todo These two should really be handled in ci_sock_cmn_init() */ /* Make sure we don't hit any state assertions. Can use * UDP_STATE_FROM_SOCKET_EPINFO() after this. */ us->s.b.state = CI_TCP_STATE_UDP; us->s.so.sndbuf = NI_OPTS(netif).udp_sndbuf_def; us->s.so.rcvbuf = NI_OPTS(netif).udp_rcvbuf_def; /* Init the ip-caches (packet header templates). */ ci_udp_hdrs_init(&us->s.pkt); ci_ip_cache_init(&us->ephemeral_pkt); ci_udp_hdrs_init(&us->ephemeral_pkt); udp_lport_be16(us) = 0; udp_rport_be16(us) = 0; #if CI_CFG_ZC_RECV_FILTER us->recv_q_filter = 0; us->recv_q_filter_arg = 0; #endif ci_udp_recv_q_init(&us->recv_q); us->zc_kernel_datagram = OO_PP_NULL; us->zc_kernel_datagram_count = 0; us->tx_async_q = CI_ILL_END; oo_atomic_set(&us->tx_async_q_level, 0); us->tx_count = 0; us->udpflags = CI_UDPF_MCAST_LOOP; us->ip_pktinfo_cache.intf_i = -1; us->stamp = 0; memset(&us->stats, 0, sizeof(us->stats)); }