DIRECTORY
BasicTime USING [GMT, Now, Period],
Convert USING [RopeFromTime],
IO USING [Flush, PutFR, PutRope, STREAM],
Rope USING [Cat, Equal, ROPE],
IPConfig USING[rootServers],
IPDefs USING [Address],
IPName USING [AddressToRope, LoadCacheFromName],
IPNameSupport,
IPNameCache USING [AddressEntry, AliasEntry, BogusAddressEntry, BogusNameEntry, DownAddressEntry, DownNameEntry, DownServerEntry, NameEntry, MXEntry, MXHostInfo, ZoneEntry],
ViewerIO
USING [CreateViewerStreams, GetViewerFromStream];
IPNameSupportImpl:
CEDAR
MONITOR
IMPORTS BasicTime, Convert, IO, Rope, IPName, IPConfig, ViewerIO
EXPORTS IPNameSupport =
BEGIN
ROPE: TYPE = Rope.ROPE;
theLog: IO.STREAM;
Resolver log support routines
LogRope:
PUBLIC
PROC [rope:
ROPE] ~ {
putRope: PROC [stream: IO.STREAM] ~ { IO.PutRope[stream, rope] };
LogItem[putRope];
};
LogItem: ENTRY PROC [put: PROC [IO.STREAM]] ~ { put[theLog]; IO.Flush[theLog] };
NameSummaryLine:
PUBLIC
PROC [entry: IPNameCache.NameEntry, time:
BOOLEAN, showttl:
BOOLEAN ←
FALSE, log:
PROC[
ROPE] ← LogRope] = {
now: BasicTime.GMT ← BasicTime.Now[];
expires: INT ← BasicTime.Period[from: now, to: entry.expires];
ttl: INT ← entry.ttl;
source: ROPE ← IPName.AddressToRope[entry.source];
line: ROPE;
Put: PROC [r1, r2, r3, r4: ROPE ← NIL] = {line ← Rope.Cat[line, r1, r2, r3, r4]};
IF time
THEN {
Put[Convert.RopeFromTime[from: now, start: hours, end: seconds, useAMPM: FALSE, includeZone: FALSE]];
Put[" "];
};
Put[entry.name];
IF entry.addresses # NIL THEN Put[" => "];
FOR list:
LIST
OF IPDefs.Address ← entry.addresses, list.rest
UNTIL list =
NIL
DO
IF list # entry.addresses THEN Put[", "];
Put[IPName.AddressToRope[list.first]];
ENDLOOP;
Put[IO.PutFR[", %G", [integer[expires]]]];
IF showttl THEN Put[IO.PutFR[", %G", [integer[ttl]]]];
Put[IO.PutFR[", %G", [rope[source]]]];
IF ~entry.authoritative THEN Put[", Not Auth"];
Put["\n"];
log[line]};
MXSummaryLine:
PUBLIC
PROC [entry: IPNameCache.MXEntry, time:
BOOLEAN, showttl:
BOOLEAN ←
FALSE, log:
PROC[
ROPE] ← LogRope] = {
now: BasicTime.GMT ← BasicTime.Now[];
expires: INT ← BasicTime.Period[from: now, to: entry.expires];
ttl: INT ← entry.ttl;
source: ROPE ← IPName.AddressToRope[entry.source];
line: ROPE;
Put: PROC [r1, r2, r3, r4: ROPE ← NIL] = {line ← Rope.Cat[line, r1, r2, r3, r4]};
IF time
THEN {
Put[Convert.RopeFromTime[from: now, start: hours, end: seconds, useAMPM: FALSE, includeZone: FALSE]];
Put[" "];
};
Put[entry.name];
IF entry.mxHosts # NIL THEN Put[" => "];
FOR list:
LIST
OF IPNameCache.MXHostInfo ← entry.mxHosts, list.rest
UNTIL list =
NIL
DO
IF list # entry.mxHosts THEN Put[" "];
Put[list.first.host];
Put[IO.PutFR[", MXP: %G", [integer[list.first.preference]]]];
Put[IO.PutFR[", %G", [integer[expires]]]];
IF showttl THEN Put[IO.PutFR[", %G", [integer[ttl]]]];
Put[IO.PutFR[", %G", [rope[source]]]];
IF ~entry.authoritative THEN Put[", Not Auth"];
Put["\n"];
ENDLOOP;
log[line]};
AliasSummaryLine:
PUBLIC
PROC [entry: IPNameCache.AliasEntry, time:
BOOLEAN, showttl:
BOOLEAN ←
FALSE, log:
PROC[
ROPE] ← LogRope] = {
now: BasicTime.GMT ← BasicTime.Now[];
expires: INT ← BasicTime.Period[from: now, to: entry.expires];
ttl: INT ← entry.ttl;
source: ROPE ← IPName.AddressToRope[entry.source];
line: ROPE;
Put: PROC [r1, r2, r3, r4: ROPE ← NIL] = {line ← Rope.Cat[line, r1, r2, r3, r4]};
IF time
THEN {
Put[Convert.RopeFromTime[from: now, start: hours, end: seconds, useAMPM: FALSE, includeZone: FALSE]];
Put[" "]};
Put[entry.alias];
Put[" => "];
Put[entry.name];
Put[IO.PutFR[", %G", [integer[expires]]]];
IF showttl THEN Put[IO.PutFR[", %G", [integer[ttl]]]];
Put[IO.PutFR[", %G", [rope[source]]]];
IF ~entry.authoritative THEN Put[", Not Auth"];
Put["\n"];
log[line]};
BogusNameSummaryLine:
PUBLIC
PROC [entry: IPNameCache.BogusNameEntry, time:
BOOLEAN, showttl:
BOOLEAN ←
FALSE, log:
PROC[
ROPE] ← LogRope] = {
now: BasicTime.GMT ← BasicTime.Now[];
expires: INT ← BasicTime.Period[from: now, to: entry.expires];
ttl: INT ← entry.ttl;
source: ROPE ← IPName.AddressToRope[entry.source];
line: ROPE;
Put: PROC [r1, r2, r3, r4: ROPE ← NIL] = {line ← Rope.Cat[line, r1, r2, r3, r4]};
IF time
THEN {
Put[Convert.RopeFromTime[from: now, start: hours, end: seconds, useAMPM: FALSE, includeZone: FALSE]];
Put[" "]};
Put[entry.bogus];
Put[IO.PutFR[ " => ??, %G", [integer[expires]]]];
IF showttl THEN Put[IO.PutFR[", %G", [integer[ttl]]]];
Put[IO.PutFR[", %G", [rope[source]]]];
IF ~entry.authoritative THEN Put[", Not Auth"];
Put["\n"];
log[line]};
DownNameSummaryLine:
PUBLIC
PROC [entry: IPNameCache.DownNameEntry, time:
BOOLEAN, showttl:
BOOLEAN ←
FALSE, log:
PROC[
ROPE] ← LogRope] = {
now: BasicTime.GMT ← BasicTime.Now[];
expires: INT ← BasicTime.Period[from: now, to: entry.expires];
ttl: INT ← entry.ttl;
line: ROPE;
Put: PROC [r1, r2, r3, r4: ROPE ← NIL] = {line ← Rope.Cat[line, r1, r2, r3, r4]};
IF time
THEN {
Put[Convert.RopeFromTime[from: now, start: hours, end: seconds, useAMPM: FALSE, includeZone: FALSE]];
Put[" "]};
Put[entry.name];
Put[IO.PutFR[ " => ??, %G", [integer[expires]]]];
IF showttl THEN Put[IO.PutFR[ ", %G", [integer[ttl]]]];
Put["\n"];
log[line]};
AddressSummaryLine:
PUBLIC
PROC [entry: IPNameCache.AddressEntry, time:
BOOLEAN, showttl:
BOOLEAN ←
FALSE, log:
PROC[
ROPE] ← LogRope] = {
now: BasicTime.GMT ← BasicTime.Now[];
expires: INT ← BasicTime.Period[from: now, to: entry.expires];
ttl: INT ← entry.ttl;
source: ROPE ← IPName.AddressToRope[entry.source];
line: ROPE;
Put: PROC [r1, r2, r3, r4: ROPE ← NIL] = {line ← Rope.Cat[line, r1, r2, r3, r4]};
IF time
THEN {
Put[Convert.RopeFromTime[from: now, start: hours, end: seconds, useAMPM: FALSE, includeZone: FALSE]];
Put[" "]};
Put[IPName.AddressToRope[entry.address]];
Put[" => "];
FOR list:
LIST
OF
ROPE ← entry.names, list.rest
UNTIL list =
NIL
DO
IF list # entry.names THEN Put[", "];
Put[list.first];
ENDLOOP;
Put[IO.PutFR[ ", %G", [integer[expires]]]];
IF showttl THEN Put[IO.PutFR[ ", %G", [integer[ttl]]]];
Put[IO.PutFR[ ", %G", [rope[source]]]];
IF ~entry.authoritative THEN Put[", Not Auth"];
Put["\n"];
log[line]};
BogusAddressSummaryLine:
PUBLIC
PROC [entry: IPNameCache.BogusAddressEntry, time:
BOOLEAN, showttl:
BOOLEAN ←
FALSE, log:
PROC[
ROPE] ← LogRope] = {
now: BasicTime.GMT ← BasicTime.Now[];
expires: INT ← BasicTime.Period[from: now, to: entry.expires];
ttl: INT ← entry.ttl;
source: ROPE ← IPName.AddressToRope[entry.source];
line: ROPE;
Put: PROC [r1, r2, r3, r4: ROPE ← NIL] = {line ← Rope.Cat[line, r1, r2, r3, r4]};
IF time
THEN {
Put[Convert.RopeFromTime[from: now, start: hours, end: seconds, useAMPM: FALSE, includeZone: FALSE]];
Put[" "]};
Put[IPName.AddressToRope[entry.bogus]];
Put[IO.PutFR[ " => ??, %G", [integer[expires]]]];
IF showttl THEN Put[IO.PutFR[ ", %G", [integer[ttl]]]];
IF ~entry.authoritative THEN Put[", Not Auth"];
Put["\n"];
log[line]};
DownAddressSummaryLine:
PUBLIC
PROC [entry: IPNameCache.DownAddressEntry, time:
BOOLEAN, showttl:
BOOLEAN ←
FALSE, log:
PROC[
ROPE] ← LogRope] = {
now: BasicTime.GMT ← BasicTime.Now[];
expires: INT ← BasicTime.Period[from: now, to: entry.expires];
ttl: INT ← entry.ttl;
line: ROPE;
Put: PROC [r1, r2, r3, r4: ROPE ← NIL] = {line ← Rope.Cat[line, r1, r2, r3, r4]};
IF time
THEN {
Put[Convert.RopeFromTime[from: now, start: hours, end: seconds, useAMPM: FALSE, includeZone: FALSE]];
Put[" "]};
Put[IPName.AddressToRope[entry.address]];
Put[IO.PutFR[ " => ??, %G", [integer[expires]]]];
IF showttl THEN Put[IO.PutFR[ ", %G", [integer[ttl]]]];
Put["\n"];
log[line]};
DownServerSummaryLine:
PUBLIC
PROC [entry: IPNameCache.DownServerEntry, time:
BOOLEAN, showttl:
BOOLEAN ←
FALSE, log:
PROC[
ROPE] ← LogRope] = {
now: BasicTime.GMT ← BasicTime.Now[];
expires: INT ← BasicTime.Period[from: now, to: entry.expires];
ttl: INT ← entry.ttl;
line: ROPE;
Put: PROC [r1, r2, r3, r4: ROPE ← NIL] = {line ← Rope.Cat[line, r1, r2, r3, r4]};
IF time
THEN {
Put[Convert.RopeFromTime[from: now, start: hours, end: seconds, useAMPM: FALSE, includeZone: FALSE]];
Put[" "]};
Put[IPName.AddressToRope[entry.address]];
Put[IO.PutFR[ " => ??, %G", [integer[expires]]]];
IF showttl THEN Put[IO.PutFR[ ", %G", [integer[ttl]]]];
Put["\n"];
log[line]};
ZoneSummaryLine:
PUBLIC
PROC [entry: IPNameCache.ZoneEntry, time:
BOOLEAN, showttl:
BOOLEAN ←
FALSE, log:
PROC[
ROPE] ← LogRope] = {
now: BasicTime.GMT ← BasicTime.Now[];
expires: INT ← BasicTime.Period[from: now, to: entry.expires];
ttl: INT ← entry.ttl;
source: ROPE ← IPName.AddressToRope[entry.source];
line: ROPE;
Put: PROC [r1, r2, r3, r4: ROPE ← NIL] = {line ← Rope.Cat[line, r1, r2, r3, r4]};
IF time
THEN {
Put[Convert.RopeFromTime[from: now, start: hours, end: seconds, useAMPM: FALSE, includeZone: FALSE]];
Put[" "]};
Put[entry.zone];
Put[" is served by "];
FOR list:
LIST
OF
ROPE ← entry.servers, list.rest
UNTIL list =
NIL
DO
IF list # entry.servers THEN Put[", "];
Put[list.first];
ENDLOOP;
Put[IO.PutFR[ ", %G", [integer[expires]]]];
IF showttl THEN Put[IO.PutFR[ ", %G", [integer[ttl]]]];
Put[IO.PutFR[ ", %G", [rope[source]]]];
IF ~entry.authoritative THEN Put[", Not Auth"];
Put["\n"];
log[line]};
RopeInList:
PUBLIC
PROC [ropes:
LIST
OF
ROPE, rope:
ROPE]
RETURNS [yes: BOOL] = {
FOR list:
LIST
OF
ROPE ← ropes, list.rest
UNTIL list =
NIL
DO
IF Rope.Equal[list.first, rope, FALSE] THEN RETURN [TRUE];
ENDLOOP;
RETURN[FALSE]; };
AddressInList:
PUBLIC
PROC [addresses:
LIST
OF IPDefs.Address, address: IPDefs.Address]
RETURNS [yes: BOOL] = {
FOR list:
LIST
OF IPDefs.Address ← addresses, list.rest
UNTIL list =
NIL
DO
IF list.first = address THEN RETURN [TRUE];
ENDLOOP;
RETURN[FALSE]; };
MakeRopeInList:
PUBLIC
PROC [ropes:
LIST
OF
ROPE, name:
ROPE]
RETURNS [new: LIST OF ROPE] = {
IF ropes = NIL THEN RETURN[LIST[name]];
new ← ropes;
DO
IF Rope.Equal[ropes.first, name, FALSE] THEN RETURN;
IF ropes.rest = NIL THEN { ropes.rest ← LIST[name]; RETURN; };
ropes ← ropes.rest;
ENDLOOP; };
MakeAddressInList:
PUBLIC
PROC [addresses:
LIST
OF IPDefs.Address, address: IPDefs.Address]
RETURNS [new: LIST OF IPDefs.Address] = {
IF addresses = NIL THEN RETURN[LIST[address]];
new ← addresses;
DO
IF addresses.first = address THEN RETURN;
IF addresses.rest = NIL THEN { addresses.rest ← LIST[address]; RETURN; };
addresses ← addresses.rest;
ENDLOOP; };
Set up the name resolver log
[, theLog] ← ViewerIO.CreateViewerStreams [
name: "Resolver Log", backingFile: "Resolver.log", editedStream: FALSE];
ViewerIO.GetViewerFromStream[theLog].inhibitDestroy ← TRUE;
theLog.PutRope["########## ArpaGateway Resolver Log ##########\n\n"];
Load root server addresses
FOR servers:
LIST
OF Rope.
ROPE ← IPConfig.rootServers, servers.rest
UNTIL servers =
NIL
DO
[] ← IPName.LoadCacheFromName[servers.first, FALSE, TRUE];
ENDLOOP;
END.