node-uplink links answers each link's mac, master and parent (S1a links-mac, issue 1965)
mesh/delivery merged: source.main moved to novox/mesh-catalog@0ec8347786f4
mesh/check checking 700b37890bfd on 0ec8347786f4
mesh/delivery merged: source.main moved to novox/mesh-catalog@0ec8347786f4
mesh/check checking 700b37890bfd on 0ec8347786f4
Both holders' uplink-tools copies read address, master, link and
link_index/link_netnsid from the existing ip -j address show call. Fields
are left out where a link has none (L3); a parent in another namespace is
{index, namespace} (L2); the form lives in uplink.go only (L4); only the
tool description changes, not seat.json (L5); bridge fdb MACs are not
answered (L6); names mac, master, parent (L1).
Builds: design 48 10, design 08 code:, issue 1965 note 11 L1-L6
This commit is contained in:
@@ -221,12 +221,24 @@ type Link struct {
|
||||
State string `json:"state"`
|
||||
Kind string `json:"kind,omitempty"`
|
||||
Addresses []string `json:"addresses,omitempty"`
|
||||
// MAC is the link-layer address as ip says it (lo's all-zero included); left out where the link has
|
||||
// none. Master is the bridge or bond the link is enslaved to. Parent is the link it rides on: its
|
||||
// name where that link is in this machine's namespace, else a ParentPeer; both left out where none.
|
||||
MAC string `json:"mac,omitempty"`
|
||||
Master string `json:"master,omitempty"`
|
||||
Parent any `json:"parent,omitempty"`
|
||||
// Default says the default route leaves through it, and Metric that route's metric.
|
||||
Default bool `json:"default_route,omitempty"`
|
||||
Metric *int `json:"metric,omitempty"`
|
||||
DNS *LinkDNS `json:"dns,omitempty"`
|
||||
}
|
||||
|
||||
// ParentPeer is a parent in another network namespace, which has no name here: ip's index and namespace id.
|
||||
type ParentPeer struct {
|
||||
Index int `json:"index"`
|
||||
Namespace int `json:"namespace"`
|
||||
}
|
||||
|
||||
// Links answers the links verb: every link from the kernel, its default route, and what the manager
|
||||
// knows of its names. A manager that cannot be asked is said, never read as no resolvers.
|
||||
func (m Machine) Links(ctx context.Context) (map[string]any, error) {
|
||||
@@ -238,6 +250,11 @@ func (m Machine) Links(ctx context.Context) (map[string]any, error) {
|
||||
Name string `json:"ifname"`
|
||||
State string `json:"operstate"`
|
||||
Kind string `json:"link_type"`
|
||||
MAC string `json:"address"`
|
||||
Master string `json:"master"`
|
||||
Link string `json:"link"`
|
||||
LinkIdx *int `json:"link_index"`
|
||||
NetNSID *int `json:"link_netnsid"`
|
||||
AddrInfo []struct {
|
||||
Local string `json:"local"`
|
||||
Prefix int `json:"prefixlen"`
|
||||
@@ -276,7 +293,13 @@ func (m Machine) Links(ctx context.Context) (map[string]any, error) {
|
||||
}
|
||||
links := []Link{}
|
||||
for _, a := range addrs {
|
||||
l := Link{Name: a.Name, State: a.State, Kind: a.Kind}
|
||||
l := Link{Name: a.Name, State: a.State, Kind: a.Kind, MAC: a.MAC, Master: a.Master}
|
||||
switch {
|
||||
case a.Link != "":
|
||||
l.Parent = a.Link
|
||||
case a.LinkIdx != nil && a.NetNSID != nil:
|
||||
l.Parent = ParentPeer{Index: *a.LinkIdx, Namespace: *a.NetNSID}
|
||||
}
|
||||
for _, ai := range a.AddrInfo {
|
||||
l.Addresses = append(l.Addresses, a2s(ai.Local, ai.Prefix))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user