Skip to content

Commit fd6a064

Browse files
authored
feat: Store interface internal name & dev type as metadata (#1706)
Signed-off-by: Ondrej Fabry <[email protected]>
1 parent 72644e2 commit fd6a064

File tree

6 files changed

+31
-19
lines changed

6 files changed

+31
-19
lines changed

plugins/vpp/ifplugin/descriptor/interface_crud.go

+2
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,8 @@ func (d *InterfaceDescriptor) Retrieve(correlate []adapter.InterfaceKVWithMetada
580580
Vrf: intf.Interface.Vrf,
581581
IPAddresses: intf.Interface.IpAddresses,
582582
TAPHostIfName: tapHostIfName,
583+
InternalName: intf.Meta.InternalName,
584+
DevType: intf.Meta.DevType,
583585
}
584586
retrieved = append(retrieved, adapter.InterfaceKVWithMetadata{
585587
Key: models.Key(intf.Interface),

plugins/vpp/ifplugin/ifaceidx/ifaceidx.go

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ type IfaceMetadata struct {
6363
Vrf uint32
6464
IPAddresses []string // TODO: update from interfaceAddress descriptor with real IPs (not netalloc links)
6565
TAPHostIfName string /* host interface name set for the Linux-side of the TAP interface; empty for non-TAPs */
66+
InternalName string // internal VPP name
67+
DevType string // device type
6668
}
6769

6870
// GetIndex returns sw_if_index assigned to the interface.

plugins/vpp/ifplugin/vppcalls/interface_handler_api.go

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type InterfaceMeta struct {
4242
SupSwIfIndex uint32 `json:"sub_sw_if_index"`
4343
L2Address net.HardwareAddr `json:"l2_address"`
4444
InternalName string `json:"internal_name"`
45+
DevType string `json:"dev_type"`
4546
IsAdminStateUp bool `json:"is_admin_state_up"`
4647
IsLinkStateUp bool `json:"is_link_state_up"`
4748
LinkDuplex uint32 `json:"link_duplex"`
@@ -50,11 +51,14 @@ type InterfaceMeta struct {
5051
LinkSpeed uint32 `json:"link_speed"`
5152
SubID uint32 `json:"sub_id"`
5253
Tag string `json:"tag"`
54+
5355
// dhcp
5456
Dhcp *Dhcp `json:"dhcp"`
57+
5558
// vrf
5659
VrfIPv4 uint32 `json:"vrf_ipv4"`
5760
VrfIPv6 uint32 `json:"vrf_ipv6"`
61+
5862
// wmxnet3
5963
Pci uint32 `json:"pci"`
6064
}

plugins/vpp/ifplugin/vppcalls/vpp1908/dump_interface_vppcalls.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,14 @@ func (h *InterfaceVppHandler) dumpInterfaces(ifIdxs ...uint32) (map[uint32]*vppc
9595
return nil, fmt.Errorf("failed to dump interface: %v", err)
9696
}
9797

98-
ifaceName := strings.TrimRight(ifDetails.InterfaceName, "\x00")
98+
internalName := strings.TrimRight(ifDetails.InterfaceName, "\x00")
9999
l2addr := net.HardwareAddr(ifDetails.L2Address[:ifDetails.L2AddressLength])
100100

101101
details := &vppcalls.InterfaceDetails{
102102
Interface: &interfaces.Interface{
103103
Name: strings.TrimRight(ifDetails.Tag, "\x00"),
104104
// the type may be amended later by further dumps
105-
Type: guessInterfaceType(ifaceName),
105+
Type: guessInterfaceType(internalName),
106106
Enabled: ifDetails.AdminUpDown > 0,
107107
PhysAddress: net.HardwareAddr(ifDetails.L2Address[:ifDetails.L2AddressLength]).String(),
108108
Mtu: getMtu(ifDetails.LinkMtu),
@@ -111,7 +111,7 @@ func (h *InterfaceVppHandler) dumpInterfaces(ifIdxs ...uint32) (map[uint32]*vppc
111111
SwIfIndex: ifDetails.SwIfIndex,
112112
SupSwIfIndex: ifDetails.SupSwIfIndex,
113113
L2Address: l2addr,
114-
InternalName: ifaceName,
114+
InternalName: internalName,
115115
IsAdminStateUp: uintToBool(ifDetails.AdminUpDown),
116116
IsLinkStateUp: uintToBool(ifDetails.LinkUpDown),
117117
LinkDuplex: uint32(ifDetails.LinkDuplex),
@@ -140,18 +140,18 @@ func (h *InterfaceVppHandler) dumpInterfaces(ifIdxs ...uint32) (map[uint32]*vppc
140140
// Fill name for physical interfaces (they are mostly without tag)
141141
switch details.Interface.Type {
142142
case interfaces.Interface_DPDK:
143-
details.Interface.Name = ifaceName
143+
details.Interface.Name = internalName
144144
case interfaces.Interface_AF_PACKET:
145145
details.Interface.Link = &interfaces.Interface_Afpacket{
146146
Afpacket: &interfaces.AfpacketLink{
147-
HostIfName: strings.TrimPrefix(ifaceName, "host-"),
147+
HostIfName: strings.TrimPrefix(internalName, "host-"),
148148
},
149149
}
150150
}
151151
if details.Interface.Name == "" {
152152
// untagged interface - generate a logical name for it
153153
// (apart from local0 it will get removed by resync)
154-
details.Interface.Name = untaggedIfPreffix + ifaceName
154+
details.Interface.Name = untaggedIfPreffix + internalName
155155
}
156156
ifs[ifDetails.SwIfIndex] = details
157157
}

plugins/vpp/ifplugin/vppcalls/vpp2001/dump_interface_vppcalls.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,16 @@ func (h *InterfaceVppHandler) dumpInterfaces(ifIdxs ...uint32) (map[uint32]*vppc
103103
return nil, fmt.Errorf("failed to dump interface: %v", err)
104104
}
105105

106-
ifaceName := strings.TrimRight(ifDetails.InterfaceName, "\x00")
106+
internalName := strings.TrimRight(ifDetails.InterfaceName, "\x00")
107+
ifaceDevType := strings.TrimRight(ifDetails.InterfaceDevType, "\x00")
107108
physAddr := make(net.HardwareAddr, macLength)
108109
copy(physAddr, ifDetails.L2Address[:])
109110

110111
details := &vppcalls.InterfaceDetails{
111112
Interface: &ifs.Interface{
112113
Name: strings.TrimRight(ifDetails.Tag, "\x00"),
113114
// the type may be amended later by further dumps
114-
Type: guessInterfaceType(ifaceName),
115+
Type: guessInterfaceType(internalName),
115116
Enabled: isAdminStateUp(ifDetails.Flags),
116117
PhysAddress: net.HardwareAddr(ifDetails.L2Address[:]).String(),
117118
Mtu: getMtu(ifDetails.LinkMtu),
@@ -120,7 +121,8 @@ func (h *InterfaceVppHandler) dumpInterfaces(ifIdxs ...uint32) (map[uint32]*vppc
120121
SwIfIndex: uint32(ifDetails.SwIfIndex),
121122
SupSwIfIndex: ifDetails.SupSwIfIndex,
122123
L2Address: physAddr,
123-
InternalName: ifaceName,
124+
InternalName: internalName,
125+
DevType: ifaceDevType,
124126
IsAdminStateUp: isAdminStateUp(ifDetails.Flags),
125127
IsLinkStateUp: isLinkStateUp(ifDetails.Flags),
126128
LinkDuplex: uint32(ifDetails.LinkDuplex),
@@ -149,18 +151,18 @@ func (h *InterfaceVppHandler) dumpInterfaces(ifIdxs ...uint32) (map[uint32]*vppc
149151
// Fill name for physical interfaces (they are mostly without tag)
150152
switch details.Interface.Type {
151153
case ifs.Interface_DPDK:
152-
details.Interface.Name = ifaceName
154+
details.Interface.Name = internalName
153155
case ifs.Interface_AF_PACKET:
154156
details.Interface.Link = &ifs.Interface_Afpacket{
155157
Afpacket: &ifs.AfpacketLink{
156-
HostIfName: strings.TrimPrefix(ifaceName, "host-"),
158+
HostIfName: strings.TrimPrefix(internalName, "host-"),
157159
},
158160
}
159161
}
160162
if details.Interface.Name == "" {
161163
// untagged interface - generate a logical name for it
162164
// (apart from local0 it will get removed by resync)
163-
details.Interface.Name = untaggedIfPreffix + ifaceName
165+
details.Interface.Name = untaggedIfPreffix + internalName
164166
}
165167
interfaces[uint32(ifDetails.SwIfIndex)] = details
166168
}

plugins/vpp/ifplugin/vppcalls/vpp2005/dump_interface_vppcalls.go

+9-7
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,16 @@ func (h *InterfaceVppHandler) dumpInterfaces(ifIdxs ...uint32) (map[uint32]*vppc
103103
return nil, fmt.Errorf("failed to dump interface: %v", err)
104104
}
105105

106-
ifaceName := strings.TrimRight(ifDetails.InterfaceName, "\x00")
106+
internalName := strings.TrimRight(ifDetails.InterfaceName, "\x00")
107+
ifaceDevType := strings.TrimRight(ifDetails.InterfaceDevType, "\x00")
107108
physAddr := make(net.HardwareAddr, macLength)
108109
copy(physAddr, ifDetails.L2Address[:])
109110

110111
details := &vppcalls.InterfaceDetails{
111112
Interface: &ifs.Interface{
112113
Name: strings.TrimRight(ifDetails.Tag, "\x00"),
113114
// the type may be amended later by further dumps
114-
Type: guessInterfaceType(ifaceName),
115+
Type: guessInterfaceType(ifaceDevType, internalName),
115116
Enabled: isAdminStateUp(ifDetails.Flags),
116117
PhysAddress: net.HardwareAddr(ifDetails.L2Address[:]).String(),
117118
Mtu: getMtu(ifDetails.LinkMtu),
@@ -120,7 +121,8 @@ func (h *InterfaceVppHandler) dumpInterfaces(ifIdxs ...uint32) (map[uint32]*vppc
120121
SwIfIndex: uint32(ifDetails.SwIfIndex),
121122
SupSwIfIndex: ifDetails.SupSwIfIndex,
122123
L2Address: physAddr,
123-
InternalName: ifaceName,
124+
InternalName: internalName,
125+
DevType: ifaceDevType,
124126
IsAdminStateUp: isAdminStateUp(ifDetails.Flags),
125127
IsLinkStateUp: isLinkStateUp(ifDetails.Flags),
126128
LinkDuplex: uint32(ifDetails.LinkDuplex),
@@ -149,18 +151,18 @@ func (h *InterfaceVppHandler) dumpInterfaces(ifIdxs ...uint32) (map[uint32]*vppc
149151
// Fill name for physical interfaces (they are mostly without tag)
150152
switch details.Interface.Type {
151153
case ifs.Interface_DPDK:
152-
details.Interface.Name = ifaceName
154+
details.Interface.Name = internalName
153155
case ifs.Interface_AF_PACKET:
154156
details.Interface.Link = &ifs.Interface_Afpacket{
155157
Afpacket: &ifs.AfpacketLink{
156-
HostIfName: strings.TrimPrefix(ifaceName, "host-"),
158+
HostIfName: strings.TrimPrefix(internalName, "host-"),
157159
},
158160
}
159161
}
160162
if details.Interface.Name == "" {
161163
// untagged interface - generate a logical name for it
162164
// (apart from local0 it will get removed by resync)
163-
details.Interface.Name = untaggedIfPreffix + ifaceName
165+
details.Interface.Name = untaggedIfPreffix + internalName
164166
}
165167
interfaces[uint32(ifDetails.SwIfIndex)] = details
166168
}
@@ -928,7 +930,7 @@ func dhcpAddressToString(address vpp_dhcp.Address, maskWidth uint32, isIPv6 bool
928930
// guessInterfaceType attempts to guess the correct interface type from its internal name (as given by VPP).
929931
// This is required mainly for those interface types, that do not provide dump binary API,
930932
// such as loopback of af_packet.
931-
func guessInterfaceType(ifName string) ifs.Interface_Type {
933+
func guessInterfaceType(ifDevType, ifName string) ifs.Interface_Type {
932934
switch {
933935
case strings.HasPrefix(ifName, "loop"),
934936
strings.HasPrefix(ifName, "local"):

0 commit comments

Comments
 (0)