1/** 2 * @brief 3 * net.h 4 */ 5 6/* 7 * Copyright (c) 2017, ETH Zurich. 8 * All rights reserved. 9 * 10 * This file is distributed under the terms in the attached LICENSE file. 11 * If you do not find this file, copies can be found by writing to: 12 * ETH Zurich D-INFK, Universitaetsstrasse 6, CH-8092 Zurich. Attn: Systems Group. 13 */ 14 15 16#ifndef LIB_NET_INCLUDE_NETWORKING_INTERNAL_H_ 17#define LIB_NET_INCLUDE_NETWORKING_INTERNAL_H_ 18 19 20#include <barrelfish/barrelfish.h> 21#include <barrelfish/deferred.h> 22 23#include <devif/queue_interface.h> 24#include <devif/backends/loopback_devif.h> 25#include <devif/backends/net/sfn5122f_devif.h> 26#include <devif/backends/net/e10k_devif.h> 27#include <devif/backends/net/e1000_devif.h> 28#include <devif/backends/net/mlx4_devif.h> 29 30#include <driverkit/iommu.h> 31 32#include <lwip/netif.h> 33 34#include <net/net_filter.h> 35#include <net/net.h> 36#include <net/netbufs.h> 37#include <net/netif.h> 38#include <net/dhcp.h> 39#include <net/arp.h> 40 41#include <collections/list.h> 42 43#include <if/net_ARP_defs.h> 44 45#include "debug.h" 46 47// enable benchmarking 48#define BENCH_LWIP_STACK 0 49#define BENCH_DEVQ_ENQUEUE 0 50#define BENCH_DEVQ_DEQUEUE 0 51#define BENCH_NUM_MEASUREMENTS_BITS 16 52#define BENCH_NUM_MEASUREMENTS (1UL << BENCH_NUM_MEASUREMENTS_BITS) 53 54#define NETBUF_DEBGUG 0 55 56/** 57 * @brief encapsulates the state of the networking library 58 */ 59struct net_state { 60 uint64_t queueid; 61 const char *cardname; 62 net_flags_t flags; 63 bool initialized; 64 65 /* DHCP timer events */ 66 uint64_t dhcp_ticks; 67 struct periodic_event dhcp_timer; 68 bool dhcp_done; 69 bool dhcp_running; 70 71 bool arp_running; 72 bool arp_connected; 73 uint64_t arp_triggerid; 74 struct net_ARP_binding* arp; 75 collections_listnode *outstanding_arp; 76 struct periodic_event arp_send; 77 78 struct waitset *waitset; 79 80 struct devq *queue; 81 struct net_buf_pool *pool; 82 struct netif netif; 83 bool hw_filter; 84 struct net_filter_state* filter; 85 struct capref filter_ep; 86 87 // ip4_addr_t ipaddr, netmask, gw; 88}; 89 90extern struct net_state state; 91 92static inline struct net_state *get_default_net_state(void) 93{ 94 return &state; 95} 96 97 98struct net_buf_pool; 99 100struct net_buf_p 101{ 102 struct pbuf_custom pbuf; 103#if NETBUF_DEBGUG 104 uint64_t flags; 105 bool allocated; 106 bool enqueued; 107#endif 108 lpaddr_t offset; 109 void *vbase; 110 struct net_buf_region *region; 111#if BENCH_LWIP_STACK 112 cycles_t timestamp; 113 cycles_t timestamp2; 114#endif 115#if NETBUF_DEBGUG 116 uint64_t magic; 117#endif 118}; 119 120struct net_buf_region 121{ 122 void *vbase; 123 struct frame_identity frame; 124 struct capref framecap; 125 struct net_buf_region *next; 126 size_t buffer_size; 127 uint8_t buffer_shift; 128 regionid_t regionid; 129 struct net_buf_pool *pool; 130 struct net_buf_p *netbufs; /// array of netbufs 131 struct dmem mem; 132}; 133 134struct net_buf_pool 135{ 136 struct net_buf_region *regions; 137 struct devq *dev_q; 138 struct pbuf *pbufs; 139 // stats 140 size_t buffer_count; 141 size_t buffer_free; 142 143}; 144 145#endif /* LIB_NET_INCLUDE_NETWORKING_INTERNAL_H_ */ 146