summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2014-04-07 16:30:15 +0200
committerDaniel Borkmann <dborkman@redhat.com>2014-04-07 16:34:39 +0200
commit3bcd95bb1da97f00eb0e1d6e8d497911c14b4e44 (patch)
treef2e14c575116acdbdc167abc401e9478774fd057
parentc10621e6fa8de50619d7dd28546dd3288f053ab8 (diff)
pcap_io: fill sll when reading pcap
When reading from a pcap in Kuznetsov/netsniff-ng format, we currently do not fill out sll. Do so so that users can see pkttype and the interface. Reported-by: Flavio Leitner <fbl@redhat.com> Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
-rw-r--r--netsniff-ng.c4
-rw-r--r--pcap_io.h25
2 files changed, 26 insertions, 3 deletions
diff --git a/netsniff-ng.c b/netsniff-ng.c
index 351dcc9..6a83702 100644
--- a/netsniff-ng.c
+++ b/netsniff-ng.c
@@ -281,7 +281,7 @@ static void pcap_to_xmit(struct ctx *ctx)
!bpf_run_filter(&bpf_ops, out,
pcap_get_length(&phdr, ctx->magic)));
- pcap_pkthdr_to_tpacket_hdr(&phdr, ctx->magic, &hdr->tp_h);
+ pcap_pkthdr_to_tpacket_hdr(&phdr, ctx->magic, &hdr->tp_h, NULL);
ctx->tx_bytes += hdr->tp_h.tp_len;;
ctx->tx_packets++;
@@ -620,7 +620,7 @@ static void read_pcap(struct ctx *ctx)
!bpf_run_filter(&bpf_ops, out,
pcap_get_length(&phdr, ctx->magic)));
- pcap_pkthdr_to_tpacket_hdr(&phdr, ctx->magic, &fm.tp_h);
+ pcap_pkthdr_to_tpacket_hdr(&phdr, ctx->magic, &fm.tp_h, &fm.s_ll);
ctx->tx_bytes += fm.tp_h.tp_len;
ctx->tx_packets++;
diff --git a/pcap_io.h b/pcap_io.h
index 454976c..41fe470 100644
--- a/pcap_io.h
+++ b/pcap_io.h
@@ -450,7 +450,8 @@ static inline void tpacket3_hdr_to_pcap_pkthdr(struct tpacket3_hdr *thdr,
static inline void pcap_pkthdr_to_tpacket_hdr(pcap_pkthdr_t *phdr,
enum pcap_type type,
- struct tpacket2_hdr *thdr)
+ struct tpacket2_hdr *thdr,
+ struct sockaddr_ll *sll)
{
switch (type) {
case DEFAULT:
@@ -486,6 +487,11 @@ static inline void pcap_pkthdr_to_tpacket_hdr(pcap_pkthdr_t *phdr,
thdr->tp_nsec = phdr->ppk.ts.tv_usec * 1000;
thdr->tp_snaplen = phdr->ppk.caplen;
thdr->tp_len = phdr->ppk.len;
+ if (sll) {
+ sll->sll_ifindex = phdr->ppk.ifindex;
+ sll->sll_protocol = phdr->ppk.protocol;
+ sll->sll_pkttype = phdr->ppk.pkttype;
+ }
break;
case KUZNETZOV_SWAPPED:
@@ -493,6 +499,11 @@ static inline void pcap_pkthdr_to_tpacket_hdr(pcap_pkthdr_t *phdr,
thdr->tp_nsec = ___constant_swab32(phdr->ppk.ts.tv_usec) * 1000;
thdr->tp_snaplen = ___constant_swab32(phdr->ppk.caplen);
thdr->tp_len = ___constant_swab32(phdr->ppk.len);
+ if (sll) {
+ sll->sll_ifindex = ___constant_swab32(phdr->ppk.ifindex);
+ sll->sll_protocol = ___constant_swab16(phdr->ppk.protocol);
+ sll->sll_pkttype = phdr->ppk.pkttype;
+ }
break;
case BORKMANN:
@@ -500,6 +511,12 @@ static inline void pcap_pkthdr_to_tpacket_hdr(pcap_pkthdr_t *phdr,
thdr->tp_nsec = phdr->ppb.ts.tv_nsec;
thdr->tp_snaplen = phdr->ppb.caplen;
thdr->tp_len = phdr->ppb.len;
+ if (sll) {
+ sll->sll_ifindex = phdr->ppb.ifindex;
+ sll->sll_protocol = phdr->ppb.protocol;
+ sll->sll_hatype = phdr->ppb.hatype;
+ sll->sll_pkttype = phdr->ppb.pkttype;
+ }
break;
case BORKMANN_SWAPPED:
@@ -507,6 +524,12 @@ static inline void pcap_pkthdr_to_tpacket_hdr(pcap_pkthdr_t *phdr,
thdr->tp_nsec = ___constant_swab32(phdr->ppb.ts.tv_nsec);
thdr->tp_snaplen = ___constant_swab32(phdr->ppb.caplen);
thdr->tp_len = ___constant_swab32(phdr->ppb.len);
+ if (sll) {
+ sll->sll_ifindex = ___constant_swab16(phdr->ppb.ifindex);
+ sll->sll_protocol = ___constant_swab16(phdr->ppb.protocol);
+ sll->sll_hatype = phdr->ppb.hatype;
+ sll->sll_pkttype = phdr->ppb.pkttype;
+ }
break;
default: