change 128 bit IDs to 32 bit
This commit is contained in:
parent
184956829b
commit
60e1f4c540
@ -167,13 +167,13 @@ func (g *Group) LinkUpdateHook(event netlink.LinkUpdate) error {
|
||||
}
|
||||
|
||||
func NewGroup(group *models.Group, nh4 *netfilterHelper.NetfilterHelper, chainPrefix, ipsetNamePrefix string) (*Group, error) {
|
||||
ipsetName := fmt.Sprintf("%s%8x", ipsetNamePrefix, group.ID.ID())
|
||||
ipsetName := fmt.Sprintf("%s%8x", ipsetNamePrefix, group.ID)
|
||||
ipset, err := nh4.IPSet(ipsetName)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to initialize ipset: %w", err)
|
||||
}
|
||||
|
||||
ipsetToLink := nh4.IPSetToLink(fmt.Sprintf("%s%8x", chainPrefix, group.ID.ID()), group.Interface, ipsetName)
|
||||
ipsetToLink := nh4.IPSetToLink(fmt.Sprintf("%s%8x", chainPrefix, group.ID), group.Interface, ipsetName)
|
||||
return &Group{
|
||||
Group: group,
|
||||
iptables: nh4.IPTables,
|
||||
|
18
kvas2.go
18
kvas2.go
@ -2,8 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
@ -16,7 +19,6 @@ import (
|
||||
"kvas2-go/netfilter-helper"
|
||||
"kvas2-go/records"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/miekg/dns"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/vishvananda/netlink"
|
||||
@ -28,6 +30,12 @@ var (
|
||||
ErrGroupIDConflict = errors.New("group id conflict")
|
||||
)
|
||||
|
||||
func randomId() [4]byte {
|
||||
id := make([]byte, 4)
|
||||
binary.BigEndian.PutUint32(id, rand.Uint32())
|
||||
return [4]byte(id)
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
AdditionalTTL uint32
|
||||
ChainPrefix string
|
||||
@ -45,7 +53,7 @@ type App struct {
|
||||
NetfilterHelper4 *netfilterHelper.NetfilterHelper
|
||||
NetfilterHelper6 *netfilterHelper.NetfilterHelper
|
||||
Records *records.Records
|
||||
Groups map[uuid.UUID]*group.Group
|
||||
Groups map[[4]byte]*group.Group
|
||||
|
||||
Link netlink.Link
|
||||
|
||||
@ -72,7 +80,7 @@ func (a *App) handleLink(event netlink.LinkUpdate) {
|
||||
|
||||
err := group.LinkUpdateHook(event)
|
||||
if err != nil {
|
||||
log.Error().Str("group", group.ID.String()).Err(err).Msg("error while handling interface up")
|
||||
log.Error().Str("group", hex.EncodeToString(group.ID[:])).Err(err).Msg("error while handling interface up")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -460,7 +468,7 @@ func New(config Config) (*App, error) {
|
||||
}
|
||||
|
||||
app.Records = records.New()
|
||||
app.Groups = make(map[uuid.UUID]*group.Group)
|
||||
app.Groups = make(map[[4]byte]*group.Group)
|
||||
|
||||
link, err := netlink.LinkByName(app.Config.LinkName)
|
||||
if err != nil {
|
||||
@ -488,7 +496,7 @@ func New(config Config) (*App, error) {
|
||||
return nil, fmt.Errorf("failed to clear iptables: %w", err)
|
||||
}
|
||||
|
||||
app.Groups = make(map[uuid.UUID]*group.Group)
|
||||
app.Groups = make(map[[4]byte]*group.Group)
|
||||
|
||||
return app, nil
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
package models
|
||||
|
||||
import "github.com/google/uuid"
|
||||
|
||||
type Group struct {
|
||||
ID uuid.UUID
|
||||
ID [4]byte
|
||||
Name string
|
||||
Interface string
|
||||
Rules []*Rule
|
||||
|
@ -4,11 +4,10 @@ import (
|
||||
"regexp"
|
||||
|
||||
"github.com/IGLOU-EU/go-wildcard/v2"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type Rule struct {
|
||||
ID uuid.UUID
|
||||
ID [4]byte
|
||||
Name string
|
||||
Type string
|
||||
Rule string
|
||||
|
Loading…
x
Reference in New Issue
Block a user