mirror of
https://github.com/containers/podman.git
synced 2025-10-17 11:14:40 +08:00
Vendor latest c/common and fix tests
This vendors the latest c/common version, including making Pasta the default rootless network provider. That broke a number of tests, which have been fixed as part of this PR. Also includes a change to network stats logic, which simplifies the code a bit and makes it actually work with Pasta. Signed-off-by: Matt Heon <mheon@redhat.com>
This commit is contained in:
@ -191,7 +191,7 @@ func getContainerNetNS(ctr *Container) (string, *Container, error) {
|
||||
func getContainerNetIO(ctr *Container) (map[string]define.ContainerNetworkStats, error) {
|
||||
perNetworkStats := make(map[string]define.ContainerNetworkStats)
|
||||
|
||||
netNSPath, otherCtr, netPathErr := getContainerNetNS(ctr)
|
||||
netNSPath, _, netPathErr := getContainerNetNS(ctr)
|
||||
if netPathErr != nil {
|
||||
return nil, netPathErr
|
||||
}
|
||||
@ -201,42 +201,19 @@ func getContainerNetIO(ctr *Container) (map[string]define.ContainerNetworkStats,
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
netMode := ctr.config.NetMode
|
||||
netStatus := ctr.getNetworkStatus()
|
||||
if otherCtr != nil {
|
||||
netMode = otherCtr.config.NetMode
|
||||
netStatus = otherCtr.getNetworkStatus()
|
||||
}
|
||||
if netMode.IsSlirp4netns() {
|
||||
// create a fake status with correct interface name for the logic below
|
||||
netStatus = map[string]types.StatusBlock{
|
||||
"slirp4netns": {
|
||||
Interfaces: map[string]types.NetInterface{"tap0": {}},
|
||||
},
|
||||
}
|
||||
}
|
||||
err := ns.WithNetNSPath(netNSPath, func(_ ns.NetNS) error {
|
||||
for _, status := range netStatus {
|
||||
for dev := range status.Interfaces {
|
||||
link, err := netlink.LinkByName(dev)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
stats := link.Attrs().Statistics
|
||||
if stats != nil {
|
||||
newStats := define.ContainerNetworkStats{
|
||||
RxBytes: stats.RxBytes,
|
||||
RxDropped: stats.RxDropped,
|
||||
RxErrors: stats.RxErrors,
|
||||
RxPackets: stats.RxPackets,
|
||||
TxBytes: stats.TxBytes,
|
||||
TxDropped: stats.TxDropped,
|
||||
TxErrors: stats.TxErrors,
|
||||
TxPackets: stats.TxPackets,
|
||||
}
|
||||
links, err := netlink.LinkList()
|
||||
if err != nil {
|
||||
return fmt.Errorf("retrieving all network interfaces: %w", err)
|
||||
}
|
||||
for _, link := range links {
|
||||
attributes := link.Attrs()
|
||||
if attributes.Flags&net.FlagLoopback != 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
perNetworkStats[dev] = newStats
|
||||
}
|
||||
if attributes.Statistics != nil {
|
||||
perNetworkStats[attributes.Name] = getNetStatsFromNetlinkStats(attributes.Statistics)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@ -244,6 +221,19 @@ func getContainerNetIO(ctr *Container) (map[string]define.ContainerNetworkStats,
|
||||
return perNetworkStats, err
|
||||
}
|
||||
|
||||
func getNetStatsFromNetlinkStats(stats *netlink.LinkStatistics) define.ContainerNetworkStats {
|
||||
return define.ContainerNetworkStats{
|
||||
RxBytes: stats.RxBytes,
|
||||
RxDropped: stats.RxDropped,
|
||||
RxErrors: stats.RxErrors,
|
||||
RxPackets: stats.RxPackets,
|
||||
TxBytes: stats.TxBytes,
|
||||
TxDropped: stats.TxDropped,
|
||||
TxErrors: stats.TxErrors,
|
||||
TxPackets: stats.TxPackets,
|
||||
}
|
||||
}
|
||||
|
||||
// joinedNetworkNSPath returns netns path and bool if netns was set
|
||||
func (c *Container) joinedNetworkNSPath() (string, bool) {
|
||||
for _, namespace := range c.config.Spec.Linux.Namespaces {
|
||||
|
Reference in New Issue
Block a user