From: Mats Erik Andersson Date: Thu, 14 Oct 2010 13:11:59 +0000 (+0200) Subject: Activate accounting for IPv6 hosts. X-Git-Tag: 3.0.714~82 X-Git-Url: https://unix4lyfe.org/gitweb/darkstat/commitdiff_plain/f2e0493cd79657110cf40fdcfb022e27444120d0 Activate accounting for IPv6 hosts. The already implemented host table functions are put to work also for IPv6 hosts. In addition, IPPROTO_AH, IPPROTO_ESP, and IPPROTO_OSPF now prevent complaints about these protocols being unknown. A complete URI is augmented for hostreporting, since the dubble colon can be confused for a protocol switch. --- diff --git a/acct.c b/acct.c index a8e20d0..65e2bc1 100644 --- a/acct.c +++ b/acct.c @@ -222,20 +222,34 @@ acct_for(const pktsummary *sm) graph_acct((uint64_t)sm->len, GRAPH_IN); } - if (sm->af == AF_INET6) return; /* Still no continuation for IPv6! */ - if (hosts_max == 0) return; /* skip per-host accounting */ /* Hosts. */ - ipaddr.af = sm->af; /* TODO */ - ipaddr.addr.ip = sm->src_ip; /* TODO */ + ipaddr.af = sm->af; + switch (ipaddr.af) { + case AF_INET6: + memcpy(&ipaddr.addr.ip6, &sm->src_ip6, sizeof(ipaddr.addr.ip6)); + break; + case AF_INET: + default: + memcpy(&ipaddr.addr.ip, &sm->src_ip, sizeof(ipaddr.addr.ip)); + break; + } hs = host_get(&ipaddr); hs->out += sm->len; hs->total += sm->len; memcpy(hs->u.host.mac_addr, sm->src_mac, sizeof(sm->src_mac)); hs->u.host.last_seen = now; - ipaddr.addr.ip = sm->dest_ip; /* TODO */ + switch (ipaddr.af) { + case AF_INET6: + memcpy(&ipaddr.addr.ip6, &sm->dest_ip6, sizeof(ipaddr.addr.ip6)); + break; + case AF_INET: + default: + memcpy(&ipaddr.addr.ip, &sm->dest_ip, sizeof(ipaddr.addr.ip)); + break; + } hd = host_get(&ipaddr); /* this can invalidate hs! */ hd->in += sm->len; hd->total += sm->len; @@ -243,7 +257,15 @@ acct_for(const pktsummary *sm) hd->u.host.last_seen = now; /* Protocols. */ - ipaddr.addr.ip = sm->src_ip; /* TODO */ + switch (ipaddr.af) { + case AF_INET6: + memcpy(&ipaddr.addr.ip6, &sm->src_ip6, sizeof(ipaddr.addr.ip6)); + break; + case AF_INET: + default: + memcpy(&ipaddr.addr.ip, &sm->src_ip, sizeof(ipaddr.addr.ip)); + break; + } hs = host_find(&ipaddr); if (hs != NULL) { ps = host_get_ip_proto(hs, sm->proto); @@ -296,6 +318,9 @@ acct_for(const pktsummary *sm) case IPPROTO_ICMP: case IPPROTO_ICMPV6: + case IPPROTO_AH: + case IPPROTO_ESP: + case IPPROTO_OSPF: /* known protocol, don't complain about it */ break; diff --git a/decode.c b/decode.c index c8e2f24..c91140b 100644 --- a/decode.c +++ b/decode.c @@ -401,6 +401,9 @@ decode_ip(const u_char *pdata, const uint32_t len, pktsummary *sm) } case IPPROTO_ICMP: + case IPPROTO_AH: + case IPPROTO_ESP: + case IPPROTO_OSPF: /* known protocol, don't complain about it */ break; @@ -453,6 +456,9 @@ decode_ipv6(const u_char *pdata, const uint32_t len, pktsummary *sm) } case IPPROTO_ICMPV6: + case IPPROTO_AH: + case IPPROTO_ESP: + case IPPROTO_OSPF: /* known protocol, don't complain about it */ break; diff --git a/decode.h b/decode.h index 679b2e8..7fbd5fe 100644 --- a/decode.h +++ b/decode.h @@ -30,6 +30,10 @@ #define ETHER_ADDR_LEN 6 #endif +#ifndef IPPROTO_OSPF +# define IPPROTO_OSPF 89 +#endif + typedef struct { int linktype; unsigned int hdrlen; diff --git a/dns.c b/dns.c index 128910a..125ab62 100644 --- a/dns.c +++ b/dns.c @@ -125,13 +125,10 @@ dns_queue(const struct addr46 *const ipaddr) if (pid == -1) return; /* no child was started - we're not doing any DNS */ -#if 1 - if (ipaddr->af != AF_INET) { + if (ipaddr->af != AF_INET && ipaddr->af != AF_INET6) { verbosef("dns_queue() for unknown family %d.\n", ipaddr->af); - /* Not yet IPv6 capable. */ return; } -#endif rec = xmalloc(sizeof(*rec)); memcpy(&rec->ip, ipaddr, sizeof(rec->ip)); diff --git a/hosts_db.c b/hosts_db.c index 81d7959..d0d0b85 100644 --- a/hosts_db.c +++ b/hosts_db.c @@ -331,7 +331,7 @@ format_row_host(struct str *buf, const struct bucket *b, str_appendf(buf, "\n" - " %s\n" + " %s\n" " %s\n", css_class, ip, ip,