static void process_msg(struct slip_context *slip) { u16_t vlan_tag = NET_VLAN_TAG_UNSPEC; struct net_pkt *pkt; pkt = slip_poll_handler(slip); if (!pkt || !pkt->frags) { return; } #if defined(CONFIG_NET_VLAN) { struct net_eth_hdr *hdr = NET_ETH_HDR(pkt); if (ntohs(hdr->type) == NET_ETH_PTYPE_VLAN) { struct net_eth_vlan_hdr *hdr_vlan = (struct net_eth_vlan_hdr *)NET_ETH_HDR(pkt); net_pkt_set_vlan_tci(pkt, ntohs(hdr_vlan->vlan.tci)); vlan_tag = net_pkt_vlan_tag(pkt); } } #endif if (net_recv_data(get_iface(slip, vlan_tag), pkt) < 0) { net_pkt_unref(pkt); } slip->rx = NULL; slip->last = NULL; }
static struct net_pkt *prepare_vlan_pkt(struct eth_context *ctx, int count, u16_t *vlan_tag, int *status) { struct net_eth_vlan_hdr *hdr = (struct net_eth_vlan_hdr *)ctx->recv; struct net_pkt *pkt; u8_t pos; if (IS_ENABLED(CONFIG_ETH_NATIVE_POSIX_VLAN_TAG_STRIP)) { count -= NET_ETH_VLAN_HDR_SIZE; } pkt = net_pkt_rx_alloc_with_buffer(ctx->iface, count, AF_UNSPEC, 0, NET_BUF_TIMEOUT); if (!pkt) { *status = -ENOMEM; return NULL; } net_pkt_set_vlan_tci(pkt, ntohs(hdr->vlan.tci)); *vlan_tag = net_pkt_vlan_tag(pkt); pos = 0; if (IS_ENABLED(CONFIG_ETH_NATIVE_POSIX_VLAN_TAG_STRIP)) { if (net_pkt_write(pkt, ctx->recv, 2 * sizeof(struct net_eth_addr))) { goto error; } pos = (2 * sizeof(struct net_eth_addr)) + NET_ETH_VLAN_HDR_SIZE; count -= (2 * sizeof(struct net_eth_addr)); } if (net_pkt_write(pkt, ctx->recv + pos, count)) { goto error; } #if CONFIG_NET_TC_RX_COUNT > 1 { enum net_priority prio; prio = net_vlan2priority(net_pkt_vlan_priority(pkt)); net_pkt_set_priority(pkt, prio); } #endif *status = 0; LOG_DBG("Recv pkt %p len %d", pkt, count); return pkt; error: net_pkt_unref(pkt); *status = -ENOBUFS; return NULL; }