Skip to content

Commit

Permalink
fixes to be able to read the source ip
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesm committed Jan 9, 2014
1 parent 95b0e6c commit 7c128e6
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
17 changes: 10 additions & 7 deletions dns-server/dns-server.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ define class <dns-server> (<filter>)
end;

define method push-data-aux
(input :: <push-input>, node :: <dns-server>, data :: <dns-frame>) => ()
(input :: <push-input>, dns :: <dns-server>, data :: <dns-frame>) => ()
//dbg("received %=\n", data);
let remote-ip-c = dns.the-output.connected-input.node.reply-addr;
let remote-ip = make(<ipv4-network-order-address>,
address: remote-ip-c);
if (data.query-or-response == #"query" &
data.question-count == 1)
let question = data.questions.first;
Expand All @@ -16,13 +19,13 @@ define method push-data-aux

//TODO: check authority!

dbg("question: ?%s%s\n", dns-query-entry(question.question-type), que);
let answers = choose(rcurry(entry-matches?, type, que), node.zone.entries);
dbg("%s ?%s%s\n", as(<string>, remote-ip), dns-query-entry(question.question-type), que);
let answers = choose(rcurry(entry-matches?, type, que), dns.zone.entries);

dbg("answers: %d\n", answers.size);
for (x in answers, i from 0)
dbg("answer %d: %=\n", i, x);
end;
//for (x in answers, i from 0)
// dbg("answer %d: %=\n", i, x);
//end;

let d1 = as(<domain-name>, que);
let quest = dns-question(domainname: d1,
Expand All @@ -40,7 +43,7 @@ define method push-data-aux
answers: frs);
quest.parent := res;
do(method(x) x.parent := res end, frs);
push-data(node.the-output, res);
push-data(dns.the-output, res);
else
format-out("not a question or multiple.\n")
end;
Expand Down
2 changes: 2 additions & 0 deletions dns-server/library.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ define library dns-server
use socket-flow;
use system;
use command-line-parser;
use network;
end library;

define module dns-server
Expand All @@ -29,4 +30,5 @@ define module dns-server
use standard-io, import: { *standard-output* };
use command-line-parser;
use simple-random;
use sockets, import: { <ipv4-network-order-address> };
end module;
4 changes: 2 additions & 2 deletions dns-server/zone-reader.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ end;
define function domain-name-matches? (domain-name :: <string>, question :: <string>) => (res :: <boolean>)
//dbg("comparing %s with %s\n", domain-name, question);
if (domain-name[0] == '*')
copy-sequence(domain-name, start: 2) = join(copy-sequence(split(question, "."), start: 1), ".");
as-lowercase(copy-sequence(domain-name, start: 2)) = as-lowercase(join(copy-sequence(split(question, "."), start: 1), "."));
else
domain-name = question
as-lowercase(domain-name) = as-lowercase(question)
end
end;

Expand Down
2 changes: 1 addition & 1 deletion socket-flow/library-unix.dylan
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ define module socket-flow
use sockets, import: { interruptible-system-call };
use dylan-direct-c-ffi;

export <flow-socket>;
export <flow-socket>, reply-addr, reply-port;
end module;

0 comments on commit 7c128e6

Please sign in to comment.