@@ -51,11 +51,12 @@ type Attribute struct {
5151
5252func (a Attribute ) String () string {
5353 if a .Nested {
54- return fmt .Sprintf ("<Length %d, Type %d, Nested %t, %d Children (%v)>" , len (a .Data ), a .Type , a .Nested , len (a .Children ), a .Children )
54+ return fmt .Sprintf ("<Length %d, Type %d, Nested %t, %d Children (%v)>" ,
55+ len (a .Data ), a .Type , a .Nested , len (a .Children ), a .Children )
5556 }
5657
57- return fmt .Sprintf ("<Length %d, Type %d, Nested %t, NetByteOrder %t, %v>" , len ( a . Data ), a . Type , a . Nested , a . NetByteOrder , a . Data )
58-
58+ return fmt .Sprintf ("<Length %d, Type %d, Nested %t, NetByteOrder %t, %v>" ,
59+ len ( a . Data ), a . Type , a . Nested , a . NetByteOrder , a . Data )
5960}
6061
6162// Uint16 interprets a non-nested Netfilter attribute in network byte order as a uint16.
@@ -84,7 +85,6 @@ func (a *Attribute) PutUint16(v uint16) {
8485
8586// Uint32 interprets a non-nested Netfilter attribute in network byte order as a uint32.
8687func (a Attribute ) Uint32 () uint32 {
87-
8888 if a .Nested {
8989 panic ("Uint32: unexpected Nested attribute" )
9090 }
@@ -98,7 +98,6 @@ func (a Attribute) Uint32() uint32 {
9898
9999// PutUint32 sets the Attribute's data field to a Uint32 encoded in net byte order.
100100func (a * Attribute ) PutUint32 (v uint32 ) {
101-
102101 if len (a .Data ) != 4 {
103102 a .Data = make ([]byte , 4 )
104103 }
@@ -113,7 +112,6 @@ func (a Attribute) Int32() int32 {
113112
114113// Uint64 interprets a non-nested Netfilter attribute in network byte order as a uint64.
115114func (a Attribute ) Uint64 () uint64 {
116-
117115 if a .Nested {
118116 panic ("Uint64: unexpected Nested attribute" )
119117 }
@@ -127,7 +125,6 @@ func (a Attribute) Uint64() uint64 {
127125
128126// PutUint64 sets the Attribute's data field to a Uint64 encoded in net byte order.
129127func (a * Attribute ) PutUint64 (v uint64 ) {
130-
131128 if len (a .Data ) != 8 {
132129 a .Data = make ([]byte , 8 )
133130 }
@@ -164,9 +161,7 @@ func Uint64Bytes(u uint64) []byte {
164161// decode fills the Attribute's Children field with Attributes
165162// obtained by exhausting ad.
166163func (a * Attribute ) decode (ad * netlink.AttributeDecoder ) error {
167-
168164 for ad .Next () {
169-
170165 // Copy the netlink attribute's fields into the netfilter attribute.
171166 nfa := Attribute {
172167 // Only consider the rightmost 14 bits for Type.
@@ -198,11 +193,8 @@ func (a *Attribute) decode(ad *netlink.AttributeDecoder) error {
198193// This function can be passed to AttributeEncoder.Nested for recursively
199194// encoding Attributes.
200195func (a * Attribute ) encode (attrs []Attribute ) func (* netlink.AttributeEncoder ) error {
201-
202196 return func (ae * netlink.AttributeEncoder ) error {
203-
204197 for _ , nfa := range attrs {
205-
206198 if nfa .NetByteOrder && nfa .Nested {
207199 return errInvalidAttributeFlags
208200 }
@@ -227,7 +219,6 @@ func (a *Attribute) encode(attrs []Attribute) func(*netlink.AttributeEncoder) er
227219// a byte array. This byte array should be taken from the netlink.Message's
228220// Data payload after the nfHeaderLen offset.
229221func decodeAttributes (ad * netlink.AttributeDecoder ) ([]Attribute , error ) {
230-
231222 // Use the Children element of the Attribute to decode into.
232223 // Attribute already has nested decoding implemented on the type.
233224 var a Attribute
@@ -247,7 +238,6 @@ func decodeAttributes(ad *netlink.AttributeDecoder) ([]Attribute, error) {
247238
248239// encodeAttributes encodes a list of Attributes into the given netlink.AttributeEncoder.
249240func encodeAttributes (ae * netlink.AttributeEncoder , attrs []Attribute ) error {
250-
251241 if ae == nil {
252242 return errNilAttributeEncoder
253243 }
@@ -260,9 +250,7 @@ func encodeAttributes(ae *netlink.AttributeEncoder, attrs []Attribute) error {
260250// This byte slice can then be copied into a netlink.Message's Data field after
261251// the nfHeaderLen offset.
262252func MarshalAttributes (attrs []Attribute ) ([]byte , error ) {
263-
264253 ae := NewAttributeEncoder ()
265-
266254 if err := encodeAttributes (ae , attrs ); err != nil {
267255 return nil , err
268256 }
@@ -277,7 +265,6 @@ func MarshalAttributes(attrs []Attribute) ([]byte, error) {
277265
278266// UnmarshalAttributes unmarshals a byte slice into a list of Attributes.
279267func UnmarshalAttributes (b []byte ) ([]Attribute , error ) {
280-
281268 ad , err := NewAttributeDecoder (b )
282269 if err != nil {
283270 return nil , err
0 commit comments