Merge set elements
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 42/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- go, linux
- Ambito
- networking
Direzione di ricerca
Inizia da GetSetElements e dai campi di intervallo di SetElement, quindi confronta l’ordinamento e i marker restituiti con gli esempi IPv4 e IPv6 nell’issue. Il lavoro è completato quando un helper della libreria o un comportamento integrato produce le rappresentazioni CIDR e degli indirizzi in stile nft mostrate, inclusi i limiti finali degli intervalli e gli elementi zero, senza fare affidamento su un presupposto di ordinamento non documentato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hi,
nft will print intervals in CIDR representation - for example:
inet filter @testset6
element 000080fe 00000000 00000000 02000000 : 1 [end]
element 000080fe 00000000 00000000 01000000 : 0 [end]
element 0000072a 01000000 00000000 00000000 : 1 [end]
element 0000072a 00000000 00000000 00000000 : 0 [end]
element 00000000 00000000 00000000 00000000 : 1 [end]
inet filter @testset4
element 0001a8c0 : 1 [end]
element 0000a8c0 : 0 [end]
element 0200007f : 1 [end]
element 0100007f : 0 [end]
element 0200000a : 1 [end]
element 0100000a : 0 [end]
element 00000000 : 1 [end]
gets turned into:
table inet filter {
set testset6 {
type ipv6_addr
flags interval
elements = { 2a07::/64,
fe80::1 }
}
set testset4 {
type ipv4_addr
flags interval
elements = { 10.0.0.1, 127.0.0.1,
192.168.0.0/24 }
}
}
Thanks to https://github.com/google/nftables/pull/342 it is now easy to add new elements in this format.
I would appreciate some advice in regards to retrieving elements in the same representation.
One issue is https://github.com/google/nftables/issues/320, but it can be worked around by iterating over the returned elements in reverse order (hoping the order is stable).
So far I came up with the following (omitted set discovery and error handling for brevity):
elements, _ := nft.GetSetElements(set)
var (
out []string // will contain the resulting nft-style elements
last nftables.SetElement
)
NullIPv4 := []byte{0, 0, 0, 0}
NullIPv6 := []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
for i := len(elements)-1; i >= 0; i-- {
e := elements[i]
switch set.KeyType.Name {
case "ipv4_addr", "ipv6_addr":
if bytes.Compare(e.Key, NullIPv4) == 0 || bytes.Compare(e.Key, NullIPv6) == 0 {
continue
}
ipCurrent, _ := netip.AddrFromSlice(e.Key)
ipLast, _ := netip.AddrFromSlice(last.Key)
ipLastNext := ipLast.Next()
if e.IntervalEnd && ipCurrent == ipLastNext {
out = append(out, ipLast.String())
continue
}
if e.IntervalEnd {
maxLen := 32
if ipLastNext.Is6() {
if !ipCurrent.Is6() {
continue
}
maxLen = 128
}
for l := maxLen; l >= 0; l-- {
mask := net.CIDRMask(l, maxLen)
na := net.IP(ipLastNext.AsSlice()).Mask(mask)
n := net.IPNet{IP: na, Mask: mask}
if n.Contains(net.IP(ipCurrent.AsSlice())) {
out = append(out, fmt.Sprintf("%s/%d", na, l+1))
break
}
}
continue
}
last = e
}
}
Returns (in out):
["10.0.0.1","127.0.0.1","192.168.0.0/24"] // "testset4"
["2a07::/64","fe80::1"] // "testset6"
I would be interested if anyone has feedback and/or a better approach for this - the above feels rather clunky, and I'm not sure if I am not missing any cases (for example, the skipping of zero elements and the need for appending 1 to the mask feels wrong).
If there is a cleaner solution, possibly we could integrate it into the library (either directly into GetSetElements or into a helper function)? It would be useful to reduce the differences between nft and Go, particularly when using both for management.
- Lingua principale
- Go
- Stelle
- 1.4k
- Fork
- 187
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di google/nftables
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
-
Multiple Netlink Decode Paths Can Panic on Malformed or Undersized InputForse già presa @vulragrag-star l’ha presa 33 giorni fa. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 68/100
-
New Tag release.Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
Tutte le issue di google/nftables
Issue simili
-
status:needs-review type:bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Gentleman-Programming/engram#2079 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
limitlessprojects/Go-Hybrid#1377 ·
I maintainer di solito rispondono entro 1 giorno
-
bug report
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 3 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
I maintainer di solito rispondono entro 1 giorno