()
| 115 | } |
| 116 | |
| 117 | func (n *cniNetwork) loadNetworks() error { |
| 118 | // check the mod time of the config dir |
| 119 | f, err := os.Stat(n.cniConfigDir) |
| 120 | if err != nil { |
| 121 | return err |
| 122 | } |
| 123 | modTime := f.ModTime() |
| 124 | |
| 125 | // skip loading networks if they are already loaded and |
| 126 | // if the config dir was not modified since the last call |
| 127 | if n.networks != nil && modTime.Equal(n.modTime) { |
| 128 | return nil |
| 129 | } |
| 130 | // make sure the remove all networks before we reload them |
| 131 | n.networks = nil |
| 132 | n.modTime = modTime |
| 133 | |
| 134 | // FIXME: do we have to support other file types as well, e.g. .conf? |
| 135 | files, err := libcni.ConfFiles(n.cniConfigDir, []string{".conflist"}) |
| 136 | if err != nil { |
| 137 | return err |
| 138 | } |
| 139 | networks := make(map[string]*network, len(files)) |
| 140 | for _, file := range files { |
| 141 | conf, err := libcni.ConfListFromFile(file) |
| 142 | if err != nil { |
| 143 | // do not log ENOENT errors |
| 144 | if !errors.Is(err, os.ErrNotExist) { |
| 145 | logrus.Warnf("Error loading CNI config file %s: %v", file, err) |
| 146 | } |
| 147 | continue |
| 148 | } |
| 149 | |
| 150 | if !types.NameRegex.MatchString(conf.Name) { |
| 151 | logrus.Warnf("CNI config list %s has invalid name, skipping: %v", file, types.RegexError) |
| 152 | continue |
| 153 | } |
| 154 | |
| 155 | // podman < v4.0 used the podman-machine cni plugin for podman machine port forwarding |
| 156 | // since this is now build into podman we no longer use the plugin |
| 157 | // old configs may still contain it so we just remove it here |
| 158 | if n.isMachine { |
| 159 | conf = removeMachinePlugin(conf) |
| 160 | } |
| 161 | |
| 162 | if _, err := n.cniConf.ValidateNetworkList(context.Background(), conf); err != nil { |
| 163 | logrus.Warnf("Error validating CNI config file %s: %v", file, err) |
| 164 | continue |
| 165 | } |
| 166 | |
| 167 | if val, ok := networks[conf.Name]; ok { |
| 168 | logrus.Warnf("CNI config list %s has the same network name as %s, skipping", file, val.filename) |
| 169 | continue |
| 170 | } |
| 171 | |
| 172 | net, err := createNetworkFromCNIConfigList(conf, file) |
| 173 | if err != nil { |
| 174 | logrus.Errorf("CNI config list %s could not be converted to a libpod config, skipping: %v", file, err) |
no test coverage detected