Skip to content

Commit

Permalink
foo
Browse files Browse the repository at this point in the history
  • Loading branch information
johanix committed May 8, 2024
1 parent 12d1fd2 commit f40c9d4
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 24 deletions.
21 changes: 14 additions & 7 deletions apihandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ func APIcommand(conf *Config) func(w http.ResponseWriter, r *http.Request) {
resp = tapir.CommandResponse{
Status: "ok", // only status we know, so far
Msg: "We're happy, but send more cookies"}
case "stop":
log.Printf("Daemon instructed to stop\n")
resp = tapir.CommandResponse{
Status: "stopping",
Msg: "Daemon was happy, but now winding down",
}
conf.Internal.APIStopCh <- struct{}{}
case "bump":
resp.Msg, err = BumpSerial(conf, cp.Zone)
if err != nil {
Expand Down Expand Up @@ -154,14 +161,14 @@ func APIcommand(conf *Config) func(w http.ResponseWriter, r *http.Request) {
}
resp.Msg = rpzresp.Msg

case "stop":
log.Printf("Daemon instructed to stop\n")
// var done struct{}
// case "stop":
// log.Printf("Daemon instructed to stop\n")
// // var done struct{}
// conf.Internal.APIStopCh <- done
resp = tapir.CommandResponse{
Status: "stopping",
Msg: "Daemon was happy, but now winding down",
}
// resp = tapir.CommandResponse{
// Status: "stopping",
// Msg: "Daemon was happy, but now winding down",
// }
default:
resp.ErrorMsg = fmt.Sprintf("Unknown command: %s", cp.Command)
resp.Error = true
Expand Down
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type ApiserverConf struct {
type InternalConf struct {
// RefreshZoneCh chan RpzRefresher
// RpzCmdCh chan RpzCmdData
APIStopCh chan struct{}
}

func ValidateConfig(v *viper.Viper, cfgfile string) error {
Expand Down
26 changes: 13 additions & 13 deletions dnshandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,19 @@ func ApexResponder(w dns.ResponseWriter, r *dns.Msg, zd *tapir.ZoneData,
var glue tapir.RRset

switch qtype {
case dns.TypeAXFR, dns.TypeIXFR:
// log.Printf("We have the zone %s, so let's try to serve it", qname)
// log.Printf("SOA: %s", zd.SOA.String())
// log.Printf("BodyRRs: %d (+ %d apex RRs)", len(zd.BodyRRs), zd.ApexLen)

zd.Logger.Printf("ApexResponder: sending zone %s with %d body RRs to XfrOut",
zd.ZoneName, len(zd.RRs))

_, err := zd.ZoneTransferOut(w, r)
if err != nil {
zd.Logger.Printf("ApexResponder: error serving zone %s: %v", zd.ZoneName, err)
}
return nil
// case dns.TypeAXFR, dns.TypeIXFR:
// log.Printf("We have the zone %s, so let's try to serve it", qname)
// log.Printf("SOA: %s", zd.SOA.String())
// log.Printf("BodyRRs: %d (+ %d apex RRs)", len(zd.BodyRRs), zd.ApexLen)

// zd.Logger.Printf("ApexResponder: sending zone %s with %d body RRs to XfrOut",
// zd.ZoneName, len(zd.RRs))

// _, err := zd.ZoneTransferOut(w, r)
// if err != nil {
// zd.Logger.Printf("ApexResponder: error serving zone %s: %v", zd.ZoneName, err)
// }
// return nil
case dns.TypeSOA:
// zd.Logger.Printf("There are %d SOA RRs in %s. rrset: %v", len(apex.RRtypes[dns.TypeSOA].RRs),
// zd.ZoneName, apex.RRtypes[dns.TypeSOA])
Expand Down
9 changes: 7 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

_ "github.com/mattn/go-sqlite3"
"github.com/spf13/viper"

"github.com/dnstapir/tapir"
)

Expand All @@ -37,7 +38,7 @@ func (td *TemData) SaveRpzSerial() error {
if serialFile == "" {
log.Fatalf("TEMExiter:No serial cache file specified")
}
serialData := []byte(fmt.Sprintf("%d", td.Downstreams.Serial))
serialData := []byte(fmt.Sprintf("%d", td.Rpz.CurrentSerial))
err := os.WriteFile(serialFile, serialData, 0644)
if err != nil {
log.Printf("Error writing current serial to file: %v", err)
Expand Down Expand Up @@ -102,6 +103,10 @@ func mainloop(conf *Config, configfile *string, td *TemData) {
log.Println("mainloop: SIGHUP received. Forcing refresh of all configured zones.")
log.Printf("mainloop: Requesting refresh of all RPZ zones")
conf.TemData.RpzRefreshCh <- RpzRefresh{Name: ""}
case <-conf.Internal.APIStopCh:
log.Printf("mainloop: API instruction to stop\n")
td.SaveRpzSerial()
wg.Done()
}
}
}()
Expand Down Expand Up @@ -183,7 +188,7 @@ func main() {
}

apistopper := make(chan struct{}) //
// conf.Internal.APIStopCh = apistopper
conf.Internal.APIStopCh = apistopper
go APIdispatcher(&conf, apistopper)
// go httpsserver(&conf, apistopper)

Expand Down
3 changes: 2 additions & 1 deletion output.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func (td *TemData) ParseOutputs() error {
}
// Read the current value of td.Downstreams.Serial from a text file
serialFile := viper.GetString("output.rpz.serialcache")

if serialFile != "" {
serialData, err := os.ReadFile(serialFile)
if err != nil {
Expand Down Expand Up @@ -277,7 +278,7 @@ func (td *TemData) ComputeRpzGreylistAction(name string) tapir.Action {

if _, exists := greyHits["dns-tapir"]; exists {
numtapirtags := greyHits["dns-tapir"].TagMask.NumTags()
if numtapirtags > td.Policy.Greylist.NumTapirTags {
if numtapirtags >= td.Policy.Greylist.NumTapirTags {
td.Logger.Printf("ComputeRpzGreylistAction: name %s has more than %d tapir tags, action is %s",
name, td.Policy.Greylist.NumTapirTags, tapir.ActionToString[td.Policy.Greylist.NumTapirTagsAction])
return td.Policy.Greylist.NumTapirTagsAction
Expand Down
2 changes: 1 addition & 1 deletion tem-policy.sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ policy:
limit: 4
action: DROP
blacktapir: # any of these->action
tags: [ likelymalware, badip, childporn ]
tags: [ likelymalware, badip ]
action: REDIRECT

0 comments on commit f40c9d4

Please sign in to comment.