Skip to content

Commit fe9d234

Browse files
committed
New flag parsing system:
Using a patched flag package, we can now send proper options to the reflector and AS112 responders.
1 parent 2da0bbd commit fe9d234

File tree

7 files changed

+634
-18
lines changed

7 files changed

+634
-18
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test: grong
99
@echo "Running server on port $(DEFAULTPORT)..."
1010
./grong -debug=4 -nodaemon -address ":$(DEFAULTPORT)" -servername "grong.dns.test"
1111

12-
server.$O: responder.$O types.$O
12+
server.$O: responder.$O types.$O myflag.$O
1313

1414
responder.$O: types.$O
1515

README

+20-9
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,28 @@ The official source is <https://github.com/bortzmeyer/grong>
2121
Usage
2222
*****
2323

24-
./grong [-address="[ADDRESS]:PORT"] [-debug=N] [-nodaemon]
24+
./grong [-address="[ADDRESS]:PORT"] [-debug=N] [-nodaemon] [-domain="DOMAIN NAME"]
2525

26-
Run with -h to see the defaults (and the other, less common, options)
26+
Run with -help to see the defaults (and the other, less common, options)
2727

2828
The -address option takes either a port (in the syntax ":NNN"), in
2929
that case GRONG listens on all IP addresses, or one address (in the
3030
syntax "x.y.z.T:NNN" for IPv4 and "[xxxx:yyyy::zzzz]:NNN" for
3131
IPv6). There is currently no way to listen on some (but not all) of the IP
3232
addresses.
3333

34+
The -domain option takes a domain name, which will be the name of the
35+
zone for which the name server will be authoritative for. Not all
36+
responders use it.
37+
3438
The back-end is choosen at compile-time only (I have no idea about the
3539
support for dynamic linking in Go)
3640

3741
Among the provided responders:
3842
* rude-responder: responds REFUSED to every query
3943
* reflector-responder: responds with the IP address of the client (for TXT
40-
requests, in text form, for A or AAAA requests, as binary)
44+
requests, in text form, for A or AAAA requests, as binary). -domain indicates
45+
the zone name it uses (e.g. whoami.example.net)
4146
* as112: an AS 112 name server (see <http://www.as112.net/>)
4247

4348
For the person who compiles
@@ -86,7 +91,8 @@ code of server.go to find others) are:
8691
debug, etc). Always set.
8792
* servername: if set, a string identifying this specific name server
8893
(for instance "cdg1.a.ns.example.net").
89-
* zone: if set, the name of the zone currently served
94+
* zonename: if set, the name of the zone currently served (for instance
95+
"myself.example.net")
9096

9197
Since the map stores various types (the "interface{}", which means the
9298
empty interface, something which is fulfilled by every possible
@@ -97,6 +103,14 @@ if exists {
97103
debugi := reflect.NewValue(debug).(*reflect.IntValue).Get()
98104
}
99105

106+
The responder must also provide a function:
107+
108+
func Init(firstoption int)
109+
110+
which will be called at server startup and which can be used to
111+
process additional command-line flags (see as112.go for a good
112+
example) or any other stuff.
113+
100114
Implementation notes
101115
********************
102116

@@ -107,10 +121,6 @@ are behind BIND.
107121
TODO
108122
****
109123

110-
Pass unknown command-line options to the responder. Options Qname for
111-
the reflector and various TXT for as112. Or use the global config
112-
object? For instance, config["zone"] should be common enough.
113-
114124
Finish the AS112 responder (SOA and NS records)
115125

116126
The ability to listen to more than one address (but not all). Can I
@@ -134,7 +144,8 @@ net, they are meant for internal use only.
134144

135145
Daemonizing seems very difficult with Go
136146
<http://groups.google.com/group/golang-nuts/browse_thread/thread/2b29d93b90501a4b/95242bfb7ae0549e>
137-
In the mean time, nohup + & + disown seems the only solution.
147+
In the mean time, nohup + & + disown seems the only solution. Provide
148+
an example at least for Debian, using start-stop-daemon?
138149

139150
A name server with data, for instance able to serve a zone with a
140151
simple setup, one SOA, a few NS, and one A record for www.$ORIGIN. The

as112.go

+36-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@
22
33
Stephane Bortzmeyer <[email protected]>
44
5+
Example of use:
6+
7+
grong -servername "grong.cloud.as112.test" -- -email toto.example.net -hostname me.as112.net -location "In the cloud"
8+
59
*/
610

711
package responder
812

913
import (
1014
"regexp"
1115
"strings"
16+
"fmt"
17+
"os"
1218
"./types"
19+
"./myflag"
1320
)
1421

1522
const as112Regexp = "(168\\.192\\.in-addr\\.arpa|154\\.169\\.in-addr\\.arpa|16\\.172\\.in-addr\\.arpa|17\\.172\\.in-addr\\.arpa|18\\.172\\.in-addr\\.arpa|19\\.172\\.in-addr\\.arpa|20\\.172\\.in-addr\\.arpa|21\\.172\\.in-addr\\.arpa|22\\.172\\.in-addr\\.arpa|23\\.172\\.in-addr\\.arpa|24\\.172\\.in-addr\\.arpa|25\\.172\\.in-addr\\.arpa|26\\.172\\.in-addr\\.arpa|27\\.172\\.in-addr\\.arpa|28\\.172\\.in-addr\\.arpa|29\\.172\\.in-addr\\.arpa|30\\.172\\.in-addr\\.arpa|31\\.172\\.in-addr\\.arpa|10\\.in-addr\\.arpa)$"
@@ -33,8 +40,8 @@ var (
3340
}
3441

3542
hostnamesoa = types.SOArecord{
36-
Mname: "NOT-CONFIGURED.as112.example.net", // Put the real host name
37-
Rname: "UNKNOWN.as112.example.net", // Put your email address (with @ replaced by .)
43+
Mname: "NOT-CONFIGURED-use-hostname-option.as112.example.net", // Put the real hostname with the -hostname command-line option. We do not use -server which has lightly different semantics.
44+
Rname: "UNKNOWN-use-email-option.as112.example.net", // Put your email address (with @ replaced by .) with the -email command-line option
3845
Serial: 2003030100,
3946
Refresh: 3600,
4047
Retry: 600,
@@ -127,3 +134,30 @@ func Respond(query types.DNSquery, config map[string]interface{}) (result types.
127134
}
128135
return result
129136
}
137+
138+
func Init(firstoption int) {
139+
flag.Reinit(firstoption)
140+
helpptr := flag.Bool("help", false, "Displays usage instructions")
141+
emailptr := flag.String("email", "",
142+
"Set the email address of the manager for this server (in DNS format, with . instead of @)")
143+
locationptr := flag.String("location", "",
144+
"Set the location of this server, for instance \"ALIX exchange point in Somewhere, Somestate\"")
145+
hostnameptr := flag.String("hostname", "",
146+
"Set the official host name for this server")
147+
flag.Parse()
148+
help := *helpptr
149+
if help {
150+
fmt.Printf("Usage of the AS112 responder:\n")
151+
flag.PrintDefaults()
152+
os.Exit(0)
153+
}
154+
if *emailptr != "" {
155+
hostnamesoa.Rname = *emailptr
156+
}
157+
if *locationptr != "" {
158+
hostnameAnswers[0] = *locationptr
159+
}
160+
if *hostnameptr != "" {
161+
hostnamesoa.Mname = *hostnameptr
162+
}
163+
}

0 commit comments

Comments
 (0)