Skip to content

Commit

Permalink
More pull request cleanups
Browse files Browse the repository at this point in the history
-Fixed broken comments and various issues in the header
-Removed commented legacy code
-port naming consistency in fieldsets
-assert(0) -> log_fatal
  • Loading branch information
paul-pearce committed Sep 21, 2015
1 parent 4d4f012 commit 60aef39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
19 changes: 7 additions & 12 deletions src/probe_modules/module_dns.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,10 +713,6 @@ int dns_validate_packet(const struct ip *ip_hdr, uint32_t len,
}

struct icmp *icmp = (struct icmp*) ((char *) ip_hdr + 4*ip_hdr->ip_hl);
// We want to handle more of this.
/*if (icmp->icmp_type != ICMP_UNREACH) {
return 0;
}*/

struct ip *ip_inner = (struct ip*) ((char *) icmp + ICMP_UNREACH_HEADER_SIZE);
// Now we know the actual inner ip length, we should recheck the buffer
Expand Down Expand Up @@ -808,8 +804,8 @@ void dns_process_packet(const u_char *packet, uint32_t len, fieldset_t *fs,
fs_add_uint64(fs, "app_success", is_valid && (qr == DNS_QR_ANSWER) && (rcode == DNS_RCODE_NOERR));

// UDP info
fs_add_uint64(fs, "udp_sport", ntohs(udp_hdr->uh_sport));
fs_add_uint64(fs, "udp_dport", ntohs(udp_hdr->uh_dport));
fs_add_uint64(fs, "sport", ntohs(udp_hdr->uh_sport));
fs_add_uint64(fs, "dport", ntohs(udp_hdr->uh_dport));
fs_add_uint64(fs, "udp_len", udp_len);

// ICMP info
Expand Down Expand Up @@ -910,7 +906,6 @@ void dns_process_packet(const u_char *packet, uint32_t len, fieldset_t *fs,

// Now the raw stuff.
fs_add_binary(fs, "raw_data", (udp_len - sizeof(struct udphdr)), (void*) &udp_hdr[1], 0);
//fs_add_binary(fs, "raw_data", len, (void*)packet, 0);

return;

Expand All @@ -929,8 +924,8 @@ void dns_process_packet(const u_char *packet, uint32_t len, fieldset_t *fs,
fs_add_uint64(fs, "app_success", 0);

// UDP info
fs_add_uint64(fs, "udp_sport", ntohs(udp_hdr->uh_sport));
fs_add_uint64(fs, "udp_dport", ntohs(udp_hdr->uh_dport));
fs_add_uint64(fs, "sport", ntohs(udp_hdr->uh_sport));
fs_add_uint64(fs, "dport", ntohs(udp_hdr->uh_dport));
fs_add_uint64(fs, "udp_len", udp_len);

// ICMP info
Expand Down Expand Up @@ -975,7 +970,7 @@ void dns_process_packet(const u_char *packet, uint32_t len, fieldset_t *fs,

} else {
// This should not happen. Both the pcap filter and validate packet prevent this.
assert(0);
log_fatal("dns", "Die. This can only happen if you change the pcap filter and don't update the process function.");
return;
}
}
Expand All @@ -984,8 +979,8 @@ static fielddef_t fields[] = {
{.name = "classification", .type="string", .desc = "packet protocol"},
{.name = "success", .type="int", .desc = "Are the validation bits and question correct"},
{.name = "app_success", .type="int", .desc = "Is the RA bit set with no error code?"},
{.name = "udp_sport", .type = "int", .desc = "UDP source port"},
{.name = "udp_dport", .type = "int", .desc = "UDP destination port"},
{.name = "sport", .type = "int", .desc = "UDP source port"},
{.name = "dport", .type = "int", .desc = "UDP destination port"},
{.name = "udp_len", .type="int", .desc = "UDP packet lenght"},
{.name = "icmp_responder", .type = "string", .desc = "Source IP of ICMP_UNREACH message"},
{.name = "icmp_type", .type = "int", .desc = "icmp message type"},
Expand Down
23 changes: 6 additions & 17 deletions src/probe_modules/module_dns.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ typedef struct __attribute__((packed)) {
char rdata[];
} dns_answer_tail;

// XXX
typedef struct __attribute__((packed)) {
uint16_t name;
uint16_t type;
uint16_t addr_class;
uint32_t ttl;
uint16_t length;
uint32_t addr;
} dnsans;

typedef enum {
DNS_QTYPE_A = 1,
DNS_QTYPE_NS = 2,
Expand All @@ -68,12 +58,11 @@ typedef enum {
DNS_QTYPE_ALL = 255
} dns_qtype;

// TODO: we may want to put out strings.
typedef enum {
DNS_RCODE_NOERR = 0, /* Response code NO ERROR */
DNS_RCODE_FORMATERR = 1, /* Response code NO ERROR */
DNS_RCODE_SRVFAILURE = 2, /* Response code NO ERROR */
DNS_RCODE_NXDOMAIN = 3, /* Response code NO ERROR */
DNS_RCODE_QTYPENOTIMPL = 4, /* Response code NO ERROR */
DNS_RCODE_QRYREFUSED = 5 /* Response code NO ERROR */
DNS_RCODE_NOERR = 0,
DNS_RCODE_FORMATERR = 1,
DNS_RCODE_SRVFAILURE = 2,
DNS_RCODE_NXDOMAIN = 3,
DNS_RCODE_QTYPENOTIMPL = 4,
DNS_RCODE_QRYREFUSED = 5
} dns_rcode;

0 comments on commit 60aef39

Please sign in to comment.