lxd/container_lxc.go
func (c *containerLXC) setNetworkRoutes(m types.Device) error {
	if !shared.PathExists(fmt.Sprintf("/sys/class/net/%s", m["host_name"])) {
		return fmt.Errorf("Unknown or missing host side veth: %s", m["host_name"])
	}

	// Flush all IPv4 routes
	_, err := shared.RunCommand("ip", "-4", "route", "flush", "dev", m["host_name"], "proto", "static")
	if err != nil {
		return err
	}

	// Flush all IPv6 routes
	_, err = shared.RunCommand("ip", "-6", "route", "flush", "dev", m["host_name"], "proto", "static")
	if err != nil {
		return err
	}

	// Add additional IPv4 routes
	if m["ipv4.routes"] != "" {
		for _, route := range strings.Split(m["ipv4.routes"], ",") {
			route = strings.TrimSpace(route)
			_, err := shared.RunCommand("ip", "-4", "route", "add", "dev", m["host_name"], route, "proto", "static")
			if err != nil {
				return err
			}
		}
	}

	// Add additional IPv6 routes
	if m["ipv6.routes"] != "" {
		for _, route := range strings.Split(m["ipv6.routes"], ",") {
			route = strings.TrimSpace(route)
			_, err := shared.RunCommand("ip", "-6", "route", "add", "dev", m["host_name"], route, "proto", "static")
			if err != nil {
				return err
			}
		}
	}

	return nil
}
func (c *containerLXC) setNetworkRoutes(m types.Device) error {
	if !shared.PathExists(fmt.Sprintf("/sys/class/net/%s", m["host_name"])) {
		return fmt.Errorf("Unknown or missing host side veth: %s", m["host_name"])
	}

	// Flush all IPv4 routes
	_, err := shared.RunCommand("ip", "-4", "route", "flush", "dev", m["host_name"], "proto", "static")
	if err != nil {
		return err
	}

	// Flush all IPv6 routes
	_, err = shared.RunCommand("ip", "-6", "route", "flush", "dev", m["host_name"], "proto", "static")
	if err != nil {
		return err
	}

	// Add additional IPv4 routes
	if m["ipv4.routes"] != "" {
		for _, route := range strings.Split(m["ipv4.routes"], ",") {
			route = strings.TrimSpace(route)
			_, err := shared.RunCommand("ip", "-4", "route", "add", "dev", m["host_name"], route, "proto", "static")
			if err != nil {
				return err
			}
		}
	}

	// Add additional IPv6 routes
	if m["ipv6.routes"] != "" {
		for _, route := range strings.Split(m["ipv6.routes"], ",") {
			route = strings.TrimSpace(route)
			_, err := shared.RunCommand("ip", "-6", "route", "add", "dev", m["host_name"], route, "proto", "static")
			if err != nil {
				return err
			}
		}
	}

	return nil
}
// setNetworkRoutes applies any static routes configured from the host to the container nic.