* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "config.h"
+
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include "conf.h"
+#include "confile.h"
+#include "confile_utils.h"
+#include "error.h"
#include "log.h"
+#include "list.h"
#include "utils.h"
+lxc_log_define(lxc_confile_utils, lxc);
+
int parse_idmaps(const char *idmap, char *type, unsigned long *nsid,
unsigned long *hostid, unsigned long *range)
{
return true;
}
+
+struct lxc_netdev *lxc_find_netdev_by_idx(struct lxc_conf *conf,
+ unsigned int idx)
+{
+ struct lxc_netdev *netdev = NULL;
+ struct lxc_list *networks = &conf->network;
+ struct lxc_list *insert = networks;
+
+ /* lookup network */
+ if (lxc_list_empty(networks))
+ return NULL;
+
+ lxc_list_for_each(insert, networks) {
+ netdev = insert->elem;
+ if (netdev->idx >= idx)
+ break;
+ }
+
+ /* network already exists */
+ if (netdev->idx == idx)
+ return netdev;
+
+ return NULL;
+}
+
+/* Takes care of finding the correct netdev struct in the networks list or
+ * allocates a new one if it couldn't be found.
+ */
+struct lxc_netdev *lxc_get_netdev_by_idx(struct lxc_conf *conf,
+ unsigned int idx)
+{
+ struct lxc_list *newlist;
+ struct lxc_netdev *netdev = NULL;
+ struct lxc_list *networks = &conf->network;
+ struct lxc_list *insert = networks;
+
+ /* lookup network */
+ netdev = lxc_find_netdev_by_idx(conf, idx);
+ if (netdev)
+ return netdev;
+
+ /* network does not exist */
+ netdev = malloc(sizeof(*netdev));
+ if (!netdev)
+ return NULL;
+
+ memset(netdev, 0, sizeof(*netdev));
+ lxc_list_init(&netdev->ipv4);
+ lxc_list_init(&netdev->ipv6);
+
+ /* give network a unique index */
+ netdev->idx = idx;
+
+ /* prepare new list */
+ newlist = malloc(sizeof(*newlist));
+ if (!newlist) {
+ free(netdev);
+ return NULL;
+ }
+
+ lxc_list_init(newlist);
+ newlist->elem = netdev;
+
+ /* Insert will now point to the correct position to insert the new
+ * netdev.
+ */
+ lxc_list_add_tail(insert, newlist);
+
+ return netdev;
+}
#include <stdbool.h>
+#include "conf.h"
+
extern int parse_idmaps(const char *idmap, char *type, unsigned long *nsid,
unsigned long *hostid, unsigned long *range);
extern bool lxc_config_value_empty(const char *value);
+extern struct lxc_netdev *lxc_find_netdev_by_idx(struct lxc_conf *conf,
+ unsigned int idx);
+extern struct lxc_netdev *lxc_get_netdev_by_idx(struct lxc_conf *conf,
+ unsigned int idx);
#endif /* __LXC_CONFILE_UTILS_H */