7 * Copyright (c) 2017, ETH Zurich.
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.
16 #ifndef LIB_NET_INCLUDE_NETWORKING_H_
17 #define LIB_NET_INCLUDE_NETWORKING_H_
19 #include <netinet/in.h>
20 #include <errors/errno.h>
22 // forward declarations
27 * ==============================================================================
29 * ==============================================================================
32 ///< default flags to initialize the networking library
33 #define NET_FLAGS_DEFAULTS (0)
35 ///< use polling instead of interrupt driven messaging
36 #define NET_FLAGS_POLLING (1 << 0)
38 ///< enable DHCP functionality on this queue
39 #define NET_FLAGS_DO_DHCP (1 << 1)
41 #define NET_FLAGS_BLOCKING_INIT (1 << 2)
43 ///< initalize with default queue
44 #define NET_FLAGS_DEFAULT_QUEUE (1 << 3)
46 ///< do not initalize the net filter
47 #define NET_FLAGS_NO_NET_FILTER (1 << 4)
50 typedef uint32_t net_flags_t;
54 /* network interfaces */
56 ///< the default network interface
57 #define NET_DEFAULT_NIC NULL
60 * ==============================================================================
61 * Library Initialization
62 * ==============================================================================
66 * @brief initializes the networking with the defaults
68 * @return SYS_ERR_OK on sucess, errval on failure
70 errval_t networking_init_default(void);
74 * @brief initializes the networking library
76 * @param nic the nic to use with the networking library
77 * @param flags flags to use to initialize the networking library
79 * @return SYS_ERR_OK on success, errval on failure
81 errval_t networking_init(const char *nic, net_flags_t flags);
84 * @brief initializes the networking library with a given device queue
86 * @param q the device queue to initialize the networking on
87 * @param flags supplied initialization flags
89 * @return SYS_ERR_OK on success, errval on failure
91 errval_t networking_init_with_queue(struct devq *q, net_flags_t flags);
95 * @brief polls the network for new packets
97 * @return SYS_ERR_OK on success, errval on failure
99 errval_t networking_poll(void);
105 * @brief creates a queue to the given card and the queueid
107 * @param cardname network card to create the queue for
108 * @param queueid queueid of the network card
109 * @param retqueue returns the pointer to the queue
111 * @return SYS_ERR_OK on success, errval on failure
113 errval_t networking_create_queue(const char *cardname, uint64_t* queueid,
114 struct devq **retqueue);
117 * @brief obtains the default setting for initialization of the driver
119 * @param queue returns the queue to be used
120 * @param cardname returns the card name to be used
122 * @return SYS_ERR_OK on success, SKB_ERR_* on failure
124 errval_t networking_get_defaults(uint64_t *queue, const char **cardname, uint32_t *flags);
127 * ==============================================================================
129 * ==============================================================================
133 * @brief Install L3/L4 filter
135 * @param tcp should TCP packets be filtered or UPD
136 * @param src_ip source ip of the filter, 0 for wildcard
137 * @param src_port source port of the filter, 0 for wildcard
138 * @param dst_port destination port fo the filter
140 * @return SYS_ERR_OK on success, NET_FILTER_ERR_* on failure
142 errval_t networking_install_ip_filter(bool tcp, struct in_addr *src,
143 uint16_t src_port, uint16_t dst_port);
146 * @brief Remove L3/L4 filter
148 * @param tcp should TCP packets be filtered or UPD
149 * @param src_ip source ip of the filter, 0 for wildcard
150 * @param src_port source port of the filter, 0 for wildcard
151 * @param dst_port destination port fo the filter
153 * @return SYS_ERR_OK on success, NET_FILTER_ERR_* on failure
155 errval_t networking_remove_ip_filter(bool tcp, struct in_addr *src,
156 uint16_t src_port, uint16_t dst_port);
158 #endif /* LIB_NET_INCLUDE_NETWORKING_H_ */