On Fri, Jul 13, 2012 at 03:19:18PM +0200, Nikola Pajkovsky wrote:
not everything is possible converth right now
Signed-off-by: Nikola Pajkovsky <npajkovs(a)redhat.com>
---
src/detstats.c | 6 ++---
src/itrafmon.c | 70 +++++++++++++++++++++++++-------------------------------
src/packet.c | 6 +++++
src/packet.h | 4 ++++
src/serv.c | 13 +++++------
5 files changed, 49 insertions(+), 50 deletions(-)
diff --git a/src/detstats.c b/src/detstats.c
index 2364662..4eebdaf 100644
--- a/src/detstats.c
+++ b/src/detstats.c
@@ -259,7 +259,6 @@ void detstats(char *iface, const struct OPTIONS *options, time_t
facilitytime,
WINDOW *statwin;
PANEL *statpanel;
- struct iphdr *ipacket = NULL;
struct ip6_hdr *ip6packet = NULL;
int framelen = 0;
@@ -562,9 +561,8 @@ void detstats(char *iface, const struct OPTIONS *options, time_t
facilitytime,
continue;
}
- ipacket = (struct iphdr *) pkt.pkt_payload;
- iplen = ntohs(ipacket->tot_len);
- ipproto = ipacket->protocol;
+ iplen = ntohs(pkt.iphdr->tot_len);
+ ipproto = pkt.iphdr->protocol;
update_proto_counter(&ifcounts.ipv4, outgoing, iplen);
break;
diff --git a/src/itrafmon.c b/src/itrafmon.c
index ce68688..c2baaf7 100644
--- a/src/itrafmon.c
+++ b/src/itrafmon.c
@@ -552,8 +552,6 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
{
int logging = options->logging;
- struct iphdr *ippacket;
- struct ip6_hdr *ip6packet;
unsigned int protocol;
unsigned int frag_off;
struct tcphdr *transpacket; /* IP-encapsulated packet */
@@ -1019,17 +1017,13 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
switch(pkt.pkt_protocol) {
case ETH_P_IP:
- ippacket = (struct iphdr *) pkt.pkt_payload;
- iphlen = ippacket->ihl * 4;
- ip6packet = NULL;
- protocol = ippacket->protocol;
- frag_off = ippacket->frag_off;
+ iphlen = pkt.iphdr->ihl * 4;
+ protocol = pkt.iphdr->protocol;
+ frag_off = pkt.iphdr->frag_off;
break;
case ETH_P_IPV6:
- ip6packet = (struct ip6_hdr *) pkt.pkt_payload;
iphlen = 40;
- ippacket = NULL;
- protocol = ip6packet->ip6_nxt;
+ protocol = pkt.ip6_hdr->ip6_nxt;
frag_off = 0;
break;
default:
@@ -1045,11 +1039,11 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
transpacket = (struct tcphdr *) (pkt.pkt_payload + iphlen);
if (protocol == IPPROTO_TCP) {
- if (ippacket != NULL) {
+ if (pkt.iphdr) {
tcpentry =
in_table(&table,
- ippacket->saddr,
- ippacket->daddr,
+ pkt.iphdr->saddr,
+ pkt.iphdr->daddr,
NULL, NULL,
ntohs(sport),
ntohs(dport),
@@ -1058,14 +1052,12 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
} else {
tcpentry =
in_table(&table, 0, 0,
- (uint8_t *) (&ip6packet->
- ip6_src.
- s6_addr),
- (uint8_t *) (&ip6packet->
- ip6_dst.
- s6_addr),
- ntohs(sport), ntohs(dport),
- ifname, logging, logfile, options);
+ (uint8_t *) &pkt.ip6_hdr->
+ ip6_src.s6_addr,
+ (uint8_t *) &pkt.ip6_hdr->
+ ip6_dst.s6_addr,
+ ntohs(sport), ntohs(dport),
+ ifname, logging, logfile, options);
}
/*
@@ -1082,21 +1074,21 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
* is not yet closed, or if it is a SYN packet.
*/
wasempty = (table.head == NULL);
- if (ippacket != NULL)
+ if (pkt.iphdr)
tcpentry =
addentry(&table,
- (unsigned long) ippacket->saddr,
- (unsigned long) ippacket->daddr,
+ (unsigned long) pkt.iphdr->saddr,
+ (unsigned long) pkt.iphdr->daddr,
NULL, NULL, sport, dport,
- ippacket->protocol,
+ pkt.iphdr->protocol,
ifname, &revlook, rvnfd,
options->servnames);
else
tcpentry =
addentry(&table, 0, 0,
- (uint8_t *) (&ip6packet->ip6_src.s6_addr),
- (uint8_t *) (&ip6packet->ip6_dst.s6_addr),
- sport, dport, ip6packet->ip6_nxt,
+ (uint8_t *) &pkt.ip6_hdr->ip6_src.s6_addr,
+ (uint8_t *) &pkt.ip6_hdr->ip6_dst.s6_addr,
+ sport, dport, pkt.ip6_hdr->ip6_nxt,
ifname, &revlook, rvnfd,
options->servnames);
if (tcpentry != NULL) {
@@ -1128,10 +1120,10 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
p_dstat = tcpentry->d_fstat;
}
- if (ippacket != NULL)
+ if (pkt.iphdr)
updateentry(&table, tcpentry, transpacket,
pkt.pkt_buf, pkt.pkt_hatype,
- pkt.pkt_len, br, ippacket->frag_off,
+ pkt.pkt_len, br, pkt.iphdr->frag_off,
logging, &revlook, rvnfd, options,
logfile);
else
@@ -1190,10 +1182,10 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
printentry(&table, tcpentry->oth_connection,
screen_idx, mode);
}
- } else if (ippacket != NULL) {
- fragment = ((ntohs(ippacket->frag_off) & 0x1fff) != 0);
+ } else if (pkt.iphdr) {
+ fragment = ((ntohs(pkt.iphdr->frag_off) & 0x1fff) != 0);
- if (ippacket->protocol == IPPROTO_ICMP) {
+ if (pkt.iphdr->protocol == IPPROTO_ICMP) {
/*
* Cancel the corresponding TCP entry if an ICMP
@@ -1205,23 +1197,23 @@ void ipmon(struct OPTIONS *options, struct filterstate *ofilter,
process_dest_unreach(&table, (char *) transpacket,
ifname);
}
- add_othp_entry(&othptbl, &pkt, ippacket->saddr,
- ippacket->daddr, NULL, NULL, IS_IP,
- ippacket->protocol,
+ add_othp_entry(&othptbl, &pkt, pkt.iphdr->saddr,
+ pkt.iphdr->daddr, NULL, NULL, IS_IP,
+ pkt.iphdr->protocol,
(char *) transpacket,
ifname, &revlook, rvnfd,
logging, logfile,
options->servnames, fragment);
} else {
- if (ip6packet->ip6_nxt == IPPROTO_ICMPV6
+ if (pkt.ip6_hdr->ip6_nxt == IPPROTO_ICMPV6
&& (((struct icmp6_hdr *) transpacket)->icmp6_type ==
ICMP6_DST_UNREACH))
process_dest_unreach(&table, (char *) transpacket,
ifname);
add_othp_entry(&othptbl, &pkt, 0, 0,
- &ip6packet->ip6_src, &ip6packet->ip6_dst,
- IS_IP, ip6packet->ip6_nxt,
+ &pkt.ip6_hdr->ip6_src, &pkt.ip6_hdr->ip6_dst,
+ IS_IP, pkt.ip6_hdr->ip6_nxt,
(char *) transpacket, ifname,
&revlook, rvnfd,
logging, logfile, options->servnames,
diff --git a/src/packet.c b/src/packet.c
index fbd94f1..2a22dbc 100644
--- a/src/packet.c
+++ b/src/packet.c
@@ -47,6 +47,12 @@ static int packet_adjust(struct pkt_hdr *pkt)
case ARPHRD_ETHER:
case ARPHRD_LOOPBACK:
pkt_cast_hdrp(ethhdr, pkt, 0);
+ if (pkt->pkt_protocol == ETH_P_IP)
+ pkt_cast_hdrp(iphdr, pkt, ETH_HLEN);
+
+ if (pkt->pkt_protocol == ETH_P_IPV6)
+ pkt_cast_hdrp(ip6_hdr, pkt, ETH_HLEN);
+
pkt->pkt_payload = pkt->pkt_buf;
pkt->pkt_payload += ETH_HLEN;
pkt->pkt_len -= ETH_HLEN;
NAK.
Tests for upper layer protocol should be moved after this switch and
pkt_cast_hdrp() (better some new function) should use pkt->pkt_payload
pointer. (You are mixing two protocol layers together - don't do this!)
Vita
diff --git a/src/packet.h b/src/packet.h
index 72a7062..15296a1 100644
--- a/src/packet.h
+++ b/src/packet.h
@@ -35,6 +35,8 @@ struct pkt_hdr {
unsigned char pkt_addr[8]; /* Physical layer address */
struct ethhdr *ethhdr;
struct fddihdr *fddihdr;
+ struct iphdr *iphdr;
+ struct ip6_hdr *ip6_hdr;
char pkt_buf[MAX_PACKET_SIZE];
};
@@ -50,6 +52,8 @@ struct pkt_hdr {
.pkt_payload = NULL, \
.ethhdr = NULL, \
.fddihdr = NULL, \
+ .iphdr = NULL, \
+ .ip6_hdr = NULL, \
};
void open_socket(int *fd);
diff --git a/src/serv.c b/src/serv.c
index aeea6b2..caa8a6c 100644
--- a/src/serv.c
+++ b/src/serv.c
@@ -1048,9 +1048,6 @@ void servmon(char *ifname, const struct OPTIONS *options,
if (pkt.pkt_len <= 0)
continue;
- unsigned short ipproto;
- unsigned short iplen;
-
pkt_result =
packet_process(&pkt, &tot_br, &sport, &dport,
ofilter,
@@ -1060,14 +1057,16 @@ void servmon(char *ifname, const struct OPTIONS *options,
if (pkt_result != PACKET_OK)
continue;
+ unsigned short ipproto;
+ unsigned short iplen;
switch (pkt.pkt_protocol) {
case ETH_P_IP:
- ipproto = ((struct iphdr *) pkt.pkt_payload)->protocol;
- iplen = ntohs(((struct iphdr *) pkt.pkt_payload)->tot_len);
+ ipproto = pkt.iphdr->protocol;
+ iplen = ntohs(pkt.iphdr->tot_len);
break;
case ETH_P_IPV6:
- ipproto = ((struct ip6_hdr *) pkt.pkt_payload)->ip6_nxt; /* FIXME: extension
headers ??? */
- iplen = ntohs(((struct ip6_hdr *) pkt.pkt_payload)->ip6_plen) + 40;
+ ipproto = pkt.ip6_hdr->ip6_nxt; /* FIXME: extension headers ??? */
+ iplen = ntohs(pkt.ip6_hdr->ip6_plen) + 40;
break;
default:
/* unknown link protocol */
--
1.7.10.2