[PATCH] move v6inv4asv6 check into the processpacket()
by Vitezslav Samel
This makes the code more readable.
Signed-off-by: Vitezslav Samel <vitezslav(a)samel.cz>
---
src/hostmon.c | 2 +-
src/ifstats.c | 43 ++-----------------------------------------
src/itrafmon.c | 25 +------------------------
src/packet.c | 10 ++++++++--
src/packet.h | 2 +-
src/pktsize.c | 2 +-
src/serv.c | 2 +-
7 files changed, 15 insertions(+), 71 deletions(-)
diff --git a/src/hostmon.c b/src/hostmon.c
index aafe34d..a9aed5e 100644
--- a/src/hostmon.c
+++ b/src/hostmon.c
@@ -866,7 +866,7 @@ void hostmon(const struct OPTIONS *options, int facilitytime, char *ifptr,
NULL, NULL, NULL, &fromaddr,
&linktype, ofilter,
MATCH_OPPOSITE_USECONFIG, ifname,
- ifptr);
+ ifptr, 0);
if (pkt_result != PACKET_OK)
continue;
diff --git a/src/ifstats.c b/src/ifstats.c
index 18ca3dd..8a3260e 100644
--- a/src/ifstats.c
+++ b/src/ifstats.c
@@ -555,30 +555,12 @@ void ifstats(const struct OPTIONS *options, struct filterstate *ofilter,
NULL, NULL, NULL, &fromaddr,
&linktype, ofilter,
MATCH_OPPOSITE_USECONFIG,
- ifname, NULL);
+ ifname, NULL, options->v6inv4asv6);
if (pkt_result != PACKET_OK
&& pkt_result != MORE_FRAGMENTS)
continue;
- if ((options->v6inv4asv6)
- && (fromaddr.sll_protocol == ETH_P_IP)
- && ((struct iphdr *) packet)->protocol == IPPROTO_IPV6) {
- iphlen = ((struct iphdr *) packet)->ihl * 4;
- fromaddr.sll_protocol = htons(ETH_P_IPV6);
- memmove(buf, buf + iphlen, MAX_PACKET_SIZE - iphlen);
- // Reprocess the IPv6 packet
- pkt_result = processpacket(buf, &packet,
- (unsigned int *) &br,
- NULL, NULL, NULL, &fromaddr,
- &linktype, ofilter,
- MATCH_OPPOSITE_USECONFIG,
- ifname, NULL);
-
- if (pkt_result != PACKET_OK
- && pkt_result != MORE_FRAGMENTS)
- continue;
- }
positionptr(&table, &ptmp, ifname);
ptmp->total++;
@@ -1015,33 +997,12 @@ void detstats(char *iface, const struct OPTIONS *options, int facilitytime,
NULL, NULL, NULL, &fromaddr,
&linktype, ofilter,
MATCH_OPPOSITE_USECONFIG, ifname,
- iface);
+ iface, options->v6inv4asv6);
if (pkt_result != PACKET_OK
&& pkt_result != MORE_FRAGMENTS)
continue;
- if ((options->v6inv4asv6)
- && (fromaddr.sll_protocol == ETH_P_IP)
- && ((struct iphdr *) packet)->protocol ==
- IPPROTO_IPV6) {
- iphlen = ((struct iphdr *) packet)->ihl * 4;
- fromaddr.sll_protocol = htons(ETH_P_IPV6);
- memmove(buf, buf + iphlen,
- MAX_PACKET_SIZE - iphlen);
- // Reprocess the IPv6 packet
- pkt_result =
- processpacket(buf, &packet,
- (unsigned int *) &br, NULL,
- NULL, NULL, &fromaddr,
- &linktype, ofilter,
- MATCH_OPPOSITE_USECONFIG,
- ifname, NULL);
- if (pkt_result != PACKET_OK
- && pkt_result != MORE_FRAGMENTS)
- continue;
- }
-
totals.total++;
totals.bytestotal += framelen;
diff --git a/src/itrafmon.c b/src/itrafmon.c
index 75925aa..7f7c798 100644
--- a/src/itrafmon.c
+++ b/src/itrafmon.c
@@ -1148,7 +1148,7 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
(unsigned int *) &readlen, &br,
&sport, &dport, &fromaddr, &linktype,
ofilter, MATCH_OPPOSITE_ALWAYS,
- ifname, ifptr);
+ ifname, ifptr, options->v6inv4asv6);
if (pkt_result != PACKET_OK)
continue;
@@ -1164,29 +1164,6 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
options->servnames, 0, &nomem);
continue;
} else {
- if ((options->v6inv4asv6)
- && (fromaddr.sll_protocol == ETH_P_IP)
- && ((struct iphdr *) packet)->protocol ==
- IPPROTO_IPV6) {
- iphlen =
- ((struct iphdr *) packet)->ihl * 4;
- fromaddr.sll_protocol =
- htons(ETH_P_IPV6);
- memmove(tpacket, tpacket + iphlen,
- MAX_PACKET_SIZE - iphlen);
- // Reprocess the ipv6 packet
- pkt_result =
- processpacket((char *) tpacket,
- &packet,
- (unsigned int *)
- &readlen, &br, &sport,
- &dport, &fromaddr,
- &linktype, ofilter,
- MATCH_OPPOSITE_ALWAYS,
- ifname, ifptr);
- if (pkt_result != PACKET_OK)
- continue;
- }
if (fromaddr.sll_protocol == ETH_P_IP) {
ippacket = (struct iphdr *) packet;
iphlen = ippacket->ihl * 4;
diff --git a/src/packet.c b/src/packet.c
index 27677e9..ccbff89 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -153,7 +153,7 @@ int processpacket(char *tpacket, char **packet, unsigned int *br,
unsigned int *total_br, unsigned int *sport,
unsigned int *dport, struct sockaddr_ll *fromaddr,
unsigned short *linktype, struct filterstate *filter,
- int match_opposite, char *ifname, char *ifptr)
+ int match_opposite, char *ifname, char *ifptr, int v6inv4asv6)
{
/*
* Does returned interface (ifname) match the specified interface name
@@ -180,7 +180,7 @@ int processpacket(char *tpacket, char **packet, unsigned int *br,
if (*packet == NULL)
return INVALID_PACKET;
- if (fromaddr->sll_protocol == ETH_P_IP) {
+again: if (fromaddr->sll_protocol == ETH_P_IP) {
struct iphdr *ip;
int hdr_check;
register int ip_checksum;
@@ -275,6 +275,12 @@ int processpacket(char *tpacket, char **packet, unsigned int *br,
(ip->saddr, ip->daddr, f_sport, f_dport, ip->protocol,
match_opposite, &(filter->fl))))
return PACKET_FILTERED;
+ if (v6inv4asv6 && (ip->protocol == IPPROTO_IPV6)) {
+ fromaddr->sll_protocol = ETH_P_IPV6;
+ *packet += iphlen;
+ *br -= iphlen;
+ goto again;
+ }
return PACKET_OK;
} else if (fromaddr->sll_protocol == ETH_P_IPV6) {
struct tcphdr *tcp;
diff --git a/src/packet.h b/src/packet.h
index b3bea27..c04b80a 100644
--- a/src/packet.h
+++ b/src/packet.h
@@ -32,7 +32,7 @@ int processpacket(char *tpacket, char **packet, unsigned int *br,
unsigned int *total_br, unsigned int *sport,
unsigned int *dport, struct sockaddr_ll *fromaddr,
unsigned short *linktype, struct filterstate *ofilter,
- int match_opposite, char *ifname, char *ifptr);
+ int match_opposite, char *ifname, char *ifptr, int v6inv4asv6);
void pkt_cleanup(void);
#endif /* IPTRAF_NG_PACKET_H */
diff --git a/src/pktsize.c b/src/pktsize.c
index cccea2d..a980ebf 100644
--- a/src/pktsize.c
+++ b/src/pktsize.c
@@ -310,7 +310,7 @@ void packet_size_breakdown(struct OPTIONS *options, char *ifname,
NULL, NULL, NULL, &fromaddr,
&linktype, ofilter,
MATCH_OPPOSITE_USECONFIG, iface,
- ifname);
+ ifname, 0);
if (pkt_result != PACKET_OK)
continue;
diff --git a/src/serv.c b/src/serv.c
index ed49df1..cf5bc60 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -1050,7 +1050,7 @@ void servmon(char *ifname, struct porttab *ports, const struct OPTIONS *options,
&tot_br, &sport, &dport, &fromaddr,
&linktype, ofilter,
MATCH_OPPOSITE_USECONFIG, iface,
- ifname);
+ ifname, options->v6inv4asv6);
if (pkt_result != PACKET_OK)
continue;
--
1.7.8.4
11 years, 9 months
[PATCH 0/2] iptraf-ng: fix and cleanup
by Vitezslav Samel
Vitezslav Samel (2):
get_next_iface(): fix string overflow check
ipfilter.c: gethostparams(): simplify menu initializers
src/ifaces.c | 1 +
src/ifstats.c | 2 +-
src/ipfilter.c | 84 ++++++++------------------------------------------------
src/promisc.c | 2 +-
4 files changed, 15 insertions(+), 74 deletions(-)
--
1.7.8.4
11 years, 9 months
[PATCH 0/8] iptraf-ng: fixes and cleanups
by Vitezslav Samel
Fixes and cleanups; see the shortlog and diffstat
Vitezslav Samel (8):
packet.c: processpacket(): simplify ipv4 filtering
packet.c: processpacket(): indentation cleanup.
packet.c: kill micro-optimization
packet.c: adjustpacket(): bugfix: decrement packet size not the
pointer to it
packet.c: adjustpacket(): fix VLAN header handling
packet.c: getpacket(): remove unnecessary assignment
packet.c: adjustpacket(): allow capturing on tun like interface
packet.h: delete unused defines
src/packet.c | 97 ++++++++++++++-------------------------------------------
src/packet.h | 15 ++------
2 files changed, 28 insertions(+), 84 deletions(-)
--
1.7.8.4
11 years, 9 months
iptraf-ng: packet.c: processpacket(): question
by Vitezslav Samel
Hi!
Do you know what's the purpose and/or history of these lines in
packet.c in processpacket()?
------------
if (fromaddr->sll_protocol == ETH_P_8021Q)
fromaddr->sll_protocol =
ntohs(*((unsigned short *) (tpacket + ETH_HLEN + 2)));
------------
IMHO the "tpacket + ETH_HLEN + 2" is wrong - there is no protocol number
at this place!
Thanks,
Vita
11 years, 9 months
[PATCH 0/3] iptraf-ng cleanups
by Vitezslav Samel
Self explanatory shortlog and diffstat below.
Cheers,
Vita
Vitezslav Samel (3):
Guard every header against multiple inclusion.
Kill unused header file.
Kill unused file.
src/Makefile.am | 1 -
src/addproto.h | 5 ++++-
src/arphdr.h | 5 +++++
src/attrs.h | 5 +++++
src/bar.h | 5 +++++
src/cidr.h | 4 ++++
src/deskman.h | 5 +++++
src/dirs.h | 5 +++++
src/error.h | 5 +++++
src/externs.h | 4 ++++
src/fltdefs.h | 5 +++++
src/fltedit.h | 5 +++++
src/fltmgr.h | 5 +++++
src/fltselect.h | 4 ++++
src/getpath.h | 5 +++++
src/hostmon.h | 5 +++++
src/ifaces.h | 5 +++++
src/ifstats.h | 4 ++++
src/instances.h | 5 +++++
src/ipcsum.h | 5 +++++
src/ipfilter.h | 5 +++++
src/ipfrag.h | 5 +++++
src/iptraf-ng-compat.h | 2 +-
src/isdntab.h | 5 +++++
src/landesc.h | 8 ++++----
src/list.h | 8 ++++----
src/log.h | 5 +++++
src/logvars.h | 5 +++++
src/options.h | 4 ++++
src/ospf.h | 18 ------------------
src/othptab.h | 5 +++++
src/packet.h | 8 ++++----
src/parse-options.h | 8 ++++----
src/parseproto.h | 5 +++++
src/pktsize.h | 5 +++++
src/promisc.h | 5 +++++
src/revname.h | 5 +++++
src/rvnamed.h | 5 +++++
src/serv.h | 5 +++++
src/servname.h | 5 +++++
src/strbuf.h | 7 ++++---
src/tcptable.h | 5 +++++
src/tcptimeout.h | 5 +++++
src/timer.h | 5 +++++
src/tr.h | 5 +++++
src/tui/input.h | 4 ++++
src/tui/labels.h | 5 +++++
src/tui/listbox.h | 5 +++++
src/tui/menurt.h | 5 +++++
src/tui/msgboxes.h | 4 ++++
src/tui/tui.h | 8 ++++----
src/tui/winops.h | 5 +++++
src/version | 1 -
53 files changed, 232 insertions(+), 45 deletions(-)
delete mode 100644 src/ospf.h
delete mode 100644 src/version
--
1.7.8.4
11 years, 9 months
[PATCH 0/2] iptraf-ng cleanups
by Vitezslav Samel
Vitezslav Samel (2):
Kill active_facility_* variables.
Kill unneeded check for empty iflist.
src/hostmon.c | 1 -
src/ifstats.c | 236 ++++++++++++++++++++++++++-----------------------------
src/instances.c | 2 -
src/instances.h | 2 -
src/iptraf.c | 2 -
src/itrafmon.c | 1 -
src/pktsize.c | 1 -
src/serv.c | 1 -
8 files changed, 113 insertions(+), 133 deletions(-)
--
1.7.8.4
11 years, 9 months
[PATCH 0/2] iptraf-ng cleanups
by Vitezslav Samel
Self-explanatory shortlog below.
Cheers,
Vita
Vitezslav Samel (2):
Delete never used graphing code.
Move about() dialog into the main menu.
src/ifstats.c | 62 ---------------------------------------------------------
src/iptraf.c | 8 +++++-
2 files changed, 6 insertions(+), 64 deletions(-)
--
1.7.8.4
11 years, 9 months
[PATCH 0/6] iptraf-ng: fix and cleanups
by Vitezslav Samel
Hi!
These are some fixes and cleanups to current HEAD. I think its names
are clear and doesn't need any explanation.
Cheers,
Vita
Vitezslav Samel (6):
packet.c: recvfrom(): use sizeof(struct sockaddr_ll)
packet.c: processpacket(): change if()s into switch()es
packet.c: processpacket(): simplify nonip filter
packet.c: processpacket(): make the local variables scope smaller
packet.c: processpacket(): keyboard event handling cleanup
ifstats.c: pagegstatwin(): fix the type of idx arg
src/fltselect.c | 2 +-
src/ifstats.c | 71 +++++++++++++++----------------
src/packet.c | 125 ++++++++++++++++++++++++++----------------------------
3 files changed, 95 insertions(+), 103 deletions(-)
--
1.7.8.4
11 years, 10 months