Created
August 14, 2019 18:20
-
-
Save florianl/707c04bb72da6b86bb5336e41c6d3096 to your computer and use it in GitHub Desktop.
inspect netlink attributes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strings" | |
"github.com/mdlayher/netlink" | |
) | |
const nlafNested = (1 << 15) | |
func main() { | |
tests:= map[string] []byte{ | |
"master": []byte{0x3c, 0x0, 0x1, 0x80, 0x14, 0x0, 0x1, 0x80, 0x8, 0x0, 0x1, 0x0, 0x7f, 0x0, 0x0, 0x1, 0x8, 0x0, 0x2, 0x0, 0x7f, 0x0, 0x0, 0x3, 0x24, 0x0, 0x2, 0x80, 0x5, 0x0, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, 0x5, 0x0, 0x5, 0x0, 0x8, 0x0, 0x0, 0x0, 0x5, 0x0, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x0, 0x4, 0x0, 0x4e, 0x8e, 0x0, 0x0}, | |
"future": []byte{0x3c, 0x0, 0x1, 0x80, 0x14, 0x0, 0x1, 0x80, 0x8, 0x0, 0x1, 0x0, 0x7f, 0x0, 0x0, 0x1, 0x8, 0x0, 0x2, 0x0, 0x7f, 0x0, 0x0, 0x2, 0x24, 0x0, 0x2, 0x80, 0x5, 0x0, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, 0x6, 0x0, 0x4, 0x0, 0x75, 0xf0, 0x0, 0x0, 0x5, 0x0, 0x5, 0x0, 0x8, 0x0, 0x0, 0x0, 0x5, 0x0, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3c, 0x0, 0x2, 0x80, 0x14, 0x0, 0x1, 0x80, 0x8, 0x0, 0x1, 0x0, 0x7f, 0x0, 0x0, 0x2, 0x8, 0x0, 0x2, 0x0, 0x7f, 0x0, 0x0, 0x1, 0x24, 0x0, 0x2, 0x80, 0x5, 0x0, 0x1, 0x0, 0x1, 0x0, 0x0, 0x0, 0x6, 0x0, 0x4, 0x0, 0x75, 0xf0, 0x0, 0x0, 0x5, 0x0, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5, 0x0, 0x6, 0x0, 0x0, 0x0, 0x0, 0x0, 0x8, 0x0, 0xc, 0x0, 0xd9, 0x1a, 0xb2, 0xcb, 0x8, 0x0, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0}, | |
} | |
for key, value := range tests { | |
fmt.Println(key) | |
decodeNetlink(value,0) | |
} | |
} | |
func decodeNetlink(data []byte, lvl int) error { | |
ad, err := netlink.NewAttributeDecoder(data) | |
if err != nil { | |
return err | |
} | |
for ad.Next() { | |
space := strings.Repeat(" ", lvl) | |
if ad.Type() & nlafNested == nlafNested { | |
fmt.Printf("%s %4d | %d\n", space, ad.Type(), ad.Type()^nlafNested) | |
decodeNetlink(ad.Bytes(), lvl+3) | |
continue | |
} | |
fmt.Printf("%s %4d\t%#v\n", space, ad.Type(), ad.Bytes()) | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment