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, Universitaetstrasse 6, CH-8092 Zurich. Attn: Systems Group. 13 */ 14 15#include <barrelfish/barrelfish.h> 16#include <barrelfish/net_constants.h> 17 18// For event loops 19#include <barrelfish/dispatch.h> 20 21// standard include files 22#include <stdio.h> 23#include <stdlib.h> 24#include <string.h> 25 26#include <netd/netd.h> 27#include <netd/netd_debug.h> 28 29static void netd_event_polling_loop(void) 30{ 31 errval_t err; 32 NETD_DEBUG("Starting event polling loop!!!\n"); 33 struct waitset *ws = get_default_waitset(); 34 uint32_t ecounter = 0; 35 while (1) { 36 err = event_dispatch_debug(ws); 37 if (err_is_fail(err)) { 38 DEBUG_ERR(err, "in event_dispatch"); 39 break; 40 } 41// NETD_DEBUG("event %"PRIu32" handled\n", ecounter); 42 ecounter++; 43 } 44} 45 46 47/**************************************************************************** 48 * netd main function 49 ***************************************************************************/ 50 51int main(int argc, char **argv) 52{ 53 char *card_name = NULL; 54 uint64_t allocated_queue = 0; 55 56 uint64_t minbase = -1, maxbase = -1; 57 58 bool do_dhcp = true; // flag to control use of dhcp 59 // IP information for static configuration 60 char *ip_addr_str = NULL; // IP address for this interface 61 char *netmask_str = NULL; // netmask for this LAN 62 char *gateway_str = NULL; // default gateway address 63 char *dns_str = NULL; // ip address of DNS name server 64 65 NETD_DEBUG("running on core %d\n", disp_get_core_id()); 66 NETD_DEBUG("###################################################\n"); 67 68 69 /* Read commandline args */ 70 for (int i = 0; i < argc; i++) { 71 if (strncmp(argv[i], "affinitymin=", strlen("affinitymin=")) == 0) { 72 minbase = atol(argv[i] + strlen("affinitymin=")); 73 NETD_DEBUG("minbase = %" PRIu64 "\n", minbase); 74 } 75 if (strncmp(argv[i], "affinitymax=", strlen("affinitymax=") - 1) == 0) { 76 maxbase = atol(argv[i] + strlen("affinitymax=")); 77 NETD_DEBUG("maxbase = %" PRIu64 "\n", maxbase); 78 } 79 if (strncmp(argv[i], "cardname=", strlen("cardname=") - 1) == 0) { 80 card_name = argv[i] + strlen("cardname="); 81 NETD_DEBUG("card name = %s\n", card_name); 82 } 83 if (!strcmp(argv[i], "do_dhcp=0")) { 84 do_dhcp = false; 85 NETD_DEBUG("using static IP address\n"); 86 } 87 88 if (strncmp(argv[i], "ip=", strlen("ip=") - 1) == 0) { 89 ip_addr_str = argv[i] + strlen("ip="); 90 } 91 92 if (strncmp(argv[i], "nm=", strlen("nm=") - 1) == 0) { 93 netmask_str = argv[i] + strlen("nm="); 94 } 95 96 if (strncmp(argv[i], "gw=", strlen("gw=") - 1) == 0) { 97 gateway_str = argv[i] + strlen("gw="); 98 } 99 100 if (strncmp(argv[i], "dns=", strlen("dns=") - 1) == 0) { 101 dns_str = argv[i] + strlen("dns="); 102 printf("Ignoring the argument [%s] as it is not supported yet!\n", 103 argv[i]); 104 } 105 106 } // end for: for each argument 107 108 if (card_name == NULL) { 109 fprintf(stderr, 110 "Error: netd: card name not specified, but it is required\n"); 111 fprintf(stderr, "Hint: try \"netd cardname=e1000\"\n"); 112 return 1; 113 } 114 115 if (!do_dhcp) { 116 // Making sure that we have enough info for static configuration 117 if ((ip_addr_str == NULL) || (netmask_str == NULL) 118 || (gateway_str == NULL)) { 119 USER_PANIC("Error, not enough information provided for static " 120 "IP configuration IP[%s], NM[%s], GW[%s]", 121 ip_addr_str, netmask_str, gateway_str); 122 return 1; 123 } 124 } 125 126 // Set memory affinity if requested 127 if ((minbase != -1) && (maxbase != -1)) { 128 ram_set_affinity(minbase, maxbase); 129 } 130 131 // FIXME: This has to be done for every card 132 // Connect to the driver for given card 133 NETD_DEBUG("trying to connect to the %s:%"PRIu64" driver...\n", 134 card_name, allocated_queue); 135 struct netd_state *state; 136 137 netd_init(&state, card_name, allocated_queue, do_dhcp, ip_addr_str, netmask_str, gateway_str); 138 139 netd_event_polling_loop(); 140 return 0; 141} 142