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 <lwip/netif.h>
31
32#include <net/net_filter.h>
33#include <net/net.h>
34#include <net/netbufs.h>
35#include <net/netif.h>
36#include <net/dhcp.h>
37#include <net/arp.h>
38
39#include <collections/list.h>
40
41#include <if/net_ARP_defs.h>
42
43#include "debug.h"
44
45// enable benchmarking
46#define BENCH_LWIP_STACK 0
47#define BENCH_DEVQ_ENQUEUE 0
48#define BENCH_DEVQ_DEQUEUE 0
49#define BENCH_NUM_MEASUREMENTS_BITS 16
50#define BENCH_NUM_MEASUREMENTS (1UL << BENCH_NUM_MEASUREMENTS_BITS)
51
52#define NETBUF_DEBGUG 0
53
54/**
55 * @brief encapsulates the state of the networking library
56 */
57struct net_state {
58    uint64_t queueid;
59    const char *cardname;
60    net_flags_t flags;
61    bool initialized;
62
63    /* DHCP timer events */
64    uint64_t dhcp_ticks;
65    struct periodic_event dhcp_timer;
66    bool dhcp_done;
67    bool dhcp_running;
68
69    bool arp_running;
70    bool arp_connected;
71    uint64_t arp_triggerid;
72    struct net_ARP_binding* arp;
73    collections_listnode *outstanding_arp;
74    struct periodic_event arp_send;
75
76    struct waitset *waitset;
77
78    struct devq *queue;
79    struct net_buf_pool *pool;
80    struct netif netif;
81    bool hw_filter;
82    struct net_filter_state* filter;
83
84  //  ip4_addr_t ipaddr, netmask, gw;
85};
86
87extern struct net_state state;
88
89static inline struct net_state *get_default_net_state(void)
90{
91    return &state;
92}
93
94
95struct net_buf_pool;
96
97struct net_buf_p
98{
99    struct pbuf_custom pbuf;
100#if NETBUF_DEBGUG
101    uint64_t flags;
102    bool allocated;
103    bool enqueued;
104#endif
105    lpaddr_t offset;
106    void *vbase;
107    struct net_buf_region *region;
108#if BENCH_LWIP_STACK
109    cycles_t timestamp;
110    cycles_t timestamp2;
111#endif
112#if NETBUF_DEBGUG
113    uint64_t magic;
114#endif
115};
116
117struct net_buf_region
118{
119    void *vbase;
120    struct frame_identity frame;
121    struct capref framecap;
122    struct net_buf_region *next;
123    size_t buffer_size;
124    uint8_t buffer_shift;
125    regionid_t regionid;
126    struct net_buf_pool *pool;
127    struct net_buf_p *netbufs;    /// array of netbufs
128};
129
130struct net_buf_pool
131{
132    struct net_buf_region *regions;
133    struct devq *dev_q;
134    struct pbuf *pbufs;
135    // stats
136    size_t buffer_count;
137    size_t buffer_free;
138
139};
140
141#endif /* LIB_NET_INCLUDE_NETWORKING_INTERNAL_H_ */
142