@@ -5921,6 +5921,68 @@ func TestSet4(t *testing.T) {
59215921 }
59225922}
59235923
5924+ func TestSetComment (t * testing.T ) {
5925+ want := [][]byte {
5926+ // batch begin
5927+ []byte ("\x00 \x00 \x00 \x0a " ),
5928+ // nft flush ruleset
5929+ []byte ("\x00 \x00 \x00 \x00 " ),
5930+ // nft add table inet filter
5931+ []byte ("\x01 \x00 \x00 \x00 \x0b \x00 \x01 \x00 \x66 \x69 \x6c \x74 \x65 \x72 \x00 \x00 \x08 \x00 \x02 \x00 \x00 \x00 \x00 \x00 " ),
5932+ // nft add set inet filter setname { type ipv4_addr\; comment \"test comment\" \; }
5933+ []byte ("\x01 \x00 \x00 \x00 \x0b \x00 \x01 \x00 \x66 \x69 \x6c \x74 \x65 \x72 \x00 \x00 \x0c \x00 \x02 \x00 \x73 \x65 \x74 \x6e \x61 \x6d \x65 \x00 \x08 \x00 \x03 \x00 \x00 \x00 \x00 \x00 \x08 \x00 \x04 \x00 \x00 \x00 \x00 \x07 \x08 \x00 \x05 \x00 \x00 \x00 \x00 \x04 \x08 \x00 \x0a \x00 \x00 \x00 \x00 \x02 \x13 \x00 \x0d \x00 \x07 \x0d \x74 \x65 \x73 \x74 \x20 \x63 \x6f \x6d \x6d \x65 \x6e \x74 \x00 \x00 " ),
5934+ // batch end
5935+ []byte ("\x00 \x00 \x00 \x0a " ),
5936+ }
5937+
5938+ c , err := nftables .New (nftables .WithTestDial (
5939+ func (req []netlink.Message ) ([]netlink.Message , error ) {
5940+ for idx , msg := range req {
5941+ b , err := msg .MarshalBinary ()
5942+ if err != nil {
5943+ t .Fatal (err )
5944+ }
5945+ if len (b ) < 16 {
5946+ continue
5947+ }
5948+ b = b [16 :]
5949+ if len (want ) == 0 {
5950+ t .Errorf ("no want entry for message %d: %x" , idx , b )
5951+ continue
5952+ }
5953+ if got , want := b , want [0 ]; ! bytes .Equal (got , want ) {
5954+ t .Errorf ("message %d: %s" , idx , linediff (nfdump (got ), nfdump (want )))
5955+ }
5956+ want = want [1 :]
5957+ }
5958+ return req , nil
5959+ }))
5960+ if err != nil {
5961+ t .Fatal (err )
5962+ }
5963+
5964+ c .FlushRuleset ()
5965+
5966+ filter := c .AddTable (& nftables.Table {
5967+ Family : nftables .TableFamilyINet ,
5968+ Name : "filter" ,
5969+ })
5970+
5971+ if err := c .AddSet (& nftables.Set {
5972+ ID : 2 ,
5973+ Table : filter ,
5974+ Name : "setname" ,
5975+ KeyType : nftables .TypeIPAddr ,
5976+ Comment : "test comment" ,
5977+ }, nil ); err != nil {
5978+ t .Fatal (err )
5979+ }
5980+
5981+ if err := c .Flush (); err != nil {
5982+ t .Fatal (err )
5983+ }
5984+ }
5985+
59245986func TestMasq (t * testing.T ) {
59255987 tests := []struct {
59265988 name string
0 commit comments