Esempio n. 1
0
File: main.go Progetto: awh/go-odp
func lookupDatapath(dpif *odp.Dpif, name string) (*odp.DatapathHandle, string) {
	dph, err := dpif.LookupDatapath(name)
	if err == nil {
		return &dph, name
	}

	if !odp.IsNoSuchDatapathError(err) {
		printErr("%s", err)
		return nil, ""
	}

	// If the name is a number, try to use it as an ifindex
	ifindex, err := strconv.ParseUint(name, 10, 32)
	if err == nil {
		dp, err := dpif.LookupDatapathByIndex(int32(ifindex))
		if err == nil {
			return &dp.Handle, dp.Name
		}

		if !odp.IsNoSuchDatapathError(err) {
			printErr("%s", err)
			return nil, ""
		}
	}

	printErr("Cannot find datapath \"%s\"", name)
	return nil, ""
}
Esempio n. 2
0
func DeleteDatapath(dpname string) error {
	dpif, err := odp.NewDpif()
	if err != nil {
		return err
	}
	defer dpif.Close()

	dp, err := dpif.LookupDatapath(dpname)
	if err != nil {
		if odp.IsNoSuchDatapathError(err) {
			return nil
		}
		return err
	}

	return dp.Delete()
}