Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
fklassen committed Nov 22, 2015
1 parent 855ecf3 commit d0a7ca2
Show file tree
Hide file tree
Showing 10 changed files with 8 additions and 159 deletions.
1 change: 0 additions & 1 deletion src/common/sendpacket.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 0 additions & 5 deletions src/tcpedit/plugins/dlt_en10mb/en10mb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 1 addition & 4 deletions src/tcpedit/plugins/dlt_ieee80211/ieee80211.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 */
Expand Down
5 changes: 1 addition & 4 deletions src/tcpedit/plugins/dlt_jnpr_ether/jnpr_ether.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 */
}

Expand Down
2 changes: 0 additions & 2 deletions src/tcpedit/plugins/dlt_linuxsll/linuxsll.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 */
}
Expand Down
9 changes: 1 addition & 8 deletions src/tcpedit/plugins/dlt_pppserial/pppserial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 */
Expand Down Expand Up @@ -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);
Expand All @@ -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 */
Expand Down Expand Up @@ -273,15 +268,13 @@ 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;

assert(ctx);
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 */
Expand Down
8 changes: 2 additions & 6 deletions src/tcpedit/plugins/dlt_radiotap/radiotap.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,21 @@ 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));

/* 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 */
}

Expand Down
9 changes: 3 additions & 6 deletions src/tcpedit/plugins/dlt_raw/raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,21 @@ 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));

/* 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 */
}

Expand Down
117 changes: 0 additions & 117 deletions src/tcpprep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);


/*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -525,22 +424,13 @@ 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:
/*
* 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:
Expand All @@ -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:
Expand Down
Loading

0 comments on commit d0a7ca2

Please sign in to comment.