1/** 2 * \file 3 * \brief Echo server main 4 */ 5 6/* 7 * Copyright (c) 2007-12 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, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group. 13 */ 14 15#define NETD_SERVICE_DEBUG 16 17#include <barrelfish/barrelfish.h> 18#include <barrelfish/net_constants.h> 19 20// For event loops 21#include <barrelfish/dispatch.h> 22 23// standard include files 24#include <stdio.h> 25#include <stdlib.h> 26#include <string.h> 27 28#include <netd/netd.h> 29#include <netd/netd_debug.h> 30#include "netd_private.h" 31 32static char * duplicate_string(const char *string) 33{ 34 if (!string) 35 return NULL; 36 char *new_string = strdup(string); 37 assert(new_string); 38 return new_string; 39} 40 41/**************************************************************************** 42 * netd initialization function 43 ***************************************************************************/ 44 45errval_t netd_init(struct netd_state **state, char *card_name, uint64_t queueid, 46 bool do_dhcp, char *ip_addr_str, char *netmask_str, char *gateway_str) 47{ 48 NETD_DEBUG("###################################################\n"); 49 NETD_DEBUG("Initialising netd library\n"); 50 51 *state = malloc(sizeof(struct netd_state)); 52 (*state)->do_dhcp = do_dhcp; 53 (*state)->dhcp_completed = false; 54 55 (*state)->ip_addr_str = duplicate_string(ip_addr_str); 56 (*state)->netmask_str = duplicate_string(netmask_str); 57 (*state)->gateway_str = duplicate_string(gateway_str); 58 59 NETD_DEBUG("running on core %d\n", disp_get_core_id()); 60 NETD_DEBUG("###################################################\n"); 61 62 63 NETD_DEBUG("card name = %s\n", card_name); 64 if (!do_dhcp) 65 NETD_DEBUG("using static IP address\n"); 66 67 assert(card_name); 68 69 if (!do_dhcp) { 70 // Making sure that we have enough info for static configuration 71 if ((ip_addr_str == NULL) || (netmask_str == NULL) 72 || (gateway_str == NULL)) { 73 USER_PANIC("Error, not enough information provided for static " 74 "IP configuration IP[%s], NM[%s], GW[%s]", 75 ip_addr_str, netmask_str, gateway_str); 76 return 1; 77 } 78 } 79 // FIXME: This has to be done for every card 80 // Connect to the driver for given card 81 NETD_DEBUG("trying to connect to the %s:%"PRIu64" driver...\n", 82 card_name, queueid); 83 startlwip(*state, card_name, queueid); 84 85 NETD_DEBUG("registering net_ARP service\n"); 86 // register ARP service 87 init_ARP_lookup_service(*state, card_name); 88 89 return SYS_ERR_OK; 90} 91