This makes the code more readable.
Signed-off-by: Vitezslav Samel vitezslav@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;
iptraf-ng@lists.fedorahosted.org