@@ -474,7 +474,7 @@ def nla_parse(msg,l,mtype,stream,idx):
474474
475475 # Note: we use unpack_from which will ignore the null bytes in numeric
476476 # datatypes & for strings & unspec we just strip trailing null bytes
477- if dt == nlh .NLA_STRING or dt == nlh .NLA_UNSPEC : a = _nla_strip (a )
477+ if dt == nlh .NLA_STRING or dt == nlh .NLA_UNSPEC : a = _nla_strip_ (a )
478478 if dt == nlh .NLA_NESTED : a = nla_parse_nested (a )
479479 elif dt == nlh .NLA_U8 : a = struct .unpack_from ("B" ,a ,0 )[0 ]
480480 elif dt == nlh .NLA_U16 : a = struct .unpack_from ("H" ,a ,0 )[0 ]
@@ -485,7 +485,7 @@ def nla_parse(msg,l,mtype,stream,idx):
485485 nla_put (msg ,a ,atype ,dt )
486486 except struct .error :
487487 # append as Error, stripping null bytes
488- nla_put (msg ,_nla_strip (a ),atype ,nlh .NLA_ERROR )
488+ nla_put (msg ,_nla_strip_ (a ),atype ,nlh .NLA_ERROR )
489489 idx = nlh .NLMSG_ALIGN (idx + alen ) # move index to next attr
490490
491491def nla_parse_nested (nested ):
@@ -531,20 +531,6 @@ def nla_parse_nested(nested):
531531 idx = nlh .NLMSG_ALIGN (idx + alen )
532532 return ns
533533
534- def _nla_strip (v ):
535- """
536- strips padding from v
537- :param v: value to strip
538- :returns: v w/o padding
539- **NOTE: Do not use on numeric attributes
540- """
541- try :
542- for i ,e in reversed (list (enumerate (v ))):
543- if e != '\x00 ' : return v [:i + 1 ]
544- return v
545- except IndexError :
546- return v
547-
548534def nla_put (msg ,v ,a ,d ):
549535 """
550536 append attribute to msg's attribute list
@@ -617,6 +603,21 @@ def nla_get(msg,i,value=True):
617603
618604#### FILE PRIVATE ####
619605
606+ def _nla_strip_ (v ):
607+ """
608+ strips padding from v
609+ :param v: value to strip
610+ :returns: v w/o padding
611+ **NOTE: Do not use on numeric attributes
612+ """
613+ try :
614+ for i ,e in reversed (list (enumerate (v ))):
615+ if e != '\x00 ' : return v [:i + 1 ]
616+ return v
617+ except IndexError :
618+ return v
619+
620+
620621def _attrpack_ (a ,v ,d ):
621622 """
622623 :param a: attribute type
0 commit comments