#define TCP_SND_BUF (TCP_MSS * 40)
#define TCP_SND_QUEUELEN (16 * (TCP_SND_BUF/TCP_MSS))
+#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS
+
#endif /* LWIP_LWIPOPTS_H */
/**
- * @brief
+ * @brief
* net.h
*/
*
* @return
*/
-errval_t dhcpd_get_ipconfig(ip_addr_t *ip, ip_addr_t *gw, ip_addr_t *nm);
+errval_t dhcpd_get_ipconfig(struct in_addr *ip, struct in_addr *gw, struct in_addr *nm);
/**
* @brief sets the IP configuration
*
* @return SYS_ERR_OK on success, errval on failure
*/
-errval_t dhcpd_set_ipconfig(ip_addr_t *ip, ip_addr_t *gw, ip_addr_t *nm);
+errval_t dhcpd_set_ipconfig(struct in_addr *ip, struct in_addr *gw, struct in_addr *nm);
#endif /* LIB_NET_INCLUDE_NETWORKING_DHCP_H_ */
/**
- * @brief
+ * @brief
* net.h
*/
#ifndef LIB_NET_INCLUDE_NETWORKING_H_
#define LIB_NET_INCLUDE_NETWORKING_H_
+#include <netinet/in.h>
+
// forward declarations
struct devq;
struct eth_addr;
* @param tcp should TCP packets be filtered or UPD
* @param src_ip source ip of the filter, 0 for wildcard
* @param src_port source port of the filter, 0 for wildcard
- * @param dst_port destination port fo the filter
+ * @param dst_port destination port fo the filter
*
* @return SYS_ERR_OK on success, NET_FILTER_ERR_* on failure
*/
-errval_t networking_install_ip_filter(bool tcp, ip_addr_t* src,
+errval_t networking_install_ip_filter(bool tcp, struct in_addr *src,
uint16_t src_port, uint16_t dst_port);
/**
* @param tcp should TCP packets be filtered or UPD
* @param src_ip source ip of the filter, 0 for wildcard
* @param src_port source port of the filter, 0 for wildcard
- * @param dst_port destination port fo the filter
+ * @param dst_port destination port fo the filter
*
* @return SYS_ERR_OK on success, NET_FILTER_ERR_* on failure
*/
-errval_t networking_remove_ip_filter(bool tcp, ip_addr_t* src,
+errval_t networking_remove_ip_filter(bool tcp, struct in_addr *src,
uint16_t src_port, uint16_t dst_port);
#endif /* LIB_NET_INCLUDE_NETWORKING_H_ */
void net_set_user_state(struct net_socket *socket, void *user_state);
void net_close(struct net_socket *socket);
-errval_t net_bind(struct net_socket *socket, host_address_t ip_address, uint16_t port);
+errval_t net_bind(struct net_socket *socket, struct in_addr ip_address, uint16_t port);
errval_t net_listen(struct net_socket *socket, uint8_t backlog);
errval_t net_send(struct net_socket *socket, void *data, size_t size);
-errval_t net_send_to(struct net_socket *socket, void *data, size_t size, host_address_t ip_address, uint16_t port);
+errval_t net_send_to(struct net_socket *socket, void *data, size_t size, struct in_addr ip_address, uint16_t port);
void net_recv(struct net_socket *socket, net_received_callback_t cb);
void net_set_sent(struct net_socket *socket, net_sent_callback_t cb);
-errval_t net_connect(struct net_socket *socket, host_address_t ip_address, uint16_t port, net_connected_callback_t cb);
+errval_t net_connect(struct net_socket *socket, struct in_addr ip_address, uint16_t port, net_connected_callback_t cb);
void net_accept(struct net_socket *socket, net_accepted_callback_t cb);
#define NET_SOCKETS_TYPES_H
#include <barrelfish/barrelfish.h>
-
-typedef uint32_t host_address_t;
+#include <netinet/in.h>
struct net_socket;
-typedef void (*net_received_callback_t)(void *user_state, struct net_socket *socket, void *data, size_t size, host_address_t ip_address, uint16_t port);
+typedef void (*net_received_callback_t)(void *user_state, struct net_socket *socket, void *data, size_t size, struct in_addr ip_address, uint16_t port);
typedef void (*net_sent_callback_t)(void *user_state, struct net_socket *socket, void *data);
typedef void (*net_connected_callback_t)(void *user_state, struct net_socket *socket);
-typedef void (*net_accepted_callback_t)(void *user_state, struct net_socket *accepted_socket, host_address_t ip_address, uint16_t port);
+typedef void (*net_accepted_callback_t)(void *user_state, struct net_socket *accepted_socket, struct in_addr ip_address, uint16_t port);
struct net_buffer {
net_received_callback_t user_callback;
uint64_t user_state;
uint32_t size;
uint32_t descriptor;
- host_address_t host_address;
+ struct in_addr host_address;
uint16_t port;
};
typedef void (*nfs_remove_callback_t)(void *arg, struct nfs_client *client,
REMOVE3res *result);
-struct nfs_client *nfs_mount(host_address_t server, const char *path,
+struct nfs_client *nfs_mount(struct in_addr server, const char *path,
nfs_mount_callback_t callback, void *cbarg);
errval_t nfs_getattr(struct nfs_client *client, struct nfs_fh3 fh,
nfs_getattr_callback_t callback, void *cbarg);
"arm/aeabi/aeabi_atexit.c", "arm/aeabi/aeabi_unwind_cpp.c",
"arm/aeabi/aeabi_unwind_exidx.c" ]
"armv8" -> [ "aarch64/gen/flt_rounds.c" ],
- addLibraries = [ "locale", "stdio", "string", "sys", "gdtoa", "libc_gdtoa", "stdlib", "libc_sys", "libc_gen", "vis", "libc_stdtime", "tzcode" ],
+ addLibraries = [ "locale", "stdio", "string", "sys", "gdtoa", "libc_gdtoa", "stdlib", "libc_sys", "libc_gen", "vis", "libc_stdtime", "tzcode", "libc_inet" ],
-- addLibraries = [
-- "machine" -- put this first, so machine-specific symbols are found before generic ones
-- , "ctype"
--- /dev/null
+--------------------------------------------------------------------------
+-- Copyright (c) 2017, ETH Zurich.
+-- All rights reserved.
+--
+-- This file is distributed under the terms in the attached LICENSE file.
+-- If you do not find this file, copies can be found by writing to:
+-- ETH Zurich D-INFK, Universitaetstr. 6, CH-8092 Zurich. Attn: Systems Group.
+--
+-- Hakefile for libm
+--
+--------------------------------------------------------------------------
+
+[
+ build library {
+ target = "libc_inet",
+ cFiles = concat [ find cInDir "." ],
+ addIncludes = [ "../include", "../locale" ] ++ (case arch of
+ "x86_32" -> [ "../x86" ]
+ "x86_64" -> [ "../amd64" ]
+ "k1om" -> [ "../amd64" ]
+ "armv7" -> [ "../arm" ]
+ "armv8" -> [ "../aarch64" ]),
+ omitCFlags = [ "-std=c99", "-Wmissing-prototypes", "-Wmissing-declarations", "-Wimplicit-function-declaration", "-Werror" ],
+ architectures = [ arch ]
+ } | arch <- allArchitectures
+]
*/
// stdlib includes
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
// barrelfish includes
return;
}
- ip_addr_t ipaddr, netmask, gateway;
- ipaddr.addr = (uint32_t)ip;
- netmask.addr = (uint32_t)nm;
- gateway.addr = (uint32_t)gw;
+ struct in_addr ipaddr, netmask, gateway;
+ ipaddr.s_addr = (uint32_t)ip;
+ netmask.s_addr = (uint32_t)nm;
+ gateway.s_addr = (uint32_t)gw;
- debug_printf("DHCP got ip set: %s \n", ip4addr_ntoa(&ipaddr));
- debug_printf("DHCP got gw set: %s\n", ip4addr_ntoa(&gateway));
- debug_printf("DHCP got nm set: %s\n", ip4addr_ntoa(&netmask));
+ debug_printf("DHCP got ip set: %s\n", inet_ntoa(ipaddr));
+ debug_printf("DHCP got gw set: %s\n", inet_ntoa(gateway));
+ debug_printf("DHCP got nm set: %s\n", inet_ntoa(netmask));
- netif_set_addr(&st->netif, &ipaddr, &netmask, &gateway);
+ ip_addr_t _ipaddr, _netmask, _gateway;
+ _ipaddr.addr = ipaddr.s_addr;
+ _netmask.addr = netmask.s_addr;
+ _gateway.addr = gateway.s_addr;
+ netif_set_addr(&st->netif, &_ipaddr, &_netmask, &_gateway);
netif_set_up(&st->netif);
st->dhcp_done = true;
*
* @return
*/
-errval_t dhcpd_get_ipconfig(ip_addr_t *ip, ip_addr_t *gw, ip_addr_t *nm)
+errval_t dhcpd_get_ipconfig(struct in_addr *ip, struct in_addr *gw, struct in_addr *nm)
{
struct net_state *st = get_default_net_state();
if (ip) {
- ip->addr = netif_ip4_addr(&st->netif)->addr;
+ ip->s_addr = netif_ip4_addr(&st->netif)->addr;
}
if (gw) {
- gw->addr = netif_ip4_gw(&st->netif)->addr;
+ gw->s_addr = netif_ip4_gw(&st->netif)->addr;
}
if (nm) {
- nm->addr = netif_ip4_netmask(&st->netif)->addr;
+ nm->s_addr = netif_ip4_netmask(&st->netif)->addr;
}
return SYS_ERR_OK;
*
* @return SYS_ERR_OK on success, errval on failure
*/
-errval_t dhcpd_set_ipconfig(ip_addr_t *ip, ip_addr_t *gw, ip_addr_t *nm)
+errval_t dhcpd_set_ipconfig(struct in_addr *ip, struct in_addr *gw, struct in_addr *nm)
{
errval_t err;
struct net_state *st = get_default_net_state();
}
}
- netif_set_addr(&st->netif, ip, nm, gw);
+ ip_addr_t _ipaddr, _netmask, _gateway;
+ _ipaddr.addr = ip->s_addr;
+ _netmask.addr = nm->s_addr;
+ _gateway.addr = gw->s_addr;
+ netif_set_addr(&st->netif, &_ipaddr, &_netmask, &_gateway);
netif_set_up(&st->netif);
st->dhcp_done = true;
NETDEBUG("initializing hw filter...\n");
- err = net_filter_init(&st->filter, st->cardname);
- if (err_is_fail(err)) {
- USER_PANIC("Init filter infrastructure failed: %s \n", err_getstring(err));
- }
+ // err = net_filter_init(&st->filter, st->cardname);
+ // if (err_is_fail(err)) {
+ // USER_PANIC("Init filter infrastructure failed: %s \n", err_getstring(err));
+ // }
NETDEBUG("setting default netif...\n");
// netif_set_default(&st->netif);
if (err_is_fail(err)) {
DEBUG_ERR(err, "failed to subscribte the ARP service\n");
}
+
+ ip4_addr_t ipaddr, netmask;
+ IP4_ADDR(&ipaddr, 192, 168, 0, 36);
+ IP4_ADDR(&netmask, 255, 255, 255, 0);
+ netif_set_addr(&st->netif, &ipaddr, &netmask,
+ IP_ADDR_ANY);
}
NETDEBUG("initialization complete.\n");
*
* @return SYS_ERR_OK on success, NET_FILTER_ERR_* on failure
*/
-errval_t networking_install_ip_filter(bool tcp, ip_addr_t* src,
+errval_t networking_install_ip_filter(bool tcp, struct in_addr *src,
uint16_t src_port, uint16_t dst_port)
{
errval_t err;
struct net_filter_state *st = state.filter;
// get current config
- ip_addr_t dst_ip;
+ struct in_addr dst_ip;
err = dhcpd_get_ipconfig(&dst_ip, NULL, NULL);
if (err_is_fail(err)) {
return err;
struct net_filter_ip ip = {
.qid = state.queueid,
- .ip_src = (uint32_t) src->addr,
- .ip_dst = (uint32_t) dst_ip.addr,
+ .ip_src = (uint32_t) src->s_addr,
+ .ip_dst = (uint32_t) dst_ip.s_addr,
.port_dst = dst_port,
.port_src = src_port,
};
*
* @return SYS_ERR_OK on success, NET_FILTER_ERR_* on failure
*/
-errval_t networking_remove_ip_filter(bool tcp, ip_addr_t* src,
+errval_t networking_remove_ip_filter(bool tcp, struct in_addr *src,
uint16_t src_port, uint16_t dst_port)
{
struct net_filter_state *st = state.filter;
// get current config
- ip_addr_t dst_ip;
+ struct in_addr dst_ip;
err = dhcpd_get_ipconfig(&dst_ip, NULL, NULL);
if (err_is_fail(err)) {
return err;
struct net_filter_ip ip = {
.qid = state.queueid,
- .ip_src = (uint32_t) src->addr,
- .ip_dst = (uint32_t) dst_ip.addr,
+ .ip_src = (uint32_t) src->s_addr,
+ .ip_dst = (uint32_t) dst_ip.s_addr,
.port_dst = dst_port,
.port_src = src_port,
};
#include <barrelfish/deferred.h>
#include <barrelfish/nameservice_client.h>
-#include <lwip/ip.h>
-#include <lwip/udp.h>
-#include <lwip/tcp.h>
-#include <lwip/pbuf.h>
#include <net/net.h>
#include <barrelfish/waitset_chan.h>
#include <if/net_sockets_defs.h>
#include <net_sockets/net_sockets_types.h>
-typedef uint32_t host_address_t;
+#include <lwip/ip.h>
+#include <lwip/udp.h>
+#include <lwip/tcp.h>
+#include <lwip/pbuf.h>
#define NO_OF_BUFFERS 128
#define BUFFER_SIZE 16384
nb->size = length;
nb->descriptor = connection->descriptor;
- nb->host_address = addr->addr;
+ nb->host_address.s_addr = addr->addr;
nb->port = port;
// debug_printf("%s(%d): %p -> %p %p %d\n", __func__, connection->descriptor, buffer, nb->user_callback, nb->user_state, nb->size);
assert(buffer);
nb->size = length;
nb->descriptor = socket->descriptor;
- nb->host_address = 0;
+ nb->host_address.s_addr = 0;
nb->port = 0;
// debug_printf("%s(%d): %p -> %p %p %d\n", __func__, connection->descriptor, buffer, nb->user_callback, nb->user_state, nb->size);
assert(buffer);
nb->size = 0;
nb->descriptor = socket->descriptor;
- nb->host_address = 0;
+ nb->host_address.s_addr = 0;
nb->port = 0;
debug_printf("%s(%d): close\n", __func__, socket->descriptor);
// debug_printf("%s(%d): %p -> %p %p %d\n", __func__, connection->descriptor, buffer, nb->user_callback, nb->user_state, nb->size);
return SYS_ERR_OK;
}
-static errval_t net_bind(struct net_sockets_binding *binding, uint32_t descriptor, host_address_t ip_address, uint16_t port, errval_t *error)
+static errval_t net_bind(struct net_sockets_binding *binding, uint32_t descriptor, uint32_t ip_address, uint16_t port, errval_t *error)
{
struct network_connection *nc;
struct socket_connection *socket;
return SYS_ERR_OK;
}
-static errval_t net_connect(struct net_sockets_binding *binding, uint32_t descriptor, host_address_t ip_address, uint16_t port, errval_t *error)
+static errval_t net_connect(struct net_sockets_binding *binding, uint32_t descriptor, uint32_t ip_address, uint16_t port, errval_t *error)
{
struct network_connection *nc;
struct socket_connection *socket;
ip_addr_t addr;
uint16_t port;
port = nb->port;
- addr.addr = nb->host_address;
+ addr.addr = nb->host_address.s_addr;
// debug_printf("%s: enqueue 2 %lx:%d\n", __func__, offset, BUFFER_SIZE);
err = devq_enqueue(queue, rid, offset, BUFFER_SIZE, 0, 0, 2);
assert(err_is_ok(err));
free(socket);
}
-errval_t net_bind(struct net_socket *socket, host_address_t ip_address, uint16_t port)
+errval_t net_bind(struct net_socket *socket, struct in_addr ip_address, uint16_t port)
{
errval_t err, error;
- err = binding->rpc_tx_vtbl.bind(binding, socket->descriptor, ip_address, port, &error);
+ err = binding->rpc_tx_vtbl.bind(binding, socket->descriptor, ip_address.s_addr, port, &error);
assert(err_is_ok(err));
return error;
nb->size = size;
nb->descriptor = socket->descriptor;
- nb->host_address = 0;
+ nb->host_address.s_addr = INADDR_NONE;
nb->port = 0;
// debug_printf("%s: enqueue 2 %lx:%ld\n", __func__, buffer - buffer_start, sizeof(struct net_buffer) + size);
err = devq_enqueue((struct devq *)descq_queue, regionid, buffer - buffer_start, sizeof(struct net_buffer) + size,
return error;
}
-errval_t net_send_to(struct net_socket *socket, void *data, size_t size, host_address_t ip_address, uint16_t port)
+errval_t net_send_to(struct net_socket *socket, void *data, size_t size, struct in_addr ip_address, uint16_t port)
{
errval_t err, error;
return error;
}
-errval_t net_connect(struct net_socket *socket, host_address_t ip_address, uint16_t port, net_connected_callback_t cb)
+errval_t net_connect(struct net_socket *socket, struct in_addr ip_address, uint16_t port, net_connected_callback_t cb)
{
errval_t err, error;
socket->connected = cb;
- err = binding->rpc_tx_vtbl.connect(binding, socket->descriptor, ip_address, port, &error);
+ err = binding->rpc_tx_vtbl.connect(binding, socket->descriptor, ip_address.s_addr, port, &error);
assert(err_is_ok(err));
assert(err_is_ok(error));
enqueue(&sockets, accepted_socket);
assert(socket->accepted);
- socket->accepted(socket->user_state, accepted_socket, host_address, port);
+ socket->accepted(socket->user_state, accepted_socket, (struct in_addr){(host_address)}, port);
}
* call succeeds, the returned client instance must be freed by a later call
* to nfs_destroy().
*/
-struct nfs_client *nfs_mount(host_address_t server, const char *path,
+struct nfs_client *nfs_mount(struct in_addr server, const char *path,
nfs_mount_callback_t callback, void *cbarg)
{
struct nfs_client *client;
/// Generic handler for all incoming RPC messages. Finds the appropriate call
/// instance, checks arguments, and notifies the callback.
static void rpc_recv_handler(void *user_state, struct net_socket *socket,
- void *data, size_t size, host_address_t ip_address, uint16_t port)
+ void *data, size_t size, struct in_addr ip_address, uint16_t port)
{
// uint64_t ts = rdtsc();
*
* \returns Error code (SYS_ERR_OK on success)
*/
-errval_t rpc_init(struct rpc_client *client, host_address_t server)
+errval_t rpc_init(struct rpc_client *client, struct in_addr server)
{
errval_t err;
net_debug_state = 0;
client->server = server;
- client->connected_address = 0;
+ client->connected_address.s_addr = INADDR_NONE;
client->connected_port = 0;
for (int i = 0; i < RPC_HTABLE_SIZE; ++i) {
RPC_DEBUGP("rpc_call: RPC call for xid %u x0%x\n", xid, xid);
RPC_DEBUGP("rpc_call: calling UPD_connect\n");
- if (client->server != client->connected_address || port != client->connected_port) {
+ if (client->server.s_addr != client->connected_address.s_addr || port != client->connected_port) {
r = net_connect(client->socket, client->server, port, NULL);
if (r != SYS_ERR_OK) {
XDR_DESTROY(&xdr);
/// RPC client instance data
struct rpc_client {
struct net_socket *socket; ///< UDP socket
- host_address_t connected_address, connected_port;
- host_address_t server; ///< Server IP
+ struct in_addr connected_address;
+ uint16_t connected_port;
+ struct in_addr server; ///< Server IP
struct rpc_call *call_hash[RPC_HTABLE_SIZE];
uint32_t nextxid; ///< Next transaction ID
void *arg2, uint32_t replystat,
uint32_t acceptstat, XDR *reply_xdr);
-errval_t rpc_init(struct rpc_client *client, host_address_t server);
+errval_t rpc_init(struct rpc_client *client, struct in_addr server);
void rpc_destroy(struct rpc_client *client);
errval_t rpc_call(struct rpc_client *client, uint16_t port, uint32_t prog,
uint32_t vers, uint32_t proc, xdrproc_t args_xdrproc, void *args,
flounderBindings = [ "unixsock", "octopus" ],
flounderExtraBindings = [ ("octopus", [ "rpcclient" ]) ],
flounderTHCStubs = [ "octopus" ],
- addLibraries = libDeps [ "vfs", "term_server", "octopus" ],
+ addLibraries = libDeps [ "vfs_nonfs", "term_server", "octopus", "lwip" ],
architectures = [ "x86_64" ]
},
build library {
"fdtab.c", "vfs_fd.c", "vfs_blockdevfs_megaraid.c"
],
addCFlags = [ "-DDISABLE_NFS" ],
- addLibraries = [ "lwip" ],
mackerelDevices = [ "ata_identify", "fat_bpb", "fat16_ebpb",
"fat32_ebpb", "fat_direntry", "ahci_port",
"ahci_hba"
"cache.c", "vfs_cache.c", "fdtab.c", "vfs_fd.c"
],
addCFlags = [ "-DDISABLE_NFS", "-DDISABLE_BLOCKDEV" ],
- addLibraries = [ "lwip" ],
flounderBindings = [ "trivfs", "bcache" ],
- flounderExtraBindings = [ ("trivfs", ["rpcclient"]),
- ("bcache", ["rpcclient"])
- ],
flounderDefs = [ "monitor" ]
}
]
memcpy(host_copy, host, path - host);
host_copy[path - host] = '\0';
- struct in_addr server1;
- if (inet_aton(host_copy, &server1) == 0) {
+ struct in_addr server;
+ if (inet_aton(host_copy, &server) == 0) {
printf("Invalid host IP: %s\n", host_copy);
return VFS_ERR_BAD_URI;
}
- host_address_t server2 = server1.s_addr;
// init stack if needed
static bool stack_inited;
assert(st != NULL);
// lwip_mutex_lock();
- st->client = nfs_mount(server2, path, mount_callback, st);
+ st->client = nfs_mount(server, path, mount_callback, st);
assert(st->client != NULL);
wait_for_condition();
// lwip_mutex_unlock();
int main(int argc, char**argv)
{
+ errval_t err;
vfs_init();
if(argc < 3) {
exit(EXIT_FAILURE);
}
- errval_t err = vfs_mkdir(MOUNT_DIR);
- if (err_is_fail(err)) {
- DEBUG_ERR(err, "vfs_mount");
- }
+// err = vfs_mkdir(MOUNT_DIR);
+// if (err_is_fail(err)) {
+// DEBUG_ERR(err, "vfs_mount");
+// }
err = vfs_mount(MOUNT_DIR, argv[1]);
if(err_is_fail(err)) {