From: Jack Lange Date: Tue, 26 May 2009 03:15:34 +0000 (-0500) Subject: updates for user space utilities X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=6fbb40991e6c6dc5cd247ffe3d21413722bfbfce updates for user space utilities --- diff --git a/misc/network_servers/v3_nbd/.dependencies b/misc/network_servers/v3_nbd/.dependencies new file mode 100644 index 0000000..e69de29 diff --git a/misc/network_servers/v3_nbd/Makefile b/misc/network_servers/v3_nbd/Makefile index 5598cfd..7634e3e 100644 --- a/misc/network_servers/v3_nbd/Makefile +++ b/misc/network_servers/v3_nbd/Makefile @@ -1,4 +1,4 @@ -PREFIX=../local +PREFIX=.. INCLUDEDIR=$(PREFIX)/include LIBDIR=$(PREFIX)/lib diff --git a/misc/network_servers/v3_nbd/v3_nbd.cc b/misc/network_servers/v3_nbd/v3_nbd.cc index 1b1099d..1f7ca53 100644 --- a/misc/network_servers/v3_nbd/v3_nbd.cc +++ b/misc/network_servers/v3_nbd/v3_nbd.cc @@ -17,18 +17,69 @@ * redistribute, and modify it as specified in the file "V3VEE_LICENSE". */ +#include +#include +#include +#include #include +#ifdef linux +#include +#include +#include +#elif defined(WIN32) && !defined(__CYGWIN__) + +#endif + +#include "vtl.h" + + +#define DEFAULT_LOG_FILE "./status.log" +#define DEFAULT_CONF_FILE "v3_nbd.ini" -nbd_config_t g_nbd_conf; +#define DEFAULT_PORT 9500 +#define MAX_STRING_SIZE 1024 +#define MAX_DISKS 32 + +#define LOGFILE_TAG "logfile" +#define IP_ADDR_TAG "address" +#define PORT_TAG "port" +#define DISKS_TAG "disks" + using namespace std; //using namespace __gnu_cxx; +typedef enum {ISO, RAW} disk_type_t; + +struct disk_info { + string filename; + string tag; + disk_type_t type; +}; + +// eqstr from vtl (config.h) +typedef map disk_list_t; + +struct nbd_config { + unsigned long server_addr; + int server_port; + disk_list_t disks; + int num_disks; +}; + + + +static const int enable_debug = 1; +static struct nbd_config g_nbd_conf; + +void usage(); +int config_nbd(string conf_file_name); +int serv_loop(int serv_sock); +void setup_disk(string disk_tag); -config_t g_config; int __main (int argc, char ** argv); @@ -48,9 +99,7 @@ void main() { int __main (int argc, char ** argv) { string config_file; - SOCK vnet_sock = 0; - struct vnet_config vnet_info; - iface_t * iface; + int serv_sock; if (argc > 2) { usage(); exit(0); @@ -59,48 +108,33 @@ int __main (int argc, char ** argv) { if (argc == 2) { config_file = string(argv[1]); } else { - config_file = VIDS_CONF_FILE; + config_file = DEFAULT_CONF_FILE; } - - int * foo; - int num_ports = GetOpenUdpPorts(&foo); - int i; - for (i = 0; i < num_ports; i++) { - printf("port %d open\n", foo[i]); - } - - - // g_conf.log_file = "./vids.log"; - - if (config_vids(config_file) == -1) { + + if (config_nbd(config_file) == -1) { cerr << "Configuration Error" << endl; exit(-1); } - // JRL DEBUG - debug_init(g_config[LOGFILE_TAG].c_str()); - JRLDBG("testing...\n"); - + // setup network sockets - - // Configure pcap filter... - - vids_loop(iface, vnet_sock, &vnet_info); + vtl_debug("Starting Server Loop\n"); + serv_loop(serv_sock); return 0; } #ifdef linux -int vids_loop(iface_t * iface, SOCK vnet_sock, struct vnet_config * vnet_info) { +int serv_loop(int serv_sock) { fd_set all_set, read_set; int max_fd = -1; RawEthernetPacket pkt; FD_ZERO(&all_set); - FD_SET(vnet_sock, &all_set); - max_fd = vnet_sock; + FD_SET(serv_sock, &all_set); + max_fd = serv_sock; while (1) { @@ -119,9 +153,9 @@ int vids_loop(iface_t * iface, SOCK vnet_sock, struct vnet_config * vnet_info) { } - if (FD_ISSET(vnet_sock, &read_set)) { + if (FD_ISSET(serv_sock, &read_set)) { //vnet_recv(); - + } } @@ -130,7 +164,7 @@ int vids_loop(iface_t * iface, SOCK vnet_sock, struct vnet_config * vnet_info) { } #elif WIN32 -int vids_loop(iface_t * iface, SOCK vnet_sock, struct vnet_config * vnet_info) { +int serv_loop(iface_t * iface, SOCK vnet_sock, struct vnet_config * vnet_info) { int ret; RawEthernetPacket pkt; WSANETWORKEVENTS net_events; @@ -187,102 +221,66 @@ int vids_loop(iface_t * iface, SOCK vnet_sock, struct vnet_config * vnet_info) { -int config_vids(string conf_file_name) { - if (read_config(conf_file_name, &g_config) != 0) { - return -1; - } - - if (g_config.count(VIDS_SERVER_TAG) > 0) { - g_vids_conf.server_addr = ToIPAddress(g_config[VIDS_SERVER_TAG].c_str()); - } else { - printf("Must specify VIDS server address\n"); - return -1; - } - - if (g_config.count(VIDS_SERVER_PORT_TAG) > 0) { - g_vids_conf.server_port = atoi(g_config[VIDS_SERVER_PORT_TAG].c_str()); - } else { - printf("Must specify VIDS server port\n"); - return -1; - } - - if (g_config.count(TCP_PORTS_TAG) > 0) { - istringstream port_stream(g_config[TCP_PORTS_TAG], istringstream::in); - int port; - int i = 0; +int config_nbd(string conf_file_name) { + config_t config_map; - while (port_stream >> port) { - if (i >= MAX_PORTS) { - cerr << "You specified too many ports to forward, truncating..." << endl; - break; - } - - g_vids_conf.tcp_ports[i] = port; - i++; + if (read_config(conf_file_name, &config_map) != 0) { + cerr << "Could not read config file..." << endl; + return -1; } - g_vids_conf.num_tcp_ports = i; - } - - - - if (g_config.count(VIRTUAL_MAC_TAG) > 0) { - string_to_mac(g_config[VIRTUAL_MAC_TAG].c_str(), g_vids_conf.virtual_mac); - } - - if (g_config.count(LOGFILE_TAG) == 0) { - g_config[LOGFILE_TAG] = DEFAULT_LOG_FILE; - } - - if (GetLocalMacAddress(g_config[INTERFACE_TAG], g_vids_conf.local_mac) == -1) { - cerr << "Could not get local mac address" << endl; - return -1; - } - - - return 0; -} - + if (config_map.count(IP_ADDR_TAG) > 0) { + g_nbd_conf.server_addr = ToIPAddress(config_map[IP_ADDR_TAG].c_str()); + } -int read_config(string conf_file_name) { - fstream conf_file(conf_file_name.c_str(), ios::in); - char line[MAX_STRING_SIZE]; + if (config_map.count(PORT_TAG) > 0) { + g_nbd_conf.server_port = atoi(config_map[PORT_TAG].c_str()); + } else { + g_nbd_conf.server_port = DEFAULT_PORT; + } + + if (config_map.count(DISKS_TAG) > 0) { + istringstream disk_stream(config_map[DISKS_TAG], istringstream::in); + string disk_tag; + int i = 0; + + while (disk_stream >> disk_tag) { - while ((conf_file.getline(line, MAX_STRING_SIZE))) { - string conf_line = line; - string tag; - string value; - int offset, ltrim_index, rtrim_index; + if (i >= MAX_DISKS) { + cerr << "You specified too many disks, truncating..." << endl; + break; + } + + setup_disk(disk_tag); - if (conf_line[0] == '#') { - continue; + i++; + } + + g_nbd_conf.num_disks = i; + } else { + cerr << "Must specify a set of disks" << endl; + return -1; } + + + if (config_map.count(LOGFILE_TAG) == 0) { + config_map[LOGFILE_TAG] = DEFAULT_LOG_FILE; + } + - offset = conf_line.find(":", 0); - tag = conf_line.substr(0,offset); - - // kill white space - istringstream tag_stream(tag, istringstream::in); - tag_stream >> tag; + vtl_debug_init(config_map[LOGFILE_TAG], enable_debug); - if (tag.empty()) { - continue; - } - // basic whitespace trimming, we assume that the config handlers will deal with - // tokenizing and further formatting - value = conf_line.substr(offset + 1, conf_line.length() - offset); - ltrim_index = value.find_first_not_of(" \t"); - rtrim_index = value.find_last_not_of(" \t"); - value = value.substr(ltrim_index, (rtrim_index + 1) - ltrim_index); + return 0; +} - g_config[tag] = value; - } - return 0; +void setup_disk(string disk_tag) { + printf("Setting up %s\n", disk_tag.c_str()); } + void usage() { - cout << "Usage: vids [config_file]" << endl; + cout << "Usage: v3_nbd [config_file]" << endl; return; } diff --git a/misc/network_servers/v3_nbd/v3_nbd.h b/misc/network_servers/v3_nbd/v3_nbd.h deleted file mode 100644 index b7e4e6a..0000000 --- a/misc/network_servers/v3_nbd/v3_nbd.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * This file is part of the Palacios Virtual Machine Monitor developed - * by the V3VEE Project with funding from the United States National - * Science Foundation and the Department of Energy. - * - * The V3VEE Project is a joint project between Northwestern University - * and the University of New Mexico. You can find out more at - * http://www.v3vee.org - * - * Copyright (c) 2008, Jack Lange - * Copyright (c) 2008, The V3VEE Project - * All rights reserved. - * - * Author: Jack Lange - * - * This is free software. You are permitted to use, - * redistribute, and modify it as specified in the file "V3VEE_LICENSE". - */ - -#ifndef __V3_NBD_H__ -#define __V3_NBD_H__ - -#include -#include -#include -#include -#include - -#ifdef linux -#include -#include -#include -#elif defined(WIN32) && !defined(__CYGWIN__) - -#endif - - -using namespace std; - - - -#define DEFAULT_LOG_FILE "./status.log" -#define VIDS_CONF_FILE "v3_nbd.ini" -#define MAX_STRING_SIZE 1024 - - -typedef struct nbd_config { - unsigned long server_addr; - int server_port; - - -} nbd_config_t; - - - -void usage(); -int config_nbd(string conf_file_name); - - - -#define VIDS_SERVER_TAG "vids_server" - - -#endif // !__VIDS_H diff --git a/misc/network_servers/vtl/Makefile b/misc/network_servers/vtl/Makefile index 885adf9..329a377 100644 --- a/misc/network_servers/vtl/Makefile +++ b/misc/network_servers/vtl/Makefile @@ -1,7 +1,4 @@ -DISTDIR= ../dist -PREFIX=../local -DEBUG=-DDEBUG -#DEBUG= +PREFIX=.. #PROFILER=-pg PROFILER= @@ -9,12 +6,10 @@ INCLUDEDIR=$(PREFIX)/include LIBDIR=$(PREFIX)/lib BINDIR=$(PREFIX)/bin -VTL_OBJS = vtl_util.o if.o socks.o util.o net_util.o raw_ethernet_packet.o vtl_model.o config.o -TOR_VTL_OBJS = vtl_socks5.o tor_vtl.o vtl_dns.o +VTL_OBJS = vtl_util.o if.o socks.o util.o net_util.o raw_ethernet_packet.o vtl_model.o config.o debug.o VTL_HDRS = vtl.h vtl_util.h util.h socks.h if.h net_util.h vtl_model.h raw_ethernet_packet.h debug.h config.h vtl_harness.h -DISTFILES = config.cc config.h debug.h if.cc if.h net_util.cc net_util.h raw_ethernet_packet.cc raw_ethernet_packet.h socks.cc socks.h util.cc util.h vtl.h vtl_harness.h vtl_model.cc vtl_model.h vtl_util.cc vtl_util.h Makefile .dependencies LIBNETLDFLAGS = -L$(LIBDIR) -lnet SSLFLAGS = -lssl @@ -29,8 +24,8 @@ CC=/usr/bin/gcc AR=ar RANLIB=ranlib -#CXXFLAGS = -DDEBUG -g -gstabs+ -Wall $(PCAPCFLAGS) -I/usr/kerberos/include -CXXFLAGS = $(DEBUG) -Wall -g -gstabs+ -DUSE_SSL $(PCAPCFLAGS) -I/usr/kerberos/include +#CXXFLAGS = -g -gstabs+ -Wall $(PCAPCFLAGS) -I/usr/kerberos/include +CXXFLAGS = -Wall -g -gstabs+ -DUSE_SSL $(PCAPCFLAGS) -I/usr/kerberos/include LDFLAGS = -L$(LIBDIR) $(PCAPLDFLAGS) $(LIBNETLDFLAGS) $(SSLFLAGS) diff --git a/misc/network_servers/vtl/config.cc b/misc/network_servers/vtl/config.cc index f54d765..7ec81a2 100644 --- a/misc/network_servers/vtl/config.cc +++ b/misc/network_servers/vtl/config.cc @@ -35,7 +35,10 @@ int read_config(string conf_file_name, config_t * config) { value = conf_line.substr(offset + 1, conf_line.length() - offset); ltrim_index = value.find_first_not_of(" \t"); rtrim_index = value.find_last_not_of(" \t"); - value = value.substr(ltrim_index, (rtrim_index + 1) - ltrim_index); + + if ((ltrim_index >= 0) && (rtrim_index >= 0)) { + value = value.substr(ltrim_index, (rtrim_index + 1) - ltrim_index); + } (*config)[tag] = value; } diff --git a/misc/network_servers/vtl/debug.h b/misc/network_servers/vtl/debug.h index 20cb547..91d4744 100644 --- a/misc/network_servers/vtl/debug.h +++ b/misc/network_servers/vtl/debug.h @@ -1,61 +1,12 @@ #ifndef __DEBUG_H -#define __DEBUG_H 1 +#define __DEBUG_H +#include +using namespace std; - -#ifdef DEBUG - -#define ASSERT(exp) assert(exp) - -/* - * - * - */ - -#ifdef linux - -extern FILE * logfile; -extern time_t dbgt; -extern char dmsg[1024]; - -#define DEBUG_DECLARE() FILE * logfile; time_t dbgt; char dmsg[1024]; -#define JRLDBG( ...) time(&dbgt); sprintf(dmsg,"%s: ",ctime(&dbgt)); *(dmsg + strlen(dmsg) -3) = ' '; fprintf(logfile, dmsg); sprintf(dmsg,__VA_ARGS__); fprintf(logfile,dmsg); fflush(logfile); -#define debug_init(logfilename) logfile = fopen(logfilename,"w+") - -#elif defined(WIN32) - -#define DEBUG_DECLARE() -#define JRLDBG printf -#define debug_init(logfilename) - -#endif - -/* - * - * - */ - -#else //!DEBUG - -#ifdef WIN32 - -#define ASSERT(exp) -#define DEBUG_DECLARE() -#define JRLDBG() -#define debug_init(logfilename) - -#elif defined(linux) - -#define ASSERT(exp) -#define DEBUG_DECLARE(...) -#define JRLDBG(...) -#define debug_init(logfilename) - -#endif - -#endif - +int vtl_debug_init(string logfilename, int debug_enable); +void vtl_debug(const char * fmt, ...); #endif diff --git a/misc/network_servers/vtl/if.cc b/misc/network_servers/vtl/if.cc index 808eb6b..bde6e9a 100644 --- a/misc/network_servers/vtl/if.cc +++ b/misc/network_servers/vtl/if.cc @@ -18,7 +18,7 @@ iface_t * if_connect(string if_name, char mode) { #ifdef linux if (mode & IF_RD) { if ((iface->pcap_interface = pcap_open_live((char*)if_name.c_str(), 65536, 1, 1, pcap_errbuf)) == NULL) { - JRLDBG("Could not initialize pcap\n"); + vtl_debug("Could not initialize pcap\n"); return NULL; } @@ -29,14 +29,14 @@ iface_t * if_connect(string if_name, char mode) { char libnet_errbuf[LIBNET_ERRORBUF_SIZE]; if ((iface->net_interface = libnet_init(LIBNET_LINK_ADV, (char *)if_name.c_str(), libnet_errbuf)) == NULL) { - JRLDBG("Could not initialize libnet\n"); + vtl_debug("Could not initialize libnet\n"); return NULL; } } #elif defined(WIN32) if ((iface->pcap_interface = pcap_open_live((char*)if_name.c_str(), 65536, 1, 1, pcap_errbuf)) == NULL) { - JRLDBG("Could not initialize pcap\n"); + vtl_debug("Could not initialize pcap\n"); return NULL; } @@ -115,14 +115,14 @@ int if_read_pkt(iface_t * iface, RawEthernetPacket * pkt) { int if_write_pkt(iface_t * iface, RawEthernetPacket * pkt) { - ASSERT((iface != NULL) && (pkt != NULL) && (iface->net_interface != NULL)); + assert((iface != NULL) && (pkt != NULL) && (iface->net_interface != NULL)); #ifdef linux - JRLDBG("Writing pkt size(%lu)\n", pkt->get_size()); + vtl_debug("Writing pkt size(%lu)\n", pkt->get_size()); if (libnet_adv_write_link(iface->net_interface, (u_char *)(pkt->get_data()), pkt->get_size()) < 0) { - JRLDBG("Libnet could not inject packet size (%lu)\n", pkt->get_size()); + vtl_debug("Libnet could not inject packet size (%lu)\n", pkt->get_size()); return -1; } @@ -130,7 +130,7 @@ int if_write_pkt(iface_t * iface, RawEthernetPacket * pkt) { if (pcap_sendpacket(iface->pcap_interface, (u_char *)(pkt->get_data()), pkt->get_size()) < 0) { - JRLDBG("PCAP could not inject packet\n"); + vtl_debug("PCAP could not inject packet\n"); return -1; } @@ -151,19 +151,19 @@ int if_setup_filter(iface_t * iface, string bpf_str) { strcpy(filter_buf, bpf_str.c_str()); cout << "Setting Getting interface info for " << iface->name << endl; if (pcap_lookupnet(iface->name->c_str(), &network, &netmask, errbuf) == -1) { - JRLDBG("Error looking up the network info\n"); + vtl_debug("Error looking up the network info\n"); return -1; } netmask=0xffffffff; cout << bpf_str << endl; if (pcap_compile(iface->pcap_interface, &fcode, filter_buf, 1, netmask) < 0) { - JRLDBG("Could not compile bpf filter\n"); + vtl_debug("Could not compile bpf filter\n"); return -1; } if (pcap_setfilter(iface->pcap_interface, &fcode) < 0) { - JRLDBG("Could not insert bpf filter\n"); + vtl_debug("Could not insert bpf filter\n"); return -1; } diff --git a/misc/network_servers/vtl/raw_ethernet_packet.cc b/misc/network_servers/vtl/raw_ethernet_packet.cc index 1df7149..7e17870 100644 --- a/misc/network_servers/vtl/raw_ethernet_packet.cc +++ b/misc/network_servers/vtl/raw_ethernet_packet.cc @@ -98,21 +98,21 @@ int RawEthernetPacket::Unserialize(const SOCK fd, SSL * ssl) { ret = Receive(fd, ssl, pkt, sizeof(char) * 2 + sizeof(size_t), true); if (ret == 0) { - JRLDBG("TCP socket closed\n"); + vtl_debug("TCP socket closed\n"); return 0; } else if (ret != (sizeof(char) * 2 + sizeof(size_t))) { - JRLDBG("Error unserializing packet header from tcp socket\n"); + vtl_debug("Error unserializing packet header from tcp socket\n"); return -1; } - JRLDBG("Receiving TCP data. size=%lu, offset=%d\n", this->get_size(), *(pkt + 2)); + vtl_debug("Receiving TCP data. size=%lu, offset=%d\n", this->get_size(), *(pkt + 2)); ret = Receive(fd, ssl, data, this->get_size(), true); if (ret == 0) { - JRLDBG("TCP Socket closed\n"); + vtl_debug("TCP Socket closed\n"); return 0; } else if (ret != (int)this->get_size()) { - JRLDBG("Error unserializing packet from tcp socket\n"); + vtl_debug("Error unserializing packet from tcp socket\n"); return -1; } @@ -136,21 +136,21 @@ int RawEthernetPacket::Unserialize(const SOCK fd) { ret = Receive(fd, pkt, sizeof(char) * 2 + sizeof(size_t), true); if (ret == 0) { - JRLDBG("TCP socket closed\n"); + vtl_debug("TCP socket closed\n"); return 0; } else if (ret != (sizeof(char) * 2 + sizeof(size_t))) { - JRLDBG("Error unserializing packet header from tcp socket\n"); + vtl_debug("Error unserializing packet header from tcp socket\n"); return -1; } - JRLDBG("Receiving TCP data. size=%lu, offset=%d\n", this->get_size(), *(pkt + 2)); + vtl_debug("Receiving TCP data. size=%lu, offset=%d\n", this->get_size(), *(pkt + 2)); ret = Receive(fd, data, this->get_size(), true); if (ret == 0) { - JRLDBG("TCP Socket closed\n"); + vtl_debug("TCP Socket closed\n"); return 0; } else if (ret != (int)this->get_size()) { - JRLDBG("Error unserializing packet from tcp socket\n"); + vtl_debug("Error unserializing packet from tcp socket\n"); return -1; } @@ -192,37 +192,37 @@ int RawEthernetPacket::VtpUnserialize(const SOCK fd, struct in_addr * serveraddr ret = Receive(fd, pkt, sizeof(char) * 2, true); if (ret == 0) { - JRLDBG("VTP connection has Closed\n"); + vtl_debug("VTP connection has Closed\n"); return 0; } else if (ret != (int)sizeof(char) * 2) { - JRLDBG("Could not read type from VTP packet\n"); + vtl_debug("Could not read type from VTP packet\n"); return -1; } ret = Receive(fd, (char *)serveraddr, sizeof(struct in_addr), true); if (ret == 0) { - JRLDBG("VTP connection has closed\n"); + vtl_debug("VTP connection has closed\n"); return 0; } else if (ret != (int)sizeof(struct in_addr)) { - JRLDBG("Could not read VTP address info\n"); + vtl_debug("Could not read VTP address info\n"); return -1; } ret = Receive(fd, (char *)size, sizeof(size_t), true); if (ret == 0) { - JRLDBG("VTP connection has closed\n"); + vtl_debug("VTP connection has closed\n"); return 0; } else if (ret != sizeof(size_t)) { - JRLDBG("Could not read VTP size\n"); + vtl_debug("Could not read VTP size\n"); return -1; } ret = Receive(fd, data, this->get_size(), true); if (ret == 0) { - JRLDBG("VTP connection has closed\n"); + vtl_debug("VTP connection has closed\n"); return 0; } else if (ret != (int)this->get_size()) { - JRLDBG("Could not read VTP packet data\n"); + vtl_debug("Could not read VTP packet data\n"); return -1; } @@ -235,13 +235,13 @@ int RawEthernetPacket::VtpSerialize(const SOCK fd, struct in_addr * serveraddr ) ret = Send(fd, type, sizeof(char) * 2, true); if (ret != sizeof(char) * 2) { - JRLDBG("Error writing type to VTP socket\n"); + vtl_debug("Error writing type to VTP socket\n"); return -1; } ret = Send(fd, (char *)serveraddr, sizeof(struct in_addr), true); if (ret != sizeof(struct in_addr)) { - JRLDBG("Error writing dest addr to VTP socket\n"); + vtl_debug("Error writing dest addr to VTP socket\n"); return -1; } @@ -249,7 +249,7 @@ int RawEthernetPacket::VtpSerialize(const SOCK fd, struct in_addr * serveraddr ) ret = Send(fd, pkt + (sizeof(char) * 2), length, true); if (ret != (int)length) { - JRLDBG("ERROR writing packet length and data to VTP socket\n"); + vtl_debug("ERROR writing packet length and data to VTP socket\n"); return -1; } diff --git a/misc/network_servers/vtl/vtl_model.cc b/misc/network_servers/vtl/vtl_model.cc index a571c62..58f976d 100644 --- a/misc/network_servers/vtl/vtl_model.cc +++ b/misc/network_servers/vtl/vtl_model.cc @@ -18,9 +18,9 @@ vtl_model_t * new_vtl_model(model_type_t type) { int initialize_ethernet_model(ethernet_model_t * model, RawEthernetPacket * pkt, int dir = OUTBOUND_PKT) { - ASSERT((model != NULL) && (pkt != NULL)); + assert((model != NULL) && (pkt != NULL)); - printf("initializing ethernet model\n"); + vtl_debug("initializing ethernet model\n"); if (dir == OUTBOUND_PKT) { GET_ETH_DST(pkt->data, model->dst.addr); GET_ETH_SRC(pkt->data, model->src.addr); @@ -37,7 +37,7 @@ int initialize_ethernet_model(ethernet_model_t * model, RawEthernetPacket * pkt, } int initialize_ip_model(ip_model_t * model, RawEthernetPacket * pkt, int dir) { - ASSERT((model != NULL) && (pkt != NULL)); + assert((model != NULL) && (pkt != NULL)); if (!is_ip_pkt(pkt)) { return -1; @@ -72,7 +72,7 @@ int initialize_ip_model(ip_model_t * model, RawEthernetPacket * pkt, int dir) { } int initialize_tcp_model(tcp_model_t * model, RawEthernetPacket * pkt, int dir) { - ASSERT((model != NULL) && (pkt != NULL)); + assert((model != NULL) && (pkt != NULL)); tcp_opts_t options; @@ -115,7 +115,7 @@ int initialize_tcp_model(tcp_model_t * model, RawEthernetPacket * pkt, int dir) } int initialize_udp_model(udp_model_t * model, RawEthernetPacket * pkt, int dir) { - ASSERT((model != NULL) && (pkt != NULL)); + assert((model != NULL) && (pkt != NULL)); if (!is_udp_pkt(pkt)) { return -1; @@ -141,7 +141,7 @@ int initialize_udp_model(udp_model_t * model, RawEthernetPacket * pkt, int dir) int initialize_model(vtl_model_t * model, RawEthernetPacket * pkt, int dir) { - ASSERT((model != NULL) && (pkt != NULL)); + assert((model != NULL) && (pkt != NULL)); if (model->type == TCP_MODEL) { return initialize_tcp_model(&(model->model.tcp_model), pkt, dir); @@ -157,7 +157,7 @@ int initialize_model(vtl_model_t * model, RawEthernetPacket * pkt, int dir) { int is_ethernet_model_pkt(ethernet_model_t * model, RawEthernetPacket * pkt) { - ASSERT((model != NULL) && (pkt != NULL)); + assert((model != NULL) && (pkt != NULL)); if ((memcmp(model->src.addr, ETH_SRC(pkt->data), 6) == 0) && (memcmp(model->dst.addr, ETH_DST(pkt->data), 6) == 0)) { @@ -171,7 +171,7 @@ int is_ethernet_model_pkt(ethernet_model_t * model, RawEthernetPacket * pkt) { } int is_ip_model_pkt(ip_model_t * model, RawEthernetPacket * pkt) { - ASSERT((model != NULL) && (pkt != NULL)); + assert((model != NULL) && (pkt != NULL)); if (!is_ip_pkt(pkt)) { return INVALID_PKT; @@ -190,7 +190,7 @@ int is_ip_model_pkt(ip_model_t * model, RawEthernetPacket * pkt) { int is_tcp_model_pkt(tcp_model_t * model, RawEthernetPacket * pkt) { - ASSERT((model != NULL) && (pkt != NULL)); + assert((model != NULL) && (pkt != NULL)); int ip_ret; if (!is_tcp_pkt(pkt)) { @@ -217,7 +217,7 @@ int is_tcp_model_pkt(tcp_model_t * model, RawEthernetPacket * pkt) { } int is_udp_model_pkt(udp_model_t * model, RawEthernetPacket * pkt) { - ASSERT((model != NULL) && (pkt != NULL)); + assert((model != NULL) && (pkt != NULL)); int ip_ret; if (!is_udp_pkt(pkt)) { @@ -244,7 +244,7 @@ int is_udp_model_pkt(udp_model_t * model, RawEthernetPacket * pkt) { } int is_model_pkt(vtl_model_t * model, RawEthernetPacket * pkt) { - ASSERT((model != NULL) && (pkt != NULL)); + assert((model != NULL) && (pkt != NULL)); if (model->type == TCP_MODEL) { return is_tcp_model_pkt(&(model->model.tcp_model), pkt); @@ -255,7 +255,7 @@ int is_model_pkt(vtl_model_t * model, RawEthernetPacket * pkt) { int sync_ip_model(ip_model_t * model, RawEthernetPacket * pkt) { - ASSERT((model != NULL) && (pkt != NULL)); + assert((model != NULL) && (pkt != NULL)); int ip_ret; @@ -276,7 +276,7 @@ int sync_ip_model(ip_model_t * model, RawEthernetPacket * pkt) { int sync_tcp_model(tcp_model_t * model, RawEthernetPacket * pkt) { - ASSERT((model != NULL) && (pkt != NULL)); + assert((model != NULL) && (pkt != NULL)); int tcp_ret; tcp_opts_t options; int has_opts = 0; @@ -314,7 +314,7 @@ int sync_tcp_model(tcp_model_t * model, RawEthernetPacket * pkt) { int sync_udp_model(udp_model_t * model, RawEthernetPacket * pkt) { - ASSERT((model != NULL) && (pkt != NULL)); + assert((model != NULL) && (pkt != NULL)); int udp_ret; udp_ret = is_udp_model_pkt(model, pkt); @@ -437,7 +437,7 @@ int create_empty_tcp_pkt(tcp_model_t * model, RawEthernetPacket * pkt, int dir) compute_tcp_checksum(pkt); - JRLDBG("tcp_len = %d\n", GET_TCP_HDR_LEN(pkt->data)); + vtl_debug("tcp_len = %d\n", GET_TCP_HDR_LEN(pkt->data)); // Set the ip hdr len @@ -483,20 +483,20 @@ void dbg_dump_eth_model(ethernet_model_t * model) { char src_mac[6]; char dst_mac[6]; - printf("ETHERNET MODEL {\n"); + vtl_debug("ETHERNET MODEL {\n"); - printf("\tType: %s\n", get_eth_protocol(model->type)); + vtl_debug("\tType: %s\n", get_eth_protocol(model->type)); mac_to_string(model->src.addr, src_mac); - printf("\tSrc Host {\n"); - printf("\t\taddr: %s\n", src_mac); - printf("\t}\n"); + vtl_debug("\tSrc Host {\n"); + vtl_debug("\t\taddr: %s\n", src_mac); + vtl_debug("\t}\n"); mac_to_string(model->dst.addr, dst_mac); - printf("\tDST Host {\n"); - printf("\t\taddr: %s\n", dst_mac); - printf("\t}\n"); - printf("}\n"); + vtl_debug("\tDST Host {\n"); + vtl_debug("\t\taddr: %s\n", dst_mac); + vtl_debug("\t}\n"); + vtl_debug("}\n"); } @@ -504,50 +504,50 @@ void dbg_dump_eth_model(ethernet_model_t * model) { void dbg_dump_ip_model(ip_model_t * model) { dbg_dump_eth_model(&(model->ethernet)); - printf("IP MODEL {\n"); - printf("\tVersion: %d\n", model->version); - printf("\tProtocol: %s\n", get_ip_protocol(model->proto)); + vtl_debug("IP MODEL {\n"); + vtl_debug("\tVersion: %d\n", model->version); + vtl_debug("\tProtocol: %s\n", get_ip_protocol(model->proto)); - printf("\tSrc Host {\n"); - printf("\t\taddr: %s\n", ip_to_string(model->src.addr)); - printf("\t\tIP ID: %d\n", model->src.ip_id); - printf("\t\tttl: %d\n", model->src.ttl); - printf("\t}\n"); + vtl_debug("\tSrc Host {\n"); + vtl_debug("\t\taddr: %s\n", ip_to_string(model->src.addr)); + vtl_debug("\t\tIP ID: %d\n", model->src.ip_id); + vtl_debug("\t\tttl: %d\n", model->src.ttl); + vtl_debug("\t}\n"); - printf("\tDst Host {\n"); - printf("\t\taddr: %s\n", ip_to_string(model->dst.addr)); - printf("\t\tIP ID: %d\n", model->dst.ip_id); - printf("\t\tttl: %d\n", model->dst.ttl); - printf("\t}\n"); + vtl_debug("\tDst Host {\n"); + vtl_debug("\t\taddr: %s\n", ip_to_string(model->dst.addr)); + vtl_debug("\t\tIP ID: %d\n", model->dst.ip_id); + vtl_debug("\t\tttl: %d\n", model->dst.ttl); + vtl_debug("\t}\n"); - printf("}\n"); + vtl_debug("}\n"); } void dbg_dump_tcp_model(tcp_model_t * model) { dbg_dump_ip_model(&(model->ip)); - printf("TCP MODEL {\n"); - printf("\tSrc Host {\n"); - printf("\t\tport: %hu\n", model->src.port); - printf("\t\tseq: %lu\n", (unsigned long)(model->src.seq_num)); - printf("\t\tlast ack: %lu\n", (unsigned long)(model->src.last_ack)); - printf("\t\tWin Size: %hu\n", model->src.win); - printf("\t\tTimestamp: %lu\n", (unsigned long)(model->src.ts)); - printf("\t\tMSS: %hu\n", model->src.mss); + vtl_debug("TCP MODEL {\n"); + vtl_debug("\tSrc Host {\n"); + vtl_debug("\t\tport: %hu\n", model->src.port); + vtl_debug("\t\tseq: %lu\n", (unsigned long)(model->src.seq_num)); + vtl_debug("\t\tlast ack: %lu\n", (unsigned long)(model->src.last_ack)); + vtl_debug("\t\tWin Size: %hu\n", model->src.win); + vtl_debug("\t\tTimestamp: %lu\n", (unsigned long)(model->src.ts)); + vtl_debug("\t\tMSS: %hu\n", model->src.mss); - printf("\t}\n"); + vtl_debug("\t}\n"); - printf("\tDst Host {\n"); - printf("\t\tport: %hu\n", model->dst.port); - printf("\t\tseq: %lu\n", (unsigned long)(model->dst.seq_num)); - printf("\t\tlast ack: %lu\n", (unsigned long)(model->dst.last_ack)); - printf("\t\tWin Size: %hu\n", model->dst.win); - printf("\t\tTimestamp: %lu\n", (unsigned long)(model->dst.ts)); - printf("\t\tMSS: %hu\n", model->dst.mss); - printf("\t}\n"); + vtl_debug("\tDst Host {\n"); + vtl_debug("\t\tport: %hu\n", model->dst.port); + vtl_debug("\t\tseq: %lu\n", (unsigned long)(model->dst.seq_num)); + vtl_debug("\t\tlast ack: %lu\n", (unsigned long)(model->dst.last_ack)); + vtl_debug("\t\tWin Size: %hu\n", model->dst.win); + vtl_debug("\t\tTimestamp: %lu\n", (unsigned long)(model->dst.ts)); + vtl_debug("\t\tMSS: %hu\n", model->dst.mss); + vtl_debug("\t}\n"); - printf("}\n"); + vtl_debug("}\n"); } diff --git a/misc/network_servers/vtl/vtl_util.cc b/misc/network_servers/vtl/vtl_util.cc index e9e3f9b..ded50db 100644 --- a/misc/network_servers/vtl/vtl_util.cc +++ b/misc/network_servers/vtl/vtl_util.cc @@ -17,7 +17,7 @@ void dbg_print_pkt_info(RawEthernetPacket * pkt) { dest_str = ip_to_string(GET_IP_DST(pkt->data)); src_str = ip_to_string(GET_IP_SRC(pkt->data)); - JRLDBG("Packet: %s:%d-%s:%d seq: %lu, ack: %lu\n", src_str.c_str(), ntohs(src_port), dest_str.c_str(), ntohs(dest_port), + vtl_debug("Packet: %s:%d-%s:%d seq: %lu, ack: %lu\n", src_str.c_str(), ntohs(src_port), dest_str.c_str(), ntohs(dest_port), seq_num, ack_num); return; @@ -30,7 +30,7 @@ void dbg_print_pkt(RawEthernetPacket * pkt) { char pkt_line[128]; unsigned int pkt_size = pkt->get_size() - 1; - JRLDBG("Packet Dump: (pkt_size=%lu) \n", pkt->get_size()); + vtl_debug("Packet Dump: (pkt_size=%lu) \n", pkt->get_size()); for (x = 0; x < pkt_size;) { sprintf(pkt_line, "\t%.4x: ", x); @@ -48,7 +48,7 @@ void dbg_print_pkt(RawEthernetPacket * pkt) { } } - JRLDBG("%s\n", pkt_line); + vtl_debug("%s\n", pkt_line); x += 16; } @@ -59,7 +59,7 @@ void dbg_print_buf(unsigned char * buf, unsigned int len) { int i; char pkt_line[128]; - JRLDBG("Buf Dump: (len=%d) \n", len); + vtl_debug("Buf Dump: (len=%d) \n", len); for (x = 0; x < len-1;) { sprintf(pkt_line, "\t%.4x: ", x); @@ -77,7 +77,7 @@ void dbg_print_buf(unsigned char * buf, unsigned int len) { } } - JRLDBG("%s\n", pkt_line); + vtl_debug("%s\n", pkt_line); x += 16; } @@ -135,7 +135,7 @@ int get_mss(RawEthernetPacket * pkt) { } int parse_tcp_options(tcp_opts_t * options, RawEthernetPacket * pkt) { - ASSERT((options != NULL) && (pkt != NULL)); + assert((options != NULL) && (pkt != NULL)); memset(options, 0, sizeof(options)); @@ -234,7 +234,7 @@ unsigned long get_tcp_timestamp(char *opts, int len) { offset += *(opts + offset + 1); } else { offset += *(opts + offset + 1); - //JRLDBG("Could not find timestamp\n"); + //vtl_debug("Could not find timestamp\n"); //break; } } @@ -286,7 +286,7 @@ int pkt_has_timestamp(RawEthernetPacket * pkt) { return offset; } else { offset += *(opts + offset + 1); - //JRLDBG("Could not find timestamp\n"); + //vtl_debug("Could not find timestamp\n"); //break; } } @@ -517,7 +517,7 @@ unsigned short get_tcp_checksum(RawEthernetPacket * pkt, unsigned short tcp_len) // memcpy(buf + 6, (pkt->data + ETH_HDR_LEN + GET_IP_HDR_LEN(pkt->data)), tcp_len); memcpy(buf + 6, TCP_HDR(pkt->data), tcp_len); if (tcp_len % 2) { - JRLDBG("Odd tcp_len: %hu\n", tcp_len); + vtl_debug("Odd tcp_len: %hu\n", tcp_len); *(((char*)buf) + 2 * 6 + tcp_len) = 0; } @@ -549,7 +549,7 @@ unsigned short get_udp_checksum(RawEthernetPacket * pkt, unsigned short udp_len) // memcpy(buf + 6, (pkt->data + ETH_HDR_LEN + GET_IP_HDR_LEN(pkt->data)), udp_len); memcpy(buf + 6, UDP_HDR(pkt->data), udp_len); if (udp_len % 2) { - JRLDBG("Odd udp_len: %hu\n", udp_len); + vtl_debug("Odd udp_len: %hu\n", udp_len); *(((char*)buf) + 2 * 6 + udp_len) = 0; }