Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions plugin/executable/nftset/nftset.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ package nftset

import (
"fmt"
"github.com/IrineSistiana/mosdns/v5/plugin/executable/sequence"
"strconv"
"strings"

"github.com/IrineSistiana/mosdns/v5/plugin/executable/sequence"
)

const PluginType = "nftset"
Expand All @@ -48,7 +49,7 @@ type SetArgs struct {

// QuickSetup format: [{ip|ip6|inet},table_name,set_name,{ipv4_addr|ipv6_addr},mask] *2 (can repeat once)
// e.g. "inet,my_table,my_set,ipv4_addr,24 inet,my_table,my_set,ipv6_addr,48"
func QuickSetup(_ sequence.BQ, s string) (any, error) {
func QuickSetup(bq sequence.BQ, s string) (any, error) {
fs := strings.Fields(s)
if len(fs) > 2 {
return nil, fmt.Errorf("expect no more than 2 fields, got %d", len(fs))
Expand Down Expand Up @@ -80,5 +81,5 @@ func QuickSetup(_ sequence.BQ, s string) (any, error) {
return nil, fmt.Errorf("invalid ip type, %s", ss[0])
}
}
return newNftSetPlugin(args)
return newNftSetPlugin(bq.L(), args)
}
11 changes: 9 additions & 2 deletions plugin/executable/nftset/nftset_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ import (
"github.com/IrineSistiana/mosdns/v5/pkg/utils"
"github.com/google/nftables"
"github.com/miekg/dns"
"go.uber.org/zap"
)

type nftSetPlugin struct {
l *zap.Logger
args *Args
v4Handler *nftset_utils.NftSetHandler
v6Handler *nftset_utils.NftSetHandler
}

func newNftSetPlugin(args *Args) (*nftSetPlugin, error) {
func newNftSetPlugin(l *zap.Logger, args *Args) (*nftSetPlugin, error) {
utils.SetDefaultUnsignNum(&args.IPv4.Mask, 24)
utils.SetDefaultUnsignNum(&args.IPv6.Mask, 48)
if m := args.IPv4.Mask; m > 32 {
Expand All @@ -50,6 +52,7 @@ func newNftSetPlugin(args *Args) (*nftSetPlugin, error) {
}

p := &nftSetPlugin{
l: l,
args: args,
}

Expand Down Expand Up @@ -84,7 +87,11 @@ func (p *nftSetPlugin) Exec(_ context.Context, qCtx *query_context.Context) erro
r := qCtx.R()
if r != nil {
if err := p.addElems(r); err != nil {
return fmt.Errorf("nftable: %w", err)
p.l.Info(
fmt.Errorf("nftable: %w", err).Error(),
zap.Inline(qCtx),
)
return nil
}
}
return nil
Expand Down
4 changes: 3 additions & 1 deletion plugin/executable/nftset/nftset_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ package nftset

import (
"context"

"github.com/IrineSistiana/mosdns/v5/pkg/query_context"
"go.uber.org/zap"
)

type nftSetPlugin struct{}

func newNftSetPlugin(args *Args) (*nftSetPlugin, error) {
func newNftSetPlugin(l *zap.Logger, args *Args) (*nftSetPlugin, error) {
return &nftSetPlugin{}, nil
}

Expand Down