diff --git a/src/common/sendpacket.c b/src/common/sendpacket.c index 66555d205..45b17a90c 100644 --- a/src/common/sendpacket.c +++ b/src/common/sendpacket.c @@ -831,7 +831,6 @@ sendpacket_open_tuntap(const char *device, char *errbuf) { sendpacket_t *sp; struct ifreq ifr; - int flags = 0; int tapfd; assert(device); diff --git a/src/tcpedit/plugins/dlt_en10mb/en10mb.c b/src/tcpedit/plugins/dlt_en10mb/en10mb.c index 274611dbc..18f5e1bbf 100644 --- a/src/tcpedit/plugins/dlt_en10mb/en10mb.c +++ b/src/tcpedit/plugins/dlt_en10mb/en10mb.c @@ -269,19 +269,14 @@ dlt_en10mb_parse_opts(tcpeditdlt_t *ctx) int dlt_en10mb_decode(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen) { - tcpeditdlt_plugin_t *plugin = NULL; struct tcpr_ethernet_hdr *eth = NULL; struct tcpr_802_1q_hdr *vlan = NULL; en10mb_extra_t *extra = NULL; - en10mb_config_t *config = NULL; assert(ctx); assert(packet); assert(pktlen >= 14); - plugin = tcpedit_dlt_getplugin(ctx, dlt_value); - config = plugin->config; - /* get our src & dst address */ eth = (struct tcpr_ethernet_hdr *)packet; memcpy(&(ctx->dstaddr.ethernet), eth, ETHER_ADDR_LEN); diff --git a/src/tcpedit/plugins/dlt_ieee80211/ieee80211.c b/src/tcpedit/plugins/dlt_ieee80211/ieee80211.c index a61bcbe8c..c5b0e81c3 100644 --- a/src/tcpedit/plugins/dlt_ieee80211/ieee80211.c +++ b/src/tcpedit/plugins/dlt_ieee80211/ieee80211.c @@ -101,7 +101,6 @@ int dlt_ieee80211_init(tcpeditdlt_t *ctx) { tcpeditdlt_plugin_t *plugin; - ieee80211_config_t *config; assert(ctx); if ((plugin = tcpedit_dlt_getplugin(ctx, dlt_value)) == NULL) { @@ -116,9 +115,7 @@ dlt_ieee80211_init(tcpeditdlt_t *ctx) /* allocate memory for our config data */ if (sizeof(ieee80211_config_t) > 0) plugin->config = safe_malloc(sizeof(ieee80211_config_t)); - - config = (ieee80211_config_t *)plugin->config; - + /* FIXME: set default config values here */ return TCPEDIT_OK; /* success */ diff --git a/src/tcpedit/plugins/dlt_jnpr_ether/jnpr_ether.c b/src/tcpedit/plugins/dlt_jnpr_ether/jnpr_ether.c index 291b7da3a..6ac922f78 100644 --- a/src/tcpedit/plugins/dlt_jnpr_ether/jnpr_ether.c +++ b/src/tcpedit/plugins/dlt_jnpr_ether/jnpr_ether.c @@ -109,7 +109,6 @@ int dlt_jnpr_ether_init(tcpeditdlt_t *ctx) { tcpeditdlt_plugin_t *plugin; - jnpr_ether_config_t *config; assert(ctx); if ((plugin = tcpedit_dlt_getplugin(ctx, dlt_value)) == NULL) { @@ -124,9 +123,7 @@ dlt_jnpr_ether_init(tcpeditdlt_t *ctx) /* allocate memory for our config data */ if (sizeof(jnpr_ether_config_t) > 0) plugin->config = safe_malloc(sizeof(jnpr_ether_config_t)); - - config = (jnpr_ether_config_t *)plugin->config; - + return TCPEDIT_OK; /* success */ } diff --git a/src/tcpedit/plugins/dlt_linuxsll/linuxsll.c b/src/tcpedit/plugins/dlt_linuxsll/linuxsll.c index 4cb2ecb93..8479d0278 100644 --- a/src/tcpedit/plugins/dlt_linuxsll/linuxsll.c +++ b/src/tcpedit/plugins/dlt_linuxsll/linuxsll.c @@ -96,7 +96,6 @@ int dlt_linuxsll_init(tcpeditdlt_t *ctx) { tcpeditdlt_plugin_t *plugin; - linuxsll_config_t *config; assert(ctx); if ((plugin = tcpedit_dlt_getplugin(ctx, dlt_value)) == NULL) { @@ -112,7 +111,6 @@ dlt_linuxsll_init(tcpeditdlt_t *ctx) if (sizeof(linuxsll_config_t) > 0) plugin->config = safe_malloc(sizeof(linuxsll_config_t)); - config = (linuxsll_config_t *)plugin->config; return TCPEDIT_OK; /* success */ } diff --git a/src/tcpedit/plugins/dlt_pppserial/pppserial.c b/src/tcpedit/plugins/dlt_pppserial/pppserial.c index 9be246453..e058152b5 100644 --- a/src/tcpedit/plugins/dlt_pppserial/pppserial.c +++ b/src/tcpedit/plugins/dlt_pppserial/pppserial.c @@ -108,7 +108,6 @@ int dlt_pppserial_init(tcpeditdlt_t *ctx) { tcpeditdlt_plugin_t *plugin; - pppserial_config_t *config; assert(ctx); if ((plugin = tcpedit_dlt_getplugin(ctx, dlt_value)) == NULL) { @@ -123,9 +122,7 @@ dlt_pppserial_init(tcpeditdlt_t *ctx) /* allocate memory for our config data */ if (sizeof(pppserial_config_t) > 0) plugin->config = safe_malloc(sizeof(pppserial_config_t)); - - config = (pppserial_config_t *)plugin->config; - + /* FIXME: set default config values here */ return TCPEDIT_OK; /* success */ @@ -214,7 +211,6 @@ dlt_pppserial_parse_opts(tcpeditdlt_t *ctx) int dlt_pppserial_decode(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen) { - tcpeditdlt_plugin_t *plugin = NULL; struct tcpr_pppserial_hdr *ppp = NULL; assert(ctx); @@ -227,7 +223,6 @@ dlt_pppserial_decode(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen) * protocol field informs you of the following header, but alas does not * use standard IEEE 802.11 values (IPv4 is not 0x0800, but is 0x0021) */ - plugin = tcpedit_dlt_getplugin(ctx, dlt_value); ppp = (struct tcpr_pppserial_hdr *)packet; switch (ntohs(ppp->protocol)) { case 0x0021: /* IPv4 */ @@ -273,7 +268,6 @@ dlt_pppserial_encode(tcpeditdlt_t *ctx, u_char *packet, int pktlen, _U_ tcpr_dir int dlt_pppserial_proto(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen) { - tcpeditdlt_plugin_t *plugin = NULL; struct tcpr_pppserial_hdr *ppp = NULL; int protocol = 0; @@ -281,7 +275,6 @@ dlt_pppserial_proto(tcpeditdlt_t *ctx, const u_char *packet, const int pktlen) assert(packet); assert(pktlen > 4); - plugin = tcpedit_dlt_getplugin(ctx, dlt_value); ppp = (struct tcpr_pppserial_hdr *)packet; switch (ntohs(ppp->protocol)) { case 0x0021: /* IPv4 */ diff --git a/src/tcpedit/plugins/dlt_radiotap/radiotap.c b/src/tcpedit/plugins/dlt_radiotap/radiotap.c index e0d2a10dc..c23a9e366 100644 --- a/src/tcpedit/plugins/dlt_radiotap/radiotap.c +++ b/src/tcpedit/plugins/dlt_radiotap/radiotap.c @@ -102,14 +102,13 @@ int dlt_radiotap_init(tcpeditdlt_t *ctx) { tcpeditdlt_plugin_t *plugin; - radiotap_config_t *config; assert(ctx); - + if ((plugin = tcpedit_dlt_getplugin(ctx, dlt_value)) == NULL) { tcpedit_seterr(ctx->tcpedit, "Unable to initalize unregistered plugin %s", dlt_name); return TCPEDIT_ERROR; } - + /* allocate memory for our deocde extra data */ if (sizeof(radiotap_extra_t) > 0) ctx->decoded_extra = safe_malloc(sizeof(radiotap_extra_t)); @@ -117,10 +116,7 @@ dlt_radiotap_init(tcpeditdlt_t *ctx) /* allocate memory for our config data */ if (sizeof(radiotap_config_t) > 0) plugin->config = safe_malloc(sizeof(radiotap_config_t)); - - config = (radiotap_config_t *)plugin->config; - return TCPEDIT_OK; /* success */ } diff --git a/src/tcpedit/plugins/dlt_raw/raw.c b/src/tcpedit/plugins/dlt_raw/raw.c index f9f4a7ed4..f3d8ae347 100644 --- a/src/tcpedit/plugins/dlt_raw/raw.c +++ b/src/tcpedit/plugins/dlt_raw/raw.c @@ -97,14 +97,13 @@ int dlt_raw_init(tcpeditdlt_t *ctx) { tcpeditdlt_plugin_t *plugin; - raw_config_t *config; assert(ctx); - + if ((plugin = tcpedit_dlt_getplugin(ctx, dlt_value)) == NULL) { tcpedit_seterr(ctx->tcpedit, "Unable to initalize unregistered plugin %s", dlt_name); return TCPEDIT_ERROR; } - + /* allocate memory for our deocde extra data */ if (sizeof(raw_extra_t) > 0) ctx->decoded_extra = safe_malloc(sizeof(raw_extra_t)); @@ -112,9 +111,7 @@ dlt_raw_init(tcpeditdlt_t *ctx) /* allocate memory for our config data */ if (sizeof(raw_config_t) > 0) plugin->config = safe_malloc(sizeof(raw_config_t)); - - config = (raw_config_t *)plugin->config; - + return TCPEDIT_OK; /* success */ } diff --git a/src/tcpprep.c b/src/tcpprep.c index c1f46b608..b727c93c1 100644 --- a/src/tcpprep.c +++ b/src/tcpprep.c @@ -72,7 +72,6 @@ void print_stats(const char *); static int check_ipv4_regex(const unsigned long ip); static int check_ipv6_regex(const struct tcpr_in6_addr *addr); static COUNTER process_raw_packets(pcap_t * pcap); -static int check_dst_port(ipv4_hdr_t *ip_hdr, ipv6_hdr_t *ip6_hdr, int len); /* @@ -201,79 +200,6 @@ main(int argc, char *argv[]) } - -/** - * checks the dst port to see if this is destined for a server port. - * returns 1 for true, 0 for false - */ -static int -check_dst_port(ipv4_hdr_t *ip_hdr, ipv6_hdr_t *ip6_hdr, int len) -{ - tcp_hdr_t *tcp_hdr = NULL; - udp_hdr_t *udp_hdr = NULL; - tcpprep_opt_t *options = tcpprep->options; - uint8_t proto; - u_char *l4; - - if (ip_hdr) { - if (len < ((ip_hdr->ip_hl * 4) + 4)) - return 0; /* not enough data in the packet to know */ - - proto = ip_hdr->ip_p; - l4 = get_layer4_v4(ip_hdr, len); - } else if (ip6_hdr) { - if (len < (TCPR_IPV6_H + 4)) - return 0; /* not enough data in the packet to know */ - - proto = get_ipv6_l4proto(ip6_hdr, len); - dbgx(3, "Our layer4 proto is 0x%hhu", proto); - if ((l4 = get_layer4_v6(ip6_hdr, len)) == NULL) - return 0; - - dbgx(3, "Found proto %u at offset %p. base %p (%p)", proto, (void *)l4, (void *)ip6_hdr, (void*)(l4 - (u_char *)ip6_hdr)); - } else { - assert(0); - } - - dbg(3, "Checking the destination port..."); - - switch(proto) { - case IPPROTO_TCP: - tcp_hdr = (tcp_hdr_t *)l4; - - /* is a service? */ - if (options->services.tcp[ntohs(tcp_hdr->th_dport)]) { - dbgx(1, "TCP packet is destined for a server port: %d", ntohs(tcp_hdr->th_dport)); - return 1; - } - - /* nope */ - dbgx(1, "TCP packet is NOT destined for a server port: %d", ntohs(tcp_hdr->th_dport)); - return 0; - break; - - case IPPROTO_UDP: - udp_hdr = (udp_hdr_t *)l4; - - /* is a service? */ - if (options->services.udp[ntohs(udp_hdr->uh_dport)]) { - dbgx(1, "UDP packet is destined for a server port: %d", ntohs(udp_hdr->uh_dport)); - return 1; - } - - /* nope */ - dbgx(1, "UDP packet is NOT destined for a server port: %d", ntohs(udp_hdr->uh_dport)); - return 0; - break; - - default: - /* not a TCP or UDP packet... return as non_ip */ - dbg(1, "Packet isn't a UDP or TCP packet... no port to process."); - return options->nonip; - } -} - - /** * checks to see if an ip address matches a regex. Returns 1 for true * 0 for false @@ -329,7 +255,6 @@ process_raw_packets(pcap_t * pcap) struct pcap_pkthdr pkthdr; const u_char *pktdata = NULL; COUNTER packetnum = 0; - int l2len, cache_result = 0; u_char ipbuff[MAXPACKET], *buffptr; tcpr_dir_t direction = TCPR_DIR_ERROR; tcpprep_opt_t *options = tcpprep->options; @@ -395,8 +320,6 @@ process_raw_packets(pcap_t * pcap) /* go to next packet */ continue; } - - l2len = get_l2len(pktdata, pkthdr.caplen, pcap_datalink(pcap)); /* look for include or exclude CIDR match */ if (options->xX.cidr != NULL) { @@ -427,7 +350,6 @@ process_raw_packets(pcap_t * pcap) if (HAVE_OPT(REVERSE) && (direction == TCPR_DIR_C2S || direction == TCPR_DIR_S2C)) direction = direction == TCPR_DIR_C2S ? TCPR_DIR_S2C : TCPR_DIR_C2S; - cache_result = add_cache(&options->cachedata, SEND, direction); break; case CIDR_MODE: @@ -442,7 +364,6 @@ process_raw_packets(pcap_t * pcap) if (HAVE_OPT(REVERSE) && (direction == TCPR_DIR_C2S || direction == TCPR_DIR_S2C)) direction = direction == TCPR_DIR_C2S ? TCPR_DIR_S2C : TCPR_DIR_C2S; - cache_result = add_cache(&options->cachedata, SEND, direction); break; case MAC_MODE: @@ -453,7 +374,6 @@ process_raw_packets(pcap_t * pcap) if (HAVE_OPT(REVERSE) && (direction == TCPR_DIR_C2S || direction == TCPR_DIR_S2C)) direction = direction == TCPR_DIR_C2S ? TCPR_DIR_S2C : TCPR_DIR_C2S; - cache_result = add_cache(&options->cachedata, SEND, direction); break; case AUTO_MODE: @@ -480,13 +400,6 @@ process_raw_packets(pcap_t * pcap) * based cache */ dbg(2, "processing second pass of auto: router mode..."); - if (ip_hdr) { - cache_result = add_cache(&options->cachedata, SEND, - check_ip_tree(options->nonip, ip_hdr->ip_src.s_addr)); - } else { - cache_result = add_cache(&options->cachedata, SEND, - check_ip6_tree(options->nonip, &ip6_hdr->ip_src)); - } break; case BRIDGE_MODE: @@ -495,13 +408,6 @@ process_raw_packets(pcap_t * pcap) * based cache */ dbg(2, "processing second pass of auto: bridge mode..."); - if (ip_hdr) { - cache_result = add_cache(&options->cachedata, SEND, - check_ip_tree(DIR_UNKNOWN, ip_hdr->ip_src.s_addr)); - } else { - cache_result = add_cache(&options->cachedata, SEND, - check_ip6_tree(DIR_UNKNOWN, &ip6_hdr->ip_src)); - } break; case SERVER_MODE: @@ -510,13 +416,6 @@ process_raw_packets(pcap_t * pcap) * where unknowns are servers */ dbg(2, "processing second pass of auto: server mode..."); - if (ip_hdr) { - cache_result = add_cache(&options->cachedata, SEND, - check_ip_tree(DIR_SERVER, ip_hdr->ip_src.s_addr)); - } else { - cache_result = add_cache(&options->cachedata, SEND, - check_ip6_tree(DIR_SERVER, &ip6_hdr->ip_src)); - } break; case CLIENT_MODE: @@ -525,13 +424,6 @@ process_raw_packets(pcap_t * pcap) * where unknowns are clients */ dbg(2, "processing second pass of auto: client mode..."); - if (ip_hdr) { - cache_result = add_cache(&options->cachedata, SEND, - check_ip_tree(DIR_CLIENT, ip_hdr->ip_src.s_addr)); - } else { - cache_result = add_cache(&options->cachedata, SEND, - check_ip6_tree(DIR_CLIENT, &ip6_hdr->ip_src)); - } break; case PORT_MODE: @@ -539,8 +431,6 @@ process_raw_packets(pcap_t * pcap) * process ports based on their destination port */ dbg(2, "processing port mode..."); - cache_result = add_cache(&options->cachedata, SEND, - check_dst_port(ip_hdr, ip6_hdr, (pkthdr.caplen - l2len))); break; case FIRST_MODE: @@ -549,13 +439,6 @@ process_raw_packets(pcap_t * pcap) * by the ones which send the first packet in a session */ dbg(2, "processing second pass of auto: first packet mode..."); - if (ip_hdr) { - cache_result = add_cache(&options->cachedata, SEND, - check_ip_tree(DIR_UNKNOWN, ip_hdr->ip_src.s_addr)); - } else { - cache_result = add_cache(&options->cachedata, SEND, - check_ip6_tree(DIR_UNKNOWN, &ip6_hdr->ip_src)); - } break; default: diff --git a/src/tree.c b/src/tree.c index 7f7cad167..d0cb69b57 100644 --- a/src/tree.c +++ b/src/tree.c @@ -370,7 +370,6 @@ void add_tree_first_ipv4(const u_char *data) { tcpr_tree_t *newnode = NULL, *findnode; - eth_hdr_t *eth_hdr = NULL; ipv4_hdr_t ip_hdr; assert(data); @@ -379,7 +378,6 @@ add_tree_first_ipv4(const u_char *data) */ newnode = new_tree(); - eth_hdr = (eth_hdr_t *) (data); /* prevent issues with byte alignment, must memcpy */ memcpy(&ip_hdr, (data + TCPR_ETH_H), TCPR_IPV4_H); @@ -401,7 +399,6 @@ add_tree_first_ipv4(const u_char *data) * now add/find the destination IP/server */ newnode = new_tree(); - eth_hdr = (eth_hdr_t *) (data); memcpy(&ip_hdr, (data + TCPR_ETH_H), TCPR_IPV4_H); newnode->family = AF_INET; @@ -421,7 +418,6 @@ void add_tree_first_ipv6(const u_char *data) { tcpr_tree_t *newnode = NULL, *findnode; - eth_hdr_t *eth_hdr = NULL; ipv6_hdr_t ip6_hdr; assert(data); @@ -430,7 +426,6 @@ add_tree_first_ipv6(const u_char *data) */ newnode = new_tree(); - eth_hdr = (eth_hdr_t *) (data); /* prevent issues with byte alignment, must memcpy */ memcpy(&ip6_hdr, (data + TCPR_ETH_H), TCPR_IPV6_H); @@ -452,7 +447,6 @@ add_tree_first_ipv6(const u_char *data) * now add/find the destination IP/server */ newnode = new_tree(); - eth_hdr = (eth_hdr_t *) (data); memcpy(&ip6_hdr, (data + TCPR_ETH_H), TCPR_IPV6_H); newnode->family = AF_INET6;