Skip to content

Commit e0988fd

Browse files
DrGonzoaboch
authored andcommitted
Fix adding ipset entry comment
1 parent d3c0a2c commit e0988fd

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

ipset_linux.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,16 +274,16 @@ func (h *Handle) ipsetAddDel(nlCmd int, setname string, entry *IPSetEntry) error
274274
req := h.newIpsetRequest(nlCmd)
275275
req.AddData(nl.NewRtAttr(nl.IPSET_ATTR_SETNAME, nl.ZeroTerminated(setname)))
276276

277-
if entry.Comment != "" {
278-
req.AddData(nl.NewRtAttr(nl.IPSET_ATTR_COMMENT, nl.ZeroTerminated(entry.Comment)))
279-
}
280-
281277
data := nl.NewRtAttr(nl.IPSET_ATTR_DATA|int(nl.NLA_F_NESTED), nil)
282278

283279
if !entry.Replace {
284280
req.Flags |= unix.NLM_F_EXCL
285281
}
286282

283+
if entry.Comment != "" {
284+
data.AddChild(nl.NewRtAttr(nl.IPSET_ATTR_COMMENT, nl.ZeroTerminated(entry.Comment)))
285+
}
286+
287287
if entry.Timeout != nil {
288288
data.AddChild(&nl.Uint32Attribute{Type: nl.IPSET_ATTR_TIMEOUT | nl.NLA_F_NET_BYTEORDER, Value: *entry.Timeout})
289289
}

ipset_linux_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func TestIpsetCreateListAddDelDestroy(t *testing.T) {
9595
Replace: true,
9696
Timeout: &timeout,
9797
Counters: true,
98-
Comments: false,
98+
Comments: true,
9999
Skbinfo: false,
100100
})
101101
if err != nil {
@@ -219,7 +219,7 @@ func TestIpsetCreateListAddDelDestroyWithTestCases(t *testing.T) {
219219
Replace: true,
220220
Timeout: &timeout,
221221
Counters: true,
222-
Comments: false,
222+
Comments: true,
223223
Skbinfo: false,
224224
},
225225
entry: &IPSetEntry{
@@ -333,7 +333,7 @@ func TestIpsetCreateListAddDelDestroyWithTestCases(t *testing.T) {
333333
Replace: true,
334334
Timeout: &timeout,
335335
Counters: true,
336-
Comments: false,
336+
Comments: true,
337337
Skbinfo: false,
338338
},
339339
entry: &IPSetEntry{
@@ -350,7 +350,7 @@ func TestIpsetCreateListAddDelDestroyWithTestCases(t *testing.T) {
350350
Replace: true,
351351
Timeout: &timeout,
352352
Counters: true,
353-
Comments: false,
353+
Comments: true,
354354
Skbinfo: false,
355355
},
356356
entry: &IPSetEntry{
@@ -369,7 +369,7 @@ func TestIpsetCreateListAddDelDestroyWithTestCases(t *testing.T) {
369369
Replace: true,
370370
Timeout: &timeout,
371371
Counters: true,
372-
Comments: false,
372+
Comments: true,
373373
Skbinfo: false,
374374
},
375375
entry: &IPSetEntry{

0 commit comments

Comments
 (0)