rpc new_tcp_socket(out uint32 descriptor);
rpc delete_socket(in uint32 descriptor, out errval error);
- rpc bind(in uint32 descriptor, in uint32 host_address, in uint16 port, out errval error);
+ rpc bind(in uint32 descriptor, in uint32 host_address, in uint16 port, out errval error, out uint16 bound_port);
rpc listen(in uint32 descriptor, in uint8 backlog, out errval error);
rpc connect(in uint32 descriptor, in uint32 host_address, in uint16 port, out errval error);
- message connected(uint32 descriptor, errval error);
+ message connected(uint32 descriptor, errval error, uint32 connected_address, uint16 connected_port);
// message accepted(uint32 descriptor, uint32 new_descriptor, uint32 host_address, uint16 port, errval error);
};
*/
#define LWIP_NOASSERT 1
-#define LWIP_DEBUG 1
+//#define LWIP_DEBUG 0
#define TAPIF_DEBUG LWIP_DBG_OFF
#define TUNIF_DEBUG LWIP_DBG_OFF
#define UNIXIF_DEBUG LWIP_DBG_OFF
#define IP_REASS_DEBUG LWIP_DBG_OFF
#define RAW_DEBUG LWIP_DBG_OFF
#define ICMP_DEBUG LWIP_DBG_OFF
-#define UDP_DEBUG (LWIP_DBG_ON | LWIP_DBG_TYPES_ON | LWIP_DBG_MIN_LEVEL)
+#define UDP_DEBUG LWIP_DBG_OFF
#define TCP_DEBUG LWIP_DBG_OFF
#define TCP_INPUT_DEBUG LWIP_DBG_OFF
#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF
#include <net/net.h>
#include <lwip/ip_addr.h>
+#define NET_CONFIG_IP_RECORD_FIELDS "{ ip: %d, gw: %d, netmask: %d }"
+#define NET_CONFIG_CURRENT_IP_RECORD_FORMAT "net.ipconfig " NET_CONFIG_IP_RECORD_FIELDS
+#define NET_CONFIG_CURRENT_IP_RECORD_REGEX "net.ipconfig {ip: _, gw: _, netmask: _}"
+#define NET_CONFIG_STATIC_IP_RECORD_FORMAT "net.static_ip " NET_CONFIG_IP_RECORD_FIELDS
+#define NET_CONFIG_STATIC_IP_RECORD_REGEX "net.static_ip {ip: _, gw: _, netmask: _}"
+
/**
* @brief starts the dhcpd service on the interface
*
/* functions for querying the current settings */
/**
- * @brief queries the DHCPD settings of the machine
+ * @brief queries the current ip setting of the machine
+ *
+ * @param flags flags to provide
+ *
+ * @return SYS_ERR_OK on success, errval on failure
+ */
+errval_t net_config_current_ip_query(net_flags_t flags);
+
+
+/**
+ * @brief queries the static ip setting of the machine
*
* @param flags flags to provide
*
* @return SYS_ERR_OK on success, errval on failure
*/
-errval_t dhcpd_query(net_flags_t flags);
+errval_t net_config_static_ip_query(net_flags_t flags);
/**
*
* @return
*/
-errval_t dhcpd_get_ipconfig(struct in_addr *ip, struct in_addr *gw, struct in_addr *nm);
+errval_t netif_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(struct in_addr *ip, struct in_addr *gw, struct in_addr *nm);
+errval_t netif_set_ipconfig(struct in_addr *ip, struct in_addr *gw, struct in_addr *nm);
#endif /* LIB_NET_INCLUDE_NETWORKING_DHCP_H_ */
///< initalize with default queue
#define NET_FLAGS_DEFAULT_QUEUE (1 << 3)
+///< do not initalize the net filter
+#define NET_FLAGS_NO_NET_FILTER (1 << 4)
+
///< networking flags
typedef uint32_t net_flags_t;
net_connected_callback_t connected;
net_accepted_callback_t accepted;
void *user_state;
+
+ struct in_addr bound_address;
+ uint16_t bound_port;
+ struct in_addr connected_address;
+ uint16_t connected_port;
+
struct net_socket *prev, *next;
};
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, size_t size);
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, struct in_addr ip_address, uint16_t port);
+typedef void (*net_accepted_callback_t)(void *user_state, struct net_socket *accepted_socket);
struct net_buffer {
uint32_t size;
// lwip includes
#include <lwip/ip.h>
#include <lwip/dhcp.h>
+#include <lwip/prot/dhcp.h>
#include <lwip/timeouts.h>
#include <octopus/octopus.h>
#include <octopus_server/service.h>
-#include <octopus/trigger.h>
#include <net_interfaces/flags.h>
#include "networking_internal.h"
///< the DHCP timeout in milli seconds
#define DHCP_TIMEOUT_MSECS (120UL * 1000)
-#define DHCP_RECORD_FIELDS "{ ip: %d, gw: %d, netmask: %d }"
-
-
-#define DHCP_RECORD_FORMAT "net.ipconfig " DHCP_RECORD_FIELDS
-
-#define DHCP_RECORD_REGEX "net.ipconfig {ip: _, gw: _, netmask: _}"
-
static void dhcpd_timer_callback(void *data)
{
- errval_t err;
-
struct net_state *st = data;
dhcp_fine_tmr();
-
if ((st->dhcp_ticks % (DHCP_COARSE_TIMER_MSECS / DHCP_FINE_TIMER_MSECS)) == 0) {
dhcp_coarse_tmr();
}
-
- if (!ip_addr_cmp(&st->netif.ip_addr, IP_ADDR_ANY) && st->dhcp_done == 0) {
-
- NETDEBUG("setting system DHCP record to IP: %s\n",
- ip4addr_ntoa(netif_ip4_addr(&st->netif)));
-
- /* register IP with octopus */
- err = oct_set(DHCP_RECORD_FORMAT, netif_ip4_addr(&st->netif)->addr,
- netif_ip4_gw(&st->netif)->addr,
- netif_ip4_netmask(&st->netif)->addr);
- if (err_is_fail(err)) {
- DEBUG_ERR(err, "failed to set the DHCP record\n");
- }
- st->dhcp_done = 1;
- }
-
st->dhcp_ticks++;
}
if (flags & NET_FLAGS_BLOCKING_INIT) {
printf("waiting for DHCP to complete \n");
- while(!dhcpd_has_ip()) {
+ while (!dhcpd_has_ip()) {
networking_poll();
if (st->dhcp_ticks > DHCP_TIMEOUT_MSECS / DHCP_FINE_TIMER_MSECS) {
dhcpd_stop();
}
-/* functions for querying the current settings */
-
-
-static void dhcpd_change_event(octopus_mode_t mode, const char* record, void* arg)
+/**
+ * @brief queries the current ip setting of the machine
+ *
+ * @return SYS_ERR_OK on success, errval on failure
+ */
+errval_t net_config_current_ip_query(net_flags_t flags)
{
errval_t err;
- struct net_state *st = arg;
-
- debug_printf("DHCP change event: %s\n", record);
+ NETDEBUG("query current IP...\n");
- if (mode & OCT_ON_SET) {
+ // initialize octopus if not already done
+ err = oct_init();
+ if (err_is_fail(err)) {
+ return err;
+ }
- uint64_t ip, nm, gw;
- err = oct_read(record, "_" DHCP_RECORD_FIELDS, &ip, &gw, &nm);
+ char* record = NULL;
+ err = oct_get(&record, "net.current_ip");
+ if (err_no(err) == OCT_ERR_NO_RECORD && (flags & NET_FLAGS_BLOCKING_INIT)) {
+ printf("waiting for DHCP to complete");
+ err = oct_wait_for(&record, NET_CONFIG_CURRENT_IP_RECORD_REGEX);
if (err_is_fail(err)) {
- DEBUG_ERR(err, "cannot read DHCPD record '%s\n", record);
- return;
+ return err;
}
+ } else if (err_is_fail(err)) {
+ DEBUG_ERR(err, "cannot get static ip record\n");
+ return err;
+ }
- 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", 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));
-
- 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;
+ uint64_t ip, nm, gw;
+ err = oct_read(record, "_" NET_CONFIG_IP_RECORD_FIELDS, &ip, &gw, &nm);
+ if (err_is_fail(err)) {
+ DEBUG_ERR(err, "cannot read current ip record '%s\n", record);
+ free(record);
+ return err;
}
+ free(record);
- if (mode & OCT_ON_DEL) {
+ struct in_addr ipaddr, netmask, gateway;
+ ipaddr.s_addr = (uint32_t)ip;
+ netmask.s_addr = (uint32_t)nm;
+ gateway.s_addr = (uint32_t)gw;
- /* DHCP has been removed */
- netif_set_down(&st->netif);
- }
+ debug_printf("Got current IP set: %s\n", inet_ntoa(ipaddr));
+ debug_printf("Got current GW set: %s\n", inet_ntoa(gateway));
+ debug_printf("Got current NM set: %s\n", inet_ntoa(netmask));
+
+ return SYS_ERR_OK;
}
+
/**
- * @brief queries the DHCPD settings of the machine
+ * @brief queries the static ip setting of the machine and sets it
*
* @return SYS_ERR_OK on success, errval on failure
*/
-errval_t dhcpd_query(net_flags_t flags)
+errval_t net_config_static_ip_query(net_flags_t flags)
{
errval_t err;
- NETDEBUG("query DHCPD for IP...\n");
+ NETDEBUG("query static IP...\n");
// initialize octopus if not already done
err = oct_init();
struct net_state *st = get_default_net_state();
assert(st);
- st->dhcp_ticks = 1;
- st->dhcp_running = 1;
+ char* record = NULL;
+ err = oct_get(&record, "net.static_ip");
+ if (err_is_fail(err)) {
+ DEBUG_ERR(err, "cannot get static ip record\n");
+ return err;
+ }
- err = oct_trigger_existing_and_watch(DHCP_RECORD_REGEX, dhcpd_change_event,
- st, &st->dhcp_triggerid);
+ uint64_t ip, nm, gw;
+ err = oct_read(record, "_" NET_CONFIG_IP_RECORD_FIELDS, &ip, &gw, &nm);
if (err_is_fail(err)) {
+ DEBUG_ERR(err, "cannot read static ip record '%s\n", record);
+ free(record);
return err;
}
+ free(record);
- if (flags & NET_FLAGS_BLOCKING_INIT) {
- printf("waiting for DHCP to complete");
- while(!dhcpd_has_ip()) {
- event_dispatch(get_default_waitset());
- }
+ 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("Got static IP set: %s\n", inet_ntoa(ipaddr));
+ debug_printf("Got static GW set: %s\n", inet_ntoa(gateway));
+ debug_printf("Got static NM set: %s\n", inet_ntoa(netmask));
+
+ err = netif_set_ipconfig(&ipaddr, &gateway, &netmask);
+ if (err_is_fail(err)) {
+ DEBUG_ERR(err, "cannot set static ip\n");
+ return err;
}
return SYS_ERR_OK;
*
* @return
*/
-errval_t dhcpd_get_ipconfig(struct in_addr *ip, struct in_addr *gw, struct in_addr *nm)
+errval_t netif_get_ipconfig(struct in_addr *ip, struct in_addr *gw, struct in_addr *nm)
{
struct net_state *st = get_default_net_state();
if (ip) {
}
/**
- * @brief sets the IP configuration
+ * @brief sets the IP configuration, overrides DHCP
*
* @param ip the IP address
* @param gw the Gateway
*
* @return SYS_ERR_OK on success, errval on failure
*/
-errval_t dhcpd_set_ipconfig(struct in_addr *ip, struct in_addr *gw, struct in_addr *nm)
+errval_t netif_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();
- if (st->dhcp_running == 1) {
- if (st->dhcp_triggerid) {
- err = oct_remove_trigger(st->dhcp_triggerid);
- } else {
- err = dhcpd_stop();
- }
+ if (st->dhcp_running == 1) { // stop dhcp, if it's running
+ err = dhcpd_stop();
if (err_is_fail(err)) {
return err;
}
netif_set_addr(&st->netif, &_ipaddr, &_netmask, &_gateway);
netif_set_up(&st->netif);
- st->dhcp_done = true;
-
return SYS_ERR_OK;
}
*
* @return SYS_ERR_OK on success, errval on failure
*/
-static errval_t networking_init_with_queue_st(struct net_state *st,struct devq *q,
+static errval_t networking_init_with_queue_st(struct net_state *st, struct devq *q,
net_flags_t flags)
{
errval_t err;
goto out_err1;
}
+ if (!(flags & NET_FLAGS_NO_NET_FILTER)) {
+ NETDEBUG("initializing hw filter...\n");
- 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);
+ netif_set_default(&st->netif);
NETDEBUG("adding RX buffers\n");
for (int i = 0; i < NETWORKING_BUFFER_RX_POPULATE; i++) {
DEBUG_ERR(err, "failed to start the ARP service\n");
}
} else {
- /* get IP from dhcpd */
- err = dhcpd_query(flags);
+ /* get static IP config */
+ err = net_config_static_ip_query(flags);
if (err_is_fail(err)) {
- DEBUG_ERR(err, "failed to start DHCP.\n");
+ DEBUG_ERR(err, "failed to set IP.\n");
}
err = arp_service_subscribe();
// get current config
struct in_addr dst_ip;
- err = dhcpd_get_ipconfig(&dst_ip, NULL, NULL);
+ err = netif_get_ipconfig(&dst_ip, NULL, NULL);
if (err_is_fail(err)) {
return err;
}
// get current config
struct in_addr dst_ip;
- err = dhcpd_get_ipconfig(&dst_ip, NULL, NULL);
+ err = netif_get_ipconfig(&dst_ip, NULL, NULL);
if (err_is_fail(err)) {
return err;
}
NETDEBUG("pbuf=%p\n", p);
if (p->next) {
- debug_printf("!!!!!! p->NEXT was not NULL\n");
+ debug_printf("!!!!!! p->NEXT was not NULL (%p)\n", p->next);
}
// printf("free: %p\n", p);
#include <barrelfish/barrelfish.h>
#include <devif/queue_interface.h>
#include <net_interfaces/flags.h>
+#include <octopus/octopus.h>
#include <lwip/opt.h>
static void net_if_status_cb(struct netif *netif)
{
- printf("ip_addr_cmp(&netif->ip_addr, IP_ADDR_ANY)=%u\n",
- ip_addr_cmp(&netif->ip_addr, IP_ADDR_ANY));
if (!ip_addr_cmp(&netif->ip_addr, IP_ADDR_ANY)) {
-
debug_printf("######################################\n");
debug_printf("# IP Addr %s\n", ip4addr_ntoa(netif_ip4_addr(netif)));
debug_printf("# GW Addr %s\n", ip4addr_ntoa(netif_ip4_gw(netif)));
netif_set_default(netif);
printf("setting default interface\n");
+
+ NETDEBUG("setting system ip config record to IP: %s\n",
+ ip4addr_ntoa(netif_ip4_addr(netif)));
+ /* register IP with octopus */
+ errval_t err;
+ err = oct_set(NET_CONFIG_CURRENT_IP_RECORD_FORMAT, netif_ip4_addr(netif)->addr,
+ netif_ip4_gw(netif)->addr,
+ netif_ip4_netmask(netif)->addr);
+ if (err_is_fail(err)) {
+ DEBUG_ERR(err, "failed to set the DHCP record\n");
+ }
}
}
/* DHCP timer events */
uint64_t dhcp_ticks;
- uint64_t dhcp_triggerid;
struct periodic_event dhcp_timer;
bool dhcp_done;
bool dhcp_running;
#include <barrelfish/nameservice_client.h>
#include <if/net_sockets_defs.h>
#include <net_sockets/net_sockets.h>
+#include <arpa/inet.h>
#include <barrelfish/waitset_chan.h>
#include <barrelfish/waitset.h>
}
}
-struct net_socket * net_udp_socket(void)
+static struct net_socket * allocate_socket(uint32_t descriptor)
{
- errval_t err;
struct net_socket *socket;
- uint32_t descriptor;
-
- err = binding->rpc_tx_vtbl.new_udp_socket(binding, &descriptor);
- assert(err_is_ok(err));
socket = malloc(sizeof(struct net_socket));
assert(socket);
socket->connected = NULL;
socket->accepted = NULL;
socket->user_state = NULL;
+ socket->bound_address.s_addr = 0;
+ socket->bound_port = 0;
+ socket->connected_address.s_addr = 0;
+ socket->connected_port = 0;
enqueue(&sockets, socket);
return socket;
}
+struct net_socket * net_udp_socket(void)
+{
+ errval_t err;
+ struct net_socket *socket;
+ uint32_t descriptor;
+
+ err = binding->rpc_tx_vtbl.new_udp_socket(binding, &descriptor);
+ assert(err_is_ok(err));
+
+ socket = allocate_socket(descriptor);
+ return socket;
+}
+
struct net_socket * net_tcp_socket(void)
{
errval_t err;
err = binding->rpc_tx_vtbl.new_tcp_socket(binding, &descriptor);
assert(err_is_ok(err));
- socket = malloc(sizeof(struct net_socket));
- assert(socket);
-
- socket->descriptor = descriptor;
- socket->received = NULL;
- socket->sent = NULL;
- socket->connected = NULL;
- socket->accepted = NULL;
- socket->user_state = NULL;
- enqueue(&sockets, socket);
+ socket = allocate_socket(descriptor);
return socket;
}
if (socket == sockets)
break;
}
- debug_printf("%s: %d %p\n", __func__, descriptor, __builtin_return_address(0));
+ debug_printf("%s: socket not found %d %p\n", __func__, descriptor, __builtin_return_address(0));
assert(0);
return NULL;
}
{
errval_t err, error;
- debug_printf("%s(%d):\n", __func__, socket->descriptor);
+ // debug_printf("%s(%d):\n", __func__, socket->descriptor);
err = binding->rpc_tx_vtbl.delete_socket(binding, socket->descriptor, &error);
assert(err_is_ok(err));
assert(err_is_ok(error));
dequeue(&sockets, socket);
free(socket);
- debug_printf("%s: %ld:%p %ld:%p\n", __func__, next_free, buffers[next_free], next_used, buffers[next_used]);
+ // debug_printf("%s: %ld:%p %ld:%p\n", __func__, next_free, buffers[next_free], next_used, buffers[next_used]);
}
errval_t net_bind(struct net_socket *socket, struct in_addr ip_address, uint16_t port)
{
errval_t err, error;
+ uint16_t bound_port;
- err = binding->rpc_tx_vtbl.bind(binding, socket->descriptor, ip_address.s_addr, port, &error);
+ err = binding->rpc_tx_vtbl.bind(binding, socket->descriptor, ip_address.s_addr, port, &error, &bound_port);
assert(err_is_ok(err));
+ socket->bound_address = ip_address;
+ socket->bound_port = bound_port;
return error;
}
return error;
}
-static void net_connected(struct net_sockets_binding *b, uint32_t descriptor, errval_t error)
+static void net_connected(struct net_sockets_binding *b, uint32_t descriptor, errval_t error, uint32_t connected_address, uint16_t connected_port)
{
struct net_socket *socket = get_socket(descriptor);
assert(socket->descriptor == descriptor);
assert(err_is_ok(error));
+ socket->connected_address.s_addr = connected_address;
+ socket->connected_port = connected_port;
assert(socket->connected);
socket->connected(socket->user_state, socket);
}
struct net_socket *socket = get_socket(descriptor);
assert(socket->descriptor == descriptor);
- struct net_socket *accepted_socket = malloc(sizeof(struct net_socket));
- assert(accepted_socket);
-
- accepted_socket->descriptor = accepted_descriptor;
- accepted_socket->received = NULL;
- accepted_socket->sent = NULL;
- accepted_socket->connected = NULL;
- accepted_socket->accepted = NULL;
- accepted_socket->user_state = NULL;
- enqueue(&sockets, accepted_socket);
-
- assert(socket->accepted);
- socket->accepted(socket->user_state, accepted_socket, host_address, port);
+ struct net_socket *accepted_socket = allocate_socket(accepted_descriptor);
+ accepted_socket->connected_address = host_address;
+ accepted_socket->connected_port = port;
+ socket->accepted(socket->user_state, accepted_socket);
}
struct descq_func_pointer f;
f.notify = q_notify;
- debug_printf("Descriptor queue test started \n");
+ debug_printf("net socket client started \n");
err = descq_create(&descq_queue, DESCQ_DEFAULT_SIZE, "net_sockets_queue",
false, true, true, &queue_id, &f);
assert(err_is_ok(err));
"client.c",
"common.c"
],
- addLibraries = [ "lwip", "contmng", "net_if_raw"]
+ addLibraries = [ "net_sockets" ]
},
build library {
target = "tftp_server",
"server.c",
"common.c"
],
- addLibraries = [ "lwip", "contmng", "net_if_raw"]
+ addLibraries = [ "net_sockets" ]
}
]
#include <barrelfish/waitset.h>
#include <barrelfish/nameservice_client.h>
-#include <lwip/udp.h>
-#include <lwip/init.h>
+#include <net_sockets/net_sockets.h>
+#include <arpa/inet.h>
#include <tftp/tftp.h>
tftp_st_t state;
/* connection information */
- struct ip_addr server_ip;
+ struct in_addr server_ip;
uint16_t server_port;
tftp_mode_t mode;
size_t buflen;
/* connection information */
- struct udp_pcb *pcb;
- struct pbuf *p;
+ struct net_socket *pcb;
void *ppayload;
- struct udp_pcb *rcv_pcb;
};
struct tftp_client tftp_client;
-static errval_t tftp_client_send_data(struct udp_pcb *pcb, uint32_t blockno, void *buf,
- uint32_t length, struct ip_addr *addr, u16_t port,
- struct pbuf *p)
+static errval_t tftp_client_send_data(struct net_socket *socket, uint32_t blockno, void *buf,
+ uint32_t length, struct in_addr addr, uint16_t port)
{
- p->len = TFTP_MAX_MSGSIZE;
- p->tot_len = TFTP_MAX_MSGSIZE;
- p->payload = tftp_client.ppayload;
+ void *payload = tftp_client.ppayload;
+ errval_t err;
- size_t offset = set_opcode(p->payload, TFTP_OP_DATA);
- offset += set_block_no(p->payload + offset, blockno);
+ size_t offset = set_opcode(payload, TFTP_OP_DATA);
+ offset += set_block_no(payload + offset, blockno);
if (length > TFTP_BLOCKSIZE) {
length = TFTP_BLOCKSIZE;
}
- memcpy(p->payload + offset, buf, length);
- p->len = (uint16_t)length + offset;
- p->tot_len = (uint16_t)length + offset;
-
- int r = udp_sendto(pcb, p, addr, port);
- if (r != ERR_OK) {
- USER_PANIC("send failed");
- }
-
+ memcpy(payload + offset, buf, length);
+ err = net_send_to(socket, payload, length + offset, addr, port);
+ assert(err_is_ok(err));
return SYS_ERR_OK;
}
* ------------------------------------------------------------------------------
*/
-static void tftp_client_handle_write(struct udp_pcb *pcb, struct pbuf *pbuf,
- struct ip_addr *addr, u16_t port)
+static void tftp_client_handle_write(struct net_socket *socket, void *data,
+ size_t size, struct in_addr ip_address, uint16_t port)
{
USER_PANIC("NYI");
- tpft_op_t op = get_opcode(pbuf->payload);
+ tpft_op_t op = get_opcode(data);
uint32_t blockno;
switch(op) {
case TFTP_OP_ACK :
- blockno = get_block_no(pbuf->payload, pbuf->len);
- assert(pbuf->len == pbuf->tot_len);
+ blockno = get_block_no(data, size);
if (blockno == TFTP_ERR_INVALID_BUFFER) {
TFTP_DEBUG("failed to decode block number in data packet\n");
break;
tftp_client.block++;
- tftp_client_send_data(pcb, tftp_client.block, tftp_client.buf + offset, length,
- addr, port, tftp_client.p);
+ tftp_client_send_data(socket, tftp_client.block, tftp_client.buf + offset, length,
+ ip_address, port);
tftp_client.state = TFTP_ST_DATA_SENT;
} else {
TFTP_DEBUG("got double packet: %u\n", blockno);
tftp_client.state = TFTP_ST_ERROR;
break;
}
-
- pbuf_free(pbuf);
}
-static void tftp_client_handle_read(struct udp_pcb *pcb, struct pbuf *pbuf,
- struct ip_addr *addr, u16_t port)
+static void tftp_client_handle_read(struct net_socket *socket, void *data,
+ size_t size, struct in_addr ip_address, uint16_t port)
{
- tpft_op_t op = get_opcode(pbuf->payload);
+ tpft_op_t op = get_opcode(data);
uint32_t blockno;
switch(op) {
case TFTP_OP_DATA :
- blockno = get_block_no(pbuf->payload, pbuf->len);
- assert(pbuf->len == pbuf->tot_len);
+ blockno = get_block_no(data, size);
if (blockno == TFTP_ERR_INVALID_BUFFER) {
TFTP_DEBUG("failed to decode block number in data packet\n");
break;
}
if (blockno == tftp_client.block) {
- if (pbuf->len < 5) {
+ if (size < 5) {
TFTP_DEBUG("too small pbuf lenth\n");
}
- void *buf = pbuf->payload + 4;
- size_t length = pbuf->len - 4;
+ void *buf = data + 4;
+ size_t length = size - 4;
TFTP_DEBUG_PACKETS("received block %u of size %lu bytes\n", blockno, length);
if (tftp_client.buflen < tftp_client.bytes + length) {
}
memcpy(tftp_client.buf + tftp_client.bytes, buf, length);
- int r = tftp_send_ack(pcb, blockno, addr, port, tftp_client.p,
+ int r = tftp_send_ack(socket, blockno, ip_address, port,
tftp_client.ppayload);
- if (r != ERR_OK) {
+ if (r != SYS_ERR_OK) {
tftp_client.state = TFTP_ST_ERROR;
break;
}
}
} else {
TFTP_DEBUG("got double packet: %u\n", blockno);
- int r = tftp_send_ack(pcb, blockno, addr, port, tftp_client.p,
+ int r = tftp_send_ack(socket, blockno, ip_address, port,
tftp_client.ppayload);
- if (r != ERR_OK) {
+ if (r != SYS_ERR_OK) {
tftp_client.state = TFTP_ST_ERROR;
break;
}
break;
case TFTP_OP_ERROR :
TFTP_DEBUG("got a error packet\n");
- get_error(pbuf->payload, pbuf->len);
+ get_error(data, size);
tftp_client.state = TFTP_ST_ERROR;
break;
default:
TFTP_DEBUG("unexpected packet\n");
break;
}
-
- pbuf_free(pbuf);
}
-static void tftp_client_recv_handler(void *arg, struct udp_pcb *pcb, struct pbuf *pbuf,
- struct ip_addr *addr, u16_t port)
+static void tftp_client_recv_handler(void *user_state, struct net_socket *socket,
+ void *data, size_t size, struct in_addr ip_address, uint16_t port)
{
switch(tftp_client.state) {
case TFTP_ST_WRITE_REQ_SENT:
case TFTP_ST_DATA_SENT :
case TFTP_ST_LAST_DATA_SENT :
- tftp_client_handle_write(pcb, pbuf, addr, port);
+ tftp_client_handle_write(socket, data, size, ip_address, port);
break;
case TFTP_ST_READ_REQ_SENT :
case TFTP_ST_ACK_SENT :
- tftp_client_handle_read(pcb, pbuf, addr, port);
+ tftp_client_handle_read(socket, data, size, ip_address, port);
break;
default:
TFTP_DEBUG("unexpected state: %u\n", tftp_client.state);
size_t path_length = strlen(path);
assert(strlen(path) + 14 < TFTP_MAX_MSGSIZE);
- struct pbuf *p = tftp_client.p;
- assert(p);
-
- p->len = TFTP_MAX_MSGSIZE;
- p->tot_len = TFTP_MAX_MSGSIZE;
- p->payload = tftp_client.ppayload;
-
- memset(p->payload, 0, path_length + 16);
+ void *payload = tftp_client.ppayload;
- size_t length = set_opcode(p->payload, opcode);
+ memset(payload, 0, path_length + 16);
- length += snprintf(p->payload + length, path_length + 1, "%s", path) + 1;
- length += set_mode(p->payload + length, tftp_client.mode);
+ size_t length = set_opcode(payload, opcode);
- p->len = (uint16_t)length;
- p->tot_len = (uint16_t)length;
+ length += snprintf(payload + length, path_length + 1, "%s", path) + 1;
+ length += set_mode(payload + length, tftp_client.mode);
TFTP_DEBUG("sending udp payload of %lu bytes\n", length);
-
-
- int r = udp_send(tftp_client.pcb, p);
- if (r != ERR_OK) {
+ errval_t err;
+ err = net_send_to(tftp_client.pcb, payload, length, tftp_client.server_ip, tftp_client.server_port);
+ if (err != SYS_ERR_OK) {
TFTP_DEBUG("send failed\n");
}
}
{
switch(tftp_client.state) {
case TFTP_ST_INVALID :
- lwip_init_auto();
- tftp_client.pcb = udp_new();
+ net_sockets_init();
+ tftp_client.pcb = net_udp_socket();
TFTP_DEBUG("new connection from uninitialized state\n");
break;
case TFTP_ST_CLOSED :
TFTP_DEBUG("new connection from closed state\n");
- tftp_client.pcb = udp_new();
+ tftp_client.pcb = net_udp_socket();
break;
default:
TFTP_DEBUG("connection already established, cannot connect\n");
tftp_client.server_port = port;
- struct in_addr peer_ip_gen;
- int ret = inet_aton(ip, &peer_ip_gen);
+ int ret = inet_aton(ip, &tftp_client.server_ip);
if (ret == 0) {
TFTP_DEBUG("Invalid IP addr: %s\n", ip);
return 1;
}
- tftp_client.server_ip.addr = peer_ip_gen.s_addr;
TFTP_DEBUG("connecting to %s:%" PRIu16 "\n", ip, port);
- tftp_client.rcv_pcb = udp_new();
- int r = udp_bind(tftp_client.rcv_pcb, IP_ADDR_ANY, 0);
- if (r != ERR_OK) {
+ errval_t r;
+ r = net_bind(tftp_client.pcb, (struct in_addr){(INADDR_ANY)}, 0);
+ if (r != SYS_ERR_OK) {
USER_PANIC("UDP bind failed");
}
+ debug_printf("bound to %d\n", tftp_client.pcb->bound_port);
- r = udp_connect(tftp_client.pcb, &tftp_client.server_ip, tftp_client.server_port);
- if (r != ERR_OK) {
- USER_PANIC("UDP connect failed");
- }
- tftp_client.pcb->local_port = tftp_client.rcv_pcb->local_port;
+ // r = net_connect(tftp_client.pcb, tftp_client.server_ip, tftp_client.server_port, NULL);
+ // if (r != SYS_ERR_OK) {
+ // USER_PANIC("UDP connect failed");
+ // }
TFTP_DEBUG("registering recv handler\n");
- udp_recv(tftp_client.pcb, tftp_client_recv_handler, NULL);
- udp_recv(tftp_client.rcv_pcb, tftp_client_recv_handler, NULL);
+ net_recv(tftp_client.pcb, tftp_client_recv_handler);
tftp_client.state = TFTP_ST_IDLE;
tftp_client.mode = TFTP_MODE_OCTET;
- tftp_client.p = pbuf_alloc(PBUF_TRANSPORT, TFTP_MAX_MSGSIZE, PBUF_POOL);
- if (!tftp_client.p) {
- USER_PANIC("no buffer");
- }
- tftp_client.ppayload = tftp_client.p->payload;
+ tftp_client.ppayload = net_alloc(TFTP_MAX_MSGSIZE);
TFTP_DEBUG("all set up. connection idle\n");
return SYS_ERR_OK;
}
errval_t tftp_client_disconnect(void)
{
- pbuf_free(tftp_client.p);
- udp_remove(tftp_client.pcb);
- udp_remove(tftp_client.rcv_pcb);
+ net_free(tftp_client.ppayload);
+ net_close(tftp_client.pcb);
tftp_client.state = TFTP_ST_CLOSED;
return SYS_ERR_OK;
}
-
-
*/
#include <barrelfish/barrelfish.h>
-#include <lwip/udp.h>
+#include <net_sockets/net_sockets.h>
#include <tftp/tftp.h>
#include "tftp_internal.h"
* ------------------------------------------------------------------------------
*/
-errval_t tftp_send_ack(struct udp_pcb *pcb, uint32_t blockno,
- struct ip_addr *addr, u16_t port,
- struct pbuf *p, void *payload)
+errval_t tftp_send_ack(struct net_socket *socket, uint32_t blockno,
+ struct in_addr addr, uint16_t port,
+ void *payload)
{
TFTP_DEBUG_PACKETS("sending ack(%u)\n", blockno);
- p->len = TFTP_MAX_MSGSIZE;
- p->tot_len = TFTP_MAX_MSGSIZE;
- p->payload = payload;
+ memset(payload, 0, sizeof(uint32_t) + sizeof(uint16_t));
- memset(p->payload, 0, sizeof(uint32_t) + sizeof(uint16_t));
+ size_t length = set_opcode(payload, TFTP_OP_ACK);
+ length += set_block_no(payload + length, blockno);
- size_t length = set_opcode(p->payload, TFTP_OP_ACK);
- length += set_block_no(p->payload + length, blockno);
-
- p->len = (uint16_t)length +1;
- p->tot_len = (uint16_t)length+1;
-
- int r = udp_sendto(pcb, p, addr, port);
- if (r != ERR_OK) {
- TFTP_DEBUG("send failed\n");
- }
+ errval_t err;
+ err = net_send_to(socket, payload, length + 1, addr, port);
+ assert(err_is_ok(err));
return SYS_ERR_OK;
}
-
* Sending generic messages
* ------------------------------------------------------------------------------
*/
-errval_t tftp_send_ack(struct udp_pcb *pcb, uint32_t blockno,
- struct ip_addr *addr, u16_t port,
- struct pbuf *p, void *payload);
+errval_t tftp_send_ack(struct net_socket *socket, uint32_t blockno,
+ struct in_addr addr, uint16_t port,
+ void *payload);
#endif /* TFTP_INTERNAL_H_ */
modules.add_module("e1000_net_sockets_server", ["auto"])
nfsip = socket.gethostbyname(siteconfig.get('WEBSERVER_NFS_HOST'))
modules.add_module("webserver", ["core=%d" % machine.get_coreids()[0], #2
- cardName, nfsip,
- siteconfig.get('WEBSERVER_NFS_PATH')])
+ nfsip, siteconfig.get('WEBSERVER_NFS_PATH')])
# siteconfig.get('WEBSERVER_NFS_TEST_PATH')])
return modules
#include <barrelfish/deferred.h>
#include <barrelfish/nameservice_client.h>
+#include <arpa/inet.h>
+
#include <net/net.h>
+#include <net/dhcp.h>
#include <barrelfish/waitset_chan.h>
+#include <octopus/octopus.h>
+#include <octopus_server/service.h>
+#include <octopus/trigger.h>
+
#include <devif/queue_interface.h>
#include <devif/backends/descq.h>
nb->accepted_descriptor = 0;
nb->host_address.s_addr = 0;
nb->port = 0;
- debug_printf("%s(%d): close\n", __func__, socket->descriptor);
+ // 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);
}
nc->buffers[nc->next_free] = NULL;
nc->next_free = (nc->next_free + 1) % NO_OF_BUFFERS;
assert(sizeof(struct net_buffer) + length <= BUFFER_SIZE);
- debug_printf("%s.%d: enqueue 1 %lx:%ld %d\n", __func__, __LINE__, buffer - nc->buffer_start, sizeof(struct net_buffer) + length, nb->descriptor);
+ // debug_printf("%s.%d: enqueue 1 %lx:%ld %d\n", __func__, __LINE__, buffer - nc->buffer_start, sizeof(struct net_buffer) + length, nb->descriptor);
err = devq_enqueue((struct devq *)nc->queue, nc->region_id, buffer - nc->buffer_start, sizeof(struct net_buffer) + length,
0, 0, 1);
assert(err_is_ok(err));
struct socket_connection *socket = arg;
// struct network_connection *nc = socket->connection;
- debug_printf("%s(%d): error %d\n", __func__, socket->descriptor, err);
+ // debug_printf("%s(%d): error %d\n", __func__, socket->descriptor, err);
socket->tcp_socket = NULL; // invalidate
// uint32_t length = 0;
tcp_err(accepted_socket->tcp_socket, net_tcp_error);
tcp_sent(accepted_socket->tcp_socket, net_tcp_sent);
- debug_printf("%s(%d): -> %d\n", __func__, socket->descriptor, accepted_socket->descriptor);
+ // debug_printf("%s(%d): -> %d\n", __func__, socket->descriptor, accepted_socket->descriptor);
// errval_t err = nc->binding->tx_vtbl.accepted(nc->binding, BLOCKING_CONT, socket->descriptor, accepted_socket->descriptor, 0, 0, SYS_ERR_OK);
// assert(err_is_ok(err));
nb->size = 0;
nb->descriptor = socket->descriptor;
nb->accepted_descriptor = accepted_socket->descriptor;
- nb->host_address.s_addr = 0;
- nb->port = 0;
- debug_printf("%s(%d): accepted %p\n", __func__, socket->descriptor, newpcb);
+ nb->host_address.s_addr = newpcb->remote_ip.addr;
+ nb->port = newpcb->remote_port;
+ // debug_printf("%s(%d): accepted %p\n", __func__, socket->descriptor, newpcb);
nc->buffers[nc->next_free] = NULL;
nc->next_free = (nc->next_free + 1) % NO_OF_BUFFERS;
return SYS_ERR_OK;
}
-static errval_t net_bind(struct net_sockets_binding *binding, uint32_t descriptor, uint32_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, uint16_t *bound_port)
{
struct network_connection *nc;
struct socket_connection *socket;
ip.addr = ip_address;
*error = udp_bind(socket->udp_socket, &ip, port);
assert(err_is_ok(*error));
+ *bound_port = socket->udp_socket->local_port;
*error = SYS_ERR_OK;
debug_printf("UDP ECHO bind done.\n");
ip_addr_t ip;
ip.addr = ip_address;
- debug_printf("%s(%d): %x %d\n", __func__, socket->descriptor, ip.addr, port);
+ // debug_printf("%s(%d): %x %d\n", __func__, socket->descriptor, ip.addr, port);
*error = tcp_bind(socket->tcp_socket, &ip, port);
assert(err_is_ok(*error));
+ *bound_port = socket->tcp_socket->local_port;
*error = SYS_ERR_OK;
debug_printf("TCP ECHO bind done.\n");
assert(socket);
assert(socket->tcp_socket);
socket->tcp_socket = tcp_listen(socket->tcp_socket);
- debug_printf("%s(%d): listen %p\n", __func__, descriptor, socket->tcp_socket);
+ // debug_printf("%s(%d): listen %p\n", __func__, descriptor, socket->tcp_socket);
tcp_accept(socket->tcp_socket, net_tcp_accepted);
tcp_err(socket->tcp_socket, net_tcp_error);
// socket->tcp_socket = tcp_listen_with_backlog(socket->tcp_socket, backlog);
struct socket_connection *socket = arg;
struct network_connection *nc = socket->connection;
- errval_t err = nc->binding->tx_vtbl.connected(nc->binding, BLOCKING_CONT, socket->descriptor, SYS_ERR_OK);
+ errval_t err = nc->binding->tx_vtbl.connected(nc->binding, BLOCKING_CONT, socket->descriptor, SYS_ERR_OK, tpcb->remote_ip.addr, tpcb->remote_port);
assert(err_is_ok(err));
return SYS_ERR_OK;
tcp_recv(socket->tcp_socket, NULL); // you can receive packets after you close the socket
// tcp_accept(socket->tcp_socket, NULL);
err_t e;
- debug_printf("%s(%d): tcp_close %p\n", __func__, descriptor, socket->tcp_socket);
+ // debug_printf("%s(%d): tcp_close %p\n", __func__, descriptor, socket->tcp_socket);
e = tcp_close(socket->tcp_socket);
assert(e == ERR_OK);
}
- debug_printf("%s(%d):\n", __func__, descriptor);
- debug_printf("%s: %ld:%p %ld:%p\n", __func__, nc->next_free, nc->buffers[nc->next_free], nc->next_used, nc->buffers[nc->next_used]);
+ // debug_printf("%s(%d):\n", __func__, descriptor);
+ // debug_printf("%s: %ld:%p %ld:%p\n", __func__, nc->next_free, nc->buffers[nc->next_free], nc->next_used, nc->buffers[nc->next_used]);
if (last)
last->next = socket->next;
else
char servicename[64];
snprintf(servicename, sizeof(servicename), "e1000:%s", argv[2]);
+ // err = oct_init();
+ // assert(err_is_ok(err));
+ // err = oct_set(NET_CONFIG_STATIC_IP_RECORD_FORMAT, inet_addr("192.168.0.36"), inet_addr("0.0.0.0"), inet_addr("255.255.255.0"));
+ // assert(err_is_ok(err));
+
/* connect to the network */
- err = networking_init(servicename, NET_FLAGS_DO_DHCP);
+ err = networking_init(servicename, NET_FLAGS_DO_DHCP | NET_FLAGS_NO_NET_FILTER | NET_FLAGS_BLOCKING_INIT);
if (err_is_fail(err)) {
USER_PANIC_ERR(err, "Failed to initialize the network");
}
-
struct descq *exp_queue;
struct descq_func_pointer f;
// Specific for barrelfish
#include <barrelfish/barrelfish.h>
#include <vfs/vfs.h>
-#include <lwip/init.h>
#include <barrelfish/nameservice_client.h>
#include <barrelfish/waitset.h>
#include <netbench/netbench.h>
assert(buf);
uint64_t start = rdtsc();
- lwip_benchmark_control(1, BMS_START_REQUEST, 0, 0);
for (; filesize != info.size;) {
err = vfs_read(vh, buf, 10485760, &size);
// record stop time
uint64_t stop = rdtsc();
printf("Everything done\n");
- lwip_print_interesting_stats();
double speed = ((filesize/in_seconds(stop - start))/(1024 * 1024));
if (speed < 50) {
printf("Warning: NFS throughput too low!! [%f]\n", speed);
struct http_conn *conn = arg;
DEBUGPRINT("%d, http_server_recv called\n", conn->request_no);
- debug_printf("%s(%d): %ld\n", __func__, tpcb->descriptor, size);
+ // debug_printf("%s(%d): %ld\n", __func__, tpcb->descriptor, size);
// check if connection closed
assert(conn);
if (size == 0) {
DEBUGPRINT("%d, closing from http_server_recv\n", conn->request_no);
-debug_printf("%s.%d:\n", __func__, __LINE__);
+// debug_printf("%s.%d:\n", __func__, __LINE__);
http_server_close(tpcb, conn);
return;
}
DEBUGPRINT("invalid request: %s\n", conn->request);
DEBUGPRINT("%d: invalid request: %s\n",conn->request_no, conn->request);
conn->state = HTTP_STATE_CLOSING;
-debug_printf("%s.%d:\n", __func__, __LINE__);
+// debug_printf("%s.%d:\n", __func__, __LINE__);
http_server_close(tpcb, conn);
return;
}
-static void http_server_accept(void *arg, struct net_socket *tpcb, struct in_addr ip_address, uint16_t port)
+static void http_server_accept(void *arg, struct net_socket *tpcb)
{
// #if TCP_LISTEN_BACKLOG
// /* Decrease the listen backlog counter */
// struct tcp_pcb_listen *lpcb = (struct tcp_pcb_listen*)arg;
// #endif
- debug_printf("%s(%d):\n", __func__, tpcb->descriptor);
+ // debug_printf("%s(%d):\n", __func__, tpcb->descriptor);
struct http_conn *conn = http_conn_new();
DEBUGPRINT("accpet called: %s\n", conn->request);
increment_http_conn_reference (conn);