miekgrrl
is a tiny specialized adaptor package with a single Derive()
function which
converts a miekg/dns.Msg
to a rrl.ResponseTuple
suitable for passing to
the rrl Debit()
function.
By way of background, the rrl package is an agnostic implementation of the Response Rate Limiting algorithm as originally developed by ISC. You will need to be familiar with both the rrl and the miekg package prior to understanding the purpose of this package.
The sole reason for adaptor packages such as this is to keep markdingo/rrl
agnostic.
package main
import (
"net"
"github.com/markdingo/miekgrrl"
"github.com/markdingo/rrl"
"github.com/miekg/dns"
)
func main() {
R := rrl.NewRRL(rrl.NewConfig())
response := &dns.Msg{}
... populate response ...
tuple := miekgrrl.Derive(response, "") // Derive the RRL.ResponseTuple from dns.Msg
action, _, _ := R.Debit(net.Addr, tuple) // Apply RRL rules to ResponseTuple
switch action {
case rrl.Drop:
...
case rrl.Send:
..
case rrl.Slip:
..
Alternatively, the Derive()
function is designed such that it can be used directly as an
argument to the rrl.Debit()
function. E.g:
...
R := rrl.NewRRL(rrl.NewConfig())
response := &dns.Msg{}
... populate response ...
action, _, _ := R.Debit(net.Addr, miekgrrl.Derive(response, ""))
switch action {
...
miekgrrl
requires go version 1.19 or later.
Once your application imports "github.com/markdingo/miekgrrl"
, then "go build"
or "go mod tidy"
should download and compile the miekgrrl
package automatically.
If you have any problems using miekgrrl
or suggestions on how it can do a better job,
don't hesitate to create an issue on the
project home page.
This package can only improve with your feedback.
miekgrrl
is Copyright ©️ 2023 Mark Delany and is licensed under the BSD
2-Clause "Simplified" License.