Since the ofilter variable is global now, we don't need to pass it
to every other function, just use it in places where it's needed.
This makes the iptraf-ng code about 400B smaller.
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/detstats.c | 4 +---
src/detstats.h | 4 +---
src/fltselect.c | 11 +++++------
src/fltselect.h | 2 +-
src/hostmon.c | 4 +---
src/hostmon.h | 4 +---
src/ifstats.c | 4 +---
src/ifstats.h | 4 +---
src/ipfilter.c | 23 +++++++++++------------
src/ipfilter.h | 7 ++-----
src/iptraf.c | 30 ++++++++++++++----------------
src/itrafmon.c | 5 ++---
src/itrafmon.h | 4 +---
src/packet.c | 8 ++++----
src/packet.h | 4 +---
src/pktsize.c | 6 ++----
src/pktsize.h | 5 +----
src/serv.c | 4 +---
src/serv.h | 5 +----
19 files changed, 52 insertions(+), 86 deletions(-)
diff --git a/src/detstats.c b/src/detstats.c
index efe7d1c..6fbee28 100644
--- a/src/detstats.c
+++ b/src/detstats.c
@@ -14,7 +14,6 @@ detstats.c - the interface statistics module
#include "counters.h"
#include "ifaces.h"
#include "fltdefs.h"
-#include "fltselect.h"
#include "packet.h"
#include "options.h"
#include "log.h"
@@ -251,7 +250,7 @@ static void printdetails(struct ifcounts *ifcounts, WINDOW * win)
/*
* The detailed interface statistics function
*/
-void detstats(char *iface, time_t facilitytime, struct filterstate *ofilter)
+void detstats(char *iface, time_t facilitytime)
{
int logging = options.logging;
@@ -530,7 +529,6 @@ void detstats(char *iface, time_t facilitytime, struct filterstate
*ofilter)
pkt_result =
packet_process(&pkt, NULL, NULL, NULL,
- ofilter,
MATCH_OPPOSITE_USECONFIG,
options.v6inv4asv6);
diff --git a/src/detstats.h b/src/detstats.h
index c237a4c..95cbea8 100644
--- a/src/detstats.h
+++ b/src/detstats.h
@@ -1,8 +1,6 @@
#ifndef IPTRAF_NG_DETSTATS_H
#define IPTRAF_NG_DETSTATS_H
-#include "fltselect.h"
-
-void detstats(char *iface, time_t facilitytime, struct filterstate *ofilter);
+void detstats(char *iface, time_t facilitytime);
#endif /* IPTRAF_NG_DETSTATS_H */
diff --git a/src/fltselect.c b/src/fltselect.c
index be2660f..698c5bd 100644
--- a/src/fltselect.c
+++ b/src/fltselect.c
@@ -48,8 +48,7 @@ void setfilters(unsigned int row)
switch (row) {
case 1:
- ipfilterselect(&ofilter.fl, ofilter.filename,
- &ofilter.filtercode, &aborted);
+ ipfilterselect(&aborted);
break;
case 2:
ofilter.arp = ~ofilter.arp;
@@ -100,19 +99,19 @@ void toggleprotodisplay(WINDOW *win, unsigned int row)
/*
* Filter for non-IP packets
*/
-int nonipfilter(struct filterstate *filter, unsigned int protocol)
+int nonipfilter(unsigned int protocol)
{
int result = 0;
switch (protocol) {
case ETH_P_ARP:
- result = filter->arp;
+ result = ofilter.arp;
break;
case ETH_P_RARP:
- result = filter->rarp;
+ result = ofilter.rarp;
break;
default:
- result = filter->nonip;
+ result = ofilter.nonip;
break;
}
diff --git a/src/fltselect.h b/src/fltselect.h
index 656aaf1..a33ee68 100644
--- a/src/fltselect.h
+++ b/src/fltselect.h
@@ -22,6 +22,6 @@ extern struct filterstate ofilter;
void config_filters(void);
void loadfilters(void);
void savefilters(void);
-int nonipfilter(struct filterstate *filter, unsigned int protocol);
+int nonipfilter(unsigned int protocol);
#endif /* IPTRAF_NG_FLTSELECT_H */
diff --git a/src/hostmon.c b/src/hostmon.c
index 341a4a2..5ba7f3c 100644
--- a/src/hostmon.c
+++ b/src/hostmon.c
@@ -16,7 +16,6 @@ Discovers LAN hosts and displays packet statistics for them
#include "dirs.h"
#include "deskman.h"
#include "fltdefs.h"
-#include "fltselect.h"
#include "packet.h"
#include "ifaces.h"
#include "hostmon.h"
@@ -744,7 +743,7 @@ static void sort_hosttab(struct ethtab *list, unsigned int *idx, int
command)
* The LAN station monitor
*/
-void hostmon(time_t facilitytime, char *ifptr, struct filterstate *ofilter)
+void hostmon(time_t facilitytime, char *ifptr)
{
int logging = options.logging;
struct ethtab table;
@@ -953,7 +952,6 @@ void hostmon(time_t facilitytime, char *ifptr, struct filterstate
*ofilter)
pkt_result =
packet_process(&pkt, NULL, NULL, NULL,
- ofilter,
MATCH_OPPOSITE_USECONFIG,
0);
diff --git a/src/hostmon.h b/src/hostmon.h
index ab56101..6b23b54 100644
--- a/src/hostmon.h
+++ b/src/hostmon.h
@@ -1,9 +1,7 @@
#ifndef IPTRAF_NG_HOSTMON_H
#define IPTRAF_NG_HOSTMON_H
-#include "fltselect.h"
-
void convmacaddr(char *addr, char *result);
-void hostmon(time_t facilitytime, char *ifptr, struct filterstate *ofilter);
+void hostmon(time_t facilitytime, char *ifptr);
#endif /* IPTRAF_NG_HOSTMON_H */
diff --git a/src/ifstats.c b/src/ifstats.c
index 35a5e18..fa64619 100644
--- a/src/ifstats.c
+++ b/src/ifstats.c
@@ -16,7 +16,6 @@ ifstats.c - the interface statistics module
#include "ifaces.h"
#include "fltdefs.h"
-#include "fltselect.h"
#include "packet.h"
#include "options.h"
#include "log.h"
@@ -427,7 +426,7 @@ static void pagegstatwin(struct iftab *table, int direction, unsigned
int *idx)
* The general interface statistics function
*/
-void ifstats(struct filterstate *ofilter, time_t facilitytime)
+void ifstats(time_t facilitytime)
{
int logging = options.logging;
struct iftab table;
@@ -602,7 +601,6 @@ void ifstats(struct filterstate *ofilter, time_t facilitytime)
continue;
pkt_result = packet_process(&pkt, NULL, NULL, NULL,
- ofilter,
MATCH_OPPOSITE_USECONFIG,
options.v6inv4asv6);
diff --git a/src/ifstats.h b/src/ifstats.h
index 8797fe1..5cf8b15 100644
--- a/src/ifstats.h
+++ b/src/ifstats.h
@@ -1,9 +1,7 @@
#ifndef IPTRAF_NG_IFSTATS_H
#define IPTRAF_NG_IFSTATS_H
-#include "fltselect.h"
-
void selectiface(char *ifname, int withall, int *aborted);
-void ifstats(struct filterstate *ofilter, time_t facilitytime);
+void ifstats(time_t facilitytime);
#endif /* IPTRAF_NG_IFSTATS_H */
diff --git a/src/ipfilter.c b/src/ipfilter.c
index aa03b3e..bec2dfd 100644
--- a/src/ipfilter.c
+++ b/src/ipfilter.c
@@ -19,6 +19,7 @@ ipfilter.c - user interface and filter function for all IP packets
#include "attrs.h"
#include "fltdefs.h"
#include "fltmgr.h"
+#include "fltselect.h"
#include "ipfilter.h"
#include "fltedit.h"
#include "getpath.h"
@@ -313,8 +314,7 @@ void gethostparams(struct hostparams *data, char *init_saddr, char
*init_smask,
doupdate();
}
-void ipfilterselect(struct filterlist *fl, char *filename, int *fltcode,
- int *aborted)
+void ipfilterselect(int *aborted)
{
struct MENU menu;
int row = 1;
@@ -331,19 +331,19 @@ void ipfilterselect(struct filterlist *fl, char *filename, int
*fltcode,
case 2:
selectfilter(&fflist, aborted);
if (!(*aborted)) {
- memset(filename, 0, FLT_FILENAME_MAX);
- strncpy(filename,
+ memset(ofilter.filename, 0, FLT_FILENAME_MAX);
+ strncpy(ofilter.filename,
get_path(T_WORKDIR, fflist.filename),
FLT_FILENAME_MAX - 1);
- if (!loadfilter(filename, fl, FLT_RESOLVE))
- *fltcode = 1;
+ if (!loadfilter(ofilter.filename, &ofilter.fl, FLT_RESOLVE))
+ ofilter.filtercode = 1;
else
- *fltcode = 0;
+ ofilter.filtercode = 0;
}
break;
case 3:
- destroyfilter(fl);
- *fltcode = 0;
+ destroyfilter(&ofilter.fl);
+ ofilter.filtercode = 0;
tx_infobox("IP filter deactivated", ANYKEY_MSG);
break;
case 4:
@@ -364,10 +364,9 @@ void ipfilterselect(struct filterlist *fl, char *filename, int
*fltcode,
* Display/logging filter for other (non-TCP, non-UDP) IP protocols.
*/
int ipfilter(unsigned long saddr, unsigned long daddr, unsigned int sport,
- unsigned int dport, unsigned int protocol, int match_opp_mode,
- struct filterlist *fl)
+ unsigned int dport, unsigned int protocol, int match_opp_mode)
{
- struct filterent *fe = fl->head;
+ struct filterent *fe = ofilter.fl.head;
int result = 0;
int fltexpr1;
int fltexpr2;
diff --git a/src/ipfilter.h b/src/ipfilter.h
index b1b8195..753acd7 100644
--- a/src/ipfilter.h
+++ b/src/ipfilter.h
@@ -5,11 +5,8 @@ void gethostparams(struct hostparams *data, char *init_saddr, char
*init_smask,
char *init_sport1, char *init_sport2, char *init_daddr,
char *init_dmask, char *init_dport1, char *init_dport2,
char *initinex, char *initmatchop, int *aborted);
-
-void ipfilterselect(struct filterlist *fl, char *filename, int *fltcode,
- int *faborted);
+void ipfilterselect(int *faborted);
int ipfilter(unsigned long saddr, unsigned long daddr, unsigned int sport,
- unsigned int dport, unsigned int protocol, int match_opp_mode,
- struct filterlist *fl);
+ unsigned int dport, unsigned int protocol, int match_opp_mode);
#endif /* IPTRAF_NG_IPFILTER_H */
diff --git a/src/iptraf.c b/src/iptraf.c
index 5f6becd..65e9f2c 100644
--- a/src/iptraf.c
+++ b/src/iptraf.c
@@ -183,16 +183,16 @@ static void program_interface(void)
else
ifptr = NULL;
- ipmon(&ofilter, 0, ifptr);
+ ipmon(0, ifptr);
}
break;
case 2:
- ifstats(&ofilter, 0);
+ ifstats(0);
break;
case 3:
selectiface(ifname, WITHOUTALL, &aborted);
if (!aborted)
- detstats(ifname, 0, &ofilter);
+ detstats(ifname, 0);
break;
case 4:
break_row = 1;
@@ -204,14 +204,12 @@ static void program_interface(void)
case 1:
selectiface(ifname, WITHOUTALL, &aborted);
if (!aborted)
- packet_size_breakdown(ifname,
- 0, &ofilter);
+ packet_size_breakdown(ifname, 0);
break;
case 2:
selectiface(ifname, WITHOUTALL, &aborted);
if (!aborted)
- servmon(ifname, 0,
- &ofilter);
+ servmon(ifname, 0);
break;
case 4:
break;
@@ -225,7 +223,7 @@ static void program_interface(void)
ifptr = ifname;
else
ifptr = NULL;
- hostmon(0, ifptr, &ofilter);
+ hostmon(0, ifptr);
}
break;
case 7:
@@ -510,23 +508,23 @@ int main(int argc, char **argv)
/* simplify */
if (g_opt)
- ifstats(&ofilter, facilitytime);
+ ifstats(facilitytime);
else if (i_opt)
if (strcmp(i_opt, "all") == 0)
- ipmon(&ofilter, facilitytime, NULL);
+ ipmon(facilitytime, NULL);
else
- ipmon(&ofilter, facilitytime, i_opt);
+ ipmon(facilitytime, i_opt);
else if (l_opt)
if (strcmp(l_opt, "all") == 0)
- hostmon(facilitytime, NULL, &ofilter);
+ hostmon(facilitytime, NULL);
else
- hostmon(facilitytime, l_opt, &ofilter);
+ hostmon(facilitytime, l_opt);
else if (d_opt)
- detstats(d_opt, facilitytime, &ofilter);
+ detstats(d_opt, facilitytime);
else if (s_opt)
- servmon(s_opt, facilitytime, &ofilter);
+ servmon(s_opt, facilitytime);
else if (z_opt)
- packet_size_breakdown(z_opt, facilitytime, &ofilter);
+ packet_size_breakdown(z_opt, facilitytime);
else
program_interface();
diff --git a/src/itrafmon.c b/src/itrafmon.c
index d902407..55cb52c 100644
--- a/src/itrafmon.c
+++ b/src/itrafmon.c
@@ -16,7 +16,6 @@ itrafmon.c - the IP traffic monitor module
#include "tcptable.h"
#include "othptab.h"
#include "fltdefs.h"
-#include "fltselect.h"
#include "packet.h"
#include "ifaces.h"
#include "promisc.h"
@@ -545,7 +544,7 @@ static void print_flowrate(struct tcptableent *entry, WINDOW *win)
* The IP Traffic Monitor
*/
-void ipmon(struct filterstate *ofilter, time_t facilitytime, char *ifptr)
+void ipmon(time_t facilitytime, char *ifptr)
{
int logging = options.logging;
@@ -989,7 +988,7 @@ void ipmon(struct filterstate *ofilter, time_t facilitytime, char
*ifptr)
pkt_result =
packet_process(&pkt, &br, &sport, &dport,
- ofilter, MATCH_OPPOSITE_ALWAYS,
+ MATCH_OPPOSITE_ALWAYS,
options.v6inv4asv6);
if (pkt_result != PACKET_OK)
diff --git a/src/itrafmon.h b/src/itrafmon.h
index fe9bad4..2a62431 100644
--- a/src/itrafmon.h
+++ b/src/itrafmon.h
@@ -1,8 +1,6 @@
#ifndef IPTRAF_NG_ITRAFMON_H
#define IPTRAF_NG_ITRAFMON_H
-#include "fltselect.h"
-
-void ipmon(struct filterstate *ofilter, time_t facilitytime, char *ifptr);
+void ipmon(time_t facilitytime, char *ifptr);
#endif /* IPTRAF_NG_ITRAFMON_H */
diff --git a/src/packet.c b/src/packet.c
index ef76925..c831848 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -178,7 +178,7 @@ int packet_get(int fd, struct pkt_hdr *pkt, int *ch, WINDOW *win)
int packet_process(struct pkt_hdr *pkt, unsigned int *total_br,
unsigned int *sport, unsigned int *dport,
- struct filterstate *filter, int match_opposite,
+ int match_opposite,
int v6inv4asv6)
{
/* move packet pointer (pkt->pkt_payload) past data link header */
@@ -269,11 +269,11 @@ again:
f_sport = ntohs(sport_tmp);
f_dport = ntohs(dport_tmp);
}
- if ((filter->filtercode != 0)
+ if ((ofilter.filtercode != 0)
&&
(!ipfilter
(ip->saddr, ip->daddr, f_sport, f_dport, ip->protocol,
- match_opposite, &(filter->fl))))
+ match_opposite)))
return PACKET_FILTERED;
if (v6inv4asv6 && (ip->protocol == IPPROTO_IPV6)) {
pkt->pkt_protocol = ETH_P_IPV6;
@@ -325,7 +325,7 @@ again:
goto again;
default:
/* not IPv4 and not IPv6: apply non-IP packet filter */
- if (!nonipfilter(filter, pkt->pkt_protocol)) {
+ if (!nonipfilter(pkt->pkt_protocol)) {
return PACKET_FILTERED;
}
}
diff --git a/src/packet.h b/src/packet.h
index 4979a5d..8fc656d 100644
--- a/src/packet.h
+++ b/src/packet.h
@@ -7,8 +7,6 @@ packet.h - external declarations for packet.c
***/
-#include "fltselect.h"
-
/*
* Number of bytes from captured packet to move into a buffer.
* 96 bytes should be enough for the IP header, TCP/UDP/ICMP/whatever header
@@ -82,7 +80,7 @@ void open_socket(int *fd);
int packet_get(int fd, struct pkt_hdr *pkt, int *ch, WINDOW *win);
int packet_process(struct pkt_hdr *pkt, unsigned int *total_br,
unsigned int *sport, unsigned int *dport,
- struct filterstate *filter, int match_opposite,
+ int match_opposite,
int v6inv4asv6);
void pkt_cleanup(void);
diff --git a/src/pktsize.c b/src/pktsize.c
index ff5604d..296b8fa 100644
--- a/src/pktsize.c
+++ b/src/pktsize.c
@@ -14,7 +14,6 @@ pktsize.c - the packet size breakdown facility
#include "attrs.h"
#include "dirs.h"
#include "fltdefs.h"
-#include "fltselect.h"
#include "ifaces.h"
#include "packet.h"
#include "deskman.h"
@@ -138,8 +137,7 @@ static void update_size_distrib(unsigned int length,
wprintw(win, "%8lu", brackets[i].count);
}
-void packet_size_breakdown(char *ifname, time_t facilitytime,
- struct filterstate *ofilter)
+void packet_size_breakdown(char *ifname, time_t facilitytime)
{
WINDOW *win;
PANEL *panel;
@@ -324,7 +322,7 @@ void packet_size_breakdown(char *ifname, time_t facilitytime,
continue;
pkt_result = packet_process(&pkt, NULL, NULL, NULL,
- ofilter, MATCH_OPPOSITE_USECONFIG, 0);
+ MATCH_OPPOSITE_USECONFIG, 0);
if (pkt_result != PACKET_OK)
continue;
diff --git a/src/pktsize.h b/src/pktsize.h
index 0642bd0..ad0fc9d 100644
--- a/src/pktsize.h
+++ b/src/pktsize.h
@@ -1,9 +1,6 @@
#ifndef IPTRAF_NG_PKTSIZE_H
#define IPTRAF_NG_PKTSIZE_H
-#include "fltselect.h"
-
-void packet_size_breakdown(char *iface, time_t facilitytime,
- struct filterstate *ofilter);
+void packet_size_breakdown(char *iface, time_t facilitytime);
#endif /* IPTRAF_NG_PKTSIZE_H */
diff --git a/src/serv.c b/src/serv.c
index 1491ae5..1fbf877 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -17,7 +17,6 @@ serv.c - TCP/UDP port statistics module
#include "dirs.h"
#include "deskman.h"
#include "fltdefs.h"
-#include "fltselect.h"
#include "packet.h"
#include "ipfrag.h"
#include "ifaces.h"
@@ -753,7 +752,7 @@ static void update_serv_rates(struct portlist *list, unsigned long
msecs)
* The TCP/UDP service monitor
*/
-void servmon(char *ifname, time_t facilitytime, struct filterstate *ofilter)
+void servmon(char *ifname, time_t facilitytime)
{
int logging = options.logging;
int pkt_result;
@@ -1046,7 +1045,6 @@ void servmon(char *ifname, time_t facilitytime, struct filterstate
*ofilter)
pkt_result =
packet_process(&pkt, &tot_br, &sport, &dport,
- ofilter,
MATCH_OPPOSITE_USECONFIG,
options.v6inv4asv6);
diff --git a/src/serv.h b/src/serv.h
index 51b8d3c..d5c9c76 100644
--- a/src/serv.h
+++ b/src/serv.h
@@ -18,9 +18,6 @@ void addmoreports(struct porttab **table);
void loadaddports(struct porttab **table);
void destroyporttab(struct porttab *table);
void removeaport(struct porttab **table);
-
-#include "fltselect.h"
-
-void servmon(char *iface, time_t facilitytime, struct filterstate *ofilter);
+void servmon(char *iface, time_t facilitytime);
#endif /* IPTRAF_NG_SERV_H */
--
1.7.8.4