Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
corny authored and aboch committed Oct 30, 2018
1 parent e137ed6 commit aa5b058
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 28 deletions.
3 changes: 2 additions & 1 deletion link_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -1524,7 +1524,8 @@ func LinkDeserialize(hdr *unix.NlMsghdr, m []byte) (Link, error) {
if err != nil {
return nil, err
}
base.Protinfo = parseProtinfo(attrs)
protinfo := parseProtinfo(attrs)
base.Protinfo = &protinfo
}
case unix.IFLA_OPERSTATE:
base.OperState = LinkOperState(uint8(attr.Value[0]))
Expand Down
8 changes: 2 additions & 6 deletions nl/nl_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,12 @@ func (req *NetlinkRequest) Serialize() []byte {
}

func (req *NetlinkRequest) AddData(data NetlinkRequestData) {
if data != nil {
req.Data = append(req.Data, data)
}
req.Data = append(req.Data, data)
}

// AddRawData adds raw bytes to the end of the NetlinkRequest object during serialization
func (req *NetlinkRequest) AddRawData(data []byte) {
if data != nil {
req.RawData = append(req.RawData, data...)
}
req.RawData = append(req.RawData, data...)
}

// Execute the request against a the given sockType.
Expand Down
7 changes: 3 additions & 4 deletions protinfo_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,15 @@ func (h *Handle) LinkGetProtinfo(link Link) (Protinfo, error) {
if err != nil {
return pi, err
}
pi = *parseProtinfo(infos)
pi = parseProtinfo(infos)

return pi, nil
}
}
return pi, fmt.Errorf("Device with index %d not found", base.Index)
}

func parseProtinfo(infos []syscall.NetlinkRouteAttr) *Protinfo {
var pi Protinfo
func parseProtinfo(infos []syscall.NetlinkRouteAttr) (pi Protinfo) {
for _, info := range infos {
switch info.Attr.Type {
case nl.IFLA_BRPORT_MODE:
Expand All @@ -71,5 +70,5 @@ func parseProtinfo(infos []syscall.NetlinkRouteAttr) *Protinfo {
pi.ProxyArpWiFi = byteToBool(info.Value[0])
}
}
return &pi
return
}
7 changes: 1 addition & 6 deletions xfrm_policy_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,7 @@ func (h *Handle) xfrmPolicyGetOrDelete(policy *XfrmPolicy, nlProto int) (*XfrmPo
return nil, err
}

p, err := parseXfrmPolicy(msgs[0], FAMILY_ALL)
if err != nil {
return nil, err
}

return p, nil
return parseXfrmPolicy(msgs[0], FAMILY_ALL)
}

func parseXfrmPolicy(m []byte, family int) (*XfrmPolicy, error) {
Expand Down
13 changes: 2 additions & 11 deletions xfrm_state_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,7 @@ func (h *Handle) xfrmStateAllocSpi(state *XfrmState) (*XfrmState, error) {
return nil, err
}

s, err := parseXfrmState(msgs[0], FAMILY_ALL)
if err != nil {
return nil, err
}

return s, err
return parseXfrmState(msgs[0], FAMILY_ALL)
}

// XfrmStateDel will delete an xfrm state from the system. Note that
Expand Down Expand Up @@ -394,11 +389,7 @@ func (h *Handle) XfrmStateFlush(proto Proto) error {
req.AddData(&nl.XfrmUsersaFlush{Proto: uint8(proto)})

_, err := req.Execute(unix.NETLINK_XFRM, 0)
if err != nil {
return err
}

return nil
return err
}

func limitsToLft(lmts XfrmStateLimits, lft *nl.XfrmLifetimeCfg) {
Expand Down

0 comments on commit aa5b058

Please sign in to comment.