-
Notifications
You must be signed in to change notification settings - Fork 4
/
show_prefix.go
46 lines (38 loc) · 1.07 KB
/
show_prefix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright © 2015-2016 Platina Systems, Inc. All rights reserved.
// Use of this source code is governed by the GPL-2 license described in the
// LICENSE file.
package options
import (
"net"
"github.com/platinasystems/goes/internal/nl/rtnl"
)
func (opt *Options) ShowPrefix(b []byte) {
var prefixa rtnl.Prefixa
prefixa.Write(b)
msg := rtnl.PrefixMsgPtr(b)
if msg.Family != rtnl.AF_INET6 {
opt.Print("incorrect protocol family: ",
rtnl.AfName(msg.Family))
return
}
// FIXME type?
if val := prefixa[rtnl.PREFIX_ADDRESS]; len(val) > 0 {
opt.Print("prefix ", net.IP(val), "/", msg.Len, " ")
}
if name, found := rtnl.If.NameByIndex[int32(msg.IfIndex)]; found {
opt.Print("dev ", name)
} else {
opt.Print("dev ", msg.IfIndex)
}
if (msg.Flags & rtnl.IF_PREFIX_ONLINK) != 0 {
opt.Print("onlink ")
}
if (msg.Flags & rtnl.IF_PREFIX_AUTOCONF) != 0 {
opt.Print("autoconf ")
}
if val := prefixa[rtnl.PREFIX_CACHEINFO]; len(val) > 0 {
ci := rtnl.PrefixCacheInfoPtr(val)
opt.Print("valid ", ci.ValidTime, " ")
opt.Print("preferred ", ci.PreferredTime, " ")
}
}