[Gd-chatter] r11072 - trunk/libraries/network/koala/sources/examples/buddha
hannes at gwydiondylan.org
hannes at gwydiondylan.org
Sun Dec 17 19:03:19 CET 2006
Author: hannes
Date: Sun Dec 17 19:03:15 2006
New Revision: 11072
Modified:
trunk/libraries/network/koala/sources/examples/buddha/buddha.dylan
trunk/libraries/network/koala/sources/examples/buddha/config.dylan
trunk/libraries/network/koala/sources/examples/buddha/ipv6.dylan
trunk/libraries/network/koala/sources/examples/buddha/zone.dylan
Log:
Bug: 7257
*support for v6 in zones...
Modified: trunk/libraries/network/koala/sources/examples/buddha/buddha.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/examples/buddha/buddha.dylan (original)
+++ trunk/libraries/network/koala/sources/examples/buddha/buddha.dylan Sun Dec 17 19:03:15 2006
@@ -660,15 +660,20 @@
h2(concatenate("Hosts in subnet ", show(dsubnet))),
table { tr { th("Hostname"), th("IP"), th("Mac")},
do(reset-color(storage(<host>));
+ let (ref-slot, ip) = if (instance?(dsubnet, <ipv4-subnet>))
+ values(ipv4-subnet, ipv4-address);
+ elseif (instance?(dsubnet, <ipv6-subnet>))
+ values(ipv6-subnet, ipv6-address);
+ end;
map(method(x) with-xml()
tr(class => next-color(storage(<host>)))
{ td {a(x.host-name,
href => concatenate("/host-detail?host=",
get-reference(x))) },
- td(show(x.ipv4-address)),
+ td(show(x.ip)),
td(show(x.mac-address)) }
end
- end, choose(method(y) y.ipv4-subnet = dsubnet end, storage(<host>)))) }
+ end, choose(method(y) y.ref-slot = dsubnet end, storage(<host>)))) }
//add host with predefined subnet (cause we have the context)?
}
end);
@@ -1011,8 +1016,37 @@
name => "zone",
value => get-reference(dzone))
end)),
+ h2("AAAA-records"),
+ do(if (dzone.aaaa-records.size > 0)
+ with-xml()
+ table { tr { th("Hostname"), th("IP"), th("TTL"), th("Remove") },
+ do(reset-color(dzone.a-records);
+ map(method(x) with-xml()
+ tr(class => next-color(dzone.aaaa-records))
+ {
+ td(x.host-name),
+ td(show(x.ipv6-address)),
+ td(show(x.time-to-live)),
+ td { do(remove-form(x, dzone.a-records,
+ url: "zone-detail",
+ xml: with-xml()
+ input(type => "hidden",
+ name => "zone",
+ value => get-reference(dzone))
+ end)) } }
+ end
+ end, dzone.aaaa-records)) }
+ end
+ end),
+ do(add-form(<aaaa-record>, #f, dzone.aaaa-records,
+ refer: "zone-detail",
+ xml: with-xml()
+ input(type => "hidden",
+ name => "zone",
+ value => get-reference(dzone))
+ end)),
h2("Hosts"),
- table { tr { th("Hostname"), th("IP"), th("TTL") },
+ table { tr { th("Hostname"), th("IPv4"), th("IPv6"), th("TTL") },
do(reset-color(storage(<host>));
map(method(x) with-xml()
tr(class => next-color(storage(<host>)))
@@ -1020,6 +1054,7 @@
href => concatenate("/host-detail?host=",
get-reference(x))) },
td(show(x.ipv4-address)),
+ td(show(x.ipv6-address)),
td(show(x.time-to-live)) }
end
end, choose(method(y) y.zone = dzone end, storage(<host>)))) } }
Modified: trunk/libraries/network/koala/sources/examples/buddha/config.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/examples/buddha/config.dylan (original)
+++ trunk/libraries/network/koala/sources/examples/buddha/config.dylan Sun Dec 17 19:03:15 2006
@@ -102,7 +102,12 @@
elseif (size(choose(method(x) x.ipv4-address = host.ipv4-address end,
choose(method(x) x.ipv4-subnet = host.ipv4-subnet end, storage(<host>)))) > test-result)
signal(make(<web-error>,
- error: "Host with same IP address already exists in subnet"));
+ error: "Host with same IPv4 address already exists in subnet"));
+ elseif (host.ipv6-address ~= $bottom-v6-address &
+ size(choose(method(x) x.ipv6-address = host.ipv6-address end,
+ choose(method(x) x.ipv6-subnet = host.ipv6-subnet end, storage(<host>)))) > test-result)
+ signal(make(<web-error>,
+ error: "Host with same IPv6 address already exists in subnet"));
elseif (host.ipv4-subnet.dhcp?
& size(choose(method(x) x.mac-address = host.mac-address end,
choose(method(x) x.ipv4-subnet = host.ipv4-subnet end,
@@ -157,7 +162,7 @@
end if;
end;
-define method check (subnet :: <ipv4-subnet>, #key test-result = 0)
+define method check (subnet :: <subnet>, #key test-result = 0)
=> (res :: <boolean>)
unless (network-address(subnet.cidr) = base-network-address(subnet.cidr))
signal(make(<web-form-warning>,
@@ -166,58 +171,63 @@
end;
if (every?(method(x) x = subnet end, overlaps(subnet)))
if (subnet-in-network?(subnet))
- if (subnet.dhcp-start > subnet.dhcp-end)
- signal(make(<web-error>,
- error: "DHCP start greater than DHCP end"));
- elseif (subnet.dhcp-start = broadcast-address(subnet.cidr))
- signal(make(<web-error>,
- error: "DHCP start can't be broadcast address"))
- elseif (subnet.dhcp-start = network-address(subnet.cidr))
- signal(make(<web-error>,
- error: "DHCP start can't be network address"))
- elseif (subnet.dhcp-end = broadcast-address(subnet.cidr))
- signal(make(<web-error>,
- error: "DHCP end can't be broadcast address"))
- elseif (subnet.dhcp-end = network-address(subnet.cidr))
- signal(make(<web-error>,
- error: "DHCP end can't be network address"))
- elseif (subnet.dhcp-router = broadcast-address(subnet.cidr))
- signal(make(<web-error>,
- error: "DHCP router can't be broadcast address"))
- elseif (subnet.dhcp-router = network-address(subnet.cidr))
- signal(make(<web-error>,
- error: "DHCP router can't be network address"))
- end;
- if (ip-in-net?(subnet, subnet.dhcp-start))
- if (ip-in-net?(subnet, subnet.dhcp-end))
- if (ip-in-net?(subnet, subnet.dhcp-router))
- if ((subnet.dhcp-router > subnet.dhcp-start)
- & (subnet.dhcp-router < subnet.dhcp-end))
- signal(make(<web-error>,
- error: "Router has to be outside of dhcp-range"));
- else
- #t;
- end if;
- else
- signal(make(<web-error>,
- error: "DHCP router not in subnet"));
- end
- else
+ #t;
+ else
+ signal(make(<web-error>,
+ error: "Subnet not in a defined network"));
+ end
+ else
+ signal(make(<web-error>,
+ error: "Subnet overlaps with another subnet"));
+ end if;
+end;
+define method check (subnet :: <ipv4-subnet>, #next next-method, #key test-result = 0)
+ => (res :: <boolean>)
+ next-method();
+ if (subnet.dhcp-start > subnet.dhcp-end)
+ signal(make(<web-error>,
+ error: "DHCP start greater than DHCP end"));
+ elseif (subnet.dhcp-start = broadcast-address(subnet.cidr))
+ signal(make(<web-error>,
+ error: "DHCP start can't be broadcast address"))
+ elseif (subnet.dhcp-start = network-address(subnet.cidr))
+ signal(make(<web-error>,
+ error: "DHCP start can't be network address"))
+ elseif (subnet.dhcp-end = broadcast-address(subnet.cidr))
+ signal(make(<web-error>,
+ error: "DHCP end can't be broadcast address"))
+ elseif (subnet.dhcp-end = network-address(subnet.cidr))
+ signal(make(<web-error>,
+ error: "DHCP end can't be network address"))
+ elseif (subnet.dhcp-router = broadcast-address(subnet.cidr))
+ signal(make(<web-error>,
+ error: "DHCP router can't be broadcast address"))
+ elseif (subnet.dhcp-router = network-address(subnet.cidr))
+ signal(make(<web-error>,
+ error: "DHCP router can't be network address"))
+ end;
+ if (ip-in-net?(subnet, subnet.dhcp-start))
+ if (ip-in-net?(subnet, subnet.dhcp-end))
+ if (ip-in-net?(subnet, subnet.dhcp-router))
+ if ((subnet.dhcp-router > subnet.dhcp-start)
+ & (subnet.dhcp-router < subnet.dhcp-end))
signal(make(<web-error>,
- error: "DHCP end not in subnet"));
- end
+ error: "Router has to be outside of dhcp-range"));
+ else
+ #t;
+ end if;
else
signal(make(<web-error>,
- error: "DHCP start not in subnet"));
+ error: "DHCP router not in subnet"));
end
else
signal(make(<web-error>,
- error: "Subnet not in a defined network"));
+ error: "DHCP end not in subnet"));
end
else
signal(make(<web-error>,
- error: "Subnet overlaps with another subnet"));
- end if;
+ error: "DHCP start not in subnet"));
+ end
end;
define method print-isc-dhcpd-file (config :: <collection>, stream :: <stream>)
Modified: trunk/libraries/network/koala/sources/examples/buddha/ipv6.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/examples/buddha/ipv6.dylan (original)
+++ trunk/libraries/network/koala/sources/examples/buddha/ipv6.dylan Sun Dec 17 19:03:15 2006
@@ -71,17 +71,23 @@
end;
end;
+define method as-dns-string (ip :: <ipv6-address>) => (res)
+ let res = as(<string>, ip);
+ if (res ~= "no v6 address assigned")
+ apply(concatenate, split(res, ':'));
+ end;
+end;
define method as (class == <string>, ip :: <ipv6-address>) => (res :: <string>)
if (ip = $bottom-v6-address)
"no v6 address assigned"
else
- let strings = make(<list>);
- for (i from 0 below 16 by 2)
- let count = ash(ip[i], 8) + ip[i + 1];
- strings := add!(strings, integer-to-string(count, base: 16));
+ let strings = make(<list>);
+ for (i from 0 below 16 by 2)
+ let count = ash(ip[i], 8) + ip[i + 1];
+ strings := add!(strings, integer-to-string(count, base: 16));
+ end;
+ reduce1(method(x, y) concatenate(x, ":", y) end, reverse(strings));
end;
- reduce1(method(x, y) concatenate(x, ":", y) end, reverse(strings));
-end;
end;
define constant $bottom-v6-address = as(<ipv6-address>, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff");
Modified: trunk/libraries/network/koala/sources/examples/buddha/zone.dylan
==============================================================================
--- trunk/libraries/network/koala/sources/examples/buddha/zone.dylan (original)
+++ trunk/libraries/network/koala/sources/examples/buddha/zone.dylan Sun Dec 17 19:03:15 2006
@@ -42,6 +42,22 @@
a.host-name < b.host-name
end;
+define web-class <aaaa-record> (<object>)
+ data host-name :: <string>;
+ data ipv6-address :: <ipv6-address>;
+ data time-to-live :: <integer> = 300;
+end;
+
+define method as (class == <string>, a :: <aaaa-record>)
+ => (res :: <string>)
+ concatenate(a.host-name, " ", as(<string>, a.ipv6-address));
+end;
+
+define method \< (a :: <aaaa-record>, b :: <aaaa-record>)
+ => (res :: <boolean>)
+ a.host-name < b.host-name;
+end;
+
define web-class <mail-exchange> (<object>)
data mx-name :: <string>;
data priority :: <integer> = 23;
@@ -96,6 +112,7 @@
has-many nameserver :: <nameserver>;
has-many mail-exchange :: <mail-exchange>;
has-many a-record :: <a-record>;
+ has-many aaaa-record :: <aaaa-record>;
//has-many text :: <string>;
end;
@@ -133,50 +150,6 @@
end
end;
-/*
-define method print-bind-zone-file (print-zone :: <zone>, stream :: <stream>)
- format(stream, "@\tIN\tSOA\t%s.\t%s. (\n",
- print-zone.nameservers[0],
- print-zone.hostmaster);
- format(stream, "\t\t%d\t; Serial\n", print-zone.serial);
- format(stream, "\t\t%d\t; Refresh\n", print-zone.refresh);
- format(stream, "\t\t%d\t; Retry\n", print-zone.retry);
- format(stream, "\t\t%d\t; Expire\n", print-zone.expire);
- format(stream, "\t\t%d )\t; Minimum\n\n", print-zone.minimum);
- if (print-zone.reverse?)
- do(method(x)
- format(stream, "\tIN\tNS\t%s. \n", x)
- end, print-zone.nameservers);
- do(method(x)
- format(stream, "%d\tIN\tPTR\n%s.%s.\n",
- x.ipv4-address[3],
- x.host-name,
- print-zone.zone-name)
- end, choose(method(x)
- ip-in-net?(parse-cidr(print-zone.zone-name),
- x.ipv4-address)
- end, storage(<host>)));
- else
- do(method(x)
- format(stream, "\tIN\tNS\t%s. \n", x)
- end, print-zone.nameservers);
- do(method(x)
- format(stream, "\tIN\tMX\t%d\t%s.\n", head(x), tail(x))
- end, print-zone.mail-exchanges);
- do(method(x)
- format(stream, "%s\tIN\tA\t%s\n",
- x.host-name,
- as(<string>, x.ipv4-address))
- end, choose(method(x)
- x.zone = print-zone
- end, storage(<host>)));
- do(method(x)
- format(stream, "%s\tCNAME\t%s\n", source(x), target(x))
- end, print-zone.cnames);
- end;
-end;
-*/
-
define method print-tinydns-zone-file (print-zone :: <zone>,
stream :: <stream>,
#key reverse-table)
@@ -223,6 +196,13 @@
print-zone.zone-name,
as(<string>, x.ipv4-address),
x.time-to-live);
+ unless (x.ipv6-address = $bottom-v6-address)
+ format(stream, "3%s.%s:%s:%d\n",
+ x.host-name,
+ print-zone.zone-name,
+ as-dns-string(x.ipv6-address),
+ x.time-to-live);
+ end;
end, choose(method(x)
x.zone = print-zone
end, storage(<host>)));
@@ -234,15 +214,24 @@
as(<string>, x.ipv4-address),
x.time-to-live);
end, print-zone.a-records);
+ //AAAA
+ do(method(x)
+ format(stream, "3%s.%s:%s:%d\n",
+ x.host-name,
+ print-zone.zone-name,
+ as-dns-string(x.ipv6-address),
+ x.time-to-live);
+ end, print-zone.aaaa-records);
//CNAME
do(method(x)
format(stream, "C%s.%s:%s.%s\n",
source(x), print-zone.zone-name, target(x), print-zone.zone-name);
end, print-zone.cnames);
//a records for dynamic PTR records
- let ip = storage(<network>)[0].cidr.cidr-network-address;
+ let rev-net = storage(<network>)[0].cidr;
+ let ip = rev-net.cidr-network-address;
if (reverse-table)
- while (ip < broadcast-address(storage(<network>)[0].cidr))
+ while (ip < broadcast-address(rev-net))
unless (element(reverse-table, as(<string>, ip), default: #f))
format(stream, "+%s.%s:%s:%d\n",
concatenate("hacker-", get-ptr(ip)),
More information about the chatter
mailing list